Salome HOME
bc23a468b2f1f2537c9ca2ee6c0a70b9525dffef
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 #include <PartSet_Module.h>
2 #include <PartSet_OperationSketch.h>
3 #include <PartSet_OperationFeatureCreate.h>
4 #include <PartSet_OperationFeatureEditMulti.h>
5 #include <PartSet_OperationFeatureEdit.h>
6 #include <PartSet_Listener.h>
7 #include <PartSet_TestOCC.h>
8 #include <PartSet_WidgetSketchLabel.h>
9 #include <PartSet_Validators.h>
10 #include <PartSet_Tools.h>
11
12 #include <ModuleBase_Operation.h>
13 #include <ModuleBase_OperationDescription.h>
14 #include <ModuleBase_WidgetFactory.h>
15 #include <ModuleBase_Operation.h>
16
17 #include <ModelAPI_Object.h>
18 #include <ModelAPI_Events.h>
19 #include <ModelAPI_Validator.h>
20 #include <ModelAPI_Data.h>
21
22 #include <GeomDataAPI_Point2D.h>
23
24 #include <XGUI_MainWindow.h>
25 #include <XGUI_Displayer.h>
26 #include <XGUI_Viewer.h>
27 #include <XGUI_Workshop.h>
28 #include <XGUI_OperationMgr.h>
29 #include <XGUI_SelectionMgr.h>
30 #include <XGUI_Selection.h>
31 #include <XGUI_ViewPort.h>
32 #include <XGUI_ActionsMgr.h>
33 #include <XGUI_ViewerProxy.h>
34 #include <XGUI_ContextMenuMgr.h>
35 #include <XGUI_PropertyPanel.h>
36 #include <XGUI_ModuleConnector.h>
37 #include <XGUI_Tools.h>
38
39 #include <SketchPlugin_Line.h>
40
41 #include <Config_PointerMessage.h>
42 #include <Config_ModuleReader.h>
43 #include <Config_WidgetReader.h>
44 #include <Events_Loop.h>
45 #include <Events_Message.h>
46 #include <Events_Error.h>
47
48 #include <GeomAPI_Shape.h>
49 #include <GeomAPI_AISObject.h>
50 #include <AIS_Shape.hxx>
51
52 #include <StdSelect_FaceFilter.hxx>
53 #include <StdSelect_TypeOfFace.hxx>
54
55 #include <QObject>
56 #include <QMouseEvent>
57 #include <QString>
58
59 #include <GeomAlgoAPI_FaceBuilder.h>
60 #include <GeomDataAPI_Dir.h>
61
62 #ifdef _DEBUG
63 #include <QDebug>
64 #endif
65
66 /*!Create and return new instance of XGUI_Module*/
67 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
68 {
69   return new PartSet_Module(theWshop);
70 }
71
72 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
73 {
74   myWorkshop = theWshop;
75   myListener = new PartSet_Listener(this);
76
77   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
78
79   connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
80
81   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
82           SLOT(onOperationStopped(ModuleBase_Operation*)));
83
84   XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
85   connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
86           SLOT(onContextMenuCommand(const QString&, bool)));
87
88   connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
89           SLOT(onMousePressed(QMouseEvent*)));
90   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
91           SLOT(onMouseReleased(QMouseEvent*)));
92   connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
93           SLOT(onMouseMoved(QMouseEvent*)));
94   connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
95           SLOT(onKeyRelease(QKeyEvent*)));
96   connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
97           SLOT(onMouseDoubleClick(QMouseEvent*)));
98 }
99
100 PartSet_Module::~PartSet_Module()
101 {
102 }
103
104 XGUI_Workshop* PartSet_Module::workshop() const
105 {
106   return myWorkshop;
107 }
108
109 void PartSet_Module::createFeatures()
110 {
111   //Registering of validators
112   SessionPtr aMgr = ModelAPI_Session::get();
113   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
114   aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
115   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
116   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
117   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
118   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
119
120   Config_ModuleReader aXMLReader = Config_ModuleReader();
121   aXMLReader.readAll();
122   myFeaturesInFiles = aXMLReader.featuresInFiles();
123 }
124
125 void PartSet_Module::featureCreated(QAction* theFeature)
126 {
127   connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
128 }
129
130 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
131 {
132   return myFeaturesInFiles[theFeatureId];
133 }
134
135 /*
136  *
137  */
138 void PartSet_Module::onFeatureTriggered()
139 {
140   //PartSet_TestOCC::local_selection_change_shape(myWorkshop->viewer()->AISContext(),
141   //                                   myWorkshop->viewer()->activeView());
142
143   //PartSet_TestOCC::local_selection_erase(myWorkshop->viewer()->AISContext(),
144   //                                       myWorkshop->viewer()->activeView());
145   QAction* aCmd = dynamic_cast<QAction*>(sender());
146   //Do nothing on uncheck
147   if (aCmd->isCheckable() && !aCmd->isChecked())
148     return;
149   launchOperation(aCmd->data().toString());
150 }
151
152 void PartSet_Module::launchOperation(const QString& theCmdId)
153 {
154   ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
155   //PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
156   //if (aPreviewOp) {
157     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
158     // Initialise operation with preliminary selection
159     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
160     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
161     anOperation->initSelection(aSelected, aHighlighted);
162   //}
163   sendOperation(anOperation);
164 }
165
166 void PartSet_Module::onOperationStarted()
167 {
168   ModuleBase_Operation* aOperation = myWorkshop->operationMgr()->currentOperation();
169
170   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(aOperation);
171   if (aPreviewOp) {
172     XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
173     connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
174             SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
175
176     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
177     aDisplayer->openLocalContext();
178     aDisplayer->deactivateObjectsOutOfContext();
179   }
180 }
181
182 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
183 {
184   if (!theOperation)
185     return;
186   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
187   if (aPreviewOp) {
188     XGUI_PropertyPanel* aPropPanel = myWorkshop->propertyPanel();
189     //disconnect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)),
190     //           this, SLOT(onStorePoint2D(ObjectPtr, const std::string&)));
191   } else {
192     // Activate results of current feature for selection
193     FeaturePtr aFeature = theOperation->feature();
194     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
195     std::list<ResultPtr> aResults = aFeature->results();
196     std::list<ResultPtr>::const_iterator aIt;
197     for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
198       aDisplayer->activate(*aIt);
199     }
200   }
201 }
202
203 void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
204 {
205   QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
206   if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
207     FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
208     if (aFeature)
209       editFeature(aFeature);
210   }
211 }
212
213 void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
214 {
215
216   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
217       ->operationMgr()->currentOperation());
218   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
219   if (aPreviewOp && (!aView.IsNull())) {
220     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
221     // Initialise operation with preliminary selection
222     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
223     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
224
225     aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
226   }
227 }
228
229 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
230 {
231   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
232       ->operationMgr()->currentOperation());
233   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
234   if (aPreviewOp && (!aView.IsNull())) {
235     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
236     // Initialise operation with preliminary selection
237     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
238     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
239
240     aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
241   }
242 }
243
244 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
245 {
246   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
247       ->operationMgr()->currentOperation());
248   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
249   if (aPreviewOp && (!aView.IsNull()))
250     aPreviewOp->mouseMoved(theEvent, aView);
251 }
252
253 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
254 {
255   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
256   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
257   if (aPreviewOp) {
258     aPreviewOp->keyReleased(theEvent->key());
259   }
260 }
261
262 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
263 {
264   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
265       ->operationMgr()->currentOperation());
266   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
267   if (aPreviewOp && (!aView.IsNull())) {
268     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
269     // Initialise operation with preliminary selection
270     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
271     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
272     aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
273   }
274 }
275
276 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
277 {
278   //erasePlanes();
279   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
280   myWorkshop->actionsMgr()->update();
281
282   //PartSet_TestOCC::testSelection(myWorkshop);
283 }
284
285 void PartSet_Module::onFitAllView()
286 {
287   myWorkshop->viewer()->fitAll();
288 }
289
290 void PartSet_Module::onRestartOperation(std::string theName, ObjectPtr theObject)
291 {
292   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
293
294   std::string aKind = aFeature ? aFeature->getKind() : "";
295   ModuleBase_Operation* anOperation = createOperation(theName, aKind);
296   PartSet_OperationSketchBase* aSketchOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
297   if (aSketchOp) {
298     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
299     // Initialise operation with preliminary selection
300     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
301     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
302     aSketchOp->initSelection(aSelected, aHighlighted);
303     PartSet_OperationFeatureCreate* aCreateOp = dynamic_cast<PartSet_OperationFeatureCreate*>(anOperation);
304     if (aCreateOp)
305       aCreateOp->initFeature(aFeature);
306     else {
307       PartSet_OperationFeatureEdit* aEditOp = dynamic_cast<PartSet_OperationFeatureEdit*>(anOperation);
308       if (aEditOp) 
309         anOperation->setFeature(aFeature);
310     }
311   } else if (aFeature) {
312     anOperation->setFeature(aFeature);
313     //Deactivate result of current feature in order to avoid its selection
314     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
315     std::list<ResultPtr> aResults = aFeature->results();
316     std::list<ResultPtr>::const_iterator aIt;
317     for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
318       aDisplayer->deactivate(*aIt);
319     }
320   }
321   sendOperation(anOperation);
322   myWorkshop->actionsMgr()->updateCheckState();
323 }
324
325 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
326 {
327   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
328   aViewer->enableMultiselection(theEnabled);
329 }
330
331 void PartSet_Module::onStopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop)
332 {
333   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
334   if (!isStop) {
335     foreach(ObjectPtr aObject, theFeatures)
336     {
337       activateFeature(aObject, false);
338     }
339   }
340   aDisplayer->stopSelection(theFeatures, isStop, false);
341
342   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
343   aViewer->enableSelection(!isStop);
344
345   aDisplayer->updateViewer();
346 }
347
348 void PartSet_Module::onSetSelection(const QList<ObjectPtr>& theFeatures)
349 {
350   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
351   aDisplayer->setSelected(theFeatures, false);
352   aDisplayer->updateViewer();
353 }
354
355 void PartSet_Module::onCloseLocalContext()
356 {
357   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
358   aDisplayer->deactivateObjectsOutOfContext();
359   aDisplayer->closeLocalContexts();
360 }
361
362 void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
363 {
364   bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
365   ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
366   PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
367   if (aPrevOp) {
368     std::list<FeaturePtr> aList = aPrevOp->subFeatures();
369     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
370     std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
371     std::list<FeaturePtr>::iterator aSFIt;
372     for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
373       std::list<ResultPtr> aResults = (*aSFIt)->results();
374       std::list<ResultPtr>::iterator aIt;
375       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
376         if (isDisplay)
377           aDisplayer->activateInLocalContext((*aIt), aModes, false);
378         else
379           aDisplayer->erase((*aIt), false);
380       }
381       if (!isDisplay)
382         aDisplayer->erase((*aSFIt), false);
383     }
384     aDisplayer->deactivateObjectsOutOfContext();
385   }
386   if (isDisplay)
387     ModelAPI_EventCreator::get()->sendUpdated(
388         theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
389 }
390
391 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
392                                                       const std::string& theFeatureKind)
393 {
394   // create the operation
395   ModuleBase_Operation* anOperation = 0;
396   if (theCmdId == PartSet_OperationSketch::Type()) {
397     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
398   } else {
399     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
400     FeaturePtr aSketch;
401     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
402     if (aPrevOp) {
403       aSketch = aPrevOp->sketch();
404     }
405     if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
406       anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
407     } else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) {
408       anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
409     } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
410       anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
411     }
412   }
413
414   if (!anOperation) {
415     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
416   }
417
418   // set operation description and list of widgets corresponding to the feature xml definition
419   std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
420
421   std::string aPluginFileName = featureFile(aFeatureKind);
422   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
423   aWdgReader.readAll();
424   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
425   std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
426
427   //QString aXmlRepr = QString::fromStdString(aXmlCfg);
428   //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
429   //                                                             myWorkshop->moduleConnector());
430   //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
431   //qDeleteAll(aContent->children());
432   //aFactory.createWidget(aContent);
433
434   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
435   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
436
437   //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
438
439   // connect the operation
440   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
441   if (aPreviewOp) {
442     connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
443             SLOT(onFeatureConstructed(ObjectPtr, int)));
444     connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
445             SLOT(onRestartOperation(std::string, ObjectPtr)));
446     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
447             SLOT(onMultiSelectionEnabled(bool)));
448
449     connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
450             SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
451     connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
452             SLOT(onSetSelection(const QList<ObjectPtr>&)));
453
454     connect(aPreviewOp, SIGNAL(closeLocalContext()), this, SLOT(onCloseLocalContext()));
455
456     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
457     if (aSketchOp) {
458       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
459               SLOT(onPlaneSelected(double, double, double)));
460       connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
461     }
462   }
463
464   return anOperation;
465 }
466
467 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
468 {
469   static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
470   boost::shared_ptr<Config_PointerMessage> aMessage =
471       boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
472   aMessage->setPointer(theOperation);
473   Events_Loop::loop()->send(aMessage);
474 }
475
476 void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer)
477 {
478   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
479   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
480   if (aPreviewOp) {
481     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
482     std::list<int> aModes = aPreviewOp->getSelectionModes(theFeature);
483     aDisplayer->activateInLocalContext(theFeature, aModes, isUpdateViewer);
484
485     // If this is a Sketcher then activate objects (planar faces) outside of context
486     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
487     if (aSketchOp) {
488       Handle(StdSelect_FaceFilter) aFilter = new StdSelect_FaceFilter(StdSelect_Plane);
489       aDisplayer->activateObjectsOutOfContext(aModes, aFilter);
490     } else {
491       aDisplayer->deactivateObjectsOutOfContext();
492     }
493   }
494 }
495
496 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
497 {
498   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
499   if (!anOperation)
500     return;
501
502   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
503   if (!aPreviewOp)
504     return;
505
506   FeaturePtr aFeature = aPreviewOp->feature();
507   if (!aFeature || aFeature->getKind() != theCmdId)
508     return;
509
510   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
511   // Hide result of sketch
512   std::list<ResultPtr> aResults = aFeature->results();
513   std::list<ResultPtr>::const_iterator aIt;
514   for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
515     aDisplayer->erase(*aIt, false);
516
517   std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
518   std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
519
520   std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
521   for (; anIt != aLast; anIt++) {
522     boost::shared_ptr<SketchPlugin_Feature> aSPFeature = boost::dynamic_pointer_cast<
523         SketchPlugin_Feature>(*anIt);
524     if (!aSPFeature)
525       continue;
526     std::list<ResultPtr> aResults = aSPFeature->results();
527     std::list<ResultPtr>::const_iterator aRIt;
528     for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
529       aDisplayer->display((*aRIt), false);
530       aDisplayer->activateInLocalContext((*aRIt), aModes, false);
531     }
532     aDisplayer->display(aSPFeature, false);
533     aDisplayer->activateInLocalContext(aSPFeature, aModes, false);
534   }
535   aDisplayer->updateViewer();
536 }
537
538 void PartSet_Module::editFeature(FeaturePtr theFeature)
539 {
540   if (!theFeature)
541     return;
542
543 //  if (theFeature->getKind() == SKETCH_KIND) {
544   //FeaturePtr aFeature = theFeature;
545   //if (XGUI_Tools::isModelObject(aFeature)) {
546   //  ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
547   //  aFeature = aObject->featureRef();
548   //}
549
550   //if (aFeature) {
551   onRestartOperation(theFeature->getKind(), theFeature);
552   updateCurrentPreview(theFeature->getKind());
553   //}
554 //  }
555 }
556
557 void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
558 {
559   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
560
561   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop
562       ->operationMgr()->currentOperation());
563   if (!aPreviewOp)
564     return;
565
566   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
567       aFeature->data()->attribute(theAttribute));
568
569   PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
570                                 aPoint->y());
571 }
572
573 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
574                                             Config_WidgetAPI* theWidgetApi,
575                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
576 {
577   if (theType == "sketch-start-label") {
578     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, "");
579     aWgt->setOperationsMgr(myWorkshop->operationMgr());
580     theModelWidgets.append(aWgt);
581     return aWgt->getControl();
582   } else
583     return 0;
584 }