From f7b3f47332f05fd5a0a4ca5b9df7dc9c5b198022 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 21 May 2014 13:21:18 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Hide preview by clicking "Apply" or "Abort" button in the sketch operation. --- src/PartSet/PartSet_Module.cpp | 43 +++++++++++++++------ src/PartSet/PartSet_Module.h | 3 ++ src/PartSet/PartSet_OperationSketch.cpp | 11 +++++- src/PartSet/PartSet_OperationSketch.h | 7 +++- src/PartSet/PartSet_OperationSketchBase.cpp | 2 +- src/PartSet/PartSet_OperationSketchBase.h | 9 ++--- src/PartSet/PartSet_OperationSketchLine.cpp | 2 +- 7 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index f3d111335..b54dc192a 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -164,15 +164,6 @@ void PartSet_Module::onKeyRelease(QKeyEvent* theEvent) void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) { myWorkshop->viewer()->setViewProjection(theX, theY, theZ); - - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - if (anOperation) { - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - visualizePreview(aPreviewOp->feature(), false); - } - } - myWorkshop->actionsMgr()->setNestedActionsEnabled(true); } @@ -216,11 +207,36 @@ void PartSet_Module::onSetSelection(const std::list& theFeatures aDisplayer->UpdateViewer(); } +void PartSet_Module::onCloseLocalContext() +{ + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->CloseLocalContexts(); +} + void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, int theMode) { - bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort; + bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; visualizePreview(theFeature, isDisplay, false); + if (!isDisplay) { + ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); + boost::shared_ptr aSketch; + PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); + if (aPrevOp) { + std::map, boost::shared_ptr > + aList = aPrevOp->subPreview(); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + std::list aModes = aPrevOp->getSelectionModes(aPrevOp->feature()); + + std::map, boost::shared_ptr >::const_iterator + anIt = aList.begin(), aLast = aList.end(); + for (; anIt != aLast; anIt++) { + boost::shared_ptr aFeature = (*anIt).first; + visualizePreview(aFeature, false, false); + } + aDisplayer->UpdateViewer(); + } + } if (theMode == PartSet_OperationSketchBase::FM_Activation || theMode == PartSet_OperationSketchBase::FM_Deactivation) @@ -279,6 +295,9 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI connect(aPreviewOp, SIGNAL(setSelection(const std::list&)), this, SLOT(onSetSelection(const std::list&))); + connect(aPreviewOp, SIGNAL(closeLocalContext()), + this, SLOT(onCloseLocalContext())); + PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), @@ -316,7 +335,7 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea aPreview ? aPreview->impl() : TopoDS_Shape(), false); } else - aDisplayer->Erase(anOperation->feature(), false); + aDisplayer->Erase(theFeature, false); if (isUpdateViewer) aDisplayer->UpdateViewer(); @@ -349,7 +368,7 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) return; std::map, boost::shared_ptr > - aList = aPreviewOp->preview(); + aList = aPreviewOp->subPreview(); XGUI_Displayer* aDisplayer = myWorkshop->displayer(); std::list aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature()); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index acd550257..17dc20348 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -101,6 +101,9 @@ public slots: /// \param theFeatures a list of features to be selected void onSetSelection(const std::list& theFeatures); + /// SLOT, to close the viewer local context + void onCloseLocalContext(); + /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode /// \param theMode the mode appeared on the feature diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 4c4aa241d..d527cd0f3 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -100,7 +100,7 @@ void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) } std::map, boost::shared_ptr > - PartSet_OperationSketch::preview() const + PartSet_OperationSketch::subPreview() const { std::map, boost::shared_ptr > aPreviewMap; @@ -122,6 +122,13 @@ std::map, boost::shared_ptr > return aPreviewMap; } +void PartSet_OperationSketch::stopOperation() +{ + PartSet_OperationSketchBase::stopOperation(); + emit featureConstructed(feature(), FM_Hide); + emit closeLocalContext(); +} + void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) { if (theShape.IsNull()) @@ -160,5 +167,7 @@ void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); aDirY->setValue(aC, anA, aB); boost::shared_ptr aDir = aPlane->direction(); + emit featureConstructed(feature(), FM_Hide); + emit closeLocalContext(); emit planeSelected(aDir->x(), aDir->y(), aDir->z()); } diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index e964939d4..fbb0eb376 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -58,7 +58,12 @@ public: /// Returns the map of the operation previews including the nested feature previews /// \return the map of feature to the feature preview virtual std::map, boost::shared_ptr > - preview() const; + subPreview() const; + + /// Virtual method called when operation stopped - committed or aborted. + /// Emits a signal to hide the preview of the operation + virtual void stopOperation(); + signals: /// signal about the sketch plane is selected /// \param theX the value in the X direction of the plane diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 3a02de8b8..18fdea1fd 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -40,7 +40,7 @@ boost::shared_ptr PartSet_OperationSketchBase::preview( } std::map, boost::shared_ptr > - PartSet_OperationSketchBase::preview() const + PartSet_OperationSketchBase::subPreview() const { return std::map, boost::shared_ptr >(); } diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 33b9e1d04..0045a8e87 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -31,7 +31,7 @@ class PARTSET_EXPORT PartSet_OperationSketchBase : public ModuleBase_Operation { Q_OBJECT public: - enum FeatureActionMode { FM_Activation, FM_Deactivation, FM_Abort }; + enum FeatureActionMode { FM_Activation, FM_Deactivation, FM_Hide }; public: /// Constructor @@ -47,7 +47,7 @@ public: /// Returns the map of the operation previews including the nested feature previews /// \return the map of feature to the feature preview - virtual std::map, boost::shared_ptr > preview() const; + virtual std::map, boost::shared_ptr > subPreview() const; /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode @@ -112,9 +112,8 @@ signals: /// \param theFeatures a list of features to be disabled void setSelection(const std::list& theFeatures); - /// signal to enable/disable usual selection in the viewer - /// \param theEnabled the boolean state - void selectionEnabled(bool theEnabled); + /// signal to close the operation local context if it is opened + void closeLocalContext(); protected: /// Creates an operation new feature diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 36c969305..6b64cd275 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -213,7 +213,7 @@ void PartSet_OperationSketchLine::startOperation() void PartSet_OperationSketchLine::abortOperation() { - emit featureConstructed(feature(), FM_Abort); + emit featureConstructed(feature(), FM_Hide); PartSet_OperationSketchBase::abortOperation(); } -- 2.39.2