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 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
438 mySketchMgr->startNestedSketch(theOperation);
442 //******************************************************
443 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
445 ModuleBase_OperationFeature* aFOperation =
446 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
448 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
449 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
453 //******************************************************
454 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
456 ModuleBase_IModule::operationResumed(theOperation);
458 ModuleBase_OperationFeature* aFOperation =
459 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
461 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
462 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
466 //******************************************************
467 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
469 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
470 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
471 bool isModified = isModifiedArgs || isModifiedResults;
473 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
474 mySketchMgr->stopNestedSketch(theOperation);
476 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
477 setDefaultConstraintShown();
479 //VSV: Viewer is updated on feature update and redisplay
481 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
482 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
483 aDisplayer->updateViewer();
486 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
487 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
488 for (; anIt != aLast; anIt++) {
489 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
493 //******************************************************
494 ModuleBase_Operation* PartSet_Module::currentOperation() const
496 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
497 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
498 return anOpMgr->currentOperation();
501 //******************************************************
502 bool PartSet_Module::canUndo() const
504 bool aCanUndo = false;
505 SessionPtr aMgr = ModelAPI_Session::get();
506 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
507 aCanUndo = !aMgr->isOperation();
508 if (!aCanUndo) // check the enable state additionally by sketch manager
509 aCanUndo = aMgr->canUndo();
514 //******************************************************
515 bool PartSet_Module::canRedo() const
517 bool aCanRedo = false;
518 SessionPtr aMgr = ModelAPI_Session::get();
519 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
520 aCanRedo = !aMgr->isOperation();
521 if (!aCanRedo) // check the enable state additionally by sketch manager
522 aCanRedo = aMgr->canRedo();
527 //******************************************************
528 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
531 if (theActionId == "MOVE_CMD") {
532 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
534 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
535 // part features can not be moved in the history.
536 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
543 //******************************************************
544 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
546 // the sketch manager put the restriction to the objects erase
547 return mySketchMgr->canEraseObject(theObject);
550 //******************************************************
551 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
553 // the sketch manager put the restriction to the objects display
554 return mySketchMgr->canDisplayObject(theObject);
557 //******************************************************
558 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
559 const QString& theStartedOperationKind)
561 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
564 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
567 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
569 mySketchMgr->processHiddenObject(theObjects);
572 //******************************************************
573 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
575 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
577 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
578 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
579 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
580 if (isSketchOp || isNestedOp) {
581 // in active sketch operation it is possible to activate operation object in selection
582 // in the edit operation, e.g. points of the line can be moved when the line is edited
583 ModuleBase_OperationFeature* aFOperation =
584 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
585 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
590 //******************************************************
591 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
593 QMap<int, QAction*>& theMenuActions) const
595 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
598 //******************************************************
599 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
601 myMenuMgr->updateViewerMenu(theStdActions);
604 //******************************************************
605 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
607 bool isEnabledFixed = false;
608 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
609 mySketchReentrantMgr->isInternalEditActive())
610 isEnabledFixed = true;
611 return isEnabledFixed;
614 //******************************************************
615 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
617 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
618 if (anError.isEmpty())
619 anError = sketchMgr()->getFeatureError(theFeature);
624 //******************************************************
625 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
626 QStringList& theIds) const
628 myMenuMgr->grantedOperationIds(theOperation, theIds);
630 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
631 XGUI_Workshop* aWorkshop = getWorkshop();
632 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
636 //******************************************************
637 void PartSet_Module::activeSelectionModes(QIntList& theModes)
639 if (mySketchMgr->activeSketch().get())
640 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
642 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
645 //******************************************************
646 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
648 customSubShapesSelectionModes(theModes);
649 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
650 //myWorkshop->module()->activeSelectionModes(theModes);
653 //******************************************************
654 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
655 SelectMgr_ListOfFilter& theSelectionFilters)
657 bool isSketchActive = mySketchMgr->activeSketch().get();
659 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
660 mySelectionFilters.begin();
661 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
662 int aFilterType = aFiltersIt->first;
663 // do not add not participating filters in given parameters
664 if (!theFilterTypes.contains(aFilterType))
667 // using sketch filters only if sketch operation is active
668 if (!isSketchActive &&
669 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
672 // using filtering of construction results only from faces panel
673 if (aFilterType == SF_ResultGroupNameFilter)
676 theSelectionFilters.Append(aFiltersIt->second);
680 //******************************************************
681 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
683 if (theModes.contains(TopAbs_FACE))
684 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
685 if (theModes.contains(TopAbs_WIRE))
686 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
688 if (mySketchMgr->activeSketch().get())
689 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
692 //******************************************************
693 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
694 ObjectPtr& theObject, AttributePtr& theAttribute)
696 ObjectPtr anObject = theSelected->object();
697 GeomShapePtr aShape = theSelected->shape();
699 theAttribute = findAttribute(anObject, aShape);
700 // TODO: try to create result if object is an external object
701 theObject = anObject;
704 //******************************************************
705 bool PartSet_Module::isMouseOverWindow()
707 return mySketchMgr->isMouseOverWindow();
710 //******************************************************
711 bool PartSet_Module::isSketchNeutralPointActivated() const
713 bool isNeutralPoint = true;
714 if (sketchReentranceMgr()->isInternalEditActive())
715 isNeutralPoint = false;
716 if (myIsOperationIsLaunched)
717 isNeutralPoint = false;
719 return isNeutralPoint;
722 //******************************************************
723 void PartSet_Module::closeDocument()
725 myActivePartIndex = QModelIndex();
726 SketcherPrs_PositionMgr::get()->clearAll();
729 //******************************************************
730 void PartSet_Module::clearViewer()
732 myCustomPrs->clearPrs();
734 XGUI_Workshop* aWorkshop = getWorkshop();
735 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
736 aDisplayer->deactivateSelectionFilters(false);
739 //******************************************************
740 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
742 ModuleBase_OperationFeature* aFOperation =
743 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
747 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
748 // we have to manually activate the sketch label in edit mode
749 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
750 aPanel->activateWidget(aPanel->modelWidgets().first());
753 //******************************************************
754 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
755 QList<ModuleBase_ModelWidget*>& theWidgets) const
757 bool aProcessed = false;
759 ModuleBase_OperationFeature* aFOperation =
760 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
761 XGUI_Workshop* aWorkshop = getWorkshop();
762 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
763 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
764 ModuleBase_ISelection* aSelection = workshop()->selection();
765 // click on a point in sketch leads here with the point is highlighted, not yet selected
766 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
767 if (aPreselection.size() == 1) {
768 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
769 ObjectPtr anObject = aSelectedPrs->object();
771 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
772 FeaturePtr anOpFeature = aFOperation->feature();
773 GeomShapePtr aShape = aSelectedPrs->shape();
774 // click on the digit of dimension constrain comes here
775 // with an empty shape, so we need the check
776 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
777 // if feature has only one result and shape of result is equal to selected shape
778 // this attribute is not processed. It is a case of Sketch Point.
779 if (aFeature->results().size() == 1) {
780 ResultPtr aResult = aFeature->results().front();
781 if (aResult.get() && aResult->shape()->isEqual(aShape))
784 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
785 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
786 mySketchMgr->activeSketch());
787 if (anAttribute.get()) {
788 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
789 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
791 const std::string anAttributeId = anAttribute->id();
792 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
794 theWidgets = aFactory.getModelWidgets();
795 // it is possible that the point does not present in XML definition,
796 // in this case, we assume that it is not processed by this module
797 // e.g. "Intersection point" feature
798 aProcessed = !theWidgets.isEmpty();
806 //******************************************************
807 void PartSet_Module::onSelectionChanged()
809 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
813 bool isSketcherOp = false;
814 // An edit operation is enable only if the current opeation is the sketch operation
815 if (mySketchMgr->activeSketch()) {
816 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
817 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
820 // Editing of constraints can be done on selection
821 ModuleBase_ISelection* aSelect = myWorkshop->selection();
822 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
823 if (aSelected.size() == 1) {
824 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
825 ObjectPtr aObject = aPrs->object();
826 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
828 std::string aId = aFeature->getKind();
829 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
830 (aId == SketchPlugin_ConstraintLength::ID()) ||
831 (aId == SketchPlugin_ConstraintDistance::ID()) ||
832 (aId == SketchPlugin_ConstraintAngle::ID())) {
833 editFeature(aFeature);
840 //******************************************************
841 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
843 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
844 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
845 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
848 //******************************************************
849 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
851 Config_WidgetAPI* theWidgetApi)
853 ModuleBase_IWorkshop* aWorkshop = workshop();
854 XGUI_Workshop* aXUIWorkshop = getWorkshop();
855 ModuleBase_ModelWidget* aWgt = NULL;
856 if (theType == "sketch-start-label") {
857 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
858 theWidgetApi, myHasConstraintShown);
859 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
860 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
861 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
862 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
863 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
864 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
865 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
866 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
868 } else if (theType == "sketch-2dpoint_selector") {
869 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
871 aPointWgt->setSketch(mySketchMgr->activeSketch());
872 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
874 }else if (theType == "sketch-2dpoint_flyout_selector") {
875 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
877 aPointWgt->setSketch(mySketchMgr->activeSketch());
878 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
880 } else if (theType == "sketch_shape_selector") {
881 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
882 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
883 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
884 aWgt = aShapeSelectorWgt;
885 } else if (theType == "sketch_multi_selector") {
886 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
887 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
888 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
889 aWgt = aShapeSelectorWgt;
891 else if (theType == "sketch_feature_point_selector") {
892 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
893 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
894 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
895 aWgt = aPointSelectorWgt;
897 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
898 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
899 } else if (theType == "export_file_selector") {
900 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
901 } else if (theType == "sketch_launcher") {
902 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
903 } else if (theType == "module_choice") {
904 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
905 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
906 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
911 //******************************************************
912 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
914 ModuleBase_ModelWidget* anActiveWidget = 0;
916 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
918 return anActiveWidget;
920 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
922 return anActiveWidget;
924 return aPanel->activeWidget(true);
927 //******************************************************
928 bool PartSet_Module::deleteObjects()
930 bool isProcessed = false;
932 XGUI_Workshop* aWorkshop = getWorkshop();
933 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
935 //SessionPtr aMgr = ModelAPI_Session::get();
936 // 1. check whether the delete should be processed in the module
937 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
938 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
939 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
940 if (isSketchOp || isNestedOp) {
942 // 2. find selected presentations
943 // selected objects should be collected before the current operation abort because
944 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
945 ModuleBase_ISelection* aSel = workshop()->selection();
946 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
947 // if there are no selected objects in the viewer, that means that the selection in another
948 // place cased this method. It is necessary to return the false value to understande in above
949 // method that delete is not processed
950 if (aSelectedObj.count() == 0)
953 // avoid delete of the objects, which are not belong to the current sketch
954 // in order to do not delete results of other sketches
955 QObjectPtrList aSketchObjects;
956 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
957 for ( ; anIt != aLast; anIt++) {
958 ObjectPtr anObject = *anIt;
959 if (mySketchMgr->isObjectOfSketch(anObject)) {
960 // sketch feature should be used in this list because workshop deletes features only
961 // results are skipped
962 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
963 aSketchObjects.append(aSketchFeature);
966 // if the selection contains only local selected presentations from other sketches,
967 // the Delete operation should not be done at all
968 if (aSketchObjects.size() == 0)
971 // 3. start operation
972 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
973 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
975 // the active nested sketch operation should be aborted unconditionally
976 // the Delete action should be additionally granted for the Sketch operation
977 // in order to do not abort/commit it
979 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
980 return true; // the objects are processed but can not be deleted
982 anOpMgr->startOperation(anOpAction);
984 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
985 // the problem is in AIS Dimensions recompute
986 // if a line and the dim are removed, line is the first
987 // it causes the AIS recompute, where the base line is null,
988 // the result is empty AIS in the viewer
989 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
991 // 4. delete features
992 // sketch feature should be skipped, only sub-features can be removed
993 // when sketch operation is active
994 aWorkshop->deleteFeatures(aSketchObjects);
996 anOpMgr->commitOperation();
1001 //******************************************************
1002 void PartSet_Module::editFeature(FeaturePtr theFeature)
1004 storeConstraintsState(theFeature->getKind());
1005 ModuleBase_IModule::editFeature(theFeature);
1008 //******************************************************
1009 bool PartSet_Module::canCommitOperation() const
1014 //******************************************************
1015 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1017 myIsOperationIsLaunched = true;
1018 storeConstraintsState(theCmdId.toStdString());
1019 updateConstraintsState(theCmdId.toStdString());
1021 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1023 myIsOperationIsLaunched = false;
1026 //******************************************************
1027 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1029 if (myWorkshop->currentOperation() &&
1030 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1031 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1032 mySketchMgr->showConstraintStates();
1033 myHasConstraintShown = aShownStates;
1037 //******************************************************
1038 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1040 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1041 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1042 // Show constraints if a constraint was anOperation
1043 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1044 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1045 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1046 myHasConstraintShown[PartSet_Tools::Expressions]);
1050 //******************************************************
1051 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1053 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1054 if (!anAIS.IsNull()) {
1055 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1056 if (aFeature.get()) {
1057 bool aToUseZLayer = false;
1058 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1059 aToUseZLayer = true;
1061 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1062 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1065 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1066 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1067 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1069 aCtx->SetZLayer(anAIS, myVisualLayerId);
1075 //******************************************************
1076 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1079 // it should be recomputed in order to disappear in the viewer if the corresponded object
1081 //if (myCustomPrs->isActive())
1082 // myCustomPrs->redisplay(theObject, false);
1085 //******************************************************
1086 void PartSet_Module::onViewTransformed(int theTrsfType)
1088 // Set length of arrows constant in pixel size
1089 // if the operation is panning or rotate or panglobal then do nothing
1090 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1092 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1093 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1094 if (aContext.IsNull())
1097 //Handle(V3d_View) aView = aViewer->activeView();
1099 XGUI_Workshop* aWorkshop = getWorkshop();
1100 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1101 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1102 Handle(V3d_View) aView;
1104 for (aV3dViewer->InitDefinedViews();
1105 aV3dViewer->MoreDefinedViews();
1106 aV3dViewer->NextDefinedViews()) {
1107 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1108 double aS = aV->Scale();
1117 bool isModified = false;
1118 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1119 if (aCurrentOperation &&
1120 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1121 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1122 (aCurrentOperation->id() == "Measurement")))
1124 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1126 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1127 SketcherPrs_Tools::setArrowSize(aLen);
1128 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1129 aViewer->SetScale(aViewer->activeView(), aCurScale);
1131 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1132 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1134 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1135 foreach(AISObjectPtr aAIS, aPrsList) {
1136 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1138 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1139 if (!aDim.IsNull()) {
1140 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1141 aContext->Redisplay(aDim, false);
1146 aDisplayer->updateViewer();
1151 //******************************************************
1152 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1154 return myCustomPrs->isActive(theFlag);
1157 //******************************************************
1158 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1159 const ModuleBase_CustomizeFlag& theFlag,
1160 const bool theUpdateViewer)
1162 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1165 //******************************************************
1166 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1167 const bool theUpdateViewer)
1169 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1172 //******************************************************
1173 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1174 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1176 bool aCustomized = false;
1178 XGUI_Workshop* aWorkshop = getWorkshop();
1179 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1180 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1184 if (!theResult.get()) {
1185 std::vector<int> aColor;
1186 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1187 if (!aColor.empty()) {
1188 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1191 // customize dimentional constrains
1192 sketchMgr()->customizePresentation(anObject);
1197 //******************************************************
1198 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1199 AISObjectPtr thePrs,
1200 GeomCustomPrsPtr theCustomPrs)
1202 bool aCustomized = false;
1204 XGUI_Workshop* aWorkshop = getWorkshop();
1205 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1206 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1210 std::vector<int> aColor;
1211 bool aUseCustomColor = true;
1212 if (aUseCustomColor)
1213 myOverconstraintListener->getCustomColor(anObject, aColor);
1214 // customize sketch symbol presentation
1215 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1216 if (!anAISIO.IsNull()) {
1217 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1218 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1219 if (!aPrs.IsNull()) {
1220 aPrs->SetCustomColor(aColor);
1223 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1224 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1225 if (!aPrs.IsNull()) {
1226 aPrs->SetCustomColor(aColor);
1231 // customize sketch dimension constraint presentation
1233 if (!aColor.empty()) { // otherwise presentation has the default color
1234 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1240 //******************************************************
1241 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1242 const bool theUpdateViewer)
1244 bool isRedisplayed = false;
1245 if (myCustomPrs->isActive(theFlag))
1246 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1248 return isRedisplayed;
1251 //******************************************************
1252 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1254 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1256 QLabel* aLabel = aOB->activeDocLabel();
1257 aLabel->installEventFilter(myMenuMgr);
1258 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1259 SLOT(onActiveDocPopup(const QPoint&)));
1260 aOB->treeView()->setExpandsOnDoubleClick(false);
1261 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1262 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1264 Events_Loop* aLoop = Events_Loop::loop();
1265 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1269 //******************************************************
1270 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1272 SessionPtr aMgr = ModelAPI_Session::get();
1273 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1275 XGUI_Workshop* aWorkshop = getWorkshop();
1276 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1278 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1281 aMenu.addAction(aActivatePartAction);
1282 aMenu.exec(aHeader->mapToGlobal(thePnt));
1285 //******************************************************
1286 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ObjectPtr& theObject)
1288 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1290 return mySketchMgr->createPresentation(aResult);
1292 FieldStepPtr aStep =
1293 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1295 return new PartSet_FieldStepPrs(aStep);
1298 return Handle(AIS_InteractiveObject)();
1301 //******************************************************
1302 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1305 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1307 /// If last line finished on vertex the lines creation sequence has to be break
1308 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1310 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1311 // if there is an active widget, find the presented object in it
1312 if (!anActiveWidget)
1313 anActiveWidget = aPanel->preselectionWidget();
1315 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1317 if (aWidgetValidated)
1318 anObject = aWidgetValidated->findPresentedObject(theAIS);
1324 //******************************************************
1325 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1327 bool aCanBeShaged = true;
1329 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1331 aCanBeShaged = false;
1333 return aCanBeShaged;
1336 //******************************************************
1337 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1339 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1340 int aSelected = aObjects.size();
1341 SessionPtr aMgr = ModelAPI_Session::get();
1342 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1344 bool hasResult = false;
1345 bool hasFeature = false;
1346 bool hasParameter = false;
1347 bool hasCompositeOwner = false;
1348 bool hasResultInHistory = false;
1349 bool hasFolder = false;
1350 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1351 hasCompositeOwner, hasResultInHistory, hasFolder);
1353 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1354 if (aSelected == 1) {
1355 ObjectPtr aObject = aObjects.first();
1357 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1358 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1359 bool isPart = aPart.get() ||
1360 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1362 DocumentPtr aPartDoc;
1364 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1366 if (aPart.get()) // this may be null is Part feature is disabled
1367 aPartDoc = aPart->partDoc();
1369 theMenu->addAction(aActivatePartAction);
1370 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1372 } else if (aObject->document() == aMgr->activeDocument()) {
1373 if (hasParameter || hasFeature) {
1374 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1375 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1376 if (aCurrentOp && aFeature.get()) {
1377 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1378 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1385 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1386 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1387 theMenu->addSeparator();
1390 bool aNotDeactivate = (aCurrentOp == 0);
1391 if (!aNotDeactivate) {
1392 aActivatePartAction->setEnabled(false);
1396 //******************************************************
1397 #define EXPAND_PARENT(OBJ) \
1398 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1399 if (aObjIndex.isValid()) { \
1400 QModelIndex aParent = aObjIndex.parent(); \
1401 int aCount = aDataModel->rowCount(aParent); \
1403 aTreeView->setExpanded(aParent, true); \
1406 //******************************************************
1407 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1409 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1410 // Do not change activation of parts if an operation active
1411 static QStringList aAllowActivationList;
1412 if (aAllowActivationList.isEmpty())
1413 aAllowActivationList <<
1414 QString(PartSetPlugin_Part::ID().c_str()) <<
1415 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1416 QString(PartSetPlugin_Remove::ID().c_str());
1417 if (myWorkshop->currentOperation() &&
1418 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1420 XGUI_Workshop* aWorkshop = getWorkshop();
1421 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1422 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1423 QPalette aPalet = aLabel->palette();
1425 SessionPtr aMgr = ModelAPI_Session::get();
1426 DocumentPtr aActiveDoc = aMgr->activeDocument();
1428 // Clear active part index if there is no Part documents
1429 // It could be not null if document was closed and opened a new
1430 // without closeDocument call
1431 if (aMgr->allOpenedDocuments().size() <= 1)
1432 myActivePartIndex = QModelIndex();
1434 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1435 QModelIndex aOldActive = myActivePartIndex;
1436 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1437 bool needUpdate = false;
1438 if (myActivePartIndex.isValid()) {
1439 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1441 aTreeView->setExpanded(myActivePartIndex, true);
1443 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1444 aTreeView->setExpanded(aOldActive, false);
1446 aLabel->setPalette(aPalet);
1447 aWorkshop->updateCommandStatus();
1449 // Update displayed objects in order to update active color
1450 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1451 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1453 bool aUpdateViewer = false;
1454 foreach(ObjectPtr aObj, aObjects) {
1455 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1456 aObj->isDisabled() || (!aObj->isDisplayed());
1458 aDisplayer->redisplay(aObj, false);
1459 aUpdateViewer = true;
1463 aDisplayer->updateViewer();
1464 // Update tree items if they are expanded
1466 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1468 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1469 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1470 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1471 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1473 ObjectPtr aConstrObj;
1474 ObjectPtr aResultObj;
1475 std::set<ObjectPtr>::const_iterator aIt;
1476 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1477 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1478 ObjectPtr aObject = (*aIt);
1479 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1480 && (aObject->document() != aRootDoc))
1481 aResultObj = aObject;
1482 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1483 && (aObject->document() != aRootDoc))
1484 aConstrObj = aObject;
1485 if (aResultObj.get() && aConstrObj.get())
1489 if (aResultObj.get() || aConstrObj.get()) {
1490 XGUI_Workshop* aWorkshop = getWorkshop();
1491 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1492 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1494 if (aResultObj.get()) {
1495 EXPAND_PARENT(aResultObj)
1497 if (aConstrObj.get()) {
1498 EXPAND_PARENT(aConstrObj)
1502 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1503 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1504 if (aSketch.get()) {
1505 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1506 if (PartSet_SketcherMgr::isSketchOperation(anOperation))
1507 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1512 //******************************************************
1513 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1515 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1517 SessionPtr aMgr = ModelAPI_Session::get();
1518 if (!theIndex.isValid()) {
1519 // It seems that this code is obsolete
1520 //aMgr->setActiveDocument(aMgr->moduleDocument());
1523 if (theIndex.column() != 1) // Use only first column
1526 XGUI_Workshop* aWorkshop = getWorkshop();
1527 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1528 // De not use non editable Indexes
1529 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1531 ObjectPtr aObj = aDataModel->object(theIndex);
1533 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1534 if (!aPart.get()) { // Probably this is Feature
1535 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1536 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1537 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1540 if (aPart.get()) { // if this is a part
1541 if (aPart->partDoc() == aMgr->activeDocument()) {
1542 myMenuMgr->activatePartSet();
1544 myMenuMgr->activatePart(aPart);
1549 //******************************************************
1550 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1552 // z layer is created for all started operations in order to visualize operation AIS presentation
1554 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1555 if (aContext.IsNull())
1558 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1559 if (myVisualLayerId == 0) {
1560 if (myVisualLayerId == 0)
1561 aViewer->AddZLayer(myVisualLayerId);
1563 TColStd_SequenceOfInteger aZList;
1564 aViewer->GetAllZLayers(aZList);
1565 bool aFound = false;
1566 for (int i = 1; i <= aZList.Length(); i++) {
1567 if (aZList(i) == myVisualLayerId) {
1573 aViewer->AddZLayer(myVisualLayerId);
1575 // if there is an active operation with validated widget,
1576 // the filters of this widget should be activated in the created view
1577 myWorkshop->selectionActivate()->updateSelectionFilters();
1578 myWorkshop->selectionActivate()->updateSelectionModes();
1581 //******************************************************
1582 void PartSet_Module::widgetStateChanged(int thePreviousState)
1584 mySketchMgr->widgetStateChanged(thePreviousState);
1587 //******************************************************
1588 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1590 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1593 //******************************************************
1594 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1596 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1597 mySketchMgr->stopSketch(theOperation);
1601 //******************************************************
1602 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1604 GeomShapePtr aGeomShape;
1606 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1607 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1608 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1613 //******************************************************
1614 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1615 const GeomShapePtr& theGeomShape)
1617 AttributePtr anAttribute;
1618 GeomShapePtr aGeomShape = theGeomShape;
1619 if (!aGeomShape.get()) {
1620 // processing shape of result, e.g. sketch circle center is selected, this is a result
1621 // the geom shape is empty, the shape of result should be used
1622 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1623 if (aResult.get()) {
1624 aGeomShape = aResult->shape();
1628 if (aGeomShape.get()) {
1629 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1630 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1631 mySketchMgr->activeSketch());
1636 //******************************************************
1637 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1639 return sketchReentranceMgr()->reentrantMessage();
1642 //******************************************************
1643 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1645 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1648 //******************************************************
1649 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1652 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1656 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1657 if (!aChoiceTitle.isEmpty()) {
1658 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1661 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1663 aPanel->setWindowTitle(aChoiceTitle);
1667 //******************************************************
1668 XGUI_Workshop* PartSet_Module::getWorkshop() const
1670 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1671 return aConnector->workshop();
1674 void PartSet_Module::setDefaultConstraintShown()
1676 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1677 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1678 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1681 //******************************************************
1682 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1687 //******************************************************
1688 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1689 myCustomPrs->disableCustomMode(theMode);
1692 //******************************************************
1693 void PartSet_Module::enableCustomModes() {
1694 myCustomPrs->enableCustomModes();