1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_Module.h"
22 #include "PartSet_WidgetSketchLabel.h"
23 #include "PartSet_Validators.h"
24 #include "PartSet_Tools.h"
25 #include "PartSet_PreviewPlanes.h"
26 #include "PartSet_WidgetPoint2d.h"
27 #include "PartSet_WidgetPoint2DFlyout.h"
28 #include "PartSet_WidgetShapeSelector.h"
29 #include "PartSet_WidgetMultiSelector.h"
30 #include "PartSet_WidgetFeaturePointSelector.h"
31 #include "PartSet_WidgetEditor.h"
32 #include "PartSet_WidgetFileSelector.h"
33 #include "PartSet_WidgetSketchCreator.h"
34 #include "PartSet_SketcherMgr.h"
35 #include "PartSet_SketcherReentrantMgr.h"
36 #include "PartSet_ResultSketchPrs.h"
37 #include "PartSet_MenuMgr.h"
38 #include "PartSet_CustomPrs.h"
39 #include "PartSet_IconFactory.h"
40 #include "PartSet_OverconstraintListener.h"
41 #include "PartSet_DataModel.h"
43 #include "PartSet_Filters.h"
44 #include "PartSet_FilterInfinite.h"
46 #include <PartSetPlugin_Remove.h>
47 #include <PartSetPlugin_Part.h>
48 #include <PartSetPlugin_Duplicate.h>
50 #include <ModuleBase_Operation.h>
51 #include <ModuleBase_OperationAction.h>
52 #include <ModuleBase_IViewer.h>
53 #include <ModuleBase_IViewWindow.h>
54 #include <ModuleBase_IPropertyPanel.h>
55 #include <ModuleBase_ISelectionActivate.h>
56 #include <ModuleBase_WidgetChoice.h>
57 #include <ModuleBase_WidgetEditor.h>
58 #include <ModuleBase_WidgetValidated.h>
59 #include <ModuleBase_Tools.h>
60 #include <ModuleBase_OperationFeature.h>
61 #include <ModuleBase_WidgetFactory.h>
62 #include <ModuleBase_OperationDescription.h>
63 #include <ModuleBase_ViewerPrs.h>
65 #include <ModelAPI_Object.h>
66 #include <ModelAPI_Events.h>
67 #include <ModelAPI_Validator.h>
68 #include <ModelAPI_Data.h>
69 #include <ModelAPI_Session.h>
70 #include <ModelAPI_ResultBody.h>
71 #include <ModelAPI_AttributeString.h>
72 #include <ModelAPI_AttributeSelectionList.h>
73 #include <ModelAPI_Tools.h>
74 #include <ModelAPI_ResultConstruction.h>
75 #include <ModelAPI_AttributeIntArray.h>
77 #include <GeomDataAPI_Point2D.h>
78 #include <GeomDataAPI_Point.h>
79 #include <GeomDataAPI_Dir.h>
81 #include <XGUI_ActiveControlMgr.h>
82 #include <XGUI_ActiveControlSelector.h>
83 #include <XGUI_ActionsMgr.h>
84 #include <XGUI_ContextMenuMgr.h>
85 #include <XGUI_CustomPrs.h>
86 #include <XGUI_DataModel.h>
87 #include <XGUI_Displayer.h>
88 #include <XGUI_ErrorMgr.h>
89 #include <XGUI_FacesPanelSelector.h>
90 #include <XGUI_ModuleConnector.h>
91 #include <XGUI_ObjectsBrowser.h>
92 #include <XGUI_OperationMgr.h>
93 #include <XGUI_PropertyPanel.h>
94 #include <XGUI_SelectionMgr.h>
95 #include <XGUI_Tools.h>
96 #include <XGUI_Workshop.h>
98 #include <SketchPlugin_ConstraintAngle.h>
99 #include <SketchPlugin_ConstraintLength.h>
100 #include <SketchPlugin_ConstraintDistance.h>
101 #include <SketchPlugin_ConstraintParallel.h>
102 #include <SketchPlugin_ConstraintPerpendicular.h>
103 #include <SketchPlugin_ConstraintRadius.h>
104 #include <SketchPlugin_Feature.h>
105 #include <SketchPlugin_Projection.h>
106 #include <SketchPlugin_Sketch.h>
108 #include <SketcherPrs_SymbolPrs.h>
109 #include <SketcherPrs_PositionMgr.h>
110 #include <SketcherPrs_Coincident.h>
111 #include <SketcherPrs_Tools.h>
113 #include <Events_Loop.h>
114 #include <Config_PropManager.h>
115 #include <Config_Keywords.h>
117 #include <AIS_Dimension.hxx>
118 #include <AIS_InteractiveObject.hxx>
119 #include <StdSelect_TypeOfFace.hxx>
120 #include <TopoDS_Vertex.hxx>
121 #include <TopoDS.hxx>
122 #include <TopoDS_Shape.hxx>
123 #include <BRep_Tool.hxx>
126 #include <QMouseEvent>
129 #include <QApplication>
130 #include <QMessageBox>
131 #include <QMainWindow>
135 #include <GeomAlgoAPI_FaceBuilder.h>
136 #include <GeomDataAPI_Dir.h>
138 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
144 /*!Create and return new instance of XGUI_Module*/
145 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
147 return new PartSet_Module(theWshop);
150 //******************************************************
151 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
152 : ModuleBase_IModule(theWshop),
154 myIsOperationIsLaunched(false)
156 new PartSet_IconFactory();
158 mySketchMgr = new PartSet_SketcherMgr(this);
159 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
161 myDataModel = new PartSet_DataModel();
163 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
164 XGUI_Workshop* aWorkshop = aConnector->workshop();
166 ModuleBase_IViewer* aViewer = theWshop->viewer();
167 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
168 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
169 connect(aViewer, SIGNAL(viewTransformed(int)),
170 SLOT(onViewTransformed(int)));
171 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
172 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
173 myMenuMgr = new PartSet_MenuMgr(this);
174 myCustomPrs = new PartSet_CustomPrs(theWshop);
176 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
178 Events_Loop* aLoop = Events_Loop::loop();
179 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
181 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
182 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
183 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
184 std::set<std::string> aCRGroupNames;
185 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
186 aCRFilter->setGroupNames(aCRGroupNames);
187 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
189 setDefaultConstraintShown();
191 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
192 "Reference shape wireframe color in operation", Config_Prop::Color,
193 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
194 Config_PropManager::registerProp("Visualization", "operation_result_color",
195 "Result shape wireframe color in operation", Config_Prop::Color,
196 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
197 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
198 "Multi selector item color in operation", Config_Prop::Color,
199 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
200 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
201 "Color of removed feature in operation", Config_Prop::Color,
202 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
203 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
204 "Color of sketch plane", Config_Prop::Color,
205 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
207 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
208 "Hidden faces transparency",
209 Config_Prop::DblSpin,
213 //******************************************************
214 PartSet_Module::~PartSet_Module()
216 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
217 mySelectionFilters.begin();
218 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
219 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
220 if (!aFilter.IsNull())
224 delete myOverconstraintListener;
227 //******************************************************
228 void PartSet_Module::storeSelection()
230 // cash is used only to restore selection, so it should be filled in storeSelection and
231 // after applying immediatelly cleared in restoreSelection
232 myCurrentSelection.clear();
233 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
236 //******************************************************
237 void PartSet_Module::restoreSelection()
239 // cash is used only to restore selection, so it should be filled in storeSelection and
240 // after applying immediatelly cleared in restoreSelection
241 sketchMgr()->restoreSelection(myCurrentSelection);
242 myCurrentSelection.clear();
245 //******************************************************
246 void PartSet_Module::registerValidators()
248 //Registering of validators
249 SessionPtr aMgr = ModelAPI_Session::get();
250 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
251 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
252 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
253 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
254 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
255 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
256 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
257 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
258 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
259 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
260 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
261 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
262 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
263 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
264 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
265 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
266 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
267 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
268 aFactory->registerValidator("PartSet_MultyTranslationSelection",
269 new PartSet_MultyTranslationSelection);
270 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
271 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
272 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
275 //******************************************************
276 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
277 const bool isToConnect)
279 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
282 //******************************************************
283 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
285 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
286 mySketchMgr->commitNestedSketch(theOperation);
288 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
289 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
290 overconstraintListener()->setActive(false);
292 /// Restart sketcher operations automatically
293 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
295 ModuleBase_OperationFeature* aFOperation =
296 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
297 if (aFOperation && !aFOperation->isEditOperation()) {
298 // the selection is cleared after commit the create operation
299 // in order to do not use the same selected objects in the restarted operation
300 // for common behaviour, the selection is cleared even if the operation is not restarted
301 getWorkshop()->selector()->clearSelection();
306 //******************************************************
307 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
309 /// Restart sketcher operations automatically
310 mySketchReentrantMgr->operationAborted(theOperation);
311 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
312 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
313 overconstraintListener()->setActive(false);
316 //******************************************************
317 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
319 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
322 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
323 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
325 ModuleBase_ModelWidget* aFilledWidget = 0;
326 bool aPostonedWidgetActivation = false;
328 FeaturePtr aFeature = aFOperation->feature();
329 /// Restart sketcher operations automatically
330 /// it is important to call method of sketch reentrant manager before filling of PP
331 /// because it fills some created feature attributes, these new values should be used
332 /// to fill the property panel
333 mySketchReentrantMgr->operationStarted(theOperation);
335 aWorkshop->fillPropertyPanel(aFOperation);
336 // filling the operation values by the current selection
337 // if the operation can be committed after the controls filling, the method perform should
338 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
339 bool isOperationCommitted = false;
340 if (!aFOperation->isEditOperation()) {
341 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
342 // if there is a greed attribute, automatic commit by preselection
343 // for this feature is prohibited
344 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
345 if (currentOperation() != aFOperation)
346 isOperationCommitted = true;
348 if (aGreedAttributeId.empty()) {
349 // a signal should be emitted before the next widget activation
350 // because, the activation of the next widget will give a focus to the widget.
351 // As a result the value of the widget is initialized.
352 // And commit may happens until the value is entered.
354 if (mySketchReentrantMgr->canBeCommittedByPreselection())
355 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
356 // activate the next obligatory widget
357 if (!isOperationCommitted)
358 aPropertyPanel->activateNextWidget(aFilledWidget);
361 else { // there is a greed widget
362 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
363 std::string aFirstAttributeId = aWidgets.front()->attributeID();
364 // activate next widget after greeded if it is the first widget in the panel
365 // else the first panel widget is already activated by operation start
366 if (aFirstAttributeId == aGreedAttributeId)
367 aPostonedWidgetActivation = true;
370 } if (!isOperationCommitted) {
371 aWorkshop->connectToPropertyPanel(true);
372 updateSketcherOnStart(aFOperation);
373 updatePresentationsOnStart(aFOperation);
375 // the objects of the current operation should be deactivated
376 QObjectPtrList anObjects;
377 anObjects.append(aFeature);
378 std::list<ResultPtr> aResults;
379 ModelAPI_Tools::allResults(aFeature, aResults);
380 std::list<ResultPtr>::const_iterator aIt;
381 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
382 anObjects.append(*aIt);
384 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
385 for (; anIt != aLast; anIt++)
386 aWorkshop->deactivateActiveObject(*anIt, false);
387 if (anObjects.size() > 0) {
388 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
389 aDisplayer->updateViewer();
391 /// state of command actions should be updated after displayed objects modification because
392 /// deactivation(for example) of objects may influence on selection in the viewer
393 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
394 workshop()->updateCommandStatus();
396 if (aPostonedWidgetActivation) {
397 // if the widget is an empty in the chain of activated widgets, the current operation
398 // is restarted. It should be performed after functionality of the operation starting
399 aPropertyPanel->activateNextWidget(aFilledWidget);
404 //******************************************************
405 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
407 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
408 mySketchMgr->startSketch(theOperation);
410 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
411 mySketchMgr->startNestedSketch(theOperation);
415 //******************************************************
416 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
418 ModuleBase_OperationFeature* aFOperation =
419 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
421 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
422 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
426 //******************************************************
427 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
429 ModuleBase_IModule::operationResumed(theOperation);
431 ModuleBase_OperationFeature* aFOperation =
432 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
434 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
435 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
439 //******************************************************
440 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
442 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
443 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
444 bool isModified = isModifiedArgs || isModifiedResults;
446 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
447 mySketchMgr->stopNestedSketch(theOperation);
449 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
450 setDefaultConstraintShown();
452 //VSV: Viewer is updated on feature update and redisplay
454 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
455 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
456 aDisplayer->updateViewer();
459 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
460 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
461 for (; anIt != aLast; anIt++) {
462 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
466 //******************************************************
467 ModuleBase_Operation* PartSet_Module::currentOperation() const
469 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
470 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
471 return anOpMgr->currentOperation();
474 //******************************************************
475 bool PartSet_Module::canUndo() const
477 bool aCanUndo = false;
478 SessionPtr aMgr = ModelAPI_Session::get();
479 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
480 aCanUndo = !aMgr->isOperation();
481 if (!aCanUndo) // check the enable state additionally by sketch manager
482 aCanUndo = aMgr->canUndo();
487 //******************************************************
488 bool PartSet_Module::canRedo() const
490 bool aCanRedo = false;
491 SessionPtr aMgr = ModelAPI_Session::get();
492 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
493 aCanRedo = !aMgr->isOperation();
494 if (!aCanRedo) // check the enable state additionally by sketch manager
495 aCanRedo = aMgr->canRedo();
500 //******************************************************
501 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
504 if (theActionId == "MOVE_CMD") {
505 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
507 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
508 // part features can not be moved in the history.
509 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
516 //******************************************************
517 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
519 // the sketch manager put the restriction to the objects erase
520 return mySketchMgr->canEraseObject(theObject);
523 //******************************************************
524 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
526 // the sketch manager put the restriction to the objects display
527 return mySketchMgr->canDisplayObject(theObject);
530 //******************************************************
531 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
532 const QString& theStartedOperationKind)
534 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
537 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
540 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
542 mySketchMgr->processHiddenObject(theObjects);
545 //******************************************************
546 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
548 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
550 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
551 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
552 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
553 if (isSketchOp || isNestedOp) {
554 // in active sketch operation it is possible to activate operation object in selection
555 // in the edit operation, e.g. points of the line can be moved when the line is edited
556 ModuleBase_OperationFeature* aFOperation =
557 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
558 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
563 //******************************************************
564 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
566 QMap<int, QAction*>& theMenuActions) const
568 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
571 //******************************************************
572 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
574 myMenuMgr->updateViewerMenu(theStdActions);
577 //******************************************************
578 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
580 bool isEnabledFixed = false;
581 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
582 mySketchReentrantMgr->isInternalEditActive())
583 isEnabledFixed = true;
584 return isEnabledFixed;
587 //******************************************************
588 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
590 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
591 if (anError.isEmpty())
592 anError = sketchMgr()->getFeatureError(theFeature);
597 //******************************************************
598 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
599 QStringList& theIds) const
601 myMenuMgr->grantedOperationIds(theOperation, theIds);
603 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
604 XGUI_Workshop* aWorkshop = getWorkshop();
605 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
609 //******************************************************
610 void PartSet_Module::activeSelectionModes(QIntList& theModes)
612 if (mySketchMgr->activeSketch().get())
613 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
615 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
618 //******************************************************
619 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
621 customSubShapesSelectionModes(theModes);
622 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
623 //myWorkshop->module()->activeSelectionModes(theModes);
626 //******************************************************
627 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
628 SelectMgr_ListOfFilter& theSelectionFilters)
630 bool isSketchActive = mySketchMgr->activeSketch().get();
632 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
633 mySelectionFilters.begin();
634 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
635 int aFilterType = aFiltersIt->first;
636 // do not add not participating filters in given parameters
637 if (!theFilterTypes.contains(aFilterType))
640 // using sketch filters only if sketch operation is active
641 if (!isSketchActive &&
642 mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
645 // using filtering of construction results only from faces panel
646 if (aFilterType == SF_ResultGroupNameFilter)
649 theSelectionFilters.Append(aFiltersIt->second);
653 //******************************************************
654 QIntList PartSet_Module::selectionFilters()
658 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
659 mySelectionFilters.begin();
660 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
661 aTypes.append(aFiltersIt->first);
666 //******************************************************
667 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
668 const Handle(SelectMgr_Filter)& theFilter)
670 mySelectionFilters[theFilterType] = theFilter;
673 //******************************************************
674 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
676 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
678 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
679 return mySelectionFilters[aType];
681 return Handle(SelectMgr_Filter)();
684 //******************************************************
685 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
687 if (theModes.contains(TopAbs_FACE))
688 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
689 if (theModes.contains(TopAbs_WIRE))
690 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
692 if (mySketchMgr->activeSketch().get())
693 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
696 //******************************************************
697 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
698 ObjectPtr& theObject, AttributePtr& theAttribute)
700 ObjectPtr anObject = theSelected->object();
701 GeomShapePtr aShape = theSelected->shape();
703 theAttribute = findAttribute(anObject, aShape);
704 // TODO: try to create result if object is an external object
705 theObject = anObject;
708 //******************************************************
709 bool PartSet_Module::isMouseOverWindow()
711 return mySketchMgr->isMouseOverWindow();
714 //******************************************************
715 bool PartSet_Module::isSketchNeutralPointActivated() const
717 bool isNeutralPoint = true;
718 if (sketchReentranceMgr()->isInternalEditActive())
719 isNeutralPoint = false;
720 if (myIsOperationIsLaunched)
721 isNeutralPoint = false;
723 return isNeutralPoint;
726 //******************************************************
727 void PartSet_Module::closeDocument()
729 myActivePartIndex = QModelIndex();
730 SketcherPrs_PositionMgr::get()->clearAll();
733 //******************************************************
734 void PartSet_Module::clearViewer()
736 myCustomPrs->clearPrs();
738 XGUI_Workshop* aWorkshop = getWorkshop();
739 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
740 aDisplayer->deactivateSelectionFilters(false);
743 //******************************************************
744 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
746 ModuleBase_OperationFeature* aFOperation =
747 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
751 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
752 // we have to manually activate the sketch label in edit mode
753 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
754 aPanel->activateWidget(aPanel->modelWidgets().first());
757 //******************************************************
758 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
759 QList<ModuleBase_ModelWidget*>& theWidgets) const
761 bool aProcessed = false;
763 ModuleBase_OperationFeature* aFOperation =
764 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
765 XGUI_Workshop* aWorkshop = getWorkshop();
766 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
767 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
768 ModuleBase_ISelection* aSelection = workshop()->selection();
769 // click on a point in sketch leads here with the point is highlighted, not yet selected
770 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
771 if (aPreselection.size() == 1) {
772 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
773 ObjectPtr anObject = aSelectedPrs->object();
775 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
776 FeaturePtr anOpFeature = aFOperation->feature();
777 GeomShapePtr aShape = aSelectedPrs->shape();
778 // click on the digit of dimension constrain comes here
779 // with an empty shape, so we need the check
780 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
781 // if feature has only one result and shape of result is equal to selected shape
782 // this attribute is not processed. It is a case of Sketch Point.
783 if (aFeature->results().size() == 1) {
784 ResultPtr aResult = aFeature->results().front();
785 if (aResult.get() && aResult->shape()->isEqual(aShape))
788 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
789 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
790 mySketchMgr->activeSketch());
791 if (anAttribute.get()) {
792 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
793 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
795 const std::string anAttributeId = anAttribute->id();
796 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
798 theWidgets = aFactory.getModelWidgets();
799 // it is possible that the point does not present in XML definition,
800 // in this case, we assume that it is not processed by this module
801 // e.g. "Intersection point" feature
802 aProcessed = !theWidgets.isEmpty();
810 //******************************************************
811 void PartSet_Module::onSelectionChanged()
813 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
817 bool isSketcherOp = false;
818 // An edit operation is enable only if the current opeation is the sketch operation
819 if (mySketchMgr->activeSketch()) {
820 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
821 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
824 // Editing of constraints can be done on selection
825 ModuleBase_ISelection* aSelect = myWorkshop->selection();
826 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
827 if (aSelected.size() == 1) {
828 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
829 ObjectPtr aObject = aPrs->object();
830 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
832 std::string aId = aFeature->getKind();
833 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
834 (aId == SketchPlugin_ConstraintLength::ID()) ||
835 (aId == SketchPlugin_ConstraintDistance::ID()) ||
836 (aId == SketchPlugin_ConstraintAngle::ID())) {
837 editFeature(aFeature);
844 //******************************************************
845 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
847 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
848 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
849 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
852 //******************************************************
853 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
855 Config_WidgetAPI* theWidgetApi)
857 ModuleBase_IWorkshop* aWorkshop = workshop();
858 XGUI_Workshop* aXUIWorkshop = getWorkshop();
859 ModuleBase_ModelWidget* aWgt = NULL;
860 if (theType == "sketch-start-label") {
861 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
862 theWidgetApi, myHasConstraintShown);
863 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
864 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
865 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
866 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
868 } else if (theType == "sketch-2dpoint_selector") {
869 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
871 aPointWgt->setSketch(mySketchMgr->activeSketch());
872 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
874 }else if (theType == "sketch-2dpoint_flyout_selector") {
875 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
877 aPointWgt->setSketch(mySketchMgr->activeSketch());
878 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
880 } else if (theType == "sketch_shape_selector") {
881 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
882 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
883 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
884 aWgt = aShapeSelectorWgt;
885 } else if (theType == "sketch_multi_selector") {
886 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
887 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
888 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
889 aWgt = aShapeSelectorWgt;
891 else if (theType == "sketch_feature_point_selector") {
892 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
893 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
894 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
895 aWgt = aPointSelectorWgt;
897 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
898 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
899 } else if (theType == "export_file_selector") {
900 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
901 } else if (theType == "sketch_launcher") {
902 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
903 } else if (theType == "module_choice") {
904 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
905 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
906 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
911 //******************************************************
912 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
914 ModuleBase_ModelWidget* anActiveWidget = 0;
916 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
918 return anActiveWidget;
920 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
922 return anActiveWidget;
924 return aPanel->activeWidget(true);
927 //******************************************************
928 bool PartSet_Module::deleteObjects()
930 bool isProcessed = false;
932 XGUI_Workshop* aWorkshop = getWorkshop();
933 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
935 //SessionPtr aMgr = ModelAPI_Session::get();
936 // 1. check whether the delete should be processed in the module
937 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
938 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
939 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
940 if (isSketchOp || isNestedOp) {
942 // 2. find selected presentations
943 // selected objects should be collected before the current operation abort because
944 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
945 ModuleBase_ISelection* aSel = workshop()->selection();
946 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
947 // if there are no selected objects in the viewer, that means that the selection in another
948 // place cased this method. It is necessary to return the false value to understande in above
949 // method that delete is not processed
950 if (aSelectedObj.count() == 0)
953 // avoid delete of the objects, which are not belong to the current sketch
954 // in order to do not delete results of other sketches
955 QObjectPtrList aSketchObjects;
956 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
957 for ( ; anIt != aLast; anIt++) {
958 ObjectPtr anObject = *anIt;
959 if (mySketchMgr->isObjectOfSketch(anObject)) {
960 // sketch feature should be used in this list because workshop deletes features only
961 // results are skipped
962 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
963 aSketchObjects.append(aSketchFeature);
966 // if the selection contains only local selected presentations from other sketches,
967 // the Delete operation should not be done at all
968 if (aSketchObjects.size() == 0)
971 // 3. start operation
972 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
973 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
975 // the active nested sketch operation should be aborted unconditionally
976 // the Delete action should be additionally granted for the Sketch operation
977 // in order to do not abort/commit it
979 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
980 return true; // the objects are processed but can not be deleted
982 anOpMgr->startOperation(anOpAction);
984 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
985 // the problem is in AIS Dimensions recompute
986 // if a line and the dim are removed, line is the first
987 // it causes the AIS recompute, where the base line is null,
988 // the result is empty AIS in the viewer
989 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
991 // 4. delete features
992 // sketch feature should be skipped, only sub-features can be removed
993 // when sketch operation is active
994 aWorkshop->deleteFeatures(aSketchObjects);
996 anOpMgr->commitOperation();
1001 //******************************************************
1002 void PartSet_Module::editFeature(FeaturePtr theFeature)
1004 storeConstraintsState(theFeature->getKind());
1005 ModuleBase_IModule::editFeature(theFeature);
1008 //******************************************************
1009 bool PartSet_Module::canCommitOperation() const
1014 //******************************************************
1015 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1017 myIsOperationIsLaunched = true;
1018 storeConstraintsState(theCmdId.toStdString());
1019 updateConstraintsState(theCmdId.toStdString());
1021 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1023 myIsOperationIsLaunched = false;
1026 //******************************************************
1027 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1029 if (myWorkshop->currentOperation() &&
1030 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1031 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1032 mySketchMgr->showConstraintStates();
1033 myHasConstraintShown = aShownStates;
1037 //******************************************************
1038 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1040 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1041 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1042 // Show constraints if a constraint was anOperation
1043 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1044 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1045 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1046 myHasConstraintShown[PartSet_Tools::Expressions]);
1050 //******************************************************
1051 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1053 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1054 if (!anAIS.IsNull()) {
1055 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1056 if (aFeature.get()) {
1057 bool aToUseZLayer = false;
1058 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1059 aToUseZLayer = true;
1061 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1062 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1065 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1066 aCtx->SetZLayer(anAIS, myVisualLayerId);
1072 //******************************************************
1073 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1076 // it should be recomputed in order to disappear in the viewer if the corresponded object
1078 //if (myCustomPrs->isActive())
1079 // myCustomPrs->redisplay(theObject, false);
1082 //******************************************************
1083 void PartSet_Module::onViewTransformed(int theTrsfType)
1085 // Set length of arrows constant in pixel size
1086 // if the operation is panning or rotate or panglobal then do nothing
1087 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1089 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1090 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1091 if (aContext.IsNull())
1094 //Handle(V3d_View) aView = aViewer->activeView();
1096 XGUI_Workshop* aWorkshop = getWorkshop();
1097 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1098 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1099 Handle(V3d_View) aView;
1101 for (aV3dViewer->InitDefinedViews();
1102 aV3dViewer->MoreDefinedViews();
1103 aV3dViewer->NextDefinedViews()) {
1104 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1105 double aS = aV->Scale();
1114 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1115 if (aCurrentOperation &&
1116 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1117 sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
1119 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1121 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1122 SketcherPrs_Tools::setArrowSize(aLen);
1123 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1124 aViewer->SetScale(aViewer->activeView(), aCurScale);
1125 bool isModified = false;
1126 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1127 foreach (AISObjectPtr aAIS, aPrsList) {
1128 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1130 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1131 if (!aDim.IsNull()) {
1132 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1133 aContext->Redisplay(aDim, false);
1138 aDisplayer->updateViewer();
1142 //******************************************************
1143 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1145 return myCustomPrs->isActive(theFlag);
1148 //******************************************************
1149 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1150 const ModuleBase_CustomizeFlag& theFlag,
1151 const bool theUpdateViewer)
1153 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1156 //******************************************************
1157 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1158 const bool theUpdateViewer)
1160 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1163 //******************************************************
1164 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1165 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1167 bool aCustomized = false;
1169 XGUI_Workshop* aWorkshop = getWorkshop();
1170 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1171 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1175 if (!theResult.get()) {
1176 std::vector<int> aColor;
1177 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1178 if (!aColor.empty()) {
1179 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1182 // customize dimentional constrains
1183 sketchMgr()->customizePresentation(anObject);
1188 //******************************************************
1189 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1190 AISObjectPtr thePrs,
1191 GeomCustomPrsPtr theCustomPrs)
1193 bool aCustomized = false;
1195 XGUI_Workshop* aWorkshop = getWorkshop();
1196 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1197 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1201 std::vector<int> aColor;
1202 bool aUseCustomColor = true;
1203 if (aUseCustomColor)
1204 myOverconstraintListener->getCustomColor(anObject, aColor);
1205 // customize sketch symbol presentation
1206 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1207 if (!anAISIO.IsNull()) {
1208 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1209 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1210 if (!aPrs.IsNull()) {
1211 aPrs->SetCustomColor(aColor);
1214 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1215 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1216 if (!aPrs.IsNull()) {
1217 aPrs->SetCustomColor(aColor);
1222 // customize sketch dimension constraint presentation
1224 if (!aColor.empty()) { // otherwise presentation has the default color
1225 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1231 //******************************************************
1232 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1233 const bool theUpdateViewer)
1235 bool isRedisplayed = false;
1236 if (myCustomPrs->isActive(theFlag))
1237 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1239 return isRedisplayed;
1242 //******************************************************
1243 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1245 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1247 QLabel* aLabel = aOB->activeDocLabel();
1248 aLabel->installEventFilter(myMenuMgr);
1249 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1250 SLOT(onActiveDocPopup(const QPoint&)));
1251 aOB->treeView()->setExpandsOnDoubleClick(false);
1252 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1253 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1255 Events_Loop* aLoop = Events_Loop::loop();
1256 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1260 //******************************************************
1261 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1263 SessionPtr aMgr = ModelAPI_Session::get();
1264 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1266 XGUI_Workshop* aWorkshop = getWorkshop();
1267 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1269 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1272 aMenu.addAction(aActivatePartAction);
1273 aMenu.exec(aHeader->mapToGlobal(thePnt));
1276 //******************************************************
1277 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1279 return mySketchMgr->createPresentation(theResult);
1282 //******************************************************
1283 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1286 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1288 /// If last line finished on vertex the lines creation sequence has to be break
1289 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1291 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1292 // if there is an active widget, find the presented object in it
1293 if (!anActiveWidget)
1294 anActiveWidget = aPanel->preselectionWidget();
1296 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1298 if (aWidgetValidated)
1299 anObject = aWidgetValidated->findPresentedObject(theAIS);
1305 //******************************************************
1306 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1308 bool aCanBeShaged = true;
1310 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1312 aCanBeShaged = false;
1314 return aCanBeShaged;
1317 //******************************************************
1318 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1320 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1321 int aSelected = aObjects.size();
1322 SessionPtr aMgr = ModelAPI_Session::get();
1323 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1325 bool hasResult = false;
1326 bool hasFeature = false;
1327 bool hasParameter = false;
1328 bool hasCompositeOwner = false;
1329 bool hasResultInHistory = false;
1330 bool hasFolder = false;
1331 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1332 hasCompositeOwner, hasResultInHistory, hasFolder);
1334 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1335 if (aSelected == 1) {
1336 ObjectPtr aObject = aObjects.first();
1338 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1339 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1340 bool isPart = aPart.get() ||
1341 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1343 DocumentPtr aPartDoc;
1345 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1347 if (aPart.get()) // this may be null is Part feature is disabled
1348 aPartDoc = aPart->partDoc();
1350 theMenu->addAction(aActivatePartAction);
1351 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1353 } else if (aObject->document() == aMgr->activeDocument()) {
1354 if (hasParameter || hasFeature) {
1355 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1356 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1357 if (aCurrentOp && aFeature.get()) {
1358 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1359 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1366 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1367 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1368 theMenu->addSeparator();
1371 bool aNotDeactivate = (aCurrentOp == 0);
1372 if (!aNotDeactivate) {
1373 aActivatePartAction->setEnabled(false);
1377 //******************************************************
1378 #define EXPAND_PARENT(OBJ) \
1379 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1380 if (aObjIndex.isValid()) { \
1381 QModelIndex aParent = aObjIndex.parent(); \
1382 int aCount = aDataModel->rowCount(aParent); \
1384 aTreeView->setExpanded(aParent, true); \
1387 //******************************************************
1388 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1390 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1391 // Do not change activation of parts if an operation active
1392 static QStringList aAllowActivationList;
1393 if (aAllowActivationList.isEmpty())
1394 aAllowActivationList <<
1395 QString(PartSetPlugin_Part::ID().c_str()) <<
1396 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1397 QString(PartSetPlugin_Remove::ID().c_str());
1398 if (myWorkshop->currentOperation() &&
1399 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1401 XGUI_Workshop* aWorkshop = getWorkshop();
1402 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1403 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1404 QPalette aPalet = aLabel->palette();
1406 SessionPtr aMgr = ModelAPI_Session::get();
1407 DocumentPtr aActiveDoc = aMgr->activeDocument();
1408 // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
1409 //if (myActivePartIndex.isValid())
1410 // aTreeView->setExpanded(myActivePartIndex, false);
1412 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1413 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1414 bool needUpdate = false;
1415 if (myActivePartIndex.isValid()) {
1416 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1418 aTreeView->setExpanded(myActivePartIndex, true);
1421 aLabel->setPalette(aPalet);
1422 aWorkshop->updateCommandStatus();
1424 // Update displayed objects in order to update active color
1425 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1426 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1428 foreach(ObjectPtr aObj, aObjects) {
1429 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1430 aObj->isDisabled() || (!aObj->isDisplayed());
1432 aDisplayer->redisplay(aObj, false);
1434 aDisplayer->updateViewer();
1435 // Update tree items if they are expanded
1437 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1439 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1440 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1441 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1442 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1444 ObjectPtr aConstrObj;
1445 ObjectPtr aResultObj;
1446 std::set<ObjectPtr>::const_iterator aIt;
1447 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1448 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1449 ObjectPtr aObject = (*aIt);
1450 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1451 && (aObject->document() != aRootDoc))
1452 aResultObj = aObject;
1453 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1454 && (aObject->document() != aRootDoc))
1455 aConstrObj = aObject;
1456 if (aResultObj.get() && aConstrObj.get())
1460 if (aResultObj.get() || aConstrObj.get()) {
1461 XGUI_Workshop* aWorkshop = getWorkshop();
1462 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1463 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1465 if (aResultObj.get()) {
1466 EXPAND_PARENT(aResultObj)
1468 if (aConstrObj.get()) {
1469 EXPAND_PARENT(aConstrObj)
1475 //******************************************************
1476 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1478 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1480 SessionPtr aMgr = ModelAPI_Session::get();
1481 if (!theIndex.isValid()) {
1482 // It seems that this code is obsolete
1483 //aMgr->setActiveDocument(aMgr->moduleDocument());
1486 if (theIndex.column() != 1) // Use only first column
1489 XGUI_Workshop* aWorkshop = getWorkshop();
1490 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1491 // De not use non editable Indexes
1492 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1494 ObjectPtr aObj = aDataModel->object(theIndex);
1496 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1497 if (!aPart.get()) { // Probably this is Feature
1498 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1499 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1500 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1503 if (aPart.get()) { // if this is a part
1504 if (aPart->partDoc() == aMgr->activeDocument()) {
1505 myMenuMgr->activatePartSet();
1507 myMenuMgr->activatePart(aPart);
1512 //******************************************************
1513 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1515 // z layer is created for all started operations in order to visualize operation AIS presentation
1517 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1518 if (aContext.IsNull())
1521 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1522 if (myVisualLayerId == 0) {
1523 if (myVisualLayerId == 0)
1524 aViewer->AddZLayer(myVisualLayerId);
1526 TColStd_SequenceOfInteger aZList;
1527 aViewer->GetAllZLayers(aZList);
1528 bool aFound = false;
1529 for (int i = 1; i <= aZList.Length(); i++) {
1530 if (aZList(i) == myVisualLayerId) {
1536 aViewer->AddZLayer(myVisualLayerId);
1538 // if there is an active operation with validated widget,
1539 // the filters of this widget should be activated in the created view
1540 myWorkshop->selectionActivate()->updateSelectionFilters();
1541 myWorkshop->selectionActivate()->updateSelectionModes();
1544 //******************************************************
1545 void PartSet_Module::widgetStateChanged(int thePreviousState)
1547 mySketchMgr->widgetStateChanged(thePreviousState);
1550 //******************************************************
1551 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1553 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1556 //******************************************************
1557 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1559 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1560 mySketchMgr->stopSketch(theOperation);
1564 //******************************************************
1565 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1567 GeomShapePtr aGeomShape;
1569 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1570 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1571 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1576 //******************************************************
1577 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1578 const GeomShapePtr& theGeomShape)
1580 AttributePtr anAttribute;
1581 GeomShapePtr aGeomShape = theGeomShape;
1582 if (!aGeomShape.get()) {
1583 // processing shape of result, e.g. sketch circle center is selected, this is a result
1584 // the geom shape is empty, the shape of result should be used
1585 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1586 if (aResult.get()) {
1587 aGeomShape = aResult->shape();
1591 if (aGeomShape.get()) {
1592 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1593 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1594 mySketchMgr->activeSketch());
1599 //******************************************************
1600 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1602 return sketchReentranceMgr()->reentrantMessage();
1605 //******************************************************
1606 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1608 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1611 //******************************************************
1612 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1615 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1619 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1620 if (!aChoiceTitle.isEmpty()) {
1621 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1624 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1626 aPanel->setWindowTitle(aChoiceTitle);
1630 //******************************************************
1631 XGUI_Workshop* PartSet_Module::getWorkshop() const
1633 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1634 return aConnector->workshop();
1637 void PartSet_Module::setDefaultConstraintShown()
1639 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1640 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1641 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1644 //******************************************************
1645 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1647 return myDataModel->root();