From d796ca2bf9c35ed36e02c0eac1869c09143629d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sun, 31 May 2015 15:32:29 +0200 Subject: [PATCH] better pipe view handling --- src/Gui/Command.h | 7 +- src/Mod/PartDesign/Gui/Command.cpp | 26 ++------ src/Mod/PartDesign/Gui/TaskPipeParameters.cpp | 66 +++++++++++++++++-- src/Mod/PartDesign/Gui/TaskPipeParameters.h | 4 ++ src/Mod/PartDesign/Gui/ViewProviderPipe.cpp | 47 +++++++++++++ src/Mod/PartDesign/Gui/ViewProviderPipe.h | 7 +- 6 files changed, 125 insertions(+), 32 deletions(-) diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 9907ecda9..4a5b88896 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -166,7 +166,6 @@ protected: /// Applies the menu text, tool and status tip to the passed action object void applyCommandData(const char* context, Action* ); const char* keySequenceToAccel(int) const; - void adjustCameraPosition(); //@} public: @@ -286,6 +285,12 @@ public: const char* getGroupName() const { return sGroup; } void setGroupName(const char*); //@} + + + /** @name arbitrary helper methods */ + //@{ + void adjustCameraPosition(); + //@} protected: enum CmdType { diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 0dec6e0ac..7f257cbbf 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -938,7 +938,7 @@ void finishFeature(const Gui::Command* cmd, const std::string& FeatName, const b cmd->doCommand(cmd->Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)", pcActiveBody->getNameInDocument(), FeatName.c_str()); - if (cmd->isActiveObjectValid() && (pcActiveBody != NULL)) { + if (pcActiveBody != NULL) { App::DocumentObject* prevSolidFeature = pcActiveBody->getPrevSolidFeature(NULL, false); if (hidePrevSolid && (prevSolidFeature != NULL)) cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument()); @@ -1108,9 +1108,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, void finishSketchBased(const Gui::Command* cmd, const Part::Part2DObject* sketch, const std::string& FeatName) { - if (cmd->isActiveObjectValid()) - cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument()); - + cmd->doCommand(cmd->Gui,"Gui.activeDocument().hide(\"%s\")", sketch->getNameInDocument()); finishFeature(cmd, FeatName); } @@ -1308,15 +1306,7 @@ void CmdPartDesignAdditivePipe::activated(int iMsg) if (FeatName.empty()) return; - // specific parameters for Pad - //Gui::Command::doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str()); - App::DocumentObjectGroup* grp = sketch->getGroup(); - if (grp) { - Gui::Command::doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - Gui::Command::doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),sketch->getNameInDocument()); - } + // specific parameters for pipe Gui::Command::updateActive(); finishSketchBased(cmd, sketch, FeatName); @@ -1356,15 +1346,7 @@ void CmdPartDesignSubtractivePipe::activated(int iMsg) if (FeatName.empty()) return; - // specific parameters for Pad - //Gui::Command::doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str()); - App::DocumentObjectGroup* grp = sketch->getGroup(); - if (grp) { - Gui::Command::doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),FeatName.c_str()); - Gui::Command::doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)" - ,grp->getNameInDocument(),sketch->getNameInDocument()); - } + // specific parameters for pipe Gui::Command::updateActive(); finishSketchBased(cmd, sketch, FeatName); diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 068dc5347..2e40b95b3 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -84,9 +84,21 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView,bool newObj, Q this, SLOT(onBaseButton(bool))); this->groupLayout()->addWidget(proxy); - - //add initial values + PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + + //make sure th euser sees al important things: the base feature to select edges and the + //spine/auxillery spine he already selected + if(pipe->BaseFeature.getValue()) + doc->getViewProvider(pipe->BaseFeature.getValue())->show(); + if(pipe->Spine.getValue()) { + auto* svp = doc->getViewProvider(pipe->Spine.getValue()); + spineShow = svp->isShow(); + svp->setVisible(true); + } + + //add initial values std::vector strings = pipe->Spine.getSubValues(); for (std::vector::const_iterator i = strings.begin(); i != strings.end(); i++) ui->listWidgetReferences->addItem(QString::fromStdString(*i)); @@ -127,7 +139,8 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->listWidgetReferences->clear(); ui->profileBaseEdit->setText(QString::fromAscii(msg.pObjectName)); } - //clearButtons(none); + clearButtons(); + static_cast(vp)->highlightReferences(false, false); recomputeFeature(); } clearButtons(); @@ -137,6 +150,20 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) TaskPipeParameters::~TaskPipeParameters() { + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + + //make sure th euser sees al important things: the base feature to select edges and the + //spine/auxillery spine he already selected + if(pipe->BaseFeature.getValue()) + doc->getViewProvider(pipe->BaseFeature.getValue())->hide(); + if(pipe->Spine.getValue()) { + auto* svp = doc->getViewProvider(pipe->Spine.getValue()); + svp->setVisible(spineShow); + spineShow = false; + } + static_cast(vp)->highlightReferences(false, false); + delete ui; } @@ -153,7 +180,7 @@ void TaskPipeParameters::onButtonRefAdd(bool checked) { //hideObject(); Gui::Selection().clearSelection(); selectionMode = refAdd; - //DressUpView->highlightReferences(true); + static_cast(vp)->highlightReferences(true, false); } } @@ -164,7 +191,7 @@ void TaskPipeParameters::onButtonRefRemove(bool checked) { //hideObject(); Gui::Selection().clearSelection(); selectionMode = refRemove; - //DressUpView->highlightReferences(true); + static_cast(vp)->highlightReferences(true, false); } } @@ -291,9 +318,19 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool newObj this, SLOT(onBinormalChanged(double))); this->groupLayout()->addWidget(proxy); + + PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + + //make sure th euser sees al important things: the base feature to select edges and the + //spine/auxillery spine he already selected + if(pipe->AuxillerySpine.getValue()) { + auto* svp = doc->getViewProvider(pipe->AuxillerySpine.getValue()); + auxSpineShow = svp->isShow(); + svp->show(); + } //add initial values - PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); std::vector strings = pipe->AuxillerySpine.getSubValues(); for (std::vector::const_iterator i = strings.begin(); i != strings.end(); i++) ui->listWidgetReferences->addItem(QString::fromStdString(*i)); @@ -307,6 +344,18 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool newObj TaskPipeOrientation::~TaskPipeOrientation() { + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + + //make sure th euser sees al important things: the base feature to select edges and the + //spine/auxillery spine he already selected + if(pipe->AuxillerySpine.getValue()) { + auto* svp = doc->getViewProvider(pipe->AuxillerySpine.getValue()); + svp->setVisible(auxSpineShow); + auxSpineShow = false; + } + + static_cast(vp)->highlightReferences(false, true); } void TaskPipeOrientation::onOrientationChanged(int idx) { @@ -328,6 +377,7 @@ void TaskPipeOrientation::onButtonRefAdd(bool checked) { if (checked) { Gui::Selection().clearSelection(); selectionMode = refAdd; + static_cast(vp)->highlightReferences(true, true); } } @@ -336,6 +386,7 @@ void TaskPipeOrientation::onButtonRefRemove(bool checked) { if (checked) { Gui::Selection().clearSelection(); selectionMode = refRemove; + static_cast(vp)->highlightReferences(true, true); } } @@ -394,7 +445,8 @@ void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) { ui->listWidgetReferences->clear(); ui->profileBaseEdit->setText(QString::fromAscii(msg.pObjectName)); } - //clearButtons(none); + clearButtons(); + static_cast(vp)->highlightReferences(false, true); recomputeFeature(); } clearButtons(); diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.h b/src/Mod/PartDesign/Gui/TaskPipeParameters.h index 09b6d8ec9..b4eec5da6 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.h @@ -78,6 +78,8 @@ private: void clearButtons(); void exitSelectionMode(); + bool spineShow = false; + private: QWidget* proxy; Ui_TaskPipeParameters* ui; @@ -113,6 +115,8 @@ private: void onSelectionChanged(const Gui::SelectionChanges& msg); void clearButtons(); void exitSelectionMode(); + + bool auxSpineShow = false; private: QWidget* proxy; diff --git a/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp b/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp index 038737c2e..9b2004d31 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp @@ -37,6 +37,8 @@ #include #include #include +#include +#include using namespace PartDesignGui; @@ -142,3 +144,48 @@ bool ViewProviderPipe::onDelete(const std::vector &s) return ViewProvider::onDelete(s);*/ } + + +void ViewProviderPipe::highlightReferences(const bool on, bool auxillery) +{ + PartDesign::Pipe* pcPipe = static_cast(getObject()); + Part::Feature* base; + if(!auxillery) + base = static_cast(pcPipe->Spine.getValue()); + else + base = static_cast(pcPipe->AuxillerySpine.getValue()); + + if (base == NULL) return; + PartGui::ViewProviderPart* svp = dynamic_cast( + Gui::Application::Instance->getViewProvider(base)); + if (svp == NULL) return; + + std::vector edges; + if(!auxillery) + edges = pcPipe->Spine.getSubValuesStartsWith("Edge"); + else + edges = pcPipe->AuxillerySpine.getSubValuesStartsWith("Edge"); + + if (on) { + if (!edges.empty() && originalLineColors.empty()) { + TopTools_IndexedMapOfShape eMap; + TopExp::MapShapes(base->Shape.getValue(), TopAbs_EDGE, eMap); + originalLineColors = svp->LineColorArray.getValues(); + std::vector colors = originalLineColors; + colors.resize(eMap.Extent(), LineColor.getValue()); + + for (std::string e : edges) { + int idx = atoi(e.substr(4).c_str()) - 1; + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta + } + svp->LineColorArray.setValues(colors); + } + } else { + if (!edges.empty() && !originalLineColors.empty()) { + svp->LineColorArray.setValues(originalLineColors); + originalLineColors.clear(); + } + } +} + diff --git a/src/Mod/PartDesign/Gui/ViewProviderPipe.h b/src/Mod/PartDesign/Gui/ViewProviderPipe.h index 3cf57623f..8608ccae1 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPipe.h +++ b/src/Mod/PartDesign/Gui/ViewProviderPipe.h @@ -44,11 +44,14 @@ public: bool doubleClicked(); virtual bool onDelete(const std::vector &); - + void highlightReferences(const bool on, bool auxillery); + protected: virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); - + +private: + std::vector originalLineColors; };