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_SketcherReetntrantMgr.h"
18 #include "PartSet_MenuMgr.h"
19 #include "PartSet_CustomPrs.h"
20 #include "PartSet_IconFactory.h"
22 #include "PartSet_Filters.h"
23 #include "PartSet_FilterInfinite.h"
25 #include <PartSetPlugin_Remove.h>
26 #include <PartSetPlugin_Part.h>
27 #include <PartSetPlugin_Duplicate.h>
29 #include <ModuleBase_Operation.h>
30 #include <ModuleBase_OperationAction.h>
31 #include <ModuleBase_IViewer.h>
32 #include <ModuleBase_IViewWindow.h>
33 #include <ModuleBase_IPropertyPanel.h>
34 #include <ModuleBase_WidgetEditor.h>
35 #include <ModuleBase_WidgetValidated.h>
36 #include <ModuleBase_FilterFactory.h>
37 #include <ModuleBase_Tools.h>
38 #include <ModuleBase_OperationFeature.h>
40 #include <GeomValidators_ShapeType.h>
41 #include <GeomValidators_Finite.h>
42 #include <GeomValidators_Face.h>
43 #include <GeomValidators_ConstructionComposite.h>
44 #include <GeomValidators_ZeroOffset.h>
45 #include <GeomValidators_BooleanArguments.h>
46 #include <GeomValidators_Different.h>
47 #include <GeomValidators_PartitionArguments.h>
50 #include <ModelAPI_Object.h>
51 #include <ModelAPI_Events.h>
52 #include <ModelAPI_Validator.h>
53 #include <ModelAPI_Data.h>
54 #include <ModelAPI_Session.h>
55 #include <GeomValidators_DifferentShapes.h>
56 #include <ModelAPI_ResultBody.h>
57 #include <ModelAPI_AttributeString.h>
59 #include <GeomDataAPI_Point2D.h>
60 #include <GeomDataAPI_Point.h>
61 #include <GeomDataAPI_Dir.h>
63 #include <XGUI_Displayer.h>
64 #include <XGUI_Workshop.h>
65 #include <XGUI_OperationMgr.h>
66 #include <XGUI_PropertyPanel.h>
67 #include <XGUI_ModuleConnector.h>
68 #include <XGUI_ContextMenuMgr.h>
69 #include <XGUI_Tools.h>
70 #include <XGUI_ObjectsBrowser.h>
71 #include <XGUI_SelectionMgr.h>
72 #include <XGUI_DataModel.h>
73 #include <XGUI_ErrorMgr.h>
75 #include <SketchPlugin_Feature.h>
76 #include <SketchPlugin_Sketch.h>
77 #include <SketchPlugin_ConstraintAngle.h>
78 #include <SketchPlugin_ConstraintLength.h>
79 #include <SketchPlugin_ConstraintDistance.h>
80 #include <SketchPlugin_ConstraintParallel.h>
81 #include <SketchPlugin_ConstraintPerpendicular.h>
82 #include <SketchPlugin_ConstraintRadius.h>
84 #include <SketcherPrs_SymbolPrs.h>
85 #include <SketcherPrs_Tools.h>
87 #include <Events_Loop.h>
88 #include <Config_PropManager.h>
89 #include <Config_Keywords.h>
91 #include <StdSelect_TypeOfFace.hxx>
92 #include <TopoDS_Vertex.hxx>
94 #include <TopoDS_Shape.hxx>
95 #include <BRep_Tool.hxx>
96 #include <AIS_Dimension.hxx>
99 #include <QMouseEvent>
102 #include <QApplication>
103 #include <QMessageBox>
104 #include <QMainWindow>
107 #include <GeomAlgoAPI_FaceBuilder.h>
108 #include <GeomDataAPI_Dir.h>
110 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
116 /*!Create and return new instance of XGUI_Module*/
117 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
119 return new PartSet_Module(theWshop);
122 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
123 : ModuleBase_IModule(theWshop),
124 myVisualLayerId(0), myHasConstraintShown(true)
126 new PartSet_IconFactory();
128 mySketchMgr = new PartSet_SketcherMgr(this);
129 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
131 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
132 XGUI_Workshop* aWorkshop = aConnector->workshop();
134 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
135 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
136 this, SLOT(onOperationActivatedByPreselection()));
138 ModuleBase_IViewer* aViewer = theWshop->viewer();
139 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
140 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
141 connect(aViewer, SIGNAL(viewTransformed(int)),
142 SLOT(onViewTransformed(int)));
143 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
144 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
146 myMenuMgr = new PartSet_MenuMgr(this);
147 myCustomPrs = new PartSet_CustomPrs(theWshop);
149 Events_Loop* aLoop = Events_Loop::loop();
150 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
152 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
153 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
156 PartSet_Module::~PartSet_Module()
158 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
159 for (; aIt.More(); aIt.Next()) {
160 Handle(SelectMgr_Filter) aFilter = aIt.Value();
161 if (!aFilter.IsNull())
167 void PartSet_Module::activateSelectionFilters()
169 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
170 for (; aIt.More(); aIt.Next()) {
171 Handle(SelectMgr_Filter) aFilter = aIt.Value();
172 if (!aFilter.IsNull())
173 myWorkshop->viewer()->addSelectionFilter(aFilter);
177 void PartSet_Module::deactivateSelectionFilters()
179 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
180 for (; aIt.More(); aIt.Next()) {
181 Handle(SelectMgr_Filter) aFilter = aIt.Value();
182 if (!aFilter.IsNull())
183 myWorkshop->viewer()->removeSelectionFilter(aFilter);
187 void PartSet_Module::registerValidators()
189 //Registering of validators
190 SessionPtr aMgr = ModelAPI_Session::get();
191 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
192 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
193 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
194 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
195 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
196 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
197 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
198 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
199 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
200 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
201 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
202 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
203 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
204 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
205 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
207 aFactory->registerValidator("GeomValidators_DifferentShapes", new GeomValidators_DifferentShapes);
208 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
209 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
210 aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
212 aFactory->registerValidator("GeomValidators_ConstructionComposite",
213 new GeomValidators_ConstructionComposite);
215 aFactory->registerValidator("GeomValidators_ZeroOffset",
216 new GeomValidators_ZeroOffset);
218 aFactory->registerValidator("GeomValidators_BooleanArguments",
219 new GeomValidators_BooleanArguments);
221 aFactory->registerValidator("PartSet_SketchEntityValidator",
222 new PartSet_SketchEntityValidator);
224 aFactory->registerValidator("GeomValidators_Different",
225 new GeomValidators_Different);
227 aFactory->registerValidator("GeomValidators_PartitionArguments",
228 new GeomValidators_PartitionArguments);
231 void PartSet_Module::registerFilters()
233 //Registering of selection filters
234 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
235 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
238 void PartSet_Module::registerProperties()
240 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
242 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
243 Config_Prop::Integer, SKETCH_WIDTH);
246 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
248 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
251 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
253 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
254 mySketchMgr->commitNestedSketch(theOperation);
257 /// Restart sketcher operations automatically
258 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
259 // the selection is cleared after commit the create operation
260 // in order to do not use the same selected objects in the restarted operation
261 // for common behaviour, the selection is cleared even if the operation is not restarted
262 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
263 XGUI_Workshop* aWorkshop = aConnector->workshop();
264 aWorkshop->selector()->clearSelection();
268 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
270 /// Restart sketcher operations automatically
271 mySketchReentrantMgr->operationAborted(theOperation);
274 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
276 /// Restart sketcher operations automatically
277 mySketchReentrantMgr->operationStarted(theOperation);
279 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
280 mySketchMgr->startSketch(theOperation);
282 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
283 mySketchMgr->startNestedSketch(theOperation);
286 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
288 myCustomPrs->activate(aFOperation->feature(), true);
291 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
293 ModuleBase_IModule::operationResumed(theOperation);
295 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
297 myCustomPrs->activate(aFOperation->feature(), true);
300 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
302 bool isModified = myCustomPrs->deactivate(false);
304 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
305 mySketchMgr->stopSketch(theOperation);
307 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
308 mySketchMgr->stopNestedSketch(theOperation);
311 //VSV: Viewer is updated on feature update and redisplay
313 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
314 // XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
315 // aDisplayer->updateViewer();
317 mySketchMgr->onShowConstraintsToggle(myHasConstraintShown);
320 ModuleBase_Operation* PartSet_Module::currentOperation() const
322 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
323 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
324 return anOpMgr->currentOperation();
327 bool PartSet_Module::canUndo() const
329 bool aCanUndo = false;
330 SessionPtr aMgr = ModelAPI_Session::get();
331 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
332 aCanUndo = !aMgr->isOperation();
333 if (!aCanUndo) // check the enable state additionally by sketch manager
334 aCanUndo = aMgr->canUndo();
339 bool PartSet_Module::canRedo() const
341 bool aCanRedo = false;
342 SessionPtr aMgr = ModelAPI_Session::get();
343 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
344 aCanRedo = !aMgr->isOperation();
345 if (!aCanRedo) // check the enable state additionally by sketch manager
346 aCanRedo = aMgr->canRedo();
351 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
354 if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
355 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
357 // part features are removed in the PartSet module only.
358 if (aFeature->getKind() == PartSetPlugin_Part::ID())
365 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
367 // the sketch manager put the restriction to the objects erase
368 return mySketchMgr->canEraseObject(theObject);
371 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
373 // the sketch manager put the restriction to the objects display
374 return mySketchMgr->canDisplayObject(theObject);
377 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
379 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
381 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
382 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
383 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
384 if (isSketchOp || isNestedOp) {
385 // in active sketch operation it is possible to activate operation object in selection
386 // in the edit operation, e.g. points of the line can be moved when the line is edited
387 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
388 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
393 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
395 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
398 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
400 myMenuMgr->updateViewerMenu(theStdActions);
403 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
405 QString anError = ModuleBase_IModule::getFeatureError(theFeature, isCheckGUI);
406 if (anError.isEmpty())
407 anError = sketchMgr()->getFeatureError(theFeature, isCheckGUI);
412 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
413 QStringList& theIds) const
415 myMenuMgr->grantedOperationIds(theOperation, theIds);
417 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
418 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
419 XGUI_Workshop* aWorkshop = aConnector->workshop();
421 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
425 void PartSet_Module::activeSelectionModes(QIntList& theModes)
428 if (mySketchMgr->activeSketch().get())
429 PartSet_SketcherMgr::sketchSelectionModes(theModes);
432 bool PartSet_Module::isMouseOverWindow()
434 return mySketchMgr->isMouseOverWindow();
437 void PartSet_Module::closeDocument()
442 void PartSet_Module::clearViewer()
444 myCustomPrs->clearPrs();
446 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
447 XGUI_Workshop* aWorkshop = aConnector->workshop();
448 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
449 aDisplayer->deactivateSelectionFilters();
452 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
454 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
458 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
459 // we have to manually activate the sketch label in edit mode
460 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
461 aPanel->activateWidget(aPanel->modelWidgets().first());
465 void PartSet_Module::onSelectionChanged()
467 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
471 bool isSketcherOp = false;
472 // An edit operation is enable only if the current opeation is the sketch operation
473 if (mySketchMgr->activeSketch()) {
474 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
475 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
478 // Editing of constraints can be done on selection
479 ModuleBase_ISelection* aSelect = myWorkshop->selection();
480 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
481 if (aSelected.size() == 1) {
482 ModuleBase_ViewerPrs aPrs = aSelected.first();
483 ObjectPtr aObject = aPrs.object();
484 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
486 std::string aId = aFeature->getKind();
487 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
488 (aId == SketchPlugin_ConstraintLength::ID()) ||
489 (aId == SketchPlugin_ConstraintDistance::ID()) ||
490 (aId == SketchPlugin_ConstraintAngle::ID())) {
491 editFeature(aFeature);
498 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
500 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
501 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
502 anOpMgr->onKeyReleased(theEvent);
505 void PartSet_Module::onOperationActivatedByPreselection()
507 if (!mySketchReentrantMgr->canBeCommittedByPreselection())
510 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
511 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
512 // Set final definitions if they are necessary
513 //propertyPanelDefined(aOperation);
515 /// Commit sketcher operations automatically
516 anOperation->commit();
520 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
521 Config_WidgetAPI* theWidgetApi, std::string theParentId)
523 ModuleBase_IWorkshop* aWorkshop = workshop();
524 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
525 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
526 ModuleBase_ModelWidget* aWgt = NULL;
527 if (theType == "sketch-start-label") {
528 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
529 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
530 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
531 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
532 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
533 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
535 } else if (theType == "sketch-2dpoint_selector") {
536 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
537 theWidgetApi, theParentId);
538 aPointWgt->setSketch(mySketchMgr->activeSketch());
539 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
541 } else if (theType == "sketch-2dpoint_flyout_selector") {
542 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
543 theWidgetApi, theParentId);
544 aPointWgt->setSketch(mySketchMgr->activeSketch());
545 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
547 } else if (theType == "point2ddistance") {
548 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
549 aWorkshop, theWidgetApi, theParentId);
550 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
552 } else if(theType == "point2dangle") {
553 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
554 aWorkshop, theWidgetApi, theParentId);
555 anAngleWgt->setSketch(mySketchMgr->activeSketch());
557 } else if (theType == "sketch_shape_selector") {
558 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
559 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
560 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
561 aWgt = aShapeSelectorWgt;
562 } else if (theType == "sketch_multi_selector") {
563 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
564 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
565 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
566 aWgt = aShapeSelectorWgt;
567 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
568 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
569 } else if (theType == "export_file_selector") {
570 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
571 } else if (theType == "sketch_launcher") {
572 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
577 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
579 ModuleBase_ModelWidget* anActiveWidget = 0;
581 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
582 if (!anActiveWidget) {
583 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
585 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
586 anActiveWidget = aPanel->activeWidget();
589 return anActiveWidget;
592 bool PartSet_Module::deleteObjects()
594 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
595 XGUI_Workshop* aWorkshop = aConnector->workshop();
596 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
598 //SessionPtr aMgr = ModelAPI_Session::get();
599 // 1. check whether the delete should be processed in the module
600 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
601 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
602 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
603 if (isSketchOp || isNestedOp) {
604 // 2. find selected presentations
605 // selected objects should be collected before the current operation abort because
606 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
607 ModuleBase_ISelection* aSel = workshop()->selection();
608 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
609 // if there are no selected objects in the viewer, that means that the selection in another
610 // place cased this method. It is necessary to return the false value to understande in above
611 // method that delete is not processed
612 if (aSelectedObj.count() == 0)
615 // avoid delete of the objects, which are not belong to the current sketch
616 // in order to do not delete results of other sketches
617 QObjectPtrList aSketchObjects;
618 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
619 for ( ; anIt != aLast; anIt++) {
620 ObjectPtr anObject = *anIt;
621 if (mySketchMgr->isObjectOfSketch(anObject)) {
622 // sketch feature should be used in this list because workshop deletes features only
623 // results are skipped
624 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
625 aSketchObjects.append(aSketchFeature);
628 // if the selection contains only local selected presentations from other sketches,
629 // the Delete operation should not be done at all
630 if (aSketchObjects.size() == 0)
633 // 3. start operation
634 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
635 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
637 // the active nested sketch operation should be aborted unconditionally
638 // the Delete action should be additionally granted for the Sketch operation
639 // in order to do not abort/commit it
640 if (!anOpMgr->canStartOperation(anOpAction->id()))
641 return true; // the objects are processed but can not be deleted
643 anOpMgr->startOperation(anOpAction);
645 // 4. delete features
646 // sketch feature should be skipped, only sub-features can be removed
647 // when sketch operation is active
648 aWorkshop->deleteFeatures(aSketchObjects);
650 anOpMgr->commitOperation();
653 bool isPartRemoved = false;
654 // Delete part with help of PartSet plugin
655 // TODO: the deleted objects has to be processed by multiselection
656 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
657 if (aObjects.size() == 1) {
658 ObjectPtr aObj = aObjects.first();
659 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
660 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
661 // Remove feature should be created in the document of the part results
662 ResultPtr aPartResult = aFeature->firstResult();
663 if (aPartResult.get()) {
664 std::shared_ptr<ModelAPI_ResultPart> aPart =
665 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
666 DocumentPtr aPartDoc = aPart->partDoc();
667 if (aPartDoc.get()) {
668 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
669 (PartSetPlugin_Remove::ID().c_str(), this);
670 if (!anOpMgr->canStartOperation(anOpAction->id()))
671 return true; // the objects are processed but can not be deleted
673 anOpMgr->startOperation(anOpAction);
675 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
678 anOpMgr->commitOperation();
679 isPartRemoved = true;
684 return isPartRemoved;
689 void PartSet_Module::onFeatureTriggered()
691 QAction* aCmd = dynamic_cast<QAction*>(sender());
692 if (aCmd->isCheckable() && aCmd->isChecked()) {
693 // 1. check whether the delete should be processed in the module
694 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
695 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
697 // in case if in the viewer nothing is displayed, the create operation should not be
698 // comitted even if all values of the feature are initialized
699 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
700 // the action information should be saved before the operation is aborted
701 // because this abort leads to update command status, which unchecks this action
702 anOperation->abort();
703 launchOperation(aCmd->data().toString());
707 ModuleBase_IModule::onFeatureTriggered();
710 void PartSet_Module::launchOperation(const QString& theCmdId)
712 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
713 // Show constraints if a constraint was anOperation
714 myHasConstraintShown = mySketchMgr->isConstraintsShown();
715 mySketchMgr->onShowConstraintsToggle(true);
717 ModuleBase_IModule::launchOperation(theCmdId);
721 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
723 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
724 if (!anAIS.IsNull()) {
725 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
726 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
727 if (!aDim.IsNull()) {
728 aCtx->SetZLayer(aDim, myVisualLayerId);
730 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
732 aCtx->SetZLayer(aCons, myVisualLayerId);
737 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
740 // it should be recomputed in order to disappear in the viewer if the corresponded object
742 //if (myCustomPrs->isActive())
743 // myCustomPrs->redisplay(theObject, false);
746 void PartSet_Module::onViewTransformed(int theTrsfType)
748 // Set length of arrows constant in pixel size
749 // if the operation is panning or rotate or panglobal then do nothing
750 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
752 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
753 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
754 if (aContext.IsNull())
757 //Handle(V3d_View) aView = aViewer->activeView();
759 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
760 XGUI_Workshop* aWorkshop = aConnector->workshop();
761 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
762 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
763 Handle(V3d_View) aView;
765 for (aV3dViewer->InitDefinedViews();
766 aV3dViewer->MoreDefinedViews();
767 aV3dViewer->NextDefinedViews()) {
768 Handle(V3d_View) aV = aV3dViewer->DefinedView();
769 double aS = aV->Scale();
777 double aLen = aView->Convert(20);
779 double aPrevLen = SketcherPrs_Tools::getArrowSize();
780 SketcherPrs_Tools::setArrowSize(aLen);
781 const double aPrevScale = aViewer->Scale(aViewer->activeView());
782 const double aCurScale = aViewer->activeView()->Camera()->Scale();
783 aViewer->SetScale(aViewer->activeView(), aCurScale);
784 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
785 bool isModified = false;
786 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
787 foreach (AISObjectPtr aAIS, aPrsList) {
788 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
790 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
791 if (!aDim.IsNull()) {
792 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
793 aContext->Redisplay(aDim, false);
798 aDisplayer->updateViewer();
801 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
803 bool isRedisplayed = false;
804 if (myCustomPrs->isActive())
805 isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
807 return isRedisplayed;
810 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
812 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
814 QLineEdit* aLabel = aOB->activeDocLabel();
815 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
816 SLOT(onActiveDocPopup(const QPoint&)));
817 //QPalette aPalet = aLabel->palette();
818 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
819 //aLabel->setPalette(aPalet);
820 aOB->treeView()->setExpandsOnDoubleClick(false);
821 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
822 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
826 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
828 SessionPtr aMgr = ModelAPI_Session::get();
829 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
831 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
832 XGUI_Workshop* aWorkshop = aConnector->workshop();
833 QLineEdit* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
835 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
838 aMenu.addAction(aActivatePartAction);
839 aMenu.exec(aHeader->mapToGlobal(thePnt));
843 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
846 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
848 /// If last line finished on vertex the lines creation sequence has to be break
849 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
850 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
851 // if there is an active widget, find the presented object in it
853 anActiveWidget = aPanel->preselectionWidget();
855 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
857 if (aWidgetValidated)
858 anObject = aWidgetValidated->findPresentedObject(theAIS);
863 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
865 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
866 int aSelected = aObjects.size();
867 SessionPtr aMgr = ModelAPI_Session::get();
868 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
870 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
871 if (aSelected == 1) {
872 bool hasResult = false;
873 bool hasFeature = false;
874 bool hasParameter = false;
875 bool hasSubFeature = false;
876 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
878 ObjectPtr aObject = aObjects.first();
880 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
881 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
882 bool isPart = aPart.get() ||
883 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
885 DocumentPtr aPartDoc;
887 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
889 if (aPart.get()) // this may be null is Part feature is disabled
890 aPartDoc = aPart->partDoc();
892 theMenu->addAction(aActivatePartAction);
893 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
895 } else if (aObject->document() == aMgr->activeDocument()) {
896 if (hasParameter || hasFeature) {
897 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
898 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
899 if (aCurrentOp && aFeature.get()) {
900 if (aCurrentOp->id().toStdString() == aFeature->getKind())
901 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
906 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
908 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
911 bool aNotDeactivate = (aCurrentOp == 0);
912 if (!aNotDeactivate) {
913 aActivatePartAction->setEnabled(false);
917 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
919 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
920 // Do not change activation of parts if an operation active
921 static QStringList aAllowActivationList;
922 if (aAllowActivationList.isEmpty())
923 aAllowActivationList <<
924 QString(PartSetPlugin_Part::ID().c_str()) <<
925 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
926 QString(PartSetPlugin_Remove::ID().c_str());
927 if (myWorkshop->currentOperation() &&
928 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
930 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
931 XGUI_Workshop* aWorkshop = aConnector->workshop();
932 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
933 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
934 QPalette aPalet = aLabel->palette();
936 SessionPtr aMgr = ModelAPI_Session::get();
937 DocumentPtr aActiveDoc = aMgr->activeDocument();
938 if (aActivePartIndex.isValid())
939 aTreeView->setExpanded(aActivePartIndex, false);
940 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
941 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
942 if (aActivePartIndex.isValid())
943 aTreeView->setExpanded(aActivePartIndex, true);
945 aLabel->setPalette(aPalet);
946 aWorkshop->updateCommandStatus();
948 // Update displayed objects in order to update active color
949 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
950 QObjectPtrList aObjects = aDisplayer->displayedObjects();
952 foreach(ObjectPtr aObj, aObjects) {
953 //TODO: replace by redisplay event.
954 aHidden = !aObj->data() || !aObj->data()->isValid() ||
955 aObj->isDisabled() || (!aObj->isDisplayed());
957 aDisplayer->redisplay(aObj, false);
959 aDisplayer->updateViewer();
963 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
965 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
967 SessionPtr aMgr = ModelAPI_Session::get();
968 if (!theIndex.isValid()) {
969 aMgr->setActiveDocument(aMgr->moduleDocument());
972 if (theIndex.column() != 0) // Use only first column
975 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
976 XGUI_Workshop* aWorkshop = aConnector->workshop();
977 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
978 // De not use non editable Indexes
979 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
981 ObjectPtr aObj = aDataModel->object(theIndex);
983 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
984 if (!aPart.get()) { // Probably this is Feature
985 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
986 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
987 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
990 if (aPart.get()) { // if this is a part
991 if (aPart->partDoc() == aMgr->activeDocument()) {
992 myMenuMgr->activatePartSet();
1000 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1002 // z layer is created for all started operations in order to visualize operation AIS presentation
1004 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1005 if (aContext.IsNull())
1008 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1009 if (myVisualLayerId == 0) {
1010 if (myVisualLayerId == 0)
1011 aViewer->AddZLayer(myVisualLayerId);
1013 TColStd_SequenceOfInteger aZList;
1014 aViewer->GetAllZLayers(aZList);
1015 bool aFound = false;
1016 for (int i = 1; i <= aZList.Length(); i++) {
1017 if (aZList(i) == myVisualLayerId) {
1023 aViewer->AddZLayer(myVisualLayerId);
1025 // if there is an active operation with validated widget,
1026 // the filters of this widget should be activated in the created view
1027 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1029 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1030 if (anActiveWidget) {
1031 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1033 aWSelector->activateSelectionAndFilters(true);
1038 //******************************************************
1039 void PartSet_Module::widgetStateChanged(int thePreviousState)
1041 mySketchMgr->widgetStateChanged(thePreviousState);
1044 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1046 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);