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>
10 #include <ModuleBase_Operation.h>
11 #include <ModuleBase_IViewer.h>
12 #include <ModuleBase_IViewWindow.h>
13 #include <ModuleBase_IPropertyPanel.h>
14 #include <ModuleBase_WidgetEditor.h>
15 #include <ModuleBase_FilterFactory.h>
16 #include <ModuleBase_FilterLinearEdge.h>
19 #include <ModelAPI_Object.h>
20 #include <ModelAPI_Events.h>
21 #include <ModelAPI_Validator.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Session.h>
25 #include <GeomDataAPI_Point2D.h>
26 #include <GeomDataAPI_Point.h>
27 #include <GeomDataAPI_Dir.h>
29 #include <XGUI_MainWindow.h>
30 #include <XGUI_Displayer.h>
31 #include <XGUI_Viewer.h>
32 #include <XGUI_Workshop.h>
33 #include <XGUI_OperationMgr.h>
34 #include <XGUI_ViewPort.h>
35 #include <XGUI_ActionsMgr.h>
36 #include <XGUI_ViewerProxy.h>
37 #include <XGUI_ContextMenuMgr.h>
38 #include <XGUI_PropertyPanel.h>
39 #include <XGUI_ModuleConnector.h>
40 #include <XGUI_Tools.h>
42 #include <SketchPlugin_Line.h>
43 #include <SketchPlugin_Sketch.h>
44 #include <SketchPlugin_Point.h>
45 #include <SketchPlugin_Arc.h>
46 #include <SketchPlugin_Circle.h>
47 #include <SketchPlugin_ConstraintLength.h>
48 #include <SketchPlugin_ConstraintDistance.h>
49 #include <SketchPlugin_ConstraintParallel.h>
50 #include <SketchPlugin_ConstraintPerpendicular.h>
51 #include <SketchPlugin_ConstraintRadius.h>
52 #include <SketchPlugin_ConstraintRigid.h>
54 #include <Events_Loop.h>
56 #include <StdSelect_TypeOfFace.hxx>
57 #include <TopoDS_Vertex.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <BRep_Tool.hxx>
63 #include <QMouseEvent>
66 #include <QApplication>
68 #include <GeomAlgoAPI_FaceBuilder.h>
69 #include <GeomDataAPI_Dir.h>
76 /// Returns list of unique objects by sum of objects from List1 and List2
77 QList<ObjectPtr> getSumList(const QList<ModuleBase_ViewerPrs>& theList1,
78 const QList<ModuleBase_ViewerPrs>& theList2)
80 QList<ObjectPtr> aRes;
81 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
82 if (!aRes.contains(aPrs.object()))
83 aRes.append(aPrs.object());
85 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
86 if (!aRes.contains(aPrs.object()))
87 aRes.append(aPrs.object());
92 /*!Create and return new instance of XGUI_Module*/
93 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
95 return new PartSet_Module(theWshop);
98 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
99 : ModuleBase_IModule(theWshop),
100 myIsDragging(false), myRestartingMode(RM_None), myDragDone(false)
102 //myWorkshop = dynamic_cast<XGUI_Workshop*>(theWshop);
103 ModuleBase_IViewer* aViewer = aViewer = theWshop->viewer();
104 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
105 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
107 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
108 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
110 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
111 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
113 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
114 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
116 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
117 XGUI_Workshop* aWorkshop = aConnector->workshop();
119 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
120 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
122 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
123 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
126 PartSet_Module::~PartSet_Module()
128 if (!myDocumentShapeFilter.IsNull())
129 myDocumentShapeFilter.Nullify();
130 if (!myPlaneFilter.IsNull())
131 myPlaneFilter.Nullify();
134 void PartSet_Module::registerValidators()
136 //Registering of validators
137 SessionPtr aMgr = ModelAPI_Session::get();
138 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
139 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
140 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
141 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
142 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
143 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
144 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
147 void PartSet_Module::registerFilters()
149 //Registering of selection filters
150 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
151 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
153 aFactory->registerFilter("LinearEdgeFilter", new ModuleBase_FilterLinearEdge);
156 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation)
158 if (theOperation->isEditOperation())
160 /// Restart sketcher operations automatically
161 FeaturePtr aFeature = theOperation->feature();
162 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
163 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
164 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
165 myRestartingMode == RM_EmptyFeatureUsed)) {
166 myLastOperationId = theOperation->id();
167 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
168 launchOperation(myLastOperationId);
170 breakOperationSequence();
173 void PartSet_Module::breakOperationSequence()
175 myLastOperationId = "";
176 myLastFeature = FeaturePtr();
177 myRestartingMode = RM_None;
180 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
182 breakOperationSequence();
185 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
187 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
188 // Display all sketcher sub-Objects
189 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
190 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
191 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
193 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
194 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
195 std::list<ResultPtr> aResults = aFeature->results();
196 std::list<ResultPtr>::const_iterator aIt;
197 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
198 aDisplayer->display((*aIt), false);
200 aDisplayer->display(aFeature);
202 // Hide sketcher result
203 std::list<ResultPtr> aResults = myCurrentSketch->results();
204 std::list<ResultPtr>::const_iterator aIt;
205 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
206 aDisplayer->erase((*aIt), false);
208 aDisplayer->erase(myCurrentSketch);
211 if (myPlaneFilter.IsNull())
212 myPlaneFilter = new ModuleBase_ShapeInPlaneFilter();
213 myWorkshop->viewer()->addSelectionFilter(myPlaneFilter);
214 if (theOperation->isEditOperation()) {
215 // If it is editing of sketch then it means that plane is already defined
216 std::shared_ptr<GeomAPI_Pln> aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
217 myPlaneFilter->setPlane(aPln->impl<gp_Pln>());
220 if (myDocumentShapeFilter.IsNull())
221 myDocumentShapeFilter = new PartSet_GlobalFilter(myWorkshop);
222 myWorkshop->viewer()->addSelectionFilter(myDocumentShapeFilter);
225 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
227 if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
228 DataPtr aData = myCurrentSketch->data();
229 if ((!aData) || (!aData->isValid())) {
230 // The sketch was aborted
231 myCurrentSketch = CompositeFeaturePtr();
234 // Hide all sketcher sub-Objects
235 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
236 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
237 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
238 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
239 std::list<ResultPtr> aResults = aFeature->results();
240 std::list<ResultPtr>::const_iterator aIt;
241 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
242 aDisplayer->erase((*aIt), false);
244 aDisplayer->erase(aFeature, false);
246 // Display sketcher result
247 std::list<ResultPtr> aResults = myCurrentSketch->results();
248 std::list<ResultPtr>::const_iterator aIt;
249 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
250 aDisplayer->display((*aIt), false);
252 aDisplayer->display(myCurrentSketch);
254 myCurrentSketch = CompositeFeaturePtr();
255 myWorkshop->viewer()->removeSelectionFilter(myPlaneFilter);
257 myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
260 void PartSet_Module::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
262 myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
266 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
268 ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
269 if ((theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) &&
270 (theOperation->isEditOperation())) {
271 // we have to manually activate the sketch label in edit mode
272 aPanel->activateWidget(aPanel->modelWidgets().first());
276 // Restart last operation type
277 if ((theOperation->id() == myLastOperationId) && myLastFeature) {
278 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
279 if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
280 // Initialise new line with first point equal to end of previous
281 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
283 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
284 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
285 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
287 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
288 PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(),
289 aWgt->attributeID(), aPoint->x(), aPoint->y());
290 theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
295 // Start editing constraint
296 if (theOperation->isEditOperation()) {
297 std::string aId = theOperation->id().toStdString();
298 if (sketchOperationIdList().contains(QString(aId.c_str()))) {
299 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
300 (aId == SketchPlugin_ConstraintLength::ID()) ||
301 (aId == SketchPlugin_ConstraintDistance::ID())) {
302 // Find and activate widget for management of point for dimension line position
303 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
304 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
305 PartSet_WidgetPoint2D* aPntWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
307 aPanel->activateWidget(aPntWgt);
318 void PartSet_Module::onSelectionChanged()
320 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
321 bool isSketcherOp = false;
322 // An edit operation is enable only if the current opeation is the sketch operation
323 if (aOperation && myCurrentSketch) {
324 if (PartSet_Tools::sketchPlane(myCurrentSketch))
325 isSketcherOp = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
330 // Editing of constraints can be done on selection
331 ModuleBase_ISelection* aSelect = myWorkshop->selection();
332 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
333 if (aSelected.size() == 1) {
334 ModuleBase_ViewerPrs aPrs = aSelected.first();
335 ObjectPtr aObject = aPrs.object();
336 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
338 std::string aId = aFeature->getKind();
339 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
340 (aId == SketchPlugin_ConstraintLength::ID()) ||
341 (aId == SketchPlugin_ConstraintDistance::ID())) {
342 editFeature(aFeature);
348 void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
350 if (!(theEvent->buttons() & Qt::LeftButton))
353 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
354 // Use only for sketch operations
355 if (aOperation && myCurrentSketch) {
356 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
359 bool isSketcher = (aOperation->id().toStdString() == SketchPlugin_Sketch::ID());
360 bool isSketchOpe = sketchOperationIdList().contains(aOperation->id());
362 // Avoid non-sketch operations
363 if ((!isSketchOpe) && (!isSketcher))
366 bool isEditing = aOperation->isEditOperation();
368 // Ignore creation sketch operation
369 if ((!isSketcher) && (!isEditing))
372 if (theEvent->modifiers()) {
373 // If user performs multiselection
374 if (isSketchOpe && (!isSketcher))
375 if (!aOperation->commit())
379 // Remember highlighted objects for editing
380 ModuleBase_ISelection* aSelect = myWorkshop->selection();
381 QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
382 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
383 myEditingFeatures.clear();
384 myEditingAttr.clear();
385 if ((aHighlighted.size() == 0) && (aSelected.size() == 0)) {
386 if (isSketchOpe && (!isSketcher))
387 // commit previous operation
388 if (!aOperation->commit())
393 QObjectPtrList aSelObjects = getSumList(aHighlighted, aSelected);
394 if ((aHighlighted.size() == 1) && (aSelected.size() == 0)) {
395 // Move by selected shape (vertex). Can be used only for single selection
396 foreach(ModuleBase_ViewerPrs aPrs, aHighlighted) {
397 FeaturePtr aFeature = ModelAPI_Feature::feature(aHighlighted.first().object());
399 myEditingFeatures.append(aFeature);
400 TopoDS_Shape aShape = aPrs.shape();
401 if (!aShape.IsNull()) {
402 if (aShape.ShapeType() == TopAbs_VERTEX) {
403 AttributePtr aAttr = PartSet_Tools::findAttributeBy2dPoint(myEditingFeatures.first(),
404 aShape, myCurrentSketch);
406 myEditingAttr.append(aAttr);
412 // Provide multi-selection. Can be used only for features
413 foreach (ObjectPtr aObj, aSelObjects) {
414 FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
415 if (aFeature && (!myEditingFeatures.contains(aFeature)))
416 myEditingFeatures.append(aFeature);
420 // If nothing highlighted - return
421 if (myEditingFeatures.size() == 0)
426 get2dPoint(theWnd, theEvent, myCurX, myCurY);
428 myWorkshop->viewer()->enableSelection(false);
431 } else if (isSketchOpe && isEditing) {
432 // If selected another object
436 get2dPoint(theWnd, theEvent, myCurX, myCurY);
438 myWorkshop->viewer()->enableSelection(false);
440 // This is necessary in order to finalize previous operation
441 QApplication::processEvents();
448 void PartSet_Module::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
449 double& theX, double& theY)
451 Handle(V3d_View) aView = theWnd->v3dView();
452 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
453 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, theX, theY);
457 void PartSet_Module::launchEditing()
459 if (myEditingFeatures.size() > 0) {
460 FeaturePtr aFeature = myEditingFeatures.first();
461 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
462 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
464 editFeature(aSPFeature);
469 /// Returns new instance of operation object (used in createOperation for customization)
470 ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
472 if (theFeatureId == PartSet_OperationSketch::Type()) {
473 return new PartSet_OperationSketch(theFeatureId.c_str(), this);
475 return ModuleBase_IModule::getNewOperation(theFeatureId);
479 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
481 myWorkshop->viewer()->enableSelection(true);
483 myIsDragging = false;
485 myWorkshop->currentOperation()->commit();
486 myEditingFeatures.clear();
487 myEditingAttr.clear();
493 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
496 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
497 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
498 return; // No edit operation activated
500 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
501 Handle(V3d_View) aView = theWnd->v3dView();
502 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
504 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
505 double dX = aX - myCurX;
506 double dY = aY - myCurY;
508 if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
509 (myEditingAttr.size() == 1) &&
510 myEditingAttr.first()) {
511 // probably we have prehighlighted point
512 AttributePtr aAttr = myEditingAttr.first();
513 std::string aAttrId = aAttr->id();
514 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
515 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
516 // Find corresponded widget to provide dragging
517 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
518 if (aWgt->attributeID() == aAttrId) {
519 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
521 aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
527 foreach(FeaturePtr aFeature, myEditingFeatures) {
528 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
529 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
530 if (aSketchFeature) {
531 aSketchFeature->move(dX, dY);
532 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
535 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
536 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
544 void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
546 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
547 if (aOperation->isEditOperation()) {
548 std::string aId = aOperation->id().toStdString();
549 if ((aId == SketchPlugin_ConstraintLength::ID()) ||
550 (aId == SketchPlugin_ConstraintDistance::ID()) ||
551 (aId == SketchPlugin_ConstraintRadius::ID()))
553 // Activate dimension value editing on double click
554 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
555 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
556 // Find corresponded widget to activate value editing
557 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
558 if (aWgt->attributeID() == "ConstraintValue") {
567 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
569 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
570 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
571 anOpMgr->onKeyReleased(theEvent);
574 void PartSet_Module::onEnterReleased()
576 myRestartingMode = RM_EmptyFeatureUsed;
579 void PartSet_Module::onNoMoreWidgets()
581 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
583 /// Restart sketcher operations automatically
584 FeaturePtr aFeature = aOperation->feature();
585 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
586 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
588 if (myRestartingMode != RM_Forbided)
589 myRestartingMode = RM_LastFeatureUsed;
590 aOperation->commit();
595 QStringList PartSet_Module::sketchOperationIdList() const
598 aIds << SketchPlugin_Line::ID().c_str();
599 aIds << SketchPlugin_Point::ID().c_str();
600 aIds << SketchPlugin_Arc::ID().c_str();
601 aIds << SketchPlugin_Circle::ID().c_str();
602 aIds << SketchPlugin_ConstraintLength::ID().c_str();
603 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
604 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
605 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
606 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
607 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
611 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
613 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
614 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
615 /// If last line finished on vertex the lines creation sequence has to be break
616 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
617 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
618 if (aWidgets.last() == aPanel->activeWidget()) {
619 myRestartingMode = RM_Forbided;
624 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
625 Config_WidgetAPI* theWidgetApi, std::string theParentId,
626 QList<ModuleBase_ModelWidget*>& theModelWidgets)
628 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
629 XGUI_Workshop* aWorkshop = aConnector->workshop();
630 if (theType == "sketch-start-label") {
631 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
632 aWgt->setWorkshop(aWorkshop);
633 connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
634 this, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
635 theModelWidgets.append(aWgt);
636 return aWgt->getControl();
638 } else if (theType == "sketch-2dpoint_selector") {
639 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
640 aWgt->setWorkshop(aWorkshop);
641 aWgt->setSketch(myCurrentSketch);
643 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
644 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
646 theModelWidgets.append(aWgt);
647 return aWgt->getControl();
649 } if (theType == "point2ddistance") {
650 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
651 aWgt->setWorkshop(aWorkshop);
652 aWgt->setSketch(myCurrentSketch);
654 theModelWidgets.append(aWgt);
655 return aWgt->getControl();
657 } if (theType == "sketch_shape_selector") {
658 PartSet_WidgetShapeSelector* aWgt =
659 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
660 aWgt->setSketcher(myCurrentSketch);
662 theModelWidgets.append(aWgt);
663 return aWgt->getControl();
665 } if (theType == "sketch_constraint_shape_selector") {
666 PartSet_WidgetConstraintShapeSelector* aWgt =
667 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
668 aWgt->setSketcher(myCurrentSketch);
670 theModelWidgets.append(aWgt);
671 return aWgt->getControl();