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_WidgetMultiSelector.h"
12 #include "PartSet_WidgetEditor.h"
13 #include "PartSet_WidgetFileSelector.h"
14 #include "PartSet_WidgetSketchCreator.h"
15 #include "PartSet_SketcherMgr.h"
16 #include "PartSet_SketcherReetntrantMgr.h"
17 #include "PartSet_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
20 #include "PartSet_WidgetChoice.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 <ModelAPI_Object.h>
41 #include <ModelAPI_Events.h>
42 #include <ModelAPI_Validator.h>
43 #include <ModelAPI_Data.h>
44 #include <ModelAPI_Session.h>
45 #include <ModelAPI_ResultBody.h>
46 #include <ModelAPI_AttributeString.h>
48 #include <GeomDataAPI_Point2D.h>
49 #include <GeomDataAPI_Point.h>
50 #include <GeomDataAPI_Dir.h>
52 #include <XGUI_Displayer.h>
53 #include <XGUI_Workshop.h>
54 #include <XGUI_OperationMgr.h>
55 #include <XGUI_PropertyPanel.h>
56 #include <XGUI_ModuleConnector.h>
57 #include <XGUI_ContextMenuMgr.h>
58 #include <XGUI_Tools.h>
59 #include <XGUI_ObjectsBrowser.h>
60 #include <XGUI_SelectionMgr.h>
61 #include <XGUI_DataModel.h>
62 #include <XGUI_ErrorMgr.h>
64 #include <SketchPlugin_Feature.h>
65 #include <SketchPlugin_Sketch.h>
66 #include <SketchPlugin_ConstraintAngle.h>
67 #include <SketchPlugin_ConstraintLength.h>
68 #include <SketchPlugin_ConstraintDistance.h>
69 #include <SketchPlugin_ConstraintParallel.h>
70 #include <SketchPlugin_ConstraintPerpendicular.h>
71 #include <SketchPlugin_ConstraintRadius.h>
73 #include <SketcherPrs_SymbolPrs.h>
74 #include <SketcherPrs_Tools.h>
76 #include <Events_Loop.h>
77 #include <Config_PropManager.h>
78 #include <Config_Keywords.h>
80 #include <StdSelect_TypeOfFace.hxx>
81 #include <TopoDS_Vertex.hxx>
83 #include <TopoDS_Shape.hxx>
84 #include <BRep_Tool.hxx>
85 #include <AIS_Dimension.hxx>
88 #include <QMouseEvent>
91 #include <QApplication>
92 #include <QMessageBox>
93 #include <QMainWindow>
96 #include <GeomAlgoAPI_FaceBuilder.h>
97 #include <GeomDataAPI_Dir.h>
99 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
105 /*!Create and return new instance of XGUI_Module*/
106 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
108 return new PartSet_Module(theWshop);
111 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
112 : ModuleBase_IModule(theWshop),
115 new PartSet_IconFactory();
117 mySketchMgr = new PartSet_SketcherMgr(this);
118 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
120 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
121 XGUI_Workshop* aWorkshop = aConnector->workshop();
123 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
124 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
125 this, SLOT(onOperationActivatedByPreselection()));
127 ModuleBase_IViewer* aViewer = theWshop->viewer();
128 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
129 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
130 connect(aViewer, SIGNAL(viewTransformed(int)),
131 SLOT(onViewTransformed(int)));
132 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
133 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
134 myMenuMgr = new PartSet_MenuMgr(this);
135 myCustomPrs = new PartSet_CustomPrs(theWshop);
137 Events_Loop* aLoop = Events_Loop::loop();
138 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
140 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
141 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
143 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
144 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
146 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
147 "Reference shape wireframe color in operation", Config_Prop::Color,
148 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
149 Config_PropManager::registerProp("Visualization", "operation_result_color",
150 "Result shape wireframe color in operation", Config_Prop::Color,
151 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
152 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
153 "Multi selector item color in operation", Config_Prop::Color,
154 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
157 PartSet_Module::~PartSet_Module()
159 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
160 for (; aIt.More(); aIt.Next()) {
161 Handle(SelectMgr_Filter) aFilter = aIt.Value();
162 if (!aFilter.IsNull())
168 void PartSet_Module::activateSelectionFilters()
170 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
171 for (; aIt.More(); aIt.Next()) {
172 Handle(SelectMgr_Filter) aFilter = aIt.Value();
173 if (!aFilter.IsNull())
174 myWorkshop->viewer()->addSelectionFilter(aFilter);
178 void PartSet_Module::deactivateSelectionFilters()
180 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
181 for (; aIt.More(); aIt.Next()) {
182 Handle(SelectMgr_Filter) aFilter = aIt.Value();
183 if (!aFilter.IsNull())
184 myWorkshop->viewer()->removeSelectionFilter(aFilter);
188 void PartSet_Module::registerValidators()
190 //Registering of validators
191 SessionPtr aMgr = ModelAPI_Session::get();
192 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
193 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
194 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
195 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
196 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
197 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
198 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
199 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
200 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
201 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
202 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
203 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
204 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
205 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
206 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
207 aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
210 void PartSet_Module::registerFilters()
212 //Registering of selection filters
213 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
214 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
217 void PartSet_Module::registerProperties()
219 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
221 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
222 Config_Prop::Integer, SKETCH_WIDTH);
223 Config_PropManager::registerProp("Sketch planes", "rotate_to_plane", "Rotate to plane when selected",
224 Config_Prop::Boolean, "false");
227 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect)
229 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
232 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
234 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
235 mySketchMgr->commitNestedSketch(theOperation);
238 /// Restart sketcher operations automatically
239 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
241 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
242 if (aFOperation && !aFOperation->isEditOperation()) {
243 // the selection is cleared after commit the create operation
244 // in order to do not use the same selected objects in the restarted operation
245 // for common behaviour, the selection is cleared even if the operation is not restarted
246 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
247 XGUI_Workshop* aWorkshop = aConnector->workshop();
248 aWorkshop->selector()->clearSelection();
253 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
255 /// Restart sketcher operations automatically
256 mySketchReentrantMgr->operationAborted(theOperation);
259 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
261 /// Restart sketcher operations automatically
262 mySketchReentrantMgr->operationStarted(theOperation);
264 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
265 mySketchMgr->startSketch(theOperation);
267 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
268 mySketchMgr->startNestedSketch(theOperation);
271 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
273 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
274 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
278 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
280 ModuleBase_IModule::operationResumed(theOperation);
282 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
284 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
285 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
289 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
291 bool isModified = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false) ||
292 myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
294 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
295 mySketchMgr->stopNestedSketch(theOperation);
298 //VSV: Viewer is updated on feature update and redisplay
300 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
301 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
302 aDisplayer->updateViewer();
305 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator anIt = myHasConstraintShown.begin(),
306 aLast = myHasConstraintShown.end();
307 for (; anIt != aLast; anIt++) {
308 myHasConstraintShown[anIt.key()];
309 mySketchMgr->onShowConstraintsToggle(anIt.value(), myHasConstraintShown[anIt.key()]);
313 ModuleBase_Operation* PartSet_Module::currentOperation() const
315 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
316 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
317 return anOpMgr->currentOperation();
320 bool PartSet_Module::canUndo() const
322 bool aCanUndo = false;
323 SessionPtr aMgr = ModelAPI_Session::get();
324 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
325 aCanUndo = !aMgr->isOperation();
326 if (!aCanUndo) // check the enable state additionally by sketch manager
327 aCanUndo = aMgr->canUndo();
332 bool PartSet_Module::canRedo() const
334 bool aCanRedo = false;
335 SessionPtr aMgr = ModelAPI_Session::get();
336 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
337 aCanRedo = !aMgr->isOperation();
338 if (!aCanRedo) // check the enable state additionally by sketch manager
339 aCanRedo = aMgr->canRedo();
344 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
347 if (theActionId == "MOVE_CMD") {
348 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
350 // part features can not be moved in the history.
351 if (aFeature->getKind() == PartSetPlugin_Part::ID())
358 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
360 // the sketch manager put the restriction to the objects erase
361 return mySketchMgr->canEraseObject(theObject);
364 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
366 // the sketch manager put the restriction to the objects display
367 return mySketchMgr->canDisplayObject(theObject);
370 void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
372 mySketchMgr->processHiddenObject(theObjects);
375 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
377 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
379 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
380 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
381 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
382 if (isSketchOp || isNestedOp) {
383 // in active sketch operation it is possible to activate operation object in selection
384 // in the edit operation, e.g. points of the line can be moved when the line is edited
385 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
386 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
391 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
393 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
396 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
398 myMenuMgr->updateViewerMenu(theStdActions);
401 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
403 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
404 if (anError.isEmpty())
405 anError = sketchMgr()->getFeatureError(theFeature);
410 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
411 QStringList& theIds) const
413 myMenuMgr->grantedOperationIds(theOperation, theIds);
415 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
416 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
417 XGUI_Workshop* aWorkshop = aConnector->workshop();
419 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
423 void PartSet_Module::activeSelectionModes(QIntList& theModes)
426 if (mySketchMgr->activeSketch().get())
427 PartSet_SketcherMgr::sketchSelectionModes(theModes);
430 bool PartSet_Module::isMouseOverWindow()
432 return mySketchMgr->isMouseOverWindow();
435 void PartSet_Module::closeDocument()
440 void PartSet_Module::clearViewer()
442 myCustomPrs->clearPrs();
444 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
445 XGUI_Workshop* aWorkshop = aConnector->workshop();
446 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
447 aDisplayer->deactivateSelectionFilters();
450 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
452 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
456 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
457 // we have to manually activate the sketch label in edit mode
458 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
459 aPanel->activateWidget(aPanel->modelWidgets().first());
463 void PartSet_Module::onSelectionChanged()
465 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
469 bool isSketcherOp = false;
470 // An edit operation is enable only if the current opeation is the sketch operation
471 if (mySketchMgr->activeSketch()) {
472 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
473 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
476 // Editing of constraints can be done on selection
477 ModuleBase_ISelection* aSelect = myWorkshop->selection();
478 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
479 if (aSelected.size() == 1) {
480 ModuleBase_ViewerPrs aPrs = aSelected.first();
481 ObjectPtr aObject = aPrs.object();
482 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
484 std::string aId = aFeature->getKind();
485 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
486 (aId == SketchPlugin_ConstraintLength::ID()) ||
487 (aId == SketchPlugin_ConstraintDistance::ID()) ||
488 (aId == SketchPlugin_ConstraintAngle::ID())) {
489 editFeature(aFeature);
496 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
498 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
499 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
500 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
503 void PartSet_Module::onOperationActivatedByPreselection()
505 if (!mySketchReentrantMgr->canBeCommittedByPreselection())
507 mySketchMgr->operationActivatedByPreselection();
510 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
511 Config_WidgetAPI* theWidgetApi, std::string theParentId)
513 ModuleBase_IWorkshop* aWorkshop = workshop();
514 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
515 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
516 ModuleBase_ModelWidget* aWgt = NULL;
517 if (theType == "sketch-start-label") {
518 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
519 theWidgetApi, theParentId, mySketchMgr->showConstraintStates());
520 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
521 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
522 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool, int)),
523 mySketchMgr, SLOT(onShowConstraintsToggle(bool, int)));
525 } else if (theType == "sketch-2dpoint_selector") {
526 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
527 theWidgetApi, theParentId);
528 aPointWgt->setSketch(mySketchMgr->activeSketch());
529 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
531 }else if (theType == "sketch-2dpoint_flyout_selector") {
532 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
533 theWidgetApi, theParentId);
534 aPointWgt->setSketch(mySketchMgr->activeSketch());
535 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
537 } else if (theType == "point2ddistance") {
538 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
539 aWorkshop, theWidgetApi, theParentId);
540 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
542 } else if (theType == "sketch_shape_selector") {
543 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
544 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
545 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
546 aWgt = aShapeSelectorWgt;
547 } else if (theType == "sketch_multi_selector") {
548 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
549 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
550 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
551 aWgt = aShapeSelectorWgt;
552 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
553 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
554 } else if (theType == "export_file_selector") {
555 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
556 } else if (theType == "sketch_launcher") {
557 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
558 } else if (theType == "module_choice") {
559 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi, theParentId);
560 connect(aWgt, SIGNAL(itemSelected(int)), SLOT(onBooleanOperationChange(int)));
565 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
567 ModuleBase_ModelWidget* anActiveWidget = 0;
569 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
570 if (!anActiveWidget) {
571 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
573 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
574 anActiveWidget = aPanel->activeWidget();
577 return anActiveWidget;
580 bool PartSet_Module::deleteObjects()
582 bool isProcessed = false;
584 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
585 XGUI_Workshop* aWorkshop = aConnector->workshop();
586 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
588 //SessionPtr aMgr = ModelAPI_Session::get();
589 // 1. check whether the delete should be processed in the module
590 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
591 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
592 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
593 if (isSketchOp || isNestedOp) {
595 // 2. find selected presentations
596 // selected objects should be collected before the current operation abort because
597 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
598 ModuleBase_ISelection* aSel = workshop()->selection();
599 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
600 // if there are no selected objects in the viewer, that means that the selection in another
601 // place cased this method. It is necessary to return the false value to understande in above
602 // method that delete is not processed
603 if (aSelectedObj.count() == 0)
606 // avoid delete of the objects, which are not belong to the current sketch
607 // in order to do not delete results of other sketches
608 QObjectPtrList aSketchObjects;
609 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
610 for ( ; anIt != aLast; anIt++) {
611 ObjectPtr anObject = *anIt;
612 if (mySketchMgr->isObjectOfSketch(anObject)) {
613 // sketch feature should be used in this list because workshop deletes features only
614 // results are skipped
615 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
616 aSketchObjects.append(aSketchFeature);
619 // if the selection contains only local selected presentations from other sketches,
620 // the Delete operation should not be done at all
621 if (aSketchObjects.size() == 0)
624 // 3. start operation
625 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
626 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
628 // the active nested sketch operation should be aborted unconditionally
629 // the Delete action should be additionally granted for the Sketch operation
630 // in order to do not abort/commit it
631 if (!anOpMgr->canStartOperation(anOpAction->id()))
632 return true; // the objects are processed but can not be deleted
634 anOpMgr->startOperation(anOpAction);
636 // 4. delete features
637 // sketch feature should be skipped, only sub-features can be removed
638 // when sketch operation is active
639 aWorkshop->deleteFeatures(aSketchObjects);
641 anOpMgr->commitOperation();
646 void PartSet_Module::onFeatureTriggered()
648 QAction* aCmd = dynamic_cast<QAction*>(sender());
649 if (aCmd->isCheckable() && aCmd->isChecked()) {
650 // 1. check whether the delete should be processed in the module
651 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
652 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
654 // in case if in the viewer nothing is displayed, the create operation should not be
655 // comitted even if all values of the feature are initialized
656 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
657 // the action information should be saved before the operation is aborted
658 // because this abort leads to update command status, which unchecks this action
659 anOperation->abort();
660 launchOperation(aCmd->data().toString());
664 ModuleBase_IModule::onFeatureTriggered();
667 void PartSet_Module::launchOperation(const QString& theCmdId)
669 if (myWorkshop->currentOperation() &&
670 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
671 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates = mySketchMgr->showConstraintStates();
672 myHasConstraintShown = aShownStates;
674 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
675 // Show constraints if a constraint was anOperation
676 mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Geometrical);
677 mySketchMgr->onShowConstraintsToggle(true, PartSet_Tools::Dimensional);
679 ModuleBase_IModule::launchOperation(theCmdId);
683 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
685 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
686 if (!anAIS.IsNull()) {
687 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
688 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
689 if (!aDim.IsNull()) {
690 aCtx->SetZLayer(aDim, myVisualLayerId);
692 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
694 aCtx->SetZLayer(aCons, myVisualLayerId);
699 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
702 // it should be recomputed in order to disappear in the viewer if the corresponded object
704 //if (myCustomPrs->isActive())
705 // myCustomPrs->redisplay(theObject, false);
708 void PartSet_Module::onViewTransformed(int theTrsfType)
710 // Set length of arrows constant in pixel size
711 // if the operation is panning or rotate or panglobal then do nothing
712 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
714 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
715 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
716 if (aContext.IsNull())
719 //Handle(V3d_View) aView = aViewer->activeView();
721 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
722 XGUI_Workshop* aWorkshop = aConnector->workshop();
723 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
724 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
725 Handle(V3d_View) aView;
727 for (aV3dViewer->InitDefinedViews();
728 aV3dViewer->MoreDefinedViews();
729 aV3dViewer->NextDefinedViews()) {
730 Handle(V3d_View) aV = aV3dViewer->DefinedView();
731 double aS = aV->Scale();
739 double aLen = aView->Convert(20);
741 double aPrevLen = SketcherPrs_Tools::getArrowSize();
742 SketcherPrs_Tools::setArrowSize(aLen);
743 const double aPrevScale = aViewer->Scale(aViewer->activeView());
744 const double aCurScale = aViewer->activeView()->Camera()->Scale();
745 aViewer->SetScale(aViewer->activeView(), aCurScale);
746 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
747 bool isModified = false;
748 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
749 foreach (AISObjectPtr aAIS, aPrsList) {
750 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
752 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
753 if (!aDim.IsNull()) {
754 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
755 aContext->Redisplay(aDim, false);
760 aDisplayer->updateViewer();
763 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
764 const bool theUpdateViewer)
766 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
769 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
770 const bool theUpdateViewer)
772 myCustomPrs->deactivate(theFlag, theUpdateViewer);
775 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
776 const bool theUpdateViewer)
778 bool isRedisplayed = false;
779 if (myCustomPrs->isActive(theFlag))
780 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
782 return isRedisplayed;
785 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
787 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
789 QLabel* aLabel = aOB->activeDocLabel();
790 aLabel->installEventFilter(myMenuMgr);
791 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
792 SLOT(onActiveDocPopup(const QPoint&)));
793 //QPalette aPalet = aLabel->palette();
794 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
795 //aLabel->setPalette(aPalet);
796 aOB->treeView()->setExpandsOnDoubleClick(false);
797 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
798 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
802 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
804 SessionPtr aMgr = ModelAPI_Session::get();
805 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
807 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
808 XGUI_Workshop* aWorkshop = aConnector->workshop();
809 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
811 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
814 aMenu.addAction(aActivatePartAction);
815 aMenu.exec(aHeader->mapToGlobal(thePnt));
819 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
822 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
824 /// If last line finished on vertex the lines creation sequence has to be break
825 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
827 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
828 // if there is an active widget, find the presented object in it
830 anActiveWidget = aPanel->preselectionWidget();
832 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
834 if (aWidgetValidated)
835 anObject = aWidgetValidated->findPresentedObject(theAIS);
841 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
843 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
844 int aSelected = aObjects.size();
845 SessionPtr aMgr = ModelAPI_Session::get();
846 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
848 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
849 if (aSelected == 1) {
850 bool hasResult = false;
851 bool hasFeature = false;
852 bool hasParameter = false;
853 bool hasSubFeature = false;
854 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
856 ObjectPtr aObject = aObjects.first();
858 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
859 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
860 bool isPart = aPart.get() ||
861 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
863 DocumentPtr aPartDoc;
865 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
867 if (aPart.get()) // this may be null is Part feature is disabled
868 aPartDoc = aPart->partDoc();
870 theMenu->addAction(aActivatePartAction);
871 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
873 } else if (aObject->document() == aMgr->activeDocument()) {
874 if (hasParameter || hasFeature) {
875 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
876 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
877 if (aCurrentOp && aFeature.get()) {
878 if (aCurrentOp->id().toStdString() == aFeature->getKind())
879 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
884 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
886 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
889 bool aNotDeactivate = (aCurrentOp == 0);
890 if (!aNotDeactivate) {
891 aActivatePartAction->setEnabled(false);
895 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
897 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
898 // Do not change activation of parts if an operation active
899 static QStringList aAllowActivationList;
900 if (aAllowActivationList.isEmpty())
901 aAllowActivationList <<
902 QString(PartSetPlugin_Part::ID().c_str()) <<
903 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
904 QString(PartSetPlugin_Remove::ID().c_str());
905 if (myWorkshop->currentOperation() &&
906 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
908 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
909 XGUI_Workshop* aWorkshop = aConnector->workshop();
910 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
911 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
912 QPalette aPalet = aLabel->palette();
914 SessionPtr aMgr = ModelAPI_Session::get();
915 DocumentPtr aActiveDoc = aMgr->activeDocument();
916 if (aActivePartIndex.isValid())
917 aTreeView->setExpanded(aActivePartIndex, false);
918 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
919 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
920 if (aActivePartIndex.isValid())
921 aTreeView->setExpanded(aActivePartIndex, true);
923 aLabel->setPalette(aPalet);
924 aWorkshop->updateCommandStatus();
926 // Update displayed objects in order to update active color
927 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
928 QObjectPtrList aObjects = aDisplayer->displayedObjects();
930 foreach(ObjectPtr aObj, aObjects) {
931 //TODO: replace by redisplay event.
932 aHidden = !aObj->data() || !aObj->data()->isValid() ||
933 aObj->isDisabled() || (!aObj->isDisplayed());
935 aDisplayer->redisplay(aObj, false);
937 aDisplayer->updateViewer();
941 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
943 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
945 SessionPtr aMgr = ModelAPI_Session::get();
946 if (!theIndex.isValid()) {
947 aMgr->setActiveDocument(aMgr->moduleDocument());
950 if (theIndex.column() != 0) // Use only first column
953 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
954 XGUI_Workshop* aWorkshop = aConnector->workshop();
955 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
956 // De not use non editable Indexes
957 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
959 ObjectPtr aObj = aDataModel->object(theIndex);
961 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
962 if (!aPart.get()) { // Probably this is Feature
963 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
964 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
965 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
968 if (aPart.get()) { // if this is a part
969 if (aPart->partDoc() == aMgr->activeDocument()) {
970 myMenuMgr->activatePartSet();
978 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
980 // z layer is created for all started operations in order to visualize operation AIS presentation
982 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
983 if (aContext.IsNull())
986 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
987 if (myVisualLayerId == 0) {
988 if (myVisualLayerId == 0)
989 aViewer->AddZLayer(myVisualLayerId);
991 TColStd_SequenceOfInteger aZList;
992 aViewer->GetAllZLayers(aZList);
994 for (int i = 1; i <= aZList.Length(); i++) {
995 if (aZList(i) == myVisualLayerId) {
1001 aViewer->AddZLayer(myVisualLayerId);
1003 // if there is an active operation with validated widget,
1004 // the filters of this widget should be activated in the created view
1005 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1007 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1008 if (anActiveWidget) {
1009 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1011 aWSelector->activateSelectionAndFilters(true);
1016 //******************************************************
1017 void PartSet_Module::widgetStateChanged(int thePreviousState)
1019 mySketchMgr->widgetStateChanged(thePreviousState);
1022 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1024 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1027 //******************************************************
1028 void PartSet_Module::beforeOperationStarted(ModuleBase_Operation* theOperation)
1032 //******************************************************
1033 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1035 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1036 mySketchMgr->stopSketch(theOperation);
1040 //******************************************************
1041 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1043 GeomShapePtr aGeomShape;
1045 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1046 if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
1047 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1052 //******************************************************
1053 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1054 const GeomShapePtr& theGeomShape)
1056 AttributePtr anAttribute;
1057 GeomShapePtr aGeomShape = theGeomShape;
1058 if (!aGeomShape.get()) {
1059 // processing shape of result, e.g. sketch circle center is selected, this is a result
1060 // the geom shape is empty, the shape of result should be used
1061 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1062 if (aResult.get()) {
1063 aGeomShape = aResult->shape();
1067 if (aGeomShape.get()) {
1068 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1069 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1070 mySketchMgr->activeSketch());
1075 //******************************************************
1076 void PartSet_Module::onBooleanOperationChange(int theOperation)
1078 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1081 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1082 switch (theOperation) {
1084 aPanel->setWindowTitle(tr("Cut"));
1087 aPanel->setWindowTitle(tr("Fuse"));
1090 aPanel->setWindowTitle(tr("Common"));