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"
42 #include "PartSet_Filters.h"
43 #include "PartSet_FilterInfinite.h"
45 #include <PartSetPlugin_Remove.h>
46 #include <PartSetPlugin_Part.h>
47 #include <PartSetPlugin_Duplicate.h>
49 #include <SketchPlugin_ConstraintCoincidence.h>
51 #include <ModuleBase_Operation.h>
52 #include <ModuleBase_OperationAction.h>
53 #include <ModuleBase_IViewer.h>
54 #include <ModuleBase_IViewWindow.h>
55 #include <ModuleBase_IPropertyPanel.h>
56 #include <ModuleBase_ISelectionActivate.h>
57 #include <ModuleBase_WidgetChoice.h>
58 #include <ModuleBase_WidgetEditor.h>
59 #include <ModuleBase_WidgetValidated.h>
60 #include <ModuleBase_Tools.h>
61 #include <ModuleBase_OperationFeature.h>
62 #include <ModuleBase_WidgetFactory.h>
63 #include <ModuleBase_OperationDescription.h>
64 #include <ModuleBase_ViewerPrs.h>
66 #include <ModelAPI_Object.h>
67 #include <ModelAPI_Events.h>
68 #include <ModelAPI_Validator.h>
69 #include <ModelAPI_Data.h>
70 #include <ModelAPI_Session.h>
71 #include <ModelAPI_ResultBody.h>
72 #include <ModelAPI_AttributeString.h>
73 #include <ModelAPI_AttributeSelectionList.h>
74 #include <ModelAPI_Tools.h>
75 #include <ModelAPI_ResultConstruction.h>
76 #include <ModelAPI_AttributeIntArray.h>
78 #include <GeomDataAPI_Point2D.h>
79 #include <GeomDataAPI_Point.h>
80 #include <GeomDataAPI_Dir.h>
82 #include <XGUI_ActiveControlMgr.h>
83 #include <XGUI_ActiveControlSelector.h>
84 #include <XGUI_ActionsMgr.h>
85 #include <XGUI_ContextMenuMgr.h>
86 #include <XGUI_CustomPrs.h>
87 #include <XGUI_DataModel.h>
88 #include <XGUI_Displayer.h>
89 #include <XGUI_ErrorMgr.h>
90 #include <XGUI_FacesPanelSelector.h>
91 #include <XGUI_ModuleConnector.h>
92 #include <XGUI_ObjectsBrowser.h>
93 #include <XGUI_OperationMgr.h>
94 #include <XGUI_PropertyPanel.h>
95 #include <XGUI_SelectionMgr.h>
96 #include <XGUI_Tools.h>
97 #include <XGUI_Workshop.h>
99 #include <SketchPlugin_ConstraintAngle.h>
100 #include <SketchPlugin_ConstraintLength.h>
101 #include <SketchPlugin_ConstraintDistance.h>
102 #include <SketchPlugin_ConstraintParallel.h>
103 #include <SketchPlugin_ConstraintPerpendicular.h>
104 #include <SketchPlugin_ConstraintRadius.h>
105 #include <SketchPlugin_Feature.h>
106 #include <SketchPlugin_Projection.h>
107 #include <SketchPlugin_Sketch.h>
109 #include <SketcherPrs_SymbolPrs.h>
110 #include <SketcherPrs_PositionMgr.h>
111 #include <SketcherPrs_Coincident.h>
112 #include <SketcherPrs_Tools.h>
114 #include <Events_Loop.h>
115 #include <Config_PropManager.h>
116 #include <Config_Keywords.h>
118 #include <AIS_Dimension.hxx>
119 #include <AIS_InteractiveObject.hxx>
120 #include <StdSelect_TypeOfFace.hxx>
121 #include <TopoDS_Vertex.hxx>
122 #include <TopoDS.hxx>
123 #include <TopoDS_Shape.hxx>
124 #include <BRep_Tool.hxx>
127 #include <QMouseEvent>
130 #include <QApplication>
131 #include <QMessageBox>
132 #include <QMainWindow>
136 #include <GeomAlgoAPI_FaceBuilder.h>
137 #include <GeomDataAPI_Dir.h>
139 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
145 /*!Create and return new instance of XGUI_Module*/
146 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
148 return new PartSet_Module(theWshop);
151 //******************************************************
152 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
153 : ModuleBase_IModule(theWshop),
156 myIsOperationIsLaunched(false)
158 new PartSet_IconFactory(this);
160 mySketchMgr = new PartSet_SketcherMgr(this);
161 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
163 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
164 XGUI_Workshop* aWorkshop = aConnector->workshop();
166 ModuleBase_IViewer* aViewer = theWshop->viewer();
167 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
168 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
169 connect(aViewer, SIGNAL(viewTransformed(int)),
170 SLOT(onViewTransformed(int)));
171 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
172 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
173 myMenuMgr = new PartSet_MenuMgr(this);
174 myCustomPrs = new PartSet_CustomPrs(theWshop);
176 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
178 Events_Loop* aLoop = Events_Loop::loop();
179 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
181 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
182 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
183 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
184 std::set<std::string> aCRGroupNames;
185 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
186 aCRFilter->setGroupNames(aCRGroupNames);
187 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
189 setDefaultConstraintShown();
191 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
192 "Reference shape wireframe color in operation", Config_Prop::Color,
193 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
194 Config_PropManager::registerProp("Visualization", "operation_result_color",
195 "Result shape wireframe color in operation", Config_Prop::Color,
196 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
197 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
198 "Multi selector item color in operation", Config_Prop::Color,
199 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
200 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
201 "Color of removed feature in operation", Config_Prop::Color,
202 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
203 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
204 "Color of sketch plane", Config_Prop::Color,
205 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
207 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
208 "Hidden faces transparency",
209 Config_Prop::DblSpin,
211 std::ostringstream aStream;
212 aStream << SketcherPrs_Tools::getDefaultArrowSize();
213 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
214 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
216 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
217 Config_Prop::String, "Times-bold");
221 aStream << SketcherPrs_Tools::getDefaultTextHeight();
222 Config_PropManager::registerProp("Visualization", "dimension_value_size",
223 "Dimension value size", Config_Prop::IntSpin, aStream.str());
225 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
227 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
230 //******************************************************
231 PartSet_Module::~PartSet_Module()
233 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
234 mySelectionFilters.begin();
235 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
236 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
237 if (!aFilter.IsNull())
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, true);
449 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
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, true);
462 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
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<XGUI_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((XGUI_SelectionFilterType)aFilterType))
672 // using filtering of construction results only from faces panel
673 if (aFilterType == SF_ResultGroupNameFilter)
676 theSelectionFilters.Append(aFiltersIt->second);
680 //******************************************************
681 QIntList PartSet_Module::selectionFilters()
685 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
686 mySelectionFilters.begin();
687 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
688 aTypes.append(aFiltersIt->first);
693 //******************************************************
694 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
695 const Handle(SelectMgr_Filter)& theFilter)
697 mySelectionFilters[theFilterType] = theFilter;
700 //******************************************************
701 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
703 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
705 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
706 return mySelectionFilters[aType];
708 return Handle(SelectMgr_Filter)();
711 //******************************************************
712 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
714 if (theModes.contains(TopAbs_FACE))
715 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
716 if (theModes.contains(TopAbs_WIRE))
717 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
719 if (mySketchMgr->activeSketch().get())
720 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
723 //******************************************************
724 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
725 ObjectPtr& theObject, AttributePtr& theAttribute)
727 ObjectPtr anObject = theSelected->object();
728 GeomShapePtr aShape = theSelected->shape();
730 theAttribute = findAttribute(anObject, aShape);
731 // TODO: try to create result if object is an external object
732 theObject = anObject;
735 //******************************************************
736 bool PartSet_Module::isMouseOverWindow()
738 return mySketchMgr->isMouseOverWindow();
741 //******************************************************
742 bool PartSet_Module::isSketchNeutralPointActivated() const
744 bool isNeutralPoint = true;
745 if (sketchReentranceMgr()->isInternalEditActive())
746 isNeutralPoint = false;
747 if (myIsOperationIsLaunched)
748 isNeutralPoint = false;
750 return isNeutralPoint;
753 //******************************************************
754 void PartSet_Module::closeDocument()
756 myActivePartIndex = QModelIndex();
757 SketcherPrs_PositionMgr::get()->clearAll();
760 //******************************************************
761 void PartSet_Module::clearViewer()
763 myCustomPrs->clearPrs();
765 XGUI_Workshop* aWorkshop = getWorkshop();
766 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
767 aDisplayer->deactivateSelectionFilters(false);
770 //******************************************************
771 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
773 ModuleBase_OperationFeature* aFOperation =
774 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
778 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
779 // we have to manually activate the sketch label in edit mode
780 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
781 aPanel->activateWidget(aPanel->modelWidgets().first());
784 //******************************************************
785 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
786 QList<ModuleBase_ModelWidget*>& theWidgets) const
788 bool aProcessed = false;
790 ModuleBase_OperationFeature* aFOperation =
791 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
792 XGUI_Workshop* aWorkshop = getWorkshop();
793 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
794 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
795 ModuleBase_ISelection* aSelection = workshop()->selection();
796 // click on a point in sketch leads here with the point is highlighted, not yet selected
797 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
798 if (aPreselection.size() == 1) {
799 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
800 ObjectPtr anObject = aSelectedPrs->object();
802 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
803 FeaturePtr anOpFeature = aFOperation->feature();
804 GeomShapePtr aShape = aSelectedPrs->shape();
805 // click on the digit of dimension constrain comes here
806 // with an empty shape, so we need the check
807 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
808 // if feature has only one result and shape of result is equal to selected shape
809 // this attribute is not processed. It is a case of Sketch Point.
810 if (aFeature->results().size() == 1) {
811 ResultPtr aResult = aFeature->results().front();
812 if (aResult.get() && aResult->shape()->isEqual(aShape))
815 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
816 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
817 mySketchMgr->activeSketch());
818 if (anAttribute.get()) {
819 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
820 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
822 const std::string anAttributeId = anAttribute->id();
823 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
825 theWidgets = aFactory.getModelWidgets();
826 // it is possible that the point does not present in XML definition,
827 // in this case, we assume that it is not processed by this module
828 // e.g. "Intersection point" feature
829 aProcessed = !theWidgets.isEmpty();
837 //******************************************************
838 void PartSet_Module::onSelectionChanged()
840 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
844 bool isSketcherOp = false;
845 // An edit operation is enable only if the current opeation is the sketch operation
846 if (mySketchMgr->activeSketch()) {
847 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
848 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
851 // Editing of constraints can be done on selection
852 ModuleBase_ISelection* aSelect = myWorkshop->selection();
853 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
854 if (aSelected.size() == 1) {
855 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
856 ObjectPtr aObject = aPrs->object();
857 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
859 std::string aId = aFeature->getKind();
860 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
861 (aId == SketchPlugin_ConstraintLength::ID()) ||
862 (aId == SketchPlugin_ConstraintDistance::ID()) ||
863 (aId == SketchPlugin_ConstraintAngle::ID())) {
864 editFeature(aFeature);
871 //******************************************************
872 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
874 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
875 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
876 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
879 //******************************************************
880 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
882 Config_WidgetAPI* theWidgetApi)
884 ModuleBase_IWorkshop* aWorkshop = workshop();
885 XGUI_Workshop* aXUIWorkshop = getWorkshop();
886 ModuleBase_ModelWidget* aWgt = NULL;
887 if (theType == "sketch-start-label") {
888 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
889 theWidgetApi, myHasConstraintShown);
890 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
891 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
892 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
893 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
895 } else if (theType == "sketch-2dpoint_selector") {
896 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
898 aPointWgt->setSketch(mySketchMgr->activeSketch());
899 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
901 }else if (theType == "sketch-2dpoint_flyout_selector") {
902 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
904 aPointWgt->setSketch(mySketchMgr->activeSketch());
905 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
907 } else if (theType == "sketch_shape_selector") {
908 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
909 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
910 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
911 aWgt = aShapeSelectorWgt;
912 } else if (theType == "sketch_multi_selector") {
913 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
914 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
915 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
916 aWgt = aShapeSelectorWgt;
918 else if (theType == "sketch_feature_point_selector") {
919 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
920 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
921 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
922 aWgt = aPointSelectorWgt;
924 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
925 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
926 } else if (theType == "export_file_selector") {
927 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
928 } else if (theType == "sketch_launcher") {
929 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
930 } else if (theType == "module_choice") {
931 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
932 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
933 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
938 //******************************************************
939 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
941 ModuleBase_ModelWidget* anActiveWidget = 0;
943 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
945 return anActiveWidget;
947 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
949 return anActiveWidget;
951 return aPanel->activeWidget(true);
954 //******************************************************
955 bool PartSet_Module::deleteObjects()
957 bool isProcessed = false;
959 XGUI_Workshop* aWorkshop = getWorkshop();
960 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
962 //SessionPtr aMgr = ModelAPI_Session::get();
963 // 1. check whether the delete should be processed in the module
964 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
965 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
966 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
967 if (isSketchOp || isNestedOp) {
969 // 2. find selected presentations
970 // selected objects should be collected before the current operation abort because
971 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
972 ModuleBase_ISelection* aSel = workshop()->selection();
973 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
974 // if there are no selected objects in the viewer, that means that the selection in another
975 // place cased this method. It is necessary to return the false value to understande in above
976 // method that delete is not processed
977 if (aSelectedObj.count() == 0)
980 // avoid delete of the objects, which are not belong to the current sketch
981 // in order to do not delete results of other sketches
982 QObjectPtrList aSketchObjects;
983 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
984 for ( ; anIt != aLast; anIt++) {
985 ObjectPtr anObject = *anIt;
986 if (mySketchMgr->isObjectOfSketch(anObject)) {
987 // sketch feature should be used in this list because workshop deletes features only
988 // results are skipped
989 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
990 aSketchObjects.append(aSketchFeature);
993 // if the selection contains only local selected presentations from other sketches,
994 // the Delete operation should not be done at all
995 if (aSketchObjects.size() == 0)
998 // 3. start operation
999 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1000 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
1002 // the active nested sketch operation should be aborted unconditionally
1003 // the Delete action should be additionally granted for the Sketch operation
1004 // in order to do not abort/commit it
1006 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1007 return true; // the objects are processed but can not be deleted
1009 anOpMgr->startOperation(anOpAction);
1011 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1012 // the problem is in AIS Dimensions recompute
1013 // if a line and the dim are removed, line is the first
1014 // it causes the AIS recompute, where the base line is null,
1015 // the result is empty AIS in the viewer
1016 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1018 // 4. delete features
1019 // sketch feature should be skipped, only sub-features can be removed
1020 // when sketch operation is active
1021 aWorkshop->deleteFeatures(aSketchObjects);
1022 // 5. stop operation
1023 anOpMgr->commitOperation();
1028 //******************************************************
1029 void PartSet_Module::editFeature(FeaturePtr theFeature)
1031 storeConstraintsState(theFeature->getKind());
1032 ModuleBase_IModule::editFeature(theFeature);
1035 //******************************************************
1036 bool PartSet_Module::canCommitOperation() const
1041 //******************************************************
1042 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1044 myIsOperationIsLaunched = true;
1045 storeConstraintsState(theCmdId.toStdString());
1046 updateConstraintsState(theCmdId.toStdString());
1048 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1050 myIsOperationIsLaunched = false;
1053 //******************************************************
1054 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1056 if (myWorkshop->currentOperation() &&
1057 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1058 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1059 mySketchMgr->showConstraintStates();
1060 myHasConstraintShown = aShownStates;
1064 //******************************************************
1065 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1067 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1068 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1069 // Show constraints if a constraint was anOperation
1070 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1071 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1072 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1073 myHasConstraintShown[PartSet_Tools::Expressions]);
1077 //******************************************************
1078 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1080 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1081 if (!anAIS.IsNull()) {
1082 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1083 if (aFeature.get()) {
1084 bool aToUseZLayer = false;
1085 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1086 aToUseZLayer = true;
1088 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1089 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1092 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1093 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1094 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1096 aCtx->SetZLayer(anAIS, myVisualLayerId);
1102 //******************************************************
1103 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1106 // it should be recomputed in order to disappear in the viewer if the corresponded object
1108 //if (myCustomPrs->isActive())
1109 // myCustomPrs->redisplay(theObject, false);
1112 //******************************************************
1113 void PartSet_Module::onViewTransformed(int theTrsfType)
1115 // Set length of arrows constant in pixel size
1116 // if the operation is panning or rotate or panglobal then do nothing
1117 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1119 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1120 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1121 if (aContext.IsNull())
1124 //Handle(V3d_View) aView = aViewer->activeView();
1126 XGUI_Workshop* aWorkshop = getWorkshop();
1127 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1128 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1129 Handle(V3d_View) aView;
1131 for (aV3dViewer->InitDefinedViews();
1132 aV3dViewer->MoreDefinedViews();
1133 aV3dViewer->NextDefinedViews()) {
1134 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1135 double aS = aV->Scale();
1144 bool isModified = false;
1145 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1146 if (aCurrentOperation &&
1147 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1148 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1149 (aCurrentOperation->id() == "Measurement")))
1151 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1153 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1154 SketcherPrs_Tools::setArrowSize(aLen);
1155 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1156 aViewer->SetScale(aViewer->activeView(), aCurScale);
1158 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1159 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1161 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1162 foreach(AISObjectPtr aAIS, aPrsList) {
1163 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1165 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1166 if (!aDim.IsNull()) {
1167 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1168 aContext->Redisplay(aDim, false);
1173 aDisplayer->updateViewer();
1178 //******************************************************
1179 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1181 return myCustomPrs->isActive(theFlag);
1184 //******************************************************
1185 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1186 const ModuleBase_CustomizeFlag& theFlag,
1187 const bool theUpdateViewer)
1189 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1192 //******************************************************
1193 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1194 const bool theUpdateViewer)
1196 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1199 //******************************************************
1200 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1201 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1203 bool aCustomized = false;
1205 XGUI_Workshop* aWorkshop = getWorkshop();
1206 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1207 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1211 if (!theResult.get()) {
1212 std::vector<int> aColor;
1213 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1214 if (!aColor.empty()) {
1215 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1218 // customize dimentional constrains
1219 sketchMgr()->customizePresentation(anObject);
1224 //******************************************************
1225 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1226 AISObjectPtr thePrs,
1227 GeomCustomPrsPtr theCustomPrs)
1229 bool aCustomized = false;
1231 XGUI_Workshop* aWorkshop = getWorkshop();
1232 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1233 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1237 std::vector<int> aColor;
1238 bool aUseCustomColor = true;
1239 if (aUseCustomColor)
1240 myOverconstraintListener->getCustomColor(anObject, aColor);
1241 // customize sketch symbol presentation
1242 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1243 if (!anAISIO.IsNull()) {
1244 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1245 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1246 if (!aPrs.IsNull()) {
1247 aPrs->SetCustomColor(aColor);
1250 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1251 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1252 if (!aPrs.IsNull()) {
1253 aPrs->SetCustomColor(aColor);
1258 // customize sketch dimension constraint presentation
1260 if (!aColor.empty()) { // otherwise presentation has the default color
1261 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1267 //******************************************************
1268 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1269 const bool theUpdateViewer)
1271 bool isRedisplayed = false;
1272 if (myCustomPrs->isActive(theFlag))
1273 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1275 return isRedisplayed;
1278 //******************************************************
1279 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1281 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1283 QLabel* aLabel = aOB->activeDocLabel();
1284 aLabel->installEventFilter(myMenuMgr);
1285 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1286 SLOT(onActiveDocPopup(const QPoint&)));
1287 aOB->treeView()->setExpandsOnDoubleClick(false);
1288 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1289 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1291 Events_Loop* aLoop = Events_Loop::loop();
1292 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1296 //******************************************************
1297 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1299 SessionPtr aMgr = ModelAPI_Session::get();
1300 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1302 XGUI_Workshop* aWorkshop = getWorkshop();
1303 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1305 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1308 aMenu.addAction(aActivatePartAction);
1309 aMenu.exec(aHeader->mapToGlobal(thePnt));
1312 //******************************************************
1313 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1315 return mySketchMgr->createPresentation(theResult);
1318 //******************************************************
1319 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1322 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1324 /// If last line finished on vertex the lines creation sequence has to be break
1325 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1327 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1328 // if there is an active widget, find the presented object in it
1329 if (!anActiveWidget)
1330 anActiveWidget = aPanel->preselectionWidget();
1332 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1334 if (aWidgetValidated)
1335 anObject = aWidgetValidated->findPresentedObject(theAIS);
1341 //******************************************************
1342 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1344 bool aCanBeShaged = true;
1346 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1348 aCanBeShaged = false;
1350 return aCanBeShaged;
1353 //******************************************************
1354 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1356 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1357 int aSelected = aObjects.size();
1358 SessionPtr aMgr = ModelAPI_Session::get();
1359 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1361 bool hasResult = false;
1362 bool hasFeature = false;
1363 bool hasParameter = false;
1364 bool hasCompositeOwner = false;
1365 bool hasResultInHistory = false;
1366 bool hasFolder = false;
1367 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1368 hasCompositeOwner, hasResultInHistory, hasFolder);
1370 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1371 if (aSelected == 1) {
1372 ObjectPtr aObject = aObjects.first();
1374 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1375 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1376 bool isPart = aPart.get() ||
1377 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1379 DocumentPtr aPartDoc;
1381 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1383 if (aPart.get()) // this may be null is Part feature is disabled
1384 aPartDoc = aPart->partDoc();
1386 theMenu->addAction(aActivatePartAction);
1387 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1389 } else if (aObject->document() == aMgr->activeDocument()) {
1390 if (hasParameter || hasFeature) {
1391 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1392 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1393 if (aCurrentOp && aFeature.get()) {
1394 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1395 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1402 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1403 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1404 theMenu->addSeparator();
1407 bool aNotDeactivate = (aCurrentOp == 0);
1408 if (!aNotDeactivate) {
1409 aActivatePartAction->setEnabled(false);
1413 //******************************************************
1414 #define EXPAND_PARENT(OBJ) \
1415 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1416 if (aObjIndex.isValid()) { \
1417 QModelIndex aParent = aObjIndex.parent(); \
1418 int aCount = aDataModel->rowCount(aParent); \
1420 aTreeView->setExpanded(aParent, true); \
1423 //******************************************************
1424 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1426 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1427 // Do not change activation of parts if an operation active
1428 static QStringList aAllowActivationList;
1429 if (aAllowActivationList.isEmpty())
1430 aAllowActivationList <<
1431 QString(PartSetPlugin_Part::ID().c_str()) <<
1432 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1433 QString(PartSetPlugin_Remove::ID().c_str());
1434 if (myWorkshop->currentOperation() &&
1435 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1437 XGUI_Workshop* aWorkshop = getWorkshop();
1438 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1439 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1440 QPalette aPalet = aLabel->palette();
1442 SessionPtr aMgr = ModelAPI_Session::get();
1443 DocumentPtr aActiveDoc = aMgr->activeDocument();
1445 // Clear active part index if there is no Part documents
1446 // It could be not null if document was closed and opened a new
1447 // without closeDocument call
1448 if (aMgr->allOpenedDocuments().size() <= 1)
1449 myActivePartIndex = QModelIndex();
1451 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1452 QModelIndex aOldActive = myActivePartIndex;
1453 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1454 bool needUpdate = false;
1455 if (myActivePartIndex.isValid()) {
1456 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1458 aTreeView->setExpanded(myActivePartIndex, true);
1460 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1461 aTreeView->setExpanded(aOldActive, false);
1463 aLabel->setPalette(aPalet);
1464 aWorkshop->updateCommandStatus();
1466 // Update displayed objects in order to update active color
1467 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1468 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1470 foreach(ObjectPtr aObj, aObjects) {
1471 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1472 aObj->isDisabled() || (!aObj->isDisplayed());
1474 aDisplayer->redisplay(aObj, false);
1476 aDisplayer->updateViewer();
1477 // Update tree items if they are expanded
1479 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1481 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1482 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1483 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1484 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1486 ObjectPtr aConstrObj;
1487 ObjectPtr aResultObj;
1488 std::set<ObjectPtr>::const_iterator aIt;
1489 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1490 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1491 ObjectPtr aObject = (*aIt);
1492 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1493 && (aObject->document() != aRootDoc))
1494 aResultObj = aObject;
1495 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1496 && (aObject->document() != aRootDoc))
1497 aConstrObj = aObject;
1498 if (aResultObj.get() && aConstrObj.get())
1502 if (aResultObj.get() || aConstrObj.get()) {
1503 XGUI_Workshop* aWorkshop = getWorkshop();
1504 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1505 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1507 if (aResultObj.get()) {
1508 EXPAND_PARENT(aResultObj)
1510 if (aConstrObj.get()) {
1511 EXPAND_PARENT(aConstrObj)
1517 //******************************************************
1518 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1520 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1522 SessionPtr aMgr = ModelAPI_Session::get();
1523 if (!theIndex.isValid()) {
1524 // It seems that this code is obsolete
1525 //aMgr->setActiveDocument(aMgr->moduleDocument());
1528 if (theIndex.column() != 1) // Use only first column
1531 XGUI_Workshop* aWorkshop = getWorkshop();
1532 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1533 // De not use non editable Indexes
1534 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1536 ObjectPtr aObj = aDataModel->object(theIndex);
1538 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1539 if (!aPart.get()) { // Probably this is Feature
1540 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1541 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1542 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1545 if (aPart.get()) { // if this is a part
1546 if (aPart->partDoc() == aMgr->activeDocument()) {
1547 myMenuMgr->activatePartSet();
1549 myMenuMgr->activatePart(aPart);
1554 //******************************************************
1555 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1557 // z layer is created for all started operations in order to visualize operation AIS presentation
1559 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1560 if (aContext.IsNull())
1563 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1564 if (myVisualLayerId == 0) {
1565 if (myVisualLayerId == 0)
1566 aViewer->AddZLayer(myVisualLayerId);
1568 TColStd_SequenceOfInteger aZList;
1569 aViewer->GetAllZLayers(aZList);
1570 bool aFound = false;
1571 for (int i = 1; i <= aZList.Length(); i++) {
1572 if (aZList(i) == myVisualLayerId) {
1578 aViewer->AddZLayer(myVisualLayerId);
1580 // if there is an active operation with validated widget,
1581 // the filters of this widget should be activated in the created view
1582 myWorkshop->selectionActivate()->updateSelectionFilters();
1583 myWorkshop->selectionActivate()->updateSelectionModes();
1586 //******************************************************
1587 void PartSet_Module::widgetStateChanged(int thePreviousState)
1589 mySketchMgr->widgetStateChanged(thePreviousState);
1592 //******************************************************
1593 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1595 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1598 //******************************************************
1599 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1601 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1602 mySketchMgr->stopSketch(theOperation);
1606 //******************************************************
1607 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1609 GeomShapePtr aGeomShape;
1611 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1612 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1613 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1618 //******************************************************
1619 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1620 const GeomShapePtr& theGeomShape)
1622 AttributePtr anAttribute;
1623 GeomShapePtr aGeomShape = theGeomShape;
1624 if (!aGeomShape.get()) {
1625 // processing shape of result, e.g. sketch circle center is selected, this is a result
1626 // the geom shape is empty, the shape of result should be used
1627 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1628 if (aResult.get()) {
1629 aGeomShape = aResult->shape();
1633 if (aGeomShape.get()) {
1634 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1635 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1636 mySketchMgr->activeSketch());
1641 //******************************************************
1642 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1644 return sketchReentranceMgr()->reentrantMessage();
1647 //******************************************************
1648 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1650 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1653 //******************************************************
1654 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1657 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1661 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1662 if (!aChoiceTitle.isEmpty()) {
1663 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1666 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1668 aPanel->setWindowTitle(aChoiceTitle);
1672 //******************************************************
1673 XGUI_Workshop* PartSet_Module::getWorkshop() const
1675 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1676 return aConnector->workshop();
1679 void PartSet_Module::setDefaultConstraintShown()
1681 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1682 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1683 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1686 //******************************************************
1687 ModuleBase_ITreeNode* PartSet_Module::rootNode() const