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