1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include <PartSet_WidgetSketchLabel.h>
5 #include <PartSet_Validators.h>
6 #include <PartSet_Tools.h>
7 #include <PartSet_WidgetPoint2d.h>
8 #include <PartSet_WidgetPoint2dDistance.h>
9 #include <PartSet_WidgetShapeSelector.h>
11 #include <ModuleBase_Operation.h>
12 #include <ModuleBase_IViewer.h>
13 #include <ModuleBase_IViewWindow.h>
14 #include <ModuleBase_IPropertyPanel.h>
15 #include <ModuleBase_WidgetEditor.h>
16 #include <ModuleBase_FilterFactory.h>
17 #include <ModuleBase_FilterLinearEdge.h>
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_Events.h>
22 #include <ModelAPI_Validator.h>
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Session.h>
26 #include <GeomDataAPI_Point2D.h>
27 #include <GeomDataAPI_Point.h>
28 #include <GeomDataAPI_Dir.h>
30 #include <XGUI_Displayer.h>
31 #include <XGUI_Workshop.h>
32 #include <XGUI_OperationMgr.h>
33 #include <XGUI_PropertyPanel.h>
34 #include <XGUI_ModuleConnector.h>
35 #include <XGUI_Tools.h>
37 #include <SketchPlugin_Line.h>
38 #include <SketchPlugin_Sketch.h>
39 #include <SketchPlugin_Point.h>
40 #include <SketchPlugin_Arc.h>
41 #include <SketchPlugin_Circle.h>
42 #include <SketchPlugin_ConstraintLength.h>
43 #include <SketchPlugin_ConstraintDistance.h>
44 #include <SketchPlugin_ConstraintParallel.h>
45 #include <SketchPlugin_ConstraintPerpendicular.h>
46 #include <SketchPlugin_ConstraintRadius.h>
47 #include <SketchPlugin_ConstraintRigid.h>
49 #include <Events_Loop.h>
51 #include <StdSelect_TypeOfFace.hxx>
52 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Shape.hxx>
55 #include <BRep_Tool.hxx>
58 #include <QMouseEvent>
61 #include <QApplication>
63 #include <GeomAlgoAPI_FaceBuilder.h>
64 #include <GeomDataAPI_Dir.h>
71 /// Returns list of unique objects by sum of objects from List1 and List2
72 QList<ObjectPtr> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
73 const QList<ModuleBase_ViewerPrs>& theList2)
75 QList<ObjectPtr> aRes;
76 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
77 if (!aRes.contains(aPrs.object()))
78 aRes.append(aPrs.object());
80 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
81 if (!aRes.contains(aPrs.object()))
82 aRes.append(aPrs.object());
87 /*!Create and return new instance of XGUI_Module*/
88 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
90 return new PartSet_Module(theWshop);
93 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
94 : ModuleBase_IModule(theWshop),
95 myIsDragging(false), myRestartingMode(RM_None), myDragDone(false)
97 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
98 ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer();
99 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
100 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
102 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
103 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
105 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
106 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
108 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
109 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
111 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
112 XGUI_Workshop* aWorkshop = aConnector->workshop();
114 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
115 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
116 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
117 this, SLOT(onOperationActivatedByPreselection()));
119 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
120 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
123 PartSet_Module::~PartSet_Module()
125 if (!myDocumentShapeFilter.IsNull())
126 myDocumentShapeFilter.Nullify();
127 if (!myPlaneFilter.IsNull())
128 myPlaneFilter.Nullify();
131 void PartSet_Module::registerValidators()
133 //Registering of validators
134 SessionPtr aMgr = ModelAPI_Session::get();
135 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
136 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
137 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
138 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
139 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
140 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
141 aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
142 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
145 void PartSet_Module::registerFilters()
147 //Registering of selection filters
148 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
149 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
151 aFactory->registerFilter("LinearEdgeFilter", new ModuleBase_FilterLinearEdge);
154 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
156 if (theOperation->isEditOperation())
158 /// Restart sketcher operations automatically
159 FeaturePtr aFeature = theOperation->feature();
160 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
161 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
162 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
163 myRestartingMode == RM_EmptyFeatureUsed)) {
164 myLastOperationId = theOperation->id();
165 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
166 launchOperation(myLastOperationId);
168 breakOperationSequence();
171 void PartSet_Module::breakOperationSequence()
173 myLastOperationId = "";
174 myLastFeature = FeaturePtr();
175 myRestartingMode = RM_None;
178 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
180 breakOperationSequence();
183 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
185 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
186 // Display all sketcher sub-Objects
187 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
188 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
189 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
191 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
192 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
193 std::list<ResultPtr> aResults = aFeature->results();
194 std::list<ResultPtr>::const_iterator aIt;
195 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
196 aDisplayer->display((*aIt), false);
198 aDisplayer->display(aFeature);
200 // Hide sketcher result
201 std::list<ResultPtr> aResults = myCurrentSketch->results();
202 std::list<ResultPtr>::const_iterator aIt;
203 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
204 aDisplayer->erase((*aIt), false);
206 aDisplayer->erase(myCurrentSketch);
209 if (myPlaneFilter.IsNull())
210 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
211 myWorkshop->viewer()->addSelectionFilter(myPlaneFilter);
212 if (theOperation->isEditOperation()) {
213 // If it is editing of sketch then it means that plane is already defined
214 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
215 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
218 if (myDocumentShapeFilter.IsNull())
219 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
220 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
223 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
225 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
226 DataPtr aData = myCurrentSketch->data();
227 if ((!aData) || (!aData->isValid())) {
228 // The sketch was aborted
229 myCurrentSketch = CompositeFeaturePtr();
232 // Hide all sketcher sub-Objects
233 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
234 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
235 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
236 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
237 std::list<ResultPtr> aResults = aFeature->results();
238 std::list<ResultPtr>::const_iterator aIt;
239 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
240 aDisplayer->erase((*aIt), false);
242 aDisplayer->erase(aFeature, false);
244 // Display sketcher result
245 std::list<ResultPtr> aResults = myCurrentSketch->results();
246 std::list<ResultPtr>::const_iterator aIt;
247 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
248 aDisplayer->display((*aIt), false);
250 aDisplayer->display(myCurrentSketch);
252 myCurrentSketch = CompositeFeaturePtr();
253 myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter);
255 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
258 void PartSet_Module::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
260 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
264 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
266 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
267 if ((theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) &&
268 (theOperation->isEditOperation())) {
269 // we have to manually activate the sketch label in edit mode
270 aPanel->activateWidget(aPanel->modelWidgets().first());
274 // Restart last operation type
275 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
276 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
277 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
278 // Initialise new line with first point equal to end of previous
279 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
281 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
282 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
283 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
285 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
286 PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(),
287 aWgt->attributeID(), aPoint->x(), aPoint->y());
288 theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
293 // Start editing constraint
294 if (theOperation->isEditOperation()) {
295 std::string aId = theOperation->id().toStdString();
296 if (sketchOperationIdList().contains(QString(aId.c_str()))) {
297 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
298 (aId == SketchPlugin_ConstraintLength::ID()) ||
299 (aId == SketchPlugin_ConstraintDistance::ID())) {
300 // Find and activate widget for management of point for dimension line position
301 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
302 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
303 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
305 aPanel->activateWidget(aPntWgt);
316 void PartSet_Module::onSelectionChanged()
318 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
319 bool isSketcherOp = false;
320 // An edit operation is enable only if the current opeation is the sketch operation
321 if (aOperation && myCurrentSketch) {
322 if (PartSet_Tools::sketchPlane(myCurrentSketch))
323 isSketcherOp = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
328 // Editing of constraints can be done on selection
329 ModuleBase_ISelection* aSelect = myWorkshop->selection();
330 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
331 if (aSelected.size() == 1) {
332 ModuleBase_ViewerPrs aPrs = aSelected.first();
333 ObjectPtr aObject = aPrs.object();
334 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
336 std::string aId = aFeature->getKind();
337 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
338 (aId == SketchPlugin_ConstraintLength::ID()) ||
339 (aId == SketchPlugin_ConstraintDistance::ID())) {
340 editFeature(aFeature);
346 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
348 if (!(theEvent->buttons() & Qt::LeftButton))
351 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
352 // Use only for sketch operations
353 if (aOperation && myCurrentSketch) {
354 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
357 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
358 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
360 // Avoid non-sketch operations
361 if ((!isSketchOpe) && (!isSketcher))
364 bool isEditing = aOperation->isEditOperation();
366 // Ignore creation sketch operation
367 if ((!isSketcher) && (!isEditing))
370 if (theEvent->modifiers()) {
371 // If user performs multiselection
372 if (isSketchOpe && (!isSketcher))
373 if (!aOperation->commit())
377 // Remember highlighted objects for editing
378 ModuleBase_ISelection* aSelect = myWorkshop->selection();
379 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
380 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
381 myEditingFeatures.clear();
382 myEditingAttr.clear();
383 if ((aHighlighted.size() == 0) && (aSelected.size() == 0)) {
384 if (isSketchOpe && (!isSketcher))
385 // commit previous operation
386 if (!aOperation->commit())
391 QObjectPtrList aSelObjects = getSumList(aHighlighted, aSelected);
392 if ((aHighlighted.size() == 1) && (aSelected.size() == 0)) {
393 // Move by selected shape (vertex). Can be used only for single selection
394 foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) {
395 FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object());
397 myEditingFeatures.append(aFeature);
398 TopoDS_Shape aShape = aPrs.shape();
399 if (!aShape.IsNull()) {
400 if (aShape.ShapeType() == TopAbs_VERTEX) {
401 AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(),
402 aShape, myCurrentSketch);
404 myEditingAttr.append(aAttr);
410 // Provide multi-selection. Can be used only for features
411 foreach (ObjectPtr aObj, aSelObjects) {
412 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
413 if (aFeature && (!myEditingFeatures.contains(aFeature)))
414 myEditingFeatures.append(aFeature);
418 // If nothing highlighted - return
419 if (myEditingFeatures.size() == 0)
424 get2dPoint(theWnd, theEvent, myCurX, myCurY);
426 myWorkshop->viewer()->enableSelection(false);
429 } else if (isSketchOpe && isEditing) {
430 // If selected another object
434 get2dPoint(theWnd, theEvent, myCurX, myCurY);
436 myWorkshop->viewer()->enableSelection(false);
438 // This is necessary in order to finalize previous operation
439 QApplication::processEvents();
446 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
447 double& theX, double& theY)
449 Handle(V3d_View) aView = theWnd->v3dView();
450 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
451 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
455 void PartSet_Module::launchEditing()
457 if (myEditingFeatures.size() > 0) {
458 FeaturePtr aFeature = myEditingFeatures.first();
459 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
460 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
462 editFeature(aSPFeature);
467 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
469 myWorkshop->viewer()->enableSelection(true);
471 myIsDragging = false;
473 myWorkshop->currentOperation()->commit();
474 myEditingFeatures.clear();
475 myEditingAttr.clear();
481 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
484 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
485 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
486 return; // No edit operation activated
488 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
489 Handle(V3d_View) aView = theWnd->v3dView();
490 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
492 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
493 double dX = aX - myCurX;
494 double dY = aY - myCurY;
496 if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
497 (myEditingAttr.size() == 1) &&
498 myEditingAttr.first()) {
499 // probably we have prehighlighted point
500 AttributePtr aAttr = myEditingAttr.first();
501 std::string aAttrId = aAttr->id();
502 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
503 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
504 // Find corresponded widget to provide dragging
505 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
506 if (aWgt->attributeID() == aAttrId) {
507 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
509 aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
515 foreach(FeaturePtr aFeature, myEditingFeatures) {
516 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
517 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
518 if (aSketchFeature) {
519 aSketchFeature->move(dX, dY);
520 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
523 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
524 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
532 void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
534 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
535 if (aOperation && aOperation->isEditOperation()) {
536 std::string aId = aOperation->id().toStdString();
537 if ((aId == SketchPlugin_ConstraintLength::ID()) ||
538 (aId == SketchPlugin_ConstraintDistance::ID()) ||
539 (aId == SketchPlugin_ConstraintRadius::ID()))
541 // Activate dimension value editing on double click
542 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
543 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
544 // Find corresponded widget to activate value editing
545 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
546 if (aWgt->attributeID() == "ConstraintValue") {
555 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
557 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
558 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
559 anOpMgr->onKeyReleased(theEvent);
562 void PartSet_Module::onEnterReleased()
564 myRestartingMode = RM_EmptyFeatureUsed;
567 void PartSet_Module::onOperationActivatedByPreselection()
569 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
573 // Set final definitions if they are necessary
574 //propertyPanelDefined(aOperation);
576 /// Commit sketcher operations automatically
577 FeaturePtr aFeature = aOperation->feature();
578 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
579 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
581 aOperation->commit();
585 void PartSet_Module::onNoMoreWidgets()
587 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
589 /// Restart sketcher operations automatically
590 FeaturePtr aFeature = aOperation->feature();
591 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
592 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
594 if (myRestartingMode != RM_Forbided)
595 myRestartingMode = RM_LastFeatureUsed;
596 aOperation->commit();
601 QStringList PartSet_Module::sketchOperationIdList() const
604 aIds << SketchPlugin_Line::ID().c_str();
605 aIds << SketchPlugin_Point::ID().c_str();
606 aIds << SketchPlugin_Arc::ID().c_str();
607 aIds << SketchPlugin_Circle::ID().c_str();
608 aIds << SketchPlugin_ConstraintLength::ID().c_str();
609 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
610 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
611 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
612 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
613 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
617 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
619 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
620 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
621 /// If last line finished on vertex the lines creation sequence has to be break
622 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
623 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
624 if (aWidgets.last() == aPanel->activeWidget()) {
625 myRestartingMode = RM_Forbided;
630 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
631 Config_WidgetAPI* theWidgetApi, std::string theParentId,
632 QList<ModuleBase_ModelWidget*>& theModelWidgets)
634 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
635 XGUI_Workshop* aWorkshop = aConnector->workshop();
636 if (theType == "sketch-start-label") {
637 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
638 aWgt->setWorkshop(aWorkshop);
639 connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
640 this, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
641 theModelWidgets.append(aWgt);
642 return aWgt->getControl();
644 } else if (theType == "sketch-2dpoint_selector") {
645 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
646 aWgt->setWorkshop(aWorkshop);
647 aWgt->setSketch(myCurrentSketch);
649 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
650 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
652 theModelWidgets.append(aWgt);
653 return aWgt->getControl();
655 } if (theType == "point2ddistance") {
656 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
657 aWgt->setWorkshop(aWorkshop);
658 aWgt->setSketch(myCurrentSketch);
660 theModelWidgets.append(aWgt);
661 return aWgt->getControl();
663 } if (theType == "sketch_shape_selector") {
664 PartSet_WidgetShapeSelector* aWgt =
665 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
666 aWgt->setSketcher(myCurrentSketch);
668 theModelWidgets.append(aWgt);
669 return aWgt->getControl();
671 } if (theType == "sketch_constraint_shape_selector") {
672 PartSet_WidgetConstraintShapeSelector* aWgt =
673 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
674 aWgt->setSketcher(myCurrentSketch);
676 theModelWidgets.append(aWgt);
677 return aWgt->getControl();