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