]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
An improvement for the sketch operation restarting mode change.
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 #include "PartSet_Module.h"
2 #include <PartSet_OperationSketch.h>
3 #include <PartSet_WidgetSketchLabel.h>
4 #include <PartSet_Validators.h>
5 #include <PartSet_Tools.h>
6 #include <PartSet_WidgetPoint2D.h>
7 #include <PartSet_WidgetPoint2dDistance.h>
8 #include <PartSet_WidgetShapeSelector.h>
9
10 #include <ModuleBase_Operation.h>
11 #include <ModuleBase_IViewer.h>
12 #include <ModuleBase_IViewWindow.h>
13 #include <ModuleBase_IPropertyPanel.h>
14
15 #include <ModelAPI_Object.h>
16 #include <ModelAPI_Events.h>
17 #include <ModelAPI_Validator.h>
18 #include <ModelAPI_Data.h>
19 #include <ModelAPI_Session.h>
20
21 #include <GeomDataAPI_Point2D.h>
22 #include <GeomDataAPI_Point.h>
23 #include <GeomDataAPI_Dir.h>
24
25 #include <XGUI_MainWindow.h>
26 #include <XGUI_Displayer.h>
27 #include <XGUI_Viewer.h>
28 #include <XGUI_Workshop.h>
29 #include <XGUI_OperationMgr.h>
30 #include <XGUI_ViewPort.h>
31 #include <XGUI_ActionsMgr.h>
32 #include <XGUI_ViewerProxy.h>
33 #include <XGUI_ContextMenuMgr.h>
34 #include <XGUI_PropertyPanel.h>
35 #include <XGUI_ModuleConnector.h>
36 #include <XGUI_Tools.h>
37
38 #include <SketchPlugin_Line.h>
39 #include <SketchPlugin_Sketch.h>
40 #include <SketchPlugin_Point.h>
41 #include <SketchPlugin_Arc.h>
42 #include <SketchPlugin_Circle.h>
43 #include <SketchPlugin_ConstraintLength.h>
44 #include <SketchPlugin_ConstraintDistance.h>
45 #include <SketchPlugin_ConstraintParallel.h>
46 #include <SketchPlugin_ConstraintPerpendicular.h>
47 #include <SketchPlugin_ConstraintRadius.h>
48 #include <SketchPlugin_ConstraintRigid.h>
49
50 #include <Events_Loop.h>
51
52 #include <StdSelect_TypeOfFace.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <BRep_Tool.hxx>
57
58 #include <QObject>
59 #include <QMouseEvent>
60 #include <QString>
61 #include <QTimer>
62 #include <QApplication>
63
64 #include <GeomAlgoAPI_FaceBuilder.h>
65 #include <GeomDataAPI_Dir.h>
66
67 #ifdef _DEBUG
68 #include <QDebug>
69 #endif
70
71
72 /// Returns list of unique objects by sum of objects from List1 and List2
73 QList<ObjectPtr> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
74                                        const QList<ModuleBase_ViewerPrs>& theList2)
75 {
76   QList<ObjectPtr> aRes;
77   foreach (ModuleBase_ViewerPrs aPrs, theList1) {
78     if (!aRes.contains(aPrs.object()))
79       aRes.append(aPrs.object());
80   }
81   foreach (ModuleBase_ViewerPrs aPrs, theList2) {
82     if (!aRes.contains(aPrs.object()))
83       aRes.append(aPrs.object());
84   }
85   return aRes;
86 }
87
88 /*!Create and return new instance of XGUI_Module*/
89 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
90 {
91   return new PartSet_Module(theWshop);
92 }
93
94 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
95   : ModuleBase_IModule(theWshop), 
96   myIsDragging(false), myRestartingMode(RM_None), myDragDone(false)
97 {
98   //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
99   ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer();
100   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
101           this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
102
103   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
104           this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
105
106   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
107           this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
108
109   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
110   XGUI_Workshop* aWorkshop = aConnector->workshop();
111
112   XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
113   connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
114
115   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
116           this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
117 }
118
119 PartSet_Module::~PartSet_Module()
120 {
121   if (!myDocumentShapeFilter.IsNull())
122     myDocumentShapeFilter.Nullify();
123   if (!myPlaneFilter.IsNull())
124     myPlaneFilter.Nullify();
125 }
126
127 void PartSet_Module::registerValidators()
128 {
129   //Registering of validators
130   SessionPtr aMgr = ModelAPI_Session::get();
131   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
132   aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
133   aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
134   aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
135   aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
136   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
137 }
138
139
140 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation) 
141 {
142   if (theOperation->isEditOperation())
143     return;
144   /// Restart sketcher operations automatically
145   FeaturePtr aFeature = theOperation->feature();
146   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
147             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
148   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
149                      myRestartingMode == RM_EmptyFeatureUsed)) {
150     myLastOperationId = theOperation->id();
151     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
152     launchOperation(myLastOperationId);
153   }
154   breakOperationSequence();
155 }
156
157 void PartSet_Module::breakOperationSequence()
158 {
159   myLastOperationId = "";
160   myLastFeature = FeaturePtr();
161   myRestartingMode = RM_None;
162 }
163
164 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
165 {
166   breakOperationSequence();
167 }
168
169 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
170 {
171   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
172     // Display all sketcher sub-Objects
173     myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
174     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
175     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
176
177     for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
178       FeaturePtr aFeature = myCurrentSketch->subFeature(i);
179       std::list<ResultPtr> aResults = aFeature->results();
180       std::list<ResultPtr>::const_iterator aIt;
181       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
182         aDisplayer->display((*aIt), false);
183       }
184       aDisplayer->display(aFeature);
185     }
186     // Hide sketcher result
187     std::list<ResultPtr> aResults = myCurrentSketch->results();
188     std::list<ResultPtr>::const_iterator aIt;
189     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
190       aDisplayer->erase((*aIt), false);
191     }
192     aDisplayer->erase(myCurrentSketch);
193
194
195     if (myPlaneFilter.IsNull()) 
196       myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
197     myWorkshop->viewer()->addSelectionFilter(myPlaneFilter);
198     if (theOperation->isEditOperation()) {
199       // If it is editing of sketch then it means that plane is already defined
200       std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
201       myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
202     }
203   }
204   if (myDocumentShapeFilter.IsNull())
205     myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(myWorkshop);
206   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
207 }
208
209 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
210 {
211   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
212     DataPtr aData = myCurrentSketch->data();
213     if ((!aData) || (!aData->isValid())) {
214       // The sketch was aborted
215       myCurrentSketch = CompositeFeaturePtr();
216       return; 
217     }
218     // Hide all sketcher sub-Objects
219     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
220     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
221     for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
222       FeaturePtr aFeature = myCurrentSketch->subFeature(i);
223       std::list<ResultPtr> aResults = aFeature->results();
224       std::list<ResultPtr>::const_iterator aIt;
225       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
226         aDisplayer->erase((*aIt), false);
227       }
228       aDisplayer->erase(aFeature, false);
229     }
230     // Display sketcher result
231     std::list<ResultPtr> aResults = myCurrentSketch->results();
232     std::list<ResultPtr>::const_iterator aIt;
233     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
234       aDisplayer->display((*aIt), false);
235     }
236     aDisplayer->display(myCurrentSketch);
237     
238     myCurrentSketch = CompositeFeaturePtr();
239     myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter);
240   }
241   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
242 }
243
244 void PartSet_Module::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
245 {
246   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
247 }
248
249
250 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
251 {
252   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
253   // Restart last operation type 
254   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
255     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
256     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
257       // Initialise new line with first point equal to end of previous
258       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
259       if (aPnt2dWgt) {
260         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
261         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
262           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
263         if (aPoint) {
264           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
265           PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(), 
266             aWgt->attributeID(), aPoint->x(), aPoint->y());
267           theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
268         }
269       }
270     }
271   } else {
272     // Start editing constraint
273     if (theOperation->isEditOperation()) {
274       std::string aId = theOperation->id().toStdString();
275       if (sketchOperationIdList().contains(QString(aId.c_str()))) {
276         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
277             (aId == SketchPlugin_ConstraintLength::ID()) || 
278             (aId == SketchPlugin_ConstraintDistance::ID())) {
279           // Find and activate widget for management of point for dimension line position
280           QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
281           foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
282             PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
283             if (aPntWgt) {
284               aPanel->activateWidget(aPntWgt);
285               return;
286             }
287           }
288         } 
289       }
290     }
291   }
292 }
293
294
295 void PartSet_Module::onSelectionChanged()
296 {
297   // Editing of constraints can be done on selection
298   ModuleBase_ISelection* aSelect = myWorkshop->selection();
299   QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
300   if (aSelected.size() == 1) {
301     ModuleBase_ViewerPrs aPrs = aSelected.first();
302     ObjectPtr aObject = aPrs.object();
303     FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
304     if (aFeature) {
305       std::string aId = aFeature->getKind();
306       if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
307           (aId == SketchPlugin_ConstraintLength::ID()) || 
308           (aId == SketchPlugin_ConstraintDistance::ID())) {
309         editFeature(aFeature);
310       }
311     }
312   }
313 }
314
315 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) 
316 {
317   if (!(theEvent->buttons() & Qt::LeftButton))
318     return;
319
320   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
321   // Use only for sketch operations
322   if (aOperation && myCurrentSketch) {
323     if (!PartSet_Tools::sketchPlane(myCurrentSketch))
324       return;
325
326     bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
327     bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
328
329     // Avoid non-sketch operations
330     if ((!isSketchOpe) && (!isSketcher))
331       return;
332
333     bool isEditing = aOperation->isEditOperation();
334
335     // Ignore creation sketch operation
336     if ((!isSketcher) && (!isEditing))
337       return;
338
339     if (theEvent->modifiers()) {
340       // If user performs multiselection
341       if (isSketchOpe && (!isSketcher))
342         if (!aOperation->commit())
343           aOperation->abort();
344       return;
345     }
346     // Remember highlighted objects for editing
347     ModuleBase_ISelection* aSelect = myWorkshop->selection();
348     QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
349     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
350     myEditingFeatures.clear();
351     myEditingAttr.clear();
352     if ((aHighlighted.size() == 0) && (aSelected.size() == 0)) {
353       if (isSketchOpe && (!isSketcher))
354         // commit previous operation
355         if (!aOperation->commit())
356           aOperation->abort();
357       return;
358     }
359
360     QObjectPtrList aSelObjects = getSumList(aHighlighted, aSelected);
361     if ((aHighlighted.size() == 1) && (aSelected.size() == 0)) {
362       // Move by selected shape (vertex). Can be used only for single selection
363       foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) {
364         FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object());
365         if (aFeature) {
366           myEditingFeatures.append(aFeature);
367           TopoDS_Shape aShape = aPrs.shape();
368           if (!aShape.IsNull()) {
369             if (aShape.ShapeType() == TopAbs_VERTEX) {
370               AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(), 
371                                                                          aShape, myCurrentSketch);
372               if (aAttr)
373                 myEditingAttr.append(aAttr);
374             }
375           }
376         }
377       }
378     } else {
379       // Provide multi-selection. Can be used only for features
380       foreach (ObjectPtr aObj, aSelObjects) {
381         FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
382         if (aFeature && (!myEditingFeatures.contains(aFeature)))
383           myEditingFeatures.append(aFeature);
384       }
385
386     }
387     // If nothing highlighted - return
388     if (myEditingFeatures.size() == 0)
389       return;
390
391     if (isSketcher) {
392       myIsDragging = true;
393       get2dPoint(theWnd, theEvent, myCurX, myCurY);
394       myDragDone = false;
395       myWorkshop->viewer()->enableSelection(false);
396       launchEditing();
397
398     } else if (isSketchOpe && isEditing) {
399       // If selected another object
400       aOperation->abort();
401
402       myIsDragging = true;
403       get2dPoint(theWnd, theEvent, myCurX, myCurY);
404       myDragDone = false;
405       myWorkshop->viewer()->enableSelection(false);
406
407       // This is necessary in order to finalize previous operation
408       QApplication::processEvents();
409       launchEditing();
410     }
411   }
412 }
413
414
415 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
416                                 double& theX, double& theY)
417 {
418   Handle(V3d_View) aView = theWnd->v3dView();
419   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
420   PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
421 }
422
423
424 void PartSet_Module::launchEditing()
425 {
426   if (myEditingFeatures.size() > 0) {
427     FeaturePtr aFeature = myEditingFeatures.first();
428     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
429               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
430     if (aSPFeature) {
431       editFeature(aSPFeature);
432     }
433   }
434 }
435
436 /// Returns new instance of operation object (used in createOperation for customization)
437 ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
438 {
439   if (theFeatureId == PartSet_OperationSketch::Type()) {
440     return new PartSet_OperationSketch(theFeatureId.c_str(), this);
441   }
442   return ModuleBase_IModule::getNewOperation(theFeatureId);
443 }
444
445
446 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
447 {
448   myWorkshop->viewer()->enableSelection(true);
449   if (myIsDragging) {
450     myIsDragging = false;
451     if (myDragDone) {
452       myWorkshop->currentOperation()->commit();
453       myEditingFeatures.clear();
454       myEditingAttr.clear();
455     }
456   }
457 }
458
459
460 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
461 {
462   if (myIsDragging) {
463     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
464     if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
465       return; // No edit operation activated
466
467     static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
468     Handle(V3d_View) aView = theWnd->v3dView();
469     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
470     double aX, aY;
471     PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
472     double dX =  aX - myCurX;
473     double dY =  aY - myCurY;
474
475     if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
476         (myEditingAttr.size() == 1) && 
477         myEditingAttr.first()) {
478       // probably we have prehighlighted point
479       AttributePtr aAttr = myEditingAttr.first();
480       std::string aAttrId = aAttr->id();
481       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
482       QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
483       // Find corresponded widget to provide dragging
484       foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
485         if (aWgt->attributeID() == aAttrId) {
486           PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
487           if (aWgt2d) {
488             aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
489             break;
490           }
491         }
492       }
493     } else {
494       foreach(FeaturePtr aFeature, myEditingFeatures) {
495         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
496           std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
497         if (aSketchFeature) { 
498           aSketchFeature->move(dX, dY);
499           ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
500         }
501       }
502       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
503       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
504     }
505     myDragDone = true;
506     myCurX = aX;
507     myCurY = aY;
508   }
509 }
510
511 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
512 {
513   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
514   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
515   anOpMgr->onKeyReleased(theEvent);
516 }
517
518 void PartSet_Module::onEnterReleased()
519 {
520   myRestartingMode = RM_EmptyFeatureUsed;
521 }
522
523 void PartSet_Module::onNoMoreWidgets()
524 {
525   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
526   if (aOperation) {
527     /// Restart sketcher operations automatically
528     FeaturePtr aFeature = aOperation->feature();
529     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
530               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
531     if (aSPFeature) {
532       if (myRestartingMode != RM_Forbided)
533         myRestartingMode = RM_LastFeatureUsed;
534       aOperation->commit();
535     }
536   }
537 }
538
539 QStringList PartSet_Module::sketchOperationIdList() const
540 {
541   QStringList aIds;
542   aIds << SketchPlugin_Line::ID().c_str();
543   aIds << SketchPlugin_Point::ID().c_str();
544   aIds << SketchPlugin_Arc::ID().c_str();
545   aIds << SketchPlugin_Circle::ID().c_str();
546   aIds << SketchPlugin_ConstraintLength::ID().c_str();
547   aIds << SketchPlugin_ConstraintDistance::ID().c_str();
548   aIds << SketchPlugin_ConstraintRigid::ID().c_str();
549   aIds << SketchPlugin_ConstraintRadius::ID().c_str();
550   aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
551   aIds << SketchPlugin_ConstraintParallel::ID().c_str();
552   return aIds;
553 }
554
555 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
556 {
557   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
558   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
559     /// If last line finished on vertex the lines creation sequence has to be break
560     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
561     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
562     if (aWidgets.last() == aPanel->activeWidget()) {
563       myRestartingMode = RM_Forbided;
564     }
565   }
566 }
567
568 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
569                                             Config_WidgetAPI* theWidgetApi, std::string theParentId,
570                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
571 {
572   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
573   XGUI_Workshop* aWorkshop = aConnector->workshop();
574   if (theType == "sketch-start-label") {
575     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
576     aWgt->setWorkshop(aWorkshop);
577     connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)), 
578       this, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
579     theModelWidgets.append(aWgt);
580     return aWgt->getControl();
581
582   } else if (theType == "sketch-2dpoint_selector") {
583     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
584     aWgt->setWorkshop(aWorkshop);
585     aWgt->setSketch(myCurrentSketch);
586
587     connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)), 
588       this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
589
590     theModelWidgets.append(aWgt);
591     return aWgt->getControl();
592
593   } if (theType == "point2ddistance") {
594     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
595     aWgt->setWorkshop(aWorkshop);
596     aWgt->setSketch(myCurrentSketch);
597
598     theModelWidgets.append(aWgt);
599     return aWgt->getControl();
600
601   } if (theType == "sketch_shape_selector") {
602     PartSet_WidgetShapeSelector* aWgt = 
603       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
604     aWgt->setSketcher(myCurrentSketch);
605
606     theModelWidgets.append(aWgt);
607     return aWgt->getControl();
608
609   } if (theType == "sketch_constraint_shape_selector") {
610     PartSet_WidgetConstraintShapeSelector* aWgt = 
611       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
612     aWgt->setSketcher(myCurrentSketch);
613
614     theModelWidgets.append(aWgt);
615     return aWgt->getControl();
616
617   }else
618     return 0;
619 }