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