1 // Copyright (C) 2014-2023 CEA, EDF
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>
72 #include <ModuleBase_Preferences.h>
74 #include <ModelAPI_ResultField.h>
75 #include <ModelAPI_Object.h>
76 #include <ModelAPI_Events.h>
77 #include <ModelAPI_Validator.h>
78 #include <ModelAPI_Data.h>
79 #include <ModelAPI_Session.h>
80 #include <ModelAPI_ResultBody.h>
81 #include <ModelAPI_AttributeString.h>
82 #include <ModelAPI_AttributeSelectionList.h>
83 #include <ModelAPI_Tools.h>
84 #include <ModelAPI_ResultConstruction.h>
85 #include <ModelAPI_AttributeIntArray.h>
86 #include <ModelAPI_AttributeImage.h>
87 #include <ModelAPI_ResultGroup.h>
88 #include <ModelAPI_ResultParameter.h>
90 #include <GeomDataAPI_Point2D.h>
91 #include <GeomDataAPI_Point.h>
92 #include <GeomDataAPI_Dir.h>
94 #include <XGUI_ActiveControlMgr.h>
95 #include <XGUI_ActiveControlSelector.h>
96 #include <XGUI_ActionsMgr.h>
97 #include <XGUI_ContextMenuMgr.h>
98 #include <XGUI_DataModel.h>
99 #include <XGUI_Displayer.h>
100 #include <XGUI_ErrorMgr.h>
101 #include <XGUI_FacesPanelSelector.h>
102 #include <XGUI_ModuleConnector.h>
103 #include <XGUI_ObjectsBrowser.h>
104 #include <XGUI_OperationMgr.h>
105 #include <XGUI_PropertyPanel.h>
106 #include <XGUI_SelectionMgr.h>
107 #include <XGUI_Tools.h>
108 #include <XGUI_Workshop.h>
110 #include <SketchPlugin_ConstraintAngle.h>
111 #include <SketchPlugin_ConstraintLength.h>
112 #include <SketchPlugin_ConstraintDistance.h>
113 #include <SketchPlugin_ConstraintParallel.h>
114 #include <SketchPlugin_ConstraintPerpendicular.h>
115 #include <SketchPlugin_ConstraintRadius.h>
116 #include <SketchPlugin_Feature.h>
117 #include <SketchPlugin_Projection.h>
118 #include <SketchPlugin_Sketch.h>
120 #include <SketcherPrs_SymbolPrs.h>
121 #include <SketcherPrs_PositionMgr.h>
122 #include <SketcherPrs_Coincident.h>
123 #include <SketcherPrs_Tools.h>
125 #include <Events_Loop.h>
126 #include <Events_MessageBool.h>
127 #include <Config_PropManager.h>
128 #include <Config_Keywords.h>
130 #include <AIS_InteractiveObject.hxx>
131 #include <PrsDim_Dimension.hxx>
132 #include <StdSelect_TypeOfFace.hxx>
133 #include <TopoDS_Vertex.hxx>
134 #include <TopoDS.hxx>
135 #include <TopoDS_Shape.hxx>
136 #include <BRep_Tool.hxx>
139 #include <QMouseEvent>
142 #include <QApplication>
143 #include <QMessageBox>
144 #include <QMainWindow>
148 #include <GeomAlgoAPI_FaceBuilder.h>
149 #include <GeomDataAPI_Dir.h>
151 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
152 #include <Graphic3d_Texture2Dmanual.hxx>
154 #include <SUIT_ResourceMgr.h>
156 #include <Basics_OCCTVersion.hxx>
158 #define FEATURE_ITEM_COLOR "0,0,225"
161 /*!Create and return new instance of XGUI_Module*/
162 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
164 return new PartSet_Module(theWshop);
167 //******************************************************
168 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
169 : ModuleBase_IModule(theWshop),
170 myIsOperationIsLaunched(false),
174 new PartSet_IconFactory(this);
176 mySketchMgr = new PartSet_SketcherMgr(this);
177 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
179 ModuleBase_IViewer* aViewer = theWshop->viewer();
180 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
181 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
182 connect(aViewer, SIGNAL(viewTransformed(int)),
183 SLOT(onViewTransformed(int)));
184 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
185 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
186 myMenuMgr = new PartSet_MenuMgr(this);
187 myCustomPrs = new PartSet_CustomPrs(theWshop);
189 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
191 Events_Loop* aLoop = Events_Loop::loop();
192 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
193 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENTS_CLOSED));
194 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
195 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LICENSE_VALID));
197 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
198 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
199 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
200 std::set<std::string> aCRGroupNames;
201 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
202 aCRFilter->setGroupNames(aCRGroupNames);
203 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
205 setDefaultConstraintShown();
207 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
208 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
210 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
211 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
213 Config_PropManager::registerProp("Visualization", "result_construction_color",
214 "Construction color",
216 ModelAPI_ResultConstruction::DEFAULT_COLOR());
218 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
219 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
221 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
222 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
224 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
225 "Reference shape wireframe color in operation", Config_Prop::Color,
226 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
227 Config_PropManager::registerProp("Visualization", "operation_result_color",
228 "Result shape wireframe color in operation", Config_Prop::Color,
229 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
230 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
231 "Multi selector item color in operation", Config_Prop::Color,
232 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
233 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
234 "Color of removed feature in operation", Config_Prop::Color,
235 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
236 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
237 "Color of sketch plane", Config_Prop::Color,
238 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
240 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
241 "Hidden faces transparency",
242 Config_Prop::DblSpin,
245 std::ostringstream aStream;
246 aStream << SketcherPrs_Tools::getDefaultArrowSize();
247 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
248 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
250 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
251 Config_Prop::String, "Times-bold");
255 aStream << SketcherPrs_Tools::getDefaultTextHeight();
256 Config_PropManager::registerProp("Visualization", "dimension_value_size",
257 "Dimension value size", Config_Prop::IntSpin, aStream.str());
259 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
261 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
263 Config_PropManager::registerProp("Visualization", "feature_objectbrowser_color",
264 "Feature items in Object Browser",
265 Config_Prop::Color, FEATURE_ITEM_COLOR);
267 Config_PropManager::registerProp("Visualization", "zoom_trihedron_arrows",
268 "Keep trihedron arrows view size constant", Config_Prop::Boolean, "false");
270 Config_PropManager::registerProp("Visualization", "use_auto_rotation",
271 "Enable automatic rotation", Config_Prop::Boolean, "false");
273 Config_PropManager::registerProp("Visualization", "axis_arrow_size",
274 "Trihedron arrows constant size", Config_Prop::IntSpin, "10");
276 Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
277 "Add parameter in parameters manager dialog",
278 Config_Prop::Shortcut, "Ctrl+A");
280 Config_PropManager::registerProp("Windows", "use_hide_faces_panel",
281 "Use HideFaces panel in operations", Config_Prop::Boolean, "false");
284 //******************************************************
285 PartSet_Module::~PartSet_Module()
288 delete myOverconstraintListener;
292 //******************************************************
293 void PartSet_Module::createFeatures()
295 ModuleBase_IModule::createFeatures();
297 // send signal to initialization plugin about the state of the preferences: to create part or not
298 bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
299 ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
300 Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
303 myRoot = new PartSet_RootNode();
304 myRoot->setWorkshop(workshop());
305 ModuleBase_IModule::loadProprietaryPlugins();
309 //******************************************************
310 void PartSet_Module::storeSelection()
312 // cash is used only to restore selection, so it should be filled in storeSelection and
313 // after applying immediatelly cleared in restoreSelection
314 myCurrentSelection.clear();
315 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
318 //******************************************************
319 void PartSet_Module::restoreSelection()
321 // cash is used only to restore selection, so it should be filled in storeSelection and
322 // after applying immediatelly cleared in restoreSelection
323 sketchMgr()->restoreSelection(myCurrentSelection);
324 myCurrentSelection.clear();
327 //******************************************************
328 void PartSet_Module::registerValidators()
330 //Registering of validators
331 SessionPtr aMgr = ModelAPI_Session::get();
332 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
333 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
334 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
335 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
336 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
337 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
338 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
339 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
340 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
341 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
342 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
343 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
344 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
345 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
346 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
347 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
348 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
349 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
350 aFactory->registerValidator("PartSet_MultyTranslationSelection",
351 new PartSet_MultyTranslationSelection);
352 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
353 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
354 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
357 //******************************************************
358 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
359 const bool isToConnect)
361 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
364 //******************************************************
365 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
367 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
368 mySketchMgr->commitNestedSketch(theOperation);
370 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
371 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
372 overconstraintListener()->setActive(false);
374 /// Restart sketcher operations automatically
375 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
376 getWorkshop()->selector()->clearSelection();
380 //******************************************************
381 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
383 /// Restart sketcher operations automatically
384 mySketchReentrantMgr->operationAborted(theOperation);
385 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
386 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
387 overconstraintListener()->setActive(false);
389 getWorkshop()->selector()->clearSelection();
392 //******************************************************
393 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
395 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
398 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
399 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
401 ModuleBase_ModelWidget* aFilledWidget = 0;
402 bool aPostonedWidgetActivation = false;
404 FeaturePtr aFeature = aFOperation->feature();
405 /// Restart sketcher operations automatically
406 /// it is important to call method of sketch reentrant manager before filling of PP
407 /// because it fills some created feature attributes, these new values should be used
408 /// to fill the property panel
409 mySketchReentrantMgr->operationStarted(theOperation);
411 aWorkshop->fillPropertyPanel(aFOperation);
412 // filling the operation values by the current selection
413 // if the operation can be committed after the controls filling, the method perform should
414 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
415 bool isOperationCommitted = false;
416 if (!aFOperation->isEditOperation()) {
417 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
418 // if there is a greed attribute, automatic commit by preselection
419 // for this feature is prohibited
420 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
421 if (currentOperation() != aFOperation)
422 isOperationCommitted = true;
424 if (aGreedAttributeId.empty()) {
425 // a signal should be emitted before the next widget activation
426 // because, the activation of the next widget will give a focus to the widget.
427 // As a result the value of the widget is initialized.
428 // And commit may happens until the value is entered.
430 if (mySketchReentrantMgr->canBeCommittedByPreselection())
431 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
432 // activate the next obligatory widget
433 if (!isOperationCommitted)
434 aPropertyPanel->activateNextWidget(aFilledWidget);
437 else { // there is a greed widget
438 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
439 std::string aFirstAttributeId = aWidgets.front()->attributeID();
440 // activate next widget after greeded if it is the first widget in the panel
441 // else the first panel widget is already activated by operation start
442 if (aFirstAttributeId == aGreedAttributeId)
443 aPostonedWidgetActivation = true;
446 } if (!isOperationCommitted) {
447 aWorkshop->connectToPropertyPanel(true);
448 updateSketcherOnStart(aFOperation);
449 updatePresentationsOnStart(aFOperation);
451 // the objects of the current operation should be deactivated
452 QObjectPtrList anObjects;
453 anObjects.append(aFeature);
454 std::list<ResultPtr> aResults;
455 ModelAPI_Tools::allResults(aFeature, aResults);
456 std::list<ResultPtr>::const_iterator aIt;
457 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
458 anObjects.append(*aIt);
460 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
461 for (; anIt != aLast; anIt++)
462 aWorkshop->deactivateActiveObject(*anIt, false);
463 if (anObjects.size() > 0) {
464 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
465 aDisplayer->updateViewer();
467 /// state of command actions should be updated after displayed objects modification because
468 /// deactivation(for example) of objects may influence on selection in the viewer
469 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
470 workshop()->updateCommandStatus();
472 if (aPostonedWidgetActivation) {
473 // if the widget is an empty in the chain of activated widgets, the current operation
474 // is restarted. It should be performed after functionality of the operation starting
475 aPropertyPanel->activateNextWidget(aFilledWidget);
480 //******************************************************
481 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
483 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
484 mySketchMgr->startSketch(theOperation);
486 // It is switched off because of
487 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
488 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
489 mySketchMgr->startNestedSketch(theOperation);
493 //******************************************************
494 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
496 ModuleBase_OperationFeature* aFOperation =
497 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
499 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
500 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
504 //******************************************************
505 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
507 ModuleBase_IModule::operationResumed(theOperation);
509 ModuleBase_OperationFeature* aFOperation =
510 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
512 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
513 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
517 //******************************************************
518 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
520 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
521 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
522 bool isModified = isModifiedArgs || isModifiedResults;
524 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
525 mySketchMgr->stopNestedSketch(theOperation);
527 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
528 setDefaultConstraintShown();
530 //VSV: Viewer is updated on feature update and redisplay
532 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
533 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
534 aDisplayer->updateViewer();
537 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
538 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
539 for (; anIt != aLast; anIt++) {
540 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
544 //******************************************************
545 ModuleBase_Operation* PartSet_Module::currentOperation() const
547 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
548 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
549 return anOpMgr->currentOperation();
552 //******************************************************
553 bool PartSet_Module::canUndo() const
555 bool aCanUndo = false;
556 SessionPtr aMgr = ModelAPI_Session::get();
557 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
558 aCanUndo = !aMgr->isOperation();
559 if (!aCanUndo) // check the enable state additionally by sketch manager
560 aCanUndo = aMgr->canUndo();
565 //******************************************************
566 bool PartSet_Module::canRedo() const
568 bool aCanRedo = false;
569 SessionPtr aMgr = ModelAPI_Session::get();
570 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
571 aCanRedo = !aMgr->isOperation();
572 if (!aCanRedo) // check the enable state additionally by sketch manager
573 aCanRedo = aMgr->canRedo();
578 //******************************************************
579 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
582 if (theActionId == "MOVE_CMD" || theActionId == "MOVE_SPLIT_CMD") {
583 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
585 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
586 // part features can not be moved in the history.
587 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
594 //******************************************************
595 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
597 // the sketch manager put the restriction to the objects erase
598 return mySketchMgr->canEraseObject(theObject);
601 //******************************************************
602 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
604 // the sketch manager put the restriction to the objects display
605 return mySketchMgr->canDisplayObject(theObject);
608 //******************************************************
609 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
610 const QString& theStartedOperationKind)
612 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
615 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
618 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
620 mySketchMgr->processHiddenObject(theObjects);
623 //******************************************************
624 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
626 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
628 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
629 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
630 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
631 if (isSketchOp || isNestedOp) {
632 // in active sketch operation it is possible to activate operation object in selection
633 // in the edit operation, e.g. points of the line can be moved when the line is edited
634 ModuleBase_OperationFeature* aFOperation =
635 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
636 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
641 //******************************************************
642 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
644 QMap<int, QAction*>& theMenuActions) const
646 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
649 //******************************************************
650 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
652 myMenuMgr->updateViewerMenu(theStdActions);
655 //******************************************************
656 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
658 bool isEnabledFixed = false;
659 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
660 mySketchReentrantMgr->isInternalEditActive())
661 isEnabledFixed = true;
662 return isEnabledFixed;
665 //******************************************************
666 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
668 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
669 if (anError.isEmpty())
670 anError = sketchMgr()->getFeatureError(theFeature);
675 //******************************************************
676 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
677 QStringList& theIds) const
679 myMenuMgr->grantedOperationIds(theOperation, theIds);
681 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
682 XGUI_Workshop* aWorkshop = getWorkshop();
683 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
687 //******************************************************
688 void PartSet_Module::activeSelectionModes(QIntList& theModes)
690 if (mySketchMgr->activeSketch().get())
691 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
693 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
696 //******************************************************
697 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
699 customSubShapesSelectionModes(theModes);
700 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
701 //myWorkshop->module()->activeSelectionModes(theModes);
704 //******************************************************
705 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
706 SelectMgr_ListOfFilter& theSelectionFilters)
708 bool isSketchActive = mySketchMgr->activeSketch().get();
710 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
711 mySelectionFilters.begin();
712 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
713 int aFilterType = aFiltersIt->first;
714 // do not add not participating filters in given parameters
715 if (!theFilterTypes.contains(aFilterType))
718 // using sketch filters only if sketch operation is active
719 if (!isSketchActive &&
720 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
723 // using filtering of construction results only from faces panel
724 if (aFilterType == SF_ResultGroupNameFilter)
727 theSelectionFilters.Append(aFiltersIt->second);
731 //******************************************************
732 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
734 if (theModes.contains(TopAbs_FACE))
735 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
736 if (theModes.contains(TopAbs_WIRE))
737 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
739 if (mySketchMgr->activeSketch().get())
740 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
743 //******************************************************
744 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
745 ObjectPtr& theObject, AttributePtr& theAttribute)
747 ObjectPtr anObject = theSelected->object();
748 GeomShapePtr aShape = theSelected->shape();
750 theAttribute = findAttribute(anObject, aShape);
751 // TODO: try to create result if object is an external object
752 theObject = anObject;
755 //******************************************************
756 bool PartSet_Module::isMouseOverWindow()
758 return mySketchMgr->isMouseOverWindow();
761 //******************************************************
762 bool PartSet_Module::isSketchNeutralPointActivated() const
764 bool isNeutralPoint = true;
765 if (sketchReentranceMgr()->isInternalEditActive())
766 isNeutralPoint = false;
767 if (myIsOperationIsLaunched)
768 isNeutralPoint = false;
770 return isNeutralPoint;
773 //******************************************************
774 void PartSet_Module::closeDocument()
776 myActivePartIndex = QModelIndex();
777 SketcherPrs_PositionMgr::get()->clearAll();
780 //******************************************************
781 void PartSet_Module::clearViewer()
783 myCustomPrs->clearPrs();
785 XGUI_Workshop* aWorkshop = getWorkshop();
786 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
787 aDisplayer->deactivateSelectionFilters(false);
790 //******************************************************
791 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
793 ModuleBase_OperationFeature* aFOperation =
794 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
798 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
799 // we have to manually activate the sketch label in edit mode
800 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
801 aPanel->activateWidget(aPanel->modelWidgets().first());
804 //******************************************************
805 bool PartSet_Module::createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
806 QList<ModuleBase_ModelWidget*>& theWidgets) const
808 bool aProcessed = false;
810 XGUI_Workshop* aWorkshop = getWorkshop();
811 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
812 if (mySketchMgr->activeSketch().get() && aPropertyPanel) {
813 ModuleBase_ISelection* aSelection = workshop()->selection();
814 // click on a point in sketch leads here with the point is highlighted, not yet selected
815 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
816 if (aPreselection.size() == 1) {
817 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
818 ObjectPtr anObject = aSelectedPrs->object();
820 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
821 GeomShapePtr aShape = aSelectedPrs->shape();
822 // click on the digit of dimension constrain comes here
823 // with an empty shape, so we need the check
824 if (aFeature == theFeature && aShape.get() && !aShape->isNull()) {
825 // if feature has only one result and shape of result is equal to selected shape
826 // this attribute is not processed. It is a case of Sketch Point.
827 if (aFeature->results().size() == 1) {
828 ResultPtr aResult = aFeature->results().front();
829 if (aResult.get() && aResult->shape()->isEqual(aShape))
832 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
833 std::pair<AttributePtr, int> anAttribute =
834 PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape, mySketchMgr->activeSketch());
835 if (anAttribute.first.get()) {
836 ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
838 const std::string anAttributeId = anAttribute.first->id();
839 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
841 theWidgets = aFactory.getModelWidgets();
842 // it is possible that the point does not present in XML definition,
843 // in this case, we assume that it is not processed by this module
844 // e.g. "Intersection point" feature
845 aProcessed = !theWidgets.isEmpty();
853 //******************************************************
854 void PartSet_Module::onSelectionChanged()
856 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
860 bool isSketcherOp = false;
861 // An edit operation is enable only if the current opeation is the sketch operation
862 if (mySketchMgr->activeSketch()) {
863 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
864 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
867 // Editing of constraints can be done on selection
868 ModuleBase_ISelection* aSelect = myWorkshop->selection();
869 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
870 if (aSelected.size() == 1) {
871 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
872 ObjectPtr aObject = aPrs->object();
873 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
875 std::string aId = aFeature->getKind();
876 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
877 (aId == SketchPlugin_ConstraintLength::ID()) ||
878 (aId == SketchPlugin_ConstraintDistance::ID()) ||
879 (aId == SketchPlugin_ConstraintAngle::ID())) {
880 editFeature(aFeature);
887 //******************************************************
888 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
890 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
891 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
892 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
895 //******************************************************
896 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
898 Config_WidgetAPI* theWidgetApi)
900 ModuleBase_IWorkshop* aWorkshop = workshop();
901 ModuleBase_ModelWidget* aWgt = NULL;
902 if (theType == "sketch-start-label") {
903 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
904 theWidgetApi, myHasConstraintShown);
905 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
906 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
907 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
908 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
909 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
910 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
911 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
912 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
914 } else if (theType == "sketch-2dpoint_selector") {
915 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
917 aPointWgt->setSketch(mySketchMgr->activeSketch());
918 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
920 }else if (theType == "sketch-2dpoint_flyout_selector") {
921 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
923 aPointWgt->setSketch(mySketchMgr->activeSketch());
924 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
926 } else if (theType == "sketch_shape_selector") {
927 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
928 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
929 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
930 aWgt = aShapeSelectorWgt;
931 } else if (theType == "sketch_multi_selector") {
932 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
933 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
934 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
935 aWgt = aShapeSelectorWgt;
937 else if (theType == "sketch_feature_point_selector") {
938 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
939 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
940 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
941 aWgt = aPointSelectorWgt;
943 else if (theType == "sketch-bspline_selector") {
944 PartSet_WidgetBSplinePoints* aBSplineWgt =
945 new PartSet_WidgetBSplinePoints(theParent, aWorkshop, theWidgetApi);
946 aBSplineWgt->setSketch(mySketchMgr->activeSketch());
949 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
950 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
951 } else if (theType == "export_file_selector") {
952 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
953 } else if (theType == "sketch_launcher") {
954 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
956 else if (theType == "module_choice") {
957 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
958 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
959 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
960 } else if (theType == "bspline-panel") {
961 PartSet_BSplineWidget* aPanel = new PartSet_BSplineWidget(theParent, theWidgetApi);
962 //aPanel->setFeature(theFeature);
968 //******************************************************
969 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
971 ModuleBase_ModelWidget* anActiveWidget = 0;
973 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
975 return anActiveWidget;
977 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
979 return anActiveWidget;
981 return aPanel->activeWidget(true);
984 //******************************************************
985 bool PartSet_Module::deleteObjects()
987 bool isProcessed = false;
989 XGUI_Workshop* aWorkshop = getWorkshop();
990 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
992 //SessionPtr aMgr = ModelAPI_Session::get();
993 // 1. check whether the delete should be processed in the module
994 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
995 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
996 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
997 if (isSketchOp || isNestedOp) {
999 // 2. find selected presentations
1000 // selected objects should be collected before the current operation abort because
1001 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
1002 ModuleBase_ISelection* aSel = workshop()->selection();
1003 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
1004 // if there are no selected objects in the viewer, that means that the selection in another
1005 // place cased this method. It is necessary to return the false value to understande in above
1006 // method that delete is not processed
1007 if (aSelectedObj.count() == 0)
1010 // avoid delete of the objects, which are not belong to the current sketch
1011 // in order to do not delete results of other sketches
1012 QObjectPtrList aSketchObjects;
1013 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
1014 for ( ; anIt != aLast; anIt++) {
1015 ObjectPtr anObject = *anIt;
1016 if (mySketchMgr->isObjectOfSketch(anObject)) {
1017 // sketch feature should be used in this list because workshop deletes features only
1018 // results are skipped
1019 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
1020 aSketchObjects.append(aSketchFeature);
1023 // if the selection contains only local selected presentations from other sketches,
1024 // the Delete operation should not be done at all
1025 if (aSketchObjects.size() == 0)
1028 // 3. start operation
1029 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1030 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, this);
1032 // the active nested sketch operation should be aborted unconditionally
1033 // the Delete action should be additionally granted for the Sketch operation
1034 // in order to do not abort/commit it
1036 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1037 return true; // the objects are processed but can not be deleted
1039 anOpMgr->startOperation(anOpAction);
1041 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1042 // the problem is in AIS Dimensions recompute
1043 // if a line and the dim are removed, line is the first
1044 // it causes the AIS recompute, where the base line is null,
1045 // the result is empty AIS in the viewer
1046 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1048 // 4. delete features
1049 // sketch feature should be skipped, only sub-features can be removed
1050 // when sketch operation is active
1051 aWorkshop->deleteFeatures(aSketchObjects);
1052 // 5. stop operation
1053 anOpMgr->commitOperation();
1058 //******************************************************
1059 void PartSet_Module::editFeature(FeaturePtr theFeature)
1061 storeConstraintsState(theFeature->getKind());
1062 ModuleBase_IModule::editFeature(theFeature);
1065 //******************************************************
1066 bool PartSet_Module::canCommitOperation() const
1071 //******************************************************
1072 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1074 myIsOperationIsLaunched = true;
1075 storeConstraintsState(theCmdId.toStdString());
1076 updateConstraintsState(theCmdId.toStdString());
1078 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1080 myIsOperationIsLaunched = false;
1083 //******************************************************
1084 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1086 if (myWorkshop->currentOperation() &&
1087 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1088 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1089 mySketchMgr->showConstraintStates();
1090 myHasConstraintShown = aShownStates;
1094 //******************************************************
1095 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1097 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1098 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1099 // Show constraints if a constraint was anOperation
1100 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1101 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1102 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1103 myHasConstraintShown[PartSet_Tools::Expressions]);
1107 //******************************************************
1108 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1110 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1111 if (!anAIS.IsNull()) {
1112 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1113 if (aFeature.get()) {
1114 bool aToUseZLayer = false;
1115 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1116 aToUseZLayer = true;
1118 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1119 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1122 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1123 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1124 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1126 aCtx->SetZLayer(anAIS, myVisualLayerId);
1132 //******************************************************
1133 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1136 // it should be recomputed in order to disappear in the viewer if the corresponded object
1138 //if (myCustomPrs->isActive())
1139 // myCustomPrs->redisplay(theObject, false);
1142 //******************************************************
1143 void PartSet_Module::onViewTransformed(int theTrsfType)
1145 // Set length of arrows constant in pixel size
1146 // if the operation is panning or rotate or panglobal then do nothing
1147 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1149 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1150 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1151 if (aContext.IsNull())
1154 //Handle(V3d_View) aView = aViewer->activeView();
1156 XGUI_Workshop* aWorkshop = getWorkshop();
1157 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1158 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1159 Handle(V3d_View) aView;
1161 V3d_ListOfView::Iterator aDefinedViews(aV3dViewer->DefinedViews());
1162 for (; aDefinedViews.More(); aDefinedViews.Next()) {
1163 Handle(V3d_View) aV = aDefinedViews.Value();
1164 double aS = aV->Scale();
1173 bool isModified = false;
1174 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1175 if (aCurrentOperation &&
1176 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1177 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1178 (aCurrentOperation->id() == "Measurement")))
1180 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1181 SketcherPrs_Tools::setArrowSize(aLen);
1182 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1183 aViewer->SetScale(aViewer->activeView(), aCurScale);
1185 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1186 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1188 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1189 foreach(AISObjectPtr aAIS, aPrsList) {
1190 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1192 Handle(PrsDim_Dimension) aDim = Handle(PrsDim_Dimension)::DownCast(aAisObj);
1193 if (!aDim.IsNull()) {
1194 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1195 aContext->Redisplay(aDim, false);
1201 // Manage trihedron arrows
1202 if (Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows")) {
1203 Handle(AIS_Trihedron) aTrihedron = aViewer->trihedron();
1204 if (!aTrihedron.IsNull()) {
1206 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1207 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1208 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1209 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1210 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1211 aContext->Redisplay(aTrihedron, false);
1216 aDisplayer->updateViewer();
1219 //******************************************************
1220 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1222 return myCustomPrs->isActive(theFlag);
1225 //******************************************************
1226 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1227 const ModuleBase_CustomizeFlag& theFlag,
1228 const bool theUpdateViewer)
1230 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1233 //******************************************************
1234 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1235 const bool theUpdateViewer)
1237 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1240 //******************************************************
1241 //bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1242 // std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1244 // bool aCustomized = false;
1246 // XGUI_Workshop* aWorkshop = getWorkshop();
1247 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1248 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1250 // return aCustomized;
1252 // if (!theResult.get()) {
1253 // std::vector<int> aColor;
1254 // XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1255 // if (!aColor.empty()) {
1256 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1259 // // customize dimentional constrains
1260 // sketchMgr()->customisePresentation(anObject);
1262 // return aCustomized;
1265 ////******************************************************
1266 //bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1267 // AISObjectPtr thePrs,
1268 // GeomCustomPrsPtr theCustomPrs)
1270 // bool aCustomized = false;
1272 // XGUI_Workshop* aWorkshop = getWorkshop();
1273 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1274 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1276 // return aCustomized;
1278 // std::vector<int> aColor;
1279 // bool aUseCustomColor = true;
1280 // if (aUseCustomColor)
1281 // myOverconstraintListener->getCustomColor(anObject, aColor);
1282 // // customize sketch symbol presentation
1283 // Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1284 // if (!anAISIO.IsNull()) {
1285 // if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1286 // Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1287 // if (!aPrs.IsNull()) {
1288 // aPrs->SetCustomColor(aColor);
1289 // aCustomized = true;
1291 // } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1292 // Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1293 // if (!aPrs.IsNull()) {
1294 // aPrs->SetCustomColor(aColor);
1295 // aCustomized = true;
1299 // // customize sketch dimension constraint presentation
1300 // if (!aCustomized) {
1301 // if (!aColor.empty()) { // otherwise presentation has the default color
1302 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1305 // return aCustomized;
1308 //******************************************************
1309 bool PartSet_Module::customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1310 const bool theUpdateViewer)
1312 bool isRedisplayed = false;
1313 if (myCustomPrs->isActive(theFlag))
1314 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1316 return isRedisplayed;
1319 //******************************************************
1320 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1322 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1324 QLabel* aLabel = aOB->activeDocLabel();
1325 aLabel->installEventFilter(myMenuMgr);
1326 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1327 SLOT(onActiveDocPopup(const QPoint&)));
1328 aOB->treeView()->setExpandsOnDoubleClick(false);
1329 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1330 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1332 Events_Loop* aLoop = Events_Loop::loop();
1333 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1337 //******************************************************
1338 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1340 SessionPtr aMgr = ModelAPI_Session::get();
1341 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1343 XGUI_Workshop* aWorkshop = getWorkshop();
1344 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1346 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1349 aMenu.addAction(aActivatePartAction);
1352 if (aMgr->activeDocument() == aMgr->moduleDocument()) {
1353 DocumentPtr aDoc = aMgr->moduleDocument();
1354 int aNbParts = aDoc->size(ModelAPI_ResultPart::group());
1355 bool aHaveToActivate = false;
1356 for (int i = 0; i < aNbParts; i++) {
1357 ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i);
1358 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1359 if (!aPartRes->partDoc().get()) {
1360 aHaveToActivate = true;
1364 if (aHaveToActivate) {
1365 QAction* aActivateAllPartAction = myMenuMgr->action("ACTIVATE_ALL_PARTS_CMD");
1366 aMenu.addAction(aActivateAllPartAction);
1371 aMenu.exec(aHeader->mapToGlobal(thePnt));
1374 //******************************************************
1375 AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject)
1377 Handle(AIS_InteractiveObject) anAISPrs = mySketchMgr->createPresentation(theObject);
1378 if (anAISPrs.IsNull()) {
1379 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1380 if (aResult.get()) {
1381 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
1382 if (aShapePtr.get() != NULL)
1383 anAISPrs = new ModuleBase_ResultPrs(aResult);
1386 FieldStepPtr aStep =
1387 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1389 anAISPrs = new PartSet_FieldStepPrs(aStep);
1394 if (!anAISPrs.IsNull()) {
1395 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
1396 if (!aShapePrs.IsNull())
1397 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
1399 anAIS = AISObjectPtr(new GeomAPI_AISObject());
1400 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
1401 customizePresentation(theObject, anAIS);
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 static AttributeImagePtr findImage(const ObjectPtr& theResult)
1426 AttributeImagePtr anImageAttr;
1428 if (theResult.get()) {
1429 ResultBodyPtr aResultBody =
1430 std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
1431 if (aResultBody.get()) {
1432 anImageAttr = aResultBody->data()->image(ModelAPI_ResultBody::IMAGE_ID());
1433 if (!anImageAttr.get() || !anImageAttr->hasTexture()) {
1434 // try to find an image attribute in parents
1435 ObjectPtr aParent = theResult->document()->parent(theResult);
1436 anImageAttr = findImage(aParent);
1444 //******************************************************
1445 void PartSet_Module::setTexture(const AISObjectPtr& thePrs,
1446 const ResultPtr& theResult)
1448 ResultBodyPtr aResultBody =
1449 std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
1450 if (!aResultBody.get())
1453 AttributeImagePtr anImageAttr = findImage(theResult);
1454 if (!anImageAttr.get() || !anImageAttr->hasTexture())
1457 int aWidth, aHeight;
1458 std::string aFormat;
1459 std::list<unsigned char> aByteList;
1460 anImageAttr->texture(aWidth, aHeight, aByteList, aFormat);
1462 Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
1463 if (!anAIS.IsNull()) {
1464 /// set color to white and change material aspect,
1465 /// in order to keep a natural apect of the image.
1466 thePrs->setColor(255, 255, 255);
1467 Quantity_Color myShadingColor(NCollection_Vec3<float>(1., 1., 1.));
1468 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
1469 if (!anAISShape.IsNull())
1471 auto myDrawer = anAISShape->Attributes();
1473 myDrawer->ShadingAspect()->SetColor(myShadingColor);
1474 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
1475 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
1476 aMatAspect.SetTransparency(0.0);
1477 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
1478 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
1480 //aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
1481 Handle(Image_PixMap) aPixmap = new Image_PixMap();
1482 #if OCC_VERSION_LARGE < 0x07070000
1483 aPixmap->InitTrash(Image_PixMap::ImgBGRA, aWidth, aHeight);
1485 aPixmap->InitTrash(Image_Format_BGRA, aWidth, aHeight);
1487 std::list<unsigned char>::iterator aByteIter = aByteList.begin();
1488 for (int aLine = 0; aLine < aHeight; ++aLine) {
1489 // convert pixels from ARGB to renderer-compatible RGBA
1490 for (int aByte = 0; aByte < aWidth; ++aByte) {
1491 Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
1493 aPixmapBytes.b() = (Standard_Byte) *aByteIter++;
1494 aPixmapBytes.g() = (Standard_Byte) *aByteIter++;
1495 aPixmapBytes.r() = (Standard_Byte) *aByteIter++;
1496 aPixmapBytes.a() = (Standard_Byte) *aByteIter++;
1500 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
1501 (new Graphic3d_Texture2Dmanual(aPixmap));
1502 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
1504 anAISShape->SetDisplayMode(AIS_Shaded);
1509 //******************************************************
1510 void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
1511 const AISObjectPtr& thePrs) const
1513 if (mySketchMgr->isObjectOfSketch(theObject)) {
1514 mySketchMgr->customizeSketchPresentation(theObject, thePrs);
1517 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1518 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1519 if (aResult.get()) {
1520 std::vector<int> aColor;
1521 bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document());
1522 // Get user defined color for the object
1523 ModelAPI_Tools::getColor(aResult, aColor);
1525 bool isCustomized = false;
1526 if (aColor.empty() && aFeature.get()) {
1527 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1528 if (aCustPrs.get()) {
1529 isCustomized = aCustPrs->customisePresentation(aResult, thePrs);
1532 if (!isCustomized) {
1533 if (aColor.empty()) {
1534 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1536 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1540 if (aColor.empty()) {
1541 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1543 QColor aQColor(aColor[0], aColor[1], aColor[2]);
1545 QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
1546 thePrs->setColor(aNewColor.red(), aNewColor.green(), aNewColor.blue());
1548 thePrs->setDeflection(getResultDeflection(aResult));
1549 thePrs->setTransparency(getResultTransparency(aResult));
1551 /// set texture parameters, if any
1552 setTexture(thePrs, aResult);
1554 if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
1555 thePrs->setWidth(2);
1561 //******************************************************
1562 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1565 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1567 /// If last line finished on vertex the lines creation sequence has to be break
1568 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1570 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1571 // if there is an active widget, find the presented object in it
1572 if (!anActiveWidget)
1573 anActiveWidget = aPanel->preselectionWidget();
1575 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1577 if (aWidgetValidated)
1578 anObject = aWidgetValidated->findPresentedObject(theAIS);
1584 //******************************************************
1585 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1587 bool aCanBeShaged = true;
1589 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1591 aCanBeShaged = false;
1593 return aCanBeShaged;
1596 //******************************************************
1597 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1599 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1600 int aSelected = aObjects.size();
1601 SessionPtr aMgr = ModelAPI_Session::get();
1602 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1604 bool hasResult = false;
1605 bool hasFeature = false;
1606 bool hasParameter = false;
1607 bool hasCompositeOwner = false;
1608 bool hasResultInHistory = false;
1609 bool hasFolder = false;
1610 bool hasGroupsOnly = false;
1611 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1612 hasCompositeOwner, hasResultInHistory, hasFolder, hasGroupsOnly);
1614 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1615 if (aSelected == 1) {
1616 ObjectPtr aObject = aObjects.first();
1618 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1619 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1620 bool isPart = aPart.get() ||
1621 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1623 DocumentPtr aPartDoc;
1625 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1627 if (aPart.get()) // this may be null is Part feature is disabled
1628 aPartDoc = aPart->partDoc();
1630 theMenu->addAction(aActivatePartAction);
1631 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1633 } else if (aObject->document() == aMgr->activeDocument()) {
1634 if (hasParameter || hasFeature) {
1636 bool isEnabled = true;
1637 if (aFeature.get()) {
1638 // disable Edit menu for not editable features
1639 isEnabled = aFeature->isEditable();
1641 // disable Edit menu for groups under ImportResult feature
1642 if (aFeature->getKind() == "Group") {
1643 std::shared_ptr<ModelAPI_CompositeFeature> anOwner =
1644 ModelAPI_Tools::compositeOwner (aFeature);
1645 if (anOwner.get() && anOwner->getKind() == "ImportResult") {
1651 myMenuMgr->action("EDIT_CMD")->setEnabled(isEnabled);
1654 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1655 if (aCurrentOp && aFeature.get()) {
1656 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1657 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1665 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1666 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1667 theMenu->addSeparator();
1670 bool aNotDeactivate = (aCurrentOp == 0);
1671 if (!aNotDeactivate) {
1672 aActivatePartAction->setEnabled(false);
1676 //******************************************************
1677 #define EXPAND_PARENT(OBJ) \
1678 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1679 if (aObjIndex.isValid()) { \
1680 QModelIndex aParent = aObjIndex.parent(); \
1681 int aCount = aDataModel->rowCount(aParent); \
1683 aTreeView->setExpanded(aParent, true); \
1686 //******************************************************
1687 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1689 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENTS_CLOSED)) {
1691 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1692 SessionPtr aMgr = ModelAPI_Session::get();
1693 if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation
1695 // Do not change activation of parts if an operation active
1696 static QStringList aAllowActivationList;
1697 if (aAllowActivationList.isEmpty())
1698 aAllowActivationList <<
1699 QString(PartSetPlugin_Part::ID().c_str()) <<
1700 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1701 QString(PartSetPlugin_Remove::ID().c_str());
1702 if (myWorkshop->currentOperation() &&
1703 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1705 XGUI_Workshop* aWorkshop = getWorkshop();
1706 bool needUpdate = false;
1707 XGUI_DataTree* aTreeView = 0;
1708 if (aWorkshop->objectBrowser()) {
1709 aTreeView = aWorkshop->objectBrowser()->treeView();
1710 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1711 QPalette aPalet = aLabel->palette();
1713 DocumentPtr aActiveDoc = aMgr->activeDocument();
1715 // Clear active part index if there is no Part documents
1716 // It could be not null if document was closed and opened a new
1717 // without closeDocument call
1718 if (aMgr->allOpenedDocuments().size() <= 1)
1719 myActivePartIndex = QModelIndex();
1721 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1722 QModelIndex aOldActive = myActivePartIndex;
1723 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1724 if (myActivePartIndex.isValid()) {
1725 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1727 aTreeView->setExpanded(myActivePartIndex, true);
1729 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1730 aTreeView->setExpanded(aOldActive, false);
1732 aLabel->setPalette(aPalet);
1734 aWorkshop->updateCommandStatus();
1736 // Update displayed objects in order to update active color
1737 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1738 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1740 foreach(ObjectPtr aObj, aObjects) {
1741 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1742 aObj->isDisabled() || (!aObj->isDisplayed());
1744 aDisplayer->redisplay(aObj, false);
1747 aDisplayer->updateViewer();
1748 // Update tree items if they are expanded
1750 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1752 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1753 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1754 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1755 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1757 ObjectPtr aConstrObj;
1758 ObjectPtr aResultObj;
1759 std::set<ObjectPtr>::const_iterator aIt;
1760 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1761 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1762 ObjectPtr aObject = (*aIt);
1763 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1764 && (aObject->document() != aRootDoc))
1765 aResultObj = aObject;
1766 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1767 && (aObject->document() != aRootDoc))
1768 aConstrObj = aObject;
1769 if (aResultObj.get() && aConstrObj.get())
1773 if (aResultObj.get() || aConstrObj.get()) {
1774 XGUI_Workshop* aWorkshop = getWorkshop();
1775 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1776 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1778 if (aResultObj.get()) {
1779 EXPAND_PARENT(aResultObj)
1781 if (aConstrObj.get()) {
1782 EXPAND_PARENT(aConstrObj)
1786 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1787 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1788 if (aSketch.get()) {
1789 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1790 if (PartSet_SketcherMgr::isSketchOperation(anOperation) &&
1791 mySketchMgr->previewSketchPlane()->isDisplayed())
1792 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1795 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LICENSE_VALID)) {
1796 std::shared_ptr<ModelAPI_FeaturesLicenseValidMessage> aMsg =
1797 std::dynamic_pointer_cast<ModelAPI_FeaturesLicenseValidMessage>(theMessage);
1798 myFeaturesValidLicense.insert(aMsg->features().begin(), aMsg->features().end());
1799 processProprietaryFeatures();
1803 //******************************************************
1804 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1806 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1808 SessionPtr aMgr = ModelAPI_Session::get();
1809 if (!theIndex.isValid()) {
1810 // It seems that this code is obsolete
1811 //aMgr->setActiveDocument(aMgr->moduleDocument());
1814 if (theIndex.column() != 1) // Use only first column
1817 XGUI_Workshop* aWorkshop = getWorkshop();
1818 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1819 // De not use non editable Indexes
1820 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1822 ObjectPtr aObj = aDataModel->object(theIndex);
1824 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1825 if (!aPart.get()) { // Probably this is Feature
1826 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1827 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1828 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1832 if (!aPart.get() && aObj->groupName() == ModelAPI_ResultParameter::group())
1834 QObjectPtrList aSelectedObjects = aWorkshop->objectBrowser()->selectedObjects();
1835 FeaturePtr aFeature;
1836 ResultParameterPtr aParam;
1837 foreach(ObjectPtr aSelected, aSelectedObjects) {
1838 aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aSelected);
1843 aFeature = ModelAPI_Feature::feature(aParam);
1846 editFeature(aFeature);
1850 if (aPart.get()) { // if this is a part
1851 if (aPart->partDoc() == aMgr->activeDocument()) {
1852 myMenuMgr->activatePartSet();
1854 myMenuMgr->activatePart(aPart);
1859 //******************************************************
1860 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1862 // z layer is created for all started operations in order to visualize operation AIS presentation
1864 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1865 if (aContext.IsNull())
1868 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1869 if (myVisualLayerId == 0) {
1870 if (myVisualLayerId == 0)
1871 aViewer->AddZLayer(myVisualLayerId);
1873 TColStd_SequenceOfInteger aZList;
1874 aViewer->GetAllZLayers(aZList);
1875 bool aFound = false;
1876 for (int i = 1; i <= aZList.Length(); i++) {
1877 if (aZList(i) == myVisualLayerId) {
1883 aViewer->AddZLayer(myVisualLayerId);
1885 // if there is an active operation with validated widget,
1886 // the filters of this widget should be activated in the created view
1887 myWorkshop->selectionActivate()->updateSelectionFilters();
1888 myWorkshop->selectionActivate()->updateSelectionModes();
1891 //******************************************************
1892 void PartSet_Module::widgetStateChanged(int thePreviousState)
1894 mySketchMgr->widgetStateChanged(thePreviousState);
1897 //******************************************************
1898 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1900 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1903 //******************************************************
1904 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1906 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1907 mySketchMgr->stopSketch(theOperation);
1911 //******************************************************
1912 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1914 GeomShapePtr aGeomShape;
1916 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1917 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1918 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1923 //******************************************************
1924 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1925 const GeomShapePtr& theGeomShape)
1927 AttributePtr anAttribute;
1928 GeomShapePtr aGeomShape = theGeomShape;
1929 if (!aGeomShape.get()) {
1930 // processing shape of result, e.g. sketch circle center is selected, this is a result
1931 // the geom shape is empty, the shape of result should be used
1932 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1933 if (aResult.get()) {
1934 aGeomShape = aResult->shape();
1938 if (aGeomShape.get()) {
1939 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1940 std::pair<AttributePtr, int> anAttrAndIndex =
1941 PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, mySketchMgr->activeSketch());
1942 return anAttrAndIndex.first;
1947 //******************************************************
1948 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1950 return sketchReentranceMgr()->reentrantMessage();
1953 //******************************************************
1954 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1956 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1959 //******************************************************
1960 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1963 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1967 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1968 if (!aChoiceTitle.isEmpty()) {
1969 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1972 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1974 aPanel->setWindowTitle(aChoiceTitle);
1978 //******************************************************
1979 XGUI_Workshop* PartSet_Module::getWorkshop() const
1981 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1982 return aConnector->workshop();
1985 void PartSet_Module::setDefaultConstraintShown()
1987 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1988 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1989 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1992 //******************************************************
1993 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1998 //******************************************************
1999 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
2000 myCustomPrs->disableCustomMode(theMode);
2003 //******************************************************
2004 void PartSet_Module::enableCustomModes() {
2005 myCustomPrs->enableCustomModes();
2008 //******************************************************
2009 void PartSet_Module::onRemoveConflictingConstraints()
2011 const std::set<ObjectPtr>& aConstraints = myOverconstraintListener->objectsToRemove();
2012 std::set<ObjectPtr>::const_iterator anIt;
2014 XGUI_Workshop* aWorkshop = getWorkshop();
2015 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
2017 bool isAllowToNotify = ModuleBase_Preferences::resourceMgr()->booleanValue(SKETCH_TAB_NAME,
2018 "notify_change_constraint");
2020 if (isAllowToNotify) {
2021 anIt = aConstraints.begin();
2022 std::string aText("Conflict in constraints: \n");
2024 for (; anIt != aConstraints.end(); anIt++)
2026 ObjectPtr anObject = *anIt;
2027 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
2028 TCollection_AsciiString aStr(aFeature->name().c_str());
2029 std::string aName(aStr.ToCString());
2030 aText += aName + "\n";
2033 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
2034 ModuleBase_Tools::warningAboutConflict(aConnector->desktop(),
2038 ModuleBase_Operation* anOp = anOpMgr->currentOperation();
2039 if (sketchMgr()->isNestedSketchOperation(anOp)) {
2040 std::set<FeaturePtr> aFeatures;
2041 for (anIt = aConstraints.cbegin(); anIt != aConstraints.cend(); anIt++)
2042 aFeatures.insert(ModelAPI_Feature::feature(*anIt));
2044 ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2047 QObjectPtrList anObjectsList;
2048 for (anIt = aConstraints.cbegin(); anIt != aConstraints.cend(); anIt++)
2049 anObjectsList.append(*anIt);
2051 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
2052 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription);
2054 anOpMgr->startOperation(anOpAction);
2055 aWorkshop->deleteFeatures(anObjectsList);
2056 anOpMgr->commitOperation();
2058 ModuleBase_Tools::flushUpdated(sketchMgr()->activeSketch());