PartDesign changes

* Mostly for supporting in-place editing

* Add new SubShapeBinder that support cross coordinate system,
  external, and sub-object binding
This commit is contained in:
Zheng, Lei
2019-07-13 18:13:21 +08:00
committed by wmayer
parent 11321bb996
commit cd2b7e297c
55 changed files with 1944 additions and 755 deletions

View File

@@ -265,18 +265,16 @@ void CmdPartDesignBody::activated(int iMsg)
};
// Called by dialog when user hits "OK" and accepter returns true
std::string FeatName = baseFeature->getNameInDocument();
auto worker = [FeatName](const std::vector<App::DocumentObject*>& features) {
auto worker = [baseFeature](const std::vector<App::DocumentObject*>& features) {
// may happen when the user switched to an empty document while the
// dialog is open
if (features.empty())
return;
App::Plane* plane = static_cast<App::Plane*>(features.front());
std::string supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() +
", [''])";
std::string supportString = Gui::Command::getObjectCmd(plane,"(",", [''])");
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());
FCMD_OBJ_CMD(baseFeature,"Support = " << supportString);
FCMD_OBJ_CMD(baseFeature,"MapMode = '" << Attacher::AttachEngine::getModeName(Attacher::mmFlatFace) << "'");
Gui::Command::updateActive();
};
@@ -602,13 +600,12 @@ void CmdPartDesignMoveTip::activated(int iMsg)
openCommand("Move tip to selected feature");
if (selFeature == body) {
doCommand(Doc,"App.activeDocument().%s.Tip = None", body->getNameInDocument());
FCMD_OBJ_CMD(body,"Tip = None");
} else {
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",body->getNameInDocument(),
selFeature->getNameInDocument());
FCMD_OBJ_CMD(body,"Tip = " << getObjectCmd(selFeature));
// Adjust visibility to show only the Tip feature
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", selFeature->getNameInDocument());
FCMD_OBJ_SHOW(selFeature);
}
// TODO: Hide all datum features after the Tip feature? But the user might have already hidden some and wants to see
@@ -659,14 +656,13 @@ void CmdPartDesignDuplicateSelection::activated(int iMsg)
for (auto feature : newFeatures) {
if (PartDesign::Body::isAllowed(feature)) {
doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",
pcActiveBody->getNameInDocument(), feature->getNameInDocument());
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", feature->getNameInDocument());
FCMD_OBJ_CMD(pcActiveBody,"addObject(" << getObjectCmd(feature) << ")");
FCMD_OBJ_HIDE(feature);
}
}
// Adjust visibility of features
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", newFeatures.back()->getNameInDocument());
FCMD_OBJ_SHOW(newFeatures.back());
}
updateActive();
@@ -766,17 +762,16 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
openCommand("Move an object");
std::stringstream stream;
stream << "features_ = [App.ActiveDocument." << features.back()->getNameInDocument();
stream << "features_ = [" << getObjectCmd(features.back());
features.pop_back();
for (auto feat: features)
stream << ", App.ActiveDocument." << feat->getNameInDocument();
stream << ", " << getObjectCmd(feat);
stream << "]";
doCommand(Doc, stream.str().c_str());
if (source_body)
doCommand(Doc, "App.ActiveDocument.%s.removeObjects(features_)", source_body->getNameInDocument());
doCommand(Doc, "App.ActiveDocument.%s.addObjects(features_)", target->getNameInDocument());
runCommand(Doc, stream.str().c_str());
FCMD_OBJ_CMD(source_body,"removeObjects(features_)");
FCMD_OBJ_CMD(target,"addObjects(features_)");
/*
// Find body of this feature
@@ -919,26 +914,55 @@ void CmdPartDesignMoveFeatureInTree::activated(int iMsg)
for ( auto feat: features ) {
if ( feat == target ) continue;
std::string targetStr;
if (target) {
targetStr.append("App.activeDocument().").append(target->getNameInDocument());
} else {
targetStr = "None";
}
// Remove and re-insert the feature to/from the Body
// TODO: if tip was moved the new position of tip is quite undetermined (2015-08-07, Fat-Zer)
// TODO: warn the user if we are moving an object to some place before the object's link (2015-08-07, Fat-Zer)
doCommand ( Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)",
body->getNameInDocument(), feat->getNameInDocument() );
doCommand ( Doc, "App.activeDocument().%s.insertObject(App.activeDocument().%s, %s, True)",
body->getNameInDocument(), feat->getNameInDocument(), targetStr.c_str () );
FCMD_OBJ_CMD(body,"removeObject(" << getObjectCmd(feat) << ")");
FCMD_OBJ_CMD(body,"insertObject(" << getObjectCmd(feat) << ","<< getObjectCmd(target) << ", True)");
if (!lastObject)
lastObject = feat;
}
updateActive();
// Dependency order check.
// We must make sure the resulting objects of PartDesign::Feature do not
// depend on later objects
std::vector<App::DocumentObject*> bodyFeatures;
std::map<App::DocumentObject*,size_t> orders;
for(auto obj : body->Group.getValues()) {
if(obj->isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
orders.emplace(obj,bodyFeatures.size());
bodyFeatures.push_back(obj);
}
}
bool failed = false;
std::ostringstream ss;
for(size_t i=0;i<bodyFeatures.size();++i) {
auto feat = bodyFeatures[i];
for(auto obj : feat->getOutList()) {
if(obj->isDerivedFrom(PartDesign::Feature::getClassTypeId()))
continue;
for(auto dep : App::Document::getDependencyList({obj})) {
auto it = orders.find(dep);
if(it != orders.end() && it->second > i) {
ss << feat->Label.getValue() << ", " <<
obj->Label.getValue() << " -> " <<
it->first->Label.getValue();
if(!failed)
failed = true;
else
ss << std::endl;
}
}
}
}
if(failed) {
QMessageBox::critical (0, QObject::tr( "Dependency violation" ),
QObject::tr( "Early feature must not depend on later feature.\n\n")
+ QString::fromUtf8(ss.str().c_str()));
abortCommand();
return;
}
// If the selected objects have been moved after the current tip then ask the
// user if he wants the last object to be the new tip.
@@ -951,19 +975,11 @@ void CmdPartDesignMoveFeatureInTree::activated(int iMsg)
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes) {
openCommand("Move tip to selected feature");
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",
body->getNameInDocument(),
lastObject->getNameInDocument());
// Adjust visibility to show only the Tip feature
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", lastObject->getNameInDocument());
updateActive();
}
if (ret == QMessageBox::Yes)
FCMD_OBJ_CMD(body,"Tip = " << getObjectCmd(lastObject));
}
updateActive();
}
bool CmdPartDesignMoveFeatureInTree::isActive(void)