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