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