]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 6 May 2014 06:48:07 +0000 (10:48 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 6 May 2014 06:48:07 +0000 (10:48 +0400)
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.

src/PartSet/PartSet_Listener.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h

index a9c1eb2cb68dbe3e401a5fe2a5e04c845200de14..3e1c4886a78f352827be6aadb1a0727f45f02a33 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <PartSet_Module.h>
 
+#include <XGUI_Displayer.h>
+
 #include <Events_Loop.h>
 #include <Model_Events.h>
 
@@ -34,6 +36,7 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage)
   {
     const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
     boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
-    myModule->visualizePreview(aFeature, true);
+    if (myModule->workshop()->displayer()->IsVisible(aFeature))
+      myModule->visualizePreview(aFeature, true);
   }
 }
index c2395526332dd47134b980e56fd1fbf2b320e115..39af2f3d58f281da6d19b1c8de878aedfa1a43d2 100644 (file)
@@ -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<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    visualizePreview(aPreviewOp->feature(), true);
-
-    connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
-            this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)));
-    connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)),
-            this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
-
-    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(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<PartSet_OperationSketchBase*>(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<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp) {
+    connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
+            this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)));
+    connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)),
+            this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
+
+    PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(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<ModelAPI_Feature> theFea
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
     boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
-    if (aPreview) {
-      aDisplayer->RedisplayInLocalContext(theFeature, aPreview->impl<TopoDS_Shape>(),
-                                          aPreviewOp->getSelectionModes(theFeature));
-    }
+    aDisplayer->RedisplayInLocalContext(theFeature,
+                                        aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+                                        aPreviewOp->getSelectionModes(theFeature));
   }
   else {
     //aDisplayer->CloseLocalContexts(false);
index 8f0a0b086d86b13e44640dc61f0df152035fafb1..68fe21e6ff22071e2d03136e57feaa5ae5b260cf 100644 (file)
@@ -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);
index 6c274b66ef432c3cfcb74e28b4a63f452656b821..5bd17a0f9cb9a09295be05ea82c8080efc02c4c7 100644 (file)
@@ -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<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   std::list<int> aModes;
-  if (!isEditMode())
+  if (!myIsEditMode)
     aModes.push_back(TopAbs_FACE);
   return aModes;
 }
@@ -41,9 +41,9 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
 void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
                                           const TopoDS_Shape& theShape)
 {
-  if (!isEditMode()) {
+  if (!myIsEditMode) {
     setSketchPlane(theShape);
-    setEditMode(true);
+    myIsEditMode = true;
   }
   else if (theFeature)
     emit launchOperation("EditLine", theFeature);
index 9250595c47c6b0e9fc62e94e634c819ea5d3a463..47cb5031f01bb3e0478f382438311928f83581f6 100644 (file)
@@ -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
index d1f4533a0f5cd8ec5445a5e7a86c1cd506801a82..d424849b1364f96560a8dadced238af6cc30b4a8 100644 (file)
@@ -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<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
                               boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
   return aFeature->preview();
 }
+
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
+{
+  boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature();
+  emit featureConstructed(aFeature, FM_Activation);
+  return aFeature;
+}
index 7814bc9357ea18b4965e130e49db9bf719cf8a57..aeeb7c842ddfb21e488aa185d0a5cf048ef8dfda 100644 (file)
@@ -78,13 +78,12 @@ signals:
   /// theFeature the operation argument
   void launchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Feature> createFeature();
 };
 
 #endif
index 21f09e9c1f125e3004b8dbb6a4f78e6fde177541..e3a3c0f532d530cf3084de7e94cc2c161da8e255 100644 (file)
@@ -40,8 +40,10 @@ bool PartSet_OperationSketchLine::isGranted() const
 std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
   std::list<int> 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<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
 {
-  boost::shared_ptr<ModelAPI_Feature> aNewFeature = PartSet_OperationSketchBase::createFeature();
+  boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
   if (mySketch) {
     boost::shared_ptr<SketchPlugin_Feature> aFeature = 
                            boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
 
     aFeature->addSub(aNewFeature);
   }
-  //emit featureConstructed(aNewFeature, FM_Activation);
+  emit featureConstructed(aNewFeature, FM_Activation);
   return aNewFeature;
 }
 
index 8e79d48fb93b9b0c7f64b8f65d1c2b4ec2f40767..7fcc298946e8bd924de520fd175663c1fe95f8a1 100644 (file)
@@ -40,15 +40,9 @@ void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
   Handle(AIS_InteractiveContext) aContext = AISContext();
 
   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
-  std::vector<Handle(AIS_InteractiveObject)> 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<ModelAPI_Feature> XGUI_Displayer::GetFeature(const TopoDS_Shap
                                   aFLast = myFeature2AISObjectMap.end();
   for (; aFIt != aFLast && !aFeature; aFIt++)
   {
-    std::vector<Handle(AIS_InteractiveObject)> aDispAIS = (*aFIt).second;
-    std::vector<Handle(AIS_InteractiveObject)>::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<ModelAPI_Feature> theFeature,
   if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
     return;
 
-  std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
-  std::vector<Handle(AIS_InteractiveObject)>::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<ModelAPI_Feature>
                                              const std::list<int>& 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<Handle(AIS_InteractiveObject)> 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<int>::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<int>::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)
index a7f043d8e942453888165d1a2a3d6f29bd85298a..d8da366e8a4ca4e5a7b5e5af310e5f13e18d1d26 100644 (file)
@@ -88,7 +88,7 @@ protected:
 protected:
   XGUI_Workshop* myWorkshop;
 
-  typedef std::map<boost::shared_ptr<ModelAPI_Feature>, std::vector<Handle(AIS_InteractiveObject)> > FeatureToAISMap;
+  typedef std::map<boost::shared_ptr<ModelAPI_Feature>, Handle(AIS_InteractiveObject) > FeatureToAISMap;
   FeatureToAISMap myFeature2AISObjectMap;
 };