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"
50 #include <PartSetPlugin_Remove.h>
51 #include <PartSetPlugin_Part.h>
52 #include <PartSetPlugin_Duplicate.h>
54 #include <SketchPlugin_ConstraintCoincidence.h>
56 #include <ModuleBase_Operation.h>
57 #include <ModuleBase_OperationAction.h>
58 #include <ModuleBase_IViewer.h>
59 #include <ModuleBase_IViewWindow.h>
60 #include <ModuleBase_IPropertyPanel.h>
61 #include <ModuleBase_ISelectionActivate.h>
62 #include <ModuleBase_WidgetChoice.h>
63 #include <ModuleBase_WidgetEditor.h>
64 #include <ModuleBase_WidgetValidated.h>
65 #include <ModuleBase_Tools.h>
66 #include <ModuleBase_OperationFeature.h>
67 #include <ModuleBase_WidgetFactory.h>
68 #include <ModuleBase_OperationDescription.h>
69 #include <ModuleBase_ViewerPrs.h>
70 #include <ModelAPI_ResultField.h>
72 #include <ModelAPI_Object.h>
73 #include <ModelAPI_Events.h>
74 #include <ModelAPI_Validator.h>
75 #include <ModelAPI_Data.h>
76 #include <ModelAPI_Session.h>
77 #include <ModelAPI_ResultBody.h>
78 #include <ModelAPI_AttributeString.h>
79 #include <ModelAPI_AttributeSelectionList.h>
80 #include <ModelAPI_Tools.h>
81 #include <ModelAPI_ResultConstruction.h>
82 #include <ModelAPI_AttributeIntArray.h>
84 #include <GeomDataAPI_Point2D.h>
85 #include <GeomDataAPI_Point.h>
86 #include <GeomDataAPI_Dir.h>
88 #include <XGUI_ActiveControlMgr.h>
89 #include <XGUI_ActiveControlSelector.h>
90 #include <XGUI_ActionsMgr.h>
91 #include <XGUI_ContextMenuMgr.h>
92 #include <XGUI_CustomPrs.h>
93 #include <XGUI_DataModel.h>
94 #include <XGUI_Displayer.h>
95 #include <XGUI_ErrorMgr.h>
96 #include <XGUI_FacesPanelSelector.h>
97 #include <XGUI_ModuleConnector.h>
98 #include <XGUI_ObjectsBrowser.h>
99 #include <XGUI_OperationMgr.h>
100 #include <XGUI_PropertyPanel.h>
101 #include <XGUI_SelectionMgr.h>
102 #include <XGUI_Tools.h>
103 #include <XGUI_Workshop.h>
105 #include <SketchPlugin_ConstraintAngle.h>
106 #include <SketchPlugin_ConstraintLength.h>
107 #include <SketchPlugin_ConstraintDistance.h>
108 #include <SketchPlugin_ConstraintParallel.h>
109 #include <SketchPlugin_ConstraintPerpendicular.h>
110 #include <SketchPlugin_ConstraintRadius.h>
111 #include <SketchPlugin_Feature.h>
112 #include <SketchPlugin_Projection.h>
113 #include <SketchPlugin_Sketch.h>
115 #include <SketcherPrs_SymbolPrs.h>
116 #include <SketcherPrs_PositionMgr.h>
117 #include <SketcherPrs_Coincident.h>
118 #include <SketcherPrs_Tools.h>
120 #include <Events_Loop.h>
121 #include <Config_PropManager.h>
122 #include <Config_Keywords.h>
124 #include <AIS_Dimension.hxx>
125 #include <AIS_InteractiveObject.hxx>
126 #include <StdSelect_TypeOfFace.hxx>
127 #include <TopoDS_Vertex.hxx>
128 #include <TopoDS.hxx>
129 #include <TopoDS_Shape.hxx>
130 #include <BRep_Tool.hxx>
133 #include <QMouseEvent>
136 #include <QApplication>
137 #include <QMessageBox>
138 #include <QMainWindow>
142 #include <GeomAlgoAPI_FaceBuilder.h>
143 #include <GeomDataAPI_Dir.h>
145 #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);
232 Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
233 "Add parameter in parameters manager dialog",
234 Config_Prop::Shortcut, "Ctrl+A");
237 //******************************************************
238 PartSet_Module::~PartSet_Module()
241 delete myOverconstraintListener;
245 //******************************************************
246 void PartSet_Module::createFeatures()
248 ModuleBase_IModule::createFeatures();
249 myRoot = new PartSet_RootNode();
250 myRoot->setWorkshop(workshop());
254 //******************************************************
255 void PartSet_Module::storeSelection()
257 // cash is used only to restore selection, so it should be filled in storeSelection and
258 // after applying immediatelly cleared in restoreSelection
259 myCurrentSelection.clear();
260 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
263 //******************************************************
264 void PartSet_Module::restoreSelection()
266 // cash is used only to restore selection, so it should be filled in storeSelection and
267 // after applying immediatelly cleared in restoreSelection
268 sketchMgr()->restoreSelection(myCurrentSelection);
269 myCurrentSelection.clear();
272 //******************************************************
273 void PartSet_Module::registerValidators()
275 //Registering of validators
276 SessionPtr aMgr = ModelAPI_Session::get();
277 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
278 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
279 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
280 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
281 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
282 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
283 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
284 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
285 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
286 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
287 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
288 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
289 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
290 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
291 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
292 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
293 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
294 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
295 aFactory->registerValidator("PartSet_MultyTranslationSelection",
296 new PartSet_MultyTranslationSelection);
297 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
298 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
299 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
302 //******************************************************
303 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
304 const bool isToConnect)
306 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
309 //******************************************************
310 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
312 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
313 mySketchMgr->commitNestedSketch(theOperation);
315 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
316 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
317 overconstraintListener()->setActive(false);
319 /// Restart sketcher operations automatically
320 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
322 ModuleBase_OperationFeature* aFOperation =
323 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
324 if (aFOperation && !aFOperation->isEditOperation()) {
325 // the selection is cleared after commit the create operation
326 // in order to do not use the same selected objects in the restarted operation
327 // for common behaviour, the selection is cleared even if the operation is not restarted
328 getWorkshop()->selector()->clearSelection();
333 //******************************************************
334 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
336 /// Restart sketcher operations automatically
337 mySketchReentrantMgr->operationAborted(theOperation);
338 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
339 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
340 overconstraintListener()->setActive(false);
343 //******************************************************
344 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
346 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
349 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
350 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
352 ModuleBase_ModelWidget* aFilledWidget = 0;
353 bool aPostonedWidgetActivation = false;
355 FeaturePtr aFeature = aFOperation->feature();
356 /// Restart sketcher operations automatically
357 /// it is important to call method of sketch reentrant manager before filling of PP
358 /// because it fills some created feature attributes, these new values should be used
359 /// to fill the property panel
360 mySketchReentrantMgr->operationStarted(theOperation);
362 aWorkshop->fillPropertyPanel(aFOperation);
363 // filling the operation values by the current selection
364 // if the operation can be committed after the controls filling, the method perform should
365 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
366 bool isOperationCommitted = false;
367 if (!aFOperation->isEditOperation()) {
368 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
369 // if there is a greed attribute, automatic commit by preselection
370 // for this feature is prohibited
371 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
372 if (currentOperation() != aFOperation)
373 isOperationCommitted = true;
375 if (aGreedAttributeId.empty()) {
376 // a signal should be emitted before the next widget activation
377 // because, the activation of the next widget will give a focus to the widget.
378 // As a result the value of the widget is initialized.
379 // And commit may happens until the value is entered.
381 if (mySketchReentrantMgr->canBeCommittedByPreselection())
382 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
383 // activate the next obligatory widget
384 if (!isOperationCommitted)
385 aPropertyPanel->activateNextWidget(aFilledWidget);
388 else { // there is a greed widget
389 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
390 std::string aFirstAttributeId = aWidgets.front()->attributeID();
391 // activate next widget after greeded if it is the first widget in the panel
392 // else the first panel widget is already activated by operation start
393 if (aFirstAttributeId == aGreedAttributeId)
394 aPostonedWidgetActivation = true;
397 } if (!isOperationCommitted) {
398 aWorkshop->connectToPropertyPanel(true);
399 updateSketcherOnStart(aFOperation);
400 updatePresentationsOnStart(aFOperation);
402 // the objects of the current operation should be deactivated
403 QObjectPtrList anObjects;
404 anObjects.append(aFeature);
405 std::list<ResultPtr> aResults;
406 ModelAPI_Tools::allResults(aFeature, aResults);
407 std::list<ResultPtr>::const_iterator aIt;
408 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
409 anObjects.append(*aIt);
411 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
412 for (; anIt != aLast; anIt++)
413 aWorkshop->deactivateActiveObject(*anIt, false);
414 if (anObjects.size() > 0) {
415 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
416 aDisplayer->updateViewer();
418 /// state of command actions should be updated after displayed objects modification because
419 /// deactivation(for example) of objects may influence on selection in the viewer
420 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
421 workshop()->updateCommandStatus();
423 if (aPostonedWidgetActivation) {
424 // if the widget is an empty in the chain of activated widgets, the current operation
425 // is restarted. It should be performed after functionality of the operation starting
426 aPropertyPanel->activateNextWidget(aFilledWidget);
431 //******************************************************
432 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
434 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
435 mySketchMgr->startSketch(theOperation);
437 // It is switched off because of
438 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
439 //else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
440 // mySketchMgr->startNestedSketch(theOperation);
444 //******************************************************
445 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
447 ModuleBase_OperationFeature* aFOperation =
448 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
450 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
451 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
455 //******************************************************
456 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
458 ModuleBase_IModule::operationResumed(theOperation);
460 ModuleBase_OperationFeature* aFOperation =
461 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
463 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
464 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
468 //******************************************************
469 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
471 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
472 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
473 bool isModified = isModifiedArgs || isModifiedResults;
475 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
476 mySketchMgr->stopNestedSketch(theOperation);
478 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
479 setDefaultConstraintShown();
481 //VSV: Viewer is updated on feature update and redisplay
483 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
484 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
485 aDisplayer->updateViewer();
488 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
489 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
490 for (; anIt != aLast; anIt++) {
491 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
495 //******************************************************
496 ModuleBase_Operation* PartSet_Module::currentOperation() const
498 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
499 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
500 return anOpMgr->currentOperation();
503 //******************************************************
504 bool PartSet_Module::canUndo() const
506 bool aCanUndo = false;
507 SessionPtr aMgr = ModelAPI_Session::get();
508 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
509 aCanUndo = !aMgr->isOperation();
510 if (!aCanUndo) // check the enable state additionally by sketch manager
511 aCanUndo = aMgr->canUndo();
516 //******************************************************
517 bool PartSet_Module::canRedo() const
519 bool aCanRedo = false;
520 SessionPtr aMgr = ModelAPI_Session::get();
521 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
522 aCanRedo = !aMgr->isOperation();
523 if (!aCanRedo) // check the enable state additionally by sketch manager
524 aCanRedo = aMgr->canRedo();
529 //******************************************************
530 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
533 if (theActionId == "MOVE_CMD") {
534 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
536 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
537 // part features can not be moved in the history.
538 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
545 //******************************************************
546 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
548 // the sketch manager put the restriction to the objects erase
549 return mySketchMgr->canEraseObject(theObject);
552 //******************************************************
553 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
555 // the sketch manager put the restriction to the objects display
556 return mySketchMgr->canDisplayObject(theObject);
559 //******************************************************
560 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
561 const QString& theStartedOperationKind)
563 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
566 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
569 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
571 mySketchMgr->processHiddenObject(theObjects);
574 //******************************************************
575 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
577 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
579 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
580 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
581 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
582 if (isSketchOp || isNestedOp) {
583 // in active sketch operation it is possible to activate operation object in selection
584 // in the edit operation, e.g. points of the line can be moved when the line is edited
585 ModuleBase_OperationFeature* aFOperation =
586 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
587 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
592 //******************************************************
593 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
595 QMap<int, QAction*>& theMenuActions) const
597 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
600 //******************************************************
601 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
603 myMenuMgr->updateViewerMenu(theStdActions);
606 //******************************************************
607 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
609 bool isEnabledFixed = false;
610 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
611 mySketchReentrantMgr->isInternalEditActive())
612 isEnabledFixed = true;
613 return isEnabledFixed;
616 //******************************************************
617 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
619 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
620 if (anError.isEmpty())
621 anError = sketchMgr()->getFeatureError(theFeature);
626 //******************************************************
627 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
628 QStringList& theIds) const
630 myMenuMgr->grantedOperationIds(theOperation, theIds);
632 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
633 XGUI_Workshop* aWorkshop = getWorkshop();
634 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
638 //******************************************************
639 void PartSet_Module::activeSelectionModes(QIntList& theModes)
641 if (mySketchMgr->activeSketch().get())
642 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
644 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
647 //******************************************************
648 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
650 customSubShapesSelectionModes(theModes);
651 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
652 //myWorkshop->module()->activeSelectionModes(theModes);
655 //******************************************************
656 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
657 SelectMgr_ListOfFilter& theSelectionFilters)
659 bool isSketchActive = mySketchMgr->activeSketch().get();
661 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
662 mySelectionFilters.begin();
663 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
664 int aFilterType = aFiltersIt->first;
665 // do not add not participating filters in given parameters
666 if (!theFilterTypes.contains(aFilterType))
669 // using sketch filters only if sketch operation is active
670 if (!isSketchActive &&
671 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
674 // using filtering of construction results only from faces panel
675 if (aFilterType == SF_ResultGroupNameFilter)
678 theSelectionFilters.Append(aFiltersIt->second);
682 //******************************************************
683 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
685 if (theModes.contains(TopAbs_FACE))
686 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
687 if (theModes.contains(TopAbs_WIRE))
688 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
690 if (mySketchMgr->activeSketch().get())
691 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
694 //******************************************************
695 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
696 ObjectPtr& theObject, AttributePtr& theAttribute)
698 ObjectPtr anObject = theSelected->object();
699 GeomShapePtr aShape = theSelected->shape();
701 theAttribute = findAttribute(anObject, aShape);
702 // TODO: try to create result if object is an external object
703 theObject = anObject;
706 //******************************************************
707 bool PartSet_Module::isMouseOverWindow()
709 return mySketchMgr->isMouseOverWindow();
712 //******************************************************
713 bool PartSet_Module::isSketchNeutralPointActivated() const
715 bool isNeutralPoint = true;
716 if (sketchReentranceMgr()->isInternalEditActive())
717 isNeutralPoint = false;
718 if (myIsOperationIsLaunched)
719 isNeutralPoint = false;
721 return isNeutralPoint;
724 //******************************************************
725 void PartSet_Module::closeDocument()
727 myActivePartIndex = QModelIndex();
728 SketcherPrs_PositionMgr::get()->clearAll();
731 //******************************************************
732 void PartSet_Module::clearViewer()
734 myCustomPrs->clearPrs();
736 XGUI_Workshop* aWorkshop = getWorkshop();
737 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
738 aDisplayer->deactivateSelectionFilters(false);
741 //******************************************************
742 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
744 ModuleBase_OperationFeature* aFOperation =
745 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
749 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
750 // we have to manually activate the sketch label in edit mode
751 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
752 aPanel->activateWidget(aPanel->modelWidgets().first());
755 //******************************************************
756 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
757 QList<ModuleBase_ModelWidget*>& theWidgets) const
759 bool aProcessed = false;
761 ModuleBase_OperationFeature* aFOperation =
762 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
763 XGUI_Workshop* aWorkshop = getWorkshop();
764 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
765 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
766 ModuleBase_ISelection* aSelection = workshop()->selection();
767 // click on a point in sketch leads here with the point is highlighted, not yet selected
768 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
769 if (aPreselection.size() == 1) {
770 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
771 ObjectPtr anObject = aSelectedPrs->object();
773 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
774 FeaturePtr anOpFeature = aFOperation->feature();
775 GeomShapePtr aShape = aSelectedPrs->shape();
776 // click on the digit of dimension constrain comes here
777 // with an empty shape, so we need the check
778 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
779 // if feature has only one result and shape of result is equal to selected shape
780 // this attribute is not processed. It is a case of Sketch Point.
781 if (aFeature->results().size() == 1) {
782 ResultPtr aResult = aFeature->results().front();
783 if (aResult.get() && aResult->shape()->isEqual(aShape))
786 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
787 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
788 mySketchMgr->activeSketch());
789 if (anAttribute.get()) {
790 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
791 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
793 const std::string anAttributeId = anAttribute->id();
794 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
796 theWidgets = aFactory.getModelWidgets();
797 // it is possible that the point does not present in XML definition,
798 // in this case, we assume that it is not processed by this module
799 // e.g. "Intersection point" feature
800 aProcessed = !theWidgets.isEmpty();
808 //******************************************************
809 void PartSet_Module::onSelectionChanged()
811 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
815 bool isSketcherOp = false;
816 // An edit operation is enable only if the current opeation is the sketch operation
817 if (mySketchMgr->activeSketch()) {
818 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
819 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
822 // Editing of constraints can be done on selection
823 ModuleBase_ISelection* aSelect = myWorkshop->selection();
824 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
825 if (aSelected.size() == 1) {
826 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
827 ObjectPtr aObject = aPrs->object();
828 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
830 std::string aId = aFeature->getKind();
831 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
832 (aId == SketchPlugin_ConstraintLength::ID()) ||
833 (aId == SketchPlugin_ConstraintDistance::ID()) ||
834 (aId == SketchPlugin_ConstraintAngle::ID())) {
835 editFeature(aFeature);
842 //******************************************************
843 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
845 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
846 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
847 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
850 //******************************************************
851 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
853 Config_WidgetAPI* theWidgetApi)
855 ModuleBase_IWorkshop* aWorkshop = workshop();
856 XGUI_Workshop* aXUIWorkshop = getWorkshop();
857 ModuleBase_ModelWidget* aWgt = NULL;
858 if (theType == "sketch-start-label") {
859 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
860 theWidgetApi, myHasConstraintShown);
861 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
862 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
863 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
864 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
865 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
866 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
867 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
868 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
870 } else if (theType == "sketch-2dpoint_selector") {
871 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
873 aPointWgt->setSketch(mySketchMgr->activeSketch());
874 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
876 }else if (theType == "sketch-2dpoint_flyout_selector") {
877 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
879 aPointWgt->setSketch(mySketchMgr->activeSketch());
880 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
882 } else if (theType == "sketch_shape_selector") {
883 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
884 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
885 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
886 aWgt = aShapeSelectorWgt;
887 } else if (theType == "sketch_multi_selector") {
888 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
889 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
890 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
891 aWgt = aShapeSelectorWgt;
893 else if (theType == "sketch_feature_point_selector") {
894 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
895 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
896 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
897 aWgt = aPointSelectorWgt;
899 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
900 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
901 } else if (theType == "export_file_selector") {
902 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
903 } else if (theType == "sketch_launcher") {
904 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
905 } else if (theType == "module_choice") {
906 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
907 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
908 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
913 //******************************************************
914 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
916 ModuleBase_ModelWidget* anActiveWidget = 0;
918 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
920 return anActiveWidget;
922 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
924 return anActiveWidget;
926 return aPanel->activeWidget(true);
929 //******************************************************
930 bool PartSet_Module::deleteObjects()
932 bool isProcessed = false;
934 XGUI_Workshop* aWorkshop = getWorkshop();
935 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
937 //SessionPtr aMgr = ModelAPI_Session::get();
938 // 1. check whether the delete should be processed in the module
939 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
940 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
941 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
942 if (isSketchOp || isNestedOp) {
944 // 2. find selected presentations
945 // selected objects should be collected before the current operation abort because
946 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
947 ModuleBase_ISelection* aSel = workshop()->selection();
948 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
949 // if there are no selected objects in the viewer, that means that the selection in another
950 // place cased this method. It is necessary to return the false value to understande in above
951 // method that delete is not processed
952 if (aSelectedObj.count() == 0)
955 // avoid delete of the objects, which are not belong to the current sketch
956 // in order to do not delete results of other sketches
957 QObjectPtrList aSketchObjects;
958 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
959 for ( ; anIt != aLast; anIt++) {
960 ObjectPtr anObject = *anIt;
961 if (mySketchMgr->isObjectOfSketch(anObject)) {
962 // sketch feature should be used in this list because workshop deletes features only
963 // results are skipped
964 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
965 aSketchObjects.append(aSketchFeature);
968 // if the selection contains only local selected presentations from other sketches,
969 // the Delete operation should not be done at all
970 if (aSketchObjects.size() == 0)
973 // 3. start operation
974 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
975 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
977 // the active nested sketch operation should be aborted unconditionally
978 // the Delete action should be additionally granted for the Sketch operation
979 // in order to do not abort/commit it
981 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
982 return true; // the objects are processed but can not be deleted
984 anOpMgr->startOperation(anOpAction);
986 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
987 // the problem is in AIS Dimensions recompute
988 // if a line and the dim are removed, line is the first
989 // it causes the AIS recompute, where the base line is null,
990 // the result is empty AIS in the viewer
991 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
993 // 4. delete features
994 // sketch feature should be skipped, only sub-features can be removed
995 // when sketch operation is active
996 aWorkshop->deleteFeatures(aSketchObjects);
998 anOpMgr->commitOperation();
1003 //******************************************************
1004 void PartSet_Module::editFeature(FeaturePtr theFeature)
1006 storeConstraintsState(theFeature->getKind());
1007 ModuleBase_IModule::editFeature(theFeature);
1010 //******************************************************
1011 bool PartSet_Module::canCommitOperation() const
1016 //******************************************************
1017 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1019 myIsOperationIsLaunched = true;
1020 storeConstraintsState(theCmdId.toStdString());
1021 updateConstraintsState(theCmdId.toStdString());
1023 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1025 myIsOperationIsLaunched = false;
1028 //******************************************************
1029 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1031 if (myWorkshop->currentOperation() &&
1032 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1033 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1034 mySketchMgr->showConstraintStates();
1035 myHasConstraintShown = aShownStates;
1039 //******************************************************
1040 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1042 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1043 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1044 // Show constraints if a constraint was anOperation
1045 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1046 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1047 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1048 myHasConstraintShown[PartSet_Tools::Expressions]);
1052 //******************************************************
1053 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1055 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1056 if (!anAIS.IsNull()) {
1057 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1058 if (aFeature.get()) {
1059 bool aToUseZLayer = false;
1060 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1061 aToUseZLayer = true;
1063 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1064 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1067 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1068 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1069 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1071 aCtx->SetZLayer(anAIS, myVisualLayerId);
1077 //******************************************************
1078 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1081 // it should be recomputed in order to disappear in the viewer if the corresponded object
1083 //if (myCustomPrs->isActive())
1084 // myCustomPrs->redisplay(theObject, false);
1087 //******************************************************
1088 void PartSet_Module::onViewTransformed(int theTrsfType)
1090 // Set length of arrows constant in pixel size
1091 // if the operation is panning or rotate or panglobal then do nothing
1092 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1094 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1095 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1096 if (aContext.IsNull())
1099 //Handle(V3d_View) aView = aViewer->activeView();
1101 XGUI_Workshop* aWorkshop = getWorkshop();
1102 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1103 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1104 Handle(V3d_View) aView;
1106 for (aV3dViewer->InitDefinedViews();
1107 aV3dViewer->MoreDefinedViews();
1108 aV3dViewer->NextDefinedViews()) {
1109 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1110 double aS = aV->Scale();
1119 bool isModified = false;
1120 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1121 if (aCurrentOperation &&
1122 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1123 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1124 (aCurrentOperation->id() == "Measurement")))
1126 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1128 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1129 SketcherPrs_Tools::setArrowSize(aLen);
1130 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1131 aViewer->SetScale(aViewer->activeView(), aCurScale);
1133 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1134 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1136 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1137 foreach(AISObjectPtr aAIS, aPrsList) {
1138 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1140 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1141 if (!aDim.IsNull()) {
1142 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1143 aContext->Redisplay(aDim, false);
1148 aDisplayer->updateViewer();
1153 //******************************************************
1154 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1156 return myCustomPrs->isActive(theFlag);
1159 //******************************************************
1160 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1161 const ModuleBase_CustomizeFlag& theFlag,
1162 const bool theUpdateViewer)
1164 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1167 //******************************************************
1168 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1169 const bool theUpdateViewer)
1171 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1174 //******************************************************
1175 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1176 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1178 bool aCustomized = false;
1180 XGUI_Workshop* aWorkshop = getWorkshop();
1181 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1182 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1186 if (!theResult.get()) {
1187 std::vector<int> aColor;
1188 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1189 if (!aColor.empty()) {
1190 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1193 // customize dimentional constrains
1194 sketchMgr()->customizePresentation(anObject);
1199 //******************************************************
1200 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1201 AISObjectPtr thePrs,
1202 GeomCustomPrsPtr theCustomPrs)
1204 bool aCustomized = false;
1206 XGUI_Workshop* aWorkshop = getWorkshop();
1207 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1208 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1212 std::vector<int> aColor;
1213 bool aUseCustomColor = true;
1214 if (aUseCustomColor)
1215 myOverconstraintListener->getCustomColor(anObject, aColor);
1216 // customize sketch symbol presentation
1217 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1218 if (!anAISIO.IsNull()) {
1219 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1220 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1221 if (!aPrs.IsNull()) {
1222 aPrs->SetCustomColor(aColor);
1225 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1226 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1227 if (!aPrs.IsNull()) {
1228 aPrs->SetCustomColor(aColor);
1233 // customize sketch dimension constraint presentation
1235 if (!aColor.empty()) { // otherwise presentation has the default color
1236 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1242 //******************************************************
1243 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1244 const bool theUpdateViewer)
1246 bool isRedisplayed = false;
1247 if (myCustomPrs->isActive(theFlag))
1248 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1250 return isRedisplayed;
1253 //******************************************************
1254 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1256 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1258 QLabel* aLabel = aOB->activeDocLabel();
1259 aLabel->installEventFilter(myMenuMgr);
1260 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1261 SLOT(onActiveDocPopup(const QPoint&)));
1262 aOB->treeView()->setExpandsOnDoubleClick(false);
1263 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1264 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1266 Events_Loop* aLoop = Events_Loop::loop();
1267 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1271 //******************************************************
1272 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1274 SessionPtr aMgr = ModelAPI_Session::get();
1275 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1277 XGUI_Workshop* aWorkshop = getWorkshop();
1278 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1280 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1283 aMenu.addAction(aActivatePartAction);
1284 aMenu.exec(aHeader->mapToGlobal(thePnt));
1287 //******************************************************
1288 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1290 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1292 return mySketchMgr->createPresentation(aResult);
1294 FieldStepPtr aStep =
1295 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1297 return new PartSet_FieldStepPrs(aStep);
1300 return Handle(AIS_InteractiveObject)();
1303 //******************************************************
1304 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1307 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1309 /// If last line finished on vertex the lines creation sequence has to be break
1310 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1312 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1313 // if there is an active widget, find the presented object in it
1314 if (!anActiveWidget)
1315 anActiveWidget = aPanel->preselectionWidget();
1317 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1319 if (aWidgetValidated)
1320 anObject = aWidgetValidated->findPresentedObject(theAIS);
1326 //******************************************************
1327 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1329 bool aCanBeShaged = true;
1331 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1333 aCanBeShaged = false;
1335 return aCanBeShaged;
1338 //******************************************************
1339 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1341 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1342 int aSelected = aObjects.size();
1343 SessionPtr aMgr = ModelAPI_Session::get();
1344 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1346 bool hasResult = false;
1347 bool hasFeature = false;
1348 bool hasParameter = false;
1349 bool hasCompositeOwner = false;
1350 bool hasResultInHistory = false;
1351 bool hasFolder = false;
1352 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1353 hasCompositeOwner, hasResultInHistory, hasFolder);
1355 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1356 if (aSelected == 1) {
1357 ObjectPtr aObject = aObjects.first();
1359 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1360 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1361 bool isPart = aPart.get() ||
1362 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1364 DocumentPtr aPartDoc;
1366 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1368 if (aPart.get()) // this may be null is Part feature is disabled
1369 aPartDoc = aPart->partDoc();
1371 theMenu->addAction(aActivatePartAction);
1372 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1374 } else if (aObject->document() == aMgr->activeDocument()) {
1375 if (hasParameter || hasFeature) {
1376 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1377 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1378 if (aCurrentOp && aFeature.get()) {
1379 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1380 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1387 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1388 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1389 theMenu->addSeparator();
1392 bool aNotDeactivate = (aCurrentOp == 0);
1393 if (!aNotDeactivate) {
1394 aActivatePartAction->setEnabled(false);
1398 //******************************************************
1399 #define EXPAND_PARENT(OBJ) \
1400 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1401 if (aObjIndex.isValid()) { \
1402 QModelIndex aParent = aObjIndex.parent(); \
1403 int aCount = aDataModel->rowCount(aParent); \
1405 aTreeView->setExpanded(aParent, true); \
1408 //******************************************************
1409 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1411 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1412 // Do not change activation of parts if an operation active
1413 static QStringList aAllowActivationList;
1414 if (aAllowActivationList.isEmpty())
1415 aAllowActivationList <<
1416 QString(PartSetPlugin_Part::ID().c_str()) <<
1417 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1418 QString(PartSetPlugin_Remove::ID().c_str());
1419 if (myWorkshop->currentOperation() &&
1420 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1422 XGUI_Workshop* aWorkshop = getWorkshop();
1423 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1424 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1425 QPalette aPalet = aLabel->palette();
1427 SessionPtr aMgr = ModelAPI_Session::get();
1428 DocumentPtr aActiveDoc = aMgr->activeDocument();
1430 // Clear active part index if there is no Part documents
1431 // It could be not null if document was closed and opened a new
1432 // without closeDocument call
1433 if (aMgr->allOpenedDocuments().size() <= 1)
1434 myActivePartIndex = QModelIndex();
1436 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1437 QModelIndex aOldActive = myActivePartIndex;
1438 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1439 bool needUpdate = false;
1440 if (myActivePartIndex.isValid()) {
1441 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1443 aTreeView->setExpanded(myActivePartIndex, true);
1445 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1446 aTreeView->setExpanded(aOldActive, false);
1448 aLabel->setPalette(aPalet);
1449 aWorkshop->updateCommandStatus();
1451 // Update displayed objects in order to update active color
1452 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1453 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1455 bool aUpdateViewer = false;
1456 foreach(ObjectPtr aObj, aObjects) {
1457 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1458 aObj->isDisabled() || (!aObj->isDisplayed());
1460 aDisplayer->redisplay(aObj, false);
1461 aUpdateViewer = true;
1465 aDisplayer->updateViewer();
1466 // Update tree items if they are expanded
1468 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1470 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1471 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1472 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1473 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1475 ObjectPtr aConstrObj;
1476 ObjectPtr aResultObj;
1477 std::set<ObjectPtr>::const_iterator aIt;
1478 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1479 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1480 ObjectPtr aObject = (*aIt);
1481 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1482 && (aObject->document() != aRootDoc))
1483 aResultObj = aObject;
1484 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1485 && (aObject->document() != aRootDoc))
1486 aConstrObj = aObject;
1487 if (aResultObj.get() && aConstrObj.get())
1491 if (aResultObj.get() || aConstrObj.get()) {
1492 XGUI_Workshop* aWorkshop = getWorkshop();
1493 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1494 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1496 if (aResultObj.get()) {
1497 EXPAND_PARENT(aResultObj)
1499 if (aConstrObj.get()) {
1500 EXPAND_PARENT(aConstrObj)
1504 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1505 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1506 if (aSketch.get()) {
1507 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1508 if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1509 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1514 //******************************************************
1515 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1517 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1519 SessionPtr aMgr = ModelAPI_Session::get();
1520 if (!theIndex.isValid()) {
1521 // It seems that this code is obsolete
1522 //aMgr->setActiveDocument(aMgr->moduleDocument());
1525 if (theIndex.column() != 1) // Use only first column
1528 XGUI_Workshop* aWorkshop = getWorkshop();
1529 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1530 // De not use non editable Indexes
1531 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1533 ObjectPtr aObj = aDataModel->object(theIndex);
1535 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1536 if (!aPart.get()) { // Probably this is Feature
1537 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1538 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1539 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1542 if (aPart.get()) { // if this is a part
1543 if (aPart->partDoc() == aMgr->activeDocument()) {
1544 myMenuMgr->activatePartSet();
1546 myMenuMgr->activatePart(aPart);
1551 //******************************************************
1552 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1554 // z layer is created for all started operations in order to visualize operation AIS presentation
1556 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1557 if (aContext.IsNull())
1560 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1561 if (myVisualLayerId == 0) {
1562 if (myVisualLayerId == 0)
1563 aViewer->AddZLayer(myVisualLayerId);
1565 TColStd_SequenceOfInteger aZList;
1566 aViewer->GetAllZLayers(aZList);
1567 bool aFound = false;
1568 for (int i = 1; i <= aZList.Length(); i++) {
1569 if (aZList(i) == myVisualLayerId) {
1575 aViewer->AddZLayer(myVisualLayerId);
1577 // if there is an active operation with validated widget,
1578 // the filters of this widget should be activated in the created view
1579 myWorkshop->selectionActivate()->updateSelectionFilters();
1580 myWorkshop->selectionActivate()->updateSelectionModes();
1583 //******************************************************
1584 void PartSet_Module::widgetStateChanged(int thePreviousState)
1586 mySketchMgr->widgetStateChanged(thePreviousState);
1589 //******************************************************
1590 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1592 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1595 //******************************************************
1596 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1598 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1599 mySketchMgr->stopSketch(theOperation);
1603 //******************************************************
1604 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1606 GeomShapePtr aGeomShape;
1608 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1609 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1610 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1615 //******************************************************
1616 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1617 const GeomShapePtr& theGeomShape)
1619 AttributePtr anAttribute;
1620 GeomShapePtr aGeomShape = theGeomShape;
1621 if (!aGeomShape.get()) {
1622 // processing shape of result, e.g. sketch circle center is selected, this is a result
1623 // the geom shape is empty, the shape of result should be used
1624 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1625 if (aResult.get()) {
1626 aGeomShape = aResult->shape();
1630 if (aGeomShape.get()) {
1631 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1632 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1633 mySketchMgr->activeSketch());
1638 //******************************************************
1639 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1641 return sketchReentranceMgr()->reentrantMessage();
1644 //******************************************************
1645 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1647 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1650 //******************************************************
1651 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1654 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1658 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1659 if (!aChoiceTitle.isEmpty()) {
1660 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1663 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1665 aPanel->setWindowTitle(aChoiceTitle);
1669 //******************************************************
1670 XGUI_Workshop* PartSet_Module::getWorkshop() const
1672 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1673 return aConnector->workshop();
1676 void PartSet_Module::setDefaultConstraintShown()
1678 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1679 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1680 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1683 //******************************************************
1684 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1689 //******************************************************
1690 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1691 myCustomPrs->disableCustomMode(theMode);
1694 //******************************************************
1695 void PartSet_Module::enableCustomModes() {
1696 myCustomPrs->enableCustomModes();