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