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 <ModuleBase_Operation.h>
51 #include <ModuleBase_OperationAction.h>
52 #include <ModuleBase_IViewer.h>
53 #include <ModuleBase_IViewWindow.h>
54 #include <ModuleBase_IPropertyPanel.h>
55 #include <ModuleBase_ISelectionActivate.h>
56 #include <ModuleBase_WidgetChoice.h>
57 #include <ModuleBase_WidgetEditor.h>
58 #include <ModuleBase_WidgetValidated.h>
59 #include <ModuleBase_Tools.h>
60 #include <ModuleBase_OperationFeature.h>
61 #include <ModuleBase_WidgetFactory.h>
62 #include <ModuleBase_OperationDescription.h>
63 #include <ModuleBase_ViewerPrs.h>
65 #include <ModelAPI_Object.h>
66 #include <ModelAPI_Events.h>
67 #include <ModelAPI_Validator.h>
68 #include <ModelAPI_Data.h>
69 #include <ModelAPI_Session.h>
70 #include <ModelAPI_ResultBody.h>
71 #include <ModelAPI_AttributeString.h>
72 #include <ModelAPI_AttributeSelectionList.h>
73 #include <ModelAPI_Tools.h>
74 #include <ModelAPI_ResultConstruction.h>
75 #include <ModelAPI_AttributeIntArray.h>
77 #include <GeomDataAPI_Point2D.h>
78 #include <GeomDataAPI_Point.h>
79 #include <GeomDataAPI_Dir.h>
81 #include <XGUI_ActiveControlMgr.h>
82 #include <XGUI_ActiveControlSelector.h>
83 #include <XGUI_ActionsMgr.h>
84 #include <XGUI_ContextMenuMgr.h>
85 #include <XGUI_CustomPrs.h>
86 #include <XGUI_DataModel.h>
87 #include <XGUI_Displayer.h>
88 #include <XGUI_ErrorMgr.h>
89 #include <XGUI_FacesPanelSelector.h>
90 #include <XGUI_ModuleConnector.h>
91 #include <XGUI_ObjectsBrowser.h>
92 #include <XGUI_OperationMgr.h>
93 #include <XGUI_PropertyPanel.h>
94 #include <XGUI_SelectionMgr.h>
95 #include <XGUI_Tools.h>
96 #include <XGUI_Workshop.h>
98 #include <SketchPlugin_ConstraintAngle.h>
99 #include <SketchPlugin_ConstraintLength.h>
100 #include <SketchPlugin_ConstraintDistance.h>
101 #include <SketchPlugin_ConstraintParallel.h>
102 #include <SketchPlugin_ConstraintPerpendicular.h>
103 #include <SketchPlugin_ConstraintRadius.h>
104 #include <SketchPlugin_Feature.h>
105 #include <SketchPlugin_Projection.h>
106 #include <SketchPlugin_Sketch.h>
108 #include <SketcherPrs_SymbolPrs.h>
109 #include <SketcherPrs_PositionMgr.h>
110 #include <SketcherPrs_Coincident.h>
111 #include <SketcherPrs_Tools.h>
113 #include <Events_Loop.h>
114 #include <Config_PropManager.h>
115 #include <Config_Keywords.h>
117 #include <AIS_Dimension.hxx>
118 #include <AIS_InteractiveObject.hxx>
119 #include <StdSelect_TypeOfFace.hxx>
120 #include <TopoDS_Vertex.hxx>
121 #include <TopoDS.hxx>
122 #include <TopoDS_Shape.hxx>
123 #include <BRep_Tool.hxx>
126 #include <QMouseEvent>
129 #include <QApplication>
130 #include <QMessageBox>
131 #include <QMainWindow>
135 #include <GeomAlgoAPI_FaceBuilder.h>
136 #include <GeomDataAPI_Dir.h>
138 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
144 /*!Create and return new instance of XGUI_Module*/
145 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
147 return new PartSet_Module(theWshop);
150 //******************************************************
151 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
152 : ModuleBase_IModule(theWshop),
155 myIsOperationIsLaunched(false)
157 new PartSet_IconFactory();
159 mySketchMgr = new PartSet_SketcherMgr(this);
160 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
162 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
163 XGUI_Workshop* aWorkshop = aConnector->workshop();
165 ModuleBase_IViewer* aViewer = theWshop->viewer();
166 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
167 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
168 connect(aViewer, SIGNAL(viewTransformed(int)),
169 SLOT(onViewTransformed(int)));
170 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
171 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
172 myMenuMgr = new PartSet_MenuMgr(this);
173 myCustomPrs = new PartSet_CustomPrs(theWshop);
175 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
177 Events_Loop* aLoop = Events_Loop::loop();
178 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
180 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
181 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
182 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
183 std::set<std::string> aCRGroupNames;
184 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
185 aCRFilter->setGroupNames(aCRGroupNames);
186 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
188 setDefaultConstraintShown();
190 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
191 "Reference shape wireframe color in operation", Config_Prop::Color,
192 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
193 Config_PropManager::registerProp("Visualization", "operation_result_color",
194 "Result shape wireframe color in operation", Config_Prop::Color,
195 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
196 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
197 "Multi selector item color in operation", Config_Prop::Color,
198 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
199 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
200 "Color of removed feature in operation", Config_Prop::Color,
201 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
202 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
203 "Color of sketch plane", Config_Prop::Color,
204 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
206 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
207 "Hidden faces transparency",
208 Config_Prop::DblSpin,
210 std::ostringstream aStream;
211 aStream << SketcherPrs_Tools::getDefaultArrowSize();
212 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
213 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
215 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
216 Config_Prop::String, "Times-bold");
220 aStream << SketcherPrs_Tools::getDefaultTextHeight();
221 Config_PropManager::registerProp("Visualization", "dimension_value_size",
222 "Dimension value size", Config_Prop::IntSpin, aStream.str());
224 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
225 "Sketch dimension color",
226 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
229 //******************************************************
230 PartSet_Module::~PartSet_Module()
232 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
233 mySelectionFilters.begin();
234 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
235 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
236 if (!aFilter.IsNull())
240 delete myOverconstraintListener;
244 //******************************************************
245 void PartSet_Module::createFeatures()
247 ModuleBase_IModule::createFeatures();
248 myRoot = new PartSet_RootNode();
249 myRoot->setWorkshop(workshop());
253 //******************************************************
254 void PartSet_Module::storeSelection()
256 // cash is used only to restore selection, so it should be filled in storeSelection and
257 // after applying immediatelly cleared in restoreSelection
258 myCurrentSelection.clear();
259 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
262 //******************************************************
263 void PartSet_Module::restoreSelection()
265 // cash is used only to restore selection, so it should be filled in storeSelection and
266 // after applying immediatelly cleared in restoreSelection
267 sketchMgr()->restoreSelection(myCurrentSelection);
268 myCurrentSelection.clear();
271 //******************************************************
272 void PartSet_Module::registerValidators()
274 //Registering of validators
275 SessionPtr aMgr = ModelAPI_Session::get();
276 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
277 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
278 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
279 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
280 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
281 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
282 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
283 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
284 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
285 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
286 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
287 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
288 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
289 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
290 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
291 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
292 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
293 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
294 aFactory->registerValidator("PartSet_MultyTranslationSelection",
295 new PartSet_MultyTranslationSelection);
296 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
297 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
298 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
301 //******************************************************
302 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
303 const bool isToConnect)
305 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
308 //******************************************************
309 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
311 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
312 mySketchMgr->commitNestedSketch(theOperation);
314 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
315 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
316 overconstraintListener()->setActive(false);
318 /// Restart sketcher operations automatically
319 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
321 ModuleBase_OperationFeature* aFOperation =
322 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
323 if (aFOperation && !aFOperation->isEditOperation()) {
324 // the selection is cleared after commit the create operation
325 // in order to do not use the same selected objects in the restarted operation
326 // for common behaviour, the selection is cleared even if the operation is not restarted
327 getWorkshop()->selector()->clearSelection();
332 //******************************************************
333 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
335 /// Restart sketcher operations automatically
336 mySketchReentrantMgr->operationAborted(theOperation);
337 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
338 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
339 overconstraintListener()->setActive(false);
342 //******************************************************
343 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
345 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
348 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
349 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
351 ModuleBase_ModelWidget* aFilledWidget = 0;
352 bool aPostonedWidgetActivation = false;
354 FeaturePtr aFeature = aFOperation->feature();
355 /// Restart sketcher operations automatically
356 /// it is important to call method of sketch reentrant manager before filling of PP
357 /// because it fills some created feature attributes, these new values should be used
358 /// to fill the property panel
359 mySketchReentrantMgr->operationStarted(theOperation);
361 aWorkshop->fillPropertyPanel(aFOperation);
362 // filling the operation values by the current selection
363 // if the operation can be committed after the controls filling, the method perform should
364 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
365 bool isOperationCommitted = false;
366 if (!aFOperation->isEditOperation()) {
367 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
368 // if there is a greed attribute, automatic commit by preselection
369 // for this feature is prohibited
370 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
371 if (currentOperation() != aFOperation)
372 isOperationCommitted = true;
374 if (aGreedAttributeId.empty()) {
375 // a signal should be emitted before the next widget activation
376 // because, the activation of the next widget will give a focus to the widget.
377 // As a result the value of the widget is initialized.
378 // And commit may happens until the value is entered.
380 if (mySketchReentrantMgr->canBeCommittedByPreselection())
381 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
382 // activate the next obligatory widget
383 if (!isOperationCommitted)
384 aPropertyPanel->activateNextWidget(aFilledWidget);
387 else { // there is a greed widget
388 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
389 std::string aFirstAttributeId = aWidgets.front()->attributeID();
390 // activate next widget after greeded if it is the first widget in the panel
391 // else the first panel widget is already activated by operation start
392 if (aFirstAttributeId == aGreedAttributeId)
393 aPostonedWidgetActivation = true;
396 } if (!isOperationCommitted) {
397 aWorkshop->connectToPropertyPanel(true);
398 updateSketcherOnStart(aFOperation);
399 updatePresentationsOnStart(aFOperation);
401 // the objects of the current operation should be deactivated
402 QObjectPtrList anObjects;
403 anObjects.append(aFeature);
404 std::list<ResultPtr> aResults;
405 ModelAPI_Tools::allResults(aFeature, aResults);
406 std::list<ResultPtr>::const_iterator aIt;
407 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
408 anObjects.append(*aIt);
410 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
411 for (; anIt != aLast; anIt++)
412 aWorkshop->deactivateActiveObject(*anIt, false);
413 if (anObjects.size() > 0) {
414 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
415 aDisplayer->updateViewer();
417 /// state of command actions should be updated after displayed objects modification because
418 /// deactivation(for example) of objects may influence on selection in the viewer
419 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
420 workshop()->updateCommandStatus();
422 if (aPostonedWidgetActivation) {
423 // if the widget is an empty in the chain of activated widgets, the current operation
424 // is restarted. It should be performed after functionality of the operation starting
425 aPropertyPanel->activateNextWidget(aFilledWidget);
430 //******************************************************
431 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
433 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
434 mySketchMgr->startSketch(theOperation);
436 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
437 mySketchMgr->startNestedSketch(theOperation);
441 //******************************************************
442 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
444 ModuleBase_OperationFeature* aFOperation =
445 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
447 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
448 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
452 //******************************************************
453 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
455 ModuleBase_IModule::operationResumed(theOperation);
457 ModuleBase_OperationFeature* aFOperation =
458 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
460 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
461 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
465 //******************************************************
466 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
468 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
469 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
470 bool isModified = isModifiedArgs || isModifiedResults;
472 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
473 mySketchMgr->stopNestedSketch(theOperation);
475 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
476 setDefaultConstraintShown();
478 //VSV: Viewer is updated on feature update and redisplay
480 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
481 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
482 aDisplayer->updateViewer();
485 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
486 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
487 for (; anIt != aLast; anIt++) {
488 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
492 //******************************************************
493 ModuleBase_Operation* PartSet_Module::currentOperation() const
495 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
496 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
497 return anOpMgr->currentOperation();
500 //******************************************************
501 bool PartSet_Module::canUndo() const
503 bool aCanUndo = false;
504 SessionPtr aMgr = ModelAPI_Session::get();
505 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
506 aCanUndo = !aMgr->isOperation();
507 if (!aCanUndo) // check the enable state additionally by sketch manager
508 aCanUndo = aMgr->canUndo();
513 //******************************************************
514 bool PartSet_Module::canRedo() const
516 bool aCanRedo = false;
517 SessionPtr aMgr = ModelAPI_Session::get();
518 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
519 aCanRedo = !aMgr->isOperation();
520 if (!aCanRedo) // check the enable state additionally by sketch manager
521 aCanRedo = aMgr->canRedo();
526 //******************************************************
527 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
530 if (theActionId == "MOVE_CMD") {
531 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
533 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
534 // part features can not be moved in the history.
535 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
542 //******************************************************
543 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
545 // the sketch manager put the restriction to the objects erase
546 return mySketchMgr->canEraseObject(theObject);
549 //******************************************************
550 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
552 // the sketch manager put the restriction to the objects display
553 return mySketchMgr->canDisplayObject(theObject);
556 //******************************************************
557 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
558 const QString& theStartedOperationKind)
560 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
563 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
566 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
568 mySketchMgr->processHiddenObject(theObjects);
571 //******************************************************
572 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
574 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
576 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
577 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
578 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
579 if (isSketchOp || isNestedOp) {
580 // in active sketch operation it is possible to activate operation object in selection
581 // in the edit operation, e.g. points of the line can be moved when the line is edited
582 ModuleBase_OperationFeature* aFOperation =
583 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
584 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
589 //******************************************************
590 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
592 QMap<int, QAction*>& theMenuActions) const
594 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
597 //******************************************************
598 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
600 myMenuMgr->updateViewerMenu(theStdActions);
603 //******************************************************
604 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
606 bool isEnabledFixed = false;
607 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
608 mySketchReentrantMgr->isInternalEditActive())
609 isEnabledFixed = true;
610 return isEnabledFixed;
613 //******************************************************
614 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
616 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
617 if (anError.isEmpty())
618 anError = sketchMgr()->getFeatureError(theFeature);
623 //******************************************************
624 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
625 QStringList& theIds) const
627 myMenuMgr->grantedOperationIds(theOperation, theIds);
629 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
630 XGUI_Workshop* aWorkshop = getWorkshop();
631 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
635 //******************************************************
636 void PartSet_Module::activeSelectionModes(QIntList& theModes)
638 if (mySketchMgr->activeSketch().get())
639 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
641 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
644 //******************************************************
645 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
647 customSubShapesSelectionModes(theModes);
648 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
649 //myWorkshop->module()->activeSelectionModes(theModes);
652 //******************************************************
653 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
654 SelectMgr_ListOfFilter& theSelectionFilters)
656 bool isSketchActive = mySketchMgr->activeSketch().get();
658 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
659 mySelectionFilters.begin();
660 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
661 int aFilterType = aFiltersIt->first;
662 // do not add not participating filters in given parameters
663 if (!theFilterTypes.contains(aFilterType))
666 // using sketch filters only if sketch operation is active
667 if (!isSketchActive &&
668 mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
671 // using filtering of construction results only from faces panel
672 if (aFilterType == SF_ResultGroupNameFilter)
675 theSelectionFilters.Append(aFiltersIt->second);
679 //******************************************************
680 QIntList PartSet_Module::selectionFilters()
684 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
685 mySelectionFilters.begin();
686 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
687 aTypes.append(aFiltersIt->first);
692 //******************************************************
693 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
694 const Handle(SelectMgr_Filter)& theFilter)
696 mySelectionFilters[theFilterType] = theFilter;
699 //******************************************************
700 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
702 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
704 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
705 return mySelectionFilters[aType];
707 return Handle(SelectMgr_Filter)();
710 //******************************************************
711 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
713 if (theModes.contains(TopAbs_FACE))
714 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
715 if (theModes.contains(TopAbs_WIRE))
716 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
718 if (mySketchMgr->activeSketch().get())
719 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
722 //******************************************************
723 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
724 ObjectPtr& theObject, AttributePtr& theAttribute)
726 ObjectPtr anObject = theSelected->object();
727 GeomShapePtr aShape = theSelected->shape();
729 theAttribute = findAttribute(anObject, aShape);
730 // TODO: try to create result if object is an external object
731 theObject = anObject;
734 //******************************************************
735 bool PartSet_Module::isMouseOverWindow()
737 return mySketchMgr->isMouseOverWindow();
740 //******************************************************
741 bool PartSet_Module::isSketchNeutralPointActivated() const
743 bool isNeutralPoint = true;
744 if (sketchReentranceMgr()->isInternalEditActive())
745 isNeutralPoint = false;
746 if (myIsOperationIsLaunched)
747 isNeutralPoint = false;
749 return isNeutralPoint;
752 //******************************************************
753 void PartSet_Module::closeDocument()
755 myActivePartIndex = QModelIndex();
756 SketcherPrs_PositionMgr::get()->clearAll();
759 //******************************************************
760 void PartSet_Module::clearViewer()
762 myCustomPrs->clearPrs();
764 XGUI_Workshop* aWorkshop = getWorkshop();
765 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
766 aDisplayer->deactivateSelectionFilters(false);
769 //******************************************************
770 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
772 ModuleBase_OperationFeature* aFOperation =
773 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
777 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
778 // we have to manually activate the sketch label in edit mode
779 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
780 aPanel->activateWidget(aPanel->modelWidgets().first());
783 //******************************************************
784 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
785 QList<ModuleBase_ModelWidget*>& theWidgets) const
787 bool aProcessed = false;
789 ModuleBase_OperationFeature* aFOperation =
790 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
791 XGUI_Workshop* aWorkshop = getWorkshop();
792 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
793 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
794 ModuleBase_ISelection* aSelection = workshop()->selection();
795 // click on a point in sketch leads here with the point is highlighted, not yet selected
796 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
797 if (aPreselection.size() == 1) {
798 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
799 ObjectPtr anObject = aSelectedPrs->object();
801 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
802 FeaturePtr anOpFeature = aFOperation->feature();
803 GeomShapePtr aShape = aSelectedPrs->shape();
804 // click on the digit of dimension constrain comes here
805 // with an empty shape, so we need the check
806 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
807 // if feature has only one result and shape of result is equal to selected shape
808 // this attribute is not processed. It is a case of Sketch Point.
809 if (aFeature->results().size() == 1) {
810 ResultPtr aResult = aFeature->results().front();
811 if (aResult.get() && aResult->shape()->isEqual(aShape))
814 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
815 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
816 mySketchMgr->activeSketch());
817 if (anAttribute.get()) {
818 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
819 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
821 const std::string anAttributeId = anAttribute->id();
822 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
824 theWidgets = aFactory.getModelWidgets();
825 // it is possible that the point does not present in XML definition,
826 // in this case, we assume that it is not processed by this module
827 // e.g. "Intersection point" feature
828 aProcessed = !theWidgets.isEmpty();
836 //******************************************************
837 void PartSet_Module::onSelectionChanged()
839 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
843 bool isSketcherOp = false;
844 // An edit operation is enable only if the current opeation is the sketch operation
845 if (mySketchMgr->activeSketch()) {
846 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
847 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
850 // Editing of constraints can be done on selection
851 ModuleBase_ISelection* aSelect = myWorkshop->selection();
852 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
853 if (aSelected.size() == 1) {
854 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
855 ObjectPtr aObject = aPrs->object();
856 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
858 std::string aId = aFeature->getKind();
859 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
860 (aId == SketchPlugin_ConstraintLength::ID()) ||
861 (aId == SketchPlugin_ConstraintDistance::ID()) ||
862 (aId == SketchPlugin_ConstraintAngle::ID())) {
863 editFeature(aFeature);
870 //******************************************************
871 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
873 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
874 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
875 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
878 //******************************************************
879 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
881 Config_WidgetAPI* theWidgetApi)
883 ModuleBase_IWorkshop* aWorkshop = workshop();
884 XGUI_Workshop* aXUIWorkshop = getWorkshop();
885 ModuleBase_ModelWidget* aWgt = NULL;
886 if (theType == "sketch-start-label") {
887 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
888 theWidgetApi, myHasConstraintShown);
889 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
890 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
891 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
892 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
894 } else if (theType == "sketch-2dpoint_selector") {
895 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
897 aPointWgt->setSketch(mySketchMgr->activeSketch());
898 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
900 }else if (theType == "sketch-2dpoint_flyout_selector") {
901 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
903 aPointWgt->setSketch(mySketchMgr->activeSketch());
904 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
906 } else if (theType == "sketch_shape_selector") {
907 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
908 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
909 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
910 aWgt = aShapeSelectorWgt;
911 } else if (theType == "sketch_multi_selector") {
912 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
913 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
914 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
915 aWgt = aShapeSelectorWgt;
917 else if (theType == "sketch_feature_point_selector") {
918 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
919 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
920 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
921 aWgt = aPointSelectorWgt;
923 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
924 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
925 } else if (theType == "export_file_selector") {
926 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
927 } else if (theType == "sketch_launcher") {
928 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
929 } else if (theType == "module_choice") {
930 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
931 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
932 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
937 //******************************************************
938 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
940 ModuleBase_ModelWidget* anActiveWidget = 0;
942 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
944 return anActiveWidget;
946 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
948 return anActiveWidget;
950 return aPanel->activeWidget(true);
953 //******************************************************
954 bool PartSet_Module::deleteObjects()
956 bool isProcessed = false;
958 XGUI_Workshop* aWorkshop = getWorkshop();
959 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
961 //SessionPtr aMgr = ModelAPI_Session::get();
962 // 1. check whether the delete should be processed in the module
963 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
964 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
965 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
966 if (isSketchOp || isNestedOp) {
968 // 2. find selected presentations
969 // selected objects should be collected before the current operation abort because
970 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
971 ModuleBase_ISelection* aSel = workshop()->selection();
972 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
973 // if there are no selected objects in the viewer, that means that the selection in another
974 // place cased this method. It is necessary to return the false value to understande in above
975 // method that delete is not processed
976 if (aSelectedObj.count() == 0)
979 // avoid delete of the objects, which are not belong to the current sketch
980 // in order to do not delete results of other sketches
981 QObjectPtrList aSketchObjects;
982 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
983 for ( ; anIt != aLast; anIt++) {
984 ObjectPtr anObject = *anIt;
985 if (mySketchMgr->isObjectOfSketch(anObject)) {
986 // sketch feature should be used in this list because workshop deletes features only
987 // results are skipped
988 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
989 aSketchObjects.append(aSketchFeature);
992 // if the selection contains only local selected presentations from other sketches,
993 // the Delete operation should not be done at all
994 if (aSketchObjects.size() == 0)
997 // 3. start operation
998 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
999 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
1001 // the active nested sketch operation should be aborted unconditionally
1002 // the Delete action should be additionally granted for the Sketch operation
1003 // in order to do not abort/commit it
1005 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1006 return true; // the objects are processed but can not be deleted
1008 anOpMgr->startOperation(anOpAction);
1010 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1011 // the problem is in AIS Dimensions recompute
1012 // if a line and the dim are removed, line is the first
1013 // it causes the AIS recompute, where the base line is null,
1014 // the result is empty AIS in the viewer
1015 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1017 // 4. delete features
1018 // sketch feature should be skipped, only sub-features can be removed
1019 // when sketch operation is active
1020 aWorkshop->deleteFeatures(aSketchObjects);
1021 // 5. stop operation
1022 anOpMgr->commitOperation();
1027 //******************************************************
1028 void PartSet_Module::editFeature(FeaturePtr theFeature)
1030 storeConstraintsState(theFeature->getKind());
1031 ModuleBase_IModule::editFeature(theFeature);
1034 //******************************************************
1035 bool PartSet_Module::canCommitOperation() const
1040 //******************************************************
1041 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1043 myIsOperationIsLaunched = true;
1044 storeConstraintsState(theCmdId.toStdString());
1045 updateConstraintsState(theCmdId.toStdString());
1047 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1049 myIsOperationIsLaunched = false;
1052 //******************************************************
1053 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1055 if (myWorkshop->currentOperation() &&
1056 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1057 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1058 mySketchMgr->showConstraintStates();
1059 myHasConstraintShown = aShownStates;
1063 //******************************************************
1064 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1066 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1067 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1068 // Show constraints if a constraint was anOperation
1069 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1070 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1071 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1072 myHasConstraintShown[PartSet_Tools::Expressions]);
1076 //******************************************************
1077 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1079 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1080 if (!anAIS.IsNull()) {
1081 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1082 if (aFeature.get()) {
1083 bool aToUseZLayer = false;
1084 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1085 aToUseZLayer = true;
1087 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1088 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1091 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1092 aCtx->SetZLayer(anAIS, myVisualLayerId);
1098 //******************************************************
1099 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1102 // it should be recomputed in order to disappear in the viewer if the corresponded object
1104 //if (myCustomPrs->isActive())
1105 // myCustomPrs->redisplay(theObject, false);
1108 //******************************************************
1109 void PartSet_Module::onViewTransformed(int theTrsfType)
1111 // Set length of arrows constant in pixel size
1112 // if the operation is panning or rotate or panglobal then do nothing
1113 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1115 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1116 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1117 if (aContext.IsNull())
1120 //Handle(V3d_View) aView = aViewer->activeView();
1122 XGUI_Workshop* aWorkshop = getWorkshop();
1123 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1124 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1125 Handle(V3d_View) aView;
1127 for (aV3dViewer->InitDefinedViews();
1128 aV3dViewer->MoreDefinedViews();
1129 aV3dViewer->NextDefinedViews()) {
1130 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1131 double aS = aV->Scale();
1140 bool isModified = false;
1141 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1142 if (aCurrentOperation &&
1143 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1144 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1145 (aCurrentOperation->id() == "Measurement")))
1147 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1149 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1150 SketcherPrs_Tools::setArrowSize(aLen);
1151 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1152 aViewer->SetScale(aViewer->activeView(), aCurScale);
1153 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1154 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1155 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1156 if (!aDim.IsNull()) {
1157 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1158 aContext->Redisplay(aDim, false);
1163 aDisplayer->updateViewer();
1168 //******************************************************
1169 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1171 return myCustomPrs->isActive(theFlag);
1174 //******************************************************
1175 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1176 const ModuleBase_CustomizeFlag& theFlag,
1177 const bool theUpdateViewer)
1179 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1182 //******************************************************
1183 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1184 const bool theUpdateViewer)
1186 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1189 //******************************************************
1190 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1191 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1193 bool aCustomized = false;
1195 XGUI_Workshop* aWorkshop = getWorkshop();
1196 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1197 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1201 if (!theResult.get()) {
1202 std::vector<int> aColor;
1203 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1204 if (!aColor.empty()) {
1205 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1208 // customize dimentional constrains
1209 sketchMgr()->customizePresentation(anObject);
1214 //******************************************************
1215 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1216 AISObjectPtr thePrs,
1217 GeomCustomPrsPtr theCustomPrs)
1219 bool aCustomized = false;
1221 XGUI_Workshop* aWorkshop = getWorkshop();
1222 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1223 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1227 std::vector<int> aColor;
1228 bool aUseCustomColor = true;
1229 if (aUseCustomColor)
1230 myOverconstraintListener->getCustomColor(anObject, aColor);
1231 // customize sketch symbol presentation
1232 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1233 if (!anAISIO.IsNull()) {
1234 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1235 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1236 if (!aPrs.IsNull()) {
1237 aPrs->SetCustomColor(aColor);
1240 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1241 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1242 if (!aPrs.IsNull()) {
1243 aPrs->SetCustomColor(aColor);
1248 // customize sketch dimension constraint presentation
1250 if (!aColor.empty()) { // otherwise presentation has the default color
1251 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1257 //******************************************************
1258 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1259 const bool theUpdateViewer)
1261 bool isRedisplayed = false;
1262 if (myCustomPrs->isActive(theFlag))
1263 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1265 return isRedisplayed;
1268 //******************************************************
1269 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1271 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1273 QLabel* aLabel = aOB->activeDocLabel();
1274 aLabel->installEventFilter(myMenuMgr);
1275 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1276 SLOT(onActiveDocPopup(const QPoint&)));
1277 aOB->treeView()->setExpandsOnDoubleClick(false);
1278 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1279 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1281 Events_Loop* aLoop = Events_Loop::loop();
1282 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1286 //******************************************************
1287 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1289 SessionPtr aMgr = ModelAPI_Session::get();
1290 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1292 XGUI_Workshop* aWorkshop = getWorkshop();
1293 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1295 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1298 aMenu.addAction(aActivatePartAction);
1299 aMenu.exec(aHeader->mapToGlobal(thePnt));
1302 //******************************************************
1303 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1305 return mySketchMgr->createPresentation(theResult);
1308 //******************************************************
1309 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1312 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1314 /// If last line finished on vertex the lines creation sequence has to be break
1315 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1317 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1318 // if there is an active widget, find the presented object in it
1319 if (!anActiveWidget)
1320 anActiveWidget = aPanel->preselectionWidget();
1322 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1324 if (aWidgetValidated)
1325 anObject = aWidgetValidated->findPresentedObject(theAIS);
1331 //******************************************************
1332 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1334 bool aCanBeShaged = true;
1336 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1338 aCanBeShaged = false;
1340 return aCanBeShaged;
1343 //******************************************************
1344 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1346 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1347 int aSelected = aObjects.size();
1348 SessionPtr aMgr = ModelAPI_Session::get();
1349 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1351 bool hasResult = false;
1352 bool hasFeature = false;
1353 bool hasParameter = false;
1354 bool hasCompositeOwner = false;
1355 bool hasResultInHistory = false;
1356 bool hasFolder = false;
1357 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1358 hasCompositeOwner, hasResultInHistory, hasFolder);
1360 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1361 if (aSelected == 1) {
1362 ObjectPtr aObject = aObjects.first();
1364 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1365 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1366 bool isPart = aPart.get() ||
1367 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1369 DocumentPtr aPartDoc;
1371 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1373 if (aPart.get()) // this may be null is Part feature is disabled
1374 aPartDoc = aPart->partDoc();
1376 theMenu->addAction(aActivatePartAction);
1377 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1379 } else if (aObject->document() == aMgr->activeDocument()) {
1380 if (hasParameter || hasFeature) {
1381 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1382 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1383 if (aCurrentOp && aFeature.get()) {
1384 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1385 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1392 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1393 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1394 theMenu->addSeparator();
1397 bool aNotDeactivate = (aCurrentOp == 0);
1398 if (!aNotDeactivate) {
1399 aActivatePartAction->setEnabled(false);
1403 //******************************************************
1404 #define EXPAND_PARENT(OBJ) \
1405 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1406 if (aObjIndex.isValid()) { \
1407 QModelIndex aParent = aObjIndex.parent(); \
1408 int aCount = aDataModel->rowCount(aParent); \
1410 aTreeView->setExpanded(aParent, true); \
1413 //******************************************************
1414 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1416 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1417 // Do not change activation of parts if an operation active
1418 static QStringList aAllowActivationList;
1419 if (aAllowActivationList.isEmpty())
1420 aAllowActivationList <<
1421 QString(PartSetPlugin_Part::ID().c_str()) <<
1422 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1423 QString(PartSetPlugin_Remove::ID().c_str());
1424 if (myWorkshop->currentOperation() &&
1425 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1427 XGUI_Workshop* aWorkshop = getWorkshop();
1428 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1429 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1430 QPalette aPalet = aLabel->palette();
1432 SessionPtr aMgr = ModelAPI_Session::get();
1433 DocumentPtr aActiveDoc = aMgr->activeDocument();
1434 // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
1435 //if (myActivePartIndex.isValid())
1436 // aTreeView->setExpanded(myActivePartIndex, false);
1438 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1439 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1440 bool needUpdate = false;
1441 if (myActivePartIndex.isValid()) {
1442 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1444 aTreeView->setExpanded(myActivePartIndex, true);
1447 aLabel->setPalette(aPalet);
1448 aWorkshop->updateCommandStatus();
1450 // Update displayed objects in order to update active color
1451 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1452 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1454 foreach(ObjectPtr aObj, aObjects) {
1455 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1456 aObj->isDisabled() || (!aObj->isDisplayed());
1458 aDisplayer->redisplay(aObj, false);
1460 aDisplayer->updateViewer();
1461 // Update tree items if they are expanded
1463 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1465 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1466 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1467 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1468 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1470 ObjectPtr aConstrObj;
1471 ObjectPtr aResultObj;
1472 std::set<ObjectPtr>::const_iterator aIt;
1473 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1474 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1475 ObjectPtr aObject = (*aIt);
1476 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1477 && (aObject->document() != aRootDoc))
1478 aResultObj = aObject;
1479 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1480 && (aObject->document() != aRootDoc))
1481 aConstrObj = aObject;
1482 if (aResultObj.get() && aConstrObj.get())
1486 if (aResultObj.get() || aConstrObj.get()) {
1487 XGUI_Workshop* aWorkshop = getWorkshop();
1488 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1489 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1491 if (aResultObj.get()) {
1492 EXPAND_PARENT(aResultObj)
1494 if (aConstrObj.get()) {
1495 EXPAND_PARENT(aConstrObj)
1501 //******************************************************
1502 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1504 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1506 SessionPtr aMgr = ModelAPI_Session::get();
1507 if (!theIndex.isValid()) {
1508 // It seems that this code is obsolete
1509 //aMgr->setActiveDocument(aMgr->moduleDocument());
1512 if (theIndex.column() != 1) // Use only first column
1515 XGUI_Workshop* aWorkshop = getWorkshop();
1516 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1517 // De not use non editable Indexes
1518 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1520 ObjectPtr aObj = aDataModel->object(theIndex);
1522 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1523 if (!aPart.get()) { // Probably this is Feature
1524 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1525 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1526 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1529 if (aPart.get()) { // if this is a part
1530 if (aPart->partDoc() == aMgr->activeDocument()) {
1531 myMenuMgr->activatePartSet();
1533 myMenuMgr->activatePart(aPart);
1538 //******************************************************
1539 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1541 // z layer is created for all started operations in order to visualize operation AIS presentation
1543 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1544 if (aContext.IsNull())
1547 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1548 if (myVisualLayerId == 0) {
1549 if (myVisualLayerId == 0)
1550 aViewer->AddZLayer(myVisualLayerId);
1552 TColStd_SequenceOfInteger aZList;
1553 aViewer->GetAllZLayers(aZList);
1554 bool aFound = false;
1555 for (int i = 1; i <= aZList.Length(); i++) {
1556 if (aZList(i) == myVisualLayerId) {
1562 aViewer->AddZLayer(myVisualLayerId);
1564 // if there is an active operation with validated widget,
1565 // the filters of this widget should be activated in the created view
1566 myWorkshop->selectionActivate()->updateSelectionFilters();
1567 myWorkshop->selectionActivate()->updateSelectionModes();
1570 //******************************************************
1571 void PartSet_Module::widgetStateChanged(int thePreviousState)
1573 mySketchMgr->widgetStateChanged(thePreviousState);
1576 //******************************************************
1577 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1579 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1582 //******************************************************
1583 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1585 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1586 mySketchMgr->stopSketch(theOperation);
1590 //******************************************************
1591 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1593 GeomShapePtr aGeomShape;
1595 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1596 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1597 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1602 //******************************************************
1603 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1604 const GeomShapePtr& theGeomShape)
1606 AttributePtr anAttribute;
1607 GeomShapePtr aGeomShape = theGeomShape;
1608 if (!aGeomShape.get()) {
1609 // processing shape of result, e.g. sketch circle center is selected, this is a result
1610 // the geom shape is empty, the shape of result should be used
1611 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1612 if (aResult.get()) {
1613 aGeomShape = aResult->shape();
1617 if (aGeomShape.get()) {
1618 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1619 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1620 mySketchMgr->activeSketch());
1625 //******************************************************
1626 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1628 return sketchReentranceMgr()->reentrantMessage();
1631 //******************************************************
1632 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1634 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1637 //******************************************************
1638 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1641 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1645 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1646 if (!aChoiceTitle.isEmpty()) {
1647 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1650 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1652 aPanel->setWindowTitle(aChoiceTitle);
1656 //******************************************************
1657 XGUI_Workshop* PartSet_Module::getWorkshop() const
1659 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1660 return aConnector->workshop();
1663 void PartSet_Module::setDefaultConstraintShown()
1665 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1666 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1667 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1670 //******************************************************
1671 ModuleBase_ITreeNode* PartSet_Module::rootNode() const