1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_Module.h"
22 #include "PartSet_WidgetSketchLabel.h"
23 #include "PartSet_Validators.h"
24 #include "PartSet_Tools.h"
25 #include "PartSet_PreviewPlanes.h"
26 #include "PartSet_WidgetPoint2d.h"
27 #include "PartSet_WidgetPoint2DFlyout.h"
28 #include "PartSet_WidgetShapeSelector.h"
29 #include "PartSet_WidgetMultiSelector.h"
30 #include "PartSet_WidgetFeaturePointSelector.h"
31 #include "PartSet_WidgetEditor.h"
32 #include "PartSet_WidgetFileSelector.h"
33 #include "PartSet_WidgetSketchCreator.h"
34 #include "PartSet_SketcherMgr.h"
35 #include "PartSet_SketcherReentrantMgr.h"
36 #include "PartSet_ResultSketchPrs.h"
37 #include "PartSet_MenuMgr.h"
38 #include "PartSet_CustomPrs.h"
39 #include "PartSet_IconFactory.h"
40 #include "PartSet_OverconstraintListener.h"
41 #include "PartSet_TreeNodes.h"
43 #include "PartSet_Filters.h"
44 #include "PartSet_FilterInfinite.h"
46 #include <PartSetPlugin_Remove.h>
47 #include <PartSetPlugin_Part.h>
48 #include <PartSetPlugin_Duplicate.h>
50 #include <SketchPlugin_ConstraintCoincidence.h>
52 #include <ModuleBase_Operation.h>
53 #include <ModuleBase_OperationAction.h>
54 #include <ModuleBase_IViewer.h>
55 #include <ModuleBase_IViewWindow.h>
56 #include <ModuleBase_IPropertyPanel.h>
57 #include <ModuleBase_ISelectionActivate.h>
58 #include <ModuleBase_WidgetChoice.h>
59 #include <ModuleBase_WidgetEditor.h>
60 #include <ModuleBase_WidgetValidated.h>
61 #include <ModuleBase_Tools.h>
62 #include <ModuleBase_OperationFeature.h>
63 #include <ModuleBase_WidgetFactory.h>
64 #include <ModuleBase_OperationDescription.h>
65 #include <ModuleBase_ViewerPrs.h>
67 #include <ModelAPI_Object.h>
68 #include <ModelAPI_Events.h>
69 #include <ModelAPI_Validator.h>
70 #include <ModelAPI_Data.h>
71 #include <ModelAPI_Session.h>
72 #include <ModelAPI_ResultBody.h>
73 #include <ModelAPI_AttributeString.h>
74 #include <ModelAPI_AttributeSelectionList.h>
75 #include <ModelAPI_Tools.h>
76 #include <ModelAPI_ResultConstruction.h>
77 #include <ModelAPI_AttributeIntArray.h>
79 #include <GeomDataAPI_Point2D.h>
80 #include <GeomDataAPI_Point.h>
81 #include <GeomDataAPI_Dir.h>
83 #include <XGUI_ActiveControlMgr.h>
84 #include <XGUI_ActiveControlSelector.h>
85 #include <XGUI_ActionsMgr.h>
86 #include <XGUI_ContextMenuMgr.h>
87 #include <XGUI_CustomPrs.h>
88 #include <XGUI_DataModel.h>
89 #include <XGUI_Displayer.h>
90 #include <XGUI_ErrorMgr.h>
91 #include <XGUI_FacesPanelSelector.h>
92 #include <XGUI_ModuleConnector.h>
93 #include <XGUI_ObjectsBrowser.h>
94 #include <XGUI_OperationMgr.h>
95 #include <XGUI_PropertyPanel.h>
96 #include <XGUI_SelectionMgr.h>
97 #include <XGUI_Tools.h>
98 #include <XGUI_Workshop.h>
100 #include <SketchPlugin_ConstraintAngle.h>
101 #include <SketchPlugin_ConstraintLength.h>
102 #include <SketchPlugin_ConstraintDistance.h>
103 #include <SketchPlugin_ConstraintParallel.h>
104 #include <SketchPlugin_ConstraintPerpendicular.h>
105 #include <SketchPlugin_ConstraintRadius.h>
106 #include <SketchPlugin_Feature.h>
107 #include <SketchPlugin_Projection.h>
108 #include <SketchPlugin_Sketch.h>
110 #include <SketcherPrs_SymbolPrs.h>
111 #include <SketcherPrs_PositionMgr.h>
112 #include <SketcherPrs_Coincident.h>
113 #include <SketcherPrs_Tools.h>
115 #include <Events_Loop.h>
116 #include <Config_PropManager.h>
117 #include <Config_Keywords.h>
119 #include <AIS_Dimension.hxx>
120 #include <AIS_InteractiveObject.hxx>
121 #include <StdSelect_TypeOfFace.hxx>
122 #include <TopoDS_Vertex.hxx>
123 #include <TopoDS.hxx>
124 #include <TopoDS_Shape.hxx>
125 #include <BRep_Tool.hxx>
128 #include <QMouseEvent>
131 #include <QApplication>
132 #include <QMessageBox>
133 #include <QMainWindow>
137 #include <GeomAlgoAPI_FaceBuilder.h>
138 #include <GeomDataAPI_Dir.h>
140 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
146 /*!Create and return new instance of XGUI_Module*/
147 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
149 return new PartSet_Module(theWshop);
152 //******************************************************
153 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
154 : ModuleBase_IModule(theWshop),
157 myIsOperationIsLaunched(false)
159 new PartSet_IconFactory(this);
161 mySketchMgr = new PartSet_SketcherMgr(this);
162 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
164 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
165 XGUI_Workshop* aWorkshop = aConnector->workshop();
167 ModuleBase_IViewer* aViewer = theWshop->viewer();
168 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
169 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
170 connect(aViewer, SIGNAL(viewTransformed(int)),
171 SLOT(onViewTransformed(int)));
172 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
173 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
174 myMenuMgr = new PartSet_MenuMgr(this);
175 myCustomPrs = new PartSet_CustomPrs(theWshop);
177 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
179 Events_Loop* aLoop = Events_Loop::loop();
180 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
182 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
183 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
184 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
185 std::set<std::string> aCRGroupNames;
186 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
187 aCRFilter->setGroupNames(aCRGroupNames);
188 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
190 setDefaultConstraintShown();
192 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
193 "Reference shape wireframe color in operation", Config_Prop::Color,
194 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
195 Config_PropManager::registerProp("Visualization", "operation_result_color",
196 "Result shape wireframe color in operation", Config_Prop::Color,
197 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
198 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
199 "Multi selector item color in operation", Config_Prop::Color,
200 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
201 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
202 "Color of removed feature in operation", Config_Prop::Color,
203 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
204 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
205 "Color of sketch plane", Config_Prop::Color,
206 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
208 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
209 "Hidden faces transparency",
210 Config_Prop::DblSpin,
212 std::ostringstream aStream;
213 aStream << SketcherPrs_Tools::getDefaultArrowSize();
214 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
215 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
217 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
218 Config_Prop::String, "Times-bold");
222 aStream << SketcherPrs_Tools::getDefaultTextHeight();
223 Config_PropManager::registerProp("Visualization", "dimension_value_size",
224 "Dimension value size", Config_Prop::IntSpin, aStream.str());
226 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
228 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
231 //******************************************************
232 PartSet_Module::~PartSet_Module()
234 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
235 mySelectionFilters.begin();
236 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
237 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
238 if (!aFilter.IsNull())
242 delete myOverconstraintListener;
246 //******************************************************
247 void PartSet_Module::createFeatures()
249 ModuleBase_IModule::createFeatures();
250 myRoot = new PartSet_RootNode();
251 myRoot->setWorkshop(workshop());
255 //******************************************************
256 void PartSet_Module::storeSelection()
258 // cash is used only to restore selection, so it should be filled in storeSelection and
259 // after applying immediatelly cleared in restoreSelection
260 myCurrentSelection.clear();
261 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
264 //******************************************************
265 void PartSet_Module::restoreSelection()
267 // cash is used only to restore selection, so it should be filled in storeSelection and
268 // after applying immediatelly cleared in restoreSelection
269 sketchMgr()->restoreSelection(myCurrentSelection);
270 myCurrentSelection.clear();
273 //******************************************************
274 void PartSet_Module::registerValidators()
276 //Registering of validators
277 SessionPtr aMgr = ModelAPI_Session::get();
278 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
279 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
280 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
281 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
282 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
283 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
284 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
285 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
286 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
287 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
288 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
289 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
290 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
291 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
292 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
293 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
294 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
295 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
296 aFactory->registerValidator("PartSet_MultyTranslationSelection",
297 new PartSet_MultyTranslationSelection);
298 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
299 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
300 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
303 //******************************************************
304 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
305 const bool isToConnect)
307 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
310 //******************************************************
311 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
313 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
314 mySketchMgr->commitNestedSketch(theOperation);
316 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
317 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
318 overconstraintListener()->setActive(false);
320 /// Restart sketcher operations automatically
321 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
323 ModuleBase_OperationFeature* aFOperation =
324 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
325 if (aFOperation && !aFOperation->isEditOperation()) {
326 // the selection is cleared after commit the create operation
327 // in order to do not use the same selected objects in the restarted operation
328 // for common behaviour, the selection is cleared even if the operation is not restarted
329 getWorkshop()->selector()->clearSelection();
334 //******************************************************
335 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
337 /// Restart sketcher operations automatically
338 mySketchReentrantMgr->operationAborted(theOperation);
339 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
340 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
341 overconstraintListener()->setActive(false);
344 //******************************************************
345 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
347 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
350 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
351 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
353 ModuleBase_ModelWidget* aFilledWidget = 0;
354 bool aPostonedWidgetActivation = false;
356 FeaturePtr aFeature = aFOperation->feature();
357 /// Restart sketcher operations automatically
358 /// it is important to call method of sketch reentrant manager before filling of PP
359 /// because it fills some created feature attributes, these new values should be used
360 /// to fill the property panel
361 mySketchReentrantMgr->operationStarted(theOperation);
363 aWorkshop->fillPropertyPanel(aFOperation);
364 // filling the operation values by the current selection
365 // if the operation can be committed after the controls filling, the method perform should
366 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
367 bool isOperationCommitted = false;
368 if (!aFOperation->isEditOperation()) {
369 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
370 // if there is a greed attribute, automatic commit by preselection
371 // for this feature is prohibited
372 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
373 if (currentOperation() != aFOperation)
374 isOperationCommitted = true;
376 if (aGreedAttributeId.empty()) {
377 // a signal should be emitted before the next widget activation
378 // because, the activation of the next widget will give a focus to the widget.
379 // As a result the value of the widget is initialized.
380 // And commit may happens until the value is entered.
382 if (mySketchReentrantMgr->canBeCommittedByPreselection())
383 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
384 // activate the next obligatory widget
385 if (!isOperationCommitted)
386 aPropertyPanel->activateNextWidget(aFilledWidget);
389 else { // there is a greed widget
390 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
391 std::string aFirstAttributeId = aWidgets.front()->attributeID();
392 // activate next widget after greeded if it is the first widget in the panel
393 // else the first panel widget is already activated by operation start
394 if (aFirstAttributeId == aGreedAttributeId)
395 aPostonedWidgetActivation = true;
398 } if (!isOperationCommitted) {
399 aWorkshop->connectToPropertyPanel(true);
400 updateSketcherOnStart(aFOperation);
401 updatePresentationsOnStart(aFOperation);
403 // the objects of the current operation should be deactivated
404 QObjectPtrList anObjects;
405 anObjects.append(aFeature);
406 std::list<ResultPtr> aResults;
407 ModelAPI_Tools::allResults(aFeature, aResults);
408 std::list<ResultPtr>::const_iterator aIt;
409 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
410 anObjects.append(*aIt);
412 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
413 for (; anIt != aLast; anIt++)
414 aWorkshop->deactivateActiveObject(*anIt, false);
415 if (anObjects.size() > 0) {
416 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
417 aDisplayer->updateViewer();
419 /// state of command actions should be updated after displayed objects modification because
420 /// deactivation(for example) of objects may influence on selection in the viewer
421 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
422 workshop()->updateCommandStatus();
424 if (aPostonedWidgetActivation) {
425 // if the widget is an empty in the chain of activated widgets, the current operation
426 // is restarted. It should be performed after functionality of the operation starting
427 aPropertyPanel->activateNextWidget(aFilledWidget);
432 //******************************************************
433 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
435 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
436 mySketchMgr->startSketch(theOperation);
438 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
439 mySketchMgr->startNestedSketch(theOperation);
443 //******************************************************
444 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
446 ModuleBase_OperationFeature* aFOperation =
447 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
449 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
450 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
454 //******************************************************
455 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
457 ModuleBase_IModule::operationResumed(theOperation);
459 ModuleBase_OperationFeature* aFOperation =
460 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
462 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
463 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
467 //******************************************************
468 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
470 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
471 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
472 bool isModified = isModifiedArgs || isModifiedResults;
474 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
475 mySketchMgr->stopNestedSketch(theOperation);
477 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
478 setDefaultConstraintShown();
480 //VSV: Viewer is updated on feature update and redisplay
482 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
483 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
484 aDisplayer->updateViewer();
487 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
488 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
489 for (; anIt != aLast; anIt++) {
490 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
494 //******************************************************
495 ModuleBase_Operation* PartSet_Module::currentOperation() const
497 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
498 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
499 return anOpMgr->currentOperation();
502 //******************************************************
503 bool PartSet_Module::canUndo() const
505 bool aCanUndo = false;
506 SessionPtr aMgr = ModelAPI_Session::get();
507 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
508 aCanUndo = !aMgr->isOperation();
509 if (!aCanUndo) // check the enable state additionally by sketch manager
510 aCanUndo = aMgr->canUndo();
515 //******************************************************
516 bool PartSet_Module::canRedo() const
518 bool aCanRedo = false;
519 SessionPtr aMgr = ModelAPI_Session::get();
520 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
521 aCanRedo = !aMgr->isOperation();
522 if (!aCanRedo) // check the enable state additionally by sketch manager
523 aCanRedo = aMgr->canRedo();
528 //******************************************************
529 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
532 if (theActionId == "MOVE_CMD") {
533 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
535 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
536 // part features can not be moved in the history.
537 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
544 //******************************************************
545 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
547 // the sketch manager put the restriction to the objects erase
548 return mySketchMgr->canEraseObject(theObject);
551 //******************************************************
552 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
554 // the sketch manager put the restriction to the objects display
555 return mySketchMgr->canDisplayObject(theObject);
558 //******************************************************
559 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
560 const QString& theStartedOperationKind)
562 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
565 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
568 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
570 mySketchMgr->processHiddenObject(theObjects);
573 //******************************************************
574 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
576 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
578 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
579 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
580 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
581 if (isSketchOp || isNestedOp) {
582 // in active sketch operation it is possible to activate operation object in selection
583 // in the edit operation, e.g. points of the line can be moved when the line is edited
584 ModuleBase_OperationFeature* aFOperation =
585 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
586 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
591 //******************************************************
592 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
594 QMap<int, QAction*>& theMenuActions) const
596 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
599 //******************************************************
600 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
602 myMenuMgr->updateViewerMenu(theStdActions);
605 //******************************************************
606 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
608 bool isEnabledFixed = false;
609 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
610 mySketchReentrantMgr->isInternalEditActive())
611 isEnabledFixed = true;
612 return isEnabledFixed;
615 //******************************************************
616 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
618 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
619 if (anError.isEmpty())
620 anError = sketchMgr()->getFeatureError(theFeature);
625 //******************************************************
626 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
627 QStringList& theIds) const
629 myMenuMgr->grantedOperationIds(theOperation, theIds);
631 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
632 XGUI_Workshop* aWorkshop = getWorkshop();
633 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
637 //******************************************************
638 void PartSet_Module::activeSelectionModes(QIntList& theModes)
640 if (mySketchMgr->activeSketch().get())
641 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
643 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
646 //******************************************************
647 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
649 customSubShapesSelectionModes(theModes);
650 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
651 //myWorkshop->module()->activeSelectionModes(theModes);
654 //******************************************************
655 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
656 SelectMgr_ListOfFilter& theSelectionFilters)
658 bool isSketchActive = mySketchMgr->activeSketch().get();
660 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
661 mySelectionFilters.begin();
662 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
663 int aFilterType = aFiltersIt->first;
664 // do not add not participating filters in given parameters
665 if (!theFilterTypes.contains(aFilterType))
668 // using sketch filters only if sketch operation is active
669 if (!isSketchActive &&
670 mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
673 // using filtering of construction results only from faces panel
674 if (aFilterType == SF_ResultGroupNameFilter)
677 theSelectionFilters.Append(aFiltersIt->second);
681 //******************************************************
682 QIntList PartSet_Module::selectionFilters()
686 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
687 mySelectionFilters.begin();
688 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
689 aTypes.append(aFiltersIt->first);
694 //******************************************************
695 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
696 const Handle(SelectMgr_Filter)& theFilter)
698 mySelectionFilters[theFilterType] = theFilter;
701 //******************************************************
702 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
704 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
706 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
707 return mySelectionFilters[aType];
709 return Handle(SelectMgr_Filter)();
712 //******************************************************
713 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
715 if (theModes.contains(TopAbs_FACE))
716 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
717 if (theModes.contains(TopAbs_WIRE))
718 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
720 if (mySketchMgr->activeSketch().get())
721 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
724 //******************************************************
725 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
726 ObjectPtr& theObject, AttributePtr& theAttribute)
728 ObjectPtr anObject = theSelected->object();
729 GeomShapePtr aShape = theSelected->shape();
731 theAttribute = findAttribute(anObject, aShape);
732 // TODO: try to create result if object is an external object
733 theObject = anObject;
736 //******************************************************
737 bool PartSet_Module::isMouseOverWindow()
739 return mySketchMgr->isMouseOverWindow();
742 //******************************************************
743 bool PartSet_Module::isSketchNeutralPointActivated() const
745 bool isNeutralPoint = true;
746 if (sketchReentranceMgr()->isInternalEditActive())
747 isNeutralPoint = false;
748 if (myIsOperationIsLaunched)
749 isNeutralPoint = false;
751 return isNeutralPoint;
754 //******************************************************
755 void PartSet_Module::closeDocument()
757 myActivePartIndex = QModelIndex();
758 SketcherPrs_PositionMgr::get()->clearAll();
761 //******************************************************
762 void PartSet_Module::clearViewer()
764 myCustomPrs->clearPrs();
766 XGUI_Workshop* aWorkshop = getWorkshop();
767 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
768 aDisplayer->deactivateSelectionFilters(false);
771 //******************************************************
772 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
774 ModuleBase_OperationFeature* aFOperation =
775 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
779 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
780 // we have to manually activate the sketch label in edit mode
781 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
782 aPanel->activateWidget(aPanel->modelWidgets().first());
785 //******************************************************
786 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
787 QList<ModuleBase_ModelWidget*>& theWidgets) const
789 bool aProcessed = false;
791 ModuleBase_OperationFeature* aFOperation =
792 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
793 XGUI_Workshop* aWorkshop = getWorkshop();
794 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
795 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
796 ModuleBase_ISelection* aSelection = workshop()->selection();
797 // click on a point in sketch leads here with the point is highlighted, not yet selected
798 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
799 if (aPreselection.size() == 1) {
800 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
801 ObjectPtr anObject = aSelectedPrs->object();
803 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
804 FeaturePtr anOpFeature = aFOperation->feature();
805 GeomShapePtr aShape = aSelectedPrs->shape();
806 // click on the digit of dimension constrain comes here
807 // with an empty shape, so we need the check
808 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
809 // if feature has only one result and shape of result is equal to selected shape
810 // this attribute is not processed. It is a case of Sketch Point.
811 if (aFeature->results().size() == 1) {
812 ResultPtr aResult = aFeature->results().front();
813 if (aResult.get() && aResult->shape()->isEqual(aShape))
816 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
817 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
818 mySketchMgr->activeSketch());
819 if (anAttribute.get()) {
820 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
821 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
823 const std::string anAttributeId = anAttribute->id();
824 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
826 theWidgets = aFactory.getModelWidgets();
827 // it is possible that the point does not present in XML definition,
828 // in this case, we assume that it is not processed by this module
829 // e.g. "Intersection point" feature
830 aProcessed = !theWidgets.isEmpty();
838 //******************************************************
839 void PartSet_Module::onSelectionChanged()
841 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
845 bool isSketcherOp = false;
846 // An edit operation is enable only if the current opeation is the sketch operation
847 if (mySketchMgr->activeSketch()) {
848 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
849 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
852 // Editing of constraints can be done on selection
853 ModuleBase_ISelection* aSelect = myWorkshop->selection();
854 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
855 if (aSelected.size() == 1) {
856 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
857 ObjectPtr aObject = aPrs->object();
858 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
860 std::string aId = aFeature->getKind();
861 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
862 (aId == SketchPlugin_ConstraintLength::ID()) ||
863 (aId == SketchPlugin_ConstraintDistance::ID()) ||
864 (aId == SketchPlugin_ConstraintAngle::ID())) {
865 editFeature(aFeature);
872 //******************************************************
873 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
875 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
876 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
877 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
880 //******************************************************
881 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
883 Config_WidgetAPI* theWidgetApi)
885 ModuleBase_IWorkshop* aWorkshop = workshop();
886 XGUI_Workshop* aXUIWorkshop = getWorkshop();
887 ModuleBase_ModelWidget* aWgt = NULL;
888 if (theType == "sketch-start-label") {
889 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
890 theWidgetApi, myHasConstraintShown);
891 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
892 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
893 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
894 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
896 } else if (theType == "sketch-2dpoint_selector") {
897 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
899 aPointWgt->setSketch(mySketchMgr->activeSketch());
900 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
902 }else if (theType == "sketch-2dpoint_flyout_selector") {
903 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
905 aPointWgt->setSketch(mySketchMgr->activeSketch());
906 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
908 } else if (theType == "sketch_shape_selector") {
909 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
910 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
911 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
912 aWgt = aShapeSelectorWgt;
913 } else if (theType == "sketch_multi_selector") {
914 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
915 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
916 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
917 aWgt = aShapeSelectorWgt;
919 else if (theType == "sketch_feature_point_selector") {
920 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
921 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
922 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
923 aWgt = aPointSelectorWgt;
925 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
926 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
927 } else if (theType == "export_file_selector") {
928 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
929 } else if (theType == "sketch_launcher") {
930 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
931 } else if (theType == "module_choice") {
932 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
933 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
934 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
939 //******************************************************
940 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
942 ModuleBase_ModelWidget* anActiveWidget = 0;
944 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
946 return anActiveWidget;
948 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
950 return anActiveWidget;
952 return aPanel->activeWidget(true);
955 //******************************************************
956 bool PartSet_Module::deleteObjects()
958 bool isProcessed = false;
960 XGUI_Workshop* aWorkshop = getWorkshop();
961 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
963 //SessionPtr aMgr = ModelAPI_Session::get();
964 // 1. check whether the delete should be processed in the module
965 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
966 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
967 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
968 if (isSketchOp || isNestedOp) {
970 // 2. find selected presentations
971 // selected objects should be collected before the current operation abort because
972 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
973 ModuleBase_ISelection* aSel = workshop()->selection();
974 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
975 // if there are no selected objects in the viewer, that means that the selection in another
976 // place cased this method. It is necessary to return the false value to understande in above
977 // method that delete is not processed
978 if (aSelectedObj.count() == 0)
981 // avoid delete of the objects, which are not belong to the current sketch
982 // in order to do not delete results of other sketches
983 QObjectPtrList aSketchObjects;
984 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
985 for ( ; anIt != aLast; anIt++) {
986 ObjectPtr anObject = *anIt;
987 if (mySketchMgr->isObjectOfSketch(anObject)) {
988 // sketch feature should be used in this list because workshop deletes features only
989 // results are skipped
990 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
991 aSketchObjects.append(aSketchFeature);
994 // if the selection contains only local selected presentations from other sketches,
995 // the Delete operation should not be done at all
996 if (aSketchObjects.size() == 0)
999 // 3. start operation
1000 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1001 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
1003 // the active nested sketch operation should be aborted unconditionally
1004 // the Delete action should be additionally granted for the Sketch operation
1005 // in order to do not abort/commit it
1007 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1008 return true; // the objects are processed but can not be deleted
1010 anOpMgr->startOperation(anOpAction);
1012 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1013 // the problem is in AIS Dimensions recompute
1014 // if a line and the dim are removed, line is the first
1015 // it causes the AIS recompute, where the base line is null,
1016 // the result is empty AIS in the viewer
1017 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1019 // 4. delete features
1020 // sketch feature should be skipped, only sub-features can be removed
1021 // when sketch operation is active
1022 aWorkshop->deleteFeatures(aSketchObjects);
1023 // 5. stop operation
1024 anOpMgr->commitOperation();
1029 //******************************************************
1030 void PartSet_Module::editFeature(FeaturePtr theFeature)
1032 storeConstraintsState(theFeature->getKind());
1033 ModuleBase_IModule::editFeature(theFeature);
1036 //******************************************************
1037 bool PartSet_Module::canCommitOperation() const
1042 //******************************************************
1043 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1045 myIsOperationIsLaunched = true;
1046 storeConstraintsState(theCmdId.toStdString());
1047 updateConstraintsState(theCmdId.toStdString());
1049 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1051 myIsOperationIsLaunched = false;
1054 //******************************************************
1055 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1057 if (myWorkshop->currentOperation() &&
1058 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1059 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1060 mySketchMgr->showConstraintStates();
1061 myHasConstraintShown = aShownStates;
1065 //******************************************************
1066 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1068 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1069 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1070 // Show constraints if a constraint was anOperation
1071 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1072 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1073 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1074 myHasConstraintShown[PartSet_Tools::Expressions]);
1078 //******************************************************
1079 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1081 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1082 if (!anAIS.IsNull()) {
1083 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1084 if (aFeature.get()) {
1085 bool aToUseZLayer = false;
1086 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1087 aToUseZLayer = true;
1089 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1090 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1093 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1094 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1095 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1097 aCtx->SetZLayer(anAIS, myVisualLayerId);
1103 //******************************************************
1104 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1107 // it should be recomputed in order to disappear in the viewer if the corresponded object
1109 //if (myCustomPrs->isActive())
1110 // myCustomPrs->redisplay(theObject, false);
1113 //******************************************************
1114 void PartSet_Module::onViewTransformed(int theTrsfType)
1116 // Set length of arrows constant in pixel size
1117 // if the operation is panning or rotate or panglobal then do nothing
1118 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1120 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1121 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1122 if (aContext.IsNull())
1125 //Handle(V3d_View) aView = aViewer->activeView();
1127 XGUI_Workshop* aWorkshop = getWorkshop();
1128 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1129 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1130 Handle(V3d_View) aView;
1132 for (aV3dViewer->InitDefinedViews();
1133 aV3dViewer->MoreDefinedViews();
1134 aV3dViewer->NextDefinedViews()) {
1135 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1136 double aS = aV->Scale();
1145 bool isModified = false;
1146 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1147 if (aCurrentOperation &&
1148 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1149 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1150 (aCurrentOperation->id() == "Measurement")))
1152 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1154 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1155 SketcherPrs_Tools::setArrowSize(aLen);
1156 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1157 aViewer->SetScale(aViewer->activeView(), aCurScale);
1159 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1160 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1162 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1163 foreach(AISObjectPtr aAIS, aPrsList) {
1164 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1166 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1167 if (!aDim.IsNull()) {
1168 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1169 aContext->Redisplay(aDim, false);
1174 aDisplayer->updateViewer();
1179 //******************************************************
1180 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1182 return myCustomPrs->isActive(theFlag);
1185 //******************************************************
1186 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1187 const ModuleBase_CustomizeFlag& theFlag,
1188 const bool theUpdateViewer)
1190 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1193 //******************************************************
1194 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1195 const bool theUpdateViewer)
1197 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1200 //******************************************************
1201 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1202 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1204 bool aCustomized = false;
1206 XGUI_Workshop* aWorkshop = getWorkshop();
1207 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1208 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1212 if (!theResult.get()) {
1213 std::vector<int> aColor;
1214 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1215 if (!aColor.empty()) {
1216 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1219 // customize dimentional constrains
1220 sketchMgr()->customizePresentation(anObject);
1225 //******************************************************
1226 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1227 AISObjectPtr thePrs,
1228 GeomCustomPrsPtr theCustomPrs)
1230 bool aCustomized = false;
1232 XGUI_Workshop* aWorkshop = getWorkshop();
1233 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1234 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1238 std::vector<int> aColor;
1239 bool aUseCustomColor = true;
1240 if (aUseCustomColor)
1241 myOverconstraintListener->getCustomColor(anObject, aColor);
1242 // customize sketch symbol presentation
1243 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1244 if (!anAISIO.IsNull()) {
1245 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1246 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1247 if (!aPrs.IsNull()) {
1248 aPrs->SetCustomColor(aColor);
1251 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1252 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1253 if (!aPrs.IsNull()) {
1254 aPrs->SetCustomColor(aColor);
1259 // customize sketch dimension constraint presentation
1261 if (!aColor.empty()) { // otherwise presentation has the default color
1262 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1268 //******************************************************
1269 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1270 const bool theUpdateViewer)
1272 bool isRedisplayed = false;
1273 if (myCustomPrs->isActive(theFlag))
1274 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1276 return isRedisplayed;
1279 //******************************************************
1280 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1282 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1284 QLabel* aLabel = aOB->activeDocLabel();
1285 aLabel->installEventFilter(myMenuMgr);
1286 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1287 SLOT(onActiveDocPopup(const QPoint&)));
1288 aOB->treeView()->setExpandsOnDoubleClick(false);
1289 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1290 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1292 Events_Loop* aLoop = Events_Loop::loop();
1293 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1297 //******************************************************
1298 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1300 SessionPtr aMgr = ModelAPI_Session::get();
1301 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1303 XGUI_Workshop* aWorkshop = getWorkshop();
1304 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1306 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1309 aMenu.addAction(aActivatePartAction);
1310 aMenu.exec(aHeader->mapToGlobal(thePnt));
1313 //******************************************************
1314 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1316 return mySketchMgr->createPresentation(theResult);
1319 //******************************************************
1320 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1323 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1325 /// If last line finished on vertex the lines creation sequence has to be break
1326 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1328 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1329 // if there is an active widget, find the presented object in it
1330 if (!anActiveWidget)
1331 anActiveWidget = aPanel->preselectionWidget();
1333 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1335 if (aWidgetValidated)
1336 anObject = aWidgetValidated->findPresentedObject(theAIS);
1342 //******************************************************
1343 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1345 bool aCanBeShaged = true;
1347 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1349 aCanBeShaged = false;
1351 return aCanBeShaged;
1354 //******************************************************
1355 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1357 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1358 int aSelected = aObjects.size();
1359 SessionPtr aMgr = ModelAPI_Session::get();
1360 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1362 bool hasResult = false;
1363 bool hasFeature = false;
1364 bool hasParameter = false;
1365 bool hasCompositeOwner = false;
1366 bool hasResultInHistory = false;
1367 bool hasFolder = false;
1368 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1369 hasCompositeOwner, hasResultInHistory, hasFolder);
1371 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1372 if (aSelected == 1) {
1373 ObjectPtr aObject = aObjects.first();
1375 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1376 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1377 bool isPart = aPart.get() ||
1378 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1380 DocumentPtr aPartDoc;
1382 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1384 if (aPart.get()) // this may be null is Part feature is disabled
1385 aPartDoc = aPart->partDoc();
1387 theMenu->addAction(aActivatePartAction);
1388 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1390 } else if (aObject->document() == aMgr->activeDocument()) {
1391 if (hasParameter || hasFeature) {
1392 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1393 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1394 if (aCurrentOp && aFeature.get()) {
1395 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1396 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1403 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1404 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1405 theMenu->addSeparator();
1408 bool aNotDeactivate = (aCurrentOp == 0);
1409 if (!aNotDeactivate) {
1410 aActivatePartAction->setEnabled(false);
1414 //******************************************************
1415 #define EXPAND_PARENT(OBJ) \
1416 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1417 if (aObjIndex.isValid()) { \
1418 QModelIndex aParent = aObjIndex.parent(); \
1419 int aCount = aDataModel->rowCount(aParent); \
1421 aTreeView->setExpanded(aParent, true); \
1424 //******************************************************
1425 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1427 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1428 // Do not change activation of parts if an operation active
1429 static QStringList aAllowActivationList;
1430 if (aAllowActivationList.isEmpty())
1431 aAllowActivationList <<
1432 QString(PartSetPlugin_Part::ID().c_str()) <<
1433 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1434 QString(PartSetPlugin_Remove::ID().c_str());
1435 if (myWorkshop->currentOperation() &&
1436 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1438 XGUI_Workshop* aWorkshop = getWorkshop();
1439 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1440 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1441 QPalette aPalet = aLabel->palette();
1443 SessionPtr aMgr = ModelAPI_Session::get();
1444 DocumentPtr aActiveDoc = aMgr->activeDocument();
1446 // Clear active part index if there is no Part documents
1447 // It could be not null if document was closed and opened a new
1448 // without closeDocument call
1449 if (aMgr->allOpenedDocuments().size() <= 1)
1450 myActivePartIndex = QModelIndex();
1452 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1453 QModelIndex aOldActive = myActivePartIndex;
1454 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1455 bool needUpdate = false;
1456 if (myActivePartIndex.isValid()) {
1457 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1459 aTreeView->setExpanded(myActivePartIndex, true);
1461 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1462 aTreeView->setExpanded(aOldActive, false);
1464 aLabel->setPalette(aPalet);
1465 aWorkshop->updateCommandStatus();
1467 // Update displayed objects in order to update active color
1468 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1469 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1471 foreach(ObjectPtr aObj, aObjects) {
1472 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1473 aObj->isDisabled() || (!aObj->isDisplayed());
1475 aDisplayer->redisplay(aObj, false);
1477 aDisplayer->updateViewer();
1478 // Update tree items if they are expanded
1480 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1482 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1483 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1484 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1485 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1487 ObjectPtr aConstrObj;
1488 ObjectPtr aResultObj;
1489 std::set<ObjectPtr>::const_iterator aIt;
1490 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1491 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1492 ObjectPtr aObject = (*aIt);
1493 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1494 && (aObject->document() != aRootDoc))
1495 aResultObj = aObject;
1496 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1497 && (aObject->document() != aRootDoc))
1498 aConstrObj = aObject;
1499 if (aResultObj.get() && aConstrObj.get())
1503 if (aResultObj.get() || aConstrObj.get()) {
1504 XGUI_Workshop* aWorkshop = getWorkshop();
1505 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1506 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1508 if (aResultObj.get()) {
1509 EXPAND_PARENT(aResultObj)
1511 if (aConstrObj.get()) {
1512 EXPAND_PARENT(aConstrObj)
1518 //******************************************************
1519 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1521 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1523 SessionPtr aMgr = ModelAPI_Session::get();
1524 if (!theIndex.isValid()) {
1525 // It seems that this code is obsolete
1526 //aMgr->setActiveDocument(aMgr->moduleDocument());
1529 if (theIndex.column() != 1) // Use only first column
1532 XGUI_Workshop* aWorkshop = getWorkshop();
1533 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1534 // De not use non editable Indexes
1535 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1537 ObjectPtr aObj = aDataModel->object(theIndex);
1539 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1540 if (!aPart.get()) { // Probably this is Feature
1541 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1542 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1543 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1546 if (aPart.get()) { // if this is a part
1547 if (aPart->partDoc() == aMgr->activeDocument()) {
1548 myMenuMgr->activatePartSet();
1550 myMenuMgr->activatePart(aPart);
1555 //******************************************************
1556 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1558 // z layer is created for all started operations in order to visualize operation AIS presentation
1560 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1561 if (aContext.IsNull())
1564 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1565 if (myVisualLayerId == 0) {
1566 if (myVisualLayerId == 0)
1567 aViewer->AddZLayer(myVisualLayerId);
1569 TColStd_SequenceOfInteger aZList;
1570 aViewer->GetAllZLayers(aZList);
1571 bool aFound = false;
1572 for (int i = 1; i <= aZList.Length(); i++) {
1573 if (aZList(i) == myVisualLayerId) {
1579 aViewer->AddZLayer(myVisualLayerId);
1581 // if there is an active operation with validated widget,
1582 // the filters of this widget should be activated in the created view
1583 myWorkshop->selectionActivate()->updateSelectionFilters();
1584 myWorkshop->selectionActivate()->updateSelectionModes();
1587 //******************************************************
1588 void PartSet_Module::widgetStateChanged(int thePreviousState)
1590 mySketchMgr->widgetStateChanged(thePreviousState);
1593 //******************************************************
1594 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1596 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1599 //******************************************************
1600 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1602 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1603 mySketchMgr->stopSketch(theOperation);
1607 //******************************************************
1608 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1610 GeomShapePtr aGeomShape;
1612 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1613 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1614 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1619 //******************************************************
1620 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1621 const GeomShapePtr& theGeomShape)
1623 AttributePtr anAttribute;
1624 GeomShapePtr aGeomShape = theGeomShape;
1625 if (!aGeomShape.get()) {
1626 // processing shape of result, e.g. sketch circle center is selected, this is a result
1627 // the geom shape is empty, the shape of result should be used
1628 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1629 if (aResult.get()) {
1630 aGeomShape = aResult->shape();
1634 if (aGeomShape.get()) {
1635 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1636 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1637 mySketchMgr->activeSketch());
1642 //******************************************************
1643 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1645 return sketchReentranceMgr()->reentrantMessage();
1648 //******************************************************
1649 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1651 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1654 //******************************************************
1655 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1658 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1662 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1663 if (!aChoiceTitle.isEmpty()) {
1664 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1667 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1669 aPanel->setWindowTitle(aChoiceTitle);
1673 //******************************************************
1674 XGUI_Workshop* PartSet_Module::getWorkshop() const
1676 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1677 return aConnector->workshop();
1680 void PartSet_Module::setDefaultConstraintShown()
1682 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1683 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1684 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1687 //******************************************************
1688 ModuleBase_ITreeNode* PartSet_Module::rootNode() const