From 3868952ce179012a7ca56f6c8d1f271ecdb17f73 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 9 Jul 2014 12:38:38 +0400 Subject: [PATCH] Create selection validator and selection object --- src/ModuleBase/CMakeLists.txt | 4 +- src/ModuleBase/ModuleBase_ISelection.h | 49 ++++++++ .../ModuleBase_SelectionValidator.h | 20 ++++ .../ModuleBase_ViewSelectionValidator.h | 18 --- src/ModuleBase/ModuleBase_ViewerPrs.h | 76 ++++++++++++ src/PartSet/PartSet_Module.cpp | 38 +++--- .../PartSet_OperationFeatureCreate.cpp | 16 +-- src/PartSet/PartSet_OperationFeatureCreate.h | 10 +- src/PartSet/PartSet_OperationFeatureEdit.cpp | 18 +-- src/PartSet/PartSet_OperationFeatureEdit.h | 12 +- .../PartSet_OperationFeatureEditMulti.cpp | 28 ++--- .../PartSet_OperationFeatureEditMulti.h | 14 +-- src/PartSet/PartSet_OperationSketch.cpp | 12 +- src/PartSet/PartSet_OperationSketch.h | 10 +- src/PartSet/PartSet_OperationSketchBase.cpp | 12 +- src/PartSet/PartSet_OperationSketchBase.h | 20 ++-- src/PartSet/PartSet_TestOCC.cpp | 2 +- src/PartSet/PartSet_Tools.cpp | 8 +- src/PartSet/PartSet_Tools.h | 4 +- src/PartSet/PartSet_WidgetSketchLabel.cpp | 10 +- src/PartSet/PartSet_WidgetSketchLabel.h | 3 + src/XGUI/CMakeLists.txt | 4 +- src/XGUI/XGUI_ContextMenuMgr.cpp | 5 +- src/XGUI/XGUI_Displayer.cpp | 59 ---------- src/XGUI/XGUI_Displayer.h | 22 +--- src/XGUI/XGUI_ModuleConnector.cpp | 3 +- src/XGUI/XGUI_Selection.cpp | 109 ++++++++++++++++++ src/XGUI/XGUI_Selection.h | 56 +++++++++ src/XGUI/XGUI_SelectionMgr.cpp | 20 +++- src/XGUI/XGUI_SelectionMgr.h | 13 ++- src/XGUI/XGUI_ViewerPrs.cpp | 60 ---------- src/XGUI/XGUI_ViewerPrs.h | 67 ----------- src/XGUI/XGUI_Workshop.cpp | 13 ++- 33 files changed, 468 insertions(+), 347 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_ISelection.h create mode 100644 src/ModuleBase/ModuleBase_SelectionValidator.h delete mode 100644 src/ModuleBase/ModuleBase_ViewSelectionValidator.h create mode 100644 src/ModuleBase/ModuleBase_ViewerPrs.h create mode 100644 src/XGUI/XGUI_Selection.cpp create mode 100644 src/XGUI/XGUI_Selection.h delete mode 100644 src/XGUI/XGUI_ViewerPrs.cpp delete mode 100644 src/XGUI/XGUI_ViewerPrs.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 4f34faab8..b21756a5c 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -22,7 +22,9 @@ SET(PROJECT_HEADERS ModuleBase_WidgetValue.h ModuleBase_WidgetValueFeature.h ModuleBase_Definitions.h - ModuleBase_ViewSelectionValidator.h + ModuleBase_SelectionValidator.h + ModuleBase_ISelection.h + ModuleBase_ViewerPrs.h ) SET(PROJECT_SOURCES diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h new file mode 100644 index 000000000..051998502 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -0,0 +1,49 @@ +// File: ModuleBase_ISelection.h +// Created: 2 June 2014 +// Author: Vitaly Smetannikov + +#ifndef ModuleBase_ISelection_H +#define ModuleBase_ISelection_H + +#include "ModuleBase.h" +#include "ModuleBase_Definitions.h" +#include "ModuleBase_ViewerPrs.h" + +#include +#include +#include +#include + +#include + +class ModuleBase_ISelection +{ +public: + + /// Returns a list of viewer selected presentations + /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build + /// \return list of presentations + virtual std::list getSelected(int theShapeTypeToSkip = -1) const = 0; + + /// Returns a list of viewer highlited presentations + /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build + /// \return list of presentations + virtual std::list getHighlighted(int theShapeTypeToSkip = -1) const = 0; + + /** + * Returns list of features currently selected in 3d viewer + */ + virtual QFeatureList selectedFeatures() const = 0; + + //! Returns list of currently selected QModelIndexes + virtual QModelIndexList selectedIndexes() const = 0; + + //! Returns list of currently selected AIS objects + virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0; + + //! Returns list of currently selected shapes + virtual void selectedShapes(NCollection_List& theList) const = 0; + +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_SelectionValidator.h b/src/ModuleBase/ModuleBase_SelectionValidator.h new file mode 100644 index 000000000..ff0c0a669 --- /dev/null +++ b/src/ModuleBase/ModuleBase_SelectionValidator.h @@ -0,0 +1,20 @@ +// File: ModuleBase_SelectionValidator.h +// Created: 8 Jul 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef ModuleBase_SelectionValidator_H +#define ModuleBase_SelectionValidator_H + +#include "ModuleBase.h" +#include "ModuleBase_ISelection.h" + +#include + + +class MODULEBASE_EXPORT ModuleBase_SelectionValidator: public ModelAPI_Validator +{ +public: + virtual bool isValid(const ModuleBase_ISelection* theSelection) const = 0; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_ViewSelectionValidator.h b/src/ModuleBase/ModuleBase_ViewSelectionValidator.h deleted file mode 100644 index 9dcc910c0..000000000 --- a/src/ModuleBase/ModuleBase_ViewSelectionValidator.h +++ /dev/null @@ -1,18 +0,0 @@ -// File: ModuleBase_ViewSelectionValidator.h -// Created: 8 Jul 2014 -// Author: Vitaly SMETANNIKOV - -#ifndef ModuleBase_ViewSelectionValidator_H -#define ModuleBase_ViewSelectionValidator_H - -#include "ModuleBase.h" - -#include - -class MODULEBASE_EXPORT ModuleBase_ViewSelectionValidator: public ModelAPI_Validator -{ -public: - virtual bool isValid(const Handle(AIS_InteractiveContext)& theContext) const = 0; -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_ViewerPrs.h b/src/ModuleBase/ModuleBase_ViewerPrs.h new file mode 100644 index 000000000..b595ac156 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ViewerPrs.h @@ -0,0 +1,76 @@ +// File: ModuleBase_ViewerPrs.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_ViewerPrs_H +#define ModuleBase_ViewerPrs_H + +#include "ModuleBase.h" + +#include +#include +#include + +#include + +/**\class ModuleBase_ViewerPrs + * \ingroup Module base + * \brief Presentation. Provides container to have feature, shape and/or selection owner. + */ +class ModuleBase_ViewerPrs +{ +public: + /// Constructor + ModuleBase_ViewerPrs() {} + + /// Constructor + /// \param theFeature a model feature + /// \param theShape a viewer shape + /// \param theOwner a selection owner + ModuleBase_ViewerPrs(FeaturePtr theFeature, + const TopoDS_Shape& theShape, + Handle_SelectMgr_EntityOwner theOwner) + : myFeature(theFeature), myShape(theShape), myOwner(theOwner) {} + + /// Destructor + virtual ~ModuleBase_ViewerPrs() {} + + /// Sets the feature. + /// \param theFeature a feature instance + void setFeature(FeaturePtr theFeature) { myFeature = theFeature; } + + /// Returns the feature. + /// \return a feature instance + FeaturePtr feature() const { return myFeature; } + + /// Returns the presentation owner + /// \param the owner + void setOwner(Handle_SelectMgr_EntityOwner theOwner) { myOwner = theOwner; } + + /// Returns the presentation owner + /// \return an owner + Handle_SelectMgr_EntityOwner owner() const { return myOwner; } + + /// Sets the shape + /// \param theShape a shape instance + void setShape(const TopoDS_Shape& theShape) { myShape = theShape; } + + /// Returns the shape + /// \return a shape instance + const TopoDS_Shape& shape() const { return myShape; } + + bool operator==(const ModuleBase_ViewerPrs& thePrs) + { + bool aFeature = (myFeature.get() == thePrs.feature().get()); + bool aOwner = (myOwner.Access() == thePrs.owner().Access()); + bool aShape = myShape.IsEqual(thePrs.shape()); + return aFeature && aOwner && aShape; + } + +private: + FeaturePtr myFeature; /// the feature + Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner + TopoDS_Shape myShape; /// the shape +}; + +#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8d40a07f7..3114ef944 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -140,10 +141,10 @@ void PartSet_Module::launchOperation(const QString& theCmdId) ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString()); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); // Initialise operation with preliminary selection - std::list aSelected = aDisplayer->getSelected(); - std::list aHighlighted = aDisplayer->getHighlighted(); + std::list aSelected = aSelection->getSelected(); + std::list aHighlighted = aSelection->getHighlighted(); aPreviewOp->initSelection(aSelected, aHighlighted); } sendOperation(anOperation); @@ -174,7 +175,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked) { - QFeatureList aFeatures = myWorkshop->selector()->selectedFeatures(); + QFeatureList aFeatures = myWorkshop->selector()->selection()->selectedFeatures(); if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) { editFeature(aFeatures.first()); } @@ -185,9 +186,10 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent) PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - std::list aSelected = aDisplayer->getSelected(); - std::list aHighlighted = aDisplayer->getHighlighted(); + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + // Initialise operation with preliminary selection + std::list aSelected = aSelection->getSelected(); + std::list aHighlighted = aSelection->getHighlighted(); aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } @@ -199,9 +201,10 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - std::list aSelected = aDisplayer->getSelected(); - std::list aHighlighted = aDisplayer->getHighlighted(); + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + // Initialise operation with preliminary selection + std::list aSelected = aSelection->getSelected(); + std::list aHighlighted = aSelection->getHighlighted(); aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } @@ -230,9 +233,10 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) myWorkshop->operationMgr()->currentOperation()); if (aPreviewOp) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - std::list aSelected = aDisplayer->getSelected(); - std::list aHighlighted = aDisplayer->getHighlighted(); + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + // Initialise operation with preliminary selection + std::list aSelected = aSelection->getSelected(); + std::list aHighlighted = aSelection->getHighlighted(); aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } @@ -258,10 +262,10 @@ void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeatur PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - // refill the features list with avoiding of the features, obtained only by vertex shape (TODO) - std::list aSelected = aDisplayer->getSelected(); - std::list aHighlighted = aDisplayer->getHighlighted(); + XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + // Initialise operation with preliminary selection + std::list aSelected = aSelection->getSelected(); + std::list aHighlighted = aSelection->getHighlighted(); aPreviewOp->initFeature(theFeature); aPreviewOp->initSelection(aSelected, aHighlighted); } else { diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index b2f445505..d1d5d409b 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -24,8 +24,8 @@ #include #include #include +#include -#include #include #include @@ -83,8 +83,8 @@ std::list PartSet_OperationFeatureCreate::getSelectionModes(FeaturePtr theF return aModes; } -void PartSet_OperationFeatureCreate::initSelection(const std::list& theSelected, - const std::list& /*theHighlighted*/) +void PartSet_OperationFeatureCreate::initSelection(const std::list& theSelected, + const std::list& /*theHighlighted*/) { myPreSelection = theSelected; } @@ -101,8 +101,8 @@ FeaturePtr PartSet_OperationFeatureCreate::sketch() const } void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& theSelected, - const std::list& /*theHighlighted*/) + const std::list& theSelected, + const std::list& /*theHighlighted*/) { if (canBeCommitted()) { @@ -120,7 +120,7 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); } else { - XGUI_ViewerPrs aPrs = theSelected.front(); + ModuleBase_ViewerPrs aPrs = theSelected.front(); const TopoDS_Shape& aShape = aPrs.shape(); if (!aShape.IsNull()) // the point is selected { @@ -147,7 +147,7 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle } FeaturePtr aFeature; if (!theSelected.empty()) { - XGUI_ViewerPrs aPrs = theSelected.front(); + ModuleBase_ViewerPrs aPrs = theSelected.front(); aFeature = aPrs.feature(); } else @@ -190,7 +190,7 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t { myActiveWidget = theWidget; if ((myPreSelection.size() > 0) && myActiveWidget) { - const XGUI_ViewerPrs& aPrs = myPreSelection.front(); + const ModuleBase_ViewerPrs& aPrs = myPreSelection.front(); ModuleBase_WidgetValueFeature aValue; aValue.setFeature(aPrs.feature()); if (myActiveWidget->setValue(&aValue)) { diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index ee711b1bc..f5823d6c1 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -60,8 +60,8 @@ public: /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void initSelection(const std::list& theSelected, - const std::list& theHighlighted); + virtual void initSelection(const std::list& theSelected, + const std::list& theHighlighted); /// Returns the operation sketch feature /// \returns the sketch instance @@ -73,8 +73,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event @@ -128,7 +128,7 @@ private: ModuleBase_ModelWidget* myActiveWidget; ///< the active widget - std::list myPreSelection; + std::list myPreSelection; }; #endif diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 07f077d2b..c6ad6130e 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -10,9 +10,9 @@ #include #include -#include +#include -#include +#include #include #include @@ -70,8 +70,8 @@ FeaturePtr PartSet_OperationFeatureEdit::sketch() const } void PartSet_OperationFeatureEdit::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { FeaturePtr aFeature; if (!theHighlighted.empty()) @@ -125,19 +125,19 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_ } void PartSet_OperationFeatureEdit::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) + const std::list& /*theSelected*/, + const std::list& /*theHighlighted*/) { blockSelection(false); } void PartSet_OperationFeatureEdit::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { // TODO the functionality is important only for constraint feature. Should be moved in another place if (!theSelected.empty()) { - XGUI_ViewerPrs aFeaturePrs = theSelected.front(); + ModuleBase_ViewerPrs aFeaturePrs = theSelected.front(); if (!aFeaturePrs.owner().IsNull()) { Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aFeaturePrs.owner()); if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) { diff --git a/src/PartSet/PartSet_OperationFeatureEdit.h b/src/PartSet/PartSet_OperationFeatureEdit.h index a750cf9f7..f64e25ab1 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.h +++ b/src/PartSet/PartSet_OperationFeatureEdit.h @@ -83,8 +83,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Gives the current mouse point in the viewer /// \param theEvent the mouse event /// \param theView a viewer to have the viewer the eye position @@ -95,8 +95,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Processes the mouse double click in the point /// \param theEvent the mouse event @@ -104,8 +104,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); 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_OperationFeatureEditMulti.cpp b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp index e5feef62d..ac2cd6982 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.cpp +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.cpp @@ -7,9 +7,9 @@ #include #include -#include +#include -#include +#include #include #include @@ -48,8 +48,8 @@ bool PartSet_OperationFeatureEditMulti::isGranted(ModuleBase_IOperation* theOper return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); } -void PartSet_OperationFeatureEditMulti::initSelection(const std::list& theSelected, - const std::list& theHighlighted) +void PartSet_OperationFeatureEditMulti::initSelection(const std::list& theSelected, + const std::list& theHighlighted) { if (!theHighlighted.empty()) { // if there is highlighted object, we check whether it is in the list of selected objects @@ -57,7 +57,7 @@ void PartSet_OperationFeatureEditMulti::initSelection(const std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); + std::list::const_iterator anIt = theSelected.begin(), aLast = theSelected.end(); for (; anIt != aLast && !isSelected; anIt++) { isSelected = (*anIt).feature() == feature(); } @@ -81,8 +81,8 @@ FeaturePtr PartSet_OperationFeatureEditMulti::sketch() const } void PartSet_OperationFeatureEditMulti::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& /*theSelected*/, - const std::list& theHighlighted) + const std::list& /*theSelected*/, + const std::list& theHighlighted) { } @@ -108,7 +108,7 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle boost::dynamic_pointer_cast(feature()); aSketchFeature->move(aDeltaX, aDeltaY); - std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); + std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = (*anIt).feature(); if (!aFeature || aFeature == feature()) @@ -123,12 +123,12 @@ void PartSet_OperationFeatureEditMulti::mouseMoved(QMouseEvent* theEvent, Handle } void PartSet_OperationFeatureEditMulti::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) + const std::list& /*theSelected*/, + const std::list& /*theHighlighted*/) { - std::list aFeatures = myFeatures; + std::list aFeatures = myFeatures; commit(); - std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + std::list::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = (*anIt).feature(); if (aFeature) { @@ -163,7 +163,7 @@ void PartSet_OperationFeatureEditMulti::blockSelection(bool isBlocked, const boo myIsBlockedSelection = isBlocked; QFeatureList aFeatureList; - std::list::const_iterator anIt = myFeatures.begin(), + std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for(; anIt != aLast; anIt++) aFeatureList.append((*anIt).feature()); @@ -184,7 +184,7 @@ void PartSet_OperationFeatureEditMulti::sendFeatures() static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED); std::list aFeatures; - std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); + std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = (*anIt).feature(); if (!aFeature) diff --git a/src/PartSet/PartSet_OperationFeatureEditMulti.h b/src/PartSet/PartSet_OperationFeatureEditMulti.h index a431a1d85..7f018618b 100644 --- a/src/PartSet/PartSet_OperationFeatureEditMulti.h +++ b/src/PartSet/PartSet_OperationFeatureEditMulti.h @@ -71,8 +71,8 @@ public: /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void initSelection(const std::list& theSelected, - const std::list& theHighlighted); + virtual void initSelection(const std::list& theSelected, + const std::list& theHighlighted); /// Returns the operation sketch feature /// \returns the sketch instance @@ -84,8 +84,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Gives the current mouse point in the viewer /// \param theEvent the mouse event /// \param theView a viewer to have the viewer the eye position @@ -96,8 +96,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); protected: /// \brief Virtual method called when operation is started /// Virtual method called when operation started (see start() method for more description) @@ -121,7 +121,7 @@ protected: private: FeaturePtr mySketch; ///< the sketch feature - std::list myFeatures; ///< the features to apply the edit operation + std::list myFeatures; ///< the features to apply the edit operation Point myCurPoint; ///< the current 3D point clicked or moved bool myIsBlockedSelection; ///< the state of the last state of selection blocked signal }; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index eff5a65ee..563caf21c 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -72,12 +72,12 @@ FeaturePtr PartSet_OperationSketch::sketch() const } void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { if (!hasSketchPlane()) { if (!theHighlighted.empty()) { - XGUI_ViewerPrs aPrs = theHighlighted.front(); + ModuleBase_ViewerPrs aPrs = theHighlighted.front(); const TopoDS_Shape& aShape = aPrs.shape(); if (!aShape.IsNull()) setSketchPlane(aShape); @@ -106,8 +106,8 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie } void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { if (!hasSketchPlane()) { } diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 0f0b0ead0..eb0c84775 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -52,16 +52,16 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Processes the mouse release in the point /// \param theEvent the mouse event /// \param theView a viewer to have the viewer the eye position /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer @@ -105,7 +105,7 @@ protected: void setSketchPlane(const TopoDS_Shape& theShape); private: - std::list myFeatures; ///< the features to apply the edit operation + std::list myFeatures; ///< the features to apply the edit operation }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index dd6639321..bef1dfde5 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -69,21 +69,21 @@ FeaturePtr PartSet_OperationSketchBase::createFeature(const bool theFlushMessage void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { } void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { } void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { } void PartSet_OperationSketchBase::mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted) + const std::list& theSelected, + const std::list& theHighlighted) { } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 8fa6439d7..449d65834 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -26,7 +26,7 @@ class Handle_V3d_View; class QMouseEvent; class GeomAPI_Shape; -class XGUI_ViewerPrs; +class ModuleBase_ViewerPrs; /*! \class PartSet_OperationSketchBase @@ -66,8 +66,8 @@ public: /// Initialisation of operation with preliminary selection /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations - virtual void initSelection(const std::list& theSelected, - const std::list& theHighlighted) {} + virtual void initSelection(const std::list& theSelected, + const std::list& theHighlighted) {} /// Returns the operation sketch feature /// \returns the sketch instance @@ -79,8 +79,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Processes the mouse release in the point /// \param theEvent the mouse event @@ -88,8 +88,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Processes the mouse move in the point /// \param theEvent the mouse event @@ -102,8 +102,8 @@ public: /// \param theSelected the list of selected presentations /// \param theHighlighted the list of highlighted presentations virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); + const std::list& theSelected, + const std::list& theHighlighted); /// Processes the key pressed in the view /// \param theKey a key value @@ -130,7 +130,7 @@ signals: int theMode); /// Signal about the features should be selected /// \param theSelected the list of selected presentations - void featureSelected(const std::list& theSelected); + void featureSelected(const std::list& theSelected); /// signal to enable/disable multi selection in the viewer /// \param theEnabled the boolean state void multiSelectionEnabled(bool theEnabled); diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index 00ff7cef2..f447f5966 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -7,11 +7,11 @@ #include #include #include -#include #include #include #include +#include #include #include diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index ca6b10adb..aa3ac235a 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -138,18 +138,18 @@ void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch, - const std::list& theFeatures) + const std::list& theFeatures) { double aX, anY; gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView); PartSet_Tools::convertTo2D(aPoint, theSketch, theView, aX, anY); FeaturePtr aFeature; - std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); + std::list::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end(); FeaturePtr aDeltaFeature; double aMinDelta = -1; - XGUI_ViewerPrs aPrs; + ModuleBase_ViewerPrs aPrs; for (; anIt != aLast; anIt++) { aPrs = *anIt; if (!aPrs.feature()) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index fa1f31f9d..1cd763ca0 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -18,7 +18,7 @@ #include class Handle_V3d_View; -class XGUI_ViewerPrs; +class ModuleBase_ViewerPrs; class GeomDataAPI_Point2D; class GeomAPI_Pln; class GeomAPI_Pnt2d; @@ -58,7 +58,7 @@ public: /// \param theSketch the sketch feature /// \param theFeatures the list of selected presentations static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch, - const std::list& theFeatures); + const std::list& theFeatures); /// Returns pointer to the root document. static boost::shared_ptr document(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index de9c411c1..4b39dc60e 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -42,6 +42,7 @@ void PartSet_WidgetSketchLabel::setOperationsMgr(XGUI_OperationMgr* theMgr) ModuleBase_Operation* aOperation = theMgr->currentOperation(); if (aOperation->inherits("PartSet_OperationSketch")) { PartSet_OperationSketch* aSketchOpe = static_cast(aOperation); + updateLabel(aSketchOpe); connect(aSketchOpe, SIGNAL(planeSelected(double, double, double)), this, SLOT(onPlaneSelected())); } @@ -50,11 +51,16 @@ void PartSet_WidgetSketchLabel::setOperationsMgr(XGUI_OperationMgr* theMgr) void PartSet_WidgetSketchLabel::onPlaneSelected() { PartSet_OperationSketch* aSketchOpe = static_cast(sender()); - if (aSketchOpe->hasSketchPlane()) { + updateLabel(aSketchOpe); +} + +void PartSet_WidgetSketchLabel::updateLabel(PartSet_OperationSketch* theSketchOpe) +{ + if (theSketchOpe->hasSketchPlane()) { myLabel->setText(""); myLabel->setToolTip(""); } else { myLabel->setText(myText); myLabel->setToolTip(myTooltip); } -} +} \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 1419cc667..30cdaace3 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -11,6 +11,7 @@ class QLabel; class XGUI_OperationMgr; +class PartSet_OperationSketch; class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget { @@ -38,6 +39,8 @@ private slots: void onPlaneSelected(); private: + void updateLabel(PartSet_OperationSketch* theSketchOpe); + QLabel* myLabel; QString myText; QString myTooltip; diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 450954322..438078697 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -28,10 +28,10 @@ SET(PROJECT_HEADERS XGUI_ErrorDialog.h XGUI_SalomeViewer.h XGUI_ViewerProxy.h - XGUI_ViewerPrs.h XGUI_PropertyPanel.h XGUI_ContextMenuMgr.h XGUI_ModuleConnector.h + XGUI_Selection.h ) SET(PROJECT_AUTOMOC @@ -60,10 +60,10 @@ SET(PROJECT_SOURCES XGUI_ActionsMgr.cpp XGUI_ErrorDialog.cpp XGUI_ViewerProxy.cpp - XGUI_ViewerPrs.cpp XGUI_PropertyPanel.cpp XGUI_ContextMenuMgr.cpp XGUI_ModuleConnector.cpp + XGUI_Selection.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index efe3c9c12..8ecb179b3 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -6,6 +6,7 @@ #include "XGUI_Displayer.h" #include "XGUI_MainWindow.h" #include "XGUI_ViewerProxy.h" +#include "XGUI_Selection.h" #include "PartSetPlugin_Part.h" @@ -98,7 +99,7 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const { QMenu* aMenu = new QMenu(); XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QFeatureList aFeatures = aSelMgr->selectedFeatures(); + QFeatureList aFeatures = aSelMgr->selection()->selectedFeatures(); if (aFeatures.size() == 1) { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); FeaturePtr aFeature = aFeatures.first(); @@ -152,7 +153,7 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const { XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QFeatureList aFeatures = aSelMgr->selectedFeatures(); + QFeatureList aFeatures = aSelMgr->selection()->selectedFeatures(); if (aFeatures.size() > 0) { if (aFeatures.size() == 1) theMenu->addAction(action("EDIT_CMD")); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index fc9159a91..83f70bf14 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -69,65 +69,6 @@ bool XGUI_Displayer::display(FeaturePtr theFeature, } -std::list XGUI_Displayer::getSelected(const int theShapeTypeToSkip) -{ - std::set aPrsFeatures; - std::list aPresentations; - - Handle(AIS_InteractiveContext) aContext = AISContext(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { - Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); - TopoDS_Shape aShape = aContext->SelectedShape(); - - if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) - continue; - - FeaturePtr aFeature = getFeature(anIO); - if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) - continue; - Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); - aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, anOwner)); - aPrsFeatures.insert(aFeature); - } - return aPresentations; -} - -QFeatureList XGUI_Displayer::selectedFeatures() const -{ - QFeatureList aSelectedList; - - Handle(AIS_InteractiveContext) aContext = AISContext(); - for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { - Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); - FeaturePtr aFeature = getFeature(anIO); - if (aFeature) - aSelectedList.append(aFeature); - } - return aSelectedList; -} - - -std::list XGUI_Displayer::getHighlighted(const int theShapeTypeToSkip) -{ - std::set aPrsFeatures; - std::list aPresentations; - - Handle(AIS_InteractiveContext) aContext = AISContext(); - for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { - Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive(); - TopoDS_Shape aShape = aContext->DetectedShape(); - if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) - continue; - - FeaturePtr aFeature = getFeature(anIO); - if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) - continue; - aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, NULL)); - aPrsFeatures.insert(aFeature); - } - - return aPresentations; -} void XGUI_Displayer::erase(FeaturePtr theFeature, const bool isUpdateViewer) diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index a9a7fb36f..2c730c9e8 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -6,7 +6,6 @@ #define XGUI_Displayer_H #include "XGUI.h" -#include #include #include @@ -20,7 +19,8 @@ #include -#include +#include +#include #include #include @@ -64,21 +64,6 @@ public: /// Returns true if the Feature succesfully displayed bool display(FeaturePtr theFeature, boost::shared_ptr theAIS, bool isUpdateViewer = true); - /// Returns a list of viewer selected presentations - /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build - /// \return list of presentations - std::list getSelected(const int theShapeTypeToSkip = -1); - - /** - * Returns list of features currently selected in 3d viewer - */ - QFeatureList selectedFeatures() const; - - /// Returns a list of viewer highlited presentations - /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build - /// \return list of presentations - std::list getHighlighted(const int theShapeTypeToSkip = -1); - /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance /// \param theAIS an AIS object @@ -146,11 +131,12 @@ public: /// \return theIO an interactive object boost::shared_ptr getAISObject(FeaturePtr theFeature) const; -protected: /// Searches the feature by interactive object /// \param theIO an interactive object /// \return feature the feature or NULL if it not visualized FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const; + +protected: /// Deactivate local selection /// \param isUpdateViewer the state wether the viewer should be updated immediatelly void closeAllContexts(const bool isUpdateViewer); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index c00253fa7..9cb80fa22 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -7,6 +7,7 @@ #include "XGUI_Workshop.h" #include "XGUI_ViewerProxy.h" #include "XGUI_SelectionMgr.h" +#include "XGUI_Selection.h" @@ -29,7 +30,7 @@ Handle(AIS_InteractiveContext) XGUI_ModuleConnector::AISContext() const QFeatureList XGUI_ModuleConnector::selectedFeatures() const { - return myWorkshop->selector()->selectedFeatures(); + return myWorkshop->selector()->selection()->selectedFeatures(); } ModuleBase_IModule* XGUI_ModuleConnector::module() const diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp new file mode 100644 index 000000000..5900aefea --- /dev/null +++ b/src/XGUI/XGUI_Selection.cpp @@ -0,0 +1,109 @@ +// File: XGUI_Selection.cpp +// Created: 8 July 2014 +// Author: Vitaly SMETANNIKOV + +#include "XGUI_Selection.h" +#include "XGUI_Workshop.h" +#include "XGUI_Displayer.h" +#include "XGUI_ViewerProxy.h" +#include "XGUI_ObjectsBrowser.h" + +#include + +#include + +#include + + +XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop) +: myWorkshop(theWorkshop) +{ +} + +std::list XGUI_Selection::getSelected(int theShapeTypeToSkip) const +{ + std::set aPrsFeatures; + std::list aPresentations; + + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + TopoDS_Shape aShape = aContext->SelectedShape(); + + if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) + continue; + + FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO); + if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) + continue; + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, anOwner)); + aPrsFeatures.insert(aFeature); + } + return aPresentations; +} + +std::list XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const +{ + std::set aPrsFeatures; + std::list aPresentations; + + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { + Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive(); + TopoDS_Shape aShape = aContext->DetectedShape(); + if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) + continue; + + FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO); + if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) + continue; + aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, NULL)); + aPrsFeatures.insert(aFeature); + } + + return aPresentations; +} + +QFeatureList XGUI_Selection::selectedFeatures() const +{ + return myWorkshop->objectBrowser()->selectedFeatures(); + //QFeatureList aSelectedList; + + //Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + // Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + // FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO); + // if (aFeature) + // aSelectedList.append(aFeature); + //} + //return aSelectedList; +} + + +//************************************************************** +QModelIndexList XGUI_Selection::selectedIndexes() const +{ + return myWorkshop->objectBrowser()->selectedIndexes(); +} + +//************************************************************** +void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const +{ + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + theList.Clear(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) + theList.Append(aContext->SelectedInteractive()); +} + +//************************************************************** +void XGUI_Selection::selectedShapes(NCollection_List& theList) const +{ + theList.Clear(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + TopoDS_Shape aShape = aContext->SelectedShape(); + if (!aShape.IsNull()) + theList.Append(aShape); + } +} diff --git a/src/XGUI/XGUI_Selection.h b/src/XGUI/XGUI_Selection.h new file mode 100644 index 000000000..c6f92f5ff --- /dev/null +++ b/src/XGUI/XGUI_Selection.h @@ -0,0 +1,56 @@ +// File: XGUI_Selection.h +// Created: 8 July 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef XGUI_Selection_H +#define XGUI_Selection_H + +#include "XGUI.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include + +class XGUI_Workshop; + +class XGUI_EXPORT XGUI_Selection: public ModuleBase_ISelection +{ +public: + XGUI_Selection(XGUI_Workshop* theWorkshop); + + /// Returns a list of viewer selected presentations + /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build + /// \return list of presentations + std::list getSelected(int theShapeTypeToSkip = -1) const; + + /// Returns a list of viewer highlited presentations + /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build + /// \return list of presentations + std::list getHighlighted(int theShapeTypeToSkip = -1) const; + + /** + * Returns list of features currently selected in 3d viewer + */ + QFeatureList selectedFeatures() const; + + //! Returns list of currently selected QModelIndexes + QModelIndexList selectedIndexes() const; + + //! Returns list of currently selected AIS objects + void selectedAISObjects(AIS_ListOfInteractive& theList) const; + + //! Returns list of currently selected shapes + void selectedShapes(NCollection_List& theList) const; + +private: + XGUI_Workshop* myWorkshop; +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 9f830a74e..d1d9f83a0 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -6,6 +6,7 @@ #include "XGUI_SalomeConnector.h" #include "XGUI_ViewerProxy.h" #include "XGUI_Displayer.h" +#include "XGUI_Selection.h" #include #include @@ -17,10 +18,12 @@ XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) : QObject(theParent), myWorkshop(theParent) { + mySelection = new XGUI_Selection(myWorkshop); } XGUI_SelectionMgr::~XGUI_SelectionMgr() { + delete mySelection; } //************************************************************** @@ -37,24 +40,29 @@ void XGUI_SelectionMgr::connectViewers() //************************************************************** void XGUI_SelectionMgr::onObjectBrowserSelection() { - QFeatureList aFeatures = selectedFeatures(); + QFeatureList aFeatures = myWorkshop->objectBrowser()->selectedFeatures(); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); aDisplayer->setSelected(aFeatures); - emit selectionChanged(); } //************************************************************** void XGUI_SelectionMgr::onViewerSelection() { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - QFeatureList aFeatures = aDisplayer->selectedFeatures(); + QFeatureList aFeatures; + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO); + if (aFeature) + aFeatures.append(aFeature); + } myWorkshop->objectBrowser()->setFeaturesSelected(aFeatures); emit selectionChanged(); } //************************************************************** -QFeatureList XGUI_SelectionMgr::selectedFeatures() const +/*QFeatureList XGUI_SelectionMgr::selectedFeatures() const { return myWorkshop->objectBrowser()->selectedFeatures(); } @@ -84,4 +92,4 @@ void XGUI_SelectionMgr::selectedShapes(NCollection_List& theList) if (!aShape.IsNull()) theList.Append(aShape); } -} +}*/ diff --git a/src/XGUI/XGUI_SelectionMgr.h b/src/XGUI/XGUI_SelectionMgr.h index e98b52841..93f19284c 100644 --- a/src/XGUI/XGUI_SelectionMgr.h +++ b/src/XGUI/XGUI_SelectionMgr.h @@ -12,6 +12,7 @@ class XGUI_Workshop; class XGUI_ObjectsBrowser; +class XGUI_Selection; /**\class XGUI_SelectionMgr * \ingroup GUI @@ -25,17 +26,19 @@ public: XGUI_SelectionMgr(XGUI_Workshop* theParent); virtual ~XGUI_SelectionMgr(); + XGUI_Selection* selection() const { return mySelection; } + //! Returns list of currently selected data objects - QFeatureList selectedFeatures() const; + //QFeatureList selectedFeatures() const; //! Returns list of currently selected QModelIndexes - QModelIndexList selectedIndexes() const; + //QModelIndexList selectedIndexes() const; //! Returns list of currently selected AIS objects - void selectedAISObjects(AIS_ListOfInteractive& theList) const; + //void selectedAISObjects(AIS_ListOfInteractive& theList) const; //! Returns list of currently selected shapes - void selectedShapes(NCollection_List& theList) const; + //void selectedShapes(NCollection_List& theList) const; //! Connects the manager to all viewers accessible by Workshop void connectViewers(); @@ -49,8 +52,8 @@ private slots: void onViewerSelection(); private: - XGUI_Workshop* myWorkshop; + XGUI_Selection* mySelection; }; #endif diff --git a/src/XGUI/XGUI_ViewerPrs.cpp b/src/XGUI/XGUI_ViewerPrs.cpp deleted file mode 100644 index f280905a7..000000000 --- a/src/XGUI/XGUI_ViewerPrs.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// File: XGUI_ViewerPrs.cpp -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include "XGUI_ViewerPrs.h" - -#include "SelectMgr_EntityOwner.hxx" - -XGUI_ViewerPrs::XGUI_ViewerPrs() -{ -} - -XGUI_ViewerPrs::XGUI_ViewerPrs(FeaturePtr theFeature, - const TopoDS_Shape& theShape, - Handle(SelectMgr_EntityOwner) theOwner) -: myFeature(theFeature), myShape(theShape), myOwner(theOwner) -{ -} - -XGUI_ViewerPrs::~XGUI_ViewerPrs() -{ -} - -void XGUI_ViewerPrs::setFeature(FeaturePtr theFeature) -{ - myFeature = theFeature; -} - -FeaturePtr XGUI_ViewerPrs::feature() const -{ - return myFeature; -} - -void XGUI_ViewerPrs::setOwner(Handle(SelectMgr_EntityOwner) theOwner) -{ - myOwner = theOwner; -} - -Handle(SelectMgr_EntityOwner) XGUI_ViewerPrs::owner() const -{ - return myOwner; -} - -void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape) -{ - myShape = theShape; -} - -const TopoDS_Shape& XGUI_ViewerPrs::shape() const -{ - return myShape; -} - -bool XGUI_ViewerPrs::operator==(const XGUI_ViewerPrs& thePrs) -{ - bool aFeature = (myFeature.get() == thePrs.feature().get()); - bool aOwner = (myOwner.Access() == thePrs.owner().Access()); - bool aShape = myShape.IsEqual(thePrs.shape()); - return aFeature && aOwner && aShape; -} diff --git a/src/XGUI/XGUI_ViewerPrs.h b/src/XGUI/XGUI_ViewerPrs.h deleted file mode 100644 index 808640ce4..000000000 --- a/src/XGUI/XGUI_ViewerPrs.h +++ /dev/null @@ -1,67 +0,0 @@ -// File: XGUI_ViewerPrs.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef XGUI_ViewerPrs_H -#define XGUI_ViewerPrs_H - -#include "XGUI.h" - -#include -#include -#include - -#include - -/**\class XGUI_ViewerPrs - * \ingroup GUI - * \brief Presentation. Provides container to have feature, shape and/or selection owner. - */ -class XGUI_EXPORT XGUI_ViewerPrs -{ -public: - /// Constructor - XGUI_ViewerPrs(); - /// Constructor - /// \param theFeature a model feature - /// \param theShape a viewer shape - /// \param theOwner a selection owner - XGUI_ViewerPrs(FeaturePtr theFeature, - const TopoDS_Shape& theShape, - Handle_SelectMgr_EntityOwner theOwner); - /// Destructor - virtual ~XGUI_ViewerPrs(); - - /// Sets the feature. - /// \param theFeature a feature instance - void setFeature(FeaturePtr theFeature); - - /// Returns the feature. - /// \return a feature instance - FeaturePtr feature() const; - - /// Returns the presentation owner - /// \param the owner - void setOwner(Handle_SelectMgr_EntityOwner theOwner); - - /// Returns the presentation owner - /// \return an owner - Handle_SelectMgr_EntityOwner owner() const; - - /// Sets the shape - /// \param theShape a shape instance - void setShape(const TopoDS_Shape& theShape); - - /// Returns the shape - /// \return a shape instance - const TopoDS_Shape& shape() const; - - bool operator==(const XGUI_ViewerPrs&); - -private: - FeaturePtr myFeature; /// the feature - Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner - TopoDS_Shape myShape; /// the shape -}; - -#endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index c6b5f55bd..b5b0b5f6b 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -10,6 +10,7 @@ #include "XGUI_Viewer.h" #include "ModuleBase_WidgetFactory.h" #include "XGUI_SelectionMgr.h" +#include "XGUI_Selection.h" #include "XGUI_ObjectsBrowser.h" #include "XGUI_Displayer.h" #include "XGUI_OperationMgr.h" @@ -38,7 +39,7 @@ #include #include #include -#include +#include #include #include @@ -857,7 +858,7 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const //************************************************************** void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) { - QFeatureList aFeatures = mySelector->selectedFeatures(); + QFeatureList aFeatures = mySelector->selection()->selectedFeatures(); if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0)) activatePart(aFeatures.first()); else if (theId == "DEACTIVATE_PART_CMD") @@ -964,17 +965,17 @@ void XGUI_Workshop::updateCommandsOnViewSelection() { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - Handle(AIS_InteractiveContext) aContext = viewer()->AISContext(); + XGUI_Selection* aSelection = mySelector->selection(); QList aActions = getModuleCommands(); foreach(QAction* aAction, aActions) { QString aId = aAction->data().toString(); const ModelAPI_Validator* aValidator = aFactory->validator(aId.toStdString()); if (aValidator) { - const ModuleBase_ViewSelectionValidator* aSelValidator = - dynamic_cast(aValidator); + const ModuleBase_SelectionValidator* aSelValidator = + dynamic_cast(aValidator); if (aSelValidator) { - aAction->setEnabled(aSelValidator->isValid(aContext)); + aAction->setEnabled(aSelValidator->isValid(aSelection)); } } } -- 2.30.2