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_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetPoint2dAngle.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetEditor.h"
14 #include "PartSet_WidgetFileSelector.h"
15 #include "PartSet_WidgetSketchCreator.h"
16 #include "PartSet_SketcherMgr.h"
17 #include "PartSet_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
21 #include "PartSet_Filters.h"
22 #include "PartSet_FilterInfinite.h"
24 #include <PartSetPlugin_Remove.h>
25 #include <PartSetPlugin_Part.h>
26 #include <PartSetPlugin_Duplicate.h>
28 #include <ModuleBase_Operation.h>
29 #include <ModuleBase_OperationAction.h>
30 #include <ModuleBase_IViewer.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_IPropertyPanel.h>
33 #include <ModuleBase_WidgetEditor.h>
34 #include <ModuleBase_WidgetValidated.h>
35 #include <ModuleBase_FilterFactory.h>
36 #include <ModuleBase_Tools.h>
37 #include <ModuleBase_OperationFeature.h>
39 #include <GeomValidators_ShapeType.h>
40 #include <GeomValidators_Finite.h>
41 #include <GeomValidators_Face.h>
42 #include <GeomValidators_ConstructionComposite.h>
43 #include <GeomValidators_ZeroOffset.h>
44 #include <GeomValidators_BooleanArguments.h>
45 #include <GeomValidators_Different.h>
46 #include <GeomValidators_PartitionArguments.h>
49 #include <ModelAPI_Object.h>
50 #include <ModelAPI_Events.h>
51 #include <ModelAPI_Validator.h>
52 #include <ModelAPI_Data.h>
53 #include <ModelAPI_Session.h>
54 #include <GeomValidators_DifferentShapes.h>
55 #include <ModelAPI_ResultBody.h>
56 #include <ModelAPI_AttributeString.h>
58 #include <GeomDataAPI_Point2D.h>
59 #include <GeomDataAPI_Point.h>
60 #include <GeomDataAPI_Dir.h>
62 #include <XGUI_Displayer.h>
63 #include <XGUI_Workshop.h>
64 #include <XGUI_OperationMgr.h>
65 #include <XGUI_PropertyPanel.h>
66 #include <XGUI_ModuleConnector.h>
67 #include <XGUI_ContextMenuMgr.h>
68 #include <XGUI_Tools.h>
69 #include <XGUI_ObjectsBrowser.h>
70 #include <XGUI_SelectionMgr.h>
71 #include <XGUI_DataModel.h>
72 #include <XGUI_ErrorMgr.h>
74 #include <SketchPlugin_Feature.h>
75 #include <SketchPlugin_Sketch.h>
76 #include <SketchPlugin_Line.h>
77 #include <SketchPlugin_Arc.h>
78 #include <SketchPlugin_Circle.h>
79 #include <SketchPlugin_Point.h>
80 #include <SketchPlugin_ConstraintAngle.h>
81 #include <SketchPlugin_ConstraintLength.h>
82 #include <SketchPlugin_ConstraintDistance.h>
83 #include <SketchPlugin_ConstraintParallel.h>
84 #include <SketchPlugin_ConstraintPerpendicular.h>
85 #include <SketchPlugin_ConstraintRadius.h>
87 #include <SketcherPrs_SymbolPrs.h>
88 #include <SketcherPrs_Tools.h>
90 #include <Events_Loop.h>
91 #include <Config_PropManager.h>
92 #include <Config_Keywords.h>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <TopoDS_Vertex.hxx>
97 #include <TopoDS_Shape.hxx>
98 #include <BRep_Tool.hxx>
99 #include <AIS_Dimension.hxx>
102 #include <QMouseEvent>
105 #include <QApplication>
106 #include <QMessageBox>
107 #include <QMainWindow>
110 #include <GeomAlgoAPI_FaceBuilder.h>
111 #include <GeomDataAPI_Dir.h>
113 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
119 /*!Create and return new instance of XGUI_Module*/
120 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
122 return new PartSet_Module(theWshop);
125 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
126 : ModuleBase_IModule(theWshop),
127 myRestartingMode(RM_None), myVisualLayerId(0), myHasConstraintShown(true)
129 new PartSet_IconFactory();
131 mySketchMgr = new PartSet_SketcherMgr(this);
133 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
134 XGUI_Workshop* aWorkshop = aConnector->workshop();
136 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
137 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
138 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
139 this, SLOT(onOperationActivatedByPreselection()));
141 ModuleBase_IViewer* aViewer = theWshop->viewer();
142 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
143 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
144 connect(aViewer, SIGNAL(viewTransformed(int)),
145 SLOT(onViewTransformed(int)));
146 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
147 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
149 myMenuMgr = new PartSet_MenuMgr(this);
150 myCustomPrs = new PartSet_CustomPrs(theWshop);
152 Events_Loop* aLoop = Events_Loop::loop();
153 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
155 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
156 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
159 PartSet_Module::~PartSet_Module()
161 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
162 for (; aIt.More(); aIt.Next()) {
163 Handle(SelectMgr_Filter) aFilter = aIt.Value();
164 if (!aFilter.IsNull())
170 void PartSet_Module::activateSelectionFilters()
172 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
173 for (; aIt.More(); aIt.Next()) {
174 Handle(SelectMgr_Filter) aFilter = aIt.Value();
175 if (!aFilter.IsNull())
176 myWorkshop->viewer()->addSelectionFilter(aFilter);
180 void PartSet_Module::deactivateSelectionFilters()
182 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
183 for (; aIt.More(); aIt.Next()) {
184 Handle(SelectMgr_Filter) aFilter = aIt.Value();
185 if (!aFilter.IsNull())
186 myWorkshop->viewer()->removeSelectionFilter(aFilter);
190 void PartSet_Module::registerValidators()
192 //Registering of validators
193 SessionPtr aMgr = ModelAPI_Session::get();
194 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
195 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
196 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
197 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
198 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
199 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
200 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
201 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
202 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
203 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
204 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
205 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
206 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
207 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
208 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
210 aFactory->registerValidator("GeomValidators_DifferentShapes", new GeomValidators_DifferentShapes);
211 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
212 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
213 aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
215 aFactory->registerValidator("GeomValidators_ConstructionComposite",
216 new GeomValidators_ConstructionComposite);
218 aFactory->registerValidator("GeomValidators_ZeroOffset",
219 new GeomValidators_ZeroOffset);
221 aFactory->registerValidator("GeomValidators_BooleanArguments",
222 new GeomValidators_BooleanArguments);
224 aFactory->registerValidator("PartSet_SketchEntityValidator",
225 new PartSet_SketchEntityValidator);
227 aFactory->registerValidator("GeomValidators_Different",
228 new GeomValidators_Different);
230 aFactory->registerValidator("GeomValidators_PartitionArguments",
231 new GeomValidators_PartitionArguments);
234 void PartSet_Module::registerFilters()
236 //Registering of selection filters
237 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
238 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
241 void PartSet_Module::registerProperties()
243 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
245 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
246 Config_Prop::Integer, SKETCH_WIDTH);
249 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
251 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
252 mySketchMgr->commitNestedSketch(theOperation);
255 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
256 if (!aFOperation || aFOperation->isEditOperation())
258 // the selection is cleared after commit the create operation
259 // in order to do not use the same selected objects in the restarted operation
260 // for common behaviour, the selection is cleared even if the operation is not restarted
261 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
262 XGUI_Workshop* aWorkshop = aConnector->workshop();
263 aWorkshop->selector()->clearSelection();
265 /// Restart sketcher operations automatically
266 FeaturePtr aFeature = aFOperation->feature();
267 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
268 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
269 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
270 myRestartingMode == RM_EmptyFeatureUsed)) {
271 myLastOperationId = aFOperation->id();
272 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature() : FeaturePtr();
273 if (!sketchMgr()->sketchSolverError())
274 launchOperation(myLastOperationId);
276 breakOperationSequence();
279 void PartSet_Module::breakOperationSequence()
281 myLastOperationId = "";
282 myLastFeature = FeaturePtr();
283 myRestartingMode = RM_None;
286 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
288 breakOperationSequence();
291 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
293 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
294 mySketchMgr->startSketch(theOperation);
296 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
297 mySketchMgr->startNestedSketch(theOperation);
300 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
302 myCustomPrs->activate(aFOperation->feature(), true);
305 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
307 ModuleBase_IModule::operationResumed(theOperation);
309 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
311 myCustomPrs->activate(aFOperation->feature(), true);
314 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
316 bool isModified = myCustomPrs->deactivate(false);
318 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
319 mySketchMgr->stopSketch(theOperation);
321 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
322 mySketchMgr->stopNestedSketch(theOperation);
325 //VSV: Viewer is updated on feature update and redisplay
327 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
328 // XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
329 // aDisplayer->updateViewer();
331 mySketchMgr->onShowConstraintsToggle(myHasConstraintShown);
334 ModuleBase_Operation* PartSet_Module::currentOperation() const
336 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
337 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
338 return anOpMgr->currentOperation();
341 bool PartSet_Module::canUndo() const
343 bool aCanUndo = false;
344 SessionPtr aMgr = ModelAPI_Session::get();
345 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
346 aCanUndo = !aMgr->isOperation();
347 if (!aCanUndo) // check the enable state additionally by sketch manager
348 aCanUndo = aMgr->canUndo();
353 bool PartSet_Module::canRedo() const
355 bool aCanRedo = false;
356 SessionPtr aMgr = ModelAPI_Session::get();
357 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
358 aCanRedo = !aMgr->isOperation();
359 if (!aCanRedo) // check the enable state additionally by sketch manager
360 aCanRedo = aMgr->canRedo();
365 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
368 if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
369 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
371 // part features are removed in the PartSet module only.
372 if (aFeature->getKind() == PartSetPlugin_Part::ID())
379 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
381 // the sketch manager put the restriction to the objects erase
382 return mySketchMgr->canEraseObject(theObject);
385 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
387 // the sketch manager put the restriction to the objects display
388 return mySketchMgr->canDisplayObject(theObject);
391 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
393 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
395 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
396 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
397 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
398 if (isSketchOp || isNestedOp) {
399 // in active sketch operation it is possible to activate operation object in selection
400 // in the edit operation, e.g. points of the line can be moved when the line is edited
401 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
402 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
407 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
409 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
412 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
414 myMenuMgr->updateViewerMenu(theStdActions);
417 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
419 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
421 if (anError.isEmpty())
422 anError = sketchMgr()->getFeatureError(theFeature);
424 if (anError.isEmpty()) {
425 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
426 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
428 if (anOpMgr->isValidationLocked()) {
429 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
430 (anOpMgr->currentOperation());
431 if (!aFOperation || theFeature == aFOperation->feature())
432 anError = "Validation is locked by the current operation";
438 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
439 QStringList& theIds) const
441 myMenuMgr->grantedOperationIds(theOperation, theIds);
443 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
444 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
445 XGUI_Workshop* aWorkshop = aConnector->workshop();
447 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
451 void PartSet_Module::activeSelectionModes(QIntList& theModes)
454 if (mySketchMgr->activeSketch().get())
455 PartSet_SketcherMgr::sketchSelectionModes(theModes);
458 bool PartSet_Module::isMouseOverWindow()
460 return mySketchMgr->isMouseOverWindow();
463 void PartSet_Module::closeDocument()
468 void PartSet_Module::clearViewer()
470 myCustomPrs->clearPrs();
472 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
473 XGUI_Workshop* aWorkshop = aConnector->workshop();
474 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
475 aDisplayer->deactivateSelectionFilters();
478 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
480 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
484 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
485 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation())) {
486 // we have to manually activate the sketch label in edit mode
487 aPanel->activateWidget(aPanel->modelWidgets().first());
491 // Restart last operation type
492 if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
493 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
494 if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
495 // Initialise new line with first point equal to end of previous
496 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
498 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
499 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
500 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
502 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
503 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(),
504 aWgt->attributeID(), aPoint->x(), aPoint->y());
505 aPanel->activateNextWidget(aPnt2dWgt);
513 void PartSet_Module::onSelectionChanged()
515 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
519 bool isSketcherOp = false;
520 // An edit operation is enable only if the current opeation is the sketch operation
521 if (mySketchMgr->activeSketch()) {
522 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
523 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
526 // Editing of constraints can be done on selection
527 ModuleBase_ISelection* aSelect = myWorkshop->selection();
528 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
529 if (aSelected.size() == 1) {
530 ModuleBase_ViewerPrs aPrs = aSelected.first();
531 ObjectPtr aObject = aPrs.object();
532 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
534 std::string aId = aFeature->getKind();
535 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
536 (aId == SketchPlugin_ConstraintLength::ID()) ||
537 (aId == SketchPlugin_ConstraintDistance::ID()) ||
538 (aId == SketchPlugin_ConstraintAngle::ID())) {
539 editFeature(aFeature);
546 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
548 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
549 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
550 anOpMgr->onKeyReleased(theEvent);
553 void PartSet_Module::onEnterReleased()
555 myRestartingMode = RM_EmptyFeatureUsed;
558 void PartSet_Module::onOperationActivatedByPreselection()
560 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
561 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
562 // Set final definitions if they are necessary
563 //propertyPanelDefined(aOperation);
565 /// Commit sketcher operations automatically
566 anOperation->commit();
570 void PartSet_Module::onNoMoreWidgets()
572 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
574 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
575 if (myRestartingMode != RM_Forbided)
576 myRestartingMode = RM_LastFeatureUsed;
577 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
578 XGUI_Workshop* aWorkshop = aConnector->workshop();
579 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
580 // do nothing if the feature can not be applyed
581 if (anOpMgr->isApplyEnabled())
582 anOperation->commit();
587 void PartSet_Module::onVertexSelected()
589 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
590 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
591 /// If last line finished on vertex the lines creation sequence has to be break
592 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
593 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
594 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
595 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
596 bool aFoundWidget = false;
597 bool aFoundObligatory = false;
598 for (; anIt != aLast && !aFoundObligatory; anIt++) {
600 aFoundWidget = *anIt == anActiveWidget;
602 aFoundObligatory = (*anIt)->isObligatory();
604 if (!aFoundObligatory)
605 myRestartingMode = RM_Forbided;
609 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
610 Config_WidgetAPI* theWidgetApi, std::string theParentId)
612 ModuleBase_IWorkshop* aWorkshop = workshop();
613 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
614 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
615 ModuleBase_ModelWidget* aWgt = NULL;
616 if (theType == "sketch-start-label") {
617 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
618 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
619 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
620 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
621 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
622 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
624 } else if (theType == "sketch-2dpoint_selector") {
625 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
626 theWidgetApi, theParentId);
627 aPointWgt->setSketch(mySketchMgr->activeSketch());
628 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
630 } else if (theType == "sketch-2dpoint_flyout_selector") {
631 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
632 theWidgetApi, theParentId);
633 aPointWgt->setSketch(mySketchMgr->activeSketch());
634 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
636 } else if (theType == "point2ddistance") {
637 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
638 aWorkshop, theWidgetApi, theParentId);
639 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
641 } else if(theType == "point2dangle") {
642 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
643 aWorkshop, theWidgetApi, theParentId);
644 anAngleWgt->setSketch(mySketchMgr->activeSketch());
646 } else if (theType == "sketch_shape_selector") {
647 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
648 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
649 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
650 aWgt = aShapeSelectorWgt;
651 } else if (theType == "sketch_multi_selector") {
652 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
653 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
654 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
655 aWgt = aShapeSelectorWgt;
656 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
657 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
658 } else if (theType == "export_file_selector") {
659 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
660 } else if (theType == "sketch_launcher") {
661 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
667 bool PartSet_Module::deleteObjects()
669 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
670 XGUI_Workshop* aWorkshop = aConnector->workshop();
671 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
673 //SessionPtr aMgr = ModelAPI_Session::get();
674 // 1. check whether the delete should be processed in the module
675 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
676 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
677 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
678 if (isSketchOp || isNestedOp) {
679 // 2. find selected presentations
680 // selected objects should be collected before the current operation abort because
681 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
682 ModuleBase_ISelection* aSel = workshop()->selection();
683 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
684 // if there are no selected objects in the viewer, that means that the selection in another
685 // place cased this method. It is necessary to return the false value to understande in above
686 // method that delete is not processed
687 if (aSelectedObj.count() == 0)
690 // avoid delete of the objects, which are not belong to the current sketch
691 // in order to do not delete results of other sketches
692 QObjectPtrList aSketchObjects;
693 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
694 for ( ; anIt != aLast; anIt++) {
695 ObjectPtr anObject = *anIt;
696 if (mySketchMgr->isObjectOfSketch(anObject)) {
697 // sketch feature should be used in this list because workshop deletes features only
698 // results are skipped
699 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
700 aSketchObjects.append(aSketchFeature);
703 // if the selection contains only local selected presentations from other sketches,
704 // the Delete operation should not be done at all
705 if (aSketchObjects.size() == 0)
708 // 3. start operation
709 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
710 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
712 // the active nested sketch operation should be aborted unconditionally
713 // the Delete action should be additionally granted for the Sketch operation
714 // in order to do not abort/commit it
715 if (!anOpMgr->canStartOperation(anOpAction->id()))
716 return true; // the objects are processed but can not be deleted
718 anOpMgr->startOperation(anOpAction);
720 // 4. delete features
721 // sketch feature should be skipped, only sub-features can be removed
722 // when sketch operation is active
723 aWorkshop->deleteFeatures(aSketchObjects);
725 anOpMgr->commitOperation();
728 bool isPartRemoved = false;
729 // Delete part with help of PartSet plugin
730 // TODO: the deleted objects has to be processed by multiselection
731 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
732 if (aObjects.size() == 1) {
733 ObjectPtr aObj = aObjects.first();
734 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
735 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
736 // Remove feature should be created in the document of the part results
737 ResultPtr aPartResult = aFeature->firstResult();
738 if (aPartResult.get()) {
739 std::shared_ptr<ModelAPI_ResultPart> aPart =
740 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
741 DocumentPtr aPartDoc = aPart->partDoc();
742 if (aPartDoc.get()) {
743 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
744 (PartSetPlugin_Remove::ID().c_str(), this);
745 if (!anOpMgr->canStartOperation(anOpAction->id()))
746 return true; // the objects are processed but can not be deleted
748 anOpMgr->startOperation(anOpAction);
750 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
753 anOpMgr->commitOperation();
754 isPartRemoved = true;
759 return isPartRemoved;
764 void PartSet_Module::onFeatureTriggered()
766 QAction* aCmd = dynamic_cast<QAction*>(sender());
767 if (aCmd->isCheckable() && aCmd->isChecked()) {
768 // 1. check whether the delete should be processed in the module
769 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
770 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
772 // in case if in the viewer nothing is displayed, the create operation should not be
773 // comitted even if all values of the feature are initialized
774 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
775 // the action information should be saved before the operation is aborted
776 // because this abort leads to update command status, which unchecks this action
777 anOperation->abort();
778 launchOperation(aCmd->data().toString());
782 ModuleBase_IModule::onFeatureTriggered();
785 void PartSet_Module::launchOperation(const QString& theCmdId)
787 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
788 // Show constraints if a constraint was anOperation
789 myHasConstraintShown = mySketchMgr->isConstraintsShown();
790 mySketchMgr->onShowConstraintsToggle(true);
792 ModuleBase_IModule::launchOperation(theCmdId);
796 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
798 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
799 if (!anAIS.IsNull()) {
800 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
801 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
802 if (!aDim.IsNull()) {
803 aCtx->SetZLayer(aDim, myVisualLayerId);
805 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
807 aCtx->SetZLayer(aCons, myVisualLayerId);
812 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
815 // it should be recomputed in order to disappear in the viewer if the corresponded object
817 //if (myCustomPrs->isActive())
818 // myCustomPrs->redisplay(theObject, false);
821 void PartSet_Module::onViewTransformed(int theTrsfType)
823 // Set length of arrows constant in pixel size
824 // if the operation is panning or rotate or panglobal then do nothing
825 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
827 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
828 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
829 if (aContext.IsNull())
832 //Handle(V3d_View) aView = aViewer->activeView();
834 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
835 XGUI_Workshop* aWorkshop = aConnector->workshop();
836 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
837 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
838 Handle(V3d_View) aView;
840 for (aV3dViewer->InitDefinedViews();
841 aV3dViewer->MoreDefinedViews();
842 aV3dViewer->NextDefinedViews()) {
843 Handle(V3d_View) aV = aV3dViewer->DefinedView();
844 double aS = aV->Scale();
852 double aLen = aView->Convert(20);
854 double aPrevLen = SketcherPrs_Tools::getArrowSize();
855 SketcherPrs_Tools::setArrowSize(aLen);
856 const double aPrevScale = aViewer->Scale(aViewer->activeView());
857 const double aCurScale = aViewer->activeView()->Camera()->Scale();
858 aViewer->SetScale(aViewer->activeView(), aCurScale);
859 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
860 bool isModified = false;
861 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
862 foreach (AISObjectPtr aAIS, aPrsList) {
863 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
865 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
866 if (!aDim.IsNull()) {
867 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
868 aContext->Redisplay(aDim, false);
873 aDisplayer->updateViewer();
876 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
878 bool isRedisplayed = false;
879 if (myCustomPrs->isActive())
880 isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
882 return isRedisplayed;
885 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
887 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
889 QLineEdit* aLabel = aOB->activeDocLabel();
890 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
891 SLOT(onActiveDocPopup(const QPoint&)));
892 //QPalette aPalet = aLabel->palette();
893 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
894 //aLabel->setPalette(aPalet);
895 aOB->treeView()->setExpandsOnDoubleClick(false);
896 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
897 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
901 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
903 SessionPtr aMgr = ModelAPI_Session::get();
904 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
906 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
907 XGUI_Workshop* aWorkshop = aConnector->workshop();
908 QLineEdit* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
910 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
913 aMenu.addAction(aActivatePartAction);
914 aMenu.exec(aHeader->mapToGlobal(thePnt));
918 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
921 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
923 /// If last line finished on vertex the lines creation sequence has to be break
924 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
925 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
926 // if there is an active widget, find the presented object in it
928 anActiveWidget = aPanel->preselectionWidget();
930 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
932 if (aWidgetValidated)
933 anObject = aWidgetValidated->findPresentedObject(theAIS);
938 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
940 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
941 int aSelected = aObjects.size();
942 SessionPtr aMgr = ModelAPI_Session::get();
943 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
945 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
946 if (aSelected == 1) {
947 bool hasResult = false;
948 bool hasFeature = false;
949 bool hasParameter = false;
950 bool hasSubFeature = false;
951 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
953 ObjectPtr aObject = aObjects.first();
955 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
956 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
957 bool isPart = aPart.get() ||
958 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
960 DocumentPtr aPartDoc;
962 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
964 if (aPart.get()) // this may be null is Part feature is disabled
965 aPartDoc = aPart->partDoc();
967 theMenu->addAction(aActivatePartAction);
968 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
970 } else if (aObject->document() == aMgr->activeDocument()) {
971 if (hasParameter || hasFeature) {
972 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
973 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
974 if (aCurrentOp && aFeature.get()) {
975 if (aCurrentOp->id().toStdString() == aFeature->getKind())
976 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
981 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
983 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
986 bool aNotDeactivate = (aCurrentOp == 0);
987 if (!aNotDeactivate) {
988 aActivatePartAction->setEnabled(false);
992 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
994 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
995 // Do not change activation of parts if an operation active
996 static QStringList aAllowActivationList;
997 if (aAllowActivationList.isEmpty())
998 aAllowActivationList <<
999 QString(PartSetPlugin_Part::ID().c_str()) <<
1000 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1001 QString(PartSetPlugin_Remove::ID().c_str());
1002 if (myWorkshop->currentOperation() &&
1003 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1005 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1006 XGUI_Workshop* aWorkshop = aConnector->workshop();
1007 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1008 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1009 QPalette aPalet = aLabel->palette();
1011 SessionPtr aMgr = ModelAPI_Session::get();
1012 DocumentPtr aActiveDoc = aMgr->activeDocument();
1013 if (aActivePartIndex.isValid())
1014 aTreeView->setExpanded(aActivePartIndex, false);
1015 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1016 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1017 if (aActivePartIndex.isValid())
1018 aTreeView->setExpanded(aActivePartIndex, true);
1020 aLabel->setPalette(aPalet);
1021 aWorkshop->updateCommandStatus();
1023 // Update displayed objects in order to update active color
1024 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1025 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1027 foreach(ObjectPtr aObj, aObjects) {
1028 //TODO: replace by redisplay event.
1029 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1030 aObj->isDisabled() || (!aObj->isDisplayed());
1032 aDisplayer->redisplay(aObj, false);
1034 aDisplayer->updateViewer();
1038 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1040 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1042 SessionPtr aMgr = ModelAPI_Session::get();
1043 if (!theIndex.isValid()) {
1044 aMgr->setActiveDocument(aMgr->moduleDocument());
1047 if (theIndex.column() != 0) // Use only first column
1050 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1051 XGUI_Workshop* aWorkshop = aConnector->workshop();
1052 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1053 // De not use non editable Indexes
1054 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1056 ObjectPtr aObj = aDataModel->object(theIndex);
1058 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1059 if (!aPart.get()) { // Probably this is Feature
1060 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1061 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1062 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1065 if (aPart.get()) { // if this is a part
1066 if (aPart->partDoc() == aMgr->activeDocument()) {
1067 myMenuMgr->activatePartSet();
1075 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1077 // z layer is created for all started operations in order to visualize operation AIS presentation
1079 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1080 if (aContext.IsNull())
1083 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1084 if (myVisualLayerId == 0) {
1085 if (myVisualLayerId == 0)
1086 aViewer->AddZLayer(myVisualLayerId);
1088 TColStd_SequenceOfInteger aZList;
1089 aViewer->GetAllZLayers(aZList);
1090 bool aFound = false;
1091 for (int i = 1; i <= aZList.Length(); i++) {
1092 if (aZList(i) == myVisualLayerId) {
1098 aViewer->AddZLayer(myVisualLayerId);
1100 // if there is an active operation with validated widget,
1101 // the filters of this widget should be activated in the created view
1102 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1104 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1105 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1106 if (anActiveWidget) {
1107 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1109 if (aWidgetValidated)
1110 aWidgetValidated->activateFilters(true);