Salome HOME
02d41a0fc57c26ec3ebd29d35b867f530e0273b0
[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   QFeatureList aFeatures = myWorkshop->selector()->selection()->selectedFeatures();
190   if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
191     editFeature(aFeatures.first());
192   }
193 }
194
195 void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
196 {
197   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
198                                        myWorkshop->operationMgr()->currentOperation());
199   if (aPreviewOp) {
200     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
201     // Initialise operation with preliminary selection
202     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
203     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
204
205     aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
206   }
207 }
208
209 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
210 {
211   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
212                                        myWorkshop->operationMgr()->currentOperation());
213   if (aPreviewOp)
214   {
215     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
216     // Initialise operation with preliminary selection
217     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
218     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
219
220     aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
221   }
222 }
223
224 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
225 {
226   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
227                                        myWorkshop->operationMgr()->currentOperation());
228   if (aPreviewOp)
229     aPreviewOp->mouseMoved(theEvent, myWorkshop->viewer()->activeView());
230 }
231
232 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
233 {
234   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
235   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
236   if (aPreviewOp) {
237     aPreviewOp->keyReleased(theEvent->key());
238   }
239 }
240
241 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
242 {
243   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
244                                        myWorkshop->operationMgr()->currentOperation());
245   if (aPreviewOp)
246   {
247     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
248     // Initialise operation with preliminary selection
249     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
250     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
251     aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected,
252                                  aHighlighted);
253   }
254 }
255
256 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
257 {
258   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
259   myWorkshop->actionsMgr()->update();
260
261   //PartSet_TestOCC::testSelection(myWorkshop);
262 }
263
264 void PartSet_Module::onFitAllView()
265 {
266   myWorkshop->viewer()->fitAll();
267 }
268
269 void PartSet_Module::onLaunchOperation(std::string theName, FeaturePtr theFeature)
270 {
271   ModuleBase_Operation* anOperation = createOperation(theName.c_str(),
272                                                       theFeature ? theFeature->getKind() : "");
273   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
274   if (aPreviewOp)
275   {
276     XGUI_Selection* aSelection = myWorkshop->selector()->selection();
277     // Initialise operation with preliminary selection
278     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
279     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
280     aPreviewOp->initFeature(theFeature);
281     aPreviewOp->initSelection(aSelected, aHighlighted);
282   } else {
283     anOperation->setEditingFeature(theFeature);
284   }
285   sendOperation(anOperation);
286   myWorkshop->actionsMgr()->updateCheckState();
287 }
288
289 void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
290 {
291   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
292   aViewer->enableMultiselection(theEnabled);
293 }
294
295 void PartSet_Module::onStopSelection(const QFeatureList& theFeatures, const bool isStop)
296 {
297   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
298   if (!isStop) {
299     QFeatureList::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
300     for (; anIt != aLast; anIt++) {
301       activateFeature((*anIt), false);
302     }
303   }
304   aDisplayer->stopSelection(theFeatures, isStop, false);
305
306   XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
307   aViewer->enableSelection(!isStop);
308
309   aDisplayer->updateViewer();
310 }
311
312 void PartSet_Module::onSetSelection(const QFeatureList& theFeatures)
313 {
314   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
315   aDisplayer->setSelected(theFeatures, false);
316   aDisplayer->updateViewer();
317 }
318
319 void PartSet_Module::onCloseLocalContext()
320 {
321   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
322   aDisplayer->closeLocalContexts();
323 }
324
325 void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
326 {
327   bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
328   visualizePreview(theFeature, isDisplay, false);
329   if (!isDisplay) {
330     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
331     FeaturePtr aSketch;
332     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
333     if (aPrevOp) {
334       std::list<FeaturePtr> aList = aPrevOp->subFeatures();
335       XGUI_Displayer* aDisplayer = myWorkshop->displayer();
336       std::list<int> aModes = aPrevOp->getSelectionModes(aPrevOp->feature());
337
338       std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
339                                             aLast = aList.end();
340       for (; anIt != aLast; anIt++)
341         visualizePreview(*anIt, false, false);
342       aDisplayer->updateViewer();
343     }
344   }
345
346   if (theMode == PartSet_OperationSketchBase::FM_Activation ||
347       theMode == PartSet_OperationSketchBase::FM_Deactivation)
348     activateFeature(theFeature, true);
349 }
350
351 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
352                                                       const std::string& theFeatureKind)
353 {
354   // create the operation
355   ModuleBase_Operation* anOperation = 0;
356   if (theCmdId == PartSet_OperationSketch::Type()) {
357     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
358   }
359   else {
360     ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
361     FeaturePtr aSketch;
362     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
363     if (aPrevOp)
364       aSketch = aPrevOp->sketch();
365     if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId))
366       anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
367     else if (theCmdId == PartSet_OperationFeatureEditMulti::Type())
368                 anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
369     else if (theCmdId == PartSet_OperationFeatureEdit::Type())
370       anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
371   }
372
373   if (!anOperation) {
374     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
375   }
376
377   // set operation description and list of widgets corresponding to the feature xml definition
378   std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
379
380   std::string aPluginFileName = featureFile(aFeatureKind);
381   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
382   aWdgReader.readAll();
383   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
384   std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
385
386   //QString aXmlRepr = QString::fromStdString(aXmlCfg);
387   //ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
388   //                                                             myWorkshop->moduleConnector());
389   //QWidget* aContent = myWorkshop->propertyPanel()->contentWidget();
390   //qDeleteAll(aContent->children());
391   //aFactory.createWidget(aContent);
392
393   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
394   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
395
396   //anOperation->setModelWidgets(aXmlRepr.toStdString(), aFactory.getModelWidgets());
397
398   // connect the operation
399   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
400   if (aPreviewOp) {
401     connect(aPreviewOp, SIGNAL(featureConstructed(FeaturePtr, int)),
402             this, SLOT(onFeatureConstructed(FeaturePtr, int)));
403     connect(aPreviewOp, SIGNAL(launchOperation(std::string, FeaturePtr)),
404             this, SLOT(onLaunchOperation(std::string, FeaturePtr)));
405     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
406             this, SLOT(onMultiSelectionEnabled(bool)));
407
408     connect(aPreviewOp, SIGNAL(stopSelection(const QFeatureList&, const bool)),
409             this, SLOT(onStopSelection(const QFeatureList&, const bool)));
410     connect(aPreviewOp, SIGNAL(setSelection(const QFeatureList&)),
411             this, SLOT(onSetSelection(const QFeatureList&)));
412
413      connect(aPreviewOp, SIGNAL(closeLocalContext()),
414              this, SLOT(onCloseLocalContext()));
415
416     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
417     if (aSketchOp) {
418       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
419               this, SLOT(onPlaneSelected(double, double, double)));
420       connect(aSketchOp, SIGNAL(fitAllView()),
421               this, SLOT(onFitAllView()));
422     }
423   }
424
425   return anOperation;
426 }
427
428 void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation)
429 {
430   static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
431   Config_PointerMessage aMessage(aModuleEvent, this);
432   aMessage.setPointer(theOperation);
433   Events_Loop::loop()->send(aMessage);
434 }
435
436 void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
437                                       const bool isUpdateViewer)
438 {
439   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
440   if (!anOperation)
441     return;
442
443   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
444   if (!aPreviewOp)
445     return;
446
447   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
448   if (isDisplay) {
449     boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
450       boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
451     if (aSPFeature)
452     {
453       boost::shared_ptr<GeomAPI_AISObject> anAIS = 
454         aSPFeature->getAISObject(aDisplayer->getAISObject(theFeature));
455       aDisplayer->redisplay(theFeature, anAIS, false);
456     }
457   }
458   else
459     aDisplayer->erase(theFeature, false);
460
461   if (isUpdateViewer)
462     aDisplayer->updateViewer();
463 }
464
465 void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateViewer)
466 {
467   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
468   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
469   if (aPreviewOp) {
470     XGUI_Displayer* aDisplayer = myWorkshop->displayer();
471     aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
472                                        isUpdateViewer);
473   }
474 }
475
476 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
477 {
478   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
479   if (!anOperation)
480     return;
481
482   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
483   if (!aPreviewOp)
484     return;
485
486   FeaturePtr aFeature = aPreviewOp->feature();
487   if (!aFeature || aFeature->getKind() != theCmdId)
488     return;
489
490   std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
491   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
492   std::list<int> aModes = aPreviewOp->getSelectionModes(aPreviewOp->feature());
493
494   std::list<FeaturePtr>::const_iterator anIt = aList.begin(), 
495                                         aLast = aList.end();
496   for (; anIt != aLast; anIt++) {
497     boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
498       boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
499     if (!aSPFeature)
500       continue;
501     visualizePreview(*anIt, true, false);
502     aDisplayer->activateInLocalContext(*anIt, aModes, false);
503   }
504   aDisplayer->updateViewer();
505 }
506
507 void PartSet_Module::editFeature(FeaturePtr theFeature)
508 {
509   if (!theFeature)
510     return;
511
512 //  if (theFeature->getKind() == SKETCH_KIND) {
513     FeaturePtr aFeature = theFeature;
514     if (XGUI_Tools::isModelObject(aFeature)) {
515       ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
516       aFeature = aObject->featureRef();
517     }
518
519     if (aFeature) {
520       onLaunchOperation(aFeature->getKind(), aFeature);
521       updateCurrentPreview(aFeature->getKind());
522     }
523 //  }
524 }
525
526 void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& theAttribute)
527 {
528   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
529                                        myWorkshop->operationMgr()->currentOperation());
530   if (!aPreviewOp)
531     return;
532
533   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
534         boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
535
536   PartSet_Tools::setConstraints(aPreviewOp->sketch(), theFeature, theAttribute,
537                                 aPoint->x(), aPoint->y());
538 }
539
540 /*bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
541 {
542   XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
543   XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
544
545   ModuleBase_Operation* aOperation = aOpMgr->currentOperation();
546   if (!aOperation)
547     return !aActMgr->isNested(theCmdId);
548
549   PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast<PartSet_OperationFeatureEdit*>(aOperation);
550   if (aSketchEdtOp) {
551     QStringList aConstraintList;
552     aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength"
553       <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular";
554     return aConstraintList.contains(theCmdId);
555   }
556   QStringList aList = aActMgr->nestedCommands(aOperation->id());
557   return aList.contains(theCmdId);
558 }*/
559
560 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, 
561                          Config_WidgetAPI* theWidgetApi, QList<ModuleBase_ModelWidget*>& theModelWidgets)
562 {
563   if (theType == "sketch-start-label") {
564     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi);
565     aWgt->setOperationsMgr(myWorkshop->operationMgr());
566     theModelWidgets.append(aWgt);
567     return aWgt->getControl();
568   } else
569     return 0;
570 }