From 88f6ce164eff7f5100ae97559e1bc225444706cd Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 24 Apr 2014 16:38:54 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Providing the local selection for sketch feature --- src/PartSet/PartSet_Module.cpp | 25 ++++++++++++----- src/PartSet/PartSet_Module.h | 3 +++ src/PartSet/PartSet_OperationSketch.cpp | 30 +++++++++++++++++++++ src/PartSet/PartSet_OperationSketch.h | 4 +++ src/PartSet/PartSet_OperationSketchBase.cpp | 5 ---- src/PartSet/PartSet_OperationSketchBase.h | 8 +++++- src/XGUI/XGUI_Viewer.cpp | 15 +++++++++++ src/XGUI/XGUI_Viewer.h | 12 +++++++++ 8 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 76a8c855b..568f28c86 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include @@ -37,6 +39,8 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), + this, SLOT(onViewSelectionChanged())); } PartSet_Module::~PartSet_Module() @@ -97,11 +101,8 @@ void PartSet_Module::onOperationStarted() ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), - aPreviewOp, SLOT(onViewSelectionChanged())); + if (aPreviewOp) visualizePreview(true); - } } void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) @@ -109,12 +110,22 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) ModuleBase_PropPanelOperation* anOperation = dynamic_cast(theOperation); if (!anOperation) return; + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) + visualizePreview(false); +} +void PartSet_Module::onViewSelectionChanged() +{ + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), - aPreviewOp, SLOT(onViewSelectionChanged())); - visualizePreview(false); + XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); + if (aViewer) { + AIS_ListOfInteractive aList; + aViewer->getSelectedObjects(aList); + aPreviewOp->setSelectedObjects(aList); + } } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 60f78835c..633513674 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -28,6 +28,9 @@ public slots: /// SLOT, that is called after the operation is stopped. Disconnect the sketch feature /// from the viewer selection and show the sketch preview. void onOperationStopped(ModuleBase_Operation* theOperation); + /// SLOT, that is called by the selection in the viewer is changed. + /// The selection is sent to the current operation if it listen the selection. + void onViewSelectionChanged(); private: /// Displays or erase the current operation preview, if it has it. diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 01010ee55..c9608cd2e 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -5,6 +5,11 @@ #include #include +#include +#include + +#include +#include #ifdef _DEBUG #include @@ -31,3 +36,28 @@ int PartSet_OperationSketch::getSelectionMode() const { return TopAbs_FACE; } + +void PartSet_OperationSketch::setSelectedObjects(const AIS_ListOfInteractive& theList) +{ + if (theList.IsEmpty()) + return; + + // 1. get selected fase + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(theList.First()); + if (anAISShape.IsNull()) + return; + + const TopoDS_Shape& aShape = anAISShape->Shape(); + boost::shared_ptr aRes(new GeomAPI_Shape); + aRes->setImpl(new TopoDS_Shape(aShape)); + + // get plane parameters + double anX = 1, anY = 0, aZ = 0, anOrigin = 0; + + // set plane parameters to feature + //boost::shared_ptr aData = feature()->data(); + //boost::shared_ptr anAttr = aData->docRef(SKETCH_ATTR_X); + //anAttr->setValue(anX); + + commit(); +} diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index ee8df257a..83be57a99 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -31,6 +31,10 @@ public: /// Returns the operation local selection mode /// \return the selection mode virtual int getSelectionMode() const; + + /// Gives the current selected objects to be processed by the operation + /// \param theList a list of interactive selected objects + virtual void setSelectedObjects(const AIS_ListOfInteractive& theList); }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index ba3a626f2..519c97f76 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -28,8 +28,3 @@ 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 92500d786..b6c160ae7 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -12,6 +12,8 @@ #include #include +class AIS_ListOfInteractive; + /*! \class PartSet_OperationSketchBase * \brief The base operation for the sketch features. @@ -33,7 +35,11 @@ public: /// Returns the operation local selection mode /// \return the selection mode - virtual int getSelectionMode() const; + virtual int getSelectionMode() const = 0; + + /// Gives the current selected objects to be processed by the operation + /// \param a list of interactive selected objects + virtual void setSelectedObjects(const AIS_ListOfInteractive& aList) = 0; }; #endif diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index c78bd72d1..e6dd6e2b7 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -231,6 +231,21 @@ void XGUI_Viewer::setGlobalSelection(const bool isUpdateViewer) } } +void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList) +{ + theList.Clear(); + for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected()) + theList.Append(myAISContext->SelectedInteractive()); +} + +void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList) +{ + AIS_ListIteratorOfListOfInteractive aIt; + for (aIt.Initialize(theList); aIt.More(); aIt.Next()) + myAISContext->AddOrRemoveSelected(aIt.Value(), false); + myAISContext->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 3e33be3ae..c4ae363b6 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -65,6 +65,18 @@ public: //! \param isUpdateViewer the state wether the viewer should be updated immediatelly void setGlobalSelection(const bool isUpdateViewer); + /// Return objects selected in 3D viewer + /// \param theList - list to be filled with selected objects + void getSelectedObjects(AIS_ListOfInteractive& theList); + + /// Selects objects in 3D viewer. Other selected objects are left as selected + /// \param theList - list objects to be selected + void setObjectsSelected(const AIS_ListOfInteractive& theList); + + /// Select the object in 3D viewer. + /// \param theIO - list objects to be selected + void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); } + //! Trihedron 3d object shown in the viewer Handle(AIS_Trihedron) trihedron() const { -- 2.39.2