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::onOperationCommitted(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::onOperationAborted(ModuleBase_Operation* theOperation)
288 breakOperationSequence();
291 void PartSet_Module::onOperationStarted(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::onOperationResumed(ModuleBase_Operation* theOperation)
307 ModuleBase_IModule::onOperationResumed(theOperation);
309 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
311 myCustomPrs->activate(aFOperation->feature(), true);
314 void PartSet_Module::onOperationStopped(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::canCommitOperation() const
381 return mySketchMgr->canCommitOperation();
384 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
386 // the sketch manager put the restriction to the objects erase
387 return mySketchMgr->canEraseObject(theObject);
390 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
392 // the sketch manager put the restriction to the objects display
393 return mySketchMgr->canDisplayObject(theObject);
396 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
398 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
400 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
401 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
402 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
403 if (isSketchOp || isNestedOp) {
404 // in active sketch operation it is possible to activate operation object in selection
405 // in the edit operation, e.g. points of the line can be moved when the line is edited
406 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
407 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
412 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
414 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
417 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
419 myMenuMgr->updateViewerMenu(theStdActions);
422 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
424 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
426 if (anError.isEmpty())
427 anError = sketchMgr()->getFeatureError(theFeature);
429 if (anError.isEmpty()) {
430 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
431 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
433 if (anOpMgr->isValidationLocked()) {
434 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
435 (anOpMgr->currentOperation());
436 if (!aFOperation || theFeature == aFOperation->feature())
437 anError = "Validation is locked by the current operation";
443 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
444 QStringList& theIds) const
446 myMenuMgr->grantedOperationIds(theOperation, theIds);
448 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
449 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
450 XGUI_Workshop* aWorkshop = aConnector->workshop();
452 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
456 void PartSet_Module::activeSelectionModes(QIntList& theModes)
459 if (mySketchMgr->activeSketch().get())
460 PartSet_SketcherMgr::sketchSelectionModes(theModes);
463 bool PartSet_Module::isMouseOverWindow()
465 return mySketchMgr->isMouseOverWindow();
468 void PartSet_Module::closeDocument()
473 void PartSet_Module::clearViewer()
475 myCustomPrs->clearPrs();
477 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
478 XGUI_Workshop* aWorkshop = aConnector->workshop();
479 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
480 aDisplayer->deactivateSelectionFilters();
483 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
485 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
489 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
490 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation())) {
491 // we have to manually activate the sketch label in edit mode
492 aPanel->activateWidget(aPanel->modelWidgets().first());
496 // Restart last operation type
497 if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
498 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
499 if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
500 // Initialise new line with first point equal to end of previous
501 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
503 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
504 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
505 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
507 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
508 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(),
509 aWgt->attributeID(), aPoint->x(), aPoint->y());
510 aPanel->activateNextWidget(aPnt2dWgt);
518 void PartSet_Module::onSelectionChanged()
520 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
524 bool isSketcherOp = false;
525 // An edit operation is enable only if the current opeation is the sketch operation
526 if (mySketchMgr->activeSketch()) {
527 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
528 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
531 // Editing of constraints can be done on selection
532 ModuleBase_ISelection* aSelect = myWorkshop->selection();
533 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
534 if (aSelected.size() == 1) {
535 ModuleBase_ViewerPrs aPrs = aSelected.first();
536 ObjectPtr aObject = aPrs.object();
537 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
539 std::string aId = aFeature->getKind();
540 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
541 (aId == SketchPlugin_ConstraintLength::ID()) ||
542 (aId == SketchPlugin_ConstraintDistance::ID()) ||
543 (aId == SketchPlugin_ConstraintAngle::ID())) {
544 editFeature(aFeature);
551 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
553 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
554 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
555 anOpMgr->onKeyReleased(theEvent);
558 void PartSet_Module::onEnterReleased()
560 myRestartingMode = RM_EmptyFeatureUsed;
563 void PartSet_Module::onOperationActivatedByPreselection()
565 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
566 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
567 // Set final definitions if they are necessary
568 //propertyPanelDefined(aOperation);
570 /// Commit sketcher operations automatically
571 anOperation->commit();
575 void PartSet_Module::onNoMoreWidgets()
577 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
579 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
580 if (myRestartingMode != RM_Forbided)
581 myRestartingMode = RM_LastFeatureUsed;
582 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
583 XGUI_Workshop* aWorkshop = aConnector->workshop();
584 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
585 // do nothing if the feature can not be applyed
586 if (anOpMgr->isApplyEnabled())
587 anOperation->commit();
592 void PartSet_Module::onVertexSelected()
594 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
595 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
596 /// If last line finished on vertex the lines creation sequence has to be break
597 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
598 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
599 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
600 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
601 bool aFoundWidget = false;
602 bool aFoundObligatory = false;
603 for (; anIt != aLast && !aFoundObligatory; anIt++) {
605 aFoundWidget = *anIt == anActiveWidget;
607 aFoundObligatory = (*anIt)->isObligatory();
609 if (!aFoundObligatory)
610 myRestartingMode = RM_Forbided;
614 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
615 Config_WidgetAPI* theWidgetApi, std::string theParentId)
617 ModuleBase_IWorkshop* aWorkshop = workshop();
618 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
619 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
620 ModuleBase_ModelWidget* aWgt = NULL;
621 if (theType == "sketch-start-label") {
622 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
623 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
624 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
625 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
626 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
627 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
629 } else if (theType == "sketch-2dpoint_selector") {
630 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
631 theWidgetApi, theParentId);
632 aPointWgt->setSketch(mySketchMgr->activeSketch());
633 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
635 } else if (theType == "sketch-2dpoint_flyout_selector") {
636 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
637 theWidgetApi, theParentId);
638 aPointWgt->setSketch(mySketchMgr->activeSketch());
639 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
641 } else if (theType == "point2ddistance") {
642 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
643 aWorkshop, theWidgetApi, theParentId);
644 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
646 } else if(theType == "point2dangle") {
647 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
648 aWorkshop, theWidgetApi, theParentId);
649 anAngleWgt->setSketch(mySketchMgr->activeSketch());
651 } else if (theType == "sketch_shape_selector") {
652 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
653 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
654 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
655 aWgt = aShapeSelectorWgt;
656 } else if (theType == "sketch_multi_selector") {
657 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
658 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
659 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
660 aWgt = aShapeSelectorWgt;
661 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
662 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
663 } else if (theType == "export_file_selector") {
664 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
665 } else if (theType == "sketch_launcher") {
666 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
672 bool PartSet_Module::deleteObjects()
674 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
675 XGUI_Workshop* aWorkshop = aConnector->workshop();
676 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
678 //SessionPtr aMgr = ModelAPI_Session::get();
679 // 1. check whether the delete should be processed in the module
680 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
681 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
682 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
683 if (isSketchOp || isNestedOp) {
684 // 2. find selected presentations
685 // selected objects should be collected before the current operation abort because
686 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
687 ModuleBase_ISelection* aSel = workshop()->selection();
688 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
689 // if there are no selected objects in the viewer, that means that the selection in another
690 // place cased this method. It is necessary to return the false value to understande in above
691 // method that delete is not processed
692 if (aSelectedObj.count() == 0)
695 // avoid delete of the objects, which are not belong to the current sketch
696 // in order to do not delete results of other sketches
697 QObjectPtrList aSketchObjects;
698 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
699 for ( ; anIt != aLast; anIt++) {
700 ObjectPtr anObject = *anIt;
701 if (mySketchMgr->isObjectOfSketch(anObject)) {
702 // sketch feature should be used in this list because workshop deletes features only
703 // results are skipped
704 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
705 aSketchObjects.append(aSketchFeature);
708 // if the selection contains only local selected presentations from other sketches,
709 // the Delete operation should not be done at all
710 if (aSketchObjects.size() == 0)
713 // 3. start operation
714 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
715 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
717 // the active nested sketch operation should be aborted unconditionally
718 // the Delete action should be additionally granted for the Sketch operation
719 // in order to do not abort/commit it
720 if (!anOpMgr->canStartOperation(anOpAction->id()))
721 return true; // the objects are processed but can not be deleted
723 anOpMgr->startOperation(anOpAction);
725 // 4. delete features
726 // sketch feature should be skipped, only sub-features can be removed
727 // when sketch operation is active
728 aWorkshop->deleteFeatures(aSketchObjects);
730 anOpMgr->commitOperation();
733 bool isPartRemoved = false;
734 // Delete part with help of PartSet plugin
735 // TODO: the deleted objects has to be processed by multiselection
736 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
737 if (aObjects.size() == 1) {
738 ObjectPtr aObj = aObjects.first();
739 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
740 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
741 // Remove feature should be created in the document of the part results
742 ResultPtr aPartResult = aFeature->firstResult();
743 if (aPartResult.get()) {
744 std::shared_ptr<ModelAPI_ResultPart> aPart =
745 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
746 DocumentPtr aPartDoc = aPart->partDoc();
747 if (aPartDoc.get()) {
748 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
749 (PartSetPlugin_Remove::ID().c_str(), this);
750 if (!anOpMgr->canStartOperation(anOpAction->id()))
751 return true; // the objects are processed but can not be deleted
753 anOpMgr->startOperation(anOpAction);
755 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
758 anOpMgr->commitOperation();
759 isPartRemoved = true;
764 return isPartRemoved;
769 void PartSet_Module::onFeatureTriggered()
771 QAction* aCmd = dynamic_cast<QAction*>(sender());
772 if (aCmd->isCheckable() && aCmd->isChecked()) {
773 // 1. check whether the delete should be processed in the module
774 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
775 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
777 // in case if in the viewer nothing is displayed, the create operation should not be
778 // comitted even if all values of the feature are initialized
779 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
780 // the action information should be saved before the operation is aborted
781 // because this abort leads to update command status, which unchecks this action
782 anOperation->abort();
783 launchOperation(aCmd->data().toString());
787 ModuleBase_IModule::onFeatureTriggered();
790 void PartSet_Module::launchOperation(const QString& theCmdId)
792 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
793 // Show constraints if a constraint was anOperation
794 myHasConstraintShown = mySketchMgr->isConstraintsShown();
795 mySketchMgr->onShowConstraintsToggle(true);
797 ModuleBase_IModule::launchOperation(theCmdId);
801 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
803 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
804 if (!anAIS.IsNull()) {
805 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
806 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
807 if (!aDim.IsNull()) {
808 aCtx->SetZLayer(aDim, myVisualLayerId);
810 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
812 aCtx->SetZLayer(aCons, myVisualLayerId);
817 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
820 // it should be recomputed in order to disappear in the viewer if the corresponded object
822 //if (myCustomPrs->isActive())
823 // myCustomPrs->redisplay(theObject, false);
826 void PartSet_Module::onViewTransformed(int theTrsfType)
828 // Set length of arrows constant in pixel size
829 // if the operation is panning or rotate or panglobal then do nothing
830 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
832 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
833 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
834 if (aContext.IsNull())
837 //Handle(V3d_View) aView = aViewer->activeView();
839 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
840 XGUI_Workshop* aWorkshop = aConnector->workshop();
841 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
842 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
843 Handle(V3d_View) aView;
845 for (aV3dViewer->InitDefinedViews();
846 aV3dViewer->MoreDefinedViews();
847 aV3dViewer->NextDefinedViews()) {
848 Handle(V3d_View) aV = aV3dViewer->DefinedView();
849 double aS = aV->Scale();
857 double aLen = aView->Convert(20);
859 double aPrevLen = SketcherPrs_Tools::getArrowSize();
860 SketcherPrs_Tools::setArrowSize(aLen);
861 const double aPrevScale = aViewer->Scale(aViewer->activeView());
862 const double aCurScale = aViewer->activeView()->Camera()->Scale();
863 aViewer->SetScale(aViewer->activeView(), aCurScale);
864 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
865 bool isModified = false;
866 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
867 foreach (AISObjectPtr aAIS, aPrsList) {
868 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
870 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
871 if (!aDim.IsNull()) {
872 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
873 aContext->Redisplay(aDim, false);
878 aDisplayer->updateViewer();
881 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
883 bool isRedisplayed = false;
884 if (myCustomPrs->isActive())
885 isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
887 return isRedisplayed;
890 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
892 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
894 //QLineEdit* aLabel = aOB->activeDocLabel();
895 //QPalette aPalet = aLabel->palette();
896 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
897 //aLabel->setPalette(aPalet);
898 aOB->treeView()->setExpandsOnDoubleClick(false);
899 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
900 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
904 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
907 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
909 /// If last line finished on vertex the lines creation sequence has to be break
910 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
911 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
912 // if there is an active widget, find the presented object in it
914 anActiveWidget = aPanel->preselectionWidget();
916 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
918 if (aWidgetValidated)
919 anObject = aWidgetValidated->findPresentedObject(theAIS);
924 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
926 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
927 int aSelected = aObjects.size();
928 SessionPtr aMgr = ModelAPI_Session::get();
929 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
930 QAction* aActivatePartSetAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
932 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
933 if (aSelected == 1) {
934 bool hasResult = false;
935 bool hasFeature = false;
936 bool hasParameter = false;
937 bool hasSubFeature = false;
938 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
940 ObjectPtr aObject = aObjects.first();
942 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
943 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
944 bool isPart = aPart.get() ||
945 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
947 DocumentPtr aPartDoc;
949 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
951 if (aPart.get()) // this may be null is Part feature is disabled
952 aPartDoc = aPart->partDoc();
954 theMenu->addAction(aActivatePartAction);
955 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
957 } else if (aObject->document() == aMgr->activeDocument()) {
958 if (hasParameter || hasFeature) {
959 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
960 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
961 if (aCurrentOp && aFeature.get()) {
962 if (aCurrentOp->id().toStdString() == aFeature->getKind())
963 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
968 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
970 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
971 } else { // If feature is 0 the it means that selected root object (document)
972 theMenu->addAction(aActivatePartSetAction);
973 aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
975 } else if (aSelected == 0) {
976 // if there is no selection then it means that upper label is selected
977 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
978 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
979 theMenu->addAction(aActivatePartSetAction);
980 aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
982 bool aNotDeactivate = (aCurrentOp == 0);
983 if (!aNotDeactivate) {
984 aActivatePartAction->setEnabled(false);
985 aActivatePartSetAction->setEnabled(false);
989 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
991 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
992 // Do not change activation of parts if an operation active
993 static QStringList aAllowActivationList;
994 if (aAllowActivationList.isEmpty())
995 aAllowActivationList <<
996 QString(PartSetPlugin_Part::ID().c_str()) <<
997 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
998 QString(PartSetPlugin_Remove::ID().c_str());
999 if (myWorkshop->currentOperation() &&
1000 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1002 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1003 XGUI_Workshop* aWorkshop = aConnector->workshop();
1004 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1005 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1006 QPalette aPalet = aLabel->palette();
1008 SessionPtr aMgr = ModelAPI_Session::get();
1009 DocumentPtr aActiveDoc = aMgr->activeDocument();
1010 if (aActivePartIndex.isValid())
1011 aTreeView->setExpanded(aActivePartIndex, false);
1012 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1013 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1014 if (aActivePartIndex.isValid())
1015 aTreeView->setExpanded(aActivePartIndex, true);
1017 aLabel->setPalette(aPalet);
1018 aWorkshop->updateCommandStatus();
1020 // Update displayed objects in order to update active color
1021 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1022 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1024 foreach(ObjectPtr aObj, aObjects) {
1025 //TODO: replace by redisplay event.
1026 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1027 aObj->isDisabled() || (!aObj->isDisplayed());
1029 aDisplayer->redisplay(aObj, false);
1031 aDisplayer->updateViewer();
1035 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1037 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1039 SessionPtr aMgr = ModelAPI_Session::get();
1040 if (!theIndex.isValid()) {
1041 aMgr->setActiveDocument(aMgr->moduleDocument());
1044 if (theIndex.column() != 0) // Use only first column
1047 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1048 XGUI_Workshop* aWorkshop = aConnector->workshop();
1049 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1050 // De not use non editable Indexes
1051 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1053 ObjectPtr aObj = aDataModel->object(theIndex);
1055 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1056 if (!aPart.get()) { // Probably this is Feature
1057 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1058 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1059 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1062 if (aPart.get()) { // if this is a part
1063 if (aPart->partDoc() == aMgr->activeDocument()) {
1064 myMenuMgr->activatePartSet();
1072 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1074 // z layer is created for all started operations in order to visualize operation AIS presentation
1076 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1077 if (aContext.IsNull())
1080 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1081 if (myVisualLayerId == 0) {
1082 if (myVisualLayerId == 0)
1083 aViewer->AddZLayer(myVisualLayerId);
1085 TColStd_SequenceOfInteger aZList;
1086 aViewer->GetAllZLayers(aZList);
1087 bool aFound = false;
1088 for (int i = 1; i <= aZList.Length(); i++) {
1089 if (aZList(i) == myVisualLayerId) {
1095 aViewer->AddZLayer(myVisualLayerId);
1097 // if there is an active operation with validated widget,
1098 // the filters of this widget should be activated in the created view
1099 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1101 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1102 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1103 if (anActiveWidget) {
1104 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1106 if (aWidgetValidated)
1107 aWidgetValidated->activateFilters(true);