fixes #0004188: Editing a subtractive box in PartDesign doesn't show the shaded box
This commit is contained in:
@@ -108,10 +108,12 @@ void TaskAttacher::makeRefStrings(std::vector<QString>& refstrings, std::vector<
|
||||
}
|
||||
}
|
||||
|
||||
TaskAttacher::TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider,QWidget *parent, QString picture, QString text)
|
||||
TaskAttacher::TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider, QWidget *parent,
|
||||
QString picture, QString text)
|
||||
: TaskBox(Gui::BitmapFactory().pixmap(picture.toLatin1()), text, true, parent),
|
||||
SelectionObserver(ViewProvider),
|
||||
ViewProvider(ViewProvider)
|
||||
ViewProvider(ViewProvider),
|
||||
visibilityFunc(0)
|
||||
{
|
||||
//check if we are attachable
|
||||
if (!ViewProvider->getObject()->hasExtension(Part::AttachExtension::getExtensionClassTypeId()))
|
||||
@@ -935,25 +937,11 @@ void TaskAttacher::changeEvent(QEvent *e)
|
||||
|
||||
void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
{
|
||||
if (opening_not_closing) {
|
||||
//crash guards
|
||||
if (!ViewProvider)
|
||||
return;
|
||||
if (!ViewProvider->getObject())
|
||||
return;
|
||||
if (!ViewProvider->getObject()->getNameInDocument())
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
try{
|
||||
auto defvisfunc = [] (bool opening_not_closing,
|
||||
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"
|
||||
@@ -970,11 +958,39 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
"\t\t\ttv.show([lnk[0] for lnk in tvObj.Support])\n"
|
||||
"del(tvObj)"
|
||||
).arg(
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(ViewProvider->getObject()).c_str()),
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(vp->getObject()).c_str()),
|
||||
QString::fromLatin1(Gui::Command::getObjectCmd(editObj).c_str()),
|
||||
QString::fromLatin1(editSubName.c_str()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
}
|
||||
else {
|
||||
Base::Interpreter().runString("del(tv)");
|
||||
}
|
||||
};
|
||||
|
||||
auto visAutoFunc = visibilityFunc ? visibilityFunc : defvisfunc;
|
||||
|
||||
if (opening_not_closing) {
|
||||
//crash guards
|
||||
if (!ViewProvider)
|
||||
return;
|
||||
if (!ViewProvider->getObject())
|
||||
return;
|
||||
if (!ViewProvider->getObject()->getNameInDocument())
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
try {
|
||||
visAutoFunc(opening_not_closing, ViewProvider, editObj, editSubName);
|
||||
}
|
||||
catch (const Base::Exception &e){
|
||||
e.ReportException();
|
||||
}
|
||||
@@ -985,7 +1001,7 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing)
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Base::Interpreter().runString("del(tv)");
|
||||
visAutoFunc(opening_not_closing, nullptr, nullptr, std::string());
|
||||
}
|
||||
catch (Base::Exception &e) {
|
||||
e.ReportException();
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Mod/Part/App/Attacher.h>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
|
||||
class Ui_TaskAttacher;
|
||||
@@ -52,8 +53,11 @@ class PartGuiExport TaskAttacher : public Gui::TaskView::TaskBox, public Gui::Se
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider,QWidget *parent = 0,
|
||||
QString picture = QString::fromLatin1(""), QString text = QString::fromLatin1("Attachment"));
|
||||
typedef boost::function<void (bool, Gui::ViewProviderDocumentObject*, App::DocumentObject *, const std::string&)> VisibilityFunction;
|
||||
|
||||
TaskAttacher(Gui::ViewProviderDocumentObject *ViewProvider, QWidget *parent = 0,
|
||||
QString picture = QString(),
|
||||
QString text = QString::fromLatin1("Attachment"));
|
||||
~TaskAttacher();
|
||||
|
||||
bool getFlip(void) const;
|
||||
@@ -65,6 +69,15 @@ public:
|
||||
*/
|
||||
Attacher::eMapMode getActiveMapMode();
|
||||
|
||||
/**
|
||||
* @brief setCustomVisibilityAutomation sets a customized function
|
||||
* in order to allow to handle visibility automation differently than
|
||||
* the default implementation.
|
||||
*/
|
||||
void setCustomVisibilityAutomation(VisibilityFunction func) {
|
||||
visibilityFunc = func;
|
||||
}
|
||||
|
||||
bool isCompleted() const { return completed; }
|
||||
|
||||
private Q_SLOTS:
|
||||
@@ -125,6 +138,7 @@ protected:
|
||||
private:
|
||||
QWidget* proxy;
|
||||
Ui_TaskAttacher* ui;
|
||||
VisibilityFunction visibilityFunc;
|
||||
|
||||
// TODO fix documentation here (2015-11-10, Fat-Zer)
|
||||
int iActiveRef; //what reference is being picked in 3d view now? -1 means no one, 0-3 means a reference is being picked.
|
||||
|
||||
@@ -661,7 +661,37 @@ TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* Primitiv
|
||||
primitive = new TaskBoxPrimitives(PrimitiveView);
|
||||
Content.push_back(primitive);
|
||||
|
||||
parameter = new PartGui::TaskAttacher(PrimitiveView);
|
||||
// handle visibility automation differently to the default method
|
||||
auto customvisfunc = [] (bool opening_not_closing,
|
||||
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"
|
||||
"tvObj = %1\n"
|
||||
"dep_features = tv.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"
|
||||
"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()));
|
||||
Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData());
|
||||
}
|
||||
else {
|
||||
Base::Interpreter().runString("del(tv)");
|
||||
}
|
||||
};
|
||||
|
||||
parameter = new PartGui::TaskAttacher(PrimitiveView);
|
||||
parameter->setCustomVisibilityAutomation(customvisfunc);
|
||||
Content.push_back(parameter);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user