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", "result_body_color", "Result color",
200 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
202 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
203 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
205 Config_PropManager::registerProp("Visualization", ModelAPI_ResultConstruction::RESULT_COLOR_NAME(),
206 "Construction color", Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
208 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
209 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
211 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
212 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
214 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
215 "Reference shape wireframe color in operation", Config_Prop::Color,
216 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
217 Config_PropManager::registerProp("Visualization", "operation_result_color",
218 "Result shape wireframe color in operation", Config_Prop::Color,
219 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
220 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
221 "Multi selector item color in operation", Config_Prop::Color,
222 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
223 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
224 "Color of removed feature in operation", Config_Prop::Color,
225 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
226 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
227 "Color of sketch plane", Config_Prop::Color,
228 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
230 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
231 "Hidden faces transparency",
232 Config_Prop::DblSpin,
235 std::ostringstream aStream;
236 aStream << SketcherPrs_Tools::getDefaultArrowSize();
237 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
238 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
240 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
241 Config_Prop::String, "Times-bold");
245 aStream << SketcherPrs_Tools::getDefaultTextHeight();
246 Config_PropManager::registerProp("Visualization", "dimension_value_size",
247 "Dimension value size", Config_Prop::IntSpin, aStream.str());
249 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
251 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
253 Config_PropManager::registerProp("Visualization", "feature_objectbrowser_color",
254 "Feature items in Object Browser",
255 Config_Prop::Color, FEATURE_ITEM_COLOR);
257 Config_PropManager::registerProp("Visualization", "zoom_trihedron_arrows",
258 "Keep trihedron arrows view size constant", Config_Prop::Boolean, "false");
260 Config_PropManager::registerProp("Visualization", "axis_arrow_size",
261 "Trihedron arrows constant size", Config_Prop::IntSpin, "10");
263 Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
264 "Add parameter in parameters manager dialog",
265 Config_Prop::Shortcut, "Ctrl+A");
267 Config_PropManager::registerProp("Windows", "use_hide_faces_panel",
268 "Use HideFaces panel in operations", Config_Prop::Boolean, "false");
271 //******************************************************
272 PartSet_Module::~PartSet_Module()
275 delete myOverconstraintListener;
279 //******************************************************
280 void PartSet_Module::createFeatures()
282 ModuleBase_IModule::createFeatures();
283 myRoot = new PartSet_RootNode();
284 myRoot->setWorkshop(workshop());
288 //******************************************************
289 void PartSet_Module::storeSelection()
291 // cash is used only to restore selection, so it should be filled in storeSelection and
292 // after applying immediatelly cleared in restoreSelection
293 myCurrentSelection.clear();
294 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
297 //******************************************************
298 void PartSet_Module::restoreSelection()
300 // cash is used only to restore selection, so it should be filled in storeSelection and
301 // after applying immediatelly cleared in restoreSelection
302 sketchMgr()->restoreSelection(myCurrentSelection);
303 myCurrentSelection.clear();
306 //******************************************************
307 void PartSet_Module::registerValidators()
309 //Registering of validators
310 SessionPtr aMgr = ModelAPI_Session::get();
311 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
312 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
313 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
314 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
315 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
316 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
317 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
318 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
319 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
320 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
321 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
322 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
323 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
324 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
325 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
326 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
327 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
328 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
329 aFactory->registerValidator("PartSet_MultyTranslationSelection",
330 new PartSet_MultyTranslationSelection);
331 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
332 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
333 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
336 //******************************************************
337 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
338 const bool isToConnect)
340 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
343 //******************************************************
344 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
346 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
347 mySketchMgr->commitNestedSketch(theOperation);
349 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
350 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
351 overconstraintListener()->setActive(false);
353 /// Restart sketcher operations automatically
354 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
355 getWorkshop()->selector()->clearSelection();
359 //******************************************************
360 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
362 /// Restart sketcher operations automatically
363 mySketchReentrantMgr->operationAborted(theOperation);
364 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
365 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
366 overconstraintListener()->setActive(false);
368 getWorkshop()->selector()->clearSelection();
371 //******************************************************
372 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
374 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
377 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
378 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
380 ModuleBase_ModelWidget* aFilledWidget = 0;
381 bool aPostonedWidgetActivation = false;
383 FeaturePtr aFeature = aFOperation->feature();
384 /// Restart sketcher operations automatically
385 /// it is important to call method of sketch reentrant manager before filling of PP
386 /// because it fills some created feature attributes, these new values should be used
387 /// to fill the property panel
388 mySketchReentrantMgr->operationStarted(theOperation);
390 aWorkshop->fillPropertyPanel(aFOperation);
391 // filling the operation values by the current selection
392 // if the operation can be committed after the controls filling, the method perform should
393 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
394 bool isOperationCommitted = false;
395 if (!aFOperation->isEditOperation()) {
396 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
397 // if there is a greed attribute, automatic commit by preselection
398 // for this feature is prohibited
399 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
400 if (currentOperation() != aFOperation)
401 isOperationCommitted = true;
403 if (aGreedAttributeId.empty()) {
404 // a signal should be emitted before the next widget activation
405 // because, the activation of the next widget will give a focus to the widget.
406 // As a result the value of the widget is initialized.
407 // And commit may happens until the value is entered.
409 if (mySketchReentrantMgr->canBeCommittedByPreselection())
410 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
411 // activate the next obligatory widget
412 if (!isOperationCommitted)
413 aPropertyPanel->activateNextWidget(aFilledWidget);
416 else { // there is a greed widget
417 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
418 std::string aFirstAttributeId = aWidgets.front()->attributeID();
419 // activate next widget after greeded if it is the first widget in the panel
420 // else the first panel widget is already activated by operation start
421 if (aFirstAttributeId == aGreedAttributeId)
422 aPostonedWidgetActivation = true;
425 } if (!isOperationCommitted) {
426 aWorkshop->connectToPropertyPanel(true);
427 updateSketcherOnStart(aFOperation);
428 updatePresentationsOnStart(aFOperation);
430 // the objects of the current operation should be deactivated
431 QObjectPtrList anObjects;
432 anObjects.append(aFeature);
433 std::list<ResultPtr> aResults;
434 ModelAPI_Tools::allResults(aFeature, aResults);
435 std::list<ResultPtr>::const_iterator aIt;
436 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
437 anObjects.append(*aIt);
439 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
440 for (; anIt != aLast; anIt++)
441 aWorkshop->deactivateActiveObject(*anIt, false);
442 if (anObjects.size() > 0) {
443 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
444 aDisplayer->updateViewer();
446 /// state of command actions should be updated after displayed objects modification because
447 /// deactivation(for example) of objects may influence on selection in the viewer
448 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
449 workshop()->updateCommandStatus();
451 if (aPostonedWidgetActivation) {
452 // if the widget is an empty in the chain of activated widgets, the current operation
453 // is restarted. It should be performed after functionality of the operation starting
454 aPropertyPanel->activateNextWidget(aFilledWidget);
459 //******************************************************
460 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
462 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
463 mySketchMgr->startSketch(theOperation);
465 // It is switched off because of
466 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
467 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
468 mySketchMgr->startNestedSketch(theOperation);
472 //******************************************************
473 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
475 ModuleBase_OperationFeature* aFOperation =
476 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
478 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
479 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
483 //******************************************************
484 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
486 ModuleBase_IModule::operationResumed(theOperation);
488 ModuleBase_OperationFeature* aFOperation =
489 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
491 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
492 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
496 //******************************************************
497 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
499 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
500 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
501 bool isModified = isModifiedArgs || isModifiedResults;
503 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
504 mySketchMgr->stopNestedSketch(theOperation);
506 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
507 setDefaultConstraintShown();
509 //VSV: Viewer is updated on feature update and redisplay
511 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
512 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
513 aDisplayer->updateViewer();
516 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
517 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
518 for (; anIt != aLast; anIt++) {
519 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
523 //******************************************************
524 ModuleBase_Operation* PartSet_Module::currentOperation() const
526 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
527 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
528 return anOpMgr->currentOperation();
531 //******************************************************
532 bool PartSet_Module::canUndo() const
534 bool aCanUndo = false;
535 SessionPtr aMgr = ModelAPI_Session::get();
536 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
537 aCanUndo = !aMgr->isOperation();
538 if (!aCanUndo) // check the enable state additionally by sketch manager
539 aCanUndo = aMgr->canUndo();
544 //******************************************************
545 bool PartSet_Module::canRedo() const
547 bool aCanRedo = false;
548 SessionPtr aMgr = ModelAPI_Session::get();
549 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
550 aCanRedo = !aMgr->isOperation();
551 if (!aCanRedo) // check the enable state additionally by sketch manager
552 aCanRedo = aMgr->canRedo();
557 //******************************************************
558 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
561 if (theActionId == "MOVE_CMD" || theActionId == "MOVE_SPLIT_CMD") {
562 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
564 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
565 // part features can not be moved in the history.
566 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
573 //******************************************************
574 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
576 // the sketch manager put the restriction to the objects erase
577 return mySketchMgr->canEraseObject(theObject);
580 //******************************************************
581 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
583 // the sketch manager put the restriction to the objects display
584 return mySketchMgr->canDisplayObject(theObject);
587 //******************************************************
588 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
589 const QString& theStartedOperationKind)
591 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
594 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
597 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
599 mySketchMgr->processHiddenObject(theObjects);
602 //******************************************************
603 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
605 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
607 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
608 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
609 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
610 if (isSketchOp || isNestedOp) {
611 // in active sketch operation it is possible to activate operation object in selection
612 // in the edit operation, e.g. points of the line can be moved when the line is edited
613 ModuleBase_OperationFeature* aFOperation =
614 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
615 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
620 //******************************************************
621 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
623 QMap<int, QAction*>& theMenuActions) const
625 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
628 //******************************************************
629 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
631 myMenuMgr->updateViewerMenu(theStdActions);
634 //******************************************************
635 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
637 bool isEnabledFixed = false;
638 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
639 mySketchReentrantMgr->isInternalEditActive())
640 isEnabledFixed = true;
641 return isEnabledFixed;
644 //******************************************************
645 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
647 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
648 if (anError.isEmpty())
649 anError = sketchMgr()->getFeatureError(theFeature);
654 //******************************************************
655 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
656 QStringList& theIds) const
658 myMenuMgr->grantedOperationIds(theOperation, theIds);
660 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
661 XGUI_Workshop* aWorkshop = getWorkshop();
662 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
666 //******************************************************
667 void PartSet_Module::activeSelectionModes(QIntList& theModes)
669 if (mySketchMgr->activeSketch().get())
670 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
672 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
675 //******************************************************
676 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
678 customSubShapesSelectionModes(theModes);
679 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
680 //myWorkshop->module()->activeSelectionModes(theModes);
683 //******************************************************
684 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
685 SelectMgr_ListOfFilter& theSelectionFilters)
687 bool isSketchActive = mySketchMgr->activeSketch().get();
689 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
690 mySelectionFilters.begin();
691 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
692 int aFilterType = aFiltersIt->first;
693 // do not add not participating filters in given parameters
694 if (!theFilterTypes.contains(aFilterType))
697 // using sketch filters only if sketch operation is active
698 if (!isSketchActive &&
699 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
702 // using filtering of construction results only from faces panel
703 if (aFilterType == SF_ResultGroupNameFilter)
706 theSelectionFilters.Append(aFiltersIt->second);
710 //******************************************************
711 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
713 if (theModes.contains(TopAbs_FACE))
714 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
715 if (theModes.contains(TopAbs_WIRE))
716 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
718 if (mySketchMgr->activeSketch().get())
719 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
722 //******************************************************
723 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
724 ObjectPtr& theObject, AttributePtr& theAttribute)
726 ObjectPtr anObject = theSelected->object();
727 GeomShapePtr aShape = theSelected->shape();
729 theAttribute = findAttribute(anObject, aShape);
730 // TODO: try to create result if object is an external object
731 theObject = anObject;
734 //******************************************************
735 bool PartSet_Module::isMouseOverWindow()
737 return mySketchMgr->isMouseOverWindow();
740 //******************************************************
741 bool PartSet_Module::isSketchNeutralPointActivated() const
743 bool isNeutralPoint = true;
744 if (sketchReentranceMgr()->isInternalEditActive())
745 isNeutralPoint = false;
746 if (myIsOperationIsLaunched)
747 isNeutralPoint = false;
749 return isNeutralPoint;
752 //******************************************************
753 void PartSet_Module::closeDocument()
755 myActivePartIndex = QModelIndex();
756 SketcherPrs_PositionMgr::get()->clearAll();
759 //******************************************************
760 void PartSet_Module::clearViewer()
762 myCustomPrs->clearPrs();
764 XGUI_Workshop* aWorkshop = getWorkshop();
765 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
766 aDisplayer->deactivateSelectionFilters(false);
769 //******************************************************
770 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
772 ModuleBase_OperationFeature* aFOperation =
773 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
777 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
778 // we have to manually activate the sketch label in edit mode
779 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
780 aPanel->activateWidget(aPanel->modelWidgets().first());
783 //******************************************************
784 bool PartSet_Module::createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
785 QList<ModuleBase_ModelWidget*>& theWidgets) const
787 bool aProcessed = false;
789 XGUI_Workshop* aWorkshop = getWorkshop();
790 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
791 if (mySketchMgr->activeSketch().get() && aPropertyPanel) {
792 ModuleBase_ISelection* aSelection = workshop()->selection();
793 // click on a point in sketch leads here with the point is highlighted, not yet selected
794 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
795 if (aPreselection.size() == 1) {
796 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
797 ObjectPtr anObject = aSelectedPrs->object();
799 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
800 GeomShapePtr aShape = aSelectedPrs->shape();
801 // click on the digit of dimension constrain comes here
802 // with an empty shape, so we need the check
803 if (aFeature == theFeature && aShape.get() && !aShape->isNull()) {
804 // if feature has only one result and shape of result is equal to selected shape
805 // this attribute is not processed. It is a case of Sketch Point.
806 if (aFeature->results().size() == 1) {
807 ResultPtr aResult = aFeature->results().front();
808 if (aResult.get() && aResult->shape()->isEqual(aShape))
811 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
812 std::pair<AttributePtr, int> anAttribute =
813 PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape, mySketchMgr->activeSketch());
814 if (anAttribute.first.get()) {
815 ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
817 const std::string anAttributeId = anAttribute.first->id();
818 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
820 theWidgets = aFactory.getModelWidgets();
821 // it is possible that the point does not present in XML definition,
822 // in this case, we assume that it is not processed by this module
823 // e.g. "Intersection point" feature
824 aProcessed = !theWidgets.isEmpty();
832 //******************************************************
833 void PartSet_Module::onSelectionChanged()
835 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
839 bool isSketcherOp = false;
840 // An edit operation is enable only if the current opeation is the sketch operation
841 if (mySketchMgr->activeSketch()) {
842 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
843 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
846 // Editing of constraints can be done on selection
847 ModuleBase_ISelection* aSelect = myWorkshop->selection();
848 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
849 if (aSelected.size() == 1) {
850 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
851 ObjectPtr aObject = aPrs->object();
852 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
854 std::string aId = aFeature->getKind();
855 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
856 (aId == SketchPlugin_ConstraintLength::ID()) ||
857 (aId == SketchPlugin_ConstraintDistance::ID()) ||
858 (aId == SketchPlugin_ConstraintAngle::ID())) {
859 editFeature(aFeature);
866 //******************************************************
867 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
869 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
870 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
871 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
874 //******************************************************
875 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
877 Config_WidgetAPI* theWidgetApi)
879 ModuleBase_IWorkshop* aWorkshop = workshop();
880 ModuleBase_ModelWidget* aWgt = NULL;
881 if (theType == "sketch-start-label") {
882 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
883 theWidgetApi, myHasConstraintShown);
884 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
885 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
886 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
887 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
888 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
889 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
890 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
891 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
893 } else if (theType == "sketch-2dpoint_selector") {
894 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
896 aPointWgt->setSketch(mySketchMgr->activeSketch());
897 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
899 }else if (theType == "sketch-2dpoint_flyout_selector") {
900 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
902 aPointWgt->setSketch(mySketchMgr->activeSketch());
903 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
905 } else if (theType == "sketch_shape_selector") {
906 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
907 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
908 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
909 aWgt = aShapeSelectorWgt;
910 } else if (theType == "sketch_multi_selector") {
911 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
912 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
913 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
914 aWgt = aShapeSelectorWgt;
916 else if (theType == "sketch_feature_point_selector") {
917 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
918 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
919 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
920 aWgt = aPointSelectorWgt;
922 else if (theType == "sketch-bspline_selector") {
923 PartSet_WidgetBSplinePoints* aBSplineWgt =
924 new PartSet_WidgetBSplinePoints(theParent, aWorkshop, theWidgetApi);
925 aBSplineWgt->setSketch(mySketchMgr->activeSketch());
928 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
929 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
930 } else if (theType == "export_file_selector") {
931 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
932 } else if (theType == "sketch_launcher") {
933 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
935 else if (theType == "module_choice") {
936 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
937 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
938 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
939 } else if (theType == "bspline-panel") {
940 PartSet_BSplineWidget* aPanel = new PartSet_BSplineWidget(theParent, theWidgetApi);
941 //aPanel->setFeature(theFeature);
947 //******************************************************
948 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
950 ModuleBase_ModelWidget* anActiveWidget = 0;
952 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
954 return anActiveWidget;
956 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
958 return anActiveWidget;
960 return aPanel->activeWidget(true);
963 //******************************************************
964 bool PartSet_Module::deleteObjects()
966 bool isProcessed = false;
968 XGUI_Workshop* aWorkshop = getWorkshop();
969 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
971 //SessionPtr aMgr = ModelAPI_Session::get();
972 // 1. check whether the delete should be processed in the module
973 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
974 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
975 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
976 if (isSketchOp || isNestedOp) {
978 // 2. find selected presentations
979 // selected objects should be collected before the current operation abort because
980 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
981 ModuleBase_ISelection* aSel = workshop()->selection();
982 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
983 // if there are no selected objects in the viewer, that means that the selection in another
984 // place cased this method. It is necessary to return the false value to understande in above
985 // method that delete is not processed
986 if (aSelectedObj.count() == 0)
989 // avoid delete of the objects, which are not belong to the current sketch
990 // in order to do not delete results of other sketches
991 QObjectPtrList aSketchObjects;
992 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
993 for ( ; anIt != aLast; anIt++) {
994 ObjectPtr anObject = *anIt;
995 if (mySketchMgr->isObjectOfSketch(anObject)) {
996 // sketch feature should be used in this list because workshop deletes features only
997 // results are skipped
998 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
999 aSketchObjects.append(aSketchFeature);
1002 // if the selection contains only local selected presentations from other sketches,
1003 // the Delete operation should not be done at all
1004 if (aSketchObjects.size() == 0)
1007 // 3. start operation
1008 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1009 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, this);
1011 // the active nested sketch operation should be aborted unconditionally
1012 // the Delete action should be additionally granted for the Sketch operation
1013 // in order to do not abort/commit it
1015 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1016 return true; // the objects are processed but can not be deleted
1018 anOpMgr->startOperation(anOpAction);
1020 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1021 // the problem is in AIS Dimensions recompute
1022 // if a line and the dim are removed, line is the first
1023 // it causes the AIS recompute, where the base line is null,
1024 // the result is empty AIS in the viewer
1025 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1027 // 4. delete features
1028 // sketch feature should be skipped, only sub-features can be removed
1029 // when sketch operation is active
1030 aWorkshop->deleteFeatures(aSketchObjects);
1031 // 5. stop operation
1032 anOpMgr->commitOperation();
1037 //******************************************************
1038 void PartSet_Module::editFeature(FeaturePtr theFeature)
1040 storeConstraintsState(theFeature->getKind());
1041 ModuleBase_IModule::editFeature(theFeature);
1044 //******************************************************
1045 bool PartSet_Module::canCommitOperation() const
1050 //******************************************************
1051 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1053 myIsOperationIsLaunched = true;
1054 storeConstraintsState(theCmdId.toStdString());
1055 updateConstraintsState(theCmdId.toStdString());
1057 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1059 myIsOperationIsLaunched = false;
1062 //******************************************************
1063 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1065 if (myWorkshop->currentOperation() &&
1066 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1067 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1068 mySketchMgr->showConstraintStates();
1069 myHasConstraintShown = aShownStates;
1073 //******************************************************
1074 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1076 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1077 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1078 // Show constraints if a constraint was anOperation
1079 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1080 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1081 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1082 myHasConstraintShown[PartSet_Tools::Expressions]);
1086 //******************************************************
1087 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1089 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1090 if (!anAIS.IsNull()) {
1091 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1092 if (aFeature.get()) {
1093 bool aToUseZLayer = false;
1094 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1095 aToUseZLayer = true;
1097 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1098 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1101 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1102 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1103 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1105 aCtx->SetZLayer(anAIS, myVisualLayerId);
1111 //******************************************************
1112 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1115 // it should be recomputed in order to disappear in the viewer if the corresponded object
1117 //if (myCustomPrs->isActive())
1118 // myCustomPrs->redisplay(theObject, false);
1121 //******************************************************
1122 void PartSet_Module::onViewTransformed(int theTrsfType)
1124 // Set length of arrows constant in pixel size
1125 // if the operation is panning or rotate or panglobal then do nothing
1126 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1128 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1129 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1130 if (aContext.IsNull())
1133 //Handle(V3d_View) aView = aViewer->activeView();
1135 XGUI_Workshop* aWorkshop = getWorkshop();
1136 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1137 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1138 Handle(V3d_View) aView;
1140 for (aV3dViewer->InitDefinedViews();
1141 aV3dViewer->MoreDefinedViews();
1142 aV3dViewer->NextDefinedViews()) {
1143 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1144 double aS = aV->Scale();
1153 bool isModified = false;
1154 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1155 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1156 if (aCurrentOperation &&
1157 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1158 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1159 (aCurrentOperation->id() == "Measurement")))
1161 SketcherPrs_Tools::setArrowSize(aLen);
1162 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1163 aViewer->SetScale(aViewer->activeView(), aCurScale);
1165 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1166 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1168 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1169 foreach(AISObjectPtr aAIS, aPrsList) {
1170 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1172 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
1173 if (!aDim.IsNull()) {
1174 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1175 aContext->Redisplay(aDim, false);
1181 // Manage trihedron arrows
1182 if (Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows")) {
1183 Handle(AIS_Trihedron) aTrihedron = aViewer->trihedron();
1184 if (!aTrihedron.IsNull()) {
1186 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1187 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1188 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1189 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1190 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1191 aContext->Redisplay(aTrihedron, false);
1196 aDisplayer->updateViewer();
1199 //******************************************************
1200 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1202 return myCustomPrs->isActive(theFlag);
1205 //******************************************************
1206 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1207 const ModuleBase_CustomizeFlag& theFlag,
1208 const bool theUpdateViewer)
1210 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1213 //******************************************************
1214 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1215 const bool theUpdateViewer)
1217 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1220 //******************************************************
1221 //bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1222 // std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1224 // bool aCustomized = false;
1226 // XGUI_Workshop* aWorkshop = getWorkshop();
1227 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1228 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1230 // return aCustomized;
1232 // if (!theResult.get()) {
1233 // std::vector<int> aColor;
1234 // XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1235 // if (!aColor.empty()) {
1236 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1239 // // customize dimentional constrains
1240 // sketchMgr()->customisePresentation(anObject);
1242 // return aCustomized;
1245 ////******************************************************
1246 //bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1247 // AISObjectPtr thePrs,
1248 // GeomCustomPrsPtr theCustomPrs)
1250 // bool aCustomized = false;
1252 // XGUI_Workshop* aWorkshop = getWorkshop();
1253 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1254 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1256 // return aCustomized;
1258 // std::vector<int> aColor;
1259 // bool aUseCustomColor = true;
1260 // if (aUseCustomColor)
1261 // myOverconstraintListener->getCustomColor(anObject, aColor);
1262 // // customize sketch symbol presentation
1263 // Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1264 // if (!anAISIO.IsNull()) {
1265 // if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1266 // Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1267 // if (!aPrs.IsNull()) {
1268 // aPrs->SetCustomColor(aColor);
1269 // aCustomized = true;
1271 // } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1272 // Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1273 // if (!aPrs.IsNull()) {
1274 // aPrs->SetCustomColor(aColor);
1275 // aCustomized = true;
1279 // // customize sketch dimension constraint presentation
1280 // if (!aCustomized) {
1281 // if (!aColor.empty()) { // otherwise presentation has the default color
1282 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1285 // return aCustomized;
1288 //******************************************************
1289 bool PartSet_Module::customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1290 const bool theUpdateViewer)
1292 bool isRedisplayed = false;
1293 if (myCustomPrs->isActive(theFlag))
1294 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1296 return isRedisplayed;
1299 //******************************************************
1300 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1302 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1304 QLabel* aLabel = aOB->activeDocLabel();
1305 aLabel->installEventFilter(myMenuMgr);
1306 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1307 SLOT(onActiveDocPopup(const QPoint&)));
1308 aOB->treeView()->setExpandsOnDoubleClick(false);
1309 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1310 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1312 Events_Loop* aLoop = Events_Loop::loop();
1313 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1317 //******************************************************
1318 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1320 SessionPtr aMgr = ModelAPI_Session::get();
1321 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1323 XGUI_Workshop* aWorkshop = getWorkshop();
1324 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1326 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1329 aMenu.addAction(aActivatePartAction);
1332 if (aMgr->activeDocument() == aMgr->moduleDocument()) {
1333 DocumentPtr aDoc = aMgr->moduleDocument();
1334 int aNbParts = aDoc->size(ModelAPI_ResultPart::group());
1335 bool aHaveToActivate = false;
1336 for (int i = 0; i < aNbParts; i++) {
1337 ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i);
1338 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1339 if (!aPartRes->partDoc().get()) {
1340 aHaveToActivate = true;
1344 if (aHaveToActivate) {
1345 QAction* aActivateAllPartAction = myMenuMgr->action("ACTIVATE_ALL_PARTS_CMD");
1346 aMenu.addAction(aActivateAllPartAction);
1351 aMenu.exec(aHeader->mapToGlobal(thePnt));
1354 //******************************************************
1355 AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject)
1357 Handle(AIS_InteractiveObject) anAISPrs = mySketchMgr->createPresentation(theObject);
1358 if (anAISPrs.IsNull()) {
1359 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1360 if (aResult.get()) {
1361 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
1362 if (aShapePtr.get() != NULL)
1363 anAISPrs = new ModuleBase_ResultPrs(aResult);
1366 FieldStepPtr aStep =
1367 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1369 anAISPrs = new PartSet_FieldStepPrs(aStep);
1374 if (!anAISPrs.IsNull()) {
1375 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
1376 if (!aShapePrs.IsNull())
1377 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
1379 anAIS = AISObjectPtr(new GeomAPI_AISObject());
1380 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
1381 customizePresentation(theObject, anAIS);
1386 //******************************************************
1387 double getResultDeflection(const ResultPtr& theResult)
1389 double aDeflection = ModelAPI_Tools::getDeflection(theResult);
1390 if (aDeflection < 0)
1391 aDeflection = PartSet_Tools::getDefaultDeflection(theResult);
1395 //******************************************************
1396 double getResultTransparency(const ResultPtr& theResult)
1398 double aTransparency = ModelAPI_Tools::getTransparency(theResult);
1399 if (aTransparency < 0)
1400 aTransparency = PartSet_Tools::getDefaultTransparency();
1401 return aTransparency;
1404 //******************************************************
1405 void PartSet_Module::setTexture(const std::string & theTextureFile, const AISObjectPtr& thePrs)
1407 Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
1408 if (!anAIS.IsNull())
1410 /// set color to white and change material aspect,
1411 /// in order to keep a natural apect of the image.
1412 thePrs->setColor(255, 255, 255);
1413 Quantity_Color myShadingColor(NCollection_Vec3<float>(1., 1., 1.));
1414 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
1415 if (!anAISShape.IsNull())
1417 auto myDrawer = anAISShape->Attributes();
1419 myDrawer->ShadingAspect()->SetColor(myShadingColor);
1420 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
1421 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
1422 aMatAspect.SetTransparency(0.0);
1423 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
1424 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
1426 Handle(Image_PixMap) aPixmap;
1427 QPixmap px(theTextureFile.c_str());
1430 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
1432 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
1433 (new Graphic3d_Texture2Dmanual(aPixmap));
1434 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
1436 anAISShape->SetDisplayMode(AIS_Shaded);
1441 //******************************************************
1442 void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
1443 const AISObjectPtr& thePrs) const
1445 if (mySketchMgr->isObjectOfSketch(theObject)) {
1446 mySketchMgr->customizeSketchPresentation(theObject, thePrs);
1449 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1450 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1451 if (aResult.get()) {
1452 std::vector<int> aColor;
1453 bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document());
1454 // Get user defined color for the object
1455 ModelAPI_Tools::getColor(aResult, aColor);
1457 bool isCustomized = false;
1458 if (aColor.empty() && aFeature.get()) {
1459 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1460 if (aCustPrs.get()) {
1461 isCustomized = aCustPrs->customisePresentation(aResult, thePrs);
1464 if (!isCustomized) {
1465 if (aColor.empty()) {
1466 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1468 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1472 if (aColor.empty()) {
1473 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1475 QColor aQColor(aColor[0], aColor[1], aColor[2]);
1477 QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
1478 thePrs->setColor(aNewColor.red(), aNewColor.green(), aNewColor.blue());
1480 thePrs->setDeflection(getResultDeflection(aResult));
1481 thePrs->setTransparency(getResultTransparency(aResult));
1483 /// set texture parameters
1484 if(aResult->hasTextureFile()) {
1485 setTexture(aResult->getTextureFile(), thePrs);
1488 if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
1489 thePrs->setWidth(2);
1495 //******************************************************
1496 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1499 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1501 /// If last line finished on vertex the lines creation sequence has to be break
1502 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1504 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1505 // if there is an active widget, find the presented object in it
1506 if (!anActiveWidget)
1507 anActiveWidget = aPanel->preselectionWidget();
1509 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1511 if (aWidgetValidated)
1512 anObject = aWidgetValidated->findPresentedObject(theAIS);
1518 //******************************************************
1519 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1521 bool aCanBeShaged = true;
1523 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1525 aCanBeShaged = false;
1527 return aCanBeShaged;
1530 //******************************************************
1531 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1533 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1534 int aSelected = aObjects.size();
1535 SessionPtr aMgr = ModelAPI_Session::get();
1536 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1538 bool hasResult = false;
1539 bool hasFeature = false;
1540 bool hasParameter = false;
1541 bool hasCompositeOwner = false;
1542 bool hasResultInHistory = false;
1543 bool hasFolder = false;
1544 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1545 hasCompositeOwner, hasResultInHistory, hasFolder);
1547 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1548 if (aSelected == 1) {
1549 ObjectPtr aObject = aObjects.first();
1551 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1552 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1553 bool isPart = aPart.get() ||
1554 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1556 DocumentPtr aPartDoc;
1558 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1560 if (aPart.get()) // this may be null is Part feature is disabled
1561 aPartDoc = aPart->partDoc();
1563 theMenu->addAction(aActivatePartAction);
1564 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1566 } else if (aObject->document() == aMgr->activeDocument()) {
1567 if (hasParameter || hasFeature) {
1568 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1569 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1570 if (aCurrentOp && aFeature.get()) {
1571 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1572 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1579 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1580 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1581 theMenu->addSeparator();
1584 bool aNotDeactivate = (aCurrentOp == 0);
1585 if (!aNotDeactivate) {
1586 aActivatePartAction->setEnabled(false);
1590 //******************************************************
1591 #define EXPAND_PARENT(OBJ) \
1592 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1593 if (aObjIndex.isValid()) { \
1594 QModelIndex aParent = aObjIndex.parent(); \
1595 int aCount = aDataModel->rowCount(aParent); \
1597 aTreeView->setExpanded(aParent, true); \
1600 //******************************************************
1601 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1603 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1604 SessionPtr aMgr = ModelAPI_Session::get();
1605 if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation
1607 // Do not change activation of parts if an operation active
1608 static QStringList aAllowActivationList;
1609 if (aAllowActivationList.isEmpty())
1610 aAllowActivationList <<
1611 QString(PartSetPlugin_Part::ID().c_str()) <<
1612 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1613 QString(PartSetPlugin_Remove::ID().c_str());
1614 if (myWorkshop->currentOperation() &&
1615 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1617 XGUI_Workshop* aWorkshop = getWorkshop();
1618 bool needUpdate = false;
1619 XGUI_DataTree* aTreeView = 0;
1620 if (aWorkshop->objectBrowser()) {
1621 aTreeView = aWorkshop->objectBrowser()->treeView();
1622 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1623 QPalette aPalet = aLabel->palette();
1625 DocumentPtr aActiveDoc = aMgr->activeDocument();
1627 // Clear active part index if there is no Part documents
1628 // It could be not null if document was closed and opened a new
1629 // without closeDocument call
1630 if (aMgr->allOpenedDocuments().size() <= 1)
1631 myActivePartIndex = QModelIndex();
1633 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1634 QModelIndex aOldActive = myActivePartIndex;
1635 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1636 if (myActivePartIndex.isValid()) {
1637 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1639 aTreeView->setExpanded(myActivePartIndex, true);
1641 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1642 aTreeView->setExpanded(aOldActive, false);
1644 aLabel->setPalette(aPalet);
1646 aWorkshop->updateCommandStatus();
1648 // Update displayed objects in order to update active color
1649 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1650 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1652 foreach(ObjectPtr aObj, aObjects) {
1653 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1654 aObj->isDisabled() || (!aObj->isDisplayed());
1656 aDisplayer->redisplay(aObj, false);
1659 aDisplayer->updateViewer();
1660 // Update tree items if they are expanded
1662 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1664 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1665 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1666 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1667 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1669 ObjectPtr aConstrObj;
1670 ObjectPtr aResultObj;
1671 std::set<ObjectPtr>::const_iterator aIt;
1672 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1673 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1674 ObjectPtr aObject = (*aIt);
1675 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1676 && (aObject->document() != aRootDoc))
1677 aResultObj = aObject;
1678 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1679 && (aObject->document() != aRootDoc))
1680 aConstrObj = aObject;
1681 if (aResultObj.get() && aConstrObj.get())
1685 if (aResultObj.get() || aConstrObj.get()) {
1686 XGUI_Workshop* aWorkshop = getWorkshop();
1687 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1688 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1690 if (aResultObj.get()) {
1691 EXPAND_PARENT(aResultObj)
1693 if (aConstrObj.get()) {
1694 EXPAND_PARENT(aConstrObj)
1698 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1699 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1700 if (aSketch.get()) {
1701 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1702 if (PartSet_SketcherMgr::isSketchOperation(anOperation) &&
1703 mySketchMgr->previewSketchPlane()->isDisplayed())
1704 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1709 //******************************************************
1710 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1712 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1714 SessionPtr aMgr = ModelAPI_Session::get();
1715 if (!theIndex.isValid()) {
1716 // It seems that this code is obsolete
1717 //aMgr->setActiveDocument(aMgr->moduleDocument());
1720 if (theIndex.column() != 1) // Use only first column
1723 XGUI_Workshop* aWorkshop = getWorkshop();
1724 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1725 // De not use non editable Indexes
1726 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1728 ObjectPtr aObj = aDataModel->object(theIndex);
1730 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1731 if (!aPart.get()) { // Probably this is Feature
1732 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1733 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1734 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1737 if (aPart.get()) { // if this is a part
1738 if (aPart->partDoc() == aMgr->activeDocument()) {
1739 myMenuMgr->activatePartSet();
1741 myMenuMgr->activatePart(aPart);
1746 //******************************************************
1747 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1749 // z layer is created for all started operations in order to visualize operation AIS presentation
1751 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1752 if (aContext.IsNull())
1755 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1756 if (myVisualLayerId == 0) {
1757 if (myVisualLayerId == 0)
1758 aViewer->AddZLayer(myVisualLayerId);
1760 TColStd_SequenceOfInteger aZList;
1761 aViewer->GetAllZLayers(aZList);
1762 bool aFound = false;
1763 for (int i = 1; i <= aZList.Length(); i++) {
1764 if (aZList(i) == myVisualLayerId) {
1770 aViewer->AddZLayer(myVisualLayerId);
1772 // if there is an active operation with validated widget,
1773 // the filters of this widget should be activated in the created view
1774 myWorkshop->selectionActivate()->updateSelectionFilters();
1775 myWorkshop->selectionActivate()->updateSelectionModes();
1778 //******************************************************
1779 void PartSet_Module::widgetStateChanged(int thePreviousState)
1781 mySketchMgr->widgetStateChanged(thePreviousState);
1784 //******************************************************
1785 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1787 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1790 //******************************************************
1791 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1793 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1794 mySketchMgr->stopSketch(theOperation);
1798 //******************************************************
1799 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1801 GeomShapePtr aGeomShape;
1803 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1804 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1805 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1810 //******************************************************
1811 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1812 const GeomShapePtr& theGeomShape)
1814 AttributePtr anAttribute;
1815 GeomShapePtr aGeomShape = theGeomShape;
1816 if (!aGeomShape.get()) {
1817 // processing shape of result, e.g. sketch circle center is selected, this is a result
1818 // the geom shape is empty, the shape of result should be used
1819 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1820 if (aResult.get()) {
1821 aGeomShape = aResult->shape();
1825 if (aGeomShape.get()) {
1826 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1827 std::pair<AttributePtr, int> anAttrAndIndex =
1828 PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, mySketchMgr->activeSketch());
1829 return anAttrAndIndex.first;
1834 //******************************************************
1835 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1837 return sketchReentranceMgr()->reentrantMessage();
1840 //******************************************************
1841 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1843 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1846 //******************************************************
1847 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1850 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1854 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1855 if (!aChoiceTitle.isEmpty()) {
1856 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1859 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1861 aPanel->setWindowTitle(aChoiceTitle);
1865 //******************************************************
1866 XGUI_Workshop* PartSet_Module::getWorkshop() const
1868 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1869 return aConnector->workshop();
1872 void PartSet_Module::setDefaultConstraintShown()
1874 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1875 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1876 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1879 //******************************************************
1880 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1885 //******************************************************
1886 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1887 myCustomPrs->disableCustomMode(theMode);
1890 //******************************************************
1891 void PartSet_Module::enableCustomModes() {
1892 myCustomPrs->enableCustomModes();
1895 //******************************************************
1896 void PartSet_Module::onConflictingConstraints()
1898 const std::set<ObjectPtr>& aConstraints = myOverconstraintListener->conflictingObjects();
1899 QObjectPtrList aObjectsList;
1900 std::set<ObjectPtr>::const_iterator aIt;
1901 for (aIt = aConstraints.cbegin(); aIt != aConstraints.cend(); aIt++) {
1902 if (mySketchReentrantMgr->isLastAutoConstraint(*aIt))
1903 aObjectsList.append(*aIt);
1905 if (aObjectsList.size() > 0) {
1906 XGUI_Workshop* aWorkshop = getWorkshop();
1907 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1908 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription);
1909 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
1911 ModuleBase_Operation* anOp = anOpMgr->currentOperation();
1912 if (sketchMgr()->isNestedSketchOperation(anOp))
1915 anOpMgr->startOperation(anOpAction);
1916 aWorkshop->deleteFeatures(aObjectsList);
1917 anOpMgr->commitOperation();
1918 ModuleBase_Tools::flushUpdated(sketchMgr()->activeSketch());