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_IViewer.h>
58 #include <ModuleBase_IViewWindow.h>
59 #include <ModuleBase_IPropertyPanel.h>
60 #include <ModuleBase_ISelectionActivate.h>
61 #include <ModuleBase_WidgetChoice.h>
62 #include <ModuleBase_WidgetEditor.h>
63 #include <ModuleBase_WidgetValidated.h>
64 #include <ModuleBase_Tools.h>
65 #include <ModuleBase_OperationFeature.h>
66 #include <ModuleBase_WidgetFactory.h>
67 #include <ModuleBase_OperationDescription.h>
68 #include <ModuleBase_ViewerPrs.h>
69 #include <ModelAPI_ResultField.h>
71 #include <ModelAPI_Object.h>
72 #include <ModelAPI_Events.h>
73 #include <ModelAPI_Validator.h>
74 #include <ModelAPI_Data.h>
75 #include <ModelAPI_Session.h>
76 #include <ModelAPI_ResultBody.h>
77 #include <ModelAPI_AttributeString.h>
78 #include <ModelAPI_AttributeSelectionList.h>
79 #include <ModelAPI_Tools.h>
80 #include <ModelAPI_ResultConstruction.h>
81 #include <ModelAPI_AttributeIntArray.h>
83 #include <GeomDataAPI_Point2D.h>
84 #include <GeomDataAPI_Point.h>
85 #include <GeomDataAPI_Dir.h>
87 #include <XGUI_ActiveControlMgr.h>
88 #include <XGUI_ActiveControlSelector.h>
89 #include <XGUI_ActionsMgr.h>
90 #include <XGUI_ContextMenuMgr.h>
91 #include <XGUI_CustomPrs.h>
92 #include <XGUI_DataModel.h>
93 #include <XGUI_Displayer.h>
94 #include <XGUI_ErrorMgr.h>
95 #include <XGUI_FacesPanelSelector.h>
96 #include <XGUI_ModuleConnector.h>
97 #include <XGUI_ObjectsBrowser.h>
98 #include <XGUI_OperationMgr.h>
99 #include <XGUI_PropertyPanel.h>
100 #include <XGUI_SelectionMgr.h>
101 #include <XGUI_Tools.h>
102 #include <XGUI_Workshop.h>
104 #include <SketchPlugin_ConstraintAngle.h>
105 #include <SketchPlugin_ConstraintLength.h>
106 #include <SketchPlugin_ConstraintDistance.h>
107 #include <SketchPlugin_ConstraintParallel.h>
108 #include <SketchPlugin_ConstraintPerpendicular.h>
109 #include <SketchPlugin_ConstraintRadius.h>
110 #include <SketchPlugin_Feature.h>
111 #include <SketchPlugin_Projection.h>
112 #include <SketchPlugin_Sketch.h>
114 #include <SketcherPrs_SymbolPrs.h>
115 #include <SketcherPrs_PositionMgr.h>
116 #include <SketcherPrs_Coincident.h>
117 #include <SketcherPrs_Tools.h>
119 #include <Events_Loop.h>
120 #include <Config_PropManager.h>
121 #include <Config_Keywords.h>
123 #include <AIS_Dimension.hxx>
124 #include <AIS_InteractiveObject.hxx>
125 #include <StdSelect_TypeOfFace.hxx>
126 #include <TopoDS_Vertex.hxx>
127 #include <TopoDS.hxx>
128 #include <TopoDS_Shape.hxx>
129 #include <BRep_Tool.hxx>
132 #include <QMouseEvent>
135 #include <QApplication>
136 #include <QMessageBox>
137 #include <QMainWindow>
141 #include <GeomAlgoAPI_FaceBuilder.h>
142 #include <GeomDataAPI_Dir.h>
144 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
146 /*!Create and return new instance of XGUI_Module*/
147 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
149 return new PartSet_Module(theWshop);
152 //******************************************************
153 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
154 : ModuleBase_IModule(theWshop),
157 myIsOperationIsLaunched(false)
159 new PartSet_IconFactory(this);
161 mySketchMgr = new PartSet_SketcherMgr(this);
162 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
164 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
165 XGUI_Workshop* aWorkshop = aConnector->workshop();
167 ModuleBase_IViewer* aViewer = theWshop->viewer();
168 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
169 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
170 connect(aViewer, SIGNAL(viewTransformed(int)),
171 SLOT(onViewTransformed(int)));
172 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
173 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
174 myMenuMgr = new PartSet_MenuMgr(this);
175 myCustomPrs = new PartSet_CustomPrs(theWshop);
177 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
179 Events_Loop* aLoop = Events_Loop::loop();
180 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
181 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
183 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
184 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
185 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
186 std::set<std::string> aCRGroupNames;
187 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
188 aCRFilter->setGroupNames(aCRGroupNames);
189 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
191 setDefaultConstraintShown();
193 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
194 "Reference shape wireframe color in operation", Config_Prop::Color,
195 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
196 Config_PropManager::registerProp("Visualization", "operation_result_color",
197 "Result shape wireframe color in operation", Config_Prop::Color,
198 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
199 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
200 "Multi selector item color in operation", Config_Prop::Color,
201 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
202 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
203 "Color of removed feature in operation", Config_Prop::Color,
204 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
205 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
206 "Color of sketch plane", Config_Prop::Color,
207 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
209 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
210 "Hidden faces transparency",
211 Config_Prop::DblSpin,
213 std::ostringstream aStream;
214 aStream << SketcherPrs_Tools::getDefaultArrowSize();
215 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
216 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
218 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
219 Config_Prop::String, "Times-bold");
223 aStream << SketcherPrs_Tools::getDefaultTextHeight();
224 Config_PropManager::registerProp("Visualization", "dimension_value_size",
225 "Dimension value size", Config_Prop::IntSpin, aStream.str());
227 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
229 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
231 Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
232 "Add parameter in parameters manager dialog",
233 Config_Prop::Shortcut, "Ctrl+A");
236 //******************************************************
237 PartSet_Module::~PartSet_Module()
240 delete myOverconstraintListener;
244 //******************************************************
245 void PartSet_Module::createFeatures()
247 ModuleBase_IModule::createFeatures();
248 myRoot = new PartSet_RootNode();
249 myRoot->setWorkshop(workshop());
253 //******************************************************
254 void PartSet_Module::storeSelection()
256 // cash is used only to restore selection, so it should be filled in storeSelection and
257 // after applying immediatelly cleared in restoreSelection
258 myCurrentSelection.clear();
259 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
262 //******************************************************
263 void PartSet_Module::restoreSelection()
265 // cash is used only to restore selection, so it should be filled in storeSelection and
266 // after applying immediatelly cleared in restoreSelection
267 sketchMgr()->restoreSelection(myCurrentSelection);
268 myCurrentSelection.clear();
271 //******************************************************
272 void PartSet_Module::registerValidators()
274 //Registering of validators
275 SessionPtr aMgr = ModelAPI_Session::get();
276 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
277 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
278 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
279 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
280 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
281 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
282 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
283 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
284 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
285 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
286 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
287 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
288 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
289 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
290 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
291 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
292 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
293 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
294 aFactory->registerValidator("PartSet_MultyTranslationSelection",
295 new PartSet_MultyTranslationSelection);
296 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
297 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
298 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
301 //******************************************************
302 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
303 const bool isToConnect)
305 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
308 //******************************************************
309 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
311 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
312 mySketchMgr->commitNestedSketch(theOperation);
314 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
315 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
316 overconstraintListener()->setActive(false);
318 /// Restart sketcher operations automatically
319 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
321 ModuleBase_OperationFeature* aFOperation =
322 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
323 if (aFOperation && !aFOperation->isEditOperation()) {
324 // the selection is cleared after commit the create operation
325 // in order to do not use the same selected objects in the restarted operation
326 // for common behaviour, the selection is cleared even if the operation is not restarted
327 getWorkshop()->selector()->clearSelection();
332 //******************************************************
333 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
335 /// Restart sketcher operations automatically
336 mySketchReentrantMgr->operationAborted(theOperation);
337 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
338 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
339 overconstraintListener()->setActive(false);
342 //******************************************************
343 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
345 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
348 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
349 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
351 ModuleBase_ModelWidget* aFilledWidget = 0;
352 bool aPostonedWidgetActivation = false;
354 FeaturePtr aFeature = aFOperation->feature();
355 /// Restart sketcher operations automatically
356 /// it is important to call method of sketch reentrant manager before filling of PP
357 /// because it fills some created feature attributes, these new values should be used
358 /// to fill the property panel
359 mySketchReentrantMgr->operationStarted(theOperation);
361 aWorkshop->fillPropertyPanel(aFOperation);
362 // filling the operation values by the current selection
363 // if the operation can be committed after the controls filling, the method perform should
364 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
365 bool isOperationCommitted = false;
366 if (!aFOperation->isEditOperation()) {
367 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
368 // if there is a greed attribute, automatic commit by preselection
369 // for this feature is prohibited
370 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
371 if (currentOperation() != aFOperation)
372 isOperationCommitted = true;
374 if (aGreedAttributeId.empty()) {
375 // a signal should be emitted before the next widget activation
376 // because, the activation of the next widget will give a focus to the widget.
377 // As a result the value of the widget is initialized.
378 // And commit may happens until the value is entered.
380 if (mySketchReentrantMgr->canBeCommittedByPreselection())
381 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
382 // activate the next obligatory widget
383 if (!isOperationCommitted)
384 aPropertyPanel->activateNextWidget(aFilledWidget);
387 else { // there is a greed widget
388 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
389 std::string aFirstAttributeId = aWidgets.front()->attributeID();
390 // activate next widget after greeded if it is the first widget in the panel
391 // else the first panel widget is already activated by operation start
392 if (aFirstAttributeId == aGreedAttributeId)
393 aPostonedWidgetActivation = true;
396 } if (!isOperationCommitted) {
397 aWorkshop->connectToPropertyPanel(true);
398 updateSketcherOnStart(aFOperation);
399 updatePresentationsOnStart(aFOperation);
401 // the objects of the current operation should be deactivated
402 QObjectPtrList anObjects;
403 anObjects.append(aFeature);
404 std::list<ResultPtr> aResults;
405 ModelAPI_Tools::allResults(aFeature, aResults);
406 std::list<ResultPtr>::const_iterator aIt;
407 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
408 anObjects.append(*aIt);
410 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
411 for (; anIt != aLast; anIt++)
412 aWorkshop->deactivateActiveObject(*anIt, false);
413 if (anObjects.size() > 0) {
414 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
415 aDisplayer->updateViewer();
417 /// state of command actions should be updated after displayed objects modification because
418 /// deactivation(for example) of objects may influence on selection in the viewer
419 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
420 workshop()->updateCommandStatus();
422 if (aPostonedWidgetActivation) {
423 // if the widget is an empty in the chain of activated widgets, the current operation
424 // is restarted. It should be performed after functionality of the operation starting
425 aPropertyPanel->activateNextWidget(aFilledWidget);
430 //******************************************************
431 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
433 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
434 mySketchMgr->startSketch(theOperation);
436 // It is switched off because of
437 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
438 //else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
439 // mySketchMgr->startNestedSketch(theOperation);
443 //******************************************************
444 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
446 ModuleBase_OperationFeature* aFOperation =
447 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
449 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
450 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
454 //******************************************************
455 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
457 ModuleBase_IModule::operationResumed(theOperation);
459 ModuleBase_OperationFeature* aFOperation =
460 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
462 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
463 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
467 //******************************************************
468 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
470 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
471 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
472 bool isModified = isModifiedArgs || isModifiedResults;
474 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
475 mySketchMgr->stopNestedSketch(theOperation);
477 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
478 setDefaultConstraintShown();
480 //VSV: Viewer is updated on feature update and redisplay
482 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
483 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
484 aDisplayer->updateViewer();
487 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
488 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
489 for (; anIt != aLast; anIt++) {
490 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
494 //******************************************************
495 ModuleBase_Operation* PartSet_Module::currentOperation() const
497 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
498 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
499 return anOpMgr->currentOperation();
502 //******************************************************
503 bool PartSet_Module::canUndo() const
505 bool aCanUndo = false;
506 SessionPtr aMgr = ModelAPI_Session::get();
507 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
508 aCanUndo = !aMgr->isOperation();
509 if (!aCanUndo) // check the enable state additionally by sketch manager
510 aCanUndo = aMgr->canUndo();
515 //******************************************************
516 bool PartSet_Module::canRedo() const
518 bool aCanRedo = false;
519 SessionPtr aMgr = ModelAPI_Session::get();
520 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
521 aCanRedo = !aMgr->isOperation();
522 if (!aCanRedo) // check the enable state additionally by sketch manager
523 aCanRedo = aMgr->canRedo();
528 //******************************************************
529 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
532 if (theActionId == "MOVE_CMD") {
533 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
535 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
536 // part features can not be moved in the history.
537 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
544 //******************************************************
545 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
547 // the sketch manager put the restriction to the objects erase
548 return mySketchMgr->canEraseObject(theObject);
551 //******************************************************
552 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
554 // the sketch manager put the restriction to the objects display
555 return mySketchMgr->canDisplayObject(theObject);
558 //******************************************************
559 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
560 const QString& theStartedOperationKind)
562 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
565 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
568 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
570 mySketchMgr->processHiddenObject(theObjects);
573 //******************************************************
574 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
576 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
578 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
579 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
580 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
581 if (isSketchOp || isNestedOp) {
582 // in active sketch operation it is possible to activate operation object in selection
583 // in the edit operation, e.g. points of the line can be moved when the line is edited
584 ModuleBase_OperationFeature* aFOperation =
585 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
586 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
591 //******************************************************
592 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
594 QMap<int, QAction*>& theMenuActions) const
596 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
599 //******************************************************
600 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
602 myMenuMgr->updateViewerMenu(theStdActions);
605 //******************************************************
606 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
608 bool isEnabledFixed = false;
609 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
610 mySketchReentrantMgr->isInternalEditActive())
611 isEnabledFixed = true;
612 return isEnabledFixed;
615 //******************************************************
616 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
618 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
619 if (anError.isEmpty())
620 anError = sketchMgr()->getFeatureError(theFeature);
625 //******************************************************
626 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
627 QStringList& theIds) const
629 myMenuMgr->grantedOperationIds(theOperation, theIds);
631 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
632 XGUI_Workshop* aWorkshop = getWorkshop();
633 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
637 //******************************************************
638 void PartSet_Module::activeSelectionModes(QIntList& theModes)
640 if (mySketchMgr->activeSketch().get())
641 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
643 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
646 //******************************************************
647 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
649 customSubShapesSelectionModes(theModes);
650 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
651 //myWorkshop->module()->activeSelectionModes(theModes);
654 //******************************************************
655 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
656 SelectMgr_ListOfFilter& theSelectionFilters)
658 bool isSketchActive = mySketchMgr->activeSketch().get();
660 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
661 mySelectionFilters.begin();
662 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
663 int aFilterType = aFiltersIt->first;
664 // do not add not participating filters in given parameters
665 if (!theFilterTypes.contains(aFilterType))
668 // using sketch filters only if sketch operation is active
669 if (!isSketchActive &&
670 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
673 // using filtering of construction results only from faces panel
674 if (aFilterType == SF_ResultGroupNameFilter)
677 theSelectionFilters.Append(aFiltersIt->second);
681 //******************************************************
682 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
684 if (theModes.contains(TopAbs_FACE))
685 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
686 if (theModes.contains(TopAbs_WIRE))
687 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
689 if (mySketchMgr->activeSketch().get())
690 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
693 //******************************************************
694 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
695 ObjectPtr& theObject, AttributePtr& theAttribute)
697 ObjectPtr anObject = theSelected->object();
698 GeomShapePtr aShape = theSelected->shape();
700 theAttribute = findAttribute(anObject, aShape);
701 // TODO: try to create result if object is an external object
702 theObject = anObject;
705 //******************************************************
706 bool PartSet_Module::isMouseOverWindow()
708 return mySketchMgr->isMouseOverWindow();
711 //******************************************************
712 bool PartSet_Module::isSketchNeutralPointActivated() const
714 bool isNeutralPoint = true;
715 if (sketchReentranceMgr()->isInternalEditActive())
716 isNeutralPoint = false;
717 if (myIsOperationIsLaunched)
718 isNeutralPoint = false;
720 return isNeutralPoint;
723 //******************************************************
724 void PartSet_Module::closeDocument()
726 myActivePartIndex = QModelIndex();
727 SketcherPrs_PositionMgr::get()->clearAll();
730 //******************************************************
731 void PartSet_Module::clearViewer()
733 myCustomPrs->clearPrs();
735 XGUI_Workshop* aWorkshop = getWorkshop();
736 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
737 aDisplayer->deactivateSelectionFilters(false);
740 //******************************************************
741 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
743 ModuleBase_OperationFeature* aFOperation =
744 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
748 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
749 // we have to manually activate the sketch label in edit mode
750 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
751 aPanel->activateWidget(aPanel->modelWidgets().first());
754 //******************************************************
755 bool PartSet_Module::createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
756 QList<ModuleBase_ModelWidget*>& theWidgets) const
758 bool aProcessed = false;
760 XGUI_Workshop* aWorkshop = getWorkshop();
761 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
762 if (mySketchMgr->activeSketch().get() && aPropertyPanel) {
763 ModuleBase_ISelection* aSelection = workshop()->selection();
764 // click on a point in sketch leads here with the point is highlighted, not yet selected
765 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
766 if (aPreselection.size() == 1) {
767 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
768 ObjectPtr anObject = aSelectedPrs->object();
770 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
771 GeomShapePtr aShape = aSelectedPrs->shape();
772 // click on the digit of dimension constrain comes here
773 // with an empty shape, so we need the check
774 if (aFeature == theFeature && aShape.get() && !aShape->isNull()) {
775 // if feature has only one result and shape of result is equal to selected shape
776 // this attribute is not processed. It is a case of Sketch Point.
777 if (aFeature->results().size() == 1) {
778 ResultPtr aResult = aFeature->results().front();
779 if (aResult.get() && aResult->shape()->isEqual(aShape))
782 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
783 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
784 mySketchMgr->activeSketch());
785 if (anAttribute.get()) {
786 ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
788 const std::string anAttributeId = anAttribute->id();
789 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
791 theWidgets = aFactory.getModelWidgets();
792 // it is possible that the point does not present in XML definition,
793 // in this case, we assume that it is not processed by this module
794 // e.g. "Intersection point" feature
795 aProcessed = !theWidgets.isEmpty();
803 //******************************************************
804 void PartSet_Module::onSelectionChanged()
806 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
810 bool isSketcherOp = false;
811 // An edit operation is enable only if the current opeation is the sketch operation
812 if (mySketchMgr->activeSketch()) {
813 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
814 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
817 // Editing of constraints can be done on selection
818 ModuleBase_ISelection* aSelect = myWorkshop->selection();
819 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
820 if (aSelected.size() == 1) {
821 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
822 ObjectPtr aObject = aPrs->object();
823 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
825 std::string aId = aFeature->getKind();
826 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
827 (aId == SketchPlugin_ConstraintLength::ID()) ||
828 (aId == SketchPlugin_ConstraintDistance::ID()) ||
829 (aId == SketchPlugin_ConstraintAngle::ID())) {
830 editFeature(aFeature);
837 //******************************************************
838 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
840 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
841 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
842 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
845 //******************************************************
846 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
848 Config_WidgetAPI* theWidgetApi)
850 ModuleBase_IWorkshop* aWorkshop = workshop();
851 XGUI_Workshop* aXUIWorkshop = getWorkshop();
852 ModuleBase_ModelWidget* aWgt = NULL;
853 if (theType == "sketch-start-label") {
854 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
855 theWidgetApi, myHasConstraintShown);
856 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
857 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
858 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
859 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
860 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
861 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
862 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
863 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
865 } else if (theType == "sketch-2dpoint_selector") {
866 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
868 aPointWgt->setSketch(mySketchMgr->activeSketch());
869 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
871 }else if (theType == "sketch-2dpoint_flyout_selector") {
872 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
874 aPointWgt->setSketch(mySketchMgr->activeSketch());
875 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
877 } else if (theType == "sketch_shape_selector") {
878 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
879 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
880 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
881 aWgt = aShapeSelectorWgt;
882 } else if (theType == "sketch_multi_selector") {
883 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
884 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
885 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
886 aWgt = aShapeSelectorWgt;
888 else if (theType == "sketch_feature_point_selector") {
889 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
890 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
891 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
892 aWgt = aPointSelectorWgt;
894 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
895 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
896 } else if (theType == "export_file_selector") {
897 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
898 } else if (theType == "sketch_launcher") {
899 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
900 } else if (theType == "module_choice") {
901 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
902 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
903 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
908 //******************************************************
909 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
911 ModuleBase_ModelWidget* anActiveWidget = 0;
913 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
915 return anActiveWidget;
917 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
919 return anActiveWidget;
921 return aPanel->activeWidget(true);
924 //******************************************************
925 bool PartSet_Module::deleteObjects()
927 bool isProcessed = false;
929 XGUI_Workshop* aWorkshop = getWorkshop();
930 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
932 //SessionPtr aMgr = ModelAPI_Session::get();
933 // 1. check whether the delete should be processed in the module
934 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
935 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
936 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
937 if (isSketchOp || isNestedOp) {
939 // 2. find selected presentations
940 // selected objects should be collected before the current operation abort because
941 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
942 ModuleBase_ISelection* aSel = workshop()->selection();
943 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
944 // if there are no selected objects in the viewer, that means that the selection in another
945 // place cased this method. It is necessary to return the false value to understande in above
946 // method that delete is not processed
947 if (aSelectedObj.count() == 0)
950 // avoid delete of the objects, which are not belong to the current sketch
951 // in order to do not delete results of other sketches
952 QObjectPtrList aSketchObjects;
953 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
954 for ( ; anIt != aLast; anIt++) {
955 ObjectPtr anObject = *anIt;
956 if (mySketchMgr->isObjectOfSketch(anObject)) {
957 // sketch feature should be used in this list because workshop deletes features only
958 // results are skipped
959 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
960 aSketchObjects.append(aSketchFeature);
963 // if the selection contains only local selected presentations from other sketches,
964 // the Delete operation should not be done at all
965 if (aSketchObjects.size() == 0)
968 // 3. start operation
969 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
970 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, this);
972 // the active nested sketch operation should be aborted unconditionally
973 // the Delete action should be additionally granted for the Sketch operation
974 // in order to do not abort/commit it
976 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
977 return true; // the objects are processed but can not be deleted
979 anOpMgr->startOperation(anOpAction);
981 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
982 // the problem is in AIS Dimensions recompute
983 // if a line and the dim are removed, line is the first
984 // it causes the AIS recompute, where the base line is null,
985 // the result is empty AIS in the viewer
986 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
988 // 4. delete features
989 // sketch feature should be skipped, only sub-features can be removed
990 // when sketch operation is active
991 aWorkshop->deleteFeatures(aSketchObjects);
993 anOpMgr->commitOperation();
998 //******************************************************
999 void PartSet_Module::editFeature(FeaturePtr theFeature)
1001 storeConstraintsState(theFeature->getKind());
1002 ModuleBase_IModule::editFeature(theFeature);
1005 //******************************************************
1006 bool PartSet_Module::canCommitOperation() const
1011 //******************************************************
1012 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1014 myIsOperationIsLaunched = true;
1015 storeConstraintsState(theCmdId.toStdString());
1016 updateConstraintsState(theCmdId.toStdString());
1018 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1020 myIsOperationIsLaunched = false;
1023 //******************************************************
1024 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1026 if (myWorkshop->currentOperation() &&
1027 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1028 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1029 mySketchMgr->showConstraintStates();
1030 myHasConstraintShown = aShownStates;
1034 //******************************************************
1035 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1037 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1038 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1039 // Show constraints if a constraint was anOperation
1040 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1041 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1042 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1043 myHasConstraintShown[PartSet_Tools::Expressions]);
1047 //******************************************************
1048 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1050 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1051 if (!anAIS.IsNull()) {
1052 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1053 if (aFeature.get()) {
1054 bool aToUseZLayer = false;
1055 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1056 aToUseZLayer = true;
1058 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1059 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1062 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1063 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1064 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1066 aCtx->SetZLayer(anAIS, myVisualLayerId);
1072 //******************************************************
1073 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1076 // it should be recomputed in order to disappear in the viewer if the corresponded object
1078 //if (myCustomPrs->isActive())
1079 // myCustomPrs->redisplay(theObject, false);
1082 //******************************************************
1083 void PartSet_Module::onViewTransformed(int theTrsfType)
1085 // Set length of arrows constant in pixel size
1086 // if the operation is panning or rotate or panglobal then do nothing
1087 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1089 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1090 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1091 if (aContext.IsNull())
1094 //Handle(V3d_View) aView = aViewer->activeView();
1096 XGUI_Workshop* aWorkshop = getWorkshop();
1097 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1098 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1099 Handle(V3d_View) aView;
1101 for (aV3dViewer->InitDefinedViews();
1102 aV3dViewer->MoreDefinedViews();
1103 aV3dViewer->NextDefinedViews()) {
1104 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1105 double aS = aV->Scale();
1114 bool isModified = false;
1115 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1116 if (aCurrentOperation &&
1117 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1118 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1119 (aCurrentOperation->id() == "Measurement")))
1121 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1123 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1124 SketcherPrs_Tools::setArrowSize(aLen);
1125 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1126 aViewer->SetScale(aViewer->activeView(), aCurScale);
1128 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1129 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1131 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1132 foreach(AISObjectPtr aAIS, aPrsList) {
1133 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1135 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1136 if (!aDim.IsNull()) {
1137 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1138 aContext->Redisplay(aDim, false);
1143 aDisplayer->updateViewer();
1148 //******************************************************
1149 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1151 return myCustomPrs->isActive(theFlag);
1154 //******************************************************
1155 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1156 const ModuleBase_CustomizeFlag& theFlag,
1157 const bool theUpdateViewer)
1159 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1162 //******************************************************
1163 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1164 const bool theUpdateViewer)
1166 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1169 //******************************************************
1170 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1171 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1173 bool aCustomized = false;
1175 XGUI_Workshop* aWorkshop = getWorkshop();
1176 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1177 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1181 if (!theResult.get()) {
1182 std::vector<int> aColor;
1183 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1184 if (!aColor.empty()) {
1185 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1188 // customize dimentional constrains
1189 sketchMgr()->customizePresentation(anObject);
1194 //******************************************************
1195 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1196 AISObjectPtr thePrs,
1197 GeomCustomPrsPtr theCustomPrs)
1199 bool aCustomized = false;
1201 XGUI_Workshop* aWorkshop = getWorkshop();
1202 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1203 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1207 std::vector<int> aColor;
1208 bool aUseCustomColor = true;
1209 if (aUseCustomColor)
1210 myOverconstraintListener->getCustomColor(anObject, aColor);
1211 // customize sketch symbol presentation
1212 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1213 if (!anAISIO.IsNull()) {
1214 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1215 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1216 if (!aPrs.IsNull()) {
1217 aPrs->SetCustomColor(aColor);
1220 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1221 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1222 if (!aPrs.IsNull()) {
1223 aPrs->SetCustomColor(aColor);
1228 // customize sketch dimension constraint presentation
1230 if (!aColor.empty()) { // otherwise presentation has the default color
1231 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1237 //******************************************************
1238 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1239 const bool theUpdateViewer)
1241 bool isRedisplayed = false;
1242 if (myCustomPrs->isActive(theFlag))
1243 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1245 return isRedisplayed;
1248 //******************************************************
1249 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1251 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1253 QLabel* aLabel = aOB->activeDocLabel();
1254 aLabel->installEventFilter(myMenuMgr);
1255 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1256 SLOT(onActiveDocPopup(const QPoint&)));
1257 aOB->treeView()->setExpandsOnDoubleClick(false);
1258 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1259 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1261 Events_Loop* aLoop = Events_Loop::loop();
1262 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1266 //******************************************************
1267 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1269 SessionPtr aMgr = ModelAPI_Session::get();
1270 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1272 XGUI_Workshop* aWorkshop = getWorkshop();
1273 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1275 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1278 aMenu.addAction(aActivatePartAction);
1279 aMenu.exec(aHeader->mapToGlobal(thePnt));
1282 //******************************************************
1283 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1285 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1287 return mySketchMgr->createPresentation(aResult);
1289 FieldStepPtr aStep =
1290 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1292 return new PartSet_FieldStepPrs(aStep);
1295 return Handle(AIS_InteractiveObject)();
1298 //******************************************************
1299 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1302 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1304 /// If last line finished on vertex the lines creation sequence has to be break
1305 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1307 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1308 // if there is an active widget, find the presented object in it
1309 if (!anActiveWidget)
1310 anActiveWidget = aPanel->preselectionWidget();
1312 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1314 if (aWidgetValidated)
1315 anObject = aWidgetValidated->findPresentedObject(theAIS);
1321 //******************************************************
1322 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1324 bool aCanBeShaged = true;
1326 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1328 aCanBeShaged = false;
1330 return aCanBeShaged;
1333 //******************************************************
1334 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1336 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1337 int aSelected = aObjects.size();
1338 SessionPtr aMgr = ModelAPI_Session::get();
1339 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1341 bool hasResult = false;
1342 bool hasFeature = false;
1343 bool hasParameter = false;
1344 bool hasCompositeOwner = false;
1345 bool hasResultInHistory = false;
1346 bool hasFolder = false;
1347 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1348 hasCompositeOwner, hasResultInHistory, hasFolder);
1350 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1351 if (aSelected == 1) {
1352 ObjectPtr aObject = aObjects.first();
1354 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1355 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1356 bool isPart = aPart.get() ||
1357 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1359 DocumentPtr aPartDoc;
1361 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1363 if (aPart.get()) // this may be null is Part feature is disabled
1364 aPartDoc = aPart->partDoc();
1366 theMenu->addAction(aActivatePartAction);
1367 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1369 } else if (aObject->document() == aMgr->activeDocument()) {
1370 if (hasParameter || hasFeature) {
1371 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1372 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1373 if (aCurrentOp && aFeature.get()) {
1374 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1375 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1382 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1383 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1384 theMenu->addSeparator();
1387 bool aNotDeactivate = (aCurrentOp == 0);
1388 if (!aNotDeactivate) {
1389 aActivatePartAction->setEnabled(false);
1393 //******************************************************
1394 #define EXPAND_PARENT(OBJ) \
1395 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1396 if (aObjIndex.isValid()) { \
1397 QModelIndex aParent = aObjIndex.parent(); \
1398 int aCount = aDataModel->rowCount(aParent); \
1400 aTreeView->setExpanded(aParent, true); \
1403 //******************************************************
1404 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1406 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1407 // Do not change activation of parts if an operation active
1408 static QStringList aAllowActivationList;
1409 if (aAllowActivationList.isEmpty())
1410 aAllowActivationList <<
1411 QString(PartSetPlugin_Part::ID().c_str()) <<
1412 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1413 QString(PartSetPlugin_Remove::ID().c_str());
1414 if (myWorkshop->currentOperation() &&
1415 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1417 XGUI_Workshop* aWorkshop = getWorkshop();
1418 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1419 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1420 QPalette aPalet = aLabel->palette();
1422 SessionPtr aMgr = ModelAPI_Session::get();
1423 DocumentPtr aActiveDoc = aMgr->activeDocument();
1425 // Clear active part index if there is no Part documents
1426 // It could be not null if document was closed and opened a new
1427 // without closeDocument call
1428 if (aMgr->allOpenedDocuments().size() <= 1)
1429 myActivePartIndex = QModelIndex();
1431 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1432 QModelIndex aOldActive = myActivePartIndex;
1433 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1434 bool needUpdate = false;
1435 if (myActivePartIndex.isValid()) {
1436 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1438 aTreeView->setExpanded(myActivePartIndex, true);
1440 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1441 aTreeView->setExpanded(aOldActive, false);
1443 aLabel->setPalette(aPalet);
1444 aWorkshop->updateCommandStatus();
1446 // Update displayed objects in order to update active color
1447 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1448 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1450 bool aUpdateViewer = false;
1451 foreach(ObjectPtr aObj, aObjects) {
1452 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1453 aObj->isDisabled() || (!aObj->isDisplayed());
1455 aDisplayer->redisplay(aObj, false);
1456 aUpdateViewer = true;
1460 aDisplayer->updateViewer();
1461 // Update tree items if they are expanded
1463 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1465 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1466 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1467 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1468 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1470 ObjectPtr aConstrObj;
1471 ObjectPtr aResultObj;
1472 std::set<ObjectPtr>::const_iterator aIt;
1473 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1474 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1475 ObjectPtr aObject = (*aIt);
1476 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1477 && (aObject->document() != aRootDoc))
1478 aResultObj = aObject;
1479 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1480 && (aObject->document() != aRootDoc))
1481 aConstrObj = aObject;
1482 if (aResultObj.get() && aConstrObj.get())
1486 if (aResultObj.get() || aConstrObj.get()) {
1487 XGUI_Workshop* aWorkshop = getWorkshop();
1488 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1489 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1491 if (aResultObj.get()) {
1492 EXPAND_PARENT(aResultObj)
1494 if (aConstrObj.get()) {
1495 EXPAND_PARENT(aConstrObj)
1499 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1500 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1501 if (aSketch.get()) {
1502 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1503 if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1504 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1509 //******************************************************
1510 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1512 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1514 SessionPtr aMgr = ModelAPI_Session::get();
1515 if (!theIndex.isValid()) {
1516 // It seems that this code is obsolete
1517 //aMgr->setActiveDocument(aMgr->moduleDocument());
1520 if (theIndex.column() != 1) // Use only first column
1523 XGUI_Workshop* aWorkshop = getWorkshop();
1524 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1525 // De not use non editable Indexes
1526 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1528 ObjectPtr aObj = aDataModel->object(theIndex);
1530 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1531 if (!aPart.get()) { // Probably this is Feature
1532 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1533 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1534 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1537 if (aPart.get()) { // if this is a part
1538 if (aPart->partDoc() == aMgr->activeDocument()) {
1539 myMenuMgr->activatePartSet();
1541 myMenuMgr->activatePart(aPart);
1546 //******************************************************
1547 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1549 // z layer is created for all started operations in order to visualize operation AIS presentation
1551 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1552 if (aContext.IsNull())
1555 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1556 if (myVisualLayerId == 0) {
1557 if (myVisualLayerId == 0)
1558 aViewer->AddZLayer(myVisualLayerId);
1560 TColStd_SequenceOfInteger aZList;
1561 aViewer->GetAllZLayers(aZList);
1562 bool aFound = false;
1563 for (int i = 1; i <= aZList.Length(); i++) {
1564 if (aZList(i) == myVisualLayerId) {
1570 aViewer->AddZLayer(myVisualLayerId);
1572 // if there is an active operation with validated widget,
1573 // the filters of this widget should be activated in the created view
1574 myWorkshop->selectionActivate()->updateSelectionFilters();
1575 myWorkshop->selectionActivate()->updateSelectionModes();
1578 //******************************************************
1579 void PartSet_Module::widgetStateChanged(int thePreviousState)
1581 mySketchMgr->widgetStateChanged(thePreviousState);
1584 //******************************************************
1585 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1587 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1590 //******************************************************
1591 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1593 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1594 mySketchMgr->stopSketch(theOperation);
1598 //******************************************************
1599 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1601 GeomShapePtr aGeomShape;
1603 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1604 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1605 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1610 //******************************************************
1611 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1612 const GeomShapePtr& theGeomShape)
1614 AttributePtr anAttribute;
1615 GeomShapePtr aGeomShape = theGeomShape;
1616 if (!aGeomShape.get()) {
1617 // processing shape of result, e.g. sketch circle center is selected, this is a result
1618 // the geom shape is empty, the shape of result should be used
1619 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1620 if (aResult.get()) {
1621 aGeomShape = aResult->shape();
1625 if (aGeomShape.get()) {
1626 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1627 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1628 mySketchMgr->activeSketch());
1633 //******************************************************
1634 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1636 return sketchReentranceMgr()->reentrantMessage();
1639 //******************************************************
1640 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1642 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1645 //******************************************************
1646 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1649 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1653 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1654 if (!aChoiceTitle.isEmpty()) {
1655 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1658 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1660 aPanel->setWindowTitle(aChoiceTitle);
1664 //******************************************************
1665 XGUI_Workshop* PartSet_Module::getWorkshop() const
1667 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1668 return aConnector->workshop();
1671 void PartSet_Module::setDefaultConstraintShown()
1673 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1674 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1675 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1678 //******************************************************
1679 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1684 //******************************************************
1685 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1686 myCustomPrs->disableCustomMode(theMode);
1689 //******************************************************
1690 void PartSet_Module::enableCustomModes() {
1691 myCustomPrs->enableCustomModes();