1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "PartSet_Module.h"
21 #include "PartSet_WidgetSketchLabel.h"
22 #include "PartSet_Validators.h"
23 #include "PartSet_Tools.h"
24 #include "PartSet_PreviewPlanes.h"
25 #include "PartSet_WidgetPoint2d.h"
26 #include "PartSet_WidgetPoint2DFlyout.h"
27 #include "PartSet_WidgetShapeSelector.h"
28 #include "PartSet_WidgetMultiSelector.h"
29 #include "PartSet_WidgetFeaturePointSelector.h"
30 #include "PartSet_WidgetEditor.h"
31 #include "PartSet_WidgetFileSelector.h"
32 #include "PartSet_WidgetSketchCreator.h"
33 #include "PartSet_SketcherMgr.h"
34 #include "PartSet_SketcherReentrantMgr.h"
35 #include "PartSet_ResultSketchPrs.h"
36 #include "PartSet_MenuMgr.h"
37 #include "PartSet_CustomPrs.h"
38 #include "PartSet_IconFactory.h"
39 #include "PartSet_OverconstraintListener.h"
40 #include "PartSet_TreeNodes.h"
41 #include "PartSet_FieldStepPrs.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 <SketchPlugin_ConstraintCoincidence.h>
52 #include <ModuleBase_Operation.h>
53 #include <ModuleBase_OperationAction.h>
54 #include <ModuleBase_IViewer.h>
55 #include <ModuleBase_IViewWindow.h>
56 #include <ModuleBase_IPropertyPanel.h>
57 #include <ModuleBase_ISelectionActivate.h>
58 #include <ModuleBase_WidgetChoice.h>
59 #include <ModuleBase_WidgetEditor.h>
60 #include <ModuleBase_WidgetValidated.h>
61 #include <ModuleBase_Tools.h>
62 #include <ModuleBase_OperationFeature.h>
63 #include <ModuleBase_WidgetFactory.h>
64 #include <ModuleBase_OperationDescription.h>
65 #include <ModuleBase_ViewerPrs.h>
66 #include <ModelAPI_ResultField.h>
68 #include <ModelAPI_Object.h>
69 #include <ModelAPI_Events.h>
70 #include <ModelAPI_Validator.h>
71 #include <ModelAPI_Data.h>
72 #include <ModelAPI_Session.h>
73 #include <ModelAPI_ResultBody.h>
74 #include <ModelAPI_AttributeString.h>
75 #include <ModelAPI_AttributeSelectionList.h>
76 #include <ModelAPI_Tools.h>
77 #include <ModelAPI_ResultConstruction.h>
78 #include <ModelAPI_AttributeIntArray.h>
80 #include <GeomDataAPI_Point2D.h>
81 #include <GeomDataAPI_Point.h>
82 #include <GeomDataAPI_Dir.h>
84 #include <XGUI_ActiveControlMgr.h>
85 #include <XGUI_ActiveControlSelector.h>
86 #include <XGUI_ActionsMgr.h>
87 #include <XGUI_ContextMenuMgr.h>
88 #include <XGUI_CustomPrs.h>
89 #include <XGUI_DataModel.h>
90 #include <XGUI_Displayer.h>
91 #include <XGUI_ErrorMgr.h>
92 #include <XGUI_FacesPanelSelector.h>
93 #include <XGUI_ModuleConnector.h>
94 #include <XGUI_ObjectsBrowser.h>
95 #include <XGUI_OperationMgr.h>
96 #include <XGUI_PropertyPanel.h>
97 #include <XGUI_SelectionMgr.h>
98 #include <XGUI_Tools.h>
99 #include <XGUI_Workshop.h>
101 #include <SketchPlugin_ConstraintAngle.h>
102 #include <SketchPlugin_ConstraintLength.h>
103 #include <SketchPlugin_ConstraintDistance.h>
104 #include <SketchPlugin_ConstraintParallel.h>
105 #include <SketchPlugin_ConstraintPerpendicular.h>
106 #include <SketchPlugin_ConstraintRadius.h>
107 #include <SketchPlugin_Feature.h>
108 #include <SketchPlugin_Projection.h>
109 #include <SketchPlugin_Sketch.h>
111 #include <SketcherPrs_SymbolPrs.h>
112 #include <SketcherPrs_PositionMgr.h>
113 #include <SketcherPrs_Coincident.h>
114 #include <SketcherPrs_Tools.h>
116 #include <Events_Loop.h>
117 #include <Config_PropManager.h>
118 #include <Config_Keywords.h>
120 #include <AIS_Dimension.hxx>
121 #include <AIS_InteractiveObject.hxx>
122 #include <StdSelect_TypeOfFace.hxx>
123 #include <TopoDS_Vertex.hxx>
124 #include <TopoDS.hxx>
125 #include <TopoDS_Shape.hxx>
126 #include <BRep_Tool.hxx>
129 #include <QMouseEvent>
132 #include <QApplication>
133 #include <QMessageBox>
134 #include <QMainWindow>
138 #include <GeomAlgoAPI_FaceBuilder.h>
139 #include <GeomDataAPI_Dir.h>
141 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
147 /*!Create and return new instance of XGUI_Module*/
148 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
150 return new PartSet_Module(theWshop);
153 //******************************************************
154 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
155 : ModuleBase_IModule(theWshop),
158 myIsOperationIsLaunched(false)
160 new PartSet_IconFactory(this);
162 mySketchMgr = new PartSet_SketcherMgr(this);
163 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
165 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
166 XGUI_Workshop* aWorkshop = aConnector->workshop();
168 ModuleBase_IViewer* aViewer = theWshop->viewer();
169 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
170 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
171 connect(aViewer, SIGNAL(viewTransformed(int)),
172 SLOT(onViewTransformed(int)));
173 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
174 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
175 myMenuMgr = new PartSet_MenuMgr(this);
176 myCustomPrs = new PartSet_CustomPrs(theWshop);
178 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
180 Events_Loop* aLoop = Events_Loop::loop();
181 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
182 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
184 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
185 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
186 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
187 std::set<std::string> aCRGroupNames;
188 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
189 aCRFilter->setGroupNames(aCRGroupNames);
190 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
192 setDefaultConstraintShown();
194 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
195 "Reference shape wireframe color in operation", Config_Prop::Color,
196 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
197 Config_PropManager::registerProp("Visualization", "operation_result_color",
198 "Result shape wireframe color in operation", Config_Prop::Color,
199 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
200 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
201 "Multi selector item color in operation", Config_Prop::Color,
202 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
203 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
204 "Color of removed feature in operation", Config_Prop::Color,
205 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
206 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
207 "Color of sketch plane", Config_Prop::Color,
208 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
210 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
211 "Hidden faces transparency",
212 Config_Prop::DblSpin,
214 std::ostringstream aStream;
215 aStream << SketcherPrs_Tools::getDefaultArrowSize();
216 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
217 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
219 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
220 Config_Prop::String, "Times-bold");
224 aStream << SketcherPrs_Tools::getDefaultTextHeight();
225 Config_PropManager::registerProp("Visualization", "dimension_value_size",
226 "Dimension value size", Config_Prop::IntSpin, aStream.str());
228 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
230 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
233 //******************************************************
234 PartSet_Module::~PartSet_Module()
237 delete myOverconstraintListener;
241 //******************************************************
242 void PartSet_Module::createFeatures()
244 ModuleBase_IModule::createFeatures();
245 myRoot = new PartSet_RootNode();
246 myRoot->setWorkshop(workshop());
250 //******************************************************
251 void PartSet_Module::storeSelection()
253 // cash is used only to restore selection, so it should be filled in storeSelection and
254 // after applying immediatelly cleared in restoreSelection
255 myCurrentSelection.clear();
256 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
259 //******************************************************
260 void PartSet_Module::restoreSelection()
262 // cash is used only to restore selection, so it should be filled in storeSelection and
263 // after applying immediatelly cleared in restoreSelection
264 sketchMgr()->restoreSelection(myCurrentSelection);
265 myCurrentSelection.clear();
268 //******************************************************
269 void PartSet_Module::registerValidators()
271 //Registering of validators
272 SessionPtr aMgr = ModelAPI_Session::get();
273 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
274 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
275 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
276 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
277 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
278 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
279 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
280 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
281 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
282 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
283 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
284 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
285 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
286 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
287 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
288 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
289 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
290 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
291 aFactory->registerValidator("PartSet_MultyTranslationSelection",
292 new PartSet_MultyTranslationSelection);
293 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
294 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
295 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
298 //******************************************************
299 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
300 const bool isToConnect)
302 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
305 //******************************************************
306 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
308 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
309 mySketchMgr->commitNestedSketch(theOperation);
311 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
312 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
313 overconstraintListener()->setActive(false);
315 /// Restart sketcher operations automatically
316 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
318 ModuleBase_OperationFeature* aFOperation =
319 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
320 if (aFOperation && !aFOperation->isEditOperation()) {
321 // the selection is cleared after commit the create operation
322 // in order to do not use the same selected objects in the restarted operation
323 // for common behaviour, the selection is cleared even if the operation is not restarted
324 getWorkshop()->selector()->clearSelection();
329 //******************************************************
330 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
332 /// Restart sketcher operations automatically
333 mySketchReentrantMgr->operationAborted(theOperation);
334 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
335 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
336 overconstraintListener()->setActive(false);
339 //******************************************************
340 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
342 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
345 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
346 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
348 ModuleBase_ModelWidget* aFilledWidget = 0;
349 bool aPostonedWidgetActivation = false;
351 FeaturePtr aFeature = aFOperation->feature();
352 /// Restart sketcher operations automatically
353 /// it is important to call method of sketch reentrant manager before filling of PP
354 /// because it fills some created feature attributes, these new values should be used
355 /// to fill the property panel
356 mySketchReentrantMgr->operationStarted(theOperation);
358 aWorkshop->fillPropertyPanel(aFOperation);
359 // filling the operation values by the current selection
360 // if the operation can be committed after the controls filling, the method perform should
361 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
362 bool isOperationCommitted = false;
363 if (!aFOperation->isEditOperation()) {
364 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
365 // if there is a greed attribute, automatic commit by preselection
366 // for this feature is prohibited
367 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
368 if (currentOperation() != aFOperation)
369 isOperationCommitted = true;
371 if (aGreedAttributeId.empty()) {
372 // a signal should be emitted before the next widget activation
373 // because, the activation of the next widget will give a focus to the widget.
374 // As a result the value of the widget is initialized.
375 // And commit may happens until the value is entered.
377 if (mySketchReentrantMgr->canBeCommittedByPreselection())
378 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
379 // activate the next obligatory widget
380 if (!isOperationCommitted)
381 aPropertyPanel->activateNextWidget(aFilledWidget);
384 else { // there is a greed widget
385 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
386 std::string aFirstAttributeId = aWidgets.front()->attributeID();
387 // activate next widget after greeded if it is the first widget in the panel
388 // else the first panel widget is already activated by operation start
389 if (aFirstAttributeId == aGreedAttributeId)
390 aPostonedWidgetActivation = true;
393 } if (!isOperationCommitted) {
394 aWorkshop->connectToPropertyPanel(true);
395 updateSketcherOnStart(aFOperation);
396 updatePresentationsOnStart(aFOperation);
398 // the objects of the current operation should be deactivated
399 QObjectPtrList anObjects;
400 anObjects.append(aFeature);
401 std::list<ResultPtr> aResults;
402 ModelAPI_Tools::allResults(aFeature, aResults);
403 std::list<ResultPtr>::const_iterator aIt;
404 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
405 anObjects.append(*aIt);
407 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
408 for (; anIt != aLast; anIt++)
409 aWorkshop->deactivateActiveObject(*anIt, false);
410 if (anObjects.size() > 0) {
411 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
412 aDisplayer->updateViewer();
414 /// state of command actions should be updated after displayed objects modification because
415 /// deactivation(for example) of objects may influence on selection in the viewer
416 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
417 workshop()->updateCommandStatus();
419 if (aPostonedWidgetActivation) {
420 // if the widget is an empty in the chain of activated widgets, the current operation
421 // is restarted. It should be performed after functionality of the operation starting
422 aPropertyPanel->activateNextWidget(aFilledWidget);
427 //******************************************************
428 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
430 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
431 mySketchMgr->startSketch(theOperation);
433 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
434 mySketchMgr->startNestedSketch(theOperation);
438 //******************************************************
439 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
441 ModuleBase_OperationFeature* aFOperation =
442 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
444 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
445 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
449 //******************************************************
450 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
452 ModuleBase_IModule::operationResumed(theOperation);
454 ModuleBase_OperationFeature* aFOperation =
455 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
457 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
458 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
462 //******************************************************
463 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
465 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
466 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
467 bool isModified = isModifiedArgs || isModifiedResults;
469 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
470 mySketchMgr->stopNestedSketch(theOperation);
472 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
473 setDefaultConstraintShown();
475 //VSV: Viewer is updated on feature update and redisplay
477 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
478 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
479 aDisplayer->updateViewer();
482 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
483 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
484 for (; anIt != aLast; anIt++) {
485 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
489 //******************************************************
490 ModuleBase_Operation* PartSet_Module::currentOperation() const
492 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
493 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
494 return anOpMgr->currentOperation();
497 //******************************************************
498 bool PartSet_Module::canUndo() const
500 bool aCanUndo = false;
501 SessionPtr aMgr = ModelAPI_Session::get();
502 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
503 aCanUndo = !aMgr->isOperation();
504 if (!aCanUndo) // check the enable state additionally by sketch manager
505 aCanUndo = aMgr->canUndo();
510 //******************************************************
511 bool PartSet_Module::canRedo() const
513 bool aCanRedo = false;
514 SessionPtr aMgr = ModelAPI_Session::get();
515 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
516 aCanRedo = !aMgr->isOperation();
517 if (!aCanRedo) // check the enable state additionally by sketch manager
518 aCanRedo = aMgr->canRedo();
523 //******************************************************
524 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
527 if (theActionId == "MOVE_CMD") {
528 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
530 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
531 // part features can not be moved in the history.
532 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
539 //******************************************************
540 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
542 // the sketch manager put the restriction to the objects erase
543 return mySketchMgr->canEraseObject(theObject);
546 //******************************************************
547 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
549 // the sketch manager put the restriction to the objects display
550 return mySketchMgr->canDisplayObject(theObject);
553 //******************************************************
554 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
555 const QString& theStartedOperationKind)
557 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
560 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
563 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
565 mySketchMgr->processHiddenObject(theObjects);
568 //******************************************************
569 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
571 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
573 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
574 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
575 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
576 if (isSketchOp || isNestedOp) {
577 // in active sketch operation it is possible to activate operation object in selection
578 // in the edit operation, e.g. points of the line can be moved when the line is edited
579 ModuleBase_OperationFeature* aFOperation =
580 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
581 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
586 //******************************************************
587 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
589 QMap<int, QAction*>& theMenuActions) const
591 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
594 //******************************************************
595 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
597 myMenuMgr->updateViewerMenu(theStdActions);
600 //******************************************************
601 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
603 bool isEnabledFixed = false;
604 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
605 mySketchReentrantMgr->isInternalEditActive())
606 isEnabledFixed = true;
607 return isEnabledFixed;
610 //******************************************************
611 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
613 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
614 if (anError.isEmpty())
615 anError = sketchMgr()->getFeatureError(theFeature);
620 //******************************************************
621 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
622 QStringList& theIds) const
624 myMenuMgr->grantedOperationIds(theOperation, theIds);
626 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
627 XGUI_Workshop* aWorkshop = getWorkshop();
628 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
632 //******************************************************
633 void PartSet_Module::activeSelectionModes(QIntList& theModes)
635 if (mySketchMgr->activeSketch().get())
636 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
638 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
641 //******************************************************
642 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
644 customSubShapesSelectionModes(theModes);
645 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
646 //myWorkshop->module()->activeSelectionModes(theModes);
649 //******************************************************
650 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
651 SelectMgr_ListOfFilter& theSelectionFilters)
653 bool isSketchActive = mySketchMgr->activeSketch().get();
655 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
656 mySelectionFilters.begin();
657 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
658 int aFilterType = aFiltersIt->first;
659 // do not add not participating filters in given parameters
660 if (!theFilterTypes.contains(aFilterType))
663 // using sketch filters only if sketch operation is active
664 if (!isSketchActive &&
665 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
668 // using filtering of construction results only from faces panel
669 if (aFilterType == SF_ResultGroupNameFilter)
672 theSelectionFilters.Append(aFiltersIt->second);
676 //******************************************************
677 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
679 if (theModes.contains(TopAbs_FACE))
680 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
681 if (theModes.contains(TopAbs_WIRE))
682 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
684 if (mySketchMgr->activeSketch().get())
685 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
688 //******************************************************
689 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
690 ObjectPtr& theObject, AttributePtr& theAttribute)
692 ObjectPtr anObject = theSelected->object();
693 GeomShapePtr aShape = theSelected->shape();
695 theAttribute = findAttribute(anObject, aShape);
696 // TODO: try to create result if object is an external object
697 theObject = anObject;
700 //******************************************************
701 bool PartSet_Module::isMouseOverWindow()
703 return mySketchMgr->isMouseOverWindow();
706 //******************************************************
707 bool PartSet_Module::isSketchNeutralPointActivated() const
709 bool isNeutralPoint = true;
710 if (sketchReentranceMgr()->isInternalEditActive())
711 isNeutralPoint = false;
712 if (myIsOperationIsLaunched)
713 isNeutralPoint = false;
715 return isNeutralPoint;
718 //******************************************************
719 void PartSet_Module::closeDocument()
721 myActivePartIndex = QModelIndex();
722 SketcherPrs_PositionMgr::get()->clearAll();
725 //******************************************************
726 void PartSet_Module::clearViewer()
728 myCustomPrs->clearPrs();
730 XGUI_Workshop* aWorkshop = getWorkshop();
731 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
732 aDisplayer->deactivateSelectionFilters(false);
735 //******************************************************
736 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
738 ModuleBase_OperationFeature* aFOperation =
739 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
743 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
744 // we have to manually activate the sketch label in edit mode
745 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
746 aPanel->activateWidget(aPanel->modelWidgets().first());
749 //******************************************************
750 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
751 QList<ModuleBase_ModelWidget*>& theWidgets) const
753 bool aProcessed = false;
755 ModuleBase_OperationFeature* aFOperation =
756 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
757 XGUI_Workshop* aWorkshop = getWorkshop();
758 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
759 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
760 ModuleBase_ISelection* aSelection = workshop()->selection();
761 // click on a point in sketch leads here with the point is highlighted, not yet selected
762 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
763 if (aPreselection.size() == 1) {
764 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
765 ObjectPtr anObject = aSelectedPrs->object();
767 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
768 FeaturePtr anOpFeature = aFOperation->feature();
769 GeomShapePtr aShape = aSelectedPrs->shape();
770 // click on the digit of dimension constrain comes here
771 // with an empty shape, so we need the check
772 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
773 // if feature has only one result and shape of result is equal to selected shape
774 // this attribute is not processed. It is a case of Sketch Point.
775 if (aFeature->results().size() == 1) {
776 ResultPtr aResult = aFeature->results().front();
777 if (aResult.get() && aResult->shape()->isEqual(aShape))
780 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
781 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
782 mySketchMgr->activeSketch());
783 if (anAttribute.get()) {
784 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
785 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
787 const std::string anAttributeId = anAttribute->id();
788 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
790 theWidgets = aFactory.getModelWidgets();
791 // it is possible that the point does not present in XML definition,
792 // in this case, we assume that it is not processed by this module
793 // e.g. "Intersection point" feature
794 aProcessed = !theWidgets.isEmpty();
802 //******************************************************
803 void PartSet_Module::onSelectionChanged()
805 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
809 bool isSketcherOp = false;
810 // An edit operation is enable only if the current opeation is the sketch operation
811 if (mySketchMgr->activeSketch()) {
812 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
813 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
816 // Editing of constraints can be done on selection
817 ModuleBase_ISelection* aSelect = myWorkshop->selection();
818 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
819 if (aSelected.size() == 1) {
820 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
821 ObjectPtr aObject = aPrs->object();
822 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
824 std::string aId = aFeature->getKind();
825 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
826 (aId == SketchPlugin_ConstraintLength::ID()) ||
827 (aId == SketchPlugin_ConstraintDistance::ID()) ||
828 (aId == SketchPlugin_ConstraintAngle::ID())) {
829 editFeature(aFeature);
836 //******************************************************
837 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
839 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
840 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
841 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
844 //******************************************************
845 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
847 Config_WidgetAPI* theWidgetApi)
849 ModuleBase_IWorkshop* aWorkshop = workshop();
850 XGUI_Workshop* aXUIWorkshop = getWorkshop();
851 ModuleBase_ModelWidget* aWgt = NULL;
852 if (theType == "sketch-start-label") {
853 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
854 theWidgetApi, myHasConstraintShown);
855 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
856 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
857 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
858 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
859 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
860 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
862 } else if (theType == "sketch-2dpoint_selector") {
863 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
865 aPointWgt->setSketch(mySketchMgr->activeSketch());
866 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
868 }else if (theType == "sketch-2dpoint_flyout_selector") {
869 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
871 aPointWgt->setSketch(mySketchMgr->activeSketch());
872 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
874 } else if (theType == "sketch_shape_selector") {
875 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
876 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
877 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
878 aWgt = aShapeSelectorWgt;
879 } else if (theType == "sketch_multi_selector") {
880 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
881 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
882 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
883 aWgt = aShapeSelectorWgt;
885 else if (theType == "sketch_feature_point_selector") {
886 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
887 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
888 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
889 aWgt = aPointSelectorWgt;
891 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
892 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
893 } else if (theType == "export_file_selector") {
894 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
895 } else if (theType == "sketch_launcher") {
896 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
897 } else if (theType == "module_choice") {
898 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
899 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
900 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
905 //******************************************************
906 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
908 ModuleBase_ModelWidget* anActiveWidget = 0;
910 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
912 return anActiveWidget;
914 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
916 return anActiveWidget;
918 return aPanel->activeWidget(true);
921 //******************************************************
922 bool PartSet_Module::deleteObjects()
924 bool isProcessed = false;
926 XGUI_Workshop* aWorkshop = getWorkshop();
927 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
929 //SessionPtr aMgr = ModelAPI_Session::get();
930 // 1. check whether the delete should be processed in the module
931 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
932 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
933 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
934 if (isSketchOp || isNestedOp) {
936 // 2. find selected presentations
937 // selected objects should be collected before the current operation abort because
938 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
939 ModuleBase_ISelection* aSel = workshop()->selection();
940 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
941 // if there are no selected objects in the viewer, that means that the selection in another
942 // place cased this method. It is necessary to return the false value to understande in above
943 // method that delete is not processed
944 if (aSelectedObj.count() == 0)
947 // avoid delete of the objects, which are not belong to the current sketch
948 // in order to do not delete results of other sketches
949 QObjectPtrList aSketchObjects;
950 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
951 for ( ; anIt != aLast; anIt++) {
952 ObjectPtr anObject = *anIt;
953 if (mySketchMgr->isObjectOfSketch(anObject)) {
954 // sketch feature should be used in this list because workshop deletes features only
955 // results are skipped
956 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
957 aSketchObjects.append(aSketchFeature);
960 // if the selection contains only local selected presentations from other sketches,
961 // the Delete operation should not be done at all
962 if (aSketchObjects.size() == 0)
965 // 3. start operation
966 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
967 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
969 // the active nested sketch operation should be aborted unconditionally
970 // the Delete action should be additionally granted for the Sketch operation
971 // in order to do not abort/commit it
973 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
974 return true; // the objects are processed but can not be deleted
976 anOpMgr->startOperation(anOpAction);
978 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
979 // the problem is in AIS Dimensions recompute
980 // if a line and the dim are removed, line is the first
981 // it causes the AIS recompute, where the base line is null,
982 // the result is empty AIS in the viewer
983 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
985 // 4. delete features
986 // sketch feature should be skipped, only sub-features can be removed
987 // when sketch operation is active
988 aWorkshop->deleteFeatures(aSketchObjects);
990 anOpMgr->commitOperation();
995 //******************************************************
996 void PartSet_Module::editFeature(FeaturePtr theFeature)
998 storeConstraintsState(theFeature->getKind());
999 ModuleBase_IModule::editFeature(theFeature);
1002 //******************************************************
1003 bool PartSet_Module::canCommitOperation() const
1008 //******************************************************
1009 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1011 myIsOperationIsLaunched = true;
1012 storeConstraintsState(theCmdId.toStdString());
1013 updateConstraintsState(theCmdId.toStdString());
1015 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1017 myIsOperationIsLaunched = false;
1020 //******************************************************
1021 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1023 if (myWorkshop->currentOperation() &&
1024 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1025 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1026 mySketchMgr->showConstraintStates();
1027 myHasConstraintShown = aShownStates;
1031 //******************************************************
1032 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1034 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1035 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1036 // Show constraints if a constraint was anOperation
1037 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1038 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1039 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1040 myHasConstraintShown[PartSet_Tools::Expressions]);
1044 //******************************************************
1045 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1047 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1048 if (!anAIS.IsNull()) {
1049 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1050 if (aFeature.get()) {
1051 bool aToUseZLayer = false;
1052 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1053 aToUseZLayer = true;
1055 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1056 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1059 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1060 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1061 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1063 aCtx->SetZLayer(anAIS, myVisualLayerId);
1069 //******************************************************
1070 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1073 // it should be recomputed in order to disappear in the viewer if the corresponded object
1075 //if (myCustomPrs->isActive())
1076 // myCustomPrs->redisplay(theObject, false);
1079 //******************************************************
1080 void PartSet_Module::onViewTransformed(int theTrsfType)
1082 // Set length of arrows constant in pixel size
1083 // if the operation is panning or rotate or panglobal then do nothing
1084 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1086 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1087 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1088 if (aContext.IsNull())
1091 //Handle(V3d_View) aView = aViewer->activeView();
1093 XGUI_Workshop* aWorkshop = getWorkshop();
1094 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1095 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1096 Handle(V3d_View) aView;
1098 for (aV3dViewer->InitDefinedViews();
1099 aV3dViewer->MoreDefinedViews();
1100 aV3dViewer->NextDefinedViews()) {
1101 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1102 double aS = aV->Scale();
1111 bool isModified = false;
1112 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1113 if (aCurrentOperation &&
1114 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1115 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1116 (aCurrentOperation->id() == "Measurement")))
1118 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1120 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1121 SketcherPrs_Tools::setArrowSize(aLen);
1122 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1123 aViewer->SetScale(aViewer->activeView(), aCurScale);
1125 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1126 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1128 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1129 foreach(AISObjectPtr aAIS, aPrsList) {
1130 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1132 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1133 if (!aDim.IsNull()) {
1134 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1135 aContext->Redisplay(aDim, false);
1140 aDisplayer->updateViewer();
1145 //******************************************************
1146 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1148 return myCustomPrs->isActive(theFlag);
1151 //******************************************************
1152 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1153 const ModuleBase_CustomizeFlag& theFlag,
1154 const bool theUpdateViewer)
1156 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1159 //******************************************************
1160 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1161 const bool theUpdateViewer)
1163 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1166 //******************************************************
1167 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1168 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1170 bool aCustomized = false;
1172 XGUI_Workshop* aWorkshop = getWorkshop();
1173 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1174 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1178 if (!theResult.get()) {
1179 std::vector<int> aColor;
1180 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1181 if (!aColor.empty()) {
1182 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1185 // customize dimentional constrains
1186 sketchMgr()->customizePresentation(anObject);
1191 //******************************************************
1192 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1193 AISObjectPtr thePrs,
1194 GeomCustomPrsPtr theCustomPrs)
1196 bool aCustomized = false;
1198 XGUI_Workshop* aWorkshop = getWorkshop();
1199 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1200 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1204 std::vector<int> aColor;
1205 bool aUseCustomColor = true;
1206 if (aUseCustomColor)
1207 myOverconstraintListener->getCustomColor(anObject, aColor);
1208 // customize sketch symbol presentation
1209 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1210 if (!anAISIO.IsNull()) {
1211 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1212 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1213 if (!aPrs.IsNull()) {
1214 aPrs->SetCustomColor(aColor);
1217 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1218 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1219 if (!aPrs.IsNull()) {
1220 aPrs->SetCustomColor(aColor);
1225 // customize sketch dimension constraint presentation
1227 if (!aColor.empty()) { // otherwise presentation has the default color
1228 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1234 //******************************************************
1235 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1236 const bool theUpdateViewer)
1238 bool isRedisplayed = false;
1239 if (myCustomPrs->isActive(theFlag))
1240 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1242 return isRedisplayed;
1245 //******************************************************
1246 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1248 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1250 QLabel* aLabel = aOB->activeDocLabel();
1251 aLabel->installEventFilter(myMenuMgr);
1252 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1253 SLOT(onActiveDocPopup(const QPoint&)));
1254 aOB->treeView()->setExpandsOnDoubleClick(false);
1255 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1256 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1258 Events_Loop* aLoop = Events_Loop::loop();
1259 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1263 //******************************************************
1264 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1266 SessionPtr aMgr = ModelAPI_Session::get();
1267 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1269 XGUI_Workshop* aWorkshop = getWorkshop();
1270 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1272 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1275 aMenu.addAction(aActivatePartAction);
1276 aMenu.exec(aHeader->mapToGlobal(thePnt));
1279 //******************************************************
1280 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1282 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1284 return mySketchMgr->createPresentation(aResult);
1286 FieldStepPtr aStep =
1287 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1289 return new PartSet_FieldStepPrs(aStep);
1292 return Handle(AIS_InteractiveObject)();
1295 //******************************************************
1296 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1299 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1301 /// If last line finished on vertex the lines creation sequence has to be break
1302 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1304 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1305 // if there is an active widget, find the presented object in it
1306 if (!anActiveWidget)
1307 anActiveWidget = aPanel->preselectionWidget();
1309 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1311 if (aWidgetValidated)
1312 anObject = aWidgetValidated->findPresentedObject(theAIS);
1318 //******************************************************
1319 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1321 bool aCanBeShaged = true;
1323 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1325 aCanBeShaged = false;
1327 return aCanBeShaged;
1330 //******************************************************
1331 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1333 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1334 int aSelected = aObjects.size();
1335 SessionPtr aMgr = ModelAPI_Session::get();
1336 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1338 bool hasResult = false;
1339 bool hasFeature = false;
1340 bool hasParameter = false;
1341 bool hasCompositeOwner = false;
1342 bool hasResultInHistory = false;
1343 bool hasFolder = false;
1344 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1345 hasCompositeOwner, hasResultInHistory, hasFolder);
1347 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1348 if (aSelected == 1) {
1349 ObjectPtr aObject = aObjects.first();
1351 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1352 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1353 bool isPart = aPart.get() ||
1354 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1356 DocumentPtr aPartDoc;
1358 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1360 if (aPart.get()) // this may be null is Part feature is disabled
1361 aPartDoc = aPart->partDoc();
1363 theMenu->addAction(aActivatePartAction);
1364 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1366 } else if (aObject->document() == aMgr->activeDocument()) {
1367 if (hasParameter || hasFeature) {
1368 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1369 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1370 if (aCurrentOp && aFeature.get()) {
1371 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1372 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1379 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1380 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1381 theMenu->addSeparator();
1384 bool aNotDeactivate = (aCurrentOp == 0);
1385 if (!aNotDeactivate) {
1386 aActivatePartAction->setEnabled(false);
1390 //******************************************************
1391 #define EXPAND_PARENT(OBJ) \
1392 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1393 if (aObjIndex.isValid()) { \
1394 QModelIndex aParent = aObjIndex.parent(); \
1395 int aCount = aDataModel->rowCount(aParent); \
1397 aTreeView->setExpanded(aParent, true); \
1400 //******************************************************
1401 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1403 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1404 // Do not change activation of parts if an operation active
1405 static QStringList aAllowActivationList;
1406 if (aAllowActivationList.isEmpty())
1407 aAllowActivationList <<
1408 QString(PartSetPlugin_Part::ID().c_str()) <<
1409 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1410 QString(PartSetPlugin_Remove::ID().c_str());
1411 if (myWorkshop->currentOperation() &&
1412 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1414 XGUI_Workshop* aWorkshop = getWorkshop();
1415 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1416 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1417 QPalette aPalet = aLabel->palette();
1419 SessionPtr aMgr = ModelAPI_Session::get();
1420 DocumentPtr aActiveDoc = aMgr->activeDocument();
1422 // Clear active part index if there is no Part documents
1423 // It could be not null if document was closed and opened a new
1424 // without closeDocument call
1425 if (aMgr->allOpenedDocuments().size() <= 1)
1426 myActivePartIndex = QModelIndex();
1428 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1429 QModelIndex aOldActive = myActivePartIndex;
1430 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1431 bool needUpdate = false;
1432 if (myActivePartIndex.isValid()) {
1433 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1435 aTreeView->setExpanded(myActivePartIndex, true);
1437 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1438 aTreeView->setExpanded(aOldActive, false);
1440 aLabel->setPalette(aPalet);
1441 aWorkshop->updateCommandStatus();
1443 // Update displayed objects in order to update active color
1444 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1445 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1447 foreach(ObjectPtr aObj, aObjects) {
1448 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1449 aObj->isDisabled() || (!aObj->isDisplayed());
1451 aDisplayer->redisplay(aObj, false);
1453 aDisplayer->updateViewer();
1454 // Update tree items if they are expanded
1456 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1458 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1459 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1460 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1461 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1463 ObjectPtr aConstrObj;
1464 ObjectPtr aResultObj;
1465 std::set<ObjectPtr>::const_iterator aIt;
1466 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1467 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1468 ObjectPtr aObject = (*aIt);
1469 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1470 && (aObject->document() != aRootDoc))
1471 aResultObj = aObject;
1472 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1473 && (aObject->document() != aRootDoc))
1474 aConstrObj = aObject;
1475 if (aResultObj.get() && aConstrObj.get())
1479 if (aResultObj.get() || aConstrObj.get()) {
1480 XGUI_Workshop* aWorkshop = getWorkshop();
1481 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1482 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1484 if (aResultObj.get()) {
1485 EXPAND_PARENT(aResultObj)
1487 if (aConstrObj.get()) {
1488 EXPAND_PARENT(aConstrObj)
1492 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1493 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1494 if (aSketch.get()) {
1495 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1496 if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1497 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1502 //******************************************************
1503 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1505 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1507 SessionPtr aMgr = ModelAPI_Session::get();
1508 if (!theIndex.isValid()) {
1509 // It seems that this code is obsolete
1510 //aMgr->setActiveDocument(aMgr->moduleDocument());
1513 if (theIndex.column() != 1) // Use only first column
1516 XGUI_Workshop* aWorkshop = getWorkshop();
1517 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1518 // De not use non editable Indexes
1519 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1521 ObjectPtr aObj = aDataModel->object(theIndex);
1523 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1524 if (!aPart.get()) { // Probably this is Feature
1525 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1526 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1527 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1530 if (aPart.get()) { // if this is a part
1531 if (aPart->partDoc() == aMgr->activeDocument()) {
1532 myMenuMgr->activatePartSet();
1534 myMenuMgr->activatePart(aPart);
1539 //******************************************************
1540 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1542 // z layer is created for all started operations in order to visualize operation AIS presentation
1544 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1545 if (aContext.IsNull())
1548 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1549 if (myVisualLayerId == 0) {
1550 if (myVisualLayerId == 0)
1551 aViewer->AddZLayer(myVisualLayerId);
1553 TColStd_SequenceOfInteger aZList;
1554 aViewer->GetAllZLayers(aZList);
1555 bool aFound = false;
1556 for (int i = 1; i <= aZList.Length(); i++) {
1557 if (aZList(i) == myVisualLayerId) {
1563 aViewer->AddZLayer(myVisualLayerId);
1565 // if there is an active operation with validated widget,
1566 // the filters of this widget should be activated in the created view
1567 myWorkshop->selectionActivate()->updateSelectionFilters();
1568 myWorkshop->selectionActivate()->updateSelectionModes();
1571 //******************************************************
1572 void PartSet_Module::widgetStateChanged(int thePreviousState)
1574 mySketchMgr->widgetStateChanged(thePreviousState);
1577 //******************************************************
1578 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1580 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1583 //******************************************************
1584 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1586 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1587 mySketchMgr->stopSketch(theOperation);
1591 //******************************************************
1592 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1594 GeomShapePtr aGeomShape;
1596 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1597 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1598 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1603 //******************************************************
1604 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1605 const GeomShapePtr& theGeomShape)
1607 AttributePtr anAttribute;
1608 GeomShapePtr aGeomShape = theGeomShape;
1609 if (!aGeomShape.get()) {
1610 // processing shape of result, e.g. sketch circle center is selected, this is a result
1611 // the geom shape is empty, the shape of result should be used
1612 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1613 if (aResult.get()) {
1614 aGeomShape = aResult->shape();
1618 if (aGeomShape.get()) {
1619 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1620 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1621 mySketchMgr->activeSketch());
1626 //******************************************************
1627 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1629 return sketchReentranceMgr()->reentrantMessage();
1632 //******************************************************
1633 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1635 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1638 //******************************************************
1639 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1642 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1646 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1647 if (!aChoiceTitle.isEmpty()) {
1648 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1651 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1653 aPanel->setWindowTitle(aChoiceTitle);
1657 //******************************************************
1658 XGUI_Workshop* PartSet_Module::getWorkshop() const
1660 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1661 return aConnector->workshop();
1664 void PartSet_Module::setDefaultConstraintShown()
1666 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1667 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1668 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1671 //******************************************************
1672 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1677 //******************************************************
1678 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1679 myCustomPrs->disableCustomMode(theMode);
1682 //******************************************************
1683 void PartSet_Module::enableCustomModes() {
1684 myCustomPrs->enableCustomModes();