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