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_PreviewPlanes.h"
8 #include "PartSet_WidgetPoint2d.h"
9 #include "PartSet_WidgetPoint2dDistance.h"
10 #include "PartSet_WidgetPoint2DFlyout.h"
11 #include "PartSet_WidgetShapeSelector.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetSubShapeSelector.h"
14 #include "PartSet_WidgetEditor.h"
15 #include "PartSet_WidgetFileSelector.h"
16 #include "PartSet_WidgetSketchCreator.h"
17 #include "PartSet_SketcherMgr.h"
18 #include "PartSet_SketcherReetntrantMgr.h"
19 #include "PartSet_ResultSketchPrs.h"
20 #include "PartSet_MenuMgr.h"
21 #include "PartSet_CustomPrs.h"
22 #include "PartSet_IconFactory.h"
23 #include "PartSet_WidgetChoice.h"
24 #include "PartSet_OverconstraintListener.h"
26 #include "PartSet_Filters.h"
27 #include "PartSet_FilterInfinite.h"
29 #include <PartSetPlugin_Remove.h>
30 #include <PartSetPlugin_Part.h>
31 #include <PartSetPlugin_Duplicate.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationAction.h>
35 #include <ModuleBase_IViewer.h>
36 #include <ModuleBase_IViewWindow.h>
37 #include <ModuleBase_IPropertyPanel.h>
38 #include <ModuleBase_WidgetEditor.h>
39 #include <ModuleBase_WidgetValidated.h>
40 #include <ModuleBase_FilterFactory.h>
41 #include <ModuleBase_Tools.h>
42 #include <ModuleBase_OperationFeature.h>
43 #include <ModuleBase_WidgetFactory.h>
44 #include <ModuleBase_OperationDescription.h>
45 #include <ModuleBase_ViewerPrs.h>
47 #include <ModelAPI_Object.h>
48 #include <ModelAPI_Events.h>
49 #include <ModelAPI_Validator.h>
50 #include <ModelAPI_Data.h>
51 #include <ModelAPI_Session.h>
52 #include <ModelAPI_ResultBody.h>
53 #include <ModelAPI_AttributeString.h>
54 #include <ModelAPI_AttributeSelectionList.h>
55 #include <ModelAPI_Tools.h>
56 #include <ModelAPI_ResultConstruction.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>
73 #include <XGUI_CustomPrs.h>
74 #include <XGUI_SelectionMgr.h>
75 #include <XGUI_ActionsMgr.h>
77 #include <SketchPlugin_Feature.h>
78 #include <SketchPlugin_Sketch.h>
79 #include <SketchPlugin_ConstraintAngle.h>
80 #include <SketchPlugin_ConstraintLength.h>
81 #include <SketchPlugin_ConstraintDistance.h>
82 #include <SketchPlugin_ConstraintParallel.h>
83 #include <SketchPlugin_ConstraintPerpendicular.h>
84 #include <SketchPlugin_ConstraintRadius.h>
86 #include <SketcherPrs_SymbolPrs.h>
87 #include <SketcherPrs_Coincident.h>
88 #include <SketcherPrs_Tools.h>
90 #include <Events_Loop.h>
91 #include <Config_PropManager.h>
92 #include <Config_Keywords.h>
94 #include <AIS_Dimension.hxx>
95 #include <AIS_InteractiveObject.hxx>
96 #include <StdSelect_TypeOfFace.hxx>
97 #include <TopoDS_Vertex.hxx>
99 #include <TopoDS_Shape.hxx>
100 #include <BRep_Tool.hxx>
103 #include <QMouseEvent>
106 #include <QApplication>
107 #include <QMessageBox>
108 #include <QMainWindow>
112 #include <GeomAlgoAPI_FaceBuilder.h>
113 #include <GeomDataAPI_Dir.h>
115 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
121 /*!Create and return new instance of XGUI_Module*/
122 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
124 return new PartSet_Module(theWshop);
127 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
128 : ModuleBase_IModule(theWshop),
130 myIsOperationIsLaunched(false)
132 new PartSet_IconFactory();
134 mySketchMgr = new PartSet_SketcherMgr(this);
135 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
137 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
138 XGUI_Workshop* aWorkshop = aConnector->workshop();
140 ModuleBase_IViewer* aViewer = theWshop->viewer();
141 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
142 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
143 connect(aViewer, SIGNAL(viewTransformed(int)),
144 SLOT(onViewTransformed(int)));
145 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
146 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
147 myMenuMgr = new PartSet_MenuMgr(this);
148 myCustomPrs = new PartSet_CustomPrs(theWshop);
150 myOverconstraintListener = new PartSet_OverconstraintListener(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));
158 setDefaultConstraintShown();
160 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
161 "Reference shape wireframe color in operation", Config_Prop::Color,
162 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
163 Config_PropManager::registerProp("Visualization", "operation_result_color",
164 "Result shape wireframe color in operation", Config_Prop::Color,
165 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
166 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
167 "Multi selector item color in operation", Config_Prop::Color,
168 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
171 PartSet_Module::~PartSet_Module()
173 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
174 for (; aIt.More(); aIt.Next()) {
175 Handle(SelectMgr_Filter) aFilter = aIt.Value();
176 if (!aFilter.IsNull())
180 delete myOverconstraintListener;
183 void PartSet_Module::activateSelectionFilters()
185 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
186 for (; aIt.More(); aIt.Next()) {
187 Handle(SelectMgr_Filter) aFilter = aIt.Value();
188 if (!aFilter.IsNull())
189 myWorkshop->viewer()->addSelectionFilter(aFilter);
193 void PartSet_Module::deactivateSelectionFilters()
195 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
196 for (; aIt.More(); aIt.Next()) {
197 Handle(SelectMgr_Filter) aFilter = aIt.Value();
198 if (!aFilter.IsNull())
199 myWorkshop->viewer()->removeSelectionFilter(aFilter);
203 void PartSet_Module::storeSelection()
205 sketchMgr()->storeSelection();
208 void PartSet_Module::restoreSelection()
210 sketchMgr()->restoreSelection();
213 void PartSet_Module::registerValidators()
215 //Registering of validators
216 SessionPtr aMgr = ModelAPI_Session::get();
217 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
218 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
219 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
220 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
221 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
222 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
223 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
224 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
225 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
226 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
227 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
228 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
229 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
230 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
231 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
232 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
233 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
234 aFactory->registerValidator("PartSet_MultyTranslationSelection",
235 new PartSet_MultyTranslationSelection);
236 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
237 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
240 void PartSet_Module::registerFilters()
242 //Registering of selection filters
243 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
244 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
247 void PartSet_Module::registerProperties()
249 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::Double,
251 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
252 Config_Prop::Integer, SKETCH_WIDTH);
253 Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
254 "Rotate to plane when selected", Config_Prop::Boolean, "false");
257 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
258 const bool isToConnect)
260 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
263 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
265 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
266 mySketchMgr->commitNestedSketch(theOperation);
269 /// Restart sketcher operations automatically
270 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
272 ModuleBase_OperationFeature* aFOperation =
273 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
274 if (aFOperation && !aFOperation->isEditOperation()) {
275 // the selection is cleared after commit the create operation
276 // in order to do not use the same selected objects in the restarted operation
277 // for common behaviour, the selection is cleared even if the operation is not restarted
278 getWorkshop()->selector()->clearSelection();
283 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
285 /// Restart sketcher operations automatically
286 mySketchReentrantMgr->operationAborted(theOperation);
289 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
291 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
294 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
295 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
297 ModuleBase_ModelWidget* aFilledWidget = 0;
298 bool aPostonedWidgetActivation = false;
300 FeaturePtr aFeature = aFOperation->feature();
301 /// Restart sketcher operations automatically
302 /// it is important to call method of sketch reentrant manager before filling of PP
303 /// because it fills some created feature attributes, these new values should be used
304 /// to fill the property panel
305 mySketchReentrantMgr->operationStarted(theOperation);
307 aWorkshop->fillPropertyPanel(aFOperation);
308 // filling the operation values by the current selection
309 // if the operation can be committed after the controls filling, the method perform should
310 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
311 bool isOperationCommitted = false;
312 if (!aFOperation->isEditOperation()) {
313 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
314 // if there is a greed attribute, automatic commit by preselection
315 // for this feature is prohibited
316 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
317 if (currentOperation() != aFOperation)
318 isOperationCommitted = true;
320 if (aGreedAttributeId.empty()) {
321 // a signal should be emitted before the next widget activation
322 // because, the activation of the next widget will give a focus to the widget.
323 // As a result the value of the widget is initialized.
324 // And commit may happens until the value is entered.
326 if (mySketchReentrantMgr->canBeCommittedByPreselection())
327 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
328 // activate the next obligatory widget
329 if (!isOperationCommitted)
330 aPropertyPanel->activateNextWidget(aFilledWidget);
333 else { // there is a greed widget
334 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
335 std::string aFirstAttributeId = aWidgets.front()->attributeID();
336 // activate next widget after greeded if it is the first widget in the panel
337 // else the first panel widget is already activated by operation start
338 if (aFirstAttributeId == aGreedAttributeId)
339 aPostonedWidgetActivation = true;
342 } if (!isOperationCommitted) {
343 aWorkshop->connectToPropertyPanel(true);
344 updateSketcherOnStart(aFOperation);
345 updatePresentationsOnStart(aFOperation);
347 // the objects of the current operation should be deactivated
348 QObjectPtrList anObjects;
349 anObjects.append(aFeature);
350 std::list<ResultPtr> aResults;
351 ModelAPI_Tools::allResults(aFeature, aResults);
352 std::list<ResultPtr>::const_iterator aIt;
353 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
354 anObjects.append(*aIt);
356 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
357 for (; anIt != aLast; anIt++)
358 aWorkshop->deactivateActiveObject(*anIt, false);
359 if (anObjects.size() > 0) {
360 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
361 aDisplayer->updateViewer();
363 /// state of command actions should be updated after displayed objects modification because
364 /// deactivation(for example) of objects may influence on selection in the viewer
365 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
366 workshop()->updateCommandStatus();
368 if (aPostonedWidgetActivation) {
369 // if the widget is an empty in the chain of activated widgets, the current operation
370 // is restarted. It should be performed after functionality of the operation starting
371 aPropertyPanel->activateNextWidget(aFilledWidget);
376 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
378 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
379 mySketchMgr->startSketch(theOperation);
381 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
382 mySketchMgr->startNestedSketch(theOperation);
386 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
388 ModuleBase_OperationFeature* aFOperation =
389 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
391 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
392 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
396 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
398 ModuleBase_IModule::operationResumed(theOperation);
400 ModuleBase_OperationFeature* aFOperation =
401 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
403 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
404 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
408 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
410 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
411 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
412 bool isModified = isModifiedArgs || isModifiedResults;
414 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
415 mySketchMgr->stopNestedSketch(theOperation);
417 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
418 setDefaultConstraintShown();
420 //VSV: Viewer is updated on feature update and redisplay
422 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
423 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
424 aDisplayer->updateViewer();
427 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
428 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
429 for (; anIt != aLast; anIt++) {
430 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
434 ModuleBase_Operation* PartSet_Module::currentOperation() const
436 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
437 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
438 return anOpMgr->currentOperation();
441 bool PartSet_Module::canUndo() const
443 bool aCanUndo = false;
444 SessionPtr aMgr = ModelAPI_Session::get();
445 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
446 aCanUndo = !aMgr->isOperation();
447 if (!aCanUndo) // check the enable state additionally by sketch manager
448 aCanUndo = aMgr->canUndo();
453 bool PartSet_Module::canRedo() const
455 bool aCanRedo = false;
456 SessionPtr aMgr = ModelAPI_Session::get();
457 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
458 aCanRedo = !aMgr->isOperation();
459 if (!aCanRedo) // check the enable state additionally by sketch manager
460 aCanRedo = aMgr->canRedo();
465 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
468 if (theActionId == "MOVE_CMD") {
469 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
471 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
472 // part features can not be moved in the history.
473 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
480 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
482 // the sketch manager put the restriction to the objects erase
483 return mySketchMgr->canEraseObject(theObject);
486 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
488 // the sketch manager put the restriction to the objects display
489 return mySketchMgr->canDisplayObject(theObject);
492 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
494 mySketchMgr->processHiddenObject(theObjects);
497 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
499 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
501 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
502 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
503 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
504 if (isSketchOp || isNestedOp) {
505 // in active sketch operation it is possible to activate operation object in selection
506 // in the edit operation, e.g. points of the line can be moved when the line is edited
507 ModuleBase_OperationFeature* aFOperation =
508 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
509 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
514 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
516 QMap<int, QAction*>& theMenuActions) const
518 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
521 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
523 myMenuMgr->updateViewerMenu(theStdActions);
526 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
528 bool isEnabledFixed = false;
529 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
530 mySketchReentrantMgr->isInternalEditStarted())
531 isEnabledFixed = true;
532 return isEnabledFixed;
535 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
537 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
538 if (anError.isEmpty())
539 anError = sketchMgr()->getFeatureError(theFeature);
544 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
545 QStringList& theIds) const
547 myMenuMgr->grantedOperationIds(theOperation, theIds);
549 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
550 XGUI_Workshop* aWorkshop = getWorkshop();
551 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
555 void PartSet_Module::activeSelectionModes(QIntList& theModes)
558 if (mySketchMgr->activeSketch().get())
559 PartSet_SketcherMgr::sketchSelectionModes(theModes);
562 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
564 if (theTypes.contains(TopAbs_FACE))
565 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
566 if (theTypes.contains(TopAbs_WIRE))
567 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
570 bool PartSet_Module::isMouseOverWindow()
572 return mySketchMgr->isMouseOverWindow();
575 bool PartSet_Module::isSketchNeutralPointActivated() const
577 bool isNeutralPoint = true;
578 if (sketchReentranceMgr()->isInternalEditStarted())
579 isNeutralPoint = false;
580 if (myIsOperationIsLaunched)
581 isNeutralPoint = false;
583 return isNeutralPoint;
586 void PartSet_Module::closeDocument()
588 myActivePartIndex = QModelIndex();
592 void PartSet_Module::clearViewer()
594 myCustomPrs->clearPrs();
596 XGUI_Workshop* aWorkshop = getWorkshop();
597 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
598 aDisplayer->deactivateSelectionFilters();
601 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
603 ModuleBase_OperationFeature* aFOperation =
604 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
608 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
609 // we have to manually activate the sketch label in edit mode
610 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
611 aPanel->activateWidget(aPanel->modelWidgets().first());
614 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
615 QList<ModuleBase_ModelWidget*>& theWidgets) const
617 bool aProcessed = false;
619 ModuleBase_OperationFeature* aFOperation =
620 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
621 XGUI_Workshop* aWorkshop = getWorkshop();
622 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
623 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
624 ModuleBase_ISelection* aSelection = workshop()->selection();
625 // click on a point in sketch leads here with the point is highlighted, not yet selected
626 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
627 if (aPreselection.size() == 1) {
628 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
629 ObjectPtr anObject = aSelectedPrs->object();
631 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
632 FeaturePtr anOpFeature = aFOperation->feature();
633 GeomShapePtr aShape = aSelectedPrs->shape();
634 // click on the digit of dimension constrain comes here
635 // with an empty shape, so we need the check
636 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
637 // if feature has only one result and shape of result is equal to selected shape
638 // this attribute is not processed. It is a case of Sketch Point.
639 if (aFeature->results().size() == 1) {
640 ResultPtr aResult = aFeature->results().front();
641 if (aResult.get() && aResult->shape()->isEqual(aShape))
644 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
645 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
646 mySketchMgr->activeSketch());
647 if (anAttribute.get()) {
648 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
649 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
651 const std::string anAttributeId = anAttribute->id();
652 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
654 theWidgets = aFactory.getModelWidgets();
655 // it is possible that the point does not present in XML definition,
656 // in this case, we assume that it is not processed by this module
657 // e.g. "Intersection point" feature
658 aProcessed = !theWidgets.isEmpty();
666 void PartSet_Module::onSelectionChanged()
668 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
672 bool isSketcherOp = false;
673 // An edit operation is enable only if the current opeation is the sketch operation
674 if (mySketchMgr->activeSketch()) {
675 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
676 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
679 // Editing of constraints can be done on selection
680 ModuleBase_ISelection* aSelect = myWorkshop->selection();
681 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
682 if (aSelected.size() == 1) {
683 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
684 ObjectPtr aObject = aPrs->object();
685 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
687 std::string aId = aFeature->getKind();
688 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
689 (aId == SketchPlugin_ConstraintLength::ID()) ||
690 (aId == SketchPlugin_ConstraintDistance::ID()) ||
691 (aId == SketchPlugin_ConstraintAngle::ID())) {
692 editFeature(aFeature);
699 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
701 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
702 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
703 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
706 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
708 Config_WidgetAPI* theWidgetApi)
710 ModuleBase_IWorkshop* aWorkshop = workshop();
711 XGUI_Workshop* aXUIWorkshop = getWorkshop();
712 ModuleBase_ModelWidget* aWgt = NULL;
713 if (theType == "sketch-start-label") {
714 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
715 theWidgetApi, myHasConstraintShown);
716 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
717 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
718 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
719 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
721 } else if (theType == "sketch-2dpoint_selector") {
722 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
724 aPointWgt->setSketch(mySketchMgr->activeSketch());
725 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
727 }else if (theType == "sketch-2dpoint_flyout_selector") {
728 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
730 aPointWgt->setSketch(mySketchMgr->activeSketch());
731 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
733 } else if (theType == "point2ddistance") {
734 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
735 aWorkshop, theWidgetApi);
736 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
738 } else if (theType == "sketch_shape_selector") {
739 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
740 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
741 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
742 aWgt = aShapeSelectorWgt;
743 } else if (theType == "sketch_multi_selector") {
744 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
745 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
746 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
747 aWgt = aShapeSelectorWgt;
749 else if (theType == "sketch_sub_shape_selector") {
750 PartSet_WidgetSubShapeSelector* aSubShapeSelectorWgt =
751 new PartSet_WidgetSubShapeSelector(theParent, aWorkshop, theWidgetApi);
752 aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
753 aWgt = aSubShapeSelectorWgt;
755 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
756 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
757 } else if (theType == "export_file_selector") {
758 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
759 } else if (theType == "sketch_launcher") {
760 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
761 } else if (theType == "module_choice") {
762 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
763 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
764 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
769 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
771 ModuleBase_ModelWidget* anActiveWidget = 0;
773 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
774 if (!anActiveWidget) {
775 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
777 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
778 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
781 return anActiveWidget;
784 bool PartSet_Module::deleteObjects()
786 bool isProcessed = false;
788 XGUI_Workshop* aWorkshop = getWorkshop();
789 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
791 //SessionPtr aMgr = ModelAPI_Session::get();
792 // 1. check whether the delete should be processed in the module
793 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
794 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
795 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
796 if (isSketchOp || isNestedOp) {
798 // 2. find selected presentations
799 // selected objects should be collected before the current operation abort because
800 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
801 ModuleBase_ISelection* aSel = workshop()->selection();
802 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
803 // if there are no selected objects in the viewer, that means that the selection in another
804 // place cased this method. It is necessary to return the false value to understande in above
805 // method that delete is not processed
806 if (aSelectedObj.count() == 0)
809 // avoid delete of the objects, which are not belong to the current sketch
810 // in order to do not delete results of other sketches
811 QObjectPtrList aSketchObjects;
812 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
813 for ( ; anIt != aLast; anIt++) {
814 ObjectPtr anObject = *anIt;
815 if (mySketchMgr->isObjectOfSketch(anObject)) {
816 // sketch feature should be used in this list because workshop deletes features only
817 // results are skipped
818 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
819 aSketchObjects.append(aSketchFeature);
822 // if the selection contains only local selected presentations from other sketches,
823 // the Delete operation should not be done at all
824 if (aSketchObjects.size() == 0)
827 // 3. start operation
828 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
829 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
831 // the active nested sketch operation should be aborted unconditionally
832 // the Delete action should be additionally granted for the Sketch operation
833 // in order to do not abort/commit it
834 if (!anOpMgr->canStartOperation(anOpAction->id()))
835 return true; // the objects are processed but can not be deleted
837 anOpMgr->startOperation(anOpAction);
839 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
840 // the problem is in AIS Dimensions recompute
841 // if a line and the dim are removed, line is the first
842 // it causes the AIS recompute, where the base line is null,
843 // the result is empty AIS in the viewer
844 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
846 // 4. delete features
847 // sketch feature should be skipped, only sub-features can be removed
848 // when sketch operation is active
849 aWorkshop->deleteFeatures(aSketchObjects);
851 anOpMgr->commitOperation();
856 void PartSet_Module::onFeatureTriggered()
858 // is commented for imp: Unpressing the button of the current action must behave like
859 // a validation if the entity can be created (instead of Cancel, as currently)
860 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
861 if (aCmd->isCheckable() && aCmd->isChecked()) {
862 // 1. check whether the delete should be processed in the module
863 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
864 bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
866 // in case if in the viewer nothing is displayed, the create operation should not be
867 // comitted even if all values of the feature are initialized
868 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
869 // the action information should be saved before the operation is aborted
870 // because this abort leads to update command status, which unchecks this action
871 anOperation->abort();
872 launchOperation(aCmd->data().toString());
876 ModuleBase_IModule::onFeatureTriggered();
879 void PartSet_Module::editFeature(FeaturePtr theFeature)
881 storeConstraintsState(theFeature->getKind());
882 ModuleBase_IModule::editFeature(theFeature);
885 bool PartSet_Module::canCommitOperation() const
890 void PartSet_Module::launchOperation(const QString& theCmdId)
892 myIsOperationIsLaunched = true;
893 storeConstraintsState(theCmdId.toStdString());
894 updateConstraintsState(theCmdId.toStdString());
896 ModuleBase_IModule::launchOperation(theCmdId);
898 myIsOperationIsLaunched = false;
901 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
903 if (myWorkshop->currentOperation() &&
904 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
905 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
906 mySketchMgr->showConstraintStates();
907 myHasConstraintShown = aShownStates;
911 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
913 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
914 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
915 // Show constraints if a constraint was anOperation
916 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
917 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
918 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
919 myHasConstraintShown[PartSet_Tools::Expressions]);
923 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
925 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
926 if (!anAIS.IsNull()) {
927 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
928 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
929 if (!aDim.IsNull()) {
930 aCtx->SetZLayer(aDim, myVisualLayerId);
932 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
934 aCtx->SetZLayer(aCons, myVisualLayerId);
939 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
942 // it should be recomputed in order to disappear in the viewer if the corresponded object
944 //if (myCustomPrs->isActive())
945 // myCustomPrs->redisplay(theObject, false);
948 void PartSet_Module::onViewTransformed(int theTrsfType)
950 // Set length of arrows constant in pixel size
951 // if the operation is panning or rotate or panglobal then do nothing
952 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
954 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
955 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
956 if (aContext.IsNull())
959 //Handle(V3d_View) aView = aViewer->activeView();
961 XGUI_Workshop* aWorkshop = getWorkshop();
962 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
963 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
964 Handle(V3d_View) aView;
966 for (aV3dViewer->InitDefinedViews();
967 aV3dViewer->MoreDefinedViews();
968 aV3dViewer->NextDefinedViews()) {
969 Handle(V3d_View) aV = aV3dViewer->DefinedView();
970 double aS = aV->Scale();
978 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
980 double aPrevLen = SketcherPrs_Tools::getArrowSize();
981 SketcherPrs_Tools::setArrowSize(aLen);
982 const double aPrevScale = aViewer->Scale(aViewer->activeView());
983 const double aCurScale = aViewer->activeView()->Camera()->Scale();
984 aViewer->SetScale(aViewer->activeView(), aCurScale);
985 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
986 bool isModified = false;
987 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
988 foreach (AISObjectPtr aAIS, aPrsList) {
989 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
991 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
992 if (!aDim.IsNull()) {
993 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
994 aContext->Redisplay(aDim, false);
999 aDisplayer->updateViewer();
1002 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1004 return myCustomPrs->isActive(theFlag);
1007 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1008 const ModuleBase_CustomizeFlag& theFlag,
1009 const bool theUpdateViewer)
1011 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1014 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1015 const bool theUpdateViewer)
1017 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1020 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1021 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1023 bool aCustomized = false;
1025 XGUI_Workshop* aWorkshop = getWorkshop();
1026 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1027 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1031 if (!theResult.get()) {
1032 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
1033 // customize sketch symbol presentation
1035 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1036 if (!anAISIO.IsNull()) {
1037 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1038 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1039 if (!aPrs.IsNull()) {
1040 std::vector<int> aColor;
1041 myOverconstraintListener->getConflictingColor(aColor);
1042 aPrs->SetConflictingConstraint(isConflicting, aColor);
1045 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1046 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1047 if (!aPrs.IsNull()) {
1048 std::vector<int> aColor;
1049 myOverconstraintListener->getConflictingColor(aColor);
1050 aPrs->SetConflictingConstraint(isConflicting, aColor);
1056 // customize sketch dimension constraint presentation
1058 std::vector<int> aColor;
1059 if (isConflicting) {
1060 myOverconstraintListener->getConflictingColor(aColor);
1063 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1064 if (!aColor.empty()) {
1065 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1069 // customize dimentional constrains
1070 sketchMgr()->customizePresentation(anObject);
1075 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1076 const bool theUpdateViewer)
1078 bool isRedisplayed = false;
1079 if (myCustomPrs->isActive(theFlag))
1080 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1082 return isRedisplayed;
1085 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1087 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1089 QLabel* aLabel = aOB->activeDocLabel();
1090 aLabel->installEventFilter(myMenuMgr);
1091 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1092 SLOT(onActiveDocPopup(const QPoint&)));
1093 aOB->treeView()->setExpandsOnDoubleClick(false);
1094 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1095 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1097 Events_Loop* aLoop = Events_Loop::loop();
1098 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1102 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1104 SessionPtr aMgr = ModelAPI_Session::get();
1105 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1107 XGUI_Workshop* aWorkshop = getWorkshop();
1108 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1110 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1113 aMenu.addAction(aActivatePartAction);
1114 aMenu.exec(aHeader->mapToGlobal(thePnt));
1117 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1119 return mySketchMgr->createPresentation(theResult);
1123 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1126 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1128 /// If last line finished on vertex the lines creation sequence has to be break
1129 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1131 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1132 // if there is an active widget, find the presented object in it
1133 if (!anActiveWidget)
1134 anActiveWidget = aPanel->preselectionWidget();
1136 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1138 if (aWidgetValidated)
1139 anObject = aWidgetValidated->findPresentedObject(theAIS);
1145 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1147 bool aCanBeShaged = true;
1149 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1151 aCanBeShaged = false;
1153 return aCanBeShaged;
1156 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1158 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1159 int aSelected = aObjects.size();
1160 SessionPtr aMgr = ModelAPI_Session::get();
1161 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1163 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1164 if (aSelected == 1) {
1165 bool hasResult = false;
1166 bool hasFeature = false;
1167 bool hasParameter = false;
1168 bool hasCompositeOwner = false;
1169 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1171 ObjectPtr aObject = aObjects.first();
1173 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1174 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1175 bool isPart = aPart.get() ||
1176 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1178 DocumentPtr aPartDoc;
1180 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1182 if (aPart.get()) // this may be null is Part feature is disabled
1183 aPartDoc = aPart->partDoc();
1185 theMenu->addAction(aActivatePartAction);
1186 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1188 } else if (aObject->document() == aMgr->activeDocument()) {
1189 if (hasParameter || hasFeature) {
1190 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1191 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1192 if (aCurrentOp && aFeature.get()) {
1193 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1194 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1199 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1201 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1204 bool aNotDeactivate = (aCurrentOp == 0);
1205 if (!aNotDeactivate) {
1206 aActivatePartAction->setEnabled(false);
1210 #define EXPAND_PARENT(OBJ) \
1211 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1212 if (aObjIndex.isValid()) { \
1213 QModelIndex aParent = aObjIndex.parent(); \
1214 int aCount = aDataModel->rowCount(aParent); \
1216 aTreeView->setExpanded(aParent, true); \
1220 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1222 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1223 // Do not change activation of parts if an operation active
1224 static QStringList aAllowActivationList;
1225 if (aAllowActivationList.isEmpty())
1226 aAllowActivationList <<
1227 QString(PartSetPlugin_Part::ID().c_str()) <<
1228 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1229 QString(PartSetPlugin_Remove::ID().c_str());
1230 if (myWorkshop->currentOperation() &&
1231 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1233 XGUI_Workshop* aWorkshop = getWorkshop();
1234 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1235 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1236 QPalette aPalet = aLabel->palette();
1238 SessionPtr aMgr = ModelAPI_Session::get();
1239 DocumentPtr aActiveDoc = aMgr->activeDocument();
1240 if (myActivePartIndex.isValid())
1241 aTreeView->setExpanded(myActivePartIndex, false);
1242 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1243 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1244 if (myActivePartIndex.isValid())
1245 aTreeView->setExpanded(myActivePartIndex, true);
1247 aLabel->setPalette(aPalet);
1248 aWorkshop->updateCommandStatus();
1250 // Update displayed objects in order to update active color
1251 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1252 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1254 foreach(ObjectPtr aObj, aObjects) {
1255 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1256 aObj->isDisabled() || (!aObj->isDisplayed());
1258 aDisplayer->redisplay(aObj, false);
1260 aDisplayer->updateViewer();
1261 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1262 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1263 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1264 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1266 ObjectPtr aConstrObj;
1267 ObjectPtr aResultObj;
1268 std::set<ObjectPtr>::const_iterator aIt;
1269 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1270 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1271 ObjectPtr aObject = (*aIt);
1272 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1273 && (aObject->document() != aRootDoc))
1274 aResultObj = aObject;
1275 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1276 && (aObject->document() != aRootDoc))
1277 aConstrObj = aObject;
1278 if (aResultObj.get() && aConstrObj.get())
1282 if (aResultObj.get() || aConstrObj.get()) {
1283 XGUI_Workshop* aWorkshop = getWorkshop();
1284 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1285 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1287 if (aResultObj.get()) {
1288 EXPAND_PARENT(aResultObj)
1290 if (aConstrObj.get()) {
1291 EXPAND_PARENT(aConstrObj)
1297 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1299 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1301 SessionPtr aMgr = ModelAPI_Session::get();
1302 if (!theIndex.isValid()) {
1303 // It seems that this code is obsolete
1304 //aMgr->setActiveDocument(aMgr->moduleDocument());
1307 if (theIndex.column() != 0) // Use only first column
1310 XGUI_Workshop* aWorkshop = getWorkshop();
1311 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1312 // De not use non editable Indexes
1313 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1315 ObjectPtr aObj = aDataModel->object(theIndex);
1317 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1318 if (!aPart.get()) { // Probably this is Feature
1319 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1320 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1321 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1324 if (aPart.get()) { // if this is a part
1325 if (aPart->partDoc() == aMgr->activeDocument()) {
1326 myMenuMgr->activatePartSet();
1328 myMenuMgr->activatePart(aPart);
1334 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1336 // z layer is created for all started operations in order to visualize operation AIS presentation
1338 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1339 if (aContext.IsNull())
1342 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1343 if (myVisualLayerId == 0) {
1344 if (myVisualLayerId == 0)
1345 aViewer->AddZLayer(myVisualLayerId);
1347 TColStd_SequenceOfInteger aZList;
1348 aViewer->GetAllZLayers(aZList);
1349 bool aFound = false;
1350 for (int i = 1; i <= aZList.Length(); i++) {
1351 if (aZList(i) == myVisualLayerId) {
1357 aViewer->AddZLayer(myVisualLayerId);
1359 // if there is an active operation with validated widget,
1360 // the filters of this widget should be activated in the created view
1361 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1363 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1364 if (anActiveWidget) {
1365 ModuleBase_WidgetSelector* aWSelector =
1366 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1368 aWSelector->activateSelectionAndFilters(true);
1373 //******************************************************
1374 void PartSet_Module::widgetStateChanged(int thePreviousState)
1376 mySketchMgr->widgetStateChanged(thePreviousState);
1379 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1381 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1384 //******************************************************
1385 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1387 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1388 mySketchMgr->stopSketch(theOperation);
1392 //******************************************************
1393 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1395 GeomShapePtr aGeomShape;
1397 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1398 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1399 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1404 //******************************************************
1405 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1406 const GeomShapePtr& theGeomShape)
1408 AttributePtr anAttribute;
1409 GeomShapePtr aGeomShape = theGeomShape;
1410 if (!aGeomShape.get()) {
1411 // processing shape of result, e.g. sketch circle center is selected, this is a result
1412 // the geom shape is empty, the shape of result should be used
1413 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1414 if (aResult.get()) {
1415 aGeomShape = aResult->shape();
1419 if (aGeomShape.get()) {
1420 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1421 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1422 mySketchMgr->activeSketch());
1427 //******************************************************
1428 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1431 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1435 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1436 if (!aChoiceTitle.isEmpty()) {
1437 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1440 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1442 aPanel->setWindowTitle(aChoiceTitle);
1446 //******************************************************
1447 XGUI_Workshop* PartSet_Module::getWorkshop() const
1449 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1450 return aConnector->workshop();
1453 //******************************************************
1454 void PartSet_Module::setDefaultConstraintShown()
1456 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1457 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1458 myHasConstraintShown[PartSet_Tools::Expressions] = false;