From a47345a30a1050d55ff9bdf3864578ecfc71554f Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 12 May 2014 13:51:27 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Mouse released is processed as the selection change. --- src/PartSet/PartSet_Module.cpp | 33 ++++--------- src/PartSet/PartSet_Module.h | 3 -- src/PartSet/PartSet_OperationEditLine.cpp | 19 +++++--- src/PartSet/PartSet_OperationEditLine.h | 11 ++--- src/PartSet/PartSet_OperationSketch.cpp | 23 +++++++--- src/PartSet/PartSet_OperationSketch.h | 11 +++-- src/PartSet/PartSet_OperationSketchBase.cpp | 3 +- src/PartSet/PartSet_OperationSketchBase.h | 11 ++--- src/PartSet/PartSet_OperationSketchLine.cpp | 3 +- src/PartSet/PartSet_OperationSketchLine.h | 4 +- src/XGUI/CMakeLists.txt | 2 + src/XGUI/XGUI_Displayer.cpp | 19 ++++++++ src/XGUI/XGUI_Displayer.h | 10 +++- src/XGUI/XGUI_ViewerPrs.cpp | 39 ++++++++++++++++ src/XGUI/XGUI_ViewerPrs.h | 51 +++++++++++++++++++++ 15 files changed, 179 insertions(+), 63 deletions(-) create mode 100644 src/XGUI/XGUI_ViewerPrs.cpp create mode 100644 src/XGUI/XGUI_ViewerPrs.h diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 82321d023..2ad243d68 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -54,8 +54,6 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); - connect(myWorkshop->selector(), SIGNAL(selectionChanged()), - this, SLOT(onSelectionChanged())); connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this, SLOT(onMousePressed(QMouseEvent*))); connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), @@ -124,27 +122,6 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) } } -void PartSet_Module::onSelectionChanged() -{ - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - XGUI_SelectionMgr* aSelector = myWorkshop->selector(); - if (aSelector) { - NCollection_List aList; - aSelector->selectedShapes(aList); - - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - boost::shared_ptr aFeature; - // only first selected shape is processed - if (!aList.IsEmpty()) { - aFeature = aDisplayer->GetFeature(aList.First()); - } - aPreviewOp->setSelected(aFeature, !aList.IsEmpty() ? aList.First() : TopoDS_Shape()); - } - } -} - void PartSet_Module::onMousePressed(QMouseEvent* theEvent) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( @@ -161,7 +138,15 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView()); + XGUI_SelectionMgr* aSelector = myWorkshop->selector(); + std::list aPresentations; + if (aSelector) { + NCollection_List aList; + aSelector->selectedShapes(aList); + + aPresentations = myWorkshop->displayer()->GetViewerPrs(aList); + } + aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations); } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 75dbd3063..82fe68b4f 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -50,9 +50,6 @@ public slots: /// by the operation start 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 listens selection. - void onSelectionChanged(); /// SLOT, that is called by mouse press in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 92ae140d2..5f7c7ebca 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include #include @@ -79,16 +81,19 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie myCurPressed = aPoint; } -void PartSet_OperationEditLine::setSelected(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) +void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) { - if (theFeature == feature()) + boost::shared_ptr aFeature; + if (!theSelected.empty()) + aFeature = theSelected.front().feature(); + + if (aFeature == feature()) return; - + commit(); - - if (theFeature) - emit launchOperation(PartSet_OperationEditLine::Type(), theFeature); + if (aFeature) + emit launchOperation(PartSet_OperationEditLine::Type(), aFeature); } void PartSet_OperationEditLine::startOperation() diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index 646416f91..a935f2f70 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -54,13 +54,12 @@ public: /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); - /// Gives the current selected objects to be processed by the operation - /// \param theFeature the selected feature - /// \param theShape the selected shape - virtual void setSelected(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape); - + /// \param thePoint a point clicked in the viewer + /// \param theEvent the mouse event + /// \param theSelected the list of selected presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); protected: /// \brief Virtual method called when operation is started /// Virtual method called when operation started (see start() method for more description) diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index b07fd0dff..04de17112 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -13,8 +13,11 @@ #include #include +#include + #include #include +#include #ifdef _DEBUG #include @@ -44,18 +47,24 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) +void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected) { - if (theShape.IsNull()) + if (theSelected.empty()) return; + XGUI_ViewerPrs aPrs = theSelected.front(); if (!myIsEditMode) { - setSketchPlane(theShape); - myIsEditMode = true; + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + setSketchPlane(aShape); + myIsEditMode = true; + } + } + else { + if (aPrs.feature()) + emit launchOperation(PartSet_OperationEditLine::Type(), aPrs.feature()); } - else if (theFeature) - emit launchOperation(PartSet_OperationEditLine::Type(), theFeature); } void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index b30ce2927..acc374e41 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -34,11 +34,12 @@ public: /// \return the selection mode virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; - /// Gives the current selected objects to be processed by the operation - /// \param theFeature the selected feature - /// \param theShape the selected shape - virtual void setSelected(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape); + /// Processes the mouse release in the point + /// \param thePoint a point clicked in the viewer + /// \param theEvent the mouse event + /// \param theSelected the list of selected presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); signals: /// signal about the sketch plane is selected diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 08e743572..85c0a2c30 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -43,7 +43,8 @@ boost::shared_ptr PartSet_OperationSketchBase::createFeature() void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView) { } -void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView) +void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected) { } void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 0fce89ea6..d13358515 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -18,6 +18,7 @@ class Handle_V3d_View; class QMouseEvent; class GeomAPI_Shape; +class XGUI_ViewerPrs; /*! \class PartSet_OperationSketchBase @@ -51,12 +52,6 @@ public: /// \param theFeature the feature virtual void init(boost::shared_ptr theFeature) {} - /// Gives the current selected objects to be processed by the operation - /// \param theFeature the selected feature - /// \param theShape the selected shape - virtual void setSelected(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) {}; - /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event @@ -65,7 +60,9 @@ public: /// Processes the mouse release in the point /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView); + /// \param theSelected the list of selected presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); /// Processes the mouse move in the point /// \param thePoint a 3D point clicked in the viewer diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 6fe2f6a01..2538cfd5f 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -54,7 +54,8 @@ void PartSet_OperationSketchLine::init(boost::shared_ptr theFe myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); } -void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView) +void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, + const std::list& theSelected) { gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); switch (myPointSelectionMode) diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index b4979a9c3..8dda6b9c6 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -51,7 +51,9 @@ public: /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event - virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView); + /// \param theSelected the list of selected presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 9a506a60b..aad18bff7 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -30,6 +30,7 @@ SET(PROJECT_HEADERS XGUI_ErrorDialog.h XGUI_SalomeViewer.h XGUI_ViewerProxy.h + XGUI_ViewerPrs.h XGUI_PropertyPanel.h ) @@ -59,6 +60,7 @@ SET(PROJECT_SOURCES XGUI_ActionsMgr.cpp XGUI_ErrorDialog.cpp XGUI_ViewerProxy.cpp + XGUI_ViewerPrs.cpp XGUI_PropertyPanel.cpp ) diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 7fcc29894..20a6f721e 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -64,6 +64,25 @@ boost::shared_ptr XGUI_Displayer::GetFeature(const TopoDS_Shap return aFeature; } +std::list XGUI_Displayer::GetViewerPrs + (const NCollection_List& theShapes) +{ + std::list aPresentations; + if (theShapes.IsEmpty()) + return aPresentations; + + NCollection_List::Iterator anIt(theShapes); + for (; anIt.More(); anIt.Next()) { + const TopoDS_Shape& aShape = anIt.Value(); + if (aShape.IsNull()) + continue; + boost::shared_ptr aFeature = GetFeature(aShape); + aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape)); + } + + return aPresentations; +} + void XGUI_Displayer::Erase(boost::shared_ptr theFeature, const bool isUpdateViewer) { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index d8da366e8..cda9331e6 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -13,6 +13,9 @@ #include #include #include +#include + +#include #include #include @@ -57,7 +60,12 @@ public: /// Returns the feature, that was displayed with this shape /// \param theShape a shape - boost::shared_ptr GetFeature( const TopoDS_Shape& theShape ); + boost::shared_ptr GetFeature(const TopoDS_Shape& theShape); + + /// Returns a list of viewer presentations + /// \param theShapes list of shapes to find corresponded features + /// \return list of presentations + std::list GetViewerPrs(const NCollection_List& theShapes); /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance diff --git a/src/XGUI/XGUI_ViewerPrs.cpp b/src/XGUI/XGUI_ViewerPrs.cpp new file mode 100644 index 000000000..4ab8801aa --- /dev/null +++ b/src/XGUI/XGUI_ViewerPrs.cpp @@ -0,0 +1,39 @@ +// File: XGUI_ViewerPrs.cpp +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include "XGUI_ViewerPrs.h" + +XGUI_ViewerPrs::XGUI_ViewerPrs() +{ +} + +XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape) +: myFeature(theFeature), myShape(theShape) +{ +} + +XGUI_ViewerPrs::~XGUI_ViewerPrs() +{ +} + +void XGUI_ViewerPrs::setFeature(boost::shared_ptr theFeature) +{ + myFeature = theFeature; +} + +void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape) +{ + myShape = theShape; +} + +boost::shared_ptr XGUI_ViewerPrs::feature() const +{ + return myFeature; +} + +const TopoDS_Shape& XGUI_ViewerPrs::shape() const +{ + return myShape; +} diff --git a/src/XGUI/XGUI_ViewerPrs.h b/src/XGUI/XGUI_ViewerPrs.h new file mode 100644 index 000000000..957e4dc7c --- /dev/null +++ b/src/XGUI/XGUI_ViewerPrs.h @@ -0,0 +1,51 @@ +// File: XGUI_ViewerPrs.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef XGUI_ViewerPrs_H +#define XGUI_ViewerPrs_H + +#include "XGUI.h" + +#include +#include + +class ModelAPI_Feature; + +/**\class XGUI_ViewerPrs + * \ingroup GUI + * \brief Presentation. Provides container to have feature and the shape + */ +class XGUI_EXPORT XGUI_ViewerPrs +{ +public: + /// Constructor + XGUI_ViewerPrs(); + /// Constructor + XGUI_ViewerPrs(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape); + /// Destructor + virtual ~XGUI_ViewerPrs(); + + /// Sets the feature. + /// \param theFeature a feature instance + void setFeature(boost::shared_ptr theFeature); + + /// Sets the shape + /// \param theShape a shape instance + void setShape(const TopoDS_Shape& theShape); + + /// Returns the feature. + /// \return a feature instance + boost::shared_ptr feature() const; + + /// Returns the shape + /// \return a shape instance + const TopoDS_Shape& shape() const; + +private: + boost::shared_ptr myFeature; /// the feature + TopoDS_Shape myShape; /// the shape +}; + +#endif -- 2.39.2