Salome HOME
GeomAPI_IPresentation in terface created
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 7cd1460300b283fee7df42cfcf54eee08ab3aaa3..fc2ffb51bb4fc85431ca5ec362c9ce0f1d895cf6 100644 (file)
@@ -1,13 +1,24 @@
 #include <PartSet_Module.h>
 #include <PartSet_OperationSketch.h>
-#include <PartSet_OperationSketchLine.h>
-#include <PartSet_OperationEditLine.h>
+#include <PartSet_OperationFeatureCreate.h>
+#include <PartSet_OperationFeatureEditMulti.h>
+#include <PartSet_OperationFeatureEdit.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
+#include <ModuleBase_WidgetFactory.h>
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
+#include <PartSet_WidgetSketchLabel.h>
+#include <PartSet_Validators.h>
 
 #include <ModuleBase_Operation.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Validator.h>
+
+#include <ModelAPI_Data.h>
+#include <GeomDataAPI_Point2D.h>
+#include <PartSet_Tools.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_OperationMgr.h>
 #include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
 #include <XGUI_ViewPort.h>
 #include <XGUI_ActionsMgr.h>
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_ContextMenuMgr.h>
 #include <XGUI_PropertyPanel.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Tools.h>
+
+#include <SketchPlugin_Line.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -29,8 +45,7 @@
 #include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
-
-#include <AIS_ListOfInteractive.hxx>
+#include <GeomAPI_AISObject.h>
 
 #include <QObject>
 #include <QMouseEvent>
@@ -41,7 +56,7 @@
 #endif
 
 /*!Create and return new instance of XGUI_Module*/
-extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
+extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
 {
   return new PartSet_Module(theWshop);
 }
@@ -71,6 +86,8 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
           this, SLOT(onMouseMoved(QMouseEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)),
           this, SLOT(onKeyRelease(QKeyEvent*)));
+  connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)),
+          this, SLOT(onMouseDoubleClick(QMouseEvent*)));
 }
 
 PartSet_Module::~PartSet_Module()
@@ -87,6 +104,15 @@ void PartSet_Module::createFeatures()
   Config_ModuleReader aXMLReader = Config_ModuleReader();
   aXMLReader.readAll();
   myFeaturesInFiles = aXMLReader.featuresInFiles();
+
+  //!! Test registering of validators
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
+  aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
+  aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
+  aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
+  aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
 }
 
 void PartSet_Module::featureCreated(QAction* theFeature)
@@ -109,12 +135,11 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
  */
 void PartSet_Module::onFeatureTriggered()
 {
-  //PartSet_TestOCC::testSelection_OCC(myWorkshop->viewer()->AISContext(),
+  //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
   //                                   myWorkshop->viewer()->activeView());
 
-  //PartSet_TestOCC::testErase_OCC(myWorkshop->viewer()->AISContext(),
-  //                               myWorkshop->viewer()->activeView());
-
+  //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
+  //                                       myWorkshop->viewer()->activeView());
   QAction* aCmd = dynamic_cast<QAction*>(sender());
   //Do nothing on uncheck
   if(aCmd->isCheckable() && !aCmd->isChecked())
@@ -125,6 +150,14 @@ void PartSet_Module::onFeatureTriggered()
 void PartSet_Module::launchOperation(const QString& theCmdId)
 {
   ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp) {
+    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+    // Initialise operation with preliminary selection
+    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
+    aPreviewOp->initSelection(aSelected, aHighlighted);
+  } 
   sendOperation(anOperation);
 }
 
@@ -134,8 +167,8 @@ void PartSet_Module::onOperationStarted()
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp) {
     XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
-    connect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
-            aPropPanel, SLOT(onFocusActivated(const std::string&)));
+    connect(aPropPanel, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
+      this, SLOT(onStorePoint2D(FeaturePtr, const std::string&)), Qt::UniqueConnection);
   }
 }
 
@@ -146,16 +179,18 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
   if (aPreviewOp) {
     XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
-    disconnect(aPreviewOp, SIGNAL(focusActivated(const std::string&)),
-               aPropPanel, SLOT(onFocusActivated(const std::string&)));
+    //disconnect(aPropPanel, SIGNAL(storedPoint2D(FeaturePtr, const std::string&)),
+    //           this, SLOT(onStorePoint2D(FeaturePtr, const std::string&)));
   }
 }
 
 void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
 {
-  QFeatureList aFeatures = myWorkshop->selector()->selectedFeatures();
+  QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
   if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
-    editFeature(aFeatures.first());
+    FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
+    if (aFeature)
+      editFeature(aFeature);
   }
 }
 
@@ -163,11 +198,11 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
 {
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
                                        myWorkshop->operationMgr()->currentOperation());
-  if (aPreviewOp)
-  {
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
-    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+  if (aPreviewOp) {
+    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+    // Initialise operation with preliminary selection
+    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
 
     aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
   }
@@ -179,9 +214,10 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp)
   {
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
-    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+    // Initialise operation with preliminary selection
+    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
 
     aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
   }
@@ -204,6 +240,21 @@ void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
   }
 }
 
+void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (aPreviewOp)
+  {
+    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+    // Initialise operation with preliminary selection
+    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
+    aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected,
+                                 aHighlighted);
+  }
+}
+
 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
 {
   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
@@ -212,17 +263,26 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
   //PartSet_TestOCC::testSelection(myWorkshop);
 }
 
-void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature)
+void PartSet_Module::onFitAllView()
+{
+  myWorkshop->viewer()->fitAll();
+}
+
+void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature)
 {
-  ModuleBase_Operation* anOperation = createOperation(theName.c_str());
+  ModuleBase_Operation* anOperation = createOperation(theName.c_str(),
+                                                      theFeature ? theFeature->getKind() : "");
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp)
   {
-    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-      // refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
-    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected(TopAbs_VERTEX);
-    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
-    aPreviewOp->init(theFeature, aSelected, aHighlighted);
+    XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+    // Initialise operation with preliminary selection
+    std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+    std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
+    aPreviewOp->initFeature(theFeature);
+    aPreviewOp->initSelection(aSelected, aHighlighted);
+  } else {
+    anOperation->setEditingFeature(theFeature);
   }
   sendOperation(anOperation);
   myWorkshop->actionsMgr()->updateCheckState();
@@ -234,59 +294,63 @@ void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
   aViewer->enableMultiselection(theEnabled);
 }
 
-void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+void PartSet_Module::onStopSelection(const QFeatureList& theFeatures, const bool isStop)
 {
   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;
+    QFeatureList::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
     for (; anIt != aLast; anIt++) {
-      activateFeature((*anIt).feature(), false);
+      activateFeature((*anIt), false);
+    }
+  }
+  QResultList aResults;
+  foreach(FeaturePtr aFeature, theFeatures) {
+    if (aFeature->results().size() > 0) {
+      std::list<ResultPtr>& aResList = aFeature->results();
+      std::list<ResultPtr>::iterator aIt;
+      for (aIt = aResList.begin(); aIt != aResList.end(); ++aIt)
+        aResults.append(*aIt);
     }
   }
-  aDisplayer->StopSelection(theFeatures, isStop, false);
+  aDisplayer->stopSelection(aResults, isStop, false);
 
   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
   aViewer->enableSelection(!isStop);
 
-  aDisplayer->UpdateViewer();
+  aDisplayer->updateViewer();
 }
 
-void PartSet_Module::onSetSelection(const std::list<XGUI_ViewerPrs>& theFeatures)
+void PartSet_Module::onSetSelection(const QResultList& theFeatures)
 {
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  aDisplayer->SetSelected(theFeatures, false);
-  aDisplayer->UpdateViewer();
+  aDisplayer->setSelected(theFeatures, false);
+  aDisplayer->updateViewer();
 }
 
 void PartSet_Module::onCloseLocalContext()
 {
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-  aDisplayer->CloseLocalContexts();
+  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);
+  // TODO 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::list<FeaturePtr> aList = aPrevOp->subFeatures();
       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
-                                                             anIt = aList.begin(), aLast = aList.end();
-      for (; anIt != aLast; anIt++) {
-        boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
-        visualizePreview(aFeature, false, false);
-      }
-      aDisplayer->UpdateViewer();
+      std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
+                                            aLast = aList.end();
+      for (; anIt != aLast; anIt++)
+        visualizePreview((*anIt), false, false);
+      aDisplayer->updateViewer();
     }
   }
 
@@ -295,57 +359,67 @@ void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> th
     activateFeature(theFeature, true);
 }
 
-ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
+ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
+                                                      const std::string& theFeatureKind)
 {
-  // get operation xml description
-  std::string aStdCmdId = theCmdId;
-  if (aStdCmdId == PartSet_OperationEditLine::Type())
-    aStdCmdId = PartSet_OperationSketchLine::Type();
-  std::string aPluginFileName = featureFile(aStdCmdId);
-  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
-  aWdgReader.readAll();
-  std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
-  std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
-
   // create the operation
-  ModuleBase_Operation* anOperation;
+  ModuleBase_Operation* anOperation = 0;
   if (theCmdId == PartSet_OperationSketch::Type()) {
     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
   }
-  else if(theCmdId == PartSet_OperationSketchLine::Type() ||
-          theCmdId == PartSet_OperationEditLine::Type()) {
+  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);
-    else
-      anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
+    if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId))
+      anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
+    else if (theCmdId == PartSet_OperationFeatureEditMulti::Type())
+               anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
+    else if (theCmdId == PartSet_OperationFeatureEdit::Type())
+      anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
   }
-  else {
+
+  if (!anOperation) {
     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
   }
-  anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
+
+  // set operation description and list of widgets corresponding to the feature xml definition
+  std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
+
+  std::string aPluginFileName = featureFile(aFeatureKind);
+  Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
+  aWdgReader.readAll();
+  std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
+  std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
+
+  //QString aXmlRepr = QString::fromStdString(aXmlCfg);
+  //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
+  //                                                             myWorkshop->moduleConnector());
+  //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
+  //qDeleteAll(aContent->children());
+  //aFactory.createWidget(aContent);
+
   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
+  anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
+
+  //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
 
   // 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)));
 
-    connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
-            this, SLOT(onMultiSelectionEnabled(bool)));
-    connect(aPreviewOp, SIGNAL(stopSelection(const std::list<XGUI_ViewerPrs>&, const bool)),
-            this, SLOT(onStopSelection(const std::list<XGUI_ViewerPrs>&, const bool)));
-    connect(aPreviewOp, SIGNAL(setSelection(const std::list<XGUI_ViewerPrs>&)),
-            this, SLOT(onSetSelection(const std::list<XGUI_ViewerPrs>&)));
+    connect(aPreviewOp, SIGNAL(stopSelection(const QFeatureList&, const bool)),
+            this, SLOT(onStopSelection(const QFeatureList&, const bool)));
+    connect(aPreviewOp, SIGNAL(setSelection(const QFeatureList&)),
+            this, SLOT(onSetSelection(const QFeatureList&)));
 
      connect(aPreviewOp, SIGNAL(closeLocalContext()),
              this, SLOT(onCloseLocalContext()));
@@ -354,6 +428,8 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     if (aSketchOp) {
       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
               this, SLOT(onPlaneSelected(double, double, double)));
+      connect(aSketchOp, SIGNAL(fitAllView()),
+              this, SLOT(onFitAllView()));
     }
   }
 
@@ -362,14 +438,13 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
 
 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
 {
-  //TODO(sbh): Implement static method to extract event id [SEID]
-  static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
+  static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
   Config_PointerMessage aMessage(aModuleEvent, this);
   aMessage.setPointer(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();
@@ -380,27 +455,32 @@ void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFea
   if (!aPreviewOp)
     return;
 
+  ResultPtr aResult = theFeature->firstResult();
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
-    boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
-    aDisplayer->Redisplay(theFeature,
-                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+    boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+      boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
+    if (aSPFeature) {
+      //boost::shared_ptr<GeomAPI_AISObject> anAIS = 
+      //  aSPFeature->getAISObject(aDisplayer->getAISObject(aResult));
+      aDisplayer->display(aSPFeature, false);
+      //aDisplayer->redisplay(aResult, anAIS, false);
+    }
   }
   else
-    aDisplayer->Erase(theFeature, false);
+    aDisplayer->erase(aResult, false);
 
   if (isUpdateViewer)
-    aDisplayer->UpdateViewer();
+    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);
   if (aPreviewOp) {
     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-    aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+    aDisplayer->activateInLocalContext(theFeature->firstResult(), aPreviewOp->getSelectionModes(theFeature),
                                        isUpdateViewer);
   }
 }
@@ -415,25 +495,25 @@ 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::list<FeaturePtr> aList = aPreviewOp->subFeatures();
   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
-                                                         anIt = aList.begin(), aLast = aList.end();
+  std::list<FeaturePtr>::const_iterator anIt = aList.begin(), 
+                                        aLast = aList.end();
   for (; anIt != aLast; anIt++) {
-    boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
-    boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
-    aDisplayer->Redisplay(aFeature,
-                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
-    aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
+    boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+      boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
+    if (!aSPFeature)
+      continue;
+    visualizePreview((*anIt), true, false);
+    aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false);
   }
-  aDisplayer->UpdateViewer();
+  aDisplayer->updateViewer();
 }
 
 void PartSet_Module::editFeature(FeaturePtr theFeature)
@@ -441,8 +521,62 @@ void PartSet_Module::editFeature(FeaturePtr theFeature)
   if (!theFeature)
     return;
 
-  if (theFeature->getKind() == "Sketch") {
-    onLaunchOperation(theFeature->getKind(), theFeature);
-    updateCurrentPreview(theFeature->getKind());
+//  if (theFeature->getKind() == SKETCH_KIND) {
+    //FeaturePtr aFeature = theFeature;
+    //if (XGUI_Tools::isModelObject(aFeature)) {
+    //  ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+    //  aFeature = aObject->featureRef();
+    //}
+
+    //if (aFeature) {
+      onLaunchOperation(theFeature->getKind(), theFeature);
+      updateCurrentPreview(theFeature->getKind());
+    //}
+//  }
+}
+
+void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& theAttribute)
+{
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
+                                       myWorkshop->operationMgr()->currentOperation());
+  if (!aPreviewOp)
+    return;
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
+
+  PartSet_Tools::setConstraints(aPreviewOp->sketch(), theFeature, theAttribute,
+                                aPoint->x(), aPoint->y());
+}
+
+/*bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
+{
+  XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
+  XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
+
+  ModuleBase_Operation* aOperation = aOpMgr->currentOperation();
+  if (!aOperation)
+    return !aActMgr->isNested(theCmdId);
+
+  PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast<PartSet_OperationFeatureEdit*>(aOperation);
+  if (aSketchEdtOp) {
+    QStringList aConstraintList;
+    aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength"
+      <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular";
+    return aConstraintList.contains(theCmdId);
   }
+  QStringList aList = aActMgr->nestedCommands(aOperation->id());
+  return aList.contains(theCmdId);
+}*/
+
+QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, 
+                         Config_WidgetAPI* theWidgetApi, QList<ModuleBase_ModelWidget*>& theModelWidgets)
+{
+  if (theType == "sketch-start-label") {
+    PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi);
+    aWgt->setOperationsMgr(myWorkshop->operationMgr());
+    theModelWidgets.append(aWgt);
+    return aWgt->getControl();
+  } else
+    return 0;
 }