1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PartSet_Module.h"
21 #include "PartSet_WidgetSketchLabel.h"
22 #include "PartSet_Validators.h"
23 #include "PartSet_Tools.h"
24 #include "PartSet_PreviewPlanes.h"
25 #include "PartSet_WidgetBSplinePoints.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"
42 #include "PartSet_FieldStepPrs.h"
43 #include "PartSet_BSplineWidget.h"
45 #include "PartSet_Filters.h"
46 #include "PartSet_FilterInfinite.h"
52 #include <PartSetPlugin_Remove.h>
53 #include <PartSetPlugin_Part.h>
54 #include <PartSetPlugin_Duplicate.h>
56 #include <SketchPlugin_ConstraintCoincidence.h>
58 #include <ModuleBase_Operation.h>
59 #include <ModuleBase_IViewer.h>
60 #include <ModuleBase_IViewWindow.h>
61 #include <ModuleBase_IPropertyPanel.h>
62 #include <ModuleBase_ISelectionActivate.h>
63 #include <ModuleBase_WidgetChoice.h>
64 #include <ModuleBase_WidgetEditor.h>
65 #include <ModuleBase_WidgetValidated.h>
66 #include <ModuleBase_Tools.h>
67 #include <ModuleBase_OperationFeature.h>
68 #include <ModuleBase_WidgetFactory.h>
69 #include <ModuleBase_OperationDescription.h>
70 #include <ModuleBase_ViewerPrs.h>
71 #include <ModuleBase_ResultPrs.h>
73 #include <ModelAPI_ResultField.h>
74 #include <ModelAPI_Object.h>
75 #include <ModelAPI_Events.h>
76 #include <ModelAPI_Validator.h>
77 #include <ModelAPI_Data.h>
78 #include <ModelAPI_Session.h>
79 #include <ModelAPI_ResultBody.h>
80 #include <ModelAPI_AttributeString.h>
81 #include <ModelAPI_AttributeSelectionList.h>
82 #include <ModelAPI_Tools.h>
83 #include <ModelAPI_ResultConstruction.h>
84 #include <ModelAPI_AttributeIntArray.h>
85 #include <ModelAPI_ResultGroup.h>
87 #include <GeomDataAPI_Point2D.h>
88 #include <GeomDataAPI_Point.h>
89 #include <GeomDataAPI_Dir.h>
91 #include <XGUI_ActiveControlMgr.h>
92 #include <XGUI_ActiveControlSelector.h>
93 #include <XGUI_ActionsMgr.h>
94 #include <XGUI_ContextMenuMgr.h>
95 #include <XGUI_DataModel.h>
96 #include <XGUI_Displayer.h>
97 #include <XGUI_ErrorMgr.h>
98 #include <XGUI_FacesPanelSelector.h>
99 #include <XGUI_ModuleConnector.h>
100 #include <XGUI_ObjectsBrowser.h>
101 #include <XGUI_OperationMgr.h>
102 #include <XGUI_PropertyPanel.h>
103 #include <XGUI_SelectionMgr.h>
104 #include <XGUI_Tools.h>
105 #include <XGUI_Workshop.h>
107 #include <SketchPlugin_ConstraintAngle.h>
108 #include <SketchPlugin_ConstraintLength.h>
109 #include <SketchPlugin_ConstraintDistance.h>
110 #include <SketchPlugin_ConstraintParallel.h>
111 #include <SketchPlugin_ConstraintPerpendicular.h>
112 #include <SketchPlugin_ConstraintRadius.h>
113 #include <SketchPlugin_Feature.h>
114 #include <SketchPlugin_Projection.h>
115 #include <SketchPlugin_Sketch.h>
117 #include <SketcherPrs_SymbolPrs.h>
118 #include <SketcherPrs_PositionMgr.h>
119 #include <SketcherPrs_Coincident.h>
120 #include <SketcherPrs_Tools.h>
122 #include <Events_Loop.h>
123 #include <Config_PropManager.h>
124 #include <Config_Keywords.h>
126 #include <AIS_Dimension.hxx>
127 #include <AIS_InteractiveObject.hxx>
128 #include <StdSelect_TypeOfFace.hxx>
129 #include <TopoDS_Vertex.hxx>
130 #include <TopoDS.hxx>
131 #include <TopoDS_Shape.hxx>
132 #include <BRep_Tool.hxx>
135 #include <QMouseEvent>
138 #include <QApplication>
139 #include <QMessageBox>
140 #include <QMainWindow>
144 #include <GeomAlgoAPI_FaceBuilder.h>
145 #include <GeomDataAPI_Dir.h>
147 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
148 #include <Graphic3d_Texture2Dmanual.hxx>
149 #include <OCCViewer_Utilities.h>
152 #define FEATURE_ITEM_COLOR "0,0,225"
155 /*!Create and return new instance of XGUI_Module*/
156 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
158 return new PartSet_Module(theWshop);
161 //******************************************************
162 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
163 : ModuleBase_IModule(theWshop),
164 myIsOperationIsLaunched(false),
168 new PartSet_IconFactory(this);
170 mySketchMgr = new PartSet_SketcherMgr(this);
171 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
173 ModuleBase_IViewer* aViewer = theWshop->viewer();
174 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
175 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
176 connect(aViewer, SIGNAL(viewTransformed(int)),
177 SLOT(onViewTransformed(int)));
178 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
179 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
180 myMenuMgr = new PartSet_MenuMgr(this);
181 myCustomPrs = new PartSet_CustomPrs(theWshop);
183 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
185 Events_Loop* aLoop = Events_Loop::loop();
186 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
187 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
189 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
190 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
191 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
192 std::set<std::string> aCRGroupNames;
193 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
194 aCRFilter->setGroupNames(aCRGroupNames);
195 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
197 setDefaultConstraintShown();
199 //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
200 // Config_Prop::Color, "225,225,225");
202 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
203 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
205 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
206 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
208 Config_PropManager::registerProp("Visualization",
209 ModelAPI_ResultConstruction::DEFAULT_COLOR_CONFIG_NAME(),
210 "Construction color", Config_Prop::Color,
211 ModelAPI_ResultConstruction::DEFAULT_COLOR());
213 Config_PropManager::registerProp(
215 ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME(),
216 "Construction point color", Config_Prop::Color,
217 ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR());
220 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
221 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
223 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
224 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
226 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
227 "Reference shape wireframe color in operation", Config_Prop::Color,
228 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
229 Config_PropManager::registerProp("Visualization", "operation_result_color",
230 "Result shape wireframe color in operation", Config_Prop::Color,
231 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
232 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
233 "Multi selector item color in operation", Config_Prop::Color,
234 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
235 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
236 "Color of removed feature in operation", Config_Prop::Color,
237 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
238 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
239 "Color of sketch plane", Config_Prop::Color,
240 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
242 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
243 "Hidden faces transparency",
244 Config_Prop::DblSpin,
247 std::ostringstream aStream;
248 aStream << SketcherPrs_Tools::getDefaultArrowSize();
249 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
250 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
252 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
253 Config_Prop::String, "Times-bold");
257 aStream << SketcherPrs_Tools::getDefaultTextHeight();
258 Config_PropManager::registerProp("Visualization", "dimension_value_size",
259 "Dimension value size", Config_Prop::IntSpin, aStream.str());
261 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
263 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
265 Config_PropManager::registerProp("Visualization", "feature_objectbrowser_color",
266 "Feature items in Object Browser",
267 Config_Prop::Color, FEATURE_ITEM_COLOR);
269 Config_PropManager::registerProp("Visualization", "zoom_trihedron_arrows",
270 "Keep trihedron arrows view size constant", Config_Prop::Boolean, "false");
272 Config_PropManager::registerProp("Visualization", "axis_arrow_size",
273 "Trihedron arrows constant size", Config_Prop::IntSpin, "10");
275 Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
276 "Add parameter in parameters manager dialog",
277 Config_Prop::Shortcut, "Ctrl+A");
279 Config_PropManager::registerProp("Windows", "use_hide_faces_panel",
280 "Use HideFaces panel in operations", Config_Prop::Boolean, "false");
283 //******************************************************
284 PartSet_Module::~PartSet_Module()
287 delete myOverconstraintListener;
291 //******************************************************
292 void PartSet_Module::createFeatures()
294 ModuleBase_IModule::createFeatures();
295 myRoot = new PartSet_RootNode();
296 myRoot->setWorkshop(workshop());
300 //******************************************************
301 void PartSet_Module::storeSelection()
303 // cash is used only to restore selection, so it should be filled in storeSelection and
304 // after applying immediatelly cleared in restoreSelection
305 myCurrentSelection.clear();
306 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
309 //******************************************************
310 void PartSet_Module::restoreSelection()
312 // cash is used only to restore selection, so it should be filled in storeSelection and
313 // after applying immediatelly cleared in restoreSelection
314 sketchMgr()->restoreSelection(myCurrentSelection);
315 myCurrentSelection.clear();
318 //******************************************************
319 void PartSet_Module::registerValidators()
321 //Registering of validators
322 SessionPtr aMgr = ModelAPI_Session::get();
323 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
324 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
325 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
326 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
327 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
328 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
329 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
330 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
331 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
332 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
333 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
334 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
335 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
336 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
337 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
338 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
339 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
340 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
341 aFactory->registerValidator("PartSet_MultyTranslationSelection",
342 new PartSet_MultyTranslationSelection);
343 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
344 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
345 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
348 //******************************************************
349 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
350 const bool isToConnect)
352 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
355 //******************************************************
356 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
358 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
359 mySketchMgr->commitNestedSketch(theOperation);
361 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
362 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
363 overconstraintListener()->setActive(false);
365 /// Restart sketcher operations automatically
366 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
367 getWorkshop()->selector()->clearSelection();
371 //******************************************************
372 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
374 /// Restart sketcher operations automatically
375 mySketchReentrantMgr->operationAborted(theOperation);
376 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
377 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
378 overconstraintListener()->setActive(false);
380 getWorkshop()->selector()->clearSelection();
383 //******************************************************
384 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
386 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
389 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
390 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
392 ModuleBase_ModelWidget* aFilledWidget = 0;
393 bool aPostonedWidgetActivation = false;
395 FeaturePtr aFeature = aFOperation->feature();
396 /// Restart sketcher operations automatically
397 /// it is important to call method of sketch reentrant manager before filling of PP
398 /// because it fills some created feature attributes, these new values should be used
399 /// to fill the property panel
400 mySketchReentrantMgr->operationStarted(theOperation);
402 aWorkshop->fillPropertyPanel(aFOperation);
403 // filling the operation values by the current selection
404 // if the operation can be committed after the controls filling, the method perform should
405 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
406 bool isOperationCommitted = false;
407 if (!aFOperation->isEditOperation()) {
408 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
409 // if there is a greed attribute, automatic commit by preselection
410 // for this feature is prohibited
411 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
412 if (currentOperation() != aFOperation)
413 isOperationCommitted = true;
415 if (aGreedAttributeId.empty()) {
416 // a signal should be emitted before the next widget activation
417 // because, the activation of the next widget will give a focus to the widget.
418 // As a result the value of the widget is initialized.
419 // And commit may happens until the value is entered.
421 if (mySketchReentrantMgr->canBeCommittedByPreselection())
422 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
423 // activate the next obligatory widget
424 if (!isOperationCommitted)
425 aPropertyPanel->activateNextWidget(aFilledWidget);
428 else { // there is a greed widget
429 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
430 std::string aFirstAttributeId = aWidgets.front()->attributeID();
431 // activate next widget after greeded if it is the first widget in the panel
432 // else the first panel widget is already activated by operation start
433 if (aFirstAttributeId == aGreedAttributeId)
434 aPostonedWidgetActivation = true;
437 } if (!isOperationCommitted) {
438 aWorkshop->connectToPropertyPanel(true);
439 updateSketcherOnStart(aFOperation);
440 updatePresentationsOnStart(aFOperation);
442 // the objects of the current operation should be deactivated
443 QObjectPtrList anObjects;
444 anObjects.append(aFeature);
445 std::list<ResultPtr> aResults;
446 ModelAPI_Tools::allResults(aFeature, aResults);
447 std::list<ResultPtr>::const_iterator aIt;
448 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
449 anObjects.append(*aIt);
451 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
452 for (; anIt != aLast; anIt++)
453 aWorkshop->deactivateActiveObject(*anIt, false);
454 if (anObjects.size() > 0) {
455 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
456 aDisplayer->updateViewer();
458 /// state of command actions should be updated after displayed objects modification because
459 /// deactivation(for example) of objects may influence on selection in the viewer
460 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
461 workshop()->updateCommandStatus();
463 if (aPostonedWidgetActivation) {
464 // if the widget is an empty in the chain of activated widgets, the current operation
465 // is restarted. It should be performed after functionality of the operation starting
466 aPropertyPanel->activateNextWidget(aFilledWidget);
471 //******************************************************
472 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
474 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
475 mySketchMgr->startSketch(theOperation);
477 // It is switched off because of
478 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
479 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
480 mySketchMgr->startNestedSketch(theOperation);
484 //******************************************************
485 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
487 ModuleBase_OperationFeature* aFOperation =
488 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
490 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
491 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
495 //******************************************************
496 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
498 ModuleBase_IModule::operationResumed(theOperation);
500 ModuleBase_OperationFeature* aFOperation =
501 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
503 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
504 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
508 //******************************************************
509 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
511 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
512 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
513 bool isModified = isModifiedArgs || isModifiedResults;
515 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
516 mySketchMgr->stopNestedSketch(theOperation);
518 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
519 setDefaultConstraintShown();
521 //VSV: Viewer is updated on feature update and redisplay
523 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
524 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
525 aDisplayer->updateViewer();
528 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
529 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
530 for (; anIt != aLast; anIt++) {
531 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
535 //******************************************************
536 ModuleBase_Operation* PartSet_Module::currentOperation() const
538 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
539 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
540 return anOpMgr->currentOperation();
543 //******************************************************
544 bool PartSet_Module::canUndo() const
546 bool aCanUndo = false;
547 SessionPtr aMgr = ModelAPI_Session::get();
548 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
549 aCanUndo = !aMgr->isOperation();
550 if (!aCanUndo) // check the enable state additionally by sketch manager
551 aCanUndo = aMgr->canUndo();
556 //******************************************************
557 bool PartSet_Module::canRedo() const
559 bool aCanRedo = false;
560 SessionPtr aMgr = ModelAPI_Session::get();
561 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
562 aCanRedo = !aMgr->isOperation();
563 if (!aCanRedo) // check the enable state additionally by sketch manager
564 aCanRedo = aMgr->canRedo();
569 //******************************************************
570 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
573 if (theActionId == "MOVE_CMD" || theActionId == "MOVE_SPLIT_CMD") {
574 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
576 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
577 // part features can not be moved in the history.
578 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
585 //******************************************************
586 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
588 // the sketch manager put the restriction to the objects erase
589 return mySketchMgr->canEraseObject(theObject);
592 //******************************************************
593 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
595 // the sketch manager put the restriction to the objects display
596 return mySketchMgr->canDisplayObject(theObject);
599 //******************************************************
600 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
601 const QString& theStartedOperationKind)
603 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
606 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
609 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
611 mySketchMgr->processHiddenObject(theObjects);
614 //******************************************************
615 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
617 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
619 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
620 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
621 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
622 if (isSketchOp || isNestedOp) {
623 // in active sketch operation it is possible to activate operation object in selection
624 // in the edit operation, e.g. points of the line can be moved when the line is edited
625 ModuleBase_OperationFeature* aFOperation =
626 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
627 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
632 //******************************************************
633 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
635 QMap<int, QAction*>& theMenuActions) const
637 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
640 //******************************************************
641 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
643 myMenuMgr->updateViewerMenu(theStdActions);
646 //******************************************************
647 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
649 bool isEnabledFixed = false;
650 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
651 mySketchReentrantMgr->isInternalEditActive())
652 isEnabledFixed = true;
653 return isEnabledFixed;
656 //******************************************************
657 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
659 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
660 if (anError.isEmpty())
661 anError = sketchMgr()->getFeatureError(theFeature);
666 //******************************************************
667 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
668 QStringList& theIds) const
670 myMenuMgr->grantedOperationIds(theOperation, theIds);
672 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
673 XGUI_Workshop* aWorkshop = getWorkshop();
674 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
678 //******************************************************
679 void PartSet_Module::activeSelectionModes(QIntList& theModes)
681 if (mySketchMgr->activeSketch().get())
682 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
684 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
687 //******************************************************
688 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
690 customSubShapesSelectionModes(theModes);
691 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
692 //myWorkshop->module()->activeSelectionModes(theModes);
695 //******************************************************
696 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
697 SelectMgr_ListOfFilter& theSelectionFilters)
699 bool isSketchActive = mySketchMgr->activeSketch().get();
701 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
702 mySelectionFilters.begin();
703 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
704 int aFilterType = aFiltersIt->first;
705 // do not add not participating filters in given parameters
706 if (!theFilterTypes.contains(aFilterType))
709 // using sketch filters only if sketch operation is active
710 if (!isSketchActive &&
711 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
714 // using filtering of construction results only from faces panel
715 if (aFilterType == SF_ResultGroupNameFilter)
718 theSelectionFilters.Append(aFiltersIt->second);
722 //******************************************************
723 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
725 if (theModes.contains(TopAbs_FACE))
726 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
727 if (theModes.contains(TopAbs_WIRE))
728 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
730 if (mySketchMgr->activeSketch().get())
731 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
734 //******************************************************
735 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
736 ObjectPtr& theObject, AttributePtr& theAttribute)
738 ObjectPtr anObject = theSelected->object();
739 GeomShapePtr aShape = theSelected->shape();
741 theAttribute = findAttribute(anObject, aShape);
742 // TODO: try to create result if object is an external object
743 theObject = anObject;
746 //******************************************************
747 bool PartSet_Module::isMouseOverWindow()
749 return mySketchMgr->isMouseOverWindow();
752 //******************************************************
753 bool PartSet_Module::isSketchNeutralPointActivated() const
755 bool isNeutralPoint = true;
756 if (sketchReentranceMgr()->isInternalEditActive())
757 isNeutralPoint = false;
758 if (myIsOperationIsLaunched)
759 isNeutralPoint = false;
761 return isNeutralPoint;
764 //******************************************************
765 void PartSet_Module::closeDocument()
767 myActivePartIndex = QModelIndex();
768 SketcherPrs_PositionMgr::get()->clearAll();
771 //******************************************************
772 void PartSet_Module::clearViewer()
774 myCustomPrs->clearPrs();
776 XGUI_Workshop* aWorkshop = getWorkshop();
777 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
778 aDisplayer->deactivateSelectionFilters(false);
781 //******************************************************
782 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
784 ModuleBase_OperationFeature* aFOperation =
785 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
789 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
790 // we have to manually activate the sketch label in edit mode
791 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
792 aPanel->activateWidget(aPanel->modelWidgets().first());
795 //******************************************************
796 bool PartSet_Module::createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
797 QList<ModuleBase_ModelWidget*>& theWidgets) const
799 bool aProcessed = false;
801 XGUI_Workshop* aWorkshop = getWorkshop();
802 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
803 if (mySketchMgr->activeSketch().get() && aPropertyPanel) {
804 ModuleBase_ISelection* aSelection = workshop()->selection();
805 // click on a point in sketch leads here with the point is highlighted, not yet selected
806 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
807 if (aPreselection.size() == 1) {
808 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
809 ObjectPtr anObject = aSelectedPrs->object();
811 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
812 GeomShapePtr aShape = aSelectedPrs->shape();
813 // click on the digit of dimension constrain comes here
814 // with an empty shape, so we need the check
815 if (aFeature == theFeature && aShape.get() && !aShape->isNull()) {
816 // if feature has only one result and shape of result is equal to selected shape
817 // this attribute is not processed. It is a case of Sketch Point.
818 if (aFeature->results().size() == 1) {
819 ResultPtr aResult = aFeature->results().front();
820 if (aResult.get() && aResult->shape()->isEqual(aShape))
823 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
824 std::pair<AttributePtr, int> anAttribute =
825 PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape, mySketchMgr->activeSketch());
826 if (anAttribute.first.get()) {
827 ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
829 const std::string anAttributeId = anAttribute.first->id();
830 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
832 theWidgets = aFactory.getModelWidgets();
833 // it is possible that the point does not present in XML definition,
834 // in this case, we assume that it is not processed by this module
835 // e.g. "Intersection point" feature
836 aProcessed = !theWidgets.isEmpty();
844 //******************************************************
845 void PartSet_Module::onSelectionChanged()
847 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
851 bool isSketcherOp = false;
852 // An edit operation is enable only if the current opeation is the sketch operation
853 if (mySketchMgr->activeSketch()) {
854 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
855 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
858 // Editing of constraints can be done on selection
859 ModuleBase_ISelection* aSelect = myWorkshop->selection();
860 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
861 if (aSelected.size() == 1) {
862 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
863 ObjectPtr aObject = aPrs->object();
864 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
866 std::string aId = aFeature->getKind();
867 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
868 (aId == SketchPlugin_ConstraintLength::ID()) ||
869 (aId == SketchPlugin_ConstraintDistance::ID()) ||
870 (aId == SketchPlugin_ConstraintAngle::ID())) {
871 editFeature(aFeature);
878 //******************************************************
879 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
881 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
882 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
883 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
886 //******************************************************
887 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
889 Config_WidgetAPI* theWidgetApi)
891 ModuleBase_IWorkshop* aWorkshop = workshop();
892 ModuleBase_ModelWidget* aWgt = NULL;
893 if (theType == "sketch-start-label") {
894 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
895 theWidgetApi, myHasConstraintShown);
896 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
897 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
898 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
899 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
900 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
901 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
902 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
903 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
905 } else if (theType == "sketch-2dpoint_selector") {
906 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
908 aPointWgt->setSketch(mySketchMgr->activeSketch());
909 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
911 }else if (theType == "sketch-2dpoint_flyout_selector") {
912 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
914 aPointWgt->setSketch(mySketchMgr->activeSketch());
915 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
917 } else if (theType == "sketch_shape_selector") {
918 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
919 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
920 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
921 aWgt = aShapeSelectorWgt;
922 } else if (theType == "sketch_multi_selector") {
923 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
924 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
925 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
926 aWgt = aShapeSelectorWgt;
928 else if (theType == "sketch_feature_point_selector") {
929 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
930 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
931 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
932 aWgt = aPointSelectorWgt;
934 else if (theType == "sketch-bspline_selector") {
935 PartSet_WidgetBSplinePoints* aBSplineWgt =
936 new PartSet_WidgetBSplinePoints(theParent, aWorkshop, theWidgetApi);
937 aBSplineWgt->setSketch(mySketchMgr->activeSketch());
940 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
941 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
942 } else if (theType == "export_file_selector") {
943 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
944 } else if (theType == "sketch_launcher") {
945 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
947 else if (theType == "module_choice") {
948 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
949 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
950 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
951 } else if (theType == "bspline-panel") {
952 PartSet_BSplineWidget* aPanel = new PartSet_BSplineWidget(theParent, theWidgetApi);
953 //aPanel->setFeature(theFeature);
959 //******************************************************
960 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
962 ModuleBase_ModelWidget* anActiveWidget = 0;
964 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
966 return anActiveWidget;
968 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
970 return anActiveWidget;
972 return aPanel->activeWidget(true);
975 //******************************************************
976 bool PartSet_Module::deleteObjects()
978 bool isProcessed = false;
980 XGUI_Workshop* aWorkshop = getWorkshop();
981 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
983 //SessionPtr aMgr = ModelAPI_Session::get();
984 // 1. check whether the delete should be processed in the module
985 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
986 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
987 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
988 if (isSketchOp || isNestedOp) {
990 // 2. find selected presentations
991 // selected objects should be collected before the current operation abort because
992 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
993 ModuleBase_ISelection* aSel = workshop()->selection();
994 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
995 // if there are no selected objects in the viewer, that means that the selection in another
996 // place cased this method. It is necessary to return the false value to understande in above
997 // method that delete is not processed
998 if (aSelectedObj.count() == 0)
1001 // avoid delete of the objects, which are not belong to the current sketch
1002 // in order to do not delete results of other sketches
1003 QObjectPtrList aSketchObjects;
1004 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
1005 for ( ; anIt != aLast; anIt++) {
1006 ObjectPtr anObject = *anIt;
1007 if (mySketchMgr->isObjectOfSketch(anObject)) {
1008 // sketch feature should be used in this list because workshop deletes features only
1009 // results are skipped
1010 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
1011 aSketchObjects.append(aSketchFeature);
1014 // if the selection contains only local selected presentations from other sketches,
1015 // the Delete operation should not be done at all
1016 if (aSketchObjects.size() == 0)
1019 // 3. start operation
1020 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1021 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, this);
1023 // the active nested sketch operation should be aborted unconditionally
1024 // the Delete action should be additionally granted for the Sketch operation
1025 // in order to do not abort/commit it
1027 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1028 return true; // the objects are processed but can not be deleted
1030 anOpMgr->startOperation(anOpAction);
1032 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1033 // the problem is in AIS Dimensions recompute
1034 // if a line and the dim are removed, line is the first
1035 // it causes the AIS recompute, where the base line is null,
1036 // the result is empty AIS in the viewer
1037 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1039 // 4. delete features
1040 // sketch feature should be skipped, only sub-features can be removed
1041 // when sketch operation is active
1042 aWorkshop->deleteFeatures(aSketchObjects);
1043 // 5. stop operation
1044 anOpMgr->commitOperation();
1049 //******************************************************
1050 void PartSet_Module::editFeature(FeaturePtr theFeature)
1052 storeConstraintsState(theFeature->getKind());
1053 ModuleBase_IModule::editFeature(theFeature);
1056 //******************************************************
1057 bool PartSet_Module::canCommitOperation() const
1062 //******************************************************
1063 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1065 myIsOperationIsLaunched = true;
1066 storeConstraintsState(theCmdId.toStdString());
1067 updateConstraintsState(theCmdId.toStdString());
1069 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1071 myIsOperationIsLaunched = false;
1074 //******************************************************
1075 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1077 if (myWorkshop->currentOperation() &&
1078 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1079 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1080 mySketchMgr->showConstraintStates();
1081 myHasConstraintShown = aShownStates;
1085 //******************************************************
1086 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1088 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1089 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1090 // Show constraints if a constraint was anOperation
1091 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1092 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1093 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1094 myHasConstraintShown[PartSet_Tools::Expressions]);
1098 //******************************************************
1099 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1101 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1102 if (!anAIS.IsNull()) {
1103 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1104 if (aFeature.get()) {
1105 bool aToUseZLayer = false;
1106 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1107 aToUseZLayer = true;
1109 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1110 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1113 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1114 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1115 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1117 aCtx->SetZLayer(anAIS, myVisualLayerId);
1123 //******************************************************
1124 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1127 // it should be recomputed in order to disappear in the viewer if the corresponded object
1129 //if (myCustomPrs->isActive())
1130 // myCustomPrs->redisplay(theObject, false);
1133 //******************************************************
1134 void PartSet_Module::onViewTransformed(int theTrsfType)
1136 // Set length of arrows constant in pixel size
1137 // if the operation is panning or rotate or panglobal then do nothing
1138 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1140 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1141 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1142 if (aContext.IsNull())
1145 //Handle(V3d_View) aView = aViewer->activeView();
1147 XGUI_Workshop* aWorkshop = getWorkshop();
1148 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1149 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1150 Handle(V3d_View) aView;
1152 for (aV3dViewer->InitDefinedViews();
1153 aV3dViewer->MoreDefinedViews();
1154 aV3dViewer->NextDefinedViews()) {
1155 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1156 double aS = aV->Scale();
1165 bool isModified = false;
1166 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1167 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1168 if (aCurrentOperation &&
1169 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1170 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1171 (aCurrentOperation->id() == "Measurement")))
1173 SketcherPrs_Tools::setArrowSize(aLen);
1174 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1175 aViewer->SetScale(aViewer->activeView(), aCurScale);
1177 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1178 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1180 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1181 foreach(AISObjectPtr aAIS, aPrsList) {
1182 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1184 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1185 if (!aDim.IsNull()) {
1186 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1187 aContext->Redisplay(aDim, false);
1193 // Manage trihedron arrows
1194 if (Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows")) {
1195 Handle(AIS_Trihedron) aTrihedron = aViewer->trihedron();
1196 if (!aTrihedron.IsNull()) {
1198 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1199 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1200 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1201 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1202 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1203 aContext->Redisplay(aTrihedron, false);
1208 aDisplayer->updateViewer();
1211 //******************************************************
1212 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1214 return myCustomPrs->isActive(theFlag);
1217 //******************************************************
1218 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1219 const ModuleBase_CustomizeFlag& theFlag,
1220 const bool theUpdateViewer)
1222 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1225 //******************************************************
1226 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1227 const bool theUpdateViewer)
1229 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1232 //******************************************************
1233 //bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1234 // std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1236 // bool aCustomized = false;
1238 // XGUI_Workshop* aWorkshop = getWorkshop();
1239 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1240 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1242 // return aCustomized;
1244 // if (!theResult.get()) {
1245 // std::vector<int> aColor;
1246 // XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1247 // if (!aColor.empty()) {
1248 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1251 // // customize dimentional constrains
1252 // sketchMgr()->customisePresentation(anObject);
1254 // return aCustomized;
1257 ////******************************************************
1258 //bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1259 // AISObjectPtr thePrs,
1260 // GeomCustomPrsPtr theCustomPrs)
1262 // bool aCustomized = false;
1264 // XGUI_Workshop* aWorkshop = getWorkshop();
1265 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1266 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1268 // return aCustomized;
1270 // std::vector<int> aColor;
1271 // bool aUseCustomColor = true;
1272 // if (aUseCustomColor)
1273 // myOverconstraintListener->getCustomColor(anObject, aColor);
1274 // // customize sketch symbol presentation
1275 // Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1276 // if (!anAISIO.IsNull()) {
1277 // if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1278 // Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1279 // if (!aPrs.IsNull()) {
1280 // aPrs->SetCustomColor(aColor);
1281 // aCustomized = true;
1283 // } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1284 // Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1285 // if (!aPrs.IsNull()) {
1286 // aPrs->SetCustomColor(aColor);
1287 // aCustomized = true;
1291 // // customize sketch dimension constraint presentation
1292 // if (!aCustomized) {
1293 // if (!aColor.empty()) { // otherwise presentation has the default color
1294 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1297 // return aCustomized;
1300 //******************************************************
1301 bool PartSet_Module::customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1302 const bool theUpdateViewer)
1304 bool isRedisplayed = false;
1305 if (myCustomPrs->isActive(theFlag))
1306 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1308 return isRedisplayed;
1311 //******************************************************
1312 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1314 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1316 QLabel* aLabel = aOB->activeDocLabel();
1317 aLabel->installEventFilter(myMenuMgr);
1318 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1319 SLOT(onActiveDocPopup(const QPoint&)));
1320 aOB->treeView()->setExpandsOnDoubleClick(false);
1321 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1322 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1324 Events_Loop* aLoop = Events_Loop::loop();
1325 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1329 //******************************************************
1330 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1332 SessionPtr aMgr = ModelAPI_Session::get();
1333 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1335 XGUI_Workshop* aWorkshop = getWorkshop();
1336 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1338 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1341 aMenu.addAction(aActivatePartAction);
1344 if (aMgr->activeDocument() == aMgr->moduleDocument()) {
1345 DocumentPtr aDoc = aMgr->moduleDocument();
1346 int aNbParts = aDoc->size(ModelAPI_ResultPart::group());
1347 bool aHaveToActivate = false;
1348 for (int i = 0; i < aNbParts; i++) {
1349 ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i);
1350 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1351 if (!aPartRes->partDoc().get()) {
1352 aHaveToActivate = true;
1356 if (aHaveToActivate) {
1357 QAction* aActivateAllPartAction = myMenuMgr->action("ACTIVATE_ALL_PARTS_CMD");
1358 aMenu.addAction(aActivateAllPartAction);
1363 aMenu.exec(aHeader->mapToGlobal(thePnt));
1366 //******************************************************
1367 AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject)
1369 Handle(AIS_InteractiveObject) anAISPrs = mySketchMgr->createPresentation(theObject);
1370 if (anAISPrs.IsNull()) {
1371 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1372 if (aResult.get()) {
1373 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
1374 if (aShapePtr.get() != NULL)
1375 anAISPrs = new ModuleBase_ResultPrs(aResult);
1378 FieldStepPtr aStep =
1379 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1381 anAISPrs = new PartSet_FieldStepPrs(aStep);
1386 if (!anAISPrs.IsNull()) {
1387 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
1388 if (!aShapePrs.IsNull())
1389 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
1391 anAIS = AISObjectPtr(new GeomAPI_AISObject());
1392 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
1393 customizePresentation(theObject, anAIS);
1398 //******************************************************
1399 void getResultColor(const ResultPtr& theResult, std::vector<int>& theColor)
1401 ModelAPI_Tools::getColor(theResult, theColor);
1402 if (theColor.empty())
1403 PartSet_Tools::getDefaultColor(theResult, false, theColor);
1406 //******************************************************
1407 double getResultDeflection(const ResultPtr& theResult)
1409 double aDeflection = ModelAPI_Tools::getDeflection(theResult);
1410 if (aDeflection < 0)
1411 aDeflection = PartSet_Tools::getDefaultDeflection(theResult);
1415 //******************************************************
1416 double getResultTransparency(const ResultPtr& theResult)
1418 double aTransparency = ModelAPI_Tools::getTransparency(theResult);
1419 if (aTransparency < 0)
1420 aTransparency = PartSet_Tools::getDefaultTransparency();
1421 return aTransparency;
1424 //******************************************************
1425 void PartSet_Module::setTexture(const std::string & theTextureFile, const AISObjectPtr& thePrs)
1427 Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
1428 if (!anAIS.IsNull())
1430 /// set color to white and change material aspect,
1431 /// in order to keep a natural apect of the image.
1432 thePrs->setColor(255, 255, 255);
1433 Quantity_Color myShadingColor(NCollection_Vec3<float>(1., 1., 1.));
1434 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
1435 if (!anAISShape.IsNull())
1437 auto myDrawer = anAISShape->Attributes();
1439 myDrawer->ShadingAspect()->SetColor(myShadingColor);
1440 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
1441 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
1442 aMatAspect.SetTransparency(0.0);
1443 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
1444 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
1446 Handle(Image_PixMap) aPixmap;
1447 QPixmap px(theTextureFile.c_str());
1450 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
1452 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
1453 (new Graphic3d_Texture2Dmanual(aPixmap));
1454 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
1456 anAISShape->SetDisplayMode(AIS_Shaded);
1461 //******************************************************
1462 void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
1463 const AISObjectPtr& thePrs) const
1465 if (mySketchMgr->isObjectOfSketch(theObject)) {
1466 mySketchMgr->customizeSketchPresentation(theObject, thePrs);
1469 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1470 if (aResult.get()) {
1471 std::vector<int> aColor;
1472 getResultColor(aResult, aColor);
1474 SessionPtr aMgr = ModelAPI_Session::get();
1475 if (aMgr->activeDocument() != aResult->document()) {
1476 QColor aQColor(aColor[0], aColor[1], aColor[2]);
1478 QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
1479 aColor[0] = aNewColor.red();
1480 aColor[1] = aNewColor.green();
1481 aColor[2] = aNewColor.blue();
1483 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1485 thePrs->setDeflection(getResultDeflection(aResult));
1487 thePrs->setTransparency(getResultTransparency(aResult));
1489 /// set texture parameters
1490 if(aResult->hasTextureFile()){
1491 setTexture(aResult->getTextureFile(), thePrs);
1494 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1495 if (aFeature.get()) {
1496 if (aFeature->getKind() == SketchPlugin_Sketch::ID())
1497 thePrs->setWidth(2);
1503 //******************************************************
1504 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1507 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1509 /// If last line finished on vertex the lines creation sequence has to be break
1510 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1512 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1513 // if there is an active widget, find the presented object in it
1514 if (!anActiveWidget)
1515 anActiveWidget = aPanel->preselectionWidget();
1517 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1519 if (aWidgetValidated)
1520 anObject = aWidgetValidated->findPresentedObject(theAIS);
1526 //******************************************************
1527 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1529 bool aCanBeShaged = true;
1531 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1533 aCanBeShaged = false;
1535 return aCanBeShaged;
1538 //******************************************************
1539 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1541 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1542 int aSelected = aObjects.size();
1543 SessionPtr aMgr = ModelAPI_Session::get();
1544 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1546 bool hasResult = false;
1547 bool hasFeature = false;
1548 bool hasParameter = false;
1549 bool hasCompositeOwner = false;
1550 bool hasResultInHistory = false;
1551 bool hasFolder = false;
1552 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1553 hasCompositeOwner, hasResultInHistory, hasFolder);
1555 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1556 if (aSelected == 1) {
1557 ObjectPtr aObject = aObjects.first();
1559 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1560 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1561 bool isPart = aPart.get() ||
1562 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1564 DocumentPtr aPartDoc;
1566 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1568 if (aPart.get()) // this may be null is Part feature is disabled
1569 aPartDoc = aPart->partDoc();
1571 theMenu->addAction(aActivatePartAction);
1572 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1574 } else if (aObject->document() == aMgr->activeDocument()) {
1575 if (hasParameter || hasFeature) {
1576 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1577 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1578 if (aCurrentOp && aFeature.get()) {
1579 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1580 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1587 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1588 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1589 theMenu->addSeparator();
1592 bool aNotDeactivate = (aCurrentOp == 0);
1593 if (!aNotDeactivate) {
1594 aActivatePartAction->setEnabled(false);
1598 //******************************************************
1599 #define EXPAND_PARENT(OBJ) \
1600 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1601 if (aObjIndex.isValid()) { \
1602 QModelIndex aParent = aObjIndex.parent(); \
1603 int aCount = aDataModel->rowCount(aParent); \
1605 aTreeView->setExpanded(aParent, true); \
1608 //******************************************************
1609 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1611 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1612 SessionPtr aMgr = ModelAPI_Session::get();
1613 if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation
1615 // Do not change activation of parts if an operation active
1616 static QStringList aAllowActivationList;
1617 if (aAllowActivationList.isEmpty())
1618 aAllowActivationList <<
1619 QString(PartSetPlugin_Part::ID().c_str()) <<
1620 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1621 QString(PartSetPlugin_Remove::ID().c_str());
1622 if (myWorkshop->currentOperation() &&
1623 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1625 XGUI_Workshop* aWorkshop = getWorkshop();
1626 bool needUpdate = false;
1627 XGUI_DataTree* aTreeView = 0;
1628 if (aWorkshop->objectBrowser()) {
1629 aTreeView = aWorkshop->objectBrowser()->treeView();
1630 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1631 QPalette aPalet = aLabel->palette();
1633 DocumentPtr aActiveDoc = aMgr->activeDocument();
1635 // Clear active part index if there is no Part documents
1636 // It could be not null if document was closed and opened a new
1637 // without closeDocument call
1638 if (aMgr->allOpenedDocuments().size() <= 1)
1639 myActivePartIndex = QModelIndex();
1641 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1642 QModelIndex aOldActive = myActivePartIndex;
1643 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1644 if (myActivePartIndex.isValid()) {
1645 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1647 aTreeView->setExpanded(myActivePartIndex, true);
1649 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1650 aTreeView->setExpanded(aOldActive, false);
1652 aLabel->setPalette(aPalet);
1654 aWorkshop->updateCommandStatus();
1656 // Update displayed objects in order to update active color
1657 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1658 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1660 foreach(ObjectPtr aObj, aObjects) {
1661 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1662 aObj->isDisabled() || (!aObj->isDisplayed());
1664 aDisplayer->redisplay(aObj, false);
1667 aDisplayer->updateViewer();
1668 // Update tree items if they are expanded
1670 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1672 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1673 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1674 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1675 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1677 ObjectPtr aConstrObj;
1678 ObjectPtr aResultObj;
1679 std::set<ObjectPtr>::const_iterator aIt;
1680 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1681 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1682 ObjectPtr aObject = (*aIt);
1683 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1684 && (aObject->document() != aRootDoc))
1685 aResultObj = aObject;
1686 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1687 && (aObject->document() != aRootDoc))
1688 aConstrObj = aObject;
1689 if (aResultObj.get() && aConstrObj.get())
1693 if (aResultObj.get() || aConstrObj.get()) {
1694 XGUI_Workshop* aWorkshop = getWorkshop();
1695 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1696 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1698 if (aResultObj.get()) {
1699 EXPAND_PARENT(aResultObj)
1701 if (aConstrObj.get()) {
1702 EXPAND_PARENT(aConstrObj)
1706 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1707 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1708 if (aSketch.get()) {
1709 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1710 if (PartSet_SketcherMgr::isSketchOperation(anOperation) &&
1711 mySketchMgr->previewSketchPlane()->isDisplayed())
1712 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1717 //******************************************************
1718 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1720 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1722 SessionPtr aMgr = ModelAPI_Session::get();
1723 if (!theIndex.isValid()) {
1724 // It seems that this code is obsolete
1725 //aMgr->setActiveDocument(aMgr->moduleDocument());
1728 if (theIndex.column() != 1) // Use only first column
1731 XGUI_Workshop* aWorkshop = getWorkshop();
1732 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1733 // De not use non editable Indexes
1734 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1736 ObjectPtr aObj = aDataModel->object(theIndex);
1738 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1739 if (!aPart.get()) { // Probably this is Feature
1740 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1741 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1742 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1745 if (aPart.get()) { // if this is a part
1746 if (aPart->partDoc() == aMgr->activeDocument()) {
1747 myMenuMgr->activatePartSet();
1749 myMenuMgr->activatePart(aPart);
1754 //******************************************************
1755 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1757 // z layer is created for all started operations in order to visualize operation AIS presentation
1759 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1760 if (aContext.IsNull())
1763 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1764 if (myVisualLayerId == 0) {
1765 if (myVisualLayerId == 0)
1766 aViewer->AddZLayer(myVisualLayerId);
1768 TColStd_SequenceOfInteger aZList;
1769 aViewer->GetAllZLayers(aZList);
1770 bool aFound = false;
1771 for (int i = 1; i <= aZList.Length(); i++) {
1772 if (aZList(i) == myVisualLayerId) {
1778 aViewer->AddZLayer(myVisualLayerId);
1780 // if there is an active operation with validated widget,
1781 // the filters of this widget should be activated in the created view
1782 myWorkshop->selectionActivate()->updateSelectionFilters();
1783 myWorkshop->selectionActivate()->updateSelectionModes();
1786 //******************************************************
1787 void PartSet_Module::widgetStateChanged(int thePreviousState)
1789 mySketchMgr->widgetStateChanged(thePreviousState);
1792 //******************************************************
1793 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1795 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1798 //******************************************************
1799 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1801 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1802 mySketchMgr->stopSketch(theOperation);
1806 //******************************************************
1807 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1809 GeomShapePtr aGeomShape;
1811 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1812 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1813 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1818 //******************************************************
1819 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1820 const GeomShapePtr& theGeomShape)
1822 AttributePtr anAttribute;
1823 GeomShapePtr aGeomShape = theGeomShape;
1824 if (!aGeomShape.get()) {
1825 // processing shape of result, e.g. sketch circle center is selected, this is a result
1826 // the geom shape is empty, the shape of result should be used
1827 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1828 if (aResult.get()) {
1829 aGeomShape = aResult->shape();
1833 if (aGeomShape.get()) {
1834 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1835 std::pair<AttributePtr, int> anAttrAndIndex =
1836 PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, mySketchMgr->activeSketch());
1837 return anAttrAndIndex.first;
1842 //******************************************************
1843 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1845 return sketchReentranceMgr()->reentrantMessage();
1848 //******************************************************
1849 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1851 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1854 //******************************************************
1855 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1858 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1862 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1863 if (!aChoiceTitle.isEmpty()) {
1864 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1867 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1869 aPanel->setWindowTitle(aChoiceTitle);
1873 //******************************************************
1874 XGUI_Workshop* PartSet_Module::getWorkshop() const
1876 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1877 return aConnector->workshop();
1880 void PartSet_Module::setDefaultConstraintShown()
1882 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1883 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1884 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1887 //******************************************************
1888 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1893 //******************************************************
1894 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1895 myCustomPrs->disableCustomMode(theMode);
1898 //******************************************************
1899 void PartSet_Module::enableCustomModes() {
1900 myCustomPrs->enableCustomModes();
1903 //******************************************************
1904 void PartSet_Module::onConflictingConstraints()
1906 const std::set<ObjectPtr>& aConstraints = myOverconstraintListener->conflictingObjects();
1907 QObjectPtrList aObjectsList;
1908 std::set<ObjectPtr>::const_iterator aIt;
1909 for (aIt = aConstraints.cbegin(); aIt != aConstraints.cend(); aIt++) {
1910 if (mySketchReentrantMgr->isLastAutoConstraint(*aIt))
1911 aObjectsList.append(*aIt);
1913 if (aObjectsList.size() > 0) {
1914 XGUI_Workshop* aWorkshop = getWorkshop();
1915 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1916 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription);
1917 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
1919 ModuleBase_Operation* anOp = anOpMgr->currentOperation();
1920 if (sketchMgr()->isNestedSketchOperation(anOp))
1923 anOpMgr->startOperation(anOpAction);
1924 aWorkshop->deleteFeatures(aObjectsList);
1925 anOpMgr->commitOperation();
1926 ModuleBase_Tools::flushUpdated(sketchMgr()->activeSketch());