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"
42 #include "PartSet_Filters.h"
43 #include "PartSet_FilterInfinite.h"
45 #include <PartSetPlugin_Remove.h>
46 #include <PartSetPlugin_Part.h>
47 #include <PartSetPlugin_Duplicate.h>
49 #include <ModuleBase_Operation.h>
50 #include <ModuleBase_OperationAction.h>
51 #include <ModuleBase_IViewer.h>
52 #include <ModuleBase_IViewWindow.h>
53 #include <ModuleBase_IPropertyPanel.h>
54 #include <ModuleBase_ISelectionActivate.h>
55 #include <ModuleBase_WidgetChoice.h>
56 #include <ModuleBase_WidgetEditor.h>
57 #include <ModuleBase_WidgetValidated.h>
58 #include <ModuleBase_Tools.h>
59 #include <ModuleBase_OperationFeature.h>
60 #include <ModuleBase_WidgetFactory.h>
61 #include <ModuleBase_OperationDescription.h>
62 #include <ModuleBase_ViewerPrs.h>
64 #include <ModelAPI_Object.h>
65 #include <ModelAPI_Events.h>
66 #include <ModelAPI_Validator.h>
67 #include <ModelAPI_Data.h>
68 #include <ModelAPI_Session.h>
69 #include <ModelAPI_ResultBody.h>
70 #include <ModelAPI_AttributeString.h>
71 #include <ModelAPI_AttributeSelectionList.h>
72 #include <ModelAPI_Tools.h>
73 #include <ModelAPI_ResultConstruction.h>
75 #include <GeomDataAPI_Point2D.h>
76 #include <GeomDataAPI_Point.h>
77 #include <GeomDataAPI_Dir.h>
79 #include <XGUI_ActiveControlMgr.h>
80 #include <XGUI_ActiveControlSelector.h>
81 #include <XGUI_ActionsMgr.h>
82 #include <XGUI_ContextMenuMgr.h>
83 #include <XGUI_CustomPrs.h>
84 #include <XGUI_DataModel.h>
85 #include <XGUI_Displayer.h>
86 #include <XGUI_ErrorMgr.h>
87 #include <XGUI_FacesPanelSelector.h>
88 #include <XGUI_ModuleConnector.h>
89 #include <XGUI_ObjectsBrowser.h>
90 #include <XGUI_OperationMgr.h>
91 #include <XGUI_PropertyPanel.h>
92 #include <XGUI_SelectionMgr.h>
93 #include <XGUI_Tools.h>
94 #include <XGUI_Workshop.h>
96 #include <SketchPlugin_ConstraintAngle.h>
97 #include <SketchPlugin_ConstraintLength.h>
98 #include <SketchPlugin_ConstraintDistance.h>
99 #include <SketchPlugin_ConstraintParallel.h>
100 #include <SketchPlugin_ConstraintPerpendicular.h>
101 #include <SketchPlugin_ConstraintRadius.h>
102 #include <SketchPlugin_Feature.h>
103 #include <SketchPlugin_Projection.h>
104 #include <SketchPlugin_Sketch.h>
106 #include <SketcherPrs_SymbolPrs.h>
107 #include <SketcherPrs_Coincident.h>
108 #include <SketcherPrs_Tools.h>
110 #include <Events_Loop.h>
111 #include <Config_PropManager.h>
112 #include <Config_Keywords.h>
114 #include <AIS_Dimension.hxx>
115 #include <AIS_InteractiveObject.hxx>
116 #include <StdSelect_TypeOfFace.hxx>
117 #include <TopoDS_Vertex.hxx>
118 #include <TopoDS.hxx>
119 #include <TopoDS_Shape.hxx>
120 #include <BRep_Tool.hxx>
123 #include <QMouseEvent>
126 #include <QApplication>
127 #include <QMessageBox>
128 #include <QMainWindow>
132 #include <GeomAlgoAPI_FaceBuilder.h>
133 #include <GeomDataAPI_Dir.h>
135 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
141 /*!Create and return new instance of XGUI_Module*/
142 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
144 return new PartSet_Module(theWshop);
147 //******************************************************
148 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
149 : ModuleBase_IModule(theWshop),
151 myIsOperationIsLaunched(false)
153 new PartSet_IconFactory();
155 mySketchMgr = new PartSet_SketcherMgr(this);
156 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
158 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
159 XGUI_Workshop* aWorkshop = aConnector->workshop();
161 ModuleBase_IViewer* aViewer = theWshop->viewer();
162 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
163 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
164 connect(aViewer, SIGNAL(viewTransformed(int)),
165 SLOT(onViewTransformed(int)));
166 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
167 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
168 myMenuMgr = new PartSet_MenuMgr(this);
169 myCustomPrs = new PartSet_CustomPrs(theWshop);
171 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
173 Events_Loop* aLoop = Events_Loop::loop();
174 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
176 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
177 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
178 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
179 std::set<std::string> aCRGroupNames;
180 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
181 aCRFilter->setGroupNames(aCRGroupNames);
182 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
184 setDefaultConstraintShown();
186 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
187 "Reference shape wireframe color in operation", Config_Prop::Color,
188 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
189 Config_PropManager::registerProp("Visualization", "operation_result_color",
190 "Result shape wireframe color in operation", Config_Prop::Color,
191 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
192 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
193 "Multi selector item color in operation", Config_Prop::Color,
194 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
195 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
196 "Color of removed feature in operation", Config_Prop::Color,
197 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
198 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
199 "Color of sketch plane", Config_Prop::Color,
200 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
202 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
203 "Hidden faces transparency",
208 //******************************************************
209 PartSet_Module::~PartSet_Module()
211 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
212 mySelectionFilters.begin();
213 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
214 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
215 if (!aFilter.IsNull())
219 delete myOverconstraintListener;
222 //******************************************************
223 void PartSet_Module::storeSelection()
225 // cash is used only to restore selection, so it should be filled in storeSelection and
226 // after applying immediatelly cleared in restoreSelection
227 myCurrentSelection.clear();
228 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
231 //******************************************************
232 void PartSet_Module::restoreSelection()
234 // cash is used only to restore selection, so it should be filled in storeSelection and
235 // after applying immediatelly cleared in restoreSelection
236 sketchMgr()->restoreSelection(myCurrentSelection);
237 myCurrentSelection.clear();
240 //******************************************************
241 void PartSet_Module::registerValidators()
243 //Registering of validators
244 SessionPtr aMgr = ModelAPI_Session::get();
245 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
246 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
247 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
248 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
249 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
250 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
251 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
252 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
253 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
254 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
255 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
256 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
257 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
258 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
259 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
260 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
261 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
262 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
263 aFactory->registerValidator("PartSet_MultyTranslationSelection",
264 new PartSet_MultyTranslationSelection);
265 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
266 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
269 //******************************************************
270 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
271 const bool isToConnect)
273 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
276 //******************************************************
277 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
279 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
280 mySketchMgr->commitNestedSketch(theOperation);
282 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
283 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
284 overconstraintListener()->setActive(false);
286 /// Restart sketcher operations automatically
287 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
289 ModuleBase_OperationFeature* aFOperation =
290 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
291 if (aFOperation && !aFOperation->isEditOperation()) {
292 // the selection is cleared after commit the create operation
293 // in order to do not use the same selected objects in the restarted operation
294 // for common behaviour, the selection is cleared even if the operation is not restarted
295 getWorkshop()->selector()->clearSelection();
300 //******************************************************
301 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
303 /// Restart sketcher operations automatically
304 mySketchReentrantMgr->operationAborted(theOperation);
305 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
306 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
307 overconstraintListener()->setActive(false);
310 //******************************************************
311 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
313 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
316 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
317 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
319 ModuleBase_ModelWidget* aFilledWidget = 0;
320 bool aPostonedWidgetActivation = false;
322 FeaturePtr aFeature = aFOperation->feature();
323 /// Restart sketcher operations automatically
324 /// it is important to call method of sketch reentrant manager before filling of PP
325 /// because it fills some created feature attributes, these new values should be used
326 /// to fill the property panel
327 mySketchReentrantMgr->operationStarted(theOperation);
329 aWorkshop->fillPropertyPanel(aFOperation);
330 // filling the operation values by the current selection
331 // if the operation can be committed after the controls filling, the method perform should
332 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
333 bool isOperationCommitted = false;
334 if (!aFOperation->isEditOperation()) {
335 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
336 // if there is a greed attribute, automatic commit by preselection
337 // for this feature is prohibited
338 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
339 if (currentOperation() != aFOperation)
340 isOperationCommitted = true;
342 if (aGreedAttributeId.empty()) {
343 // a signal should be emitted before the next widget activation
344 // because, the activation of the next widget will give a focus to the widget.
345 // As a result the value of the widget is initialized.
346 // And commit may happens until the value is entered.
348 if (mySketchReentrantMgr->canBeCommittedByPreselection())
349 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
350 // activate the next obligatory widget
351 if (!isOperationCommitted)
352 aPropertyPanel->activateNextWidget(aFilledWidget);
355 else { // there is a greed widget
356 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
357 std::string aFirstAttributeId = aWidgets.front()->attributeID();
358 // activate next widget after greeded if it is the first widget in the panel
359 // else the first panel widget is already activated by operation start
360 if (aFirstAttributeId == aGreedAttributeId)
361 aPostonedWidgetActivation = true;
364 } if (!isOperationCommitted) {
365 aWorkshop->connectToPropertyPanel(true);
366 updateSketcherOnStart(aFOperation);
367 updatePresentationsOnStart(aFOperation);
369 // the objects of the current operation should be deactivated
370 QObjectPtrList anObjects;
371 anObjects.append(aFeature);
372 std::list<ResultPtr> aResults;
373 ModelAPI_Tools::allResults(aFeature, aResults);
374 std::list<ResultPtr>::const_iterator aIt;
375 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
376 anObjects.append(*aIt);
378 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
379 for (; anIt != aLast; anIt++)
380 aWorkshop->deactivateActiveObject(*anIt, false);
381 if (anObjects.size() > 0) {
382 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
383 aDisplayer->updateViewer();
385 /// state of command actions should be updated after displayed objects modification because
386 /// deactivation(for example) of objects may influence on selection in the viewer
387 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
388 workshop()->updateCommandStatus();
390 if (aPostonedWidgetActivation) {
391 // if the widget is an empty in the chain of activated widgets, the current operation
392 // is restarted. It should be performed after functionality of the operation starting
393 aPropertyPanel->activateNextWidget(aFilledWidget);
398 //******************************************************
399 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
401 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
402 mySketchMgr->startSketch(theOperation);
404 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
405 mySketchMgr->startNestedSketch(theOperation);
409 //******************************************************
410 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
412 ModuleBase_OperationFeature* aFOperation =
413 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
415 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
416 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
420 //******************************************************
421 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
423 ModuleBase_IModule::operationResumed(theOperation);
425 ModuleBase_OperationFeature* aFOperation =
426 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
428 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
429 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
433 //******************************************************
434 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
436 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
437 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
438 bool isModified = isModifiedArgs || isModifiedResults;
440 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
441 mySketchMgr->stopNestedSketch(theOperation);
443 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
444 setDefaultConstraintShown();
446 //VSV: Viewer is updated on feature update and redisplay
448 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
449 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
450 aDisplayer->updateViewer();
453 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
454 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
455 for (; anIt != aLast; anIt++) {
456 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
460 //******************************************************
461 ModuleBase_Operation* PartSet_Module::currentOperation() const
463 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
464 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
465 return anOpMgr->currentOperation();
468 //******************************************************
469 bool PartSet_Module::canUndo() const
471 bool aCanUndo = false;
472 SessionPtr aMgr = ModelAPI_Session::get();
473 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
474 aCanUndo = !aMgr->isOperation();
475 if (!aCanUndo) // check the enable state additionally by sketch manager
476 aCanUndo = aMgr->canUndo();
481 //******************************************************
482 bool PartSet_Module::canRedo() const
484 bool aCanRedo = false;
485 SessionPtr aMgr = ModelAPI_Session::get();
486 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
487 aCanRedo = !aMgr->isOperation();
488 if (!aCanRedo) // check the enable state additionally by sketch manager
489 aCanRedo = aMgr->canRedo();
494 //******************************************************
495 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
498 if (theActionId == "MOVE_CMD") {
499 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
501 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
502 // part features can not be moved in the history.
503 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
510 //******************************************************
511 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
513 // the sketch manager put the restriction to the objects erase
514 return mySketchMgr->canEraseObject(theObject);
517 //******************************************************
518 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
520 // the sketch manager put the restriction to the objects display
521 return mySketchMgr->canDisplayObject(theObject);
524 //******************************************************
525 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
526 const QString& theStartedOperationKind)
528 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
531 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
534 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
536 mySketchMgr->processHiddenObject(theObjects);
539 //******************************************************
540 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
542 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
544 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
545 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
546 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
547 if (isSketchOp || isNestedOp) {
548 // in active sketch operation it is possible to activate operation object in selection
549 // in the edit operation, e.g. points of the line can be moved when the line is edited
550 ModuleBase_OperationFeature* aFOperation =
551 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
552 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
557 //******************************************************
558 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
560 QMap<int, QAction*>& theMenuActions) const
562 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
565 //******************************************************
566 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
568 myMenuMgr->updateViewerMenu(theStdActions);
571 //******************************************************
572 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
574 bool isEnabledFixed = false;
575 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
576 mySketchReentrantMgr->isInternalEditActive())
577 isEnabledFixed = true;
578 return isEnabledFixed;
581 //******************************************************
582 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
584 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
585 if (anError.isEmpty())
586 anError = sketchMgr()->getFeatureError(theFeature);
591 //******************************************************
592 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
593 QStringList& theIds) const
595 myMenuMgr->grantedOperationIds(theOperation, theIds);
597 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
598 XGUI_Workshop* aWorkshop = getWorkshop();
599 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
603 //******************************************************
604 void PartSet_Module::activeSelectionModes(QIntList& theModes)
606 if (mySketchMgr->activeSketch().get())
607 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
609 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
612 //******************************************************
613 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
615 customSubShapesSelectionModes(theModes);
616 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
617 //myWorkshop->module()->activeSelectionModes(theModes);
620 //******************************************************
621 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
622 SelectMgr_ListOfFilter& theSelectionFilters)
624 bool isSketchActive = mySketchMgr->activeSketch().get();
626 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
627 mySelectionFilters.begin();
628 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
629 int aFilterType = aFiltersIt->first;
630 // do not add not participating filters in given parameters
631 if (!theFilterTypes.contains(aFilterType))
634 // using sketch filters only if sketch operation is active
635 if (!isSketchActive &&
636 mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
639 // using filtering of construction results only from faces panel
640 if (aFilterType == SF_ResultGroupNameFilter)
643 theSelectionFilters.Append(aFiltersIt->second);
647 //******************************************************
648 QIntList PartSet_Module::selectionFilters()
652 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
653 mySelectionFilters.begin();
654 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
655 aTypes.append(aFiltersIt->first);
660 //******************************************************
661 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
662 const Handle(SelectMgr_Filter)& theFilter)
664 mySelectionFilters[theFilterType] = theFilter;
667 //******************************************************
668 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
670 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
672 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
673 return mySelectionFilters[aType];
675 return Handle(SelectMgr_Filter)();
678 //******************************************************
679 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
681 if (theModes.contains(TopAbs_FACE))
682 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
683 if (theModes.contains(TopAbs_WIRE))
684 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
686 if (mySketchMgr->activeSketch().get())
687 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
690 //******************************************************
691 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
692 ObjectPtr& theObject, AttributePtr& theAttribute)
694 ObjectPtr anObject = theSelected->object();
695 GeomShapePtr aShape = theSelected->shape();
697 theAttribute = findAttribute(anObject, aShape);
698 // TODO: try to create result if object is an external object
699 theObject = anObject;
702 //******************************************************
703 bool PartSet_Module::isMouseOverWindow()
705 return mySketchMgr->isMouseOverWindow();
708 //******************************************************
709 bool PartSet_Module::isSketchNeutralPointActivated() const
711 bool isNeutralPoint = true;
712 if (sketchReentranceMgr()->isInternalEditActive())
713 isNeutralPoint = false;
714 if (myIsOperationIsLaunched)
715 isNeutralPoint = false;
717 return isNeutralPoint;
720 //******************************************************
721 void PartSet_Module::closeDocument()
723 myActivePartIndex = QModelIndex();
726 //******************************************************
727 void PartSet_Module::clearViewer()
729 myCustomPrs->clearPrs();
731 XGUI_Workshop* aWorkshop = getWorkshop();
732 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
733 aDisplayer->deactivateSelectionFilters(false);
736 //******************************************************
737 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
739 ModuleBase_OperationFeature* aFOperation =
740 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
744 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
745 // we have to manually activate the sketch label in edit mode
746 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
747 aPanel->activateWidget(aPanel->modelWidgets().first());
750 //******************************************************
751 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
752 QList<ModuleBase_ModelWidget*>& theWidgets) const
754 bool aProcessed = false;
756 ModuleBase_OperationFeature* aFOperation =
757 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
758 XGUI_Workshop* aWorkshop = getWorkshop();
759 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
760 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
761 ModuleBase_ISelection* aSelection = workshop()->selection();
762 // click on a point in sketch leads here with the point is highlighted, not yet selected
763 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
764 if (aPreselection.size() == 1) {
765 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
766 ObjectPtr anObject = aSelectedPrs->object();
768 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
769 FeaturePtr anOpFeature = aFOperation->feature();
770 GeomShapePtr aShape = aSelectedPrs->shape();
771 // click on the digit of dimension constrain comes here
772 // with an empty shape, so we need the check
773 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
774 // if feature has only one result and shape of result is equal to selected shape
775 // this attribute is not processed. It is a case of Sketch Point.
776 if (aFeature->results().size() == 1) {
777 ResultPtr aResult = aFeature->results().front();
778 if (aResult.get() && aResult->shape()->isEqual(aShape))
781 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
782 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
783 mySketchMgr->activeSketch());
784 if (anAttribute.get()) {
785 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
786 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
788 const std::string anAttributeId = anAttribute->id();
789 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
791 theWidgets = aFactory.getModelWidgets();
792 // it is possible that the point does not present in XML definition,
793 // in this case, we assume that it is not processed by this module
794 // e.g. "Intersection point" feature
795 aProcessed = !theWidgets.isEmpty();
803 //******************************************************
804 void PartSet_Module::onSelectionChanged()
806 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
810 bool isSketcherOp = false;
811 // An edit operation is enable only if the current opeation is the sketch operation
812 if (mySketchMgr->activeSketch()) {
813 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
814 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
817 // Editing of constraints can be done on selection
818 ModuleBase_ISelection* aSelect = myWorkshop->selection();
819 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
820 if (aSelected.size() == 1) {
821 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
822 ObjectPtr aObject = aPrs->object();
823 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
825 std::string aId = aFeature->getKind();
826 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
827 (aId == SketchPlugin_ConstraintLength::ID()) ||
828 (aId == SketchPlugin_ConstraintDistance::ID()) ||
829 (aId == SketchPlugin_ConstraintAngle::ID())) {
830 editFeature(aFeature);
837 //******************************************************
838 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
840 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
841 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
842 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
845 //******************************************************
846 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
848 Config_WidgetAPI* theWidgetApi)
850 ModuleBase_IWorkshop* aWorkshop = workshop();
851 XGUI_Workshop* aXUIWorkshop = getWorkshop();
852 ModuleBase_ModelWidget* aWgt = NULL;
853 if (theType == "sketch-start-label") {
854 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
855 theWidgetApi, myHasConstraintShown);
856 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
857 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
858 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
859 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
861 } else if (theType == "sketch-2dpoint_selector") {
862 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
864 aPointWgt->setSketch(mySketchMgr->activeSketch());
865 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
867 }else if (theType == "sketch-2dpoint_flyout_selector") {
868 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
870 aPointWgt->setSketch(mySketchMgr->activeSketch());
871 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
873 } else if (theType == "sketch_shape_selector") {
874 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
875 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
876 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
877 aWgt = aShapeSelectorWgt;
878 } else if (theType == "sketch_multi_selector") {
879 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
880 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
881 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
882 aWgt = aShapeSelectorWgt;
884 else if (theType == "sketch_feature_point_selector") {
885 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
886 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
887 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
888 aWgt = aPointSelectorWgt;
890 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
891 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
892 } else if (theType == "export_file_selector") {
893 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
894 } else if (theType == "sketch_launcher") {
895 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
896 } else if (theType == "module_choice") {
897 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
898 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
899 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
904 //******************************************************
905 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
907 ModuleBase_ModelWidget* anActiveWidget = 0;
909 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
910 if (!anActiveWidget) {
911 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
913 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
914 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
917 return anActiveWidget;
920 //******************************************************
921 bool PartSet_Module::deleteObjects()
923 bool isProcessed = false;
925 XGUI_Workshop* aWorkshop = getWorkshop();
926 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
928 //SessionPtr aMgr = ModelAPI_Session::get();
929 // 1. check whether the delete should be processed in the module
930 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
931 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
932 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
933 if (isSketchOp || isNestedOp) {
935 // 2. find selected presentations
936 // selected objects should be collected before the current operation abort because
937 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
938 ModuleBase_ISelection* aSel = workshop()->selection();
939 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
940 // if there are no selected objects in the viewer, that means that the selection in another
941 // place cased this method. It is necessary to return the false value to understande in above
942 // method that delete is not processed
943 if (aSelectedObj.count() == 0)
946 // avoid delete of the objects, which are not belong to the current sketch
947 // in order to do not delete results of other sketches
948 QObjectPtrList aSketchObjects;
949 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
950 for ( ; anIt != aLast; anIt++) {
951 ObjectPtr anObject = *anIt;
952 if (mySketchMgr->isObjectOfSketch(anObject)) {
953 // sketch feature should be used in this list because workshop deletes features only
954 // results are skipped
955 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
956 aSketchObjects.append(aSketchFeature);
959 // if the selection contains only local selected presentations from other sketches,
960 // the Delete operation should not be done at all
961 if (aSketchObjects.size() == 0)
964 // 3. start operation
965 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
966 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
968 // the active nested sketch operation should be aborted unconditionally
969 // the Delete action should be additionally granted for the Sketch operation
970 // in order to do not abort/commit it
972 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
973 return true; // the objects are processed but can not be deleted
975 anOpMgr->startOperation(anOpAction);
977 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
978 // the problem is in AIS Dimensions recompute
979 // if a line and the dim are removed, line is the first
980 // it causes the AIS recompute, where the base line is null,
981 // the result is empty AIS in the viewer
982 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
984 // 4. delete features
985 // sketch feature should be skipped, only sub-features can be removed
986 // when sketch operation is active
987 aWorkshop->deleteFeatures(aSketchObjects);
989 anOpMgr->commitOperation();
994 //******************************************************
995 void PartSet_Module::editFeature(FeaturePtr theFeature)
997 storeConstraintsState(theFeature->getKind());
998 ModuleBase_IModule::editFeature(theFeature);
1001 //******************************************************
1002 bool PartSet_Module::canCommitOperation() const
1007 //******************************************************
1008 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1010 myIsOperationIsLaunched = true;
1011 storeConstraintsState(theCmdId.toStdString());
1012 updateConstraintsState(theCmdId.toStdString());
1014 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1016 myIsOperationIsLaunched = false;
1019 //******************************************************
1020 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1022 if (myWorkshop->currentOperation() &&
1023 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1024 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1025 mySketchMgr->showConstraintStates();
1026 myHasConstraintShown = aShownStates;
1030 //******************************************************
1031 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1033 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1034 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1035 // Show constraints if a constraint was anOperation
1036 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1037 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1038 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1039 myHasConstraintShown[PartSet_Tools::Expressions]);
1043 //******************************************************
1044 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1046 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1047 if (!anAIS.IsNull()) {
1048 bool aToUseZLayer = false;
1049 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1050 if (aFeature.get() && PartSet_Tools::findRefsToMeFeature(aFeature,
1051 SketchPlugin_Projection::ID()))
1052 aToUseZLayer = true;
1053 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1054 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
1055 if (!aDim.IsNull()) {
1056 aToUseZLayer = true;
1058 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
1059 if (!aCons.IsNull())
1060 aToUseZLayer = true;
1063 aCtx->SetZLayer(anAIS, myVisualLayerId);
1067 //******************************************************
1068 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1071 // it should be recomputed in order to disappear in the viewer if the corresponded object
1073 //if (myCustomPrs->isActive())
1074 // myCustomPrs->redisplay(theObject, false);
1077 //******************************************************
1078 void PartSet_Module::onViewTransformed(int theTrsfType)
1080 // Set length of arrows constant in pixel size
1081 // if the operation is panning or rotate or panglobal then do nothing
1082 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1084 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1085 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1086 if (aContext.IsNull())
1089 //Handle(V3d_View) aView = aViewer->activeView();
1091 XGUI_Workshop* aWorkshop = getWorkshop();
1092 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1093 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1094 Handle(V3d_View) aView;
1096 for (aV3dViewer->InitDefinedViews();
1097 aV3dViewer->MoreDefinedViews();
1098 aV3dViewer->NextDefinedViews()) {
1099 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1100 double aS = aV->Scale();
1109 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1110 if (aCurrentOperation &&
1111 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1112 sketchMgr()->isNestedSketchOperation(aCurrentOperation)))
1114 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1116 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1117 SketcherPrs_Tools::setArrowSize(aLen);
1118 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1119 aViewer->SetScale(aViewer->activeView(), aCurScale);
1120 bool isModified = false;
1121 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1122 foreach (AISObjectPtr aAIS, aPrsList) {
1123 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1125 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1126 if (!aDim.IsNull()) {
1127 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1128 aContext->Redisplay(aDim, false);
1133 aDisplayer->updateViewer();
1137 //******************************************************
1138 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1140 return myCustomPrs->isActive(theFlag);
1143 //******************************************************
1144 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1145 const ModuleBase_CustomizeFlag& theFlag,
1146 const bool theUpdateViewer)
1148 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1151 //******************************************************
1152 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1153 const bool theUpdateViewer)
1155 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1158 //******************************************************
1159 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1160 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1162 bool aCustomized = false;
1164 XGUI_Workshop* aWorkshop = getWorkshop();
1165 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1166 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1170 if (!theResult.get()) {
1171 std::vector<int> aColor;
1172 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1173 if (!aColor.empty()) {
1174 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1177 // customize dimentional constrains
1178 sketchMgr()->customizePresentation(anObject);
1183 //******************************************************
1184 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1185 AISObjectPtr thePrs,
1186 GeomCustomPrsPtr theCustomPrs)
1188 bool aCustomized = false;
1190 XGUI_Workshop* aWorkshop = getWorkshop();
1191 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1192 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1196 std::vector<int> aColor;
1197 bool aUseCustomColor = true;
1198 if (aUseCustomColor)
1199 myOverconstraintListener->getCustomColor(anObject, aColor);
1200 // customize sketch symbol presentation
1201 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1202 if (!anAISIO.IsNull()) {
1203 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1204 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1205 if (!aPrs.IsNull()) {
1206 aPrs->SetCustomColor(aColor);
1209 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1210 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1211 if (!aPrs.IsNull()) {
1212 aPrs->SetCustomColor(aColor);
1217 // customize sketch dimension constraint presentation
1219 if (!aColor.empty()) { // otherwise presentation has the default color
1220 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1226 //******************************************************
1227 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1228 const bool theUpdateViewer)
1230 bool isRedisplayed = false;
1231 if (myCustomPrs->isActive(theFlag))
1232 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1234 return isRedisplayed;
1237 //******************************************************
1238 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1240 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1242 QLabel* aLabel = aOB->activeDocLabel();
1243 aLabel->installEventFilter(myMenuMgr);
1244 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1245 SLOT(onActiveDocPopup(const QPoint&)));
1246 aOB->treeView()->setExpandsOnDoubleClick(false);
1247 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1248 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1250 Events_Loop* aLoop = Events_Loop::loop();
1251 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1255 //******************************************************
1256 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1258 SessionPtr aMgr = ModelAPI_Session::get();
1259 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1261 XGUI_Workshop* aWorkshop = getWorkshop();
1262 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1264 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1267 aMenu.addAction(aActivatePartAction);
1268 aMenu.exec(aHeader->mapToGlobal(thePnt));
1271 //******************************************************
1272 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1274 return mySketchMgr->createPresentation(theResult);
1277 //******************************************************
1278 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1281 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1283 /// If last line finished on vertex the lines creation sequence has to be break
1284 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1286 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1287 // if there is an active widget, find the presented object in it
1288 if (!anActiveWidget)
1289 anActiveWidget = aPanel->preselectionWidget();
1291 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1293 if (aWidgetValidated)
1294 anObject = aWidgetValidated->findPresentedObject(theAIS);
1300 //******************************************************
1301 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1303 bool aCanBeShaged = true;
1305 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1307 aCanBeShaged = false;
1309 return aCanBeShaged;
1312 //******************************************************
1313 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1315 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1316 int aSelected = aObjects.size();
1317 SessionPtr aMgr = ModelAPI_Session::get();
1318 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1320 bool hasResult = false;
1321 bool hasFeature = false;
1322 bool hasParameter = false;
1323 bool hasCompositeOwner = false;
1324 bool hasResultInHistory = false;
1325 bool hasFolder = false;
1326 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1327 hasCompositeOwner, hasResultInHistory, hasFolder);
1329 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1330 if (aSelected == 1) {
1331 ObjectPtr aObject = aObjects.first();
1333 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1334 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1335 bool isPart = aPart.get() ||
1336 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1338 DocumentPtr aPartDoc;
1340 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1342 if (aPart.get()) // this may be null is Part feature is disabled
1343 aPartDoc = aPart->partDoc();
1345 theMenu->addAction(aActivatePartAction);
1346 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1348 } else if (aObject->document() == aMgr->activeDocument()) {
1349 if (hasParameter || hasFeature) {
1350 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1351 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1352 if (aCurrentOp && aFeature.get()) {
1353 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1354 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1361 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1362 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1363 theMenu->addSeparator();
1366 bool aNotDeactivate = (aCurrentOp == 0);
1367 if (!aNotDeactivate) {
1368 aActivatePartAction->setEnabled(false);
1372 //******************************************************
1373 #define EXPAND_PARENT(OBJ) \
1374 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1375 if (aObjIndex.isValid()) { \
1376 QModelIndex aParent = aObjIndex.parent(); \
1377 int aCount = aDataModel->rowCount(aParent); \
1379 aTreeView->setExpanded(aParent, true); \
1382 //******************************************************
1383 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1385 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1386 // Do not change activation of parts if an operation active
1387 static QStringList aAllowActivationList;
1388 if (aAllowActivationList.isEmpty())
1389 aAllowActivationList <<
1390 QString(PartSetPlugin_Part::ID().c_str()) <<
1391 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1392 QString(PartSetPlugin_Remove::ID().c_str());
1393 if (myWorkshop->currentOperation() &&
1394 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1396 XGUI_Workshop* aWorkshop = getWorkshop();
1397 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1398 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1399 QPalette aPalet = aLabel->palette();
1401 SessionPtr aMgr = ModelAPI_Session::get();
1402 DocumentPtr aActiveDoc = aMgr->activeDocument();
1403 if (myActivePartIndex.isValid())
1404 aTreeView->setExpanded(myActivePartIndex, false);
1406 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1407 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1408 bool needUpdate = false;
1409 if (myActivePartIndex.isValid()) {
1410 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1412 aTreeView->setExpanded(myActivePartIndex, true);
1415 aLabel->setPalette(aPalet);
1416 aWorkshop->updateCommandStatus();
1418 // Update displayed objects in order to update active color
1419 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1420 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1422 foreach(ObjectPtr aObj, aObjects) {
1423 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1424 aObj->isDisabled() || (!aObj->isDisplayed());
1426 aDisplayer->redisplay(aObj, false);
1428 aDisplayer->updateViewer();
1429 // Update tree items if they are expanded
1431 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1433 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1434 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1435 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1436 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1438 ObjectPtr aConstrObj;
1439 ObjectPtr aResultObj;
1440 std::set<ObjectPtr>::const_iterator aIt;
1441 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1442 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1443 ObjectPtr aObject = (*aIt);
1444 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1445 && (aObject->document() != aRootDoc))
1446 aResultObj = aObject;
1447 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1448 && (aObject->document() != aRootDoc))
1449 aConstrObj = aObject;
1450 if (aResultObj.get() && aConstrObj.get())
1454 if (aResultObj.get() || aConstrObj.get()) {
1455 XGUI_Workshop* aWorkshop = getWorkshop();
1456 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1457 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1459 if (aResultObj.get()) {
1460 EXPAND_PARENT(aResultObj)
1462 if (aConstrObj.get()) {
1463 EXPAND_PARENT(aConstrObj)
1469 //******************************************************
1470 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1472 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1474 SessionPtr aMgr = ModelAPI_Session::get();
1475 if (!theIndex.isValid()) {
1476 // It seems that this code is obsolete
1477 //aMgr->setActiveDocument(aMgr->moduleDocument());
1480 if (theIndex.column() != 1) // Use only first column
1483 XGUI_Workshop* aWorkshop = getWorkshop();
1484 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1485 // De not use non editable Indexes
1486 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1488 ObjectPtr aObj = aDataModel->object(theIndex);
1490 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1491 if (!aPart.get()) { // Probably this is Feature
1492 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1493 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1494 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1497 if (aPart.get()) { // if this is a part
1498 if (aPart->partDoc() == aMgr->activeDocument()) {
1499 myMenuMgr->activatePartSet();
1501 myMenuMgr->activatePart(aPart);
1506 //******************************************************
1507 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1509 // z layer is created for all started operations in order to visualize operation AIS presentation
1511 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1512 if (aContext.IsNull())
1515 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1516 if (myVisualLayerId == 0) {
1517 if (myVisualLayerId == 0)
1518 aViewer->AddZLayer(myVisualLayerId);
1520 TColStd_SequenceOfInteger aZList;
1521 aViewer->GetAllZLayers(aZList);
1522 bool aFound = false;
1523 for (int i = 1; i <= aZList.Length(); i++) {
1524 if (aZList(i) == myVisualLayerId) {
1530 aViewer->AddZLayer(myVisualLayerId);
1532 // if there is an active operation with validated widget,
1533 // the filters of this widget should be activated in the created view
1534 myWorkshop->selectionActivate()->updateSelectionFilters();
1535 myWorkshop->selectionActivate()->updateSelectionModes();
1538 //******************************************************
1539 void PartSet_Module::widgetStateChanged(int thePreviousState)
1541 mySketchMgr->widgetStateChanged(thePreviousState);
1544 //******************************************************
1545 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1547 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1550 //******************************************************
1551 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1553 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1554 mySketchMgr->stopSketch(theOperation);
1558 //******************************************************
1559 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1561 GeomShapePtr aGeomShape;
1563 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1564 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1565 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1570 //******************************************************
1571 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1572 const GeomShapePtr& theGeomShape)
1574 AttributePtr anAttribute;
1575 GeomShapePtr aGeomShape = theGeomShape;
1576 if (!aGeomShape.get()) {
1577 // processing shape of result, e.g. sketch circle center is selected, this is a result
1578 // the geom shape is empty, the shape of result should be used
1579 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1580 if (aResult.get()) {
1581 aGeomShape = aResult->shape();
1585 if (aGeomShape.get()) {
1586 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1587 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1588 mySketchMgr->activeSketch());
1593 //******************************************************
1594 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1596 return sketchReentranceMgr()->reentrantMessage();
1599 //******************************************************
1600 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1602 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1605 //******************************************************
1606 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1609 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1613 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1614 if (!aChoiceTitle.isEmpty()) {
1615 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1618 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1620 aPanel->setWindowTitle(aChoiceTitle);
1624 //******************************************************
1625 XGUI_Workshop* PartSet_Module::getWorkshop() const
1627 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1628 return aConnector->workshop();
1631 //******************************************************
1632 void PartSet_Module::setDefaultConstraintShown()
1634 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1635 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1636 myHasConstraintShown[PartSet_Tools::Expressions] = false;