PartDesignGui: move shared code for all dressUp features into common place.

Also this allows the old workflow for thickness and draft features.
This commit is contained in:
Alexander Golubev 2015-07-22 11:58:51 +03:00 committed by Stefan Tröger
parent b14d7c2e14
commit 9db8afd716
2 changed files with 123 additions and 217 deletions

View File

@ -1474,31 +1474,49 @@ bool CmdPartDesignSubtractiveLoft::isActive(void)
// Common utility functions for Dressup features
//===========================================================================
void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
bool dressupGetSelected(Gui::Command* cmd, const std::string& which,
Gui::SelectionObject &selected)
{
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
selection = cmd->getSelection().getSelectionEx();
if (selection.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body."));
return;
return false;
} else if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body from a single body."));
return;
return false;
}
Gui::Selection().clearSelection();
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
// set the
selected = selection[0];
if (!selected.isObjectTypeOf(Part::Feature::getClassTypeId())) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QString::fromStdString(which) + QObject::tr(" works only on parts."));
return;
QObject::tr("%1 works only on parts.").arg(QString::fromStdString(which)));
return false;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of the selected Part is empty"));
return false;
}
return true;
}
void finishDressupFeature(const Gui::Command* cmd, const std::string& which,
Part::Feature *base, const std::vector<std::string> & SubNames)
{
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QString::fromStdString(which) + QObject::tr(" not possible on selected faces/edges."));
@ -1509,7 +1527,7 @@ void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
SelString += "(App.";
SelString += "ActiveDocument";
SelString += ".";
SelString += selection[0].getFeatName();
SelString += base->getNameInDocument();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
@ -1529,6 +1547,19 @@ void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
finishFeature(cmd, FeatName, base);
}
void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
{
Gui::SelectionObject selected;
if (!dressupGetSelected ( cmd, which, selected))
return;
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selected.getSubNames());
finishDressupFeature (cmd, which, base, SubNames);
}
//===========================================================================
// PartDesign_Fillet
//===========================================================================
@ -1603,41 +1634,16 @@ CmdPartDesignDraft::CmdPartDesignDraft()
void CmdPartDesignDraft::activated(int iMsg)
{
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true);
if (!pcActiveBody) return;
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."));
Gui::SelectionObject selected;
if (!dressupGetSelected ( this, "Draft", selected))
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());
if (base != pcActiveBody->getPrevSolidFeature(NULL, true)) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong base feature"),
QObject::tr("Only the current Tip of the active Body can be selected as the base feature"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selected.getSubNames());
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());
unsigned int i = 0;
size_t i = 0;
// filter out the edges
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
@ -1656,40 +1662,7 @@ void CmdPartDesignDraft::activated(int iMsg)
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.
// Note: When the body feature is there, the best thing would be to get pull direction and
// neutral plane from the preceding feature in the tree. Or even store them as default in
// the Body feature itself
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);
finishFeature(this, FeatName);
finishDressupFeature (this, "Draft", base, SubNames);
}
bool CmdPartDesignDraft::isActive(void)
@ -1717,41 +1690,15 @@ CmdPartDesignThickness::CmdPartDesignThickness()
void CmdPartDesignThickness::activated(int iMsg)
{
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true);
if (!pcActiveBody) return;
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."));
Gui::SelectionObject selected;
if (!dressupGetSelected ( this, "Thickness", selected))
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Thickness works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
if (base != pcActiveBody->getPrevSolidFeature(NULL, true)) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong base feature"),
QObject::tr("Only the current Tip of the active Body can be selected as the base feature"));
return;
}
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());
unsigned int i = 0;
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selected.getSubNames());
size_t i = 0;
// filter out the edges
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
@ -1763,35 +1710,7 @@ void CmdPartDesignThickness::activated(int iMsg)
i++;
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No thickness possible with 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("Thickness");
openCommand("Make Thickness");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Thickness\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Doc,"App.activeDocument().%s.Value = %f",FeatName.c_str(), 1.);
finishFeature(this, FeatName);
finishDressupFeature (this, "Thickness", base, SubNames);
}
bool CmdPartDesignThickness::isActive(void)

View File

@ -746,7 +746,9 @@ void CmdPartDesignNewSketch::activated(int iMsg)
QObject::tr("You have to select a face or plane from the active body!"));
return;
}
} else if (pcActiveBody->getNextSolidFeature() != obj) {
} else if (!obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())
&& pcActiveBody->getNextSolidFeature() != obj) {
// TOOD: checkme why it's forbidden!?
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from inactive feature"),
QObject::tr("You can only use the last solid feature as sketch support"));
return;
@ -1472,31 +1474,54 @@ bool CmdPartDesignSubtractiveLoft::isActive(void)
// Common utility functions for Dressup features
//===========================================================================
void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
bool dressupGetSelected(Gui::Command* cmd, const std::string& which,
Gui::SelectionObject &selected)
{
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
selection = cmd->getSelection().getSelectionEx();
if (selection.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body."));
return;
return false;
} else if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body from a single body."));
return;
return false;
}
Gui::Selection().clearSelection();
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
// set the
selected = selection[0];
if (!selected.isObjectTypeOf(Part::Feature::getClassTypeId())) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
<<<<<<< 666dffc868c42171b4541f1d102c319db06415a8
QString::fromStdString(which) + QObject::tr(" works only on parts."));
return;
=======
QObject::tr("%1 works only on parts").arg(QString::fromStdString(which)));
return false;
>>>>>>> PartDesignGui: move shared code for all dressUp features into common place.
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of the selected Part is empty"));
return false;
}
return true;
}
void finishDressupFeature(const Gui::Command* cmd, const std::string& which,
Part::Feature *base, const std::vector<std::string> & SubNames)
{
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QString::fromStdString(which) + QObject::tr(" not possible on selected faces/edges."));
@ -1507,7 +1532,7 @@ void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
SelString += "(App.";
SelString += "ActiveDocument";
SelString += ".";
SelString += selection[0].getFeatName();
SelString += base->getNameInDocument();
SelString += ",[";
for(std::vector<std::string>::const_iterator it = SubNames.begin();it!=SubNames.end();++it){
SelString += "\"";
@ -1523,13 +1548,21 @@ void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
cmd->openCommand((std::string("Make ") + which).c_str());
cmd->doCommand(cmd->Doc,"App.activeDocument().addObject(\"PartDesign::%s\",\"%s\")",which.c_str(), FeatName.c_str());
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
<<<<<<< 1a3440f42cfb6399e5b3914b28c96c9cbbac3f2b
doCommand(Gui,"Gui.Selection.clearSelection()");
finishFeature(cmd, FeatName);
=======
finishFeature(cmd, FeatName, base);
>>>>>>> PartDesign/Gui: more old workflow support
}
void makeChamferOrFillet(Gui::Command* cmd, const std::string& which)
{
Gui::SelectionObject selected;
if (!dressupGetSelected ( cmd, which, selected))
return;
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selected.getSubNames());
finishDressupFeature (cmd, which, base, SubNames);
}
//===========================================================================
@ -1606,15 +1639,10 @@ CmdPartDesignDraft::CmdPartDesignDraft()
void CmdPartDesignDraft::activated(int iMsg)
{
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true);
if (!pcActiveBody) return;
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."));
Gui::SelectionObject selected;
if (!dressupGetSelected ( this, "Draft", selected))
return;
<<<<<<< 666dffc868c42171b4541f1d102c319db06415a8
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
@ -1630,8 +1658,13 @@ void CmdPartDesignDraft::activated(int iMsg)
QObject::tr("Only the current Tip of the active Body can be selected as the base feature"));
return;
}
=======
>>>>>>> PartDesignGui: move shared code for all dressUp features into common place.
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selected.getSubNames());
const Part::TopoShape& TopShape = base->Shape.getShape();
<<<<<<< 666dffc868c42171b4541f1d102c319db06415a8
if (TopShape._Shape.IsNull()){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Shape of selected Part is empty."));
@ -1640,7 +1673,11 @@ void CmdPartDesignDraft::activated(int iMsg)
std::vector<std::string> SubNames = std::vector<std::string>(selection[0].getSubNames());
unsigned int i = 0;
=======
size_t i = 0;
>>>>>>> PartDesignGui: move shared code for all dressUp features into common place.
// filter out the edges
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
@ -1659,6 +1696,7 @@ void CmdPartDesignDraft::activated(int iMsg)
i++;
}
<<<<<<< 666dffc868c42171b4541f1d102c319db06415a8
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No draft possible on selected faces."));
@ -1693,6 +1731,9 @@ void CmdPartDesignDraft::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Angle = %f",FeatName.c_str(), 1.5);
finishFeature(this, FeatName);
=======
finishDressupFeature (this, "Draft", base, SubNames);
>>>>>>> PartDesignGui: move shared code for all dressUp features into common place.
}
bool CmdPartDesignDraft::isActive(void)
@ -1720,41 +1761,15 @@ CmdPartDesignThickness::CmdPartDesignThickness()
void CmdPartDesignThickness::activated(int iMsg)
{
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true);
if (!pcActiveBody) return;
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."));
Gui::SelectionObject selected;
if (!dressupGetSelected ( this, "Thickness", selected))
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Thickness works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
if (base != pcActiveBody->getPrevSolidFeature(NULL, true)) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong base feature"),
QObject::tr("Only the current Tip of the active Body can be selected as the base feature"));
return;
}
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());
unsigned int i = 0;
Part::Feature *base = static_cast<Part::Feature*>(selected.getObject());
std::vector<std::string> SubNames = std::vector<std::string>(selected.getSubNames());
size_t i = 0;
// filter out the edges
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
@ -1766,35 +1781,7 @@ void CmdPartDesignThickness::activated(int iMsg)
i++;
}
if (SubNames.size() == 0) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No thickness possible with 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("Thickness");
openCommand("Make Thickness");
doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Thickness\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
doCommand(Doc,"App.activeDocument().%s.Value = %f",FeatName.c_str(), 1.);
finishFeature(this, FeatName);
finishDressupFeature (this, "Thickness", base, SubNames);
}
bool CmdPartDesignThickness::isActive(void)