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