diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index 056581483..40025357b 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -251,14 +251,26 @@ void SoFCUnifiedSelection::doAction(SoAction *action) App::DocumentObject* obj = doc->getObject(selaction->SelChange.pObjectName); ViewProvider*vp = Application::Instance->getViewProvider(obj); if (vp && vp->useNewSelectionModel() && vp->isSelectable()) { + SoDetail* detail = vp->getDetail(selaction->SelChange.pSubName); SoSelectionElementAction::Type type = SoSelectionElementAction::None; - if (selaction->SelChange.Type == SelectionChanges::AddSelection) - type = SoSelectionElementAction::All; - else - type = SoSelectionElementAction::None; + if (selaction->SelChange.Type == SelectionChanges::AddSelection) { + if (detail) + type = SoSelectionElementAction::Append; + else + type = SoSelectionElementAction::All; + } + else { + if (detail) + type = SoSelectionElementAction::Remove; + else + type = SoSelectionElementAction::None; + } + SoSelectionElementAction action(type); action.setColor(this->colorSelection.getValue()); + action.setElement(detail); action.apply(vp->getRoot()); + delete detail; } } } @@ -335,7 +347,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action) if (vpd && vpd->useNewSelectionModel() && vpd->isSelectable()) { std::string documentName = vpd->getObject()->getDocument()->getName(); std::string objectName = vpd->getObject()->getNameInDocument(); - std::string subElementName = vpd->getElement(pp); + std::string subElementName = vpd->getElement(pp ? pp->getDetail() : 0); static char buf[513]; snprintf(buf,512,"Preselected: %s.%s.%s (%f,%f,%f)",documentName.c_str() @@ -378,7 +390,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action) SoHighlightElementAction action; action.setHighlighted(highlighted); action.setColor(this->colorHighlight.getValue()); - action.setElement(pp); + action.setElement(pp ? pp->getDetail() : 0); action.apply(currenthighlight); if (!highlighted) { currenthighlight->unref(); @@ -422,7 +434,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action) SoSelectionElementAction::Type type = SoSelectionElementAction::None; std::string documentName = vpd->getObject()->getDocument()->getName(); std::string objectName = vpd->getObject()->getNameInDocument(); - std::string subElementName = vpd->getElement(pp); + std::string subElementName = vpd->getElement(pp ? pp->getDetail() : 0); if (bCtrl) { if (Gui::Selection().isSelected(documentName.c_str() ,objectName.c_str() @@ -495,7 +507,7 @@ SoFCUnifiedSelection::handleEvent(SoHandleEventAction * action) if (currenthighlight) { SoSelectionElementAction action(type); action.setColor(this->colorSelection.getValue()); - action.setElement(pp); + action.setElement(pp ? pp->getDetail() : 0); action.apply(currenthighlight); this->touch(); } @@ -526,7 +538,7 @@ void SoHighlightElementAction::initClass() SO_ACTION_ADD_METHOD(SoPointSet,callDoAction); } -SoHighlightElementAction::SoHighlightElementAction () : _highlight(FALSE), _pp(0) +SoHighlightElementAction::SoHighlightElementAction () : _highlight(FALSE), _det(0) { SO_ACTION_CONSTRUCTOR(SoHighlightElementAction); } @@ -565,14 +577,14 @@ const SbColor& SoHighlightElementAction::getColor() const return this->_color; } -void SoHighlightElementAction::setElement(const SoPickedPoint* pp) +void SoHighlightElementAction::setElement(const SoDetail* det) { - this->_pp = pp; + this->_det = det; } -const SoPickedPoint* SoHighlightElementAction::getElement() const +const SoDetail* SoHighlightElementAction::getElement() const { - return this->_pp; + return this->_det; } // --------------------------------------------------------------- @@ -596,7 +608,7 @@ void SoSelectionElementAction::initClass() SO_ACTION_ADD_METHOD(SoPointSet,callDoAction); } -SoSelectionElementAction::SoSelectionElementAction (Type t) : _type(t), _select(FALSE), _pp(0) +SoSelectionElementAction::SoSelectionElementAction (Type t) : _type(t), _select(FALSE), _det(0) { SO_ACTION_CONSTRUCTOR(SoSelectionElementAction); } @@ -631,12 +643,12 @@ const SbColor& SoSelectionElementAction::getColor() const return this->_color; } -void SoSelectionElementAction::setElement(const SoPickedPoint* pp) +void SoSelectionElementAction::setElement(const SoDetail* det) { - this->_pp = pp; + this->_det = det; } -const SoPickedPoint* SoSelectionElementAction::getElement() const +const SoDetail* SoSelectionElementAction::getElement() const { - return this->_pp; + return this->_det; } diff --git a/src/Gui/SoFCUnifiedSelection.h b/src/Gui/SoFCUnifiedSelection.h index a5d9ccc4d..30216d668 100644 --- a/src/Gui/SoFCUnifiedSelection.h +++ b/src/Gui/SoFCUnifiedSelection.h @@ -43,6 +43,7 @@ class SoFullPath; class SoPickedPoint; +class SoDetail; namespace Gui { @@ -125,8 +126,8 @@ public: SbBool isHighlighted() const; void setColor(const SbColor&); const SbColor& getColor() const; - void setElement(const SoPickedPoint*); - const SoPickedPoint* getElement() const; + void setElement(const SoDetail*); + const SoDetail* getElement() const; static void initClass(); @@ -139,7 +140,7 @@ private: private: SbBool _highlight; SbColor _color; - const SoPickedPoint* _pp; + const SoDetail* _det; }; /** @@ -158,8 +159,8 @@ public: Type getType() const; void setColor(const SbColor&); const SbColor& getColor() const; - void setElement(const SoPickedPoint*); - const SoPickedPoint* getElement() const; + void setElement(const SoDetail*); + const SoDetail* getElement() const; static void initClass(); @@ -173,7 +174,7 @@ private: Type _type; SbBool _select; SbColor _color; - const SoPickedPoint* _pp; + const SoDetail* _det; }; diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 6fd035a13..391cc25bb 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -2055,7 +2055,7 @@ SoPath * View3DInventorViewer::pickFilterCB(void *viewer, const SoPickedPoint * { ViewProvider* vp = static_cast(viewer)->getViewProviderByPath(pp->getPath()); if (vp && vp->useNewSelectionModel()) { - std::string e = vp->getElement(pp); + std::string e = vp->getElement(pp->getDetail()); vp->getSelectionShape(e.c_str()); static char buf[513]; snprintf(buf,512,"Hovered: %s (%f,%f,%f)" diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index b45c05247..434b22574 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -944,7 +944,7 @@ Py::Object View3DInventorPy::getObjectInfo(const Py::Tuple& args) dict.setItem("Object", Py::String(vpd->getObject()->getNameInDocument())); dict.setItem("Component", - Py::String(vpd->getElement(Point))); + Py::String(vpd->getElement(Point->getDetail()))); // ok, found the node of interest ret = dict; } @@ -1017,7 +1017,7 @@ Py::Object View3DInventorPy::getObjectsInfo(const Py::Tuple& args) dict.setItem("Object", Py::String(vpd->getObject()->getNameInDocument())); dict.setItem("Component", - Py::String(vpd->getElement(point))); + Py::String(vpd->getElement(point->getDetail()))); // ok, found the node of interest list.append(dict); } diff --git a/src/Gui/ViewProvider.h b/src/Gui/ViewProvider.h index 4641c5886..7a22c7a89 100644 --- a/src/Gui/ViewProvider.h +++ b/src/Gui/ViewProvider.h @@ -40,6 +40,7 @@ class SoTransform; class SbMatrix; class SoEventCallback; class SoPickedPoint; +class SoDetail; class QString; class QMenu; class QObject; @@ -103,7 +104,8 @@ public: /// indicates if the ViewProvider can be selected virtual bool isSelectable(void) const {return true;} /// return a hit element to the selection path or 0 - virtual std::string getElement(const SoPickedPoint *) const { return std::string(); } + virtual std::string getElement(const SoDetail *) const { return std::string(); } + virtual SoDetail* getDetail(const char*) const { return 0; } /// return the higlight lines for a given element or the whole shape virtual std::vector getSelectionShape(const char* Element) const { return std::vector(); }; diff --git a/src/Gui/ViewProviderPythonFeature.cpp b/src/Gui/ViewProviderPythonFeature.cpp index b3fa7acc8..576d012ab 100644 --- a/src/Gui/ViewProviderPythonFeature.cpp +++ b/src/Gui/ViewProviderPythonFeature.cpp @@ -281,7 +281,7 @@ std::vector ViewProviderPythonFeatureImp::claimChildren() return children; } -std::string ViewProviderPythonFeatureImp::getElement(const SoPickedPoint *pp) const +std::string ViewProviderPythonFeatureImp::getElement(const SoDetail *det) const { return ""; } diff --git a/src/Gui/ViewProviderPythonFeature.h b/src/Gui/ViewProviderPythonFeature.h index 0bcea722a..693a6c448 100644 --- a/src/Gui/ViewProviderPythonFeature.h +++ b/src/Gui/ViewProviderPythonFeature.h @@ -48,7 +48,7 @@ public: // Returns the icon QIcon getIcon() const; std::vector claimChildren() const; - std::string getElement(const SoPickedPoint *pp) const; + std::string getElement(const SoDetail *det) const; std::vector getSelectionShape(const char* Element) const; bool setEdit(int ModNum); bool unsetEdit(int ModNum); @@ -125,8 +125,8 @@ public: virtual bool useNewSelectionModel() const { return ViewProviderT::useNewSelectionModel(); } - virtual std::string getElement(const SoPickedPoint *pp) const { - return ViewProviderT::getElement(pp); + virtual std::string getElement(const SoDetail *det) const { + return ViewProviderT::getElement(det); } virtual std::vector getSelectionShape(const char* Element) const { return ViewProviderT::getSelectionShape(Element); diff --git a/src/Mod/Part/Gui/SoBrepShape.cpp b/src/Mod/Part/Gui/SoBrepShape.cpp index a8bea7a7e..2b9fe5b2b 100644 --- a/src/Mod/Part/Gui/SoBrepShape.cpp +++ b/src/Mod/Part/Gui/SoBrepShape.cpp @@ -87,9 +87,8 @@ void SoBrepFaceSet::doAction(SoAction* action) return; } - const SoPickedPoint* pp = hlaction->getElement(); - if (pp && pp->getDetail()) { - const SoDetail* detail = pp->getDetail(); + const SoDetail* detail = hlaction->getElement(); + if (detail) { if (detail->isOfType(SoFaceDetail::getClassTypeId())) { int index = static_cast(detail)->getPartIndex(); this->highlightIndex.setValue(index); @@ -118,10 +117,8 @@ void SoBrepFaceSet::doAction(SoAction* action) return; } - const SoPickedPoint* pp = selaction->getElement(); - if (pp && pp->getDetail()) { - const SoDetail* detail = pp->getDetail(); - + const SoDetail* detail = selaction->getElement(); + if (detail) { if (!detail->isOfType(SoFaceDetail::getClassTypeId())) { return; } @@ -774,9 +771,8 @@ void SoBrepEdgeSet::doAction(SoAction* action) this->hl.clear(); return; } - const SoPickedPoint* pp = hlaction->getElement(); - if (pp && pp->getDetail()) { - const SoDetail* detail = pp->getDetail(); + const SoDetail* detail = hlaction->getElement(); + if (detail) { if (!detail->isOfType(SoLineDetail::getClassTypeId())) { this->highlightIndex = -1; this->hl.clear(); @@ -824,9 +820,8 @@ void SoBrepEdgeSet::doAction(SoAction* action) return; } - const SoPickedPoint* pp = selaction->getElement(); - if (pp && pp->getDetail()) { - const SoDetail* detail = pp->getDetail(); + const SoDetail* detail = selaction->getElement(); + if (detail) { if (!detail->isOfType(SoLineDetail::getClassTypeId())) { return; } @@ -992,9 +987,8 @@ void SoBrepPointSet::doAction(SoAction* action) this->highlightIndex = -1; return; } - const SoPickedPoint* pp = hlaction->getElement(); - if (pp && pp->getDetail()) { - const SoDetail* detail = pp->getDetail(); + const SoDetail* detail = hlaction->getElement(); + if (detail) { if (!detail->isOfType(SoPointDetail::getClassTypeId())) { this->highlightIndex = -1; return; @@ -1024,9 +1018,8 @@ void SoBrepPointSet::doAction(SoAction* action) return; } - const SoPickedPoint* pp = selaction->getElement(); - if (pp && pp->getDetail()) { - const SoDetail* detail = pp->getDetail(); + const SoDetail* detail = selaction->getElement(); + if (detail) { if (!detail->isOfType(SoPointDetail::getClassTypeId())) { return; } diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index 7680861cd..8f929e121 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -371,10 +371,9 @@ std::vector ViewProviderPartExt::getDisplayModes(void) const return StrList; } -std::string ViewProviderPartExt::getElement(const SoPickedPoint* pp) const +std::string ViewProviderPartExt::getElement(const SoDetail* detail) const { std::stringstream str; - const SoDetail* detail = pp->getDetail(); if (detail) { if (detail->getTypeId() == SoFaceDetail::getClassTypeId()) { const SoFaceDetail* face_detail = static_cast(detail); @@ -383,7 +382,7 @@ std::string ViewProviderPartExt::getElement(const SoPickedPoint* pp) const } else if (detail->getTypeId() == SoLineDetail::getClassTypeId()) { const SoLineDetail* line_detail = static_cast(detail); - int edge = line_detail->getPartIndex() + 1; + int edge = line_detail->getLineIndex() + 1; str << "Edge" << edge; } else if (detail->getTypeId() == SoPointDetail::getClassTypeId()) { @@ -396,6 +395,35 @@ std::string ViewProviderPartExt::getElement(const SoPickedPoint* pp) const return str.str(); } +SoDetail* ViewProviderPartExt::getDetail(const char* subelement) const +{ + std::string element = subelement; + std::string::size_type pos = element.find_first_of("0123456789"); + int index = -1; + if (pos != std::string::npos) { + index = std::atoi(element.substr(pos).c_str()); + element = element.substr(0,pos); + } + + SoDetail* detail = 0; + if (index < 0) + return detail; + if (element == "Face") { + detail = new SoFaceDetail(); + static_cast(detail)->setPartIndex(index - 1); + } + else if (element == "Edge") { + detail = new SoLineDetail(); + static_cast(detail)->setLineIndex(index - 1); + } + else if (element == "Vertex") { + detail = new SoPointDetail(); + static_cast(detail)->setCoordinateIndex(index + nodeset->startIndex.getValue() - 1); + } + + return detail; +} + std::vector ViewProviderPartExt::getSelectionShape(const char* Element) const { return std::vector(); diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index 1ad056ddc..116997963 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -99,7 +99,8 @@ public: /// indicates if the ViewProvider use the new Selection model virtual bool useNewSelectionModel(void) const {return true;} /// return a hit element to the selection path or 0 - virtual std::string getElement(const SoPickedPoint*) const; + virtual std::string getElement(const SoDetail*) const; + virtual SoDetail* getDetail(const char*) const; /// return the higlight lines for a given element or the whole shape virtual std::vector getSelectionShape(const char* Element) const; //@}