1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include <PartSet_OperationSketch.h>
5 #include <PartSet_WidgetSketchLabel.h>
6 #include <PartSet_Validators.h>
7 #include <PartSet_Tools.h>
8 #include <PartSet_WidgetPoint2d.h>
9 #include <PartSet_WidgetPoint2dDistance.h>
10 #include <PartSet_WidgetShapeSelector.h>
12 #include <ModuleBase_Operation.h>
13 #include <ModuleBase_IViewer.h>
14 #include <ModuleBase_IViewWindow.h>
15 #include <ModuleBase_IPropertyPanel.h>
16 #include <ModuleBase_WidgetEditor.h>
17 #include <ModuleBase_FilterFactory.h>
18 #include <ModuleBase_FilterLinearEdge.h>
21 #include <ModelAPI_Object.h>
22 #include <ModelAPI_Events.h>
23 #include <ModelAPI_Validator.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Session.h>
27 #include <GeomDataAPI_Point2D.h>
28 #include <GeomDataAPI_Point.h>
29 #include <GeomDataAPI_Dir.h>
31 #include <XGUI_Displayer.h>
32 #include <XGUI_Workshop.h>
33 #include <XGUI_OperationMgr.h>
34 #include <XGUI_PropertyPanel.h>
35 #include <XGUI_ModuleConnector.h>
36 #include <XGUI_Tools.h>
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>
50 #include <Events_Loop.h>
52 #include <StdSelect_TypeOfFace.hxx>
53 #include <TopoDS_Vertex.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <BRep_Tool.hxx>
59 #include <QMouseEvent>
62 #include <QApplication>
64 #include <GeomAlgoAPI_FaceBuilder.h>
65 #include <GeomDataAPI_Dir.h>
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)
76 QList<ObjectPtr> aRes;
77 foreach (ModuleBase_ViewerPrs aPrs, theList1) {
78 if (!aRes.contains(aPrs.object()))
79 aRes.append(aPrs.object());
81 foreach (ModuleBase_ViewerPrs aPrs, theList2) {
82 if (!aRes.contains(aPrs.object()))
83 aRes.append(aPrs.object());
88 /*!Create and return new instance of XGUI_Module*/
89 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
91 return new PartSet_Module(theWshop);
94 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
95 : ModuleBase_IModule(theWshop),
96 myIsDragging(false), myRestartingMode(RM_None), myDragDone(false)
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*)));
103 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
104 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
106 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
107 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
109 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
110 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
112 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
113 XGUI_Workshop* aWorkshop = aConnector->workshop();
115 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
116 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
117 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
118 this, SLOT(onOperationActivatedByPreselection()));
120 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
121 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
124 PartSet_Module::~PartSet_Module()
126 if (!myDocumentShapeFilter.IsNull())
127 myDocumentShapeFilter.Nullify();
128 if (!myPlaneFilter.IsNull())
129 myPlaneFilter.Nullify();
132 void PartSet_Module::registerValidators()
134 //Registering of validators
135 SessionPtr aMgr = ModelAPI_Session::get();
136 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
137 aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
138 aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
139 aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
140 aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
141 aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
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 /// Returns new instance of operation object (used in createOperation for customization)
468 ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
470 if (theFeatureId == PartSet_OperationSketch::Type()) {
471 return new PartSet_OperationSketch(theFeatureId.c_str(), this);
473 return ModuleBase_IModule::getNewOperation(theFeatureId);
477 void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
479 myWorkshop->viewer()->enableSelection(true);
481 myIsDragging = false;
483 myWorkshop->currentOperation()->commit();
484 myEditingFeatures.clear();
485 myEditingAttr.clear();
491 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
494 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
495 if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
496 return; // No edit operation activated
498 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
499 Handle(V3d_View) aView = theWnd->v3dView();
500 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
502 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
503 double dX = aX - myCurX;
504 double dY = aY - myCurY;
506 if ((aOperation->id().toStdString() == SketchPlugin_Line::ID()) &&
507 (myEditingAttr.size() == 1) &&
508 myEditingAttr.first()) {
509 // probably we have prehighlighted point
510 AttributePtr aAttr = myEditingAttr.first();
511 std::string aAttrId = aAttr->id();
512 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
513 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
514 // Find corresponded widget to provide dragging
515 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
516 if (aWgt->attributeID() == aAttrId) {
517 PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
519 aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
525 foreach(FeaturePtr aFeature, myEditingFeatures) {
526 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
527 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
528 if (aSketchFeature) {
529 aSketchFeature->move(dX, dY);
530 ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
533 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_MOVED));
534 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
542 void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
544 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
545 if (aOperation->isEditOperation()) {
546 std::string aId = aOperation->id().toStdString();
547 if ((aId == SketchPlugin_ConstraintLength::ID()) ||
548 (aId == SketchPlugin_ConstraintDistance::ID()) ||
549 (aId == SketchPlugin_ConstraintRadius::ID()))
551 // Activate dimension value editing on double click
552 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
553 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
554 // Find corresponded widget to activate value editing
555 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
556 if (aWgt->attributeID() == "ConstraintValue") {
565 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
567 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
568 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
569 anOpMgr->onKeyReleased(theEvent);
572 void PartSet_Module::onEnterReleased()
574 myRestartingMode = RM_EmptyFeatureUsed;
577 void PartSet_Module::onOperationActivatedByPreselection()
579 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
583 // Set final definitions if they are necessary
584 //propertyPanelDefined(aOperation);
586 /// Commit sketcher operations automatically
587 FeaturePtr aFeature = aOperation->feature();
588 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
589 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
591 aOperation->commit();
595 void PartSet_Module::onNoMoreWidgets()
597 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
599 /// Restart sketcher operations automatically
600 FeaturePtr aFeature = aOperation->feature();
601 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
602 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
604 if (myRestartingMode != RM_Forbided)
605 myRestartingMode = RM_LastFeatureUsed;
606 aOperation->commit();
611 QStringList PartSet_Module::sketchOperationIdList() const
614 aIds << SketchPlugin_Line::ID().c_str();
615 aIds << SketchPlugin_Point::ID().c_str();
616 aIds << SketchPlugin_Arc::ID().c_str();
617 aIds << SketchPlugin_Circle::ID().c_str();
618 aIds << SketchPlugin_ConstraintLength::ID().c_str();
619 aIds << SketchPlugin_ConstraintDistance::ID().c_str();
620 aIds << SketchPlugin_ConstraintRigid::ID().c_str();
621 aIds << SketchPlugin_ConstraintRadius::ID().c_str();
622 aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
623 aIds << SketchPlugin_ConstraintParallel::ID().c_str();
627 void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
629 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
630 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
631 /// If last line finished on vertex the lines creation sequence has to be break
632 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
633 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
634 if (aWidgets.last() == aPanel->activeWidget()) {
635 myRestartingMode = RM_Forbided;
640 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
641 Config_WidgetAPI* theWidgetApi, std::string theParentId,
642 QList<ModuleBase_ModelWidget*>& theModelWidgets)
644 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
645 XGUI_Workshop* aWorkshop = aConnector->workshop();
646 if (theType == "sketch-start-label") {
647 PartSet_WidgetSketchLabel* aWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId);
648 aWgt->setWorkshop(aWorkshop);
649 connect(aWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
650 this, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
651 theModelWidgets.append(aWgt);
652 return aWgt->getControl();
654 } else if (theType == "sketch-2dpoint_selector") {
655 PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
656 aWgt->setWorkshop(aWorkshop);
657 aWgt->setSketch(myCurrentSketch);
659 connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
660 this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
662 theModelWidgets.append(aWgt);
663 return aWgt->getControl();
665 } if (theType == "point2ddistance") {
666 PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
667 aWgt->setWorkshop(aWorkshop);
668 aWgt->setSketch(myCurrentSketch);
670 theModelWidgets.append(aWgt);
671 return aWgt->getControl();
673 } if (theType == "sketch_shape_selector") {
674 PartSet_WidgetShapeSelector* aWgt =
675 new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
676 aWgt->setSketcher(myCurrentSketch);
678 theModelWidgets.append(aWgt);
679 return aWgt->getControl();
681 } if (theType == "sketch_constraint_shape_selector") {
682 PartSet_WidgetConstraintShapeSelector* aWgt =
683 new PartSet_WidgetConstraintShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
684 aWgt->setSketcher(myCurrentSketch);
686 theModelWidgets.append(aWgt);
687 return aWgt->getControl();