From: nds Date: Tue, 6 May 2014 06:48:07 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~85^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=242d94c4e12eb2c2da5a324206b8364e4215c805;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Correct displayer to cash in an internal map one AIS for one feature (there was a vector of AIS). Reuse AIS for the same feature in Redisplay. --- diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index a9c1eb2cb..3e1c4886a 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -6,6 +6,8 @@ #include +#include + #include #include @@ -34,6 +36,7 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) { const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); boost::shared_ptr aFeature = aUpdMsg->feature(); - myModule->visualizePreview(aFeature, true); + if (myModule->workshop()->displayer()->IsVisible(aFeature)) + myModule->visualizePreview(aFeature, true); } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c23955263..39af2f3d5 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -52,7 +52,6 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); - connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); @@ -70,6 +69,11 @@ PartSet_Module::~PartSet_Module() { } +XGUI_Workshop* PartSet_Module::workshop() const +{ + return myWorkshop; +} + void PartSet_Module::createFeatures() { Config_ModuleReader aXMLReader = Config_ModuleReader(); @@ -110,34 +114,11 @@ void PartSet_Module::launchOperation(const QString& theCmdId) sendOperation(anOperation); } -void PartSet_Module::onOperationStarted() -{ - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - visualizePreview(aPreviewOp->feature(), true); - - connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr, int)), - this, SLOT(onFeatureConstructed(boost::shared_ptr, int))); - connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr)), - this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); - - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), - this, SLOT(onPlaneSelected(double, double, double))); - } - } -} - void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) { if (!theOperation) return; PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(theOperation); - //if (aPreviewOp) - // visualizePreview(false); } void PartSet_Module::onSelectionChanged() @@ -264,6 +245,21 @@ ModuleBase_Operation* PartSet_Module::createOperation(const QString& theCmdId) anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); anOperation->getDescription()->setDescription(QString::fromStdString(aDescription)); + // connect + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) { + connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr, int)), + this, SLOT(onFeatureConstructed(boost::shared_ptr, int))); + connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr)), + this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); + + PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); + if (aSketchOp) { + connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), + this, SLOT(onPlaneSelected(double, double, double))); + } + } + return anOperation; } @@ -289,10 +285,9 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); - if (aPreview) { - aDisplayer->RedisplayInLocalContext(theFeature, aPreview->impl(), - aPreviewOp->getSelectionModes(theFeature)); - } + aDisplayer->RedisplayInLocalContext(theFeature, + aPreview ? aPreview->impl() : TopoDS_Shape(), + aPreviewOp->getSelectionModes(theFeature)); } else { //aDisplayer->CloseLocalContexts(false); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 8f0a0b086..68fe21e6f 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -26,6 +26,10 @@ public: PartSet_Module(XGUI_Workshop* theWshop); virtual ~PartSet_Module(); + /// Returns the module workshop + /// \returns a workshop instance + XGUI_Workshop* workshop() const; + virtual void createFeatures(); virtual void featureCreated(XGUI_Command* theFeature); virtual QStringList nestedFeatures(QString theFeature); @@ -42,9 +46,6 @@ public: public slots: void onFeatureTriggered(); - /// SLOT, that is called after the operation is started. Perform some specific for module - /// actions, e.g. connect the sketch feature to the viewer selection and show the sketch preview. - void onOperationStarted(); /// SLOT, that is called after the operation is stopped. Disconnect the sketch feature /// from the viewer selection and show the sketch preview. void onOperationStopped(ModuleBase_Operation* theOperation); diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 6c274b66e..5bd17a0f9 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -22,7 +22,7 @@ using namespace std; PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) -: PartSet_OperationSketchBase(theId, theParent) +: PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false) { } @@ -33,7 +33,7 @@ PartSet_OperationSketch::~PartSet_OperationSketch() std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature) const { std::list aModes; - if (!isEditMode()) + if (!myIsEditMode) aModes.push_back(TopAbs_FACE); return aModes; } @@ -41,9 +41,9 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr theFeature, const TopoDS_Shape& theShape) { - if (!isEditMode()) { + if (!myIsEditMode) { setSketchPlane(theShape); - setEditMode(true); + myIsEditMode = true; } else if (theFeature) emit launchOperation("EditLine", theFeature); diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 9250595c4..47cb5031f 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -47,6 +47,9 @@ protected: /// Set the plane to the current sketch /// \param theShape the shape void setSketchPlane(const TopoDS_Shape& theShape); + +private: + bool myIsEditMode; /// the edit mode of this operation }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index d1f4533a0..d424849b1 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -16,7 +16,6 @@ PartSet_OperationSketchBase::PartSet_OperationSketchBase(const QString& theId, QObject* theParent) : ModuleBase_Operation(theId, theParent) { - setEditMode(false); } PartSet_OperationSketchBase::~PartSet_OperationSketchBase() @@ -30,3 +29,10 @@ boost::shared_ptr PartSet_OperationSketchBase::preview( boost::dynamic_pointer_cast(theFeature); return aFeature->preview(); } + +boost::shared_ptr PartSet_OperationSketchBase::createFeature() +{ + boost::shared_ptr aFeature = ModuleBase_Operation::createFeature(); + emit featureConstructed(aFeature, FM_Activation); + return aFeature; +} diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 7814bc935..aeeb7c842 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -78,13 +78,12 @@ signals: /// theFeature the operation argument void launchOperation(std::string theName, boost::shared_ptr theFeature); -public: - /// temporary code to provide edition mode - void setEditMode(const bool isEditMode) { myIsEditMode = isEditMode; }; protected: - bool isEditMode() const { return myIsEditMode; } -private: - bool myIsEditMode; + /// Creates an operation new feature + /// In addition to the default realization it appends the created line feature to + /// the sketch feature + /// \returns the created feature + virtual boost::shared_ptr createFeature(); }; #endif diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 21f09e9c1..e3a3c0f53 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -40,8 +40,10 @@ bool PartSet_OperationSketchLine::isGranted() const std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr theFeature) const { std::list aModes; - if (theFeature != feature()) + if (theFeature != feature()) { aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_EDGE); + } return aModes; } @@ -134,14 +136,14 @@ void PartSet_OperationSketchLine::stopOperation() boost::shared_ptr PartSet_OperationSketchLine::createFeature() { - boost::shared_ptr aNewFeature = PartSet_OperationSketchBase::createFeature(); + boost::shared_ptr aNewFeature = ModuleBase_Operation::createFeature(); if (mySketch) { boost::shared_ptr aFeature = boost::dynamic_pointer_cast(mySketch); aFeature->addSub(aNewFeature); } - //emit featureConstructed(aNewFeature, FM_Activation); + emit featureConstructed(aNewFeature, FM_Activation); return aNewFeature; } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 8e79d48fb..7fcc29894 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -40,15 +40,9 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, Handle(AIS_InteractiveContext) aContext = AISContext(); Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); - std::vector aDispAIS; - if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) { - aDispAIS = myFeature2AISObjectMap[theFeature]; - } - aDispAIS.push_back(anAIS); - myFeature2AISObjectMap[theFeature] = aDispAIS; + myFeature2AISObjectMap[theFeature] = anAIS; aContext->Display(anAIS, Standard_False); - if (isUpdateViewer) aContext->UpdateCurrentViewer(); } @@ -61,19 +55,12 @@ boost::shared_ptr XGUI_Displayer::GetFeature(const TopoDS_Shap aFLast = myFeature2AISObjectMap.end(); for (; aFIt != aFLast && !aFeature; aFIt++) { - std::vector aDispAIS = (*aFIt).second; - std::vector::const_iterator anIt = aDispAIS.begin(), - aLast = aDispAIS.end(); - Handle(AIS_InteractiveContext) aContext = AISContext(); - for (; anIt != aLast && !aFeature; anIt++) { - Handle(AIS_InteractiveObject) anAIS = *anIt; - Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); - if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) { - aFeature = (*aFIt).first; - } + Handle(AIS_InteractiveObject) anAIS = (*aFIt).second; + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) { + aFeature = (*aFIt).first; } } - return aFeature; } @@ -83,16 +70,12 @@ void XGUI_Displayer::Erase(boost::shared_ptr theFeature, if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end()) return; - std::vector aDispAIS = myFeature2AISObjectMap[theFeature]; - std::vector::const_iterator anIt = aDispAIS.begin(), - aLast = aDispAIS.end(); Handle(AIS_InteractiveContext) aContext = AISContext(); - for (; anIt != aLast; anIt++) { - Handle(AIS_InteractiveObject) anAIS = *anIt; - Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); - if (anAISShape.IsNull()) - continue; - aContext->Erase(anAISShape); + Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[theFeature]; + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull()) + { + aContext->Erase(anAISShape); } myFeature2AISObjectMap.erase(theFeature); @@ -105,39 +88,38 @@ void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr const std::list& theModes, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); - - if (IsVisible(theFeature)) { - Erase(theFeature, false); - } - - Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); - std::vector aDispAIS; - if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) { - aDispAIS = myFeature2AISObjectMap[theFeature]; - } - aDispAIS.push_back(anAIS); - myFeature2AISObjectMap[theFeature] = aDispAIS; - - Handle(AIS_InteractiveContext) ic = AISContext(); - // Open local context if there is no one - if (!ic->HasOpenedContext()) { - ic->ClearCurrents(false); - ic->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/, + if (!aContext->HasOpenedContext()) { + aContext->ClearCurrents(false); + aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/, true/*allow shape decomposition*/); } + // display or redisplay presentation + Handle(AIS_Shape) anAIS; + if (IsVisible(theFeature)) { + anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]); + if (!anAIS.IsNull()) { + anAIS->Set(theShape); + anAIS->Redisplay(); + } + } + else { + anAIS = new AIS_Shape(theShape); + myFeature2AISObjectMap[theFeature] = anAIS; + aContext->Display(anAIS, false); + } // Activate selection of objects from prs if (!anAIS.IsNull()) { - if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) { - ic->Display(anAIS, false); - ic->Load(anAIS, -1, true/*allow decomposition*/); - std::list::const_iterator anIt = theModes.begin(), aLast = theModes.end(); - for (; anIt != aLast; anIt++) - ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt)); + aContext->Load(anAIS, -1, true/*allow decomposition*/); + std::list::const_iterator anIt = theModes.begin(), aLast = theModes.end(); + for (; anIt != aLast; anIt++) + { + aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt)); } } + if (isUpdateViewer) - ic->UpdateCurrentViewer(); + aContext->UpdateCurrentViewer(); } void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer) diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index a7f043d8e..d8da366e8 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -88,7 +88,7 @@ protected: protected: XGUI_Workshop* myWorkshop; - typedef std::map, std::vector > FeatureToAISMap; + typedef std::map, Handle(AIS_InteractiveObject) > FeatureToAISMap; FeatureToAISMap myFeature2AISObjectMap; };