Salome HOME
15742d1b9319ed897ff5bbe53052b444146eabf1
[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 #include <GeomDataAPI_Point.h>
24 #include <GeomDataAPI_Dir.h>
25
26 #include <XGUI_MainWindow.h>
27 #include <XGUI_Displayer.h>
28 #include <XGUI_Viewer.h>
29 #include <XGUI_Workshop.h>
30 #include <XGUI_OperationMgr.h>
31 #include <XGUI_ViewPort.h>
32 #include <XGUI_ActionsMgr.h>
33 #include <XGUI_ViewerProxy.h>
34 #include <XGUI_ContextMenuMgr.h>
35 #include <XGUI_PropertyPanel.h>
36 #include <XGUI_ModuleConnector.h>
37 #include <XGUI_Tools.h>
38
39 #include <SketchPlugin_Line.h>
40 #include <SketchPlugin_Sketch.h>
41
42 #include <Config_PointerMessage.h>
43 #include <Config_ModuleReader.h>
44 #include <Config_WidgetReader.h>
45 #include <Events_Loop.h>
46 //#include <Events_Message.h>
47 //#include <Events_Error.h>
48
49 #include <GeomAPI_Shape.h>
50 #include <GeomAPI_AISObject.h>
51 #include <AIS_Shape.hxx>
52 #include <AIS_DimensionSelectionMode.hxx>
53
54 #include <StdSelect_TypeOfFace.hxx>
55
56 #include <QObject>
57 #include <QMouseEvent>
58 #include <QString>
59
60 #include <GeomAlgoAPI_FaceBuilder.h>
61 #include <GeomDataAPI_Dir.h>
62
63 #ifdef _DEBUG
64 #include <QDebug>
65 #endif
66
67 /*!Create and return new instance of XGUI_Module*/
68 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
69 {
70   return new PartSet_Module(theWshop);
71 }
72
73 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
74   : ModuleBase_IModule(theWshop)
75 {
76   //myWorkshop = theWshop;
77   myListener = new PartSet_Listener(this);
78
79   connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)), 
80     this, SLOT(onOperationStarted(ModuleBase_Operation*)));
81
82   connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)), this,
83           SLOT(onOperationStopped(ModuleBase_Operation*)));
84
85   XGUI_Workshop* aXWshop = xWorkshop();
86   XGUI_ContextMenuMgr* aContextMenuMgr = aXWshop->contextMenuMgr();
87   connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
88           SLOT(onContextMenuCommand(const QString&, bool)));
89
90   connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
91           SLOT(onMousePressed(QMouseEvent*)));
92   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
93           SLOT(onMouseReleased(QMouseEvent*)));
94   connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
95           SLOT(onMouseMoved(QMouseEvent*)));
96   connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
97           SLOT(onKeyRelease(QKeyEvent*)));
98   connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
99           SLOT(onMouseDoubleClick(QMouseEvent*)));
100 }
101
102 PartSet_Module::~PartSet_Module()
103 {
104 }
105
106 void PartSet_Module::createFeatures()
107 {
108   //Registering of validators
109   SessionPtr aMgr = ModelAPI_Session::get();
110   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
111   aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
112   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
113   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
114   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
115   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
116
117   Config_ModuleReader aXMLReader = Config_ModuleReader();
118   aXMLReader.readAll();
119   myFeaturesInFiles = aXMLReader.featuresInFiles();
120 }
121
122 void PartSet_Module::featureCreated(QAction* theFeature)
123 {
124   connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
125 }
126
127 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
128 {
129   return myFeaturesInFiles[theFeatureId];
130 }
131
132 /*
133  *
134  */
135 void PartSet_Module::onFeatureTriggered()
136 {
137   QAction* aCmd = dynamic_cast<QAction*>(sender());
138   //Do nothing on uncheck
139   if (aCmd->isCheckable() && !aCmd->isChecked())
140     return;
141   launchOperation(aCmd->data().toString());
142 }
143
144
145 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
146 {
147   XGUI_Workshop* aXWshp = xWorkshop();
148   XGUI_Displayer* aDisplayer = aXWshp->displayer();
149   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
150   if (aPreviewOp) {
151     XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
152     connect(aPropPanel, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
153             SLOT(onStorePoint2D(ObjectPtr, const std::string&)), Qt::UniqueConnection);
154
155     //aDisplayer->deactivateObjectsOutOfContext();
156     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
157     if (aSketchOp) {
158       if (aSketchOp->isEditOperation()) {
159         setSketchingMode(getSketchPlane(aSketchOp->feature()));
160       } else {
161         aDisplayer->openLocalContext();
162         aDisplayer->activateObjectsOutOfContext(QIntList());
163         myPlaneFilter = new StdSelect_FaceFilter(StdSelect_Plane);
164         aDisplayer->addSelectionFilter(myPlaneFilter);
165         QIntList aModes = sketchSelectionModes(aPreviewOp->feature());
166         aDisplayer->setSelectionModes(aModes);
167       } 
168     }
169   }
170 }
171
172 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
173 {
174   if (!theOperation)
175     return;
176   XGUI_Workshop* aXWshp = xWorkshop();
177   XGUI_Displayer* aDisplayer = aXWshp->displayer();
178   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
179   if (aPreviewOp) {
180     XGUI_PropertyPanel* aPropPanel = aXWshp->propertyPanel();
181
182     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
183     if (aSketchOp) {
184       aDisplayer->closeLocalContexts();
185     } else {
186       PartSet_OperationFeatureCreate* aCreationOp = 
187         dynamic_cast<PartSet_OperationFeatureCreate*>(aPreviewOp);
188       if (aCreationOp) {
189         // Activate just created object for selection
190         FeaturePtr aFeature = aCreationOp->feature();
191         QIntList aModes = sketchSelectionModes(aFeature);
192         const std::list<ResultPtr>& aResults = aFeature->results();
193         std::list<ResultPtr>::const_iterator anIt, aLast = aResults.end();
194         for (anIt = aResults.begin(); anIt != aLast; anIt++) {
195           aDisplayer->activate(*anIt, aModes);
196         }
197         aDisplayer->activate(aFeature, aModes);
198       }
199     }
200   } else {
201     // Activate results of current feature for selection
202     //FeaturePtr aFeature = theOperation->feature();
203     //XGUI_Displayer* aDisplayer = aXWshp->displayer();
204     //std::list<ResultPtr> aResults = aFeature->results();
205     //std::list<ResultPtr>::const_iterator aIt;
206     //for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
207     //  aDisplayer->activate(*aIt);
208     //}
209
210     
211     
212   }
213   // Clear selection done during operation
214   aDisplayer->clearSelected();
215 }
216
217 void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
218 {
219   QList<ObjectPtr> aFeatures = workshop()->selection()->selectedObjects();
220   if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
221     FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
222     if (aFeature)
223       editFeature(aFeature);
224   }
225 }
226
227 void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
228 {
229   XGUI_Workshop* aXWshp = xWorkshop();
230   PartSet_OperationSketchBase* aPreviewOp = 
231     dynamic_cast<PartSet_OperationSketchBase*>(workshop()->currentOperation());
232   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
233   if (aPreviewOp && (!aView.IsNull())) {
234     ModuleBase_ISelection* aSelection = workshop()->selection();
235     // Initialise operation with preliminary selection
236     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
237     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
238
239     aPreviewOp->mousePressed(theEvent, aView, aSelected, aHighlighted);
240   }
241 }
242
243 void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
244 {
245   PartSet_OperationSketchBase* aPreviewOp = 
246     dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
247   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
248   if (aPreviewOp && (!aView.IsNull())) {
249     ModuleBase_ISelection* aSelection = workshop()->selection();
250     // Initialise operation with preliminary selection
251     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
252     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
253
254     aPreviewOp->mouseReleased(theEvent, aView, aSelected, aHighlighted);
255   }
256 }
257
258 void PartSet_Module::onMouseMoved(QMouseEvent* theEvent)
259 {
260   PartSet_OperationSketchBase* aPreviewOp = 
261     dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
262   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
263   if (aPreviewOp && (!aView.IsNull()))
264     aPreviewOp->mouseMoved(theEvent, aView);
265 }
266
267 void PartSet_Module::onKeyRelease(QKeyEvent* theEvent)
268 {
269   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
270   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
271   if (aPreviewOp) {
272     aPreviewOp->keyReleased(theEvent->key());
273   }
274 }
275
276 void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent)
277 {
278   PartSet_OperationSketchBase* aPreviewOp = 
279     dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
280   Handle(V3d_View) aView = myWorkshop->viewer()->activeView();
281   if (aPreviewOp && (!aView.IsNull())) {
282     ModuleBase_ISelection* aSelection = workshop()->selection();
283     // Initialise operation with preliminary selection
284     std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
285     std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
286     aPreviewOp->mouseDoubleClick(theEvent, aView, aSelected, aHighlighted);
287   }
288 }
289
290 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
291 {
292   myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
293   xWorkshop()->actionsMgr()->update();
294   // Set working plane
295   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
296   FeaturePtr aSketch = anOperation->feature();
297   setSketchingMode(getSketchPlane(aSketch));
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(const gp_Pln& thePln)
369 {
370   XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
371   if (!myPlaneFilter.IsNull()) {
372     aDisplayer->removeSelectionFilter(myPlaneFilter);
373     myPlaneFilter.Nullify();
374   }
375   QIntList aModes;
376   // Clear standard selection modes
377   aDisplayer->setSelectionModes(aModes);
378   aDisplayer->openLocalContext();
379   // Get default selection modes
380   aModes = sketchSelectionModes(ObjectPtr());
381   aDisplayer->activateObjectsOutOfContext(aModes);
382
383   // Set filter
384   mySketchFilter = new ModuleBase_ShapeInPlaneFilter(thePln);
385   aDisplayer->addSelectionFilter(mySketchFilter);
386 }
387
388 void PartSet_Module::onFeatureConstructed(ObjectPtr theFeature, int theMode)
389 {
390   bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
391   ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
392   PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
393   if (aPrevOp) {
394     std::list<FeaturePtr> aList = aPrevOp->subFeatures();
395     XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
396     QIntList aModes = sketchSelectionModes(aPrevOp->feature());
397     std::list<FeaturePtr>::iterator aSFIt;
398     for (aSFIt = aList.begin(); aSFIt != aList.end(); ++aSFIt) {
399       std::list<ResultPtr> aResults = (*aSFIt)->results();
400       std::list<ResultPtr>::iterator aIt;
401       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
402         if (!isDisplay)
403           aDisplayer->erase((*aIt), false);
404       }
405       if (!isDisplay)
406         aDisplayer->erase((*aSFIt), false);
407     }
408     //aDisplayer->deactivateObjectsOutOfContext();
409   }
410   if (isDisplay)
411     ModelAPI_EventCreator::get()->sendUpdated(
412         theFeature, Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
413 }
414
415 ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId,
416                                                       const std::string& theFeatureKind)
417 {
418   // create the operation
419   ModuleBase_Operation* anOperation = 0;
420   if (theCmdId == PartSet_OperationSketch::Type()) {
421     anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this);
422   } else {
423     ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
424     CompositeFeaturePtr aSketch;
425     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
426     if (aPrevOp) {
427       aSketch = aPrevOp->sketch();
428     }
429     if (PartSet_OperationFeatureCreate::canProcessKind(theCmdId)) {
430       anOperation = new PartSet_OperationFeatureCreate(theCmdId.c_str(), this, aSketch);
431     } else if (theCmdId == PartSet_OperationFeatureEditMulti::Type()) {
432       anOperation = new PartSet_OperationFeatureEditMulti(theCmdId.c_str(), this, aSketch);
433     } else if (theCmdId == PartSet_OperationFeatureEdit::Type()) {
434       anOperation = new PartSet_OperationFeatureEdit(theCmdId.c_str(), this, aSketch);
435     }
436   }
437
438   if (!anOperation) {
439     anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
440   }
441
442   // set operation description and list of widgets corresponding to the feature xml definition
443   std::string aFeatureKind = theFeatureKind.empty() ? theCmdId : theFeatureKind;
444
445   std::string aPluginFileName = featureFile(aFeatureKind);
446   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
447   aWdgReader.readAll();
448   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aFeatureKind);
449   std::string aDescription = aWdgReader.featureDescription(aFeatureKind);
450
451   anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
452   anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
453
454   // connect the operation
455   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
456   if (aPreviewOp) {
457     connect(aPreviewOp, SIGNAL(featureConstructed(ObjectPtr, int)), this,
458             SLOT(onFeatureConstructed(ObjectPtr, int)));
459     connect(aPreviewOp, SIGNAL(restartRequired(std::string, ObjectPtr)), this,
460             SLOT(onRestartOperation(std::string, ObjectPtr)));
461     connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)), this,
462             SLOT(onMultiSelectionEnabled(bool)));
463
464     connect(aPreviewOp, SIGNAL(stopSelection(const QList<ObjectPtr>&, const bool)), this,
465             SLOT(onStopSelection(const QList<ObjectPtr>&, const bool)));
466     connect(aPreviewOp, SIGNAL(setSelection(const QList<ObjectPtr>&)), this,
467             SLOT(onSetSelection(const QList<ObjectPtr>&)));
468
469     PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
470     if (aSketchOp) {
471       connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
472               SLOT(onPlaneSelected(double, double, double)));
473       connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
474     }
475   }
476
477   return anOperation;
478 }
479
480
481 void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
482 {
483   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
484   if (!anOperation)
485     return;
486
487   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
488   if (!aPreviewOp)
489     return;
490
491   FeaturePtr aFeature = aPreviewOp->feature();
492   if (!aFeature || aFeature->getKind() != theCmdId)
493     return;
494
495   XGUI_Displayer* aDisplayer = xWorkshop()->displayer();
496   // Hide result of sketch
497   std::list<ResultPtr> aResults = aFeature->results();
498   std::list<ResultPtr>::const_iterator aIt;
499   for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt)
500     aDisplayer->erase(*aIt, false);
501
502   std::list<FeaturePtr> aList = aPreviewOp->subFeatures();
503
504   std::list<FeaturePtr>::const_iterator anIt = aList.begin(), aLast = aList.end();
505   for (; anIt != aLast; anIt++) {
506     boost::shared_ptr<SketchPlugin_Feature> aSPFeature = boost::dynamic_pointer_cast<
507         SketchPlugin_Feature>(*anIt);
508     if (!aSPFeature)
509       continue;
510     std::list<ResultPtr> aResults = aSPFeature->results();
511     std::list<ResultPtr>::const_iterator aRIt;
512     for (aRIt = aResults.cbegin(); aRIt != aResults.cend(); ++aRIt) {
513       aDisplayer->display((*aRIt), false);
514       aDisplayer->activate((*aRIt), sketchSelectionModes((*aRIt)));
515     }
516     aDisplayer->display(aSPFeature, false);
517     aDisplayer->activate(aSPFeature, sketchSelectionModes(aSPFeature));
518   }
519   aDisplayer->updateViewer();
520 }
521
522 void PartSet_Module::editFeature(FeaturePtr theFeature)
523 {
524   if (!theFeature)
525     return;
526
527 //  if (theFeature->getKind() == SKETCH_KIND) {
528   //FeaturePtr aFeature = theFeature;
529   //if (XGUI_Tools::isModelObject(aFeature)) {
530   //  ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
531   //  aFeature = aObject->featureRef();
532   //}
533
534   //if (aFeature) {
535   onRestartOperation(theFeature->getKind(), theFeature);
536   updateCurrentPreview(theFeature->getKind());
537   //}
538 //  }
539 }
540
541 void PartSet_Module::onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute)
542 {
543   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
544
545   PartSet_OperationSketchBase* aPreviewOp = 
546     dynamic_cast<PartSet_OperationSketchBase*>(myWorkshop->currentOperation());
547   if (!aPreviewOp)
548     return;
549
550   boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(
551       aFeature->data()->attribute(theAttribute));
552
553   PartSet_Tools::setConstraints(aPreviewOp->sketch(), aFeature, theAttribute, aPoint->x(),
554                                 aPoint->y());
555 }
556
557 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
558                                             Config_WidgetAPI* theWidgetApi,
559                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
560 {
561   if (theType == "sketch-start-label") {
562     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, "");
563     aWgt->setOperationsMgr(xWorkshop()->operationMgr());
564     theModelWidgets.append(aWgt);
565     return aWgt->getControl();
566   } else
567     return 0;
568 }
569
570
571 XGUI_Workshop* PartSet_Module::xWorkshop() const
572 {
573   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
574   if (aConnector) {
575     return aConnector->workshop();
576   }
577   return 0;
578 }
579
580
581 QIntList PartSet_Module::sketchSelectionModes(ObjectPtr theFeature)
582 {
583   QIntList aModes;
584   FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theFeature);
585   if (aFeature) {
586     if (aFeature->getKind() == SketchPlugin_Sketch::ID()) {
587       aModes.append(TopAbs_FACE);
588       return aModes;
589     } else if (PartSet_Tools::isConstraintFeature(aFeature->getKind())) {
590       aModes.append(AIS_DSM_Text);
591       aModes.append(AIS_DSM_Line);
592       return aModes;
593     }
594   } 
595   aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
596   aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
597   return aModes;
598 }
599
600
601 gp_Pln PartSet_Module::getSketchPlane(FeaturePtr theSketch) const
602 {
603   DataPtr aData = theSketch->data();
604   boost::shared_ptr<GeomDataAPI_Point> anOrigin = boost::dynamic_pointer_cast<GeomDataAPI_Point>(
605       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
606   boost::shared_ptr<GeomDataAPI_Dir> aNorm = boost::dynamic_pointer_cast<GeomDataAPI_Dir>(
607       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
608   gp_Pnt aOrig(anOrigin->x(), anOrigin->y(), anOrigin->z());
609   gp_Dir aDir(aNorm->x(), aNorm->y(), aNorm->z());
610   return gp_Pln(aOrig, aDir);
611 }
612