Part: fix TaskAttacher::visibilityAutomation()
Rename Python variable 'tv' to avoid potential conflict with others (PS. I can't reproduce error caused by this. But there is no harm doing it either). Handle editing attachment through an App::Link.
This commit is contained in:
@@ -937,33 +937,38 @@ void TaskAttacher::changeEvent(QEvent *e)
|
||||
void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
{
|
||||
auto defvisfunc = [] (bool opening_not_closing,
|
||||
const std::string &postfix,
|
||||
Gui::ViewProviderDocumentObject* vp,
|
||||
App::DocumentObject *editObj,
|
||||
const std::string& editSubName) {
|
||||
if (opening_not_closing) {
|
||||
QString code = QString::fromLatin1(
|
||||
"import Show\n"
|
||||
"tv = Show.TempoVis(App.ActiveDocument, tag= 'PartGui::TaskAttacher')\n"
|
||||
"_tv_%4 = Show.TempoVis(App.ActiveDocument, tag= 'PartGui::TaskAttacher')\n"
|
||||
"tvObj = %1\n"
|
||||
"dep_features = tv.get_all_dependent(%2, '%3')\n"
|
||||
"dep_features = _tv_%4.get_all_dependent(%2, '%3')\n"
|
||||
"if tvObj.isDerivedFrom('PartDesign::CoordinateSystem'):\n"
|
||||
"\tvisible_features = [feat for feat in tvObj.InList if feat.isDerivedFrom('PartDesign::FeaturePrimitive')]\n"
|
||||
"\tdep_features = [feat for feat in dep_features if feat not in visible_features]\n"
|
||||
"\tdel(visible_features)\n"
|
||||
"tv.hide(dep_features)\n"
|
||||
"_tv_%4.hide(dep_features)\n"
|
||||
"del(dep_features)\n"
|
||||
"if not tvObj.isDerivedFrom('PartDesign::CoordinateSystem'):\n"
|
||||
"\t\tif len(tvObj.Support) > 0:\n"
|
||||
"\t\t\ttv.show([lnk[0] for lnk in tvObj.Support])\n"
|
||||
"\t\t\t_tv_%4.show([lnk[0] for lnk in tvObj.Support])\n"
|
||||
"del(tvObj)"
|
||||
).arg(
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(vp->getObject()).c_str()),
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()),
|
||||
QString::fromLatin1(editSubName.c_str()));
|
||||
QString::fromLatin1(editSubName.c_str()),
|
||||
QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
} else if(postfix.size()) {
|
||||
QString code = QString::fromLatin1(
|
||||
"_tv_%1.restore()\n"
|
||||
"del(_tv_%1)"
|
||||
).arg(QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
}
|
||||
else {
|
||||
Base::Interpreter().runString("del(tv)");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -981,14 +986,23 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
auto editDoc = Gui::Application::Instance->editDocument();
|
||||
App::DocumentObject *editObj = ViewProvider->getObject();
|
||||
std::string editSubName;
|
||||
ViewProviderDocumentObject *editVp = 0;
|
||||
if (editDoc) {
|
||||
editDoc->getInEdit(&editVp,&editSubName);
|
||||
if (editVp)
|
||||
editObj = editVp->getObject();
|
||||
auto sels = Gui::Selection().getSelection(0,0,true);
|
||||
if(sels.size() && sels[0].pResolvedObject
|
||||
&& sels[0].pResolvedObject->getLinkedObject()==editObj)
|
||||
{
|
||||
editObj = sels[0].pObject;
|
||||
editSubName = sels[0].SubName;
|
||||
} else {
|
||||
ViewProviderDocumentObject *editVp = 0;
|
||||
if (editDoc) {
|
||||
editDoc->getInEdit(&editVp,&editSubName);
|
||||
if (editVp)
|
||||
editObj = editVp->getObject();
|
||||
}
|
||||
}
|
||||
ObjectName = ViewProvider->getObject()->getNameInDocument();
|
||||
try {
|
||||
visAutoFunc(opening_not_closing, ViewProvider, editObj, editSubName);
|
||||
visAutoFunc(opening_not_closing, ObjectName, ViewProvider, editObj, editSubName);
|
||||
}
|
||||
catch (const Base::Exception &e){
|
||||
e.ReportException();
|
||||
@@ -1000,7 +1014,9 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
}
|
||||
else {
|
||||
try {
|
||||
visAutoFunc(opening_not_closing, nullptr, nullptr, std::string());
|
||||
std::string objName;
|
||||
objName.swap(ObjectName);
|
||||
visAutoFunc(opening_not_closing, objName, nullptr, nullptr, std::string());
|
||||
}
|
||||
catch (Base::Exception &e) {
|
||||
e.ReportException();
|
||||
|
||||
@@ -53,7 +53,8 @@ class PartGuiExport TaskAttacher : public Gui::TaskView::TaskBox, public Gui::Se
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef boost::function<void (bool, Gui::ViewProviderDocumentObject*, App::DocumentObject *, const std::string&)> VisibilityFunction;
|
||||
typedef boost::function<void (bool, const std::string &, Gui::ViewProviderDocumentObject*,
|
||||
App::DocumentObject *, const std::string&)> VisibilityFunction;
|
||||
|
||||
TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider, QWidget *parent = 0,
|
||||
QString picture = QString(),
|
||||
@@ -125,6 +126,7 @@ private:
|
||||
|
||||
protected:
|
||||
Gui::ViewProviderDocumentObject *ViewProvider;
|
||||
std::string ObjectName;
|
||||
|
||||
private:
|
||||
QWidget* proxy;
|
||||
|
||||
@@ -748,33 +748,37 @@ TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* Primitiv
|
||||
|
||||
// handle visibility automation differently to the default method
|
||||
auto customvisfunc = [] (bool opening_not_closing,
|
||||
const std::string &postfix,
|
||||
Gui::ViewProviderDocumentObject* vp,
|
||||
App::DocumentObject *editObj,
|
||||
const std::string& editSubName) {
|
||||
if (opening_not_closing) {
|
||||
QString code = QString::fromLatin1(
|
||||
"import Show\n"
|
||||
"tv = Show.TempoVis(App.ActiveDocument, tag= 'PartGui::TaskAttacher')\n"
|
||||
"_tv_%4 = Show.TempoVis(App.ActiveDocument, tag= 'PartGui::TaskAttacher')\n"
|
||||
"tvObj = %1\n"
|
||||
"dep_features = tv.get_all_dependent(%2, '%3')\n"
|
||||
"dep_features = _tv_%4.get_all_dependent(%2, '%3')\n"
|
||||
"if tvObj.isDerivedFrom('PartDesign::CoordinateSystem'):\n"
|
||||
"\tvisible_features = [feat for feat in tvObj.InList if feat.isDerivedFrom('PartDesign::FeaturePrimitive')]\n"
|
||||
"\tdep_features = [feat for feat in dep_features if feat not in visible_features]\n"
|
||||
"\tdel(visible_features)\n"
|
||||
"tv.hide(dep_features)\n"
|
||||
"_tv_%4.hide(dep_features)\n"
|
||||
"del(dep_features)\n"
|
||||
"del(tvObj)"
|
||||
).arg(
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(vp->getObject()).c_str()),
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()),
|
||||
QString::fromLatin1(editSubName.c_str()));
|
||||
QString::fromLatin1(editSubName.c_str()),
|
||||
QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
} else if(postfix.size()) {
|
||||
QString code = QString::fromLatin1(
|
||||
"_tv_%1.restore()\n"
|
||||
"del(_tv_%1)"
|
||||
).arg(QString::fromLatin1(postfix.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
}
|
||||
else {
|
||||
Base::Interpreter().runString("del(tv)");
|
||||
}
|
||||
};
|
||||
|
||||
parameter = new PartGui::TaskAttacher(PrimitiveView, nullptr, QString(), tr("Attachment"), customvisfunc);
|
||||
Content.push_back(parameter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user