Skip to content

Commit

Permalink
fixes #4188: Editing a subtractive box in PartDesign doesn't show the…
Browse files Browse the repository at this point in the history
… shaded box
  • Loading branch information
wwmayer committed Jan 15, 2020
1 parent 5afd6a9 commit bff7369
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 26 deletions.
62 changes: 39 additions & 23 deletions src/Mod/Part/Gui/TaskAttacher.cpp
Expand Up @@ -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()))
Expand Down Expand Up @@ -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"
Expand All @@ -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();
}
Expand All @@ -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();
Expand Down
18 changes: 16 additions & 2 deletions src/Mod/Part/Gui/TaskAttacher.h
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -65,6 +69,15 @@ class PartGuiExport TaskAttacher : public Gui::TaskView::TaskBox, public Gui::Se
*/
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:
Expand Down Expand Up @@ -125,6 +138,7 @@ private Q_SLOTS:
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.
Expand Down
32 changes: 31 additions & 1 deletion src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp
Expand Up @@ -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);
}

Expand Down

0 comments on commit bff7369

Please sign in to comment.