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_DataModel.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),
154 myIsOperationIsLaunched(false)
156 new PartSet_IconFactory();
158 mySketchMgr = new PartSet_SketcherMgr(this);
159 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
161 myDataModel = new PartSet_DataModel();
163 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
164 XGUI_Workshop* aWorkshop = aConnector->workshop();
166 ModuleBase_IViewer* aViewer = theWshop->viewer();
167 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
168 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
169 connect(aViewer, SIGNAL(viewTransformed(int)),
170 SLOT(onViewTransformed(int)));
171 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
172 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
173 myMenuMgr = new PartSet_MenuMgr(this);
174 myCustomPrs = new PartSet_CustomPrs(theWshop);
176 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
178 Events_Loop* aLoop = Events_Loop::loop();
179 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
181 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
182 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
183 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
184 std::set<std::string> aCRGroupNames;
185 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
186 aCRFilter->setGroupNames(aCRGroupNames);
187 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
189 setDefaultConstraintShown();
191 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
192 "Reference shape wireframe color in operation", Config_Prop::Color,
193 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
194 Config_PropManager::registerProp("Visualization", "operation_result_color",
195 "Result shape wireframe color in operation", Config_Prop::Color,
196 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
197 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
198 "Multi selector item color in operation", Config_Prop::Color,
199 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
200 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
201 "Color of removed feature in operation", Config_Prop::Color,
202 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
203 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
204 "Color of sketch plane", Config_Prop::Color,
205 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
207 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
208 "Hidden faces transparency",
209 Config_Prop::DblSpin,
211 std::ostringstream aStream;
212 aStream << SketcherPrs_Tools::getDefaultArrowSize();
213 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
214 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
216 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
217 Config_Prop::String, "Times-bold");
221 aStream << SketcherPrs_Tools::getDefaultTextHeight();
222 Config_PropManager::registerProp("Visualization", "dimension_value_size",
223 "Dimension value size", Config_Prop::IntSpin, aStream.str());
225 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
226 "Sketch dimension color",
227 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
230 //******************************************************
231 PartSet_Module::~PartSet_Module()
233 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
234 mySelectionFilters.begin();
235 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
236 Handle(SelectMgr_Filter) aFilter = aFiltersIt->second;
237 if (!aFilter.IsNull())
241 delete myOverconstraintListener;
244 //******************************************************
245 void PartSet_Module::storeSelection()
247 // cash is used only to restore selection, so it should be filled in storeSelection and
248 // after applying immediatelly cleared in restoreSelection
249 myCurrentSelection.clear();
250 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
253 //******************************************************
254 void PartSet_Module::restoreSelection()
256 // cash is used only to restore selection, so it should be filled in storeSelection and
257 // after applying immediatelly cleared in restoreSelection
258 sketchMgr()->restoreSelection(myCurrentSelection);
259 myCurrentSelection.clear();
262 //******************************************************
263 void PartSet_Module::registerValidators()
265 //Registering of validators
266 SessionPtr aMgr = ModelAPI_Session::get();
267 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
268 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
269 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
270 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
271 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
272 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
273 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
274 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
275 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
276 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
277 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
278 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
279 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
280 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
281 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
282 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
283 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
284 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
285 aFactory->registerValidator("PartSet_MultyTranslationSelection",
286 new PartSet_MultyTranslationSelection);
287 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
288 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
289 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
292 //******************************************************
293 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
294 const bool isToConnect)
296 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
299 //******************************************************
300 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
302 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
303 mySketchMgr->commitNestedSketch(theOperation);
305 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
306 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
307 overconstraintListener()->setActive(false);
309 /// Restart sketcher operations automatically
310 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
312 ModuleBase_OperationFeature* aFOperation =
313 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
314 if (aFOperation && !aFOperation->isEditOperation()) {
315 // the selection is cleared after commit the create operation
316 // in order to do not use the same selected objects in the restarted operation
317 // for common behaviour, the selection is cleared even if the operation is not restarted
318 getWorkshop()->selector()->clearSelection();
323 //******************************************************
324 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
326 /// Restart sketcher operations automatically
327 mySketchReentrantMgr->operationAborted(theOperation);
328 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
329 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
330 overconstraintListener()->setActive(false);
333 //******************************************************
334 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
336 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
339 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
340 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
342 ModuleBase_ModelWidget* aFilledWidget = 0;
343 bool aPostonedWidgetActivation = false;
345 FeaturePtr aFeature = aFOperation->feature();
346 /// Restart sketcher operations automatically
347 /// it is important to call method of sketch reentrant manager before filling of PP
348 /// because it fills some created feature attributes, these new values should be used
349 /// to fill the property panel
350 mySketchReentrantMgr->operationStarted(theOperation);
352 aWorkshop->fillPropertyPanel(aFOperation);
353 // filling the operation values by the current selection
354 // if the operation can be committed after the controls filling, the method perform should
355 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
356 bool isOperationCommitted = false;
357 if (!aFOperation->isEditOperation()) {
358 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
359 // if there is a greed attribute, automatic commit by preselection
360 // for this feature is prohibited
361 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
362 if (currentOperation() != aFOperation)
363 isOperationCommitted = true;
365 if (aGreedAttributeId.empty()) {
366 // a signal should be emitted before the next widget activation
367 // because, the activation of the next widget will give a focus to the widget.
368 // As a result the value of the widget is initialized.
369 // And commit may happens until the value is entered.
371 if (mySketchReentrantMgr->canBeCommittedByPreselection())
372 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
373 // activate the next obligatory widget
374 if (!isOperationCommitted)
375 aPropertyPanel->activateNextWidget(aFilledWidget);
378 else { // there is a greed widget
379 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
380 std::string aFirstAttributeId = aWidgets.front()->attributeID();
381 // activate next widget after greeded if it is the first widget in the panel
382 // else the first panel widget is already activated by operation start
383 if (aFirstAttributeId == aGreedAttributeId)
384 aPostonedWidgetActivation = true;
387 } if (!isOperationCommitted) {
388 aWorkshop->connectToPropertyPanel(true);
389 updateSketcherOnStart(aFOperation);
390 updatePresentationsOnStart(aFOperation);
392 // the objects of the current operation should be deactivated
393 QObjectPtrList anObjects;
394 anObjects.append(aFeature);
395 std::list<ResultPtr> aResults;
396 ModelAPI_Tools::allResults(aFeature, aResults);
397 std::list<ResultPtr>::const_iterator aIt;
398 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
399 anObjects.append(*aIt);
401 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
402 for (; anIt != aLast; anIt++)
403 aWorkshop->deactivateActiveObject(*anIt, false);
404 if (anObjects.size() > 0) {
405 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
406 aDisplayer->updateViewer();
408 /// state of command actions should be updated after displayed objects modification because
409 /// deactivation(for example) of objects may influence on selection in the viewer
410 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
411 workshop()->updateCommandStatus();
413 if (aPostonedWidgetActivation) {
414 // if the widget is an empty in the chain of activated widgets, the current operation
415 // is restarted. It should be performed after functionality of the operation starting
416 aPropertyPanel->activateNextWidget(aFilledWidget);
421 //******************************************************
422 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
424 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
425 mySketchMgr->startSketch(theOperation);
427 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
428 mySketchMgr->startNestedSketch(theOperation);
432 //******************************************************
433 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
435 ModuleBase_OperationFeature* aFOperation =
436 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
438 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
439 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
443 //******************************************************
444 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
446 ModuleBase_IModule::operationResumed(theOperation);
448 ModuleBase_OperationFeature* aFOperation =
449 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
451 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
452 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
456 //******************************************************
457 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
459 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
460 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
461 bool isModified = isModifiedArgs || isModifiedResults;
463 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
464 mySketchMgr->stopNestedSketch(theOperation);
466 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
467 setDefaultConstraintShown();
469 //VSV: Viewer is updated on feature update and redisplay
471 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
472 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
473 aDisplayer->updateViewer();
476 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
477 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
478 for (; anIt != aLast; anIt++) {
479 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
483 //******************************************************
484 ModuleBase_Operation* PartSet_Module::currentOperation() const
486 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
487 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
488 return anOpMgr->currentOperation();
491 //******************************************************
492 bool PartSet_Module::canUndo() const
494 bool aCanUndo = false;
495 SessionPtr aMgr = ModelAPI_Session::get();
496 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
497 aCanUndo = !aMgr->isOperation();
498 if (!aCanUndo) // check the enable state additionally by sketch manager
499 aCanUndo = aMgr->canUndo();
504 //******************************************************
505 bool PartSet_Module::canRedo() const
507 bool aCanRedo = false;
508 SessionPtr aMgr = ModelAPI_Session::get();
509 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
510 aCanRedo = !aMgr->isOperation();
511 if (!aCanRedo) // check the enable state additionally by sketch manager
512 aCanRedo = aMgr->canRedo();
517 //******************************************************
518 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
521 if (theActionId == "MOVE_CMD") {
522 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
524 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
525 // part features can not be moved in the history.
526 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
533 //******************************************************
534 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
536 // the sketch manager put the restriction to the objects erase
537 return mySketchMgr->canEraseObject(theObject);
540 //******************************************************
541 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
543 // the sketch manager put the restriction to the objects display
544 return mySketchMgr->canDisplayObject(theObject);
547 //******************************************************
548 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
549 const QString& theStartedOperationKind)
551 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
554 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
557 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
559 mySketchMgr->processHiddenObject(theObjects);
562 //******************************************************
563 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
565 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
567 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
568 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
569 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
570 if (isSketchOp || isNestedOp) {
571 // in active sketch operation it is possible to activate operation object in selection
572 // in the edit operation, e.g. points of the line can be moved when the line is edited
573 ModuleBase_OperationFeature* aFOperation =
574 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
575 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
580 //******************************************************
581 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
583 QMap<int, QAction*>& theMenuActions) const
585 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
588 //******************************************************
589 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
591 myMenuMgr->updateViewerMenu(theStdActions);
594 //******************************************************
595 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
597 bool isEnabledFixed = false;
598 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
599 mySketchReentrantMgr->isInternalEditActive())
600 isEnabledFixed = true;
601 return isEnabledFixed;
604 //******************************************************
605 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
607 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
608 if (anError.isEmpty())
609 anError = sketchMgr()->getFeatureError(theFeature);
614 //******************************************************
615 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
616 QStringList& theIds) const
618 myMenuMgr->grantedOperationIds(theOperation, theIds);
620 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
621 XGUI_Workshop* aWorkshop = getWorkshop();
622 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
626 //******************************************************
627 void PartSet_Module::activeSelectionModes(QIntList& theModes)
629 if (mySketchMgr->activeSketch().get())
630 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
632 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
635 //******************************************************
636 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
638 customSubShapesSelectionModes(theModes);
639 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
640 //myWorkshop->module()->activeSelectionModes(theModes);
643 //******************************************************
644 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
645 SelectMgr_ListOfFilter& theSelectionFilters)
647 bool isSketchActive = mySketchMgr->activeSketch().get();
649 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
650 mySelectionFilters.begin();
651 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
652 int aFilterType = aFiltersIt->first;
653 // do not add not participating filters in given parameters
654 if (!theFilterTypes.contains(aFilterType))
657 // using sketch filters only if sketch operation is active
658 if (!isSketchActive &&
659 mySketchMgr->sketchSelectionFilter((XGUI_SelectionFilterType)aFilterType))
662 // using filtering of construction results only from faces panel
663 if (aFilterType == SF_ResultGroupNameFilter)
666 theSelectionFilters.Append(aFiltersIt->second);
670 //******************************************************
671 QIntList PartSet_Module::selectionFilters()
675 std::map<XGUI_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
676 mySelectionFilters.begin();
677 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++)
678 aTypes.append(aFiltersIt->first);
683 //******************************************************
684 void PartSet_Module::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
685 const Handle(SelectMgr_Filter)& theFilter)
687 mySelectionFilters[theFilterType] = theFilter;
690 //******************************************************
691 Handle(SelectMgr_Filter) PartSet_Module::selectionFilter(const int theType)
693 XGUI_SelectionFilterType aType = (XGUI_SelectionFilterType)theType;
695 if (mySelectionFilters.find(aType) != mySelectionFilters.end())
696 return mySelectionFilters[aType];
698 return Handle(SelectMgr_Filter)();
701 //******************************************************
702 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
704 if (theModes.contains(TopAbs_FACE))
705 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
706 if (theModes.contains(TopAbs_WIRE))
707 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
709 if (mySketchMgr->activeSketch().get())
710 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
713 //******************************************************
714 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
715 ObjectPtr& theObject, AttributePtr& theAttribute)
717 ObjectPtr anObject = theSelected->object();
718 GeomShapePtr aShape = theSelected->shape();
720 theAttribute = findAttribute(anObject, aShape);
721 // TODO: try to create result if object is an external object
722 theObject = anObject;
725 //******************************************************
726 bool PartSet_Module::isMouseOverWindow()
728 return mySketchMgr->isMouseOverWindow();
731 //******************************************************
732 bool PartSet_Module::isSketchNeutralPointActivated() const
734 bool isNeutralPoint = true;
735 if (sketchReentranceMgr()->isInternalEditActive())
736 isNeutralPoint = false;
737 if (myIsOperationIsLaunched)
738 isNeutralPoint = false;
740 return isNeutralPoint;
743 //******************************************************
744 void PartSet_Module::closeDocument()
746 myActivePartIndex = QModelIndex();
747 SketcherPrs_PositionMgr::get()->clearAll();
750 //******************************************************
751 void PartSet_Module::clearViewer()
753 myCustomPrs->clearPrs();
755 XGUI_Workshop* aWorkshop = getWorkshop();
756 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
757 aDisplayer->deactivateSelectionFilters(false);
760 //******************************************************
761 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
763 ModuleBase_OperationFeature* aFOperation =
764 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
768 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
769 // we have to manually activate the sketch label in edit mode
770 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
771 aPanel->activateWidget(aPanel->modelWidgets().first());
774 //******************************************************
775 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
776 QList<ModuleBase_ModelWidget*>& theWidgets) const
778 bool aProcessed = false;
780 ModuleBase_OperationFeature* aFOperation =
781 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
782 XGUI_Workshop* aWorkshop = getWorkshop();
783 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
784 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
785 ModuleBase_ISelection* aSelection = workshop()->selection();
786 // click on a point in sketch leads here with the point is highlighted, not yet selected
787 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
788 if (aPreselection.size() == 1) {
789 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
790 ObjectPtr anObject = aSelectedPrs->object();
792 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
793 FeaturePtr anOpFeature = aFOperation->feature();
794 GeomShapePtr aShape = aSelectedPrs->shape();
795 // click on the digit of dimension constrain comes here
796 // with an empty shape, so we need the check
797 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
798 // if feature has only one result and shape of result is equal to selected shape
799 // this attribute is not processed. It is a case of Sketch Point.
800 if (aFeature->results().size() == 1) {
801 ResultPtr aResult = aFeature->results().front();
802 if (aResult.get() && aResult->shape()->isEqual(aShape))
805 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
806 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
807 mySketchMgr->activeSketch());
808 if (anAttribute.get()) {
809 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
810 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
812 const std::string anAttributeId = anAttribute->id();
813 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
815 theWidgets = aFactory.getModelWidgets();
816 // it is possible that the point does not present in XML definition,
817 // in this case, we assume that it is not processed by this module
818 // e.g. "Intersection point" feature
819 aProcessed = !theWidgets.isEmpty();
827 //******************************************************
828 void PartSet_Module::onSelectionChanged()
830 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
834 bool isSketcherOp = false;
835 // An edit operation is enable only if the current opeation is the sketch operation
836 if (mySketchMgr->activeSketch()) {
837 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
838 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
841 // Editing of constraints can be done on selection
842 ModuleBase_ISelection* aSelect = myWorkshop->selection();
843 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
844 if (aSelected.size() == 1) {
845 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
846 ObjectPtr aObject = aPrs->object();
847 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
849 std::string aId = aFeature->getKind();
850 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
851 (aId == SketchPlugin_ConstraintLength::ID()) ||
852 (aId == SketchPlugin_ConstraintDistance::ID()) ||
853 (aId == SketchPlugin_ConstraintAngle::ID())) {
854 editFeature(aFeature);
861 //******************************************************
862 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
864 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
865 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
866 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
869 //******************************************************
870 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
872 Config_WidgetAPI* theWidgetApi)
874 ModuleBase_IWorkshop* aWorkshop = workshop();
875 XGUI_Workshop* aXUIWorkshop = getWorkshop();
876 ModuleBase_ModelWidget* aWgt = NULL;
877 if (theType == "sketch-start-label") {
878 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
879 theWidgetApi, myHasConstraintShown);
880 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
881 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
882 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
883 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
885 } else if (theType == "sketch-2dpoint_selector") {
886 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
888 aPointWgt->setSketch(mySketchMgr->activeSketch());
889 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
891 }else if (theType == "sketch-2dpoint_flyout_selector") {
892 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
894 aPointWgt->setSketch(mySketchMgr->activeSketch());
895 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
897 } else if (theType == "sketch_shape_selector") {
898 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
899 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
900 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
901 aWgt = aShapeSelectorWgt;
902 } else if (theType == "sketch_multi_selector") {
903 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
904 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
905 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
906 aWgt = aShapeSelectorWgt;
908 else if (theType == "sketch_feature_point_selector") {
909 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
910 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
911 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
912 aWgt = aPointSelectorWgt;
914 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
915 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
916 } else if (theType == "export_file_selector") {
917 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
918 } else if (theType == "sketch_launcher") {
919 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
920 } else if (theType == "module_choice") {
921 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
922 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
923 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
928 //******************************************************
929 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
931 ModuleBase_ModelWidget* anActiveWidget = 0;
933 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
935 return anActiveWidget;
937 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
939 return anActiveWidget;
941 return aPanel->activeWidget(true);
944 //******************************************************
945 bool PartSet_Module::deleteObjects()
947 bool isProcessed = false;
949 XGUI_Workshop* aWorkshop = getWorkshop();
950 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
952 //SessionPtr aMgr = ModelAPI_Session::get();
953 // 1. check whether the delete should be processed in the module
954 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
955 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
956 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
957 if (isSketchOp || isNestedOp) {
959 // 2. find selected presentations
960 // selected objects should be collected before the current operation abort because
961 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
962 ModuleBase_ISelection* aSel = workshop()->selection();
963 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
964 // if there are no selected objects in the viewer, that means that the selection in another
965 // place cased this method. It is necessary to return the false value to understande in above
966 // method that delete is not processed
967 if (aSelectedObj.count() == 0)
970 // avoid delete of the objects, which are not belong to the current sketch
971 // in order to do not delete results of other sketches
972 QObjectPtrList aSketchObjects;
973 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
974 for ( ; anIt != aLast; anIt++) {
975 ObjectPtr anObject = *anIt;
976 if (mySketchMgr->isObjectOfSketch(anObject)) {
977 // sketch feature should be used in this list because workshop deletes features only
978 // results are skipped
979 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
980 aSketchObjects.append(aSketchFeature);
983 // if the selection contains only local selected presentations from other sketches,
984 // the Delete operation should not be done at all
985 if (aSketchObjects.size() == 0)
988 // 3. start operation
989 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
990 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
992 // the active nested sketch operation should be aborted unconditionally
993 // the Delete action should be additionally granted for the Sketch operation
994 // in order to do not abort/commit it
996 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
997 return true; // the objects are processed but can not be deleted
999 anOpMgr->startOperation(anOpAction);
1001 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1002 // the problem is in AIS Dimensions recompute
1003 // if a line and the dim are removed, line is the first
1004 // it causes the AIS recompute, where the base line is null,
1005 // the result is empty AIS in the viewer
1006 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1008 // 4. delete features
1009 // sketch feature should be skipped, only sub-features can be removed
1010 // when sketch operation is active
1011 aWorkshop->deleteFeatures(aSketchObjects);
1012 // 5. stop operation
1013 anOpMgr->commitOperation();
1018 //******************************************************
1019 void PartSet_Module::editFeature(FeaturePtr theFeature)
1021 storeConstraintsState(theFeature->getKind());
1022 ModuleBase_IModule::editFeature(theFeature);
1025 //******************************************************
1026 bool PartSet_Module::canCommitOperation() const
1031 //******************************************************
1032 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1034 myIsOperationIsLaunched = true;
1035 storeConstraintsState(theCmdId.toStdString());
1036 updateConstraintsState(theCmdId.toStdString());
1038 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1040 myIsOperationIsLaunched = false;
1043 //******************************************************
1044 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1046 if (myWorkshop->currentOperation() &&
1047 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1048 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1049 mySketchMgr->showConstraintStates();
1050 myHasConstraintShown = aShownStates;
1054 //******************************************************
1055 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1057 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1058 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1059 // Show constraints if a constraint was anOperation
1060 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1061 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1062 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1063 myHasConstraintShown[PartSet_Tools::Expressions]);
1067 //******************************************************
1068 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1070 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1071 if (!anAIS.IsNull()) {
1072 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1073 if (aFeature.get()) {
1074 bool aToUseZLayer = false;
1075 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1076 aToUseZLayer = true;
1078 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1079 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1082 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1083 aCtx->SetZLayer(anAIS, myVisualLayerId);
1089 //******************************************************
1090 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1093 // it should be recomputed in order to disappear in the viewer if the corresponded object
1095 //if (myCustomPrs->isActive())
1096 // myCustomPrs->redisplay(theObject, false);
1099 //******************************************************
1100 void PartSet_Module::onViewTransformed(int theTrsfType)
1102 // Set length of arrows constant in pixel size
1103 // if the operation is panning or rotate or panglobal then do nothing
1104 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1106 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1107 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1108 if (aContext.IsNull())
1111 //Handle(V3d_View) aView = aViewer->activeView();
1113 XGUI_Workshop* aWorkshop = getWorkshop();
1114 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1115 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1116 Handle(V3d_View) aView;
1118 for (aV3dViewer->InitDefinedViews();
1119 aV3dViewer->MoreDefinedViews();
1120 aV3dViewer->NextDefinedViews()) {
1121 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1122 double aS = aV->Scale();
1131 bool isModified = false;
1132 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1133 if (aCurrentOperation &&
1134 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1135 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1136 (aCurrentOperation->id() == "Measurement")))
1138 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1140 double aPrevLen = SketcherPrs_Tools::getArrowSize();
1141 SketcherPrs_Tools::setArrowSize(aLen);
1142 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1143 aViewer->SetScale(aViewer->activeView(), aCurScale);
1144 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1145 foreach (AISObjectPtr aAIS, aPrsList) {
1146 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1148 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1149 if (!aDim.IsNull()) {
1150 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1151 aContext->Redisplay(aDim, false);
1156 aDisplayer->updateViewer();
1161 //******************************************************
1162 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1164 return myCustomPrs->isActive(theFlag);
1167 //******************************************************
1168 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1169 const ModuleBase_CustomizeFlag& theFlag,
1170 const bool theUpdateViewer)
1172 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1175 //******************************************************
1176 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1177 const bool theUpdateViewer)
1179 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1182 //******************************************************
1183 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1184 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1186 bool aCustomized = false;
1188 XGUI_Workshop* aWorkshop = getWorkshop();
1189 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1190 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1194 if (!theResult.get()) {
1195 std::vector<int> aColor;
1196 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1197 if (!aColor.empty()) {
1198 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1201 // customize dimentional constrains
1202 sketchMgr()->customizePresentation(anObject);
1207 //******************************************************
1208 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1209 AISObjectPtr thePrs,
1210 GeomCustomPrsPtr theCustomPrs)
1212 bool aCustomized = false;
1214 XGUI_Workshop* aWorkshop = getWorkshop();
1215 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1216 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1220 std::vector<int> aColor;
1221 bool aUseCustomColor = true;
1222 if (aUseCustomColor)
1223 myOverconstraintListener->getCustomColor(anObject, aColor);
1224 // customize sketch symbol presentation
1225 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1226 if (!anAISIO.IsNull()) {
1227 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1228 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1229 if (!aPrs.IsNull()) {
1230 aPrs->SetCustomColor(aColor);
1233 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1234 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1235 if (!aPrs.IsNull()) {
1236 aPrs->SetCustomColor(aColor);
1241 // customize sketch dimension constraint presentation
1243 if (!aColor.empty()) { // otherwise presentation has the default color
1244 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1250 //******************************************************
1251 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1252 const bool theUpdateViewer)
1254 bool isRedisplayed = false;
1255 if (myCustomPrs->isActive(theFlag))
1256 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1258 return isRedisplayed;
1261 //******************************************************
1262 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1264 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1266 QLabel* aLabel = aOB->activeDocLabel();
1267 aLabel->installEventFilter(myMenuMgr);
1268 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1269 SLOT(onActiveDocPopup(const QPoint&)));
1270 aOB->treeView()->setExpandsOnDoubleClick(false);
1271 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1272 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1274 Events_Loop* aLoop = Events_Loop::loop();
1275 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1279 //******************************************************
1280 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1282 SessionPtr aMgr = ModelAPI_Session::get();
1283 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1285 XGUI_Workshop* aWorkshop = getWorkshop();
1286 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1288 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1291 aMenu.addAction(aActivatePartAction);
1292 aMenu.exec(aHeader->mapToGlobal(thePnt));
1295 //******************************************************
1296 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1298 return mySketchMgr->createPresentation(theResult);
1301 //******************************************************
1302 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1305 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1307 /// If last line finished on vertex the lines creation sequence has to be break
1308 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1310 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1311 // if there is an active widget, find the presented object in it
1312 if (!anActiveWidget)
1313 anActiveWidget = aPanel->preselectionWidget();
1315 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1317 if (aWidgetValidated)
1318 anObject = aWidgetValidated->findPresentedObject(theAIS);
1324 //******************************************************
1325 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1327 bool aCanBeShaged = true;
1329 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1331 aCanBeShaged = false;
1333 return aCanBeShaged;
1336 //******************************************************
1337 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1339 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1340 int aSelected = aObjects.size();
1341 SessionPtr aMgr = ModelAPI_Session::get();
1342 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1344 bool hasResult = false;
1345 bool hasFeature = false;
1346 bool hasParameter = false;
1347 bool hasCompositeOwner = false;
1348 bool hasResultInHistory = false;
1349 bool hasFolder = false;
1350 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1351 hasCompositeOwner, hasResultInHistory, hasFolder);
1353 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1354 if (aSelected == 1) {
1355 ObjectPtr aObject = aObjects.first();
1357 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1358 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1359 bool isPart = aPart.get() ||
1360 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1362 DocumentPtr aPartDoc;
1364 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1366 if (aPart.get()) // this may be null is Part feature is disabled
1367 aPartDoc = aPart->partDoc();
1369 theMenu->addAction(aActivatePartAction);
1370 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1372 } else if (aObject->document() == aMgr->activeDocument()) {
1373 if (hasParameter || hasFeature) {
1374 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1375 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1376 if (aCurrentOp && aFeature.get()) {
1377 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1378 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1385 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1386 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1387 theMenu->addSeparator();
1390 bool aNotDeactivate = (aCurrentOp == 0);
1391 if (!aNotDeactivate) {
1392 aActivatePartAction->setEnabled(false);
1396 //******************************************************
1397 #define EXPAND_PARENT(OBJ) \
1398 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1399 if (aObjIndex.isValid()) { \
1400 QModelIndex aParent = aObjIndex.parent(); \
1401 int aCount = aDataModel->rowCount(aParent); \
1403 aTreeView->setExpanded(aParent, true); \
1406 //******************************************************
1407 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1409 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1410 // Do not change activation of parts if an operation active
1411 static QStringList aAllowActivationList;
1412 if (aAllowActivationList.isEmpty())
1413 aAllowActivationList <<
1414 QString(PartSetPlugin_Part::ID().c_str()) <<
1415 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1416 QString(PartSetPlugin_Remove::ID().c_str());
1417 if (myWorkshop->currentOperation() &&
1418 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1420 XGUI_Workshop* aWorkshop = getWorkshop();
1421 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1422 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1423 QPalette aPalet = aLabel->palette();
1425 SessionPtr aMgr = ModelAPI_Session::get();
1426 DocumentPtr aActiveDoc = aMgr->activeDocument();
1427 // workaround for #2431 (SISGSEGV when launching some unit tests from GUI)
1428 //if (myActivePartIndex.isValid())
1429 // aTreeView->setExpanded(myActivePartIndex, false);
1431 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1432 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1433 bool needUpdate = false;
1434 if (myActivePartIndex.isValid()) {
1435 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1437 aTreeView->setExpanded(myActivePartIndex, true);
1440 aLabel->setPalette(aPalet);
1441 aWorkshop->updateCommandStatus();
1443 // Update displayed objects in order to update active color
1444 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1445 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1447 foreach(ObjectPtr aObj, aObjects) {
1448 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1449 aObj->isDisabled() || (!aObj->isDisplayed());
1451 aDisplayer->redisplay(aObj, false);
1453 aDisplayer->updateViewer();
1454 // Update tree items if they are expanded
1456 aTreeView->viewport()->repaint(aTreeView->viewport()->rect());
1458 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1459 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1460 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1461 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1463 ObjectPtr aConstrObj;
1464 ObjectPtr aResultObj;
1465 std::set<ObjectPtr>::const_iterator aIt;
1466 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1467 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1468 ObjectPtr aObject = (*aIt);
1469 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1470 && (aObject->document() != aRootDoc))
1471 aResultObj = aObject;
1472 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1473 && (aObject->document() != aRootDoc))
1474 aConstrObj = aObject;
1475 if (aResultObj.get() && aConstrObj.get())
1479 if (aResultObj.get() || aConstrObj.get()) {
1480 XGUI_Workshop* aWorkshop = getWorkshop();
1481 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1482 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1484 if (aResultObj.get()) {
1485 EXPAND_PARENT(aResultObj)
1487 if (aConstrObj.get()) {
1488 EXPAND_PARENT(aConstrObj)
1494 //******************************************************
1495 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1497 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1499 SessionPtr aMgr = ModelAPI_Session::get();
1500 if (!theIndex.isValid()) {
1501 // It seems that this code is obsolete
1502 //aMgr->setActiveDocument(aMgr->moduleDocument());
1505 if (theIndex.column() != 1) // Use only first column
1508 XGUI_Workshop* aWorkshop = getWorkshop();
1509 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1510 // De not use non editable Indexes
1511 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1513 ObjectPtr aObj = aDataModel->object(theIndex);
1515 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1516 if (!aPart.get()) { // Probably this is Feature
1517 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1518 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1519 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1522 if (aPart.get()) { // if this is a part
1523 if (aPart->partDoc() == aMgr->activeDocument()) {
1524 myMenuMgr->activatePartSet();
1526 myMenuMgr->activatePart(aPart);
1531 //******************************************************
1532 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1534 // z layer is created for all started operations in order to visualize operation AIS presentation
1536 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1537 if (aContext.IsNull())
1540 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1541 if (myVisualLayerId == 0) {
1542 if (myVisualLayerId == 0)
1543 aViewer->AddZLayer(myVisualLayerId);
1545 TColStd_SequenceOfInteger aZList;
1546 aViewer->GetAllZLayers(aZList);
1547 bool aFound = false;
1548 for (int i = 1; i <= aZList.Length(); i++) {
1549 if (aZList(i) == myVisualLayerId) {
1555 aViewer->AddZLayer(myVisualLayerId);
1557 // if there is an active operation with validated widget,
1558 // the filters of this widget should be activated in the created view
1559 myWorkshop->selectionActivate()->updateSelectionFilters();
1560 myWorkshop->selectionActivate()->updateSelectionModes();
1563 //******************************************************
1564 void PartSet_Module::widgetStateChanged(int thePreviousState)
1566 mySketchMgr->widgetStateChanged(thePreviousState);
1569 //******************************************************
1570 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1572 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1575 //******************************************************
1576 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1578 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1579 mySketchMgr->stopSketch(theOperation);
1583 //******************************************************
1584 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1586 GeomShapePtr aGeomShape;
1588 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1589 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1590 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1595 //******************************************************
1596 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1597 const GeomShapePtr& theGeomShape)
1599 AttributePtr anAttribute;
1600 GeomShapePtr aGeomShape = theGeomShape;
1601 if (!aGeomShape.get()) {
1602 // processing shape of result, e.g. sketch circle center is selected, this is a result
1603 // the geom shape is empty, the shape of result should be used
1604 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1605 if (aResult.get()) {
1606 aGeomShape = aResult->shape();
1610 if (aGeomShape.get()) {
1611 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1612 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1613 mySketchMgr->activeSketch());
1618 //******************************************************
1619 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1621 return sketchReentranceMgr()->reentrantMessage();
1624 //******************************************************
1625 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1627 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1630 //******************************************************
1631 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1634 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1638 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1639 if (!aChoiceTitle.isEmpty()) {
1640 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1643 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1645 aPanel->setWindowTitle(aChoiceTitle);
1649 //******************************************************
1650 XGUI_Workshop* PartSet_Module::getWorkshop() const
1652 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1653 return aConnector->workshop();
1656 void PartSet_Module::setDefaultConstraintShown()
1658 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1659 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1660 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1663 //******************************************************
1664 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1666 return myDataModel->root();