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_TreeNodes.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),
155 myIsOperationIsLaunched(false)
157 new PartSet_IconFactory();
159 mySketchMgr = new PartSet_SketcherMgr(this);
160 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
162 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
163 XGUI_Workshop* aWorkshop = aConnector->workshop();
165 ModuleBase_IViewer* aViewer = theWshop->viewer();
166 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
167 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
168 connect(aViewer, SIGNAL(viewTransformed(int)),
169 SLOT(onViewTransformed(int)));
170 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
171 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
172 myMenuMgr = new PartSet_MenuMgr(this);
173 myCustomPrs = new PartSet_CustomPrs(theWshop);
175 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
177 Events_Loop* aLoop = Events_Loop::loop();
178 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
180 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
181 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
182 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
183 std::set<std::string> aCRGroupNames;
184 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
185 aCRFilter->setGroupNames(aCRGroupNames);
186 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
188 setDefaultConstraintShown();
190 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
191 "Reference shape wireframe color in operation", Config_Prop::Color,
192 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
193 Config_PropManager::registerProp("Visualization", "operation_result_color",
194 "Result shape wireframe color in operation", Config_Prop::Color,
195 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
196 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
197 "Multi selector item color in operation", Config_Prop::Color,
198 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
199 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
200 "Color of removed feature in operation", Config_Prop::Color,
201 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
202 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
203 "Color of sketch plane", Config_Prop::Color,
204 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
206 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
207 "Hidden faces transparency",
208 Config_Prop::DblSpin,
212 //******************************************************
213 PartSet_Module::~PartSet_Module()
215 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
216 mySelectionFilters.begin();
217 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
218 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
219 if (!aFilter.IsNull())
223 delete myOverconstraintListener;
227 //******************************************************
228 void PartSet_Module::createFeatures()
230 ModuleBase_IModule::createFeatures();
231 myRoot = new PartSet_RootNode();
232 myRoot->setWorkshop(workshop());
236 //******************************************************
237 void PartSet_Module::storeSelection()
239 // cash is used only to restore selection, so it should be filled in storeSelection and
240 // after applying immediatelly cleared in restoreSelection
241 myCurrentSelection.clear();
242 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
245 //******************************************************
246 void PartSet_Module::restoreSelection()
248 // cash is used only to restore selection, so it should be filled in storeSelection and
249 // after applying immediatelly cleared in restoreSelection
250 sketchMgr()->restoreSelection(myCurrentSelection);
251 myCurrentSelection.clear();
254 //******************************************************
255 void PartSet_Module::registerValidators()
257 //Registering of validators
258 SessionPtr aMgr = ModelAPI_Session::get();
259 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
260 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
261 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
262 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
263 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
264 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
265 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
266 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
267 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
268 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
269 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
270 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
271 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
272 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
273 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
274 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
275 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
276 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
277 aFactory->registerValidator("PartSet_MultyTranslationSelection",
278 new PartSet_MultyTranslationSelection);
279 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
280 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
281 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
284 //******************************************************
285 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
286 const bool isToConnect)
288 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
291 //******************************************************
292 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
294 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
295 mySketchMgr->commitNestedSketch(theOperation);
297 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
298 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
299 overconstraintListener()->setActive(false);
301 /// Restart sketcher operations automatically
302 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
304 ModuleBase_OperationFeature* aFOperation =
305 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
306 if (aFOperation && !aFOperation->isEditOperation()) {
307 // the selection is cleared after commit the create operation
308 // in order to do not use the same selected objects in the restarted operation
309 // for common behaviour, the selection is cleared even if the operation is not restarted
310 getWorkshop()->selector()->clearSelection();
315 //******************************************************
316 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
318 /// Restart sketcher operations automatically
319 mySketchReentrantMgr->operationAborted(theOperation);
320 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
321 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
322 overconstraintListener()->setActive(false);
325 //******************************************************
326 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
328 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
331 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
332 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
334 ModuleBase_ModelWidget* aFilledWidget = 0;
335 bool aPostonedWidgetActivation = false;
337 FeaturePtr aFeature = aFOperation->feature();
338 /// Restart sketcher operations automatically
339 /// it is important to call method of sketch reentrant manager before filling of PP
340 /// because it fills some created feature attributes, these new values should be used
341 /// to fill the property panel
342 mySketchReentrantMgr->operationStarted(theOperation);
344 aWorkshop->fillPropertyPanel(aFOperation);
345 // filling the operation values by the current selection
346 // if the operation can be committed after the controls filling, the method perform should
347 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
348 bool isOperationCommitted = false;
349 if (!aFOperation->isEditOperation()) {
350 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
351 // if there is a greed attribute, automatic commit by preselection
352 // for this feature is prohibited
353 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
354 if (currentOperation() != aFOperation)
355 isOperationCommitted = true;
357 if (aGreedAttributeId.empty()) {
358 // a signal should be emitted before the next widget activation
359 // because, the activation of the next widget will give a focus to the widget.
360 // As a result the value of the widget is initialized.
361 // And commit may happens until the value is entered.
363 if (mySketchReentrantMgr->canBeCommittedByPreselection())
364 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
365 // activate the next obligatory widget
366 if (!isOperationCommitted)
367 aPropertyPanel->activateNextWidget(aFilledWidget);
370 else { // there is a greed widget
371 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
372 std::string aFirstAttributeId = aWidgets.front()->attributeID();
373 // activate next widget after greeded if it is the first widget in the panel
374 // else the first panel widget is already activated by operation start
375 if (aFirstAttributeId == aGreedAttributeId)
376 aPostonedWidgetActivation = true;
379 } if (!isOperationCommitted) {
380 aWorkshop->connectToPropertyPanel(true);
381 updateSketcherOnStart(aFOperation);
382 updatePresentationsOnStart(aFOperation);
384 // the objects of the current operation should be deactivated
385 QObjectPtrList anObjects;
386 anObjects.append(aFeature);
387 std::list<ResultPtr> aResults;
388 ModelAPI_Tools::allResults(aFeature, aResults);
389 std::list<ResultPtr>::const_iterator aIt;
390 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
391 anObjects.append(*aIt);
393 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
394 for (; anIt != aLast; anIt++)
395 aWorkshop->deactivateActiveObject(*anIt, false);
396 if (anObjects.size() > 0) {
397 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
398 aDisplayer->updateViewer();
400 /// state of command actions should be updated after displayed objects modification because
401 /// deactivation(for example) of objects may influence on selection in the viewer
402 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
403 workshop()->updateCommandStatus();
405 if (aPostonedWidgetActivation) {
406 // if the widget is an empty in the chain of activated widgets, the current operation
407 // is restarted. It should be performed after functionality of the operation starting
408 aPropertyPanel->activateNextWidget(aFilledWidget);
413 //******************************************************
414 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
416 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
417 mySketchMgr->startSketch(theOperation);
419 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
420 mySketchMgr->startNestedSketch(theOperation);
424 //******************************************************
425 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
427 ModuleBase_OperationFeature* aFOperation =
428 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
430 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
431 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
435 //******************************************************
436 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
438 ModuleBase_IModule::operationResumed(theOperation);
440 ModuleBase_OperationFeature* aFOperation =
441 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
443 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
444 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
448 //******************************************************
449 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
451 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
452 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
453 bool isModified = isModifiedArgs || isModifiedResults;
455 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
456 mySketchMgr->stopNestedSketch(theOperation);
458 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
459 setDefaultConstraintShown();
461 //VSV: Viewer is updated on feature update and redisplay
463 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
464 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
465 aDisplayer->updateViewer();
468 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
469 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
470 for (; anIt != aLast; anIt++) {
471 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
475 //******************************************************
476 ModuleBase_Operation* PartSet_Module::currentOperation() const
478 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
479 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
480 return anOpMgr->currentOperation();
483 //******************************************************
484 bool PartSet_Module::canUndo() const
486 bool aCanUndo = false;
487 SessionPtr aMgr = ModelAPI_Session::get();
488 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
489 aCanUndo = !aMgr->isOperation();
490 if (!aCanUndo) // check the enable state additionally by sketch manager
491 aCanUndo = aMgr->canUndo();
496 //******************************************************
497 bool PartSet_Module::canRedo() const
499 bool aCanRedo = false;
500 SessionPtr aMgr = ModelAPI_Session::get();
501 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
502 aCanRedo = !aMgr->isOperation();
503 if (!aCanRedo) // check the enable state additionally by sketch manager
504 aCanRedo = aMgr->canRedo();
509 //******************************************************
510 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
513 if (theActionId == "MOVE_CMD") {
514 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
516 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
517 // part features can not be moved in the history.
518 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
525 //******************************************************
526 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
528 // the sketch manager put the restriction to the objects erase
529 return mySketchMgr->canEraseObject(theObject);
532 //******************************************************
533 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
535 // the sketch manager put the restriction to the objects display
536 return mySketchMgr->canDisplayObject(theObject);
539 //******************************************************
540 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
541 const QString& theStartedOperationKind)
543 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
546 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
549 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
551 mySketchMgr->processHiddenObject(theObjects);
554 //******************************************************
555 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
557 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
559 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
560 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
561 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
562 if (isSketchOp || isNestedOp) {
563 // in active sketch operation it is possible to activate operation object in selection
564 // in the edit operation, e.g. points of the line can be moved when the line is edited
565 ModuleBase_OperationFeature* aFOperation =
566 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
567 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
572 //******************************************************
573 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
575 QMap<int, QAction*>& theMenuActions) const
577 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
580 //******************************************************
581 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
583 myMenuMgr->updateViewerMenu(theStdActions);
586 //******************************************************
587 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
589 bool isEnabledFixed = false;
590 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
591 mySketchReentrantMgr->isInternalEditActive())
592 isEnabledFixed = true;
593 return isEnabledFixed;
596 //******************************************************
597 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
599 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
600 if (anError.isEmpty())
601 anError = sketchMgr()->getFeatureError(theFeature);
606 //******************************************************
607 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
608 QStringList& theIds) const
610 myMenuMgr->grantedOperationIds(theOperation, theIds);
612 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
613 XGUI_Workshop* aWorkshop = getWorkshop();
614 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
618 //******************************************************
619 void PartSet_Module::activeSelectionModes(QIntList& theModes)
621 if (mySketchMgr->activeSketch().get())
622 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
624 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
627 //******************************************************
628 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
630 customSubShapesSelectionModes(theModes);
631 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
632 //myWorkshop->module()->activeSelectionModes(theModes);
635 //******************************************************
636 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
637 SelectMgr_ListOfFilter& theSelectionFilters)
639 bool isSketchActive = mySketchMgr->activeSketch().get();
641 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
642 mySelectionFilters.begin();
643 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
644 int aFilterType = aFiltersIt->first;
645 // do not add not participating filters in given parameters
646 if (!theFilterTypes.contains(aFilterType))
649 // using sketch filters only if sketch operation is active
650 if (!isSketchActive &&
651 mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
654 // using filtering of construction results only from faces panel
655 if (aFilterType == SF_ResultGroupNameFilter)
658 theSelectionFilters.Append(aFiltersIt->second);
662 //******************************************************
663 QIntList PartSet_Module::selectionFilters()
667 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
668 mySelectionFilters.begin();
669 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
670 aTypes.append(aFiltersIt->first);
675 //******************************************************
676 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
677 const Handle(SelectMgr_Filter)& theFilter)
679 mySelectionFilters[theFilterType] = theFilter;
682 //******************************************************
683 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
685 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
687 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
688 return mySelectionFilters[aType];
690 return Handle(SelectMgr_Filter)();
693 //******************************************************
694 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
696 if (theModes.contains(TopAbs_FACE))
697 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
698 if (theModes.contains(TopAbs_WIRE))
699 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
701 if (mySketchMgr->activeSketch().get())
702 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
705 //******************************************************
706 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
707 ObjectPtr& theObject, AttributePtr& theAttribute)
709 ObjectPtr anObject = theSelected->object();
710 GeomShapePtr aShape = theSelected->shape();
712 theAttribute = findAttribute(anObject, aShape);
713 // TODO: try to create result if object is an external object
714 theObject = anObject;
717 //******************************************************
718 bool PartSet_Module::isMouseOverWindow()
720 return mySketchMgr->isMouseOverWindow();
723 //******************************************************
724 bool PartSet_Module::isSketchNeutralPointActivated() const
726 bool isNeutralPoint = true;
727 if (sketchReentranceMgr()->isInternalEditActive())
728 isNeutralPoint = false;
729 if (myIsOperationIsLaunched)
730 isNeutralPoint = false;
732 return isNeutralPoint;
735 //******************************************************
736 void PartSet_Module::closeDocument()
738 myActivePartIndex = QModelIndex();
739 SketcherPrs_PositionMgr::get()->clearAll();
742 //******************************************************
743 void PartSet_Module::clearViewer()
745 myCustomPrs->clearPrs();
747 XGUI_Workshop* aWorkshop = getWorkshop();
748 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
749 aDisplayer->deactivateSelectionFilters(false);
752 //******************************************************
753 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
755 ModuleBase_OperationFeature* aFOperation =
756 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
760 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
761 // we have to manually activate the sketch label in edit mode
762 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
763 aPanel->activateWidget(aPanel->modelWidgets().first());
766 //******************************************************
767 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
768 QList<ModuleBase_ModelWidget*>& theWidgets) const
770 bool aProcessed = false;
772 ModuleBase_OperationFeature* aFOperation =
773 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
774 XGUI_Workshop* aWorkshop = getWorkshop();
775 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
776 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
777 ModuleBase_ISelection* aSelection = workshop()->selection();
778 // click on a point in sketch leads here with the point is highlighted, not yet selected
779 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
780 if (aPreselection.size() == 1) {
781 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
782 ObjectPtr anObject = aSelectedPrs->object();
784 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
785 FeaturePtr anOpFeature = aFOperation->feature();
786 GeomShapePtr aShape = aSelectedPrs->shape();
787 // click on the digit of dimension constrain comes here
788 // with an empty shape, so we need the check
789 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
790 // if feature has only one result and shape of result is equal to selected shape
791 // this attribute is not processed. It is a case of Sketch Point.
792 if (aFeature->results().size() == 1) {
793 ResultPtr aResult = aFeature->results().front();
794 if (aResult.get() && aResult->shape()->isEqual(aShape))
797 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
798 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
799 mySketchMgr->activeSketch());
800 if (anAttribute.get()) {
801 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
802 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
804 const std::string anAttributeId = anAttribute->id();
805 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
807 theWidgets = aFactory.getModelWidgets();
808 // it is possible that the point does not present in XML definition,
809 // in this case, we assume that it is not processed by this module
810 // e.g. "Intersection point" feature
811 aProcessed = !theWidgets.isEmpty();
819 //******************************************************
820 void PartSet_Module::onSelectionChanged()
822 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
826 bool isSketcherOp = false;
827 // An edit operation is enable only if the current opeation is the sketch operation
828 if (mySketchMgr->activeSketch()) {
829 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
830 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
833 // Editing of constraints can be done on selection
834 ModuleBase_ISelection* aSelect = myWorkshop->selection();
835 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
836 if (aSelected.size() == 1) {
837 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
838 ObjectPtr aObject = aPrs->object();
839 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
841 std::string aId = aFeature->getKind();
842 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
843 (aId == SketchPlugin_ConstraintLength::ID()) ||
844 (aId == SketchPlugin_ConstraintDistance::ID()) ||
845 (aId == SketchPlugin_ConstraintAngle::ID())) {
846 editFeature(aFeature);
853 //******************************************************
854 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
856 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
857 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
858 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
861 //******************************************************
862 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
864 Config_WidgetAPI* theWidgetApi)
866 ModuleBase_IWorkshop* aWorkshop = workshop();
867 XGUI_Workshop* aXUIWorkshop = getWorkshop();
868 ModuleBase_ModelWidget* aWgt = NULL;
869 if (theType == "sketch-start-label") {
870 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
871 theWidgetApi, myHasConstraintShown);
872 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
873 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
874 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
875 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
877 } else if (theType == "sketch-2dpoint_selector") {
878 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
880 aPointWgt->setSketch(mySketchMgr->activeSketch());
881 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
883 }else if (theType == "sketch-2dpoint_flyout_selector") {
884 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
886 aPointWgt->setSketch(mySketchMgr->activeSketch());
887 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
889 } else if (theType == "sketch_shape_selector") {
890 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
891 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
892 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
893 aWgt = aShapeSelectorWgt;
894 } else if (theType == "sketch_multi_selector") {
895 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
896 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
897 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
898 aWgt = aShapeSelectorWgt;
900 else if (theType == "sketch_feature_point_selector") {
901 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
902 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
903 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
904 aWgt = aPointSelectorWgt;
906 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
907 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
908 } else if (theType == "export_file_selector") {
909 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
910 } else if (theType == "sketch_launcher") {
911 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
912 } else if (theType == "module_choice") {
913 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
914 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
915 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
920 //******************************************************
921 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
923 ModuleBase_ModelWidget* anActiveWidget = 0;
925 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
927 return anActiveWidget;
929 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
931 return anActiveWidget;
933 return aPanel->activeWidget(true);
936 //******************************************************
937 bool PartSet_Module::deleteObjects()
939 bool isProcessed = false;
941 XGUI_Workshop* aWorkshop = getWorkshop();
942 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
944 //SessionPtr aMgr = ModelAPI_Session::get();
945 // 1. check whether the delete should be processed in the module
946 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
947 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
948 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
949 if (isSketchOp || isNestedOp) {
951 // 2. find selected presentations
952 // selected objects should be collected before the current operation abort because
953 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
954 ModuleBase_ISelection* aSel = workshop()->selection();
955 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
956 // if there are no selected objects in the viewer, that means that the selection in another
957 // place cased this method. It is necessary to return the false value to understande in above
958 // method that delete is not processed
959 if (aSelectedObj.count() == 0)
962 // avoid delete of the objects, which are not belong to the current sketch
963 // in order to do not delete results of other sketches
964 QObjectPtrList aSketchObjects;
965 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
966 for ( ; anIt != aLast; anIt++) {
967 ObjectPtr anObject = *anIt;
968 if (mySketchMgr->isObjectOfSketch(anObject)) {
969 // sketch feature should be used in this list because workshop deletes features only
970 // results are skipped
971 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
972 aSketchObjects.append(aSketchFeature);
975 // if the selection contains only local selected presentations from other sketches,
976 // the Delete operation should not be done at all
977 if (aSketchObjects.size() == 0)
980 // 3. start operation
981 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
982 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
984 // the active nested sketch operation should be aborted unconditionally
985 // the Delete action should be additionally granted for the Sketch operation
986 // in order to do not abort/commit it
988 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
989 return true; // the objects are processed but can not be deleted
991 anOpMgr->startOperation(anOpAction);
993 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
994 // the problem is in AIS Dimensions recompute
995 // if a line and the dim are removed, line is the first
996 // it causes the AIS recompute, where the base line is null,
997 // the result is empty AIS in the viewer
998 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1000 // 4. delete features
1001 // sketch feature should be skipped, only sub-features can be removed
1002 // when sketch operation is active
1003 aWorkshop->deleteFeatures(aSketchObjects);
1004 // 5. stop operation
1005 anOpMgr->commitOperation();
1010 //******************************************************
1011 void PartSet_Module::editFeature(FeaturePtr theFeature)
1013 storeConstraintsState(theFeature->getKind());
1014 ModuleBase_IModule::editFeature(theFeature);
1017 //******************************************************
1018 bool PartSet_Module::canCommitOperation() const
1023 //******************************************************
1024 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1026 myIsOperationIsLaunched = true;
1027 storeConstraintsState(theCmdId.toStdString());
1028 updateConstraintsState(theCmdId.toStdString());
1030 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1032 myIsOperationIsLaunched = false;
1035 //******************************************************
1036 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1038 if (myWorkshop->currentOperation() &&
1039 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1040 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1041 mySketchMgr->showConstraintStates();
1042 myHasConstraintShown = aShownStates;
1046 //******************************************************
1047 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1049 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1050 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1051 // Show constraints if a constraint was anOperation
1052 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1053 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1054 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1055 myHasConstraintShown[PartSet_Tools::Expressions]);
1059 //******************************************************
1060 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1062 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1063 if (!anAIS.IsNull()) {
1064 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1065 if (aFeature.get()) {
1066 bool aToUseZLayer = false;
1067 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1068 aToUseZLayer = true;
1070 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1071 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1074 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1075 aCtx->SetZLayer(anAIS, myVisualLayerId);
1081 //******************************************************
1082 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1085 // it should be recomputed in order to disappear in the viewer if the corresponded object
1087 //if (myCustomPrs->isActive())
1088 // myCustomPrs->redisplay(theObject, false);
1091 //******************************************************
1092 void PartSet_Module::onViewTransformed(int theTrsfType)
1094 // Set length of arrows constant in pixel size
1095 // if the operation is panning or rotate or panglobal then do nothing
1096 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1098 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1099 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1100 if (aContext.IsNull())
1103 //Handle(V3d_View) aView = aViewer->activeView();
1105 XGUI_Workshop* aWorkshop = getWorkshop();
1106 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1107 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1108 Handle(V3d_View) aView;
1110 for (aV3dViewer->InitDefinedViews();
1111 aV3dViewer->MoreDefinedViews();
1112 aV3dViewer->NextDefinedViews()) {
1113 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1114 double aS = aV->Scale();
1123 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1124 if (aCurrentOperation &&
1125 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1126 sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
1128 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1130 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1131 SketcherPrs_Tools::setArrowSize(aLen);
1132 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1133 aViewer->SetScale(aViewer->activeView(), aCurScale);
1134 bool isModified = false;
1135 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1136 foreach (AISObjectPtr aAIS, aPrsList) {
1137 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1139 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1140 if (!aDim.IsNull()) {
1141 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1142 aContext->Redisplay(aDim, false);
1147 aDisplayer->updateViewer();
1151 //******************************************************
1152 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1154 return myCustomPrs->isActive(theFlag);
1157 //******************************************************
1158 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1159 const ModuleBase_CustomizeFlag& theFlag,
1160 const bool theUpdateViewer)
1162 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1165 //******************************************************
1166 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1167 const bool theUpdateViewer)
1169 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1172 //******************************************************
1173 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1174 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1176 bool aCustomized = false;
1178 XGUI_Workshop* aWorkshop = getWorkshop();
1179 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1180 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1184 if (!theResult.get()) {
1185 std::vector<int> aColor;
1186 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1187 if (!aColor.empty()) {
1188 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1191 // customize dimentional constrains
1192 sketchMgr()->customizePresentation(anObject);
1197 //******************************************************
1198 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1199 AISObjectPtr thePrs,
1200 GeomCustomPrsPtr theCustomPrs)
1202 bool aCustomized = false;
1204 XGUI_Workshop* aWorkshop = getWorkshop();
1205 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1206 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1210 std::vector<int> aColor;
1211 bool aUseCustomColor = true;
1212 if (aUseCustomColor)
1213 myOverconstraintListener->getCustomColor(anObject, aColor);
1214 // customize sketch symbol presentation
1215 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1216 if (!anAISIO.IsNull()) {
1217 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1218 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1219 if (!aPrs.IsNull()) {
1220 aPrs->SetCustomColor(aColor);
1223 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1224 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1225 if (!aPrs.IsNull()) {
1226 aPrs->SetCustomColor(aColor);
1231 // customize sketch dimension constraint presentation
1233 if (!aColor.empty()) { // otherwise presentation has the default color
1234 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1240 //******************************************************
1241 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1242 const bool theUpdateViewer)
1244 bool isRedisplayed = false;
1245 if (myCustomPrs->isActive(theFlag))
1246 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1248 return isRedisplayed;
1251 //******************************************************
1252 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1254 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1256 QLabel* aLabel = aOB->activeDocLabel();
1257 aLabel->installEventFilter(myMenuMgr);
1258 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1259 SLOT(onActiveDocPopup(const QPoint&)));
1260 aOB->treeView()->setExpandsOnDoubleClick(false);
1261 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1262 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1264 Events_Loop* aLoop = Events_Loop::loop();
1265 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1269 //******************************************************
1270 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1272 SessionPtr aMgr = ModelAPI_Session::get();
1273 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1275 XGUI_Workshop* aWorkshop = getWorkshop();
1276 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1278 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1281 aMenu.addAction(aActivatePartAction);
1282 aMenu.exec(aHeader->mapToGlobal(thePnt));
1285 //******************************************************
1286 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1288 return mySketchMgr->createPresentation(theResult);
1291 //******************************************************
1292 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1295 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1297 /// If last line finished on vertex the lines creation sequence has to be break
1298 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1300 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1301 // if there is an active widget, find the presented object in it
1302 if (!anActiveWidget)
1303 anActiveWidget = aPanel->preselectionWidget();
1305 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1307 if (aWidgetValidated)
1308 anObject = aWidgetValidated->findPresentedObject(theAIS);
1314 //******************************************************
1315 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1317 bool aCanBeShaged = true;
1319 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1321 aCanBeShaged = false;
1323 return aCanBeShaged;
1326 //******************************************************
1327 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1329 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1330 int aSelected = aObjects.size();
1331 SessionPtr aMgr = ModelAPI_Session::get();
1332 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1334 bool hasResult = false;
1335 bool hasFeature = false;
1336 bool hasParameter = false;
1337 bool hasCompositeOwner = false;
1338 bool hasResultInHistory = false;
1339 bool hasFolder = false;
1340 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1341 hasCompositeOwner, hasResultInHistory, hasFolder);
1343 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1344 if (aSelected == 1) {
1345 ObjectPtr aObject = aObjects.first();
1347 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1348 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1349 bool isPart = aPart.get() ||
1350 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1352 DocumentPtr aPartDoc;
1354 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1356 if (aPart.get()) // this may be null is Part feature is disabled
1357 aPartDoc = aPart->partDoc();
1359 theMenu->addAction(aActivatePartAction);
1360 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1362 } else if (aObject->document() == aMgr->activeDocument()) {
1363 if (hasParameter || hasFeature) {
1364 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1365 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1366 if (aCurrentOp && aFeature.get()) {
1367 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1368 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1375 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1376 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1377 theMenu->addSeparator();
1380 bool aNotDeactivate = (aCurrentOp == 0);
1381 if (!aNotDeactivate) {
1382 aActivatePartAction->setEnabled(false);
1386 //******************************************************
1387 #define EXPAND_PARENT(OBJ) \
1388 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1389 if (aObjIndex.isValid()) { \
1390 QModelIndex aParent = aObjIndex.parent(); \
1391 int aCount = aDataModel->rowCount(aParent); \
1393 aTreeView->setExpanded(aParent, true); \
1396 //******************************************************
1397 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1399 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1400 // Do not change activation of parts if an operation active
1401 static QStringList aAllowActivationList;
1402 if (aAllowActivationList.isEmpty())
1403 aAllowActivationList <<
1404 QString(PartSetPlugin_Part::ID().c_str()) <<
1405 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1406 QString(PartSetPlugin_Remove::ID().c_str());
1407 if (myWorkshop->currentOperation() &&
1408 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1410 XGUI_Workshop* aWorkshop = getWorkshop();
1411 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1412 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1413 QPalette aPalet = aLabel->palette();
1415 SessionPtr aMgr = ModelAPI_Session::get();
1416 DocumentPtr aActiveDoc = aMgr->activeDocument();
1417 // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
1418 //if (myActivePartIndex.isValid())
1419 // aTreeView->setExpanded(myActivePartIndex, false);
1421 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1422 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1423 bool needUpdate = false;
1424 if (myActivePartIndex.isValid()) {
1425 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1427 aTreeView->setExpanded(myActivePartIndex, true);
1430 aLabel->setPalette(aPalet);
1431 aWorkshop->updateCommandStatus();
1433 // Update displayed objects in order to update active color
1434 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1435 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1437 foreach(ObjectPtr aObj, aObjects) {
1438 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1439 aObj->isDisabled() || (!aObj->isDisplayed());
1441 aDisplayer->redisplay(aObj, false);
1443 aDisplayer->updateViewer();
1444 // Update tree items if they are expanded
1446 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1448 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1449 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1450 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1451 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1453 ObjectPtr aConstrObj;
1454 ObjectPtr aResultObj;
1455 std::set<ObjectPtr>::const_iterator aIt;
1456 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1457 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1458 ObjectPtr aObject = (*aIt);
1459 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1460 && (aObject->document() != aRootDoc))
1461 aResultObj = aObject;
1462 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1463 && (aObject->document() != aRootDoc))
1464 aConstrObj = aObject;
1465 if (aResultObj.get() && aConstrObj.get())
1469 if (aResultObj.get() || aConstrObj.get()) {
1470 XGUI_Workshop* aWorkshop = getWorkshop();
1471 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1472 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1474 if (aResultObj.get()) {
1475 EXPAND_PARENT(aResultObj)
1477 if (aConstrObj.get()) {
1478 EXPAND_PARENT(aConstrObj)
1484 //******************************************************
1485 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1487 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1489 SessionPtr aMgr = ModelAPI_Session::get();
1490 if (!theIndex.isValid()) {
1491 // It seems that this code is obsolete
1492 //aMgr->setActiveDocument(aMgr->moduleDocument());
1495 if (theIndex.column() != 1) // Use only first column
1498 XGUI_Workshop* aWorkshop = getWorkshop();
1499 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1500 // De not use non editable Indexes
1501 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1503 ObjectPtr aObj = aDataModel->object(theIndex);
1505 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1506 if (!aPart.get()) { // Probably this is Feature
1507 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1508 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1509 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1512 if (aPart.get()) { // if this is a part
1513 if (aPart->partDoc() == aMgr->activeDocument()) {
1514 myMenuMgr->activatePartSet();
1516 myMenuMgr->activatePart(aPart);
1521 //******************************************************
1522 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1524 // z layer is created for all started operations in order to visualize operation AIS presentation
1526 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1527 if (aContext.IsNull())
1530 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1531 if (myVisualLayerId == 0) {
1532 if (myVisualLayerId == 0)
1533 aViewer->AddZLayer(myVisualLayerId);
1535 TColStd_SequenceOfInteger aZList;
1536 aViewer->GetAllZLayers(aZList);
1537 bool aFound = false;
1538 for (int i = 1; i <= aZList.Length(); i++) {
1539 if (aZList(i) == myVisualLayerId) {
1545 aViewer->AddZLayer(myVisualLayerId);
1547 // if there is an active operation with validated widget,
1548 // the filters of this widget should be activated in the created view
1549 myWorkshop->selectionActivate()->updateSelectionFilters();
1550 myWorkshop->selectionActivate()->updateSelectionModes();
1553 //******************************************************
1554 void PartSet_Module::widgetStateChanged(int thePreviousState)
1556 mySketchMgr->widgetStateChanged(thePreviousState);
1559 //******************************************************
1560 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1562 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1565 //******************************************************
1566 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1568 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1569 mySketchMgr->stopSketch(theOperation);
1573 //******************************************************
1574 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1576 GeomShapePtr aGeomShape;
1578 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1579 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1580 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1585 //******************************************************
1586 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1587 const GeomShapePtr& theGeomShape)
1589 AttributePtr anAttribute;
1590 GeomShapePtr aGeomShape = theGeomShape;
1591 if (!aGeomShape.get()) {
1592 // processing shape of result, e.g. sketch circle center is selected, this is a result
1593 // the geom shape is empty, the shape of result should be used
1594 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1595 if (aResult.get()) {
1596 aGeomShape = aResult->shape();
1600 if (aGeomShape.get()) {
1601 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1602 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1603 mySketchMgr->activeSketch());
1608 //******************************************************
1609 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1611 return sketchReentranceMgr()->reentrantMessage();
1614 //******************************************************
1615 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1617 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1620 //******************************************************
1621 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1624 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1628 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1629 if (!aChoiceTitle.isEmpty()) {
1630 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1633 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1635 aPanel->setWindowTitle(aChoiceTitle);
1639 //******************************************************
1640 XGUI_Workshop* PartSet_Module::getWorkshop() const
1642 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1643 return aConnector->workshop();
1646 void PartSet_Module::setDefaultConstraintShown()
1648 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1649 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1650 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1653 //******************************************************
1654 ModuleBase_ITreeNode* PartSet_Module::rootNode() const