Salome HOME
f4c7826546742b23c4d945a7d307b1e932cbf9b7
[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   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
138 }
139
140
141 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation) 
142 {
143   if (theOperation->isEditOperation())
144     return;
145   /// Restart sketcher operations automatically
146   FeaturePtr aFeature = theOperation->feature();
147   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
148             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
149   if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
150                      myRestartingMode == RM_EmptyFeatureUsed)) {
151     myLastOperationId = theOperation->id();
152     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
153     launchOperation(myLastOperationId);
154   }
155   breakOperationSequence();
156 }
157
158 void PartSet_Module::breakOperationSequence()
159 {
160   myLastOperationId = "";
161   myLastFeature = FeaturePtr();
162   myRestartingMode = RM_None;
163 }
164
165 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
166 {
167   breakOperationSequence();
168 }
169
170 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
171 {
172   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
173     // Display all sketcher sub-Objects
174     myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
175     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
176     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
177
178     for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
179       FeaturePtr aFeature = myCurrentSketch->subFeature(i);
180       std::list<ResultPtr> aResults = aFeature->results();
181       std::list<ResultPtr>::const_iterator aIt;
182       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
183         aDisplayer->display((*aIt), false);
184       }
185       aDisplayer->display(aFeature);
186     }
187     // Hide sketcher result
188     std::list<ResultPtr> aResults = myCurrentSketch->results();
189     std::list<ResultPtr>::const_iterator aIt;
190     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
191       aDisplayer->erase((*aIt), false);
192     }
193     aDisplayer->erase(myCurrentSketch);
194
195
196     if (myPlaneFilter.IsNull()) 
197       myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
198     myWorkshop->viewer()->addSelectionFilter(myPlaneFilter);
199     if (theOperation->isEditOperation()) {
200       // If it is editing of sketch then it means that plane is already defined
201       std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
202       myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
203     }
204   }
205   if (myDocumentShapeFilter.IsNull())
206     myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(myWorkshop);
207   myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
208 }
209
210 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
211 {
212   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
213     DataPtr aData = myCurrentSketch->data();
214     if ((!aData) || (!aData->isValid())) {
215       // The sketch was aborted
216       myCurrentSketch = CompositeFeaturePtr();
217       return; 
218     }
219     // Hide all sketcher sub-Objects
220     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
221     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
222     for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
223       FeaturePtr aFeature = myCurrentSketch->subFeature(i);
224       std::list<ResultPtr> aResults = aFeature->results();
225       std::list<ResultPtr>::const_iterator aIt;
226       for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
227         aDisplayer->erase((*aIt), false);
228       }
229       aDisplayer->erase(aFeature, false);
230     }
231     // Display sketcher result
232     std::list<ResultPtr> aResults = myCurrentSketch->results();
233     std::list<ResultPtr>::const_iterator aIt;
234     for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
235       aDisplayer->display((*aIt), false);
236     }
237     aDisplayer->display(myCurrentSketch);
238     
239     myCurrentSketch = CompositeFeaturePtr();
240     myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter);
241   }
242   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
243 }
244
245 void PartSet_Module::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
246 {
247   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
248 }
249
250
251 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
252 {
253   ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
254   // Restart last operation type 
255   if ((theOperation->id() == myLastOperationId) && myLastFeature) {
256     ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
257     if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
258       // Initialise new line with first point equal to end of previous
259       PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
260       if (aPnt2dWgt) {
261         std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
262         std::shared_ptr<GeomDataAPI_Point2D> aPoint = 
263           std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
264         if (aPoint) {
265           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
266           PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(), 
267             aWgt->attributeID(), aPoint->x(), aPoint->y());
268           theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
269         }
270       }
271     }
272   } else {
273     // Start editing constraint
274     if (theOperation->isEditOperation()) {
275       std::string aId = theOperation->id().toStdString();
276       if (sketchOperationIdList().contains(QString(aId.c_str()))) {
277         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
278             (aId == SketchPlugin_ConstraintLength::ID()) || 
279             (aId == SketchPlugin_ConstraintDistance::ID())) {
280           // Find and activate widget for management of point for dimension line position
281           QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
282           foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
283             PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
284             if (aPntWgt) {
285               aPanel->activateWidget(aPntWgt);
286               return;
287             }
288           }
289         } 
290       }
291     }
292   }
293 }
294
295
296 void PartSet_Module::onSelectionChanged()
297 {
298   // Editing of constraints can be done on selection
299   ModuleBase_ISelection* aSelect = myWorkshop->selection();
300   QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
301   if (aSelected.size() == 1) {
302     ModuleBase_ViewerPrs aPrs = aSelected.first();
303     ObjectPtr aObject = aPrs.object();
304     FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
305     if (aFeature) {
306       std::string aId = aFeature->getKind();
307       if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
308           (aId == SketchPlugin_ConstraintLength::ID()) || 
309           (aId == SketchPlugin_ConstraintDistance::ID())) {
310         editFeature(aFeature);
311       }
312     }
313   }
314 }
315
316 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) 
317 {
318   if (!(theEvent->buttons() & Qt::LeftButton))
319     return;
320
321   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
322   // Use only for sketch operations
323   if (aOperation && myCurrentSketch) {
324     if (!PartSet_Tools::sketchPlane(myCurrentSketch))
325       return;
326
327     bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
328     bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
329
330     // Avoid non-sketch operations
331     if ((!isSketchOpe) && (!isSketcher))
332       return;
333
334     bool isEditing = aOperation->isEditOperation();
335
336     // Ignore creation sketch operation
337     if ((!isSketcher) && (!isEditing))
338       return;
339
340     if (theEvent->modifiers()) {
341       // If user performs multiselection
342       if (isSketchOpe && (!isSketcher))
343         if (!aOperation->commit())
344           aOperation->abort();
345       return;
346     }
347     // Remember highlighted objects for editing
348     ModuleBase_ISelection* aSelect = myWorkshop->selection();
349     QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
350     QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
351     myEditingFeatures.clear();
352     myEditingAttr.clear();
353     if ((aHighlighted.size() == 0) && (aSelected.size() == 0)) {
354       if (isSketchOpe && (!isSketcher))
355         // commit previous operation
356         if (!aOperation->commit())
357           aOperation->abort();
358       return;
359     }
360
361     QObjectPtrList aSelObjects = getSumList(aHighlighted, aSelected);
362     if ((aHighlighted.size() == 1) && (aSelected.size() == 0)) {
363       // Move by selected shape (vertex). Can be used only for single selection
364       foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) {
365         FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object());
366         if (aFeature) {
367           myEditingFeatures.append(aFeature);
368           TopoDS_Shape aShape = aPrs.shape();
369           if (!aShape.IsNull()) {
370             if (aShape.ShapeType() == TopAbs_VERTEX) {
371               AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(), 
372                                                                          aShape, myCurrentSketch);
373               if (aAttr)
374                 myEditingAttr.append(aAttr);
375             }
376           }
377         }
378       }
379     } else {
380       // Provide multi-selection. Can be used only for features
381       foreach (ObjectPtr aObj, aSelObjects) {
382         FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
383         if (aFeature && (!myEditingFeatures.contains(aFeature)))
384           myEditingFeatures.append(aFeature);
385       }
386
387     }
388     // If nothing highlighted - return
389     if (myEditingFeatures.size() == 0)
390       return;
391
392     if (isSketcher) {
393       myIsDragging = true;
394       get2dPoint(theWnd, theEvent, myCurX, myCurY);
395       myDragDone = false;
396       myWorkshop->viewer()->enableSelection(false);
397       launchEditing();
398
399     } else if (isSketchOpe && isEditing) {
400       // If selected another object
401       aOperation->abort();
402
403       myIsDragging = true;
404       get2dPoint(theWnd, theEvent, myCurX, myCurY);
405       myDragDone = false;
406       myWorkshop->viewer()->enableSelection(false);
407
408       // This is necessary in order to finalize previous operation
409       QApplication::processEvents();
410       launchEditing();
411     }
412   }
413 }
414
415
416 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
417                                 double& theX, double& theY)
418 {
419   Handle(V3d_View) aView = theWnd->v3dView();
420   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
421   PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
422 }
423
424
425 void PartSet_Module::launchEditing()
426 {
427   if (myEditingFeatures.size() > 0) {
428     FeaturePtr aFeature = myEditingFeatures.first();
429     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
430               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
431     if (aSPFeature) {
432       editFeature(aSPFeature);
433     }
434   }
435 }
436
437 /// Returns new instance of operation object (used in createOperation for customization)
438 ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
439 {
440   if (theFeatureId == PartSet_OperationSketch::Type()) {
441     return new PartSet_OperationSketch(theFeatureId.c_str(), this);
442   }
443   return ModuleBase_IModule::getNewOperation(theFeatureId);
444 }
445
446
447 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
448 {
449   myWorkshop->viewer()->enableSelection(true);
450   if (myIsDragging) {
451     myIsDragging = false;
452     if (myDragDone) {
453       myWorkshop->currentOperation()->commit();
454       myEditingFeatures.clear();
455       myEditingAttr.clear();
456     }
457   }
458 }
459
460
461 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
462 {
463   if (myIsDragging) {
464     ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
465     if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
466       return; // No edit operation activated
467
468     static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
469     Handle(V3d_View) aView = theWnd->v3dView();
470     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
471     double aX, aY;
472     PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
473     double dX =  aX - myCurX;
474     double dY =  aY - myCurY;
475
476     if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
477         (myEditingAttr.size() == 1) && 
478         myEditingAttr.first()) {
479       // probably we have prehighlighted point
480       AttributePtr aAttr = myEditingAttr.first();
481       std::string aAttrId = aAttr->id();
482       ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
483       QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
484       // Find corresponded widget to provide dragging
485       foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
486         if (aWgt->attributeID() == aAttrId) {
487           PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
488           if (aWgt2d) {
489             aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
490             break;
491           }
492         }
493       }
494     } else {
495       foreach(FeaturePtr aFeature, myEditingFeatures) {
496         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
497           std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
498         if (aSketchFeature) { 
499           aSketchFeature->move(dX, dY);
500           ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
501         }
502       }
503       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
504       Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
505     }
506     myDragDone = true;
507     myCurX = aX;
508     myCurY = aY;
509   }
510 }
511
512 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
513 {
514   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
515   XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
516   anOpMgr->onKeyReleased(theEvent);
517 }
518
519 void PartSet_Module::onEnterReleased()
520 {
521   myRestartingMode = RM_EmptyFeatureUsed;
522 }
523
524 void PartSet_Module::onNoMoreWidgets()
525 {
526   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
527   if (aOperation) {
528     /// Restart sketcher operations automatically
529     FeaturePtr aFeature = aOperation->feature();
530     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
531               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
532     if (aSPFeature) {
533       if (myRestartingMode != RM_Forbided)
534         myRestartingMode = RM_LastFeatureUsed;
535       aOperation->commit();
536     }
537   }
538 }
539
540 QStringList PartSet_Module::sketchOperationIdList() const
541 {
542   QStringList aIds;
543   aIds << SketchPlugin_Line::ID().c_str();
544   aIds << SketchPlugin_Point::ID().c_str();
545   aIds << SketchPlugin_Arc::ID().c_str();
546   aIds << SketchPlugin_Circle::ID().c_str();
547   aIds << SketchPlugin_ConstraintLength::ID().c_str();
548   aIds << SketchPlugin_ConstraintDistance::ID().c_str();
549   aIds << SketchPlugin_ConstraintRigid::ID().c_str();
550   aIds << SketchPlugin_ConstraintRadius::ID().c_str();
551   aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
552   aIds << SketchPlugin_ConstraintParallel::ID().c_str();
553   return aIds;
554 }
555
556 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
557 {
558   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
559   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
560     /// If last line finished on vertex the lines creation sequence has to be break
561     ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
562     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
563     if (aWidgets.last() == aPanel->activeWidget()) {
564       myRestartingMode = RM_Forbided;
565     }
566   }
567 }
568
569 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
570                                             Config_WidgetAPI* theWidgetApi, std::string theParentId,
571                                             QList<ModuleBase_ModelWidget*>& theModelWidgets)
572 {
573   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
574   XGUI_Workshop* aWorkshop = aConnector->workshop();
575   if (theType == "sketch-start-label") {
576     PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
577     aWgt->setWorkshop(aWorkshop);
578     connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)), 
579       this, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
580     theModelWidgets.append(aWgt);
581     return aWgt->getControl();
582
583   } else if (theType == "sketch-2dpoint_selector") {
584     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
585     aWgt->setWorkshop(aWorkshop);
586     aWgt->setSketch(myCurrentSketch);
587
588     connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)), 
589       this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
590
591     theModelWidgets.append(aWgt);
592     return aWgt->getControl();
593
594   } if (theType == "point2ddistance") {
595     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
596     aWgt->setWorkshop(aWorkshop);
597     aWgt->setSketch(myCurrentSketch);
598
599     theModelWidgets.append(aWgt);
600     return aWgt->getControl();
601
602   } if (theType == "sketch_shape_selector") {
603     PartSet_WidgetShapeSelector* aWgt = 
604       new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
605     aWgt->setSketcher(myCurrentSketch);
606
607     theModelWidgets.append(aWgt);
608     return aWgt->getControl();
609
610   } if (theType == "sketch_constraint_shape_selector") {
611     PartSet_WidgetConstraintShapeSelector* aWgt = 
612       new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
613     aWgt->setSketcher(myCurrentSketch);
614
615     theModelWidgets.append(aWgt);
616     return aWgt->getControl();
617
618   }else
619     return 0;
620 }