Created Draft feature for PartDesign

This commit is contained in:
jrheinlaender
2012-11-25 20:15:01 +04:30
committed by wmayer
parent 391936f4eb
commit 433ead710f
16 changed files with 1722 additions and 376 deletions

View File

@@ -20,40 +20,41 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Tool.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Face.hxx>
# include <TopExp.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <QMessageBox>
#endif
#include <sstream>
#include <algorithm>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Mod/Part/App/Part2DObject.h>
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Tool.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Face.hxx>
# include <TopExp.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <QMessageBox>
#endif
#include <sstream>
#include <algorithm>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Mod/Part/App/Part2DObject.h>
#include <Mod/PartDesign/App/FeatureAdditive.h>
#include <Mod/PartDesign/App/FeatureSubtractive.h>
using namespace std;
#include "FeaturePickDialog.h"
using namespace std;
#include "FeaturePickDialog.h"
namespace Gui {
//===========================================================================
// Common utility functions
@@ -62,7 +63,7 @@ namespace Gui {
// Take a list of Part2DObjects and erase those which are not eligible for creating a
// SketchBased feature. If supportRequired is true, also erase those that cannot be used to define
// a Subtractive feature
void validateSketches(std::vector<App::DocumentObject*>& sketches, const bool supportRequired)
void validateSketches(std::vector<App::DocumentObject*>& sketches, const bool supportRequired)
{
std::vector<App::DocumentObject*>::iterator s = sketches.begin();
@@ -448,130 +449,130 @@ CmdPartDesignFillet::CmdPartDesignFillet()
sStatusTip = sToolTipText;
sPixmap = "PartDesign_Fillet";
}
void CmdPartDesignFillet::activated(int iMsg)
{
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body. Only one body is allowed."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Fillet works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of selected Part is empty"));
return;
}
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges);
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") {
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge);
if(los.Extent() != 2)
{
SubNames.erase(SubNames.begin()+i);
continue;
}
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont != GeomAbs_C0) {
SubNames.erase(SubNames.begin()+i);
continue;
}
i++;
}
else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
TopTools_IndexedMapOfShape mapOfFaces;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces);
for(int j = 1; j <= mapOfFaces.Extent(); ++j) {
TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j));
int id = mapOfEdges.FindIndex(edge);
std::stringstream buf;
buf << "Edge";
buf << id;
if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end())
{
SubNames.push_back(buf.str());
}
}
SubNames.erase(SubNames.begin()+i);
}
// empty name or any other sub-element
else {
SubNames.erase(SubNames.begin()+i);
}
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No fillet possible on selected faces/edges"));
return;
}
std::string SelString;
SelString += "(App.";
SelString += "ActiveDocument";//getObject()->getDocument()->getName();
SelString += ".";
SelString += selection[0].getFeatName();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
SelString += *it;
SelString += "\"";
if(it != --SubNames.end())
SelString += ",";
}
SelString += "])";
std::string FeatName = getUniqueObjectName("Fillet");
openCommand("Make Fillet");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Fillet\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName());
}
void CmdPartDesignFillet::activated(int iMsg)
{
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body. Only one body is allowed."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Fillet works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of selected Part is empty"));
return;
}
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges);
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") {
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge);
if(los.Extent() != 2)
{
SubNames.erase(SubNames.begin()+i);
continue;
}
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont != GeomAbs_C0) {
SubNames.erase(SubNames.begin()+i);
continue;
}
i++;
}
else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
TopTools_IndexedMapOfShape mapOfFaces;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces);
for(int j = 1; j <= mapOfFaces.Extent(); ++j) {
TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j));
int id = mapOfEdges.FindIndex(edge);
std::stringstream buf;
buf << "Edge";
buf << id;
if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end())
{
SubNames.push_back(buf.str());
}
}
SubNames.erase(SubNames.begin()+i);
}
// empty name or any other sub-element
else {
SubNames.erase(SubNames.begin()+i);
}
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No fillet possible on selected faces/edges"));
return;
}
std::string SelString;
SelString += "(App.";
SelString += "ActiveDocument";//getObject()->getDocument()->getName();
SelString += ".";
SelString += selection[0].getFeatName();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
SelString += *it;
SelString += "\"";
if(it != --SubNames.end())
SelString += ",";
}
SelString += "])";
std::string FeatName = getUniqueObjectName("Fillet");
openCommand("Make Fillet");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Fillet\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName());
}
bool CmdPartDesignFillet::isActive(void)
{
@@ -594,137 +595,245 @@ CmdPartDesignChamfer::CmdPartDesignChamfer()
sStatusTip = sToolTipText;
sPixmap = "PartDesign_Chamfer";
}
void CmdPartDesignChamfer::activated(int iMsg)
{
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body. Only one body is allowed."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Chamfer works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of selected part is empty"));
return;
}
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges);
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") {
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge);
if(los.Extent() != 2)
{
SubNames.erase(SubNames.begin()+i);
continue;
}
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont != GeomAbs_C0) {
SubNames.erase(SubNames.begin()+i);
continue;
}
i++;
}
else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
TopTools_IndexedMapOfShape mapOfFaces;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces);
for(int j = 1; j <= mapOfFaces.Extent(); ++j) {
TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j));
int id = mapOfEdges.FindIndex(edge);
std::stringstream buf;
buf << "Edge";
buf << id;
if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end())
{
SubNames.push_back(buf.str());
}
}
SubNames.erase(SubNames.begin()+i);
}
// empty name or any other sub-element
else {
SubNames.erase(SubNames.begin()+i);
}
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No chamfer possible on selected faces/edges"));
return;
}
std::string SelString;
SelString += "(App.";
SelString += "ActiveDocument";//getObject()->getDocument()->getName();
SelString += ".";
SelString += selection[0].getFeatName();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
SelString += *it;
SelString += "\"";
if(it != --SubNames.end())
SelString += ",";
}
SelString += "])";
std::string FeatName = getUniqueObjectName("Chamfer");
openCommand("Make Chamfer");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Chamfer\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName());
}
void CmdPartDesignChamfer::activated(int iMsg)
{
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body. Only one body is allowed."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Chamfer works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of selected part is empty"));
return;
}
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges);
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") {
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge);
if(los.Extent() != 2)
{
SubNames.erase(SubNames.begin()+i);
continue;
}
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont != GeomAbs_C0) {
SubNames.erase(SubNames.begin()+i);
continue;
}
i++;
}
else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
TopTools_IndexedMapOfShape mapOfFaces;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces);
for(int j = 1; j <= mapOfFaces.Extent(); ++j) {
TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j));
int id = mapOfEdges.FindIndex(edge);
std::stringstream buf;
buf << "Edge";
buf << id;
if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end())
{
SubNames.push_back(buf.str());
}
}
SubNames.erase(SubNames.begin()+i);
}
// empty name or any other sub-element
else {
SubNames.erase(SubNames.begin()+i);
}
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No chamfer possible on selected faces/edges"));
return;
}
std::string SelString;
SelString += "(App.";
SelString += "ActiveDocument";//getObject()->getDocument()->getName();
SelString += ".";
SelString += selection[0].getFeatName();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
SelString += *it;
SelString += "\"";
if(it != --SubNames.end())
SelString += ",";
}
SelString += "])";
std::string FeatName = getUniqueObjectName("Chamfer");
openCommand("Make Chamfer");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Chamfer\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName());
}
bool CmdPartDesignChamfer::isActive(void)
{
return hasActiveDocument();
}
//===========================================================================
// PartDesign_Draft
//===========================================================================
DEF_STD_CMD_A(CmdPartDesignDraft);
CmdPartDesignDraft::CmdPartDesignDraft()
:Command("PartDesign_Draft")
{
sAppModule = "PartDesign";
sGroup = QT_TR_NOOP("PartDesign");
sMenuText = QT_TR_NOOP("Draft");
sToolTipText = QT_TR_NOOP("Make a draft on a face");
sWhatsThis = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "PartDesign_Draft";
}
void CmdPartDesignDraft::activated(int iMsg)
{
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() < 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one or more faces."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Draft works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of selected Part is empty"));
return;
}
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
// Check for valid face types
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
BRepAdaptor_Surface sf(face);
if ((sf.GetType() != GeomAbs_Plane) && (sf.GetType() != GeomAbs_Cylinder) && (sf.GetType() != GeomAbs_Cone))
SubNames.erase(SubNames.begin()+i);
} else {
// empty name or any other sub-element
SubNames.erase(SubNames.begin()+i);
}
i++;
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No draft possible on selected faces"));
return;
}
std::string SelString;
SelString += "(App.";
SelString += "ActiveDocument";
SelString += ".";
SelString += selection[0].getFeatName();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
SelString += *it;
SelString += "\"";
if(it != --SubNames.end())
SelString += ",";
}
SelString += "])";
std::string FeatName = getUniqueObjectName("Draft");
// We don't create any defaults for neutral plane and pull direction, but Draft::execute()
// will choose them.
openCommand("Make Draft");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Draft\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Doc,"App.activeDocument().%s.Angle = %f",FeatName.c_str(), 1.5);
updateActive();
if (isActiveObjectValid()) {
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName());
}
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName());
copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName());
}
bool CmdPartDesignDraft::isActive(void)
{
return hasActiveDocument();
}
//===========================================================================
// PartDesign_Mirrored
//===========================================================================
@@ -744,36 +853,36 @@ CmdPartDesignMirrored::CmdPartDesignMirrored()
void CmdPartDesignMirrored::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("Mirrored");
std::stringstream str;
std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@@ -818,36 +927,36 @@ CmdPartDesignLinearPattern::CmdPartDesignLinearPattern()
void CmdPartDesignLinearPattern::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("LinearPattern");
std::stringstream str;
std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@@ -892,36 +1001,36 @@ CmdPartDesignPolarPattern::CmdPartDesignPolarPattern()
void CmdPartDesignPolarPattern::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("PolarPattern");
std::stringstream str;
std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@@ -966,36 +1075,36 @@ CmdPartDesignScaled::CmdPartDesignScaled()
void CmdPartDesignScaled::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("Scaled");
std::stringstream str;
std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@@ -1039,36 +1148,36 @@ CmdPartDesignMultiTransform::CmdPartDesignMultiTransform()
void CmdPartDesignMultiTransform::activated(int iMsg)
{
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Get a valid original from the user
// First check selections
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(PartDesign::Additive::getClassTypeId());
std::vector<App::DocumentObject*> subtractive = getSelection().getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// Next create a list of all eligible objects
if (features.size() == 0) {
features = getDocument()->getObjectsOfType(PartDesign::Additive::getClassTypeId());
subtractive = getDocument()->getObjectsOfType(PartDesign::Subtractive::getClassTypeId());
features.insert(features.end(), subtractive.begin(), subtractive.end());
// If there is more than one selected or eligible object, show dialog and let user pick one
if (features.size() > 1) {
PartDesignGui::FeaturePickDialog Dlg(features);
if ((Dlg.exec() != QDialog::Accepted) || (features = Dlg.getFeatures()).empty())
return; // Cancelled or nothing selected
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No valid features in this document"),
QObject::tr("Please create a subtractive or additive feature first, please"));
return;
}
}
std::string FeatName = getUniqueObjectName("MultiTransform");
std::stringstream str;
std::vector<std::string> tempSelNames;
str << "App.activeDocument()." << FeatName << ".Originals = [";
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
for (std::vector<App::DocumentObject*>::iterator it = features.begin(); it != features.end(); ++it){
str << "App.activeDocument()." << (*it)->getNameInDocument() << ",";
tempSelNames.push_back((*it)->getNameInDocument());
}
str << "]";
@@ -1103,6 +1212,7 @@ void CreatePartDesignCommands(void)
rcCmdMgr.addCommand(new CmdPartDesignRevolution());
rcCmdMgr.addCommand(new CmdPartDesignGroove());
rcCmdMgr.addCommand(new CmdPartDesignFillet());
rcCmdMgr.addCommand(new CmdPartDesignDraft());
//rcCmdMgr.addCommand(new CmdPartDesignNewSketch());
rcCmdMgr.addCommand(new CmdPartDesignChamfer());
rcCmdMgr.addCommand(new CmdPartDesignMirrored());