From f4bd13ed4b2456d13a8d58fd0bc4029264592815 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 26 Jun 2014 17:23:46 +0400 Subject: [PATCH] Working with pre-selection in sketch operations --- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 7 +++++-- src/PartSet/PartSet_Module.cpp | 16 ++++++++-------- src/PartSet/PartSet_OperationFeatureCreate.cpp | 13 ++++++++++--- src/PartSet/PartSet_OperationFeatureCreate.h | 2 ++ src/XGUI/XGUI_ViewerPrs.cpp | 8 ++++++++ src/XGUI/XGUI_ViewerPrs.h | 2 ++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 28ddf17a2..baa7285b0 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -80,8 +80,11 @@ bool ModuleBase_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) ModuleBase_WidgetValueFeature* aFeatureValue = dynamic_cast(theValue); if (aFeatureValue) { - setPoint(aFeatureValue->point()); - isDone = true; + boost::shared_ptr aPoint = aFeatureValue->point(); + if (aPoint) { + setPoint(aPoint); + isDone = true; + } } } return isDone; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 5ecb14ba7..d9009a68f 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -138,14 +138,14 @@ void PartSet_Module::onFeatureTriggered() 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(); - // // Initialise operation with preliminary selection - // std::list aSelected = aDisplayer->getSelected(); - // std::list aHighlighted = aDisplayer->getHighlighted(); - // aPreviewOp->initSelection(aSelected, aHighlighted); - //} + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) { + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + // Initialise operation with preliminary selection + std::list aSelected = aDisplayer->getSelected(); + std::list aHighlighted = aDisplayer->getHighlighted(); + aPreviewOp->initSelection(aSelected, aHighlighted); + } sendOperation(anOperation); } diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 41a30c5d3..6007204ac 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -86,12 +86,11 @@ std::list PartSet_OperationFeatureCreate::getSelectionModes(FeaturePtr theF void PartSet_OperationFeatureCreate::initSelection(const std::list& theSelected, const std::list& /*theHighlighted*/) { + myPreSelection = theSelected; } void PartSet_OperationFeatureCreate::initFeature(FeaturePtr theFeature) { - //if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) - // return; myInitFeature = theFeature; } @@ -190,7 +189,15 @@ void PartSet_OperationFeatureCreate::keyReleased(std::string theName, QKeyEvent* void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget) { myActiveWidget = theWidget; - + if (myPreSelection.size() > 0) { + const XGUI_ViewerPrs& aPrs = myPreSelection.front(); + ModuleBase_WidgetValueFeature aValue; + aValue.setFeature(aPrs.feature()); + if (myActiveWidget->setValue(&aValue)) { + myPreSelection.remove(aPrs); + emit activateNextWidget(myActiveWidget); + } + } if (myInitFeature && myActiveWidget) { ModuleBase_WidgetPoint2D* aWgt = dynamic_cast(myActiveWidget); if (aWgt && aWgt->initFromPrevious(myInitFeature)) { diff --git a/src/PartSet/PartSet_OperationFeatureCreate.h b/src/PartSet/PartSet_OperationFeatureCreate.h index d6ca0c77b..ee711b1bc 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.h +++ b/src/PartSet/PartSet_OperationFeatureCreate.h @@ -127,6 +127,8 @@ private: FeaturePtr mySketch; ///< the sketch of the feature ModuleBase_ModelWidget* myActiveWidget; ///< the active widget + + std::list myPreSelection; }; #endif diff --git a/src/XGUI/XGUI_ViewerPrs.cpp b/src/XGUI/XGUI_ViewerPrs.cpp index e0958f76f..f280905a7 100644 --- a/src/XGUI/XGUI_ViewerPrs.cpp +++ b/src/XGUI/XGUI_ViewerPrs.cpp @@ -50,3 +50,11 @@ 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 index 585b65cc3..808640ce4 100644 --- a/src/XGUI/XGUI_ViewerPrs.h +++ b/src/XGUI/XGUI_ViewerPrs.h @@ -56,6 +56,8 @@ public: /// \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 -- 2.39.2