From b2b1518f7ce57ca8ccf6fd596657220711841fd7 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 5 May 2014 15:22:19 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines The "Return", "Escape" buttons processing. --- src/ModuleBase/ModuleBase_Operation.cpp | 14 ++++-- src/ModuleBase/ModuleBase_Operation.h | 3 ++ src/PartSet/PartSet_Module.cpp | 16 ++++--- src/PartSet/PartSet_Module.h | 4 +- src/PartSet/PartSet_OperationSketchBase.h | 7 ++- src/PartSet/PartSet_OperationSketchLine.cpp | 41 +++++++++++------ src/PartSet/PartSet_OperationSketchLine.h | 4 ++ src/XGUI/XGUI_Displayer.cpp | 51 ++++++++------------- src/XGUI/XGUI_Displayer.h | 8 +--- 9 files changed, 81 insertions(+), 67 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 8c2f4a274..908f2f0c5 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #ifdef _DEBUG @@ -67,10 +66,7 @@ void ModuleBase_Operation::storeCustomValue() void ModuleBase_Operation::startOperation() { - boost::shared_ptr aDoc = ModelAPI_PluginManager::get()->rootDocument(); - myFeature = aDoc->addFeature(getDescription()->operationId().toStdString()); - if (myFeature) // TODO: generate an error if feature was not created - myFeature->execute(); + createFeature(); //emit callSlot(); //commit(); } @@ -87,3 +83,11 @@ void ModuleBase_Operation::commitOperation() { if (myFeature) myFeature->execute(); } + +void ModuleBase_Operation::createFeature() +{ + boost::shared_ptr aDoc = document(); + myFeature = aDoc->addFeature(getDescription()->operationId().toStdString()); + if (myFeature) // TODO: generate an error if feature was not created + myFeature->execute(); +} diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index c9d7588d5..4632ad455 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -70,6 +70,9 @@ protected: /// Virtual method called when operation committed (see commit() method for more description) virtual void commitOperation(); + /// Creates a new feature and save it in the operation internal field + virtual void createFeature(); + private: boost::shared_ptr myFeature; /// the operation feature to be handled }; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index d38cc9f0a..59cec6d98 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -143,8 +143,8 @@ void PartSet_Module::onOperationStarted() if (aPreviewOp) { visualizePreview(aPreviewOp->feature(), true); - connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr)), - this, SLOT(onFeatureConstructed(boost::shared_ptr))); + connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr, int)), + this, SLOT(onFeatureConstructed(boost::shared_ptr, int))); PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); if (aSketchOp) { @@ -233,9 +233,11 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) myWorkshop->actionsMgr()->setNestedActionsEnabled(true); } -void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature) +void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, + int theMode) { - visualizePreview(theFeature, true); + bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort; + visualizePreview(theFeature, isDisplay); } void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay) @@ -252,12 +254,12 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); if (aPreview) { - aDisplayer->DisplayInLocalContext(theFeature, aPreview->impl(), - aPreviewOp->getSelectionMode(theFeature)); + aDisplayer->RedisplayInLocalContext(theFeature, aPreview->impl(), + aPreviewOp->getSelectionMode(theFeature)); } } else { - aDisplayer->CloseLocalContexts(false); + //aDisplayer->CloseLocalContexts(false); aDisplayer->Erase(anOperation->feature()); } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index a67b8d038..1f3197bd9 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -71,7 +71,9 @@ public slots: /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode - void onFeatureConstructed(boost::shared_ptr theFeature); + /// \param theMode the mode appeared on the feature + void onFeatureConstructed(boost::shared_ptr theFeature, + int theMode); private: XGUI_Workshop* myWorkshop; diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 6b419b080..0cb2900d7 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -25,6 +25,9 @@ class GeomAPI_Shape; class PARTSET_EXPORT PartSet_OperationSketchBase : public ModuleBase_Operation { Q_OBJECT +public: + enum FeatureActionMode { FM_Activation, FM_Deactivation, FM_Abort }; + public: /// Constructor /// \param theId an feature index @@ -61,7 +64,9 @@ public: signals: /// Signal about the feature construing is finished /// \param theFeature the result feature - void featureConstructed(boost::shared_ptr theFeature); + /// \param theMode the mode of the feature modification + void featureConstructed(boost::shared_ptr theFeature, + int theMode); public: /// temporary code to provide edition mode diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 5bc516c39..69590f33a 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -88,7 +88,7 @@ void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint) setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START); myPointSelectionMode = SM_SecondPoint; - emit featureConstructed(aPrevFeature); + emit featureConstructed(aPrevFeature, FM_Deactivation); } break; default: @@ -99,27 +99,28 @@ void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint) void PartSet_OperationSketchLine::keyReleased(const int theKey) { switch (theKey) { - case Qt::Key_Escape: + case Qt::Key_Escape: { + if (myPointSelectionMode != SM_None) + emit featureConstructed(feature(), FM_Abort); abort(); - break; - case Qt::Key_Enter: - //myPointSelectionMode = myPointSelectionMode; - break; + } + break; + case Qt::Key_Return: { + if (myPointSelectionMode != SM_None) { + emit featureConstructed(feature(), FM_Abort); + myPointSelectionMode = SM_FirstPoint; + document()->abortOperation(); + } + } + break; default: - break; + break; } } void PartSet_OperationSketchLine::startOperation() { PartSet_OperationSketchBase::startOperation(); - - if (mySketch) { - boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(mySketch); - - aFeature->addSub(feature()); - } myPointSelectionMode = SM_FirstPoint; } @@ -129,6 +130,18 @@ void PartSet_OperationSketchLine::stopOperation() myPointSelectionMode = SM_None; } +void PartSet_OperationSketchLine::createFeature() +{ + PartSet_OperationSketchBase::createFeature(); + if (mySketch) { + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(mySketch); + + aFeature->addSub(feature()); + } + //emit featureConstructed(aPrevFeature, FM_Activation); +} + void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute) { diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 86b1eaceb..939cdef7f 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -65,6 +65,10 @@ protected: /// After the parent operation body perform, reset selection point mode of the operation virtual void stopOperation(); + /// Creates a new feature and save it in the operation internal field. + /// In addition to the default realization it set a sketch feature to the created feature + virtual void createFeature(); + protected: /// \brief Save the point to the line. /// \param thePoint the 3D point in the viewer diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index dcfe8385d..8d7b6ef9d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -70,14 +70,15 @@ void XGUI_Displayer::Erase(boost::shared_ptr theFeature, continue; aContext->Erase(anAISShape); } + myFeature2AISObjectMap.erase(theFeature); if (isUpdateViewer) aContext->UpdateCurrentViewer(); } -void XGUI_Displayer::DisplayInLocalContext(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, - const int theMode, const bool isUpdateViewer) +void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape, + const int theMode, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -92,49 +93,35 @@ void XGUI_Displayer::DisplayInLocalContext(boost::shared_ptr t } aDispAIS.push_back(anAIS); myFeature2AISObjectMap[theFeature] = aDispAIS; - aContext->Display(anAIS, Standard_False); - - AIS_ListOfInteractive anAISList; - anAISList.Append(anAIS); - activateInLocalContext(anAISList, theMode, true); -} - -void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer) -{ - closeAllContexts(true); -} -void XGUI_Displayer::activateInLocalContext(const AIS_ListOfInteractive& theAISObjects, const int theMode, - const bool isUpdateViewer) -{ Handle(AIS_InteractiveContext) ic = AISContext(); // Open local context if there is no one - bool allObjects = false; // calculate by AIS shape if (!ic->HasOpenedContext()) { ic->ClearCurrents(false); - ic->OpenLocalContext(allObjects, true, true); + ic->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/, + true/*allow shape decomposition*/); } - // Activate selection of objects from prs - AIS_ListIteratorOfListOfInteractive aIter(theAISObjects); - for (; aIter.More(); aIter.Next()) { - Handle(AIS_InteractiveObject) anAIS = aIter.Value(); - if (!anAIS.IsNull()) { - if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) { - ic->Load(anAIS, -1, false); - ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode)); - } - else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) { - ic->Load(anAIS, -1, false); - ic->Activate(anAIS, theMode); - } + if (!anAIS.IsNull()) { + if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) { + ic->Display(anAIS, 0/*display mode*/, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode), + false/*update viewer*/, true/*allow decomposition*/); + /*if (theMode == TopAbs_VERTEX) { + ic->ActivateStandardMode(TopAbs_EDGE); + ic->ActivateStandardMode(TopAbs_VERTEX); + }*/ } } if (isUpdateViewer) ic->UpdateCurrentViewer(); } +void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer) +{ + closeAllContexts(true); +} + void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer) { Handle(AIS_InteractiveContext) ic = AISContext(); diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 9299a8198..3ca9b964c 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -59,7 +59,7 @@ public: /// \param theShape a shape /// \param theMode a local selection mode /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void DisplayInLocalContext(boost::shared_ptr theFeature, + void RedisplayInLocalContext(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, const int theMode, const bool isUpdateViewer = true); @@ -73,12 +73,6 @@ public: void CloseLocalContexts(const bool isUpdateViewer = true); protected: - /// Activate local selection - /// \param theAIS the list of objects - /// \param theMode the selection mode - /// \param isUpdateViewer the state wether the viewer should be updated immediatelly - void activateInLocalContext(const AIS_ListOfInteractive& theAISObjects, const int theMode, - const bool isUpdateViewer); /// Deactivate local selection /// \param isUpdateViewer the state wether the viewer should be updated immediatelly void closeAllContexts(const bool isUpdateViewer); -- 2.39.2