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