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