From: nds Date: Thu, 24 Apr 2014 10:51:19 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~123 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=35e507724b47b04e0daa4259e4f6fc1de6a42f60;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Providing the local selection for sketch feature --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 12cf4971a..c11c872ac 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -128,8 +128,12 @@ void PartSet_Module::visualizePreview(bool isDisplay) if (!aPreviewOp) return; - if (isDisplay) - myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview()); - else + if (isDisplay) { + myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(), + aPreviewOp->getSelectionMode()); + } + else { + myWorkshop->displayer()->GlobalSelection(false); myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview()); + } } diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index a12c38b0a..01010ee55 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -26,3 +26,8 @@ bool PartSet_OperationSketch::isPerformedImmediately() const { return false; } + +int PartSet_OperationSketch::getSelectionMode() const +{ + return TopAbs_FACE; +} diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 63375e5e6..ee8df257a 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -27,6 +27,10 @@ public: /// The sketch can not be created immediately, firstly a plane should be set virtual bool isPerformedImmediately() const; + + /// Returns the operation local selection mode + /// \return the selection mode + virtual int getSelectionMode() const; }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 519c97f76..ba3a626f2 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -28,3 +28,8 @@ const TopoDS_Shape& PartSet_OperationSketchBase::preview() const boost::dynamic_pointer_cast(feature()); return aFeature->preview()->impl(); } + +int PartSet_OperationSketchBase::getSelectionMode() const +{ + return 0; +} diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 1a99babc9..92500d786 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -30,6 +30,10 @@ public: /// Returns the feature preview shape const TopoDS_Shape& preview() const; + + /// Returns the operation local selection mode + /// \return the selection mode + virtual int getSelectionMode() const; }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 489d0248e..a036e8f75 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include XGUI_Displayer::XGUI_Displayer(XGUI_Viewer* theViewer) @@ -19,24 +21,47 @@ XGUI_Displayer::~XGUI_Displayer() { } -void XGUI_Displayer::Display(boost::shared_ptr theFeature) +void XGUI_Displayer::Display(boost::shared_ptr theFeature, + const bool isUpdateViewer) { } void XGUI_Displayer::Display(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) + const TopoDS_Shape& theShape, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); aContext->Display(anAIS, Standard_False); - aContext->UpdateCurrentViewer(); + if (isUpdateViewer) + aContext->UpdateCurrentViewer(); } void XGUI_Displayer::Erase(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) + const TopoDS_Shape& theShape, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); aContext->EraseAll(); + if (isUpdateViewer) + aContext->UpdateCurrentViewer(); } + +void XGUI_Displayer::LocalSelection(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape, + const int theMode, const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) aContext = myViewer->AISContext(); + + Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); + aContext->Display(anAIS, Standard_False); + AIS_ListOfInteractive anAISList; + anAISList.Append(anAIS); + myViewer->setLocalSelection(anAISList, theMode, true); +} + +void XGUI_Displayer::GlobalSelection(const bool isUpdateViewer) +{ + myViewer->setGlobalSelection(true); +} + diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 06ebcba1e..1dc238b90 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -30,17 +30,34 @@ public: /// Display the feature. Obtain the visualized object from the feature. /// \param theFeature a feature instance - void Display(boost::shared_ptr theFeature); + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void Display(boost::shared_ptr theFeature, const bool isUpdateViewer = true); /// Display the feature and a shape. This shape would be associated to the given feature /// \param theFeature a feature instance - /// \param theFeature a shape - void Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape); + /// \param theShape a shape + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, + const bool isUpdateViewer = true); + + /// Display the shape and activate selection of sub-shapes + /// \param theFeature a feature instance + /// \param theShape a shape + /// \param theMode a local selection mode + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void LocalSelection(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, + const int theMode, const bool isUpdateViewer = true); /// Erase the feature and a shape. /// \param theFeature a feature instance /// \param theFeature a shape - void Erase(boost::shared_ptr theFeature, const TopoDS_Shape& theShape); + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void Erase(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, + const bool isUpdateViewer = true); + + /// Deactivates selection of sub-shapes + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void GlobalSelection(const bool isUpdateViewer = true); protected: XGUI_Viewer* myViewer; ///< the viewer where the objects should be visualized diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 6d4c10068..c78bd72d1 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include @@ -188,6 +190,47 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) return aWnd; } +void XGUI_Viewer::setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode, + const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) ic = AISContext(); + + // Open local context if there is no one + bool allObjects = false; // calculate by AIS shape + if (!ic->HasOpenedContext()) { + ic->ClearCurrents(false); + ic->OpenLocalContext(allObjects, true, true); + } + + // Activate selection of objects from prs + AIS_ListIteratorOfListOfInteractive aIter(theAISObjects); + for (; aIter.More(); aIter.Next()) { + Handle(AIS_InteractiveObject) anAIS = aIter.Value(); + if (!anAIS.IsNull()) { + if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) { + ic->Load(anAIS, -1, false); + ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode)); + } + else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) { + ic->Load(anAIS, -1, false); + ic->Activate(anAIS, theMode); + } + } + } + if (isUpdateViewer) + ic->UpdateCurrentViewer(); +} + +void XGUI_Viewer::setGlobalSelection(const bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) ic = AISContext(); + if (!ic.IsNull()) { + ic->CloseAllContexts(false); + if (isUpdateViewer) + ic->UpdateCurrentViewer(); + } +} + /*! Sets hot button *\param theOper - hot operation *\param theState - adding state to state map operations. diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 5b68ebdf0..3e33be3ae 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -18,6 +18,8 @@ class XGUI_ViewWindow; class QMouseEvent; class QKeyEvent; +class AIS_ListOfInteractive; + /**\class XGUI_Viewer * \ingroup GUI * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows @@ -53,6 +55,16 @@ public: return myAISContext; } + //! Activate local selection + //! \param theAIS the list of objects + //! \param theMode the selection mode + //! \param isUpdateViewer the state wether the viewer should be updated immediatelly + void setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode, + const bool isUpdateViewer); + //! Deactivate local selection + //! \param isUpdateViewer the state wether the viewer should be updated immediatelly + void setGlobalSelection(const bool isUpdateViewer); + //! Trihedron 3d object shown in the viewer Handle(AIS_Trihedron) trihedron() const {