Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 149c5d8e8acfee249ccac3bfa1ed843b505252c5..7d5751707a40a97f613130f259a244ecddf58538 100644 (file)
@@ -1,6 +1,6 @@
 #include <PartSet_Module.h>
 #include <PartSet_OperationSketch.h>
-#include <PartSet_OperationSketchLine.h>
+#include <PartSet_OperationCreateFeature.h>
 #include <PartSet_OperationEditLine.h>
 #include <PartSet_OperationConstraint.h>
 #include <ModuleBase_Operation.h>
@@ -25,6 +25,8 @@
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_Tools.h>
 
+#include <SketchPlugin_Line.h>
+
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
 #include <Config_WidgetReader.h>
@@ -221,7 +223,7 @@ void PartSet_Module::onFitAllView()
   myWorkshop->viewer()->fitAll();
 }
 
-void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature)
 {
   ModuleBase_Operation* anOperation = createOperation(theName.c_str());
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
@@ -233,7 +235,7 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
     std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted(TopAbs_VERTEX);
     aPreviewOp->init(theFeature, aSelected, aHighlighted);
   } else {
-    anOperation->setFeature(theFeature);
+    anOperation->setEditingFeature(theFeature);
   }
   sendOperation(anOperation);
   myWorkshop->actionsMgr()->updateCheckState();
@@ -250,7 +252,7 @@ void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeature
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (!isStop) {
     std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
-    boost::shared_ptr<ModelAPI_Feature> aFeature;
+    FeaturePtr aFeature;
     for (; anIt != aLast; anIt++) {
       activateFeature((*anIt).feature(), false);
     }
@@ -276,25 +278,23 @@ void PartSet_Module::onCloseLocalContext()
   aDisplayer->closeLocalContexts();
 }
 
-void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                          int theMode)
+void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
 {
   bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
   visualizePreview(theFeature, isDisplay, false);
   if (!isDisplay) {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
-    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    FeaturePtr aSketch;
     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
     if (aPrevOp) {
-      std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                                         aList = aPrevOp->subPreview();
+      std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > aList = aPrevOp->subPreview();
       XGUI_Displayer* aDisplayer = myWorkshop->displayer();
       std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
 
-      std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+      std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
                                                              anIt = aList.begin(), aLast = aList.end();
       for (; anIt != aLast; anIt++) {
-        boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+        FeaturePtr aFeature = (*anIt).first;
         visualizePreview(aFeature, false, false);
       }
       aDisplayer->updateViewer();
@@ -311,7 +311,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   // get operation xml description
   std::string aStdCmdId = theCmdId;
   if (aStdCmdId == PartSet_OperationEditLine::Type())
-    aStdCmdId = PartSet_OperationSketchLine::Type();
+    aStdCmdId = SKETCH_LINE_KIND;
   std::string aPluginFileName = featureFile(aStdCmdId);
   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
   aWdgReader.readAll();
@@ -325,12 +325,12 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   }
   else {
     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
-    boost::shared_ptr<ModelAPI_Feature> aSketch;
+    FeaturePtr aSketch;
     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
     if (aPrevOp)
       aSketch = aPrevOp->sketch();
-    if (theCmdId == PartSet_OperationSketchLine::Type())
-      anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
+    if (PartSet_OperationCreateFeature::canProcessKind(theCmdId))
+      anOperation = new PartSet_OperationCreateFeature(theCmdId.c_str(), this, aSketch);
     else if (theCmdId == PartSet_OperationEditLine::Type())
       anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
     else if (theCmdId == PartSet_OperationConstraint::Type())
@@ -346,10 +346,10 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
   // connect the operation
   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>)));
+    connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)),
+            this, SLOT(onFeatureConstructed(FeaturePtr, int)));
+    connect(aPreviewOp, SIGNAL(launchOperation(std::string, FeaturePtr)),
+            this, SLOT(onLaunchOperation(std::string, FeaturePtr)));
     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
             this, SLOT(onMultiSelectionEnabled(bool)));
 
@@ -384,7 +384,7 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
   Events_Loop::loop()->send(aMessage);
 }
 
-void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
                                       const bool isUpdateViewer)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
@@ -404,7 +404,7 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
                            aDisplayer->getAISObject(theFeature));
 
     int aSelectionMode = -1;
-    if (theFeature->getKind() == "SketchConstraintLength") {
+    if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND) {
       aSelectionMode = AIS_DSM_Text;
     }
     aDisplayer->redisplay(theFeature, anAIS, aSelectionMode, false);
@@ -416,8 +416,7 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
     aDisplayer->updateViewer();
 }
 
-void PartSet_Module::activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                     const bool isUpdateViewer)
+void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateViewer)
 {
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
@@ -438,19 +437,18 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
   if (!aPreviewOp)
     return;
 
-  boost::shared_ptr<ModelAPI_Feature> aFeature = aPreviewOp->feature();
+  FeaturePtr aFeature = aPreviewOp->feature();
   if (!aFeature || aFeature->getKind() != theCmdId)
     return;
 
-  std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >
-                                                                     aList = aPreviewOp->subPreview();
+  std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> > aList = aPreviewOp->subPreview();
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
 
-  std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
+  std::map<FeaturePtr, boost::shared_ptr<GeomAPI_Shape> >::const_iterator
                                                          anIt = aList.begin(), aLast = aList.end();
   for (; anIt != aLast; anIt++) {
-    boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
+    FeaturePtr aFeature = (*anIt).first;
     boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
     Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
                            aFeature, aPreviewOp->sketch(),