PartDesign: Prevent problems with link scopes during feature creation

This commit is contained in:
Stefan Tröger
2017-08-06 10:00:56 +02:00
committed by wmayer
parent 0584c56777
commit 034219771f
4 changed files with 457 additions and 53 deletions

View File

@@ -111,7 +111,8 @@ void UnifiedDatumCommand(Gui::Command &cmd, Base::Type type, std::string name)
std::string tmp = std::string("Create ")+name;
cmd.openCommand(tmp.c_str());
cmd.doCommand(Gui::Command::Doc,"App.activeDocument().addObject('%s','%s')",fullTypeName.c_str(),FeatName.c_str());
cmd.doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject('%s','%s')", pcActiveBody->getNameInDocument(),
fullTypeName.c_str(),FeatName.c_str());
//test if current selection fits a mode.
if (support.getSize() > 0) {
@@ -127,10 +128,6 @@ void UnifiedDatumCommand(Gui::Command &cmd, Base::Type type, std::string name)
QMessageBox::information(Gui::getMainWindow(),QObject::tr("Invalid selection"), QObject::tr("There are no attachment modes that fit selected objects. Select something else."));
}
}
if (pcActiveBody) {
cmd.doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str());
}
cmd.doCommand(Gui::Command::Doc,"App.activeDocument().recompute()"); // recompute the feature based on its references
cmd.doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
} else {
@@ -275,17 +272,15 @@ void CmdPartDesignShapeBinder::activated(int iMsg)
openCommand(tmp.c_str());
doCommand(Gui::Command::Doc,"App.activeDocument().addObject('%s','%s')",
"PartDesign::ShapeBinder",FeatName.c_str());
doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject('%s','%s')",
pcActiveBody->getNameInDocument(), "PartDesign::ShapeBinder",FeatName.c_str());
//test if current selection fits a mode.
if (support.getSize() > 0) {
doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",
FeatName.c_str(), support.getPyReprString().c_str());
}
doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str());
doCommand(Gui::Command::Doc,"App.activeDocument().recompute()"); // recompute the feature based on its references
updateActive();
doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
// TODO do a proper error processing (2015-09-11, Fat-Zer)
@@ -453,13 +448,10 @@ void CmdPartDesignNewSketch::activated(int iMsg)
std::string FeatName = getUniqueObjectName("Sketch");
openCommand("Create a Sketch on Face");
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.newObject('Sketcher::SketchObject','%s')",pcActiveBody->getNameInDocument(), FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
doCommand(Doc,"App.activeDocument().%s.MapMode = '%s'",FeatName.c_str(),Attacher::AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str());
doCommand(Gui,"App.activeDocument().recompute()"); // recompute the sketch placement based on its support
//doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str());
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
else {
@@ -567,13 +559,10 @@ void CmdPartDesignNewSketch::activated(int iMsg)
std::string supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() +
", [''])";
Gui::Command::doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
Gui::Command::doCommand(Doc,"App.activeDocument().%s.newObject('Sketcher::SketchObject','%s')", pcActiveBody->getNameInDocument(), FeatName.c_str());
Gui::Command::doCommand(Doc,"App.activeDocument().%s.Support = %s",FeatName.c_str(),supportString.c_str());
Gui::Command::doCommand(Doc,"App.activeDocument().%s.MapMode = '%s'",FeatName.c_str(),Attacher::AttachEngine::getModeName(Attacher::mmFlatFace).c_str());
Gui::Command::updateActive(); // Make sure the Support's Placement property is updated
Gui::Command::doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str());
//doCommand(Gui,"Gui.activeDocument().activeView().setCamera('%s')",cam.c_str());
Gui::Command::doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
};
@@ -645,21 +634,6 @@ void finishFeature(const Gui::Command* cmd, const std::string& FeatName,
pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */false);
}
if (pcActiveBody) {
App::DocumentObject* lastSolidFeature = pcActiveBody->Tip.getValue();
if (!prevSolidFeature || prevSolidFeature == lastSolidFeature) {
// If the previous feature not given or is the Tip add Feature after it.
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), FeatName.c_str());
prevSolidFeature = lastSolidFeature;
} else {
// Insert the feature into the body after the given one.
cmd->doCommand(cmd->Doc,
"App.activeDocument().%s.insertObject(App.activeDocument().%s, App.activeDocument().%s, True)",
pcActiveBody->getNameInDocument(), FeatName.c_str(), prevSolidFeature->getNameInDocument());
}
}
if (hidePrevSolid && prevSolidFeature && (prevSolidFeature != NULL))
cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument());
@@ -789,8 +763,8 @@ void prepareProfileBased(Gui::Command* cmd, const std::string& which,
std::string FeatName = cmd->getUniqueObjectName(which.c_str());
Gui::Command::openCommand((std::string("Make ") + which).c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::%s\",\"%s\")",
which.c_str(), FeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject(\"PartDesign::%s\",\"%s\")",
PartDesignGui::getBody(false)->getNameInDocument(), which.c_str(), FeatName.c_str());
if (feature->isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Profile = App.activeDocument().%s",
@@ -968,14 +942,6 @@ void CmdPartDesignPad::activated(int iMsg)
// specific parameters for Pad
Gui::Command::doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str());
App::DocumentObjectGroup* grp = profile->getGroup();
if (grp) {
Gui::Command::doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)"
,grp->getNameInDocument(),FeatName.c_str());
if(profile->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
Gui::Command::doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)"
,grp->getNameInDocument(), profile->getNameInDocument());
}
Gui::Command::updateActive();
Part::Part2DObject* sketch = dynamic_cast<Part::Part2DObject*>(profile);
@@ -1488,7 +1454,8 @@ void finishDressupFeature(const Gui::Command* cmd, const std::string& which,
std::string FeatName = cmd->getUniqueObjectName(which.c_str());
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.newObject(\"PartDesign::%s\",\"%s\")",
PartDesignGui::getBodyFor(base,false)->getNameInDocument(), which.c_str(), FeatName.c_str());
cmd->doCommand(cmd->Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
cmd->doCommand(cmd->Gui,"Gui.Selection.clearSelection()");
finishFeature(cmd, FeatName, base);
@@ -1695,7 +1662,8 @@ void prepareTransformed(Gui::Command* cmd, const std::string& which,
str << "]";
Gui::Command::openCommand((std::string("Make ") + which + " feature").c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::%s\",\"%s\")",which.c_str(), FeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject(\"PartDesign::%s\",\"%s\")",
PartDesignGui::getBody(false)->getNameInDocument(), which.c_str(), FeatName.c_str());
// FIXME: There seems to be kind of a race condition here, leading to sporadic errors like
// Exception (Thu Sep 6 11:52:01 2012): 'App.Document' object has no attribute 'Mirrored'
Gui::Command::updateActive(); // Helps to ensure that the object already exists when the next command comes up
@@ -2068,7 +2036,7 @@ void CmdPartDesignMultiTransform::activated(int iMsg)
// Create a MultiTransform feature and move the Transformed feature inside it
std::string FeatName = getUniqueObjectName("MultiTransform");
doCommand(Doc, "App.activeDocument().addObject(\"PartDesign::MultiTransform\",\"%s\")", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.newObject(\"PartDesign::MultiTransform\",\"%s\")", pcActiveBody->getNameInDocument(), FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Originals = App.activeDocument().%s.Originals", FeatName.c_str(), trFeat->getNameInDocument());
doCommand(Doc, "App.activeDocument().%s.Originals = []", trFeat->getNameInDocument());
doCommand(Doc, "App.activeDocument().%s.Transformations = [App.activeDocument().%s]", FeatName.c_str(), trFeat->getNameInDocument());
@@ -2140,7 +2108,7 @@ void CmdPartDesignBoolean::activated(int iMsg)
openCommand("Create Boolean");
std::string FeatName = getUniqueObjectName("Boolean");
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Boolean','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.newObject('PartDesign::Boolean','%s')", pcActiveBody->getNameInDocument(), FeatName.c_str());
if (BodyFilter.match() && !BodyFilter.Result.empty()) {
std::vector<App::DocumentObject*> bodies;

View File

@@ -33,6 +33,7 @@
#include "TaskLinearPatternParameters.h"
#include "TaskPolarPatternParameters.h"
#include "TaskScaledParameters.h"
#include "Utils.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
@@ -49,9 +50,9 @@
#include <Mod/PartDesign/App/FeatureLinearPattern.h>
#include <Mod/PartDesign/App/FeaturePolarPattern.h>
#include <Mod/PartDesign/App/FeatureScaled.h>
#include <Mod/PartDesign/App/Body.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
using namespace Gui;
@@ -258,7 +259,8 @@ void TaskMultiTransformParameters::onTransformAddMirrored()
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("Mirrored");
Gui::Command::openCommand("Mirrored");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Mirrored\",\"%s\")",newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject(\"PartDesign::Mirrored\",\"%s\")",
PartDesignGui::getBody(false)->getNameInDocument(), newFeatName.c_str());
//Gui::Command::updateActive();
App::DocumentObject* sketch = getSketchObject();
if (sketch)
@@ -274,7 +276,8 @@ void TaskMultiTransformParameters::onTransformAddLinearPattern()
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("LinearPattern");
Gui::Command::openCommand("LinearPattern");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject(\"PartDesign::LinearPattern\",\"%s\")",
PartDesignGui::getBody(false), newFeatName.c_str());
//Gui::Command::updateActive();
App::DocumentObject* sketch = getSketchObject();
if (sketch)
@@ -292,7 +295,8 @@ void TaskMultiTransformParameters::onTransformAddPolarPattern()
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("PolarPattern");
Gui::Command::openCommand("PolarPattern");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject(\"PartDesign::PolarPattern\",\"%s\")",
PartDesignGui::getBody(false)->getNameInDocument(), newFeatName.c_str());
//Gui::Command::updateActive();
App::DocumentObject* sketch = getSketchObject();
if (sketch)
@@ -310,7 +314,8 @@ void TaskMultiTransformParameters::onTransformAddScaled()
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("Scaled");
Gui::Command::openCommand("Scaled");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Scaled\",\"%s\")",newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.newObject(\"PartDesign::Scaled\",\"%s\")",
PartDesignGui::getBody(false)->getNameInDocument(), newFeatName.c_str());
//Gui::Command::updateActive();
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Factor = 2", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());