1 // Copyright (C) 2014-2021 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>
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 <Config_PropManager.h>
127 #include <Config_Keywords.h>
129 #include <AIS_InteractiveObject.hxx>
130 #include <PrsDim_Dimension.hxx>
131 #include <StdSelect_TypeOfFace.hxx>
132 #include <TopoDS_Vertex.hxx>
133 #include <TopoDS.hxx>
134 #include <TopoDS_Shape.hxx>
135 #include <BRep_Tool.hxx>
138 #include <QMouseEvent>
141 #include <QApplication>
142 #include <QMessageBox>
143 #include <QMainWindow>
147 #include <GeomAlgoAPI_FaceBuilder.h>
148 #include <GeomDataAPI_Dir.h>
150 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
151 #include <Graphic3d_Texture2Dmanual.hxx>
153 #include <SUIT_ResourceMgr.h>
155 #define FEATURE_ITEM_COLOR "0,0,225"
158 /*!Create and return new instance of XGUI_Module*/
159 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
161 return new PartSet_Module(theWshop);
164 //******************************************************
165 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
166 : ModuleBase_IModule(theWshop),
167 myIsOperationIsLaunched(false),
171 new PartSet_IconFactory(this);
173 mySketchMgr = new PartSet_SketcherMgr(this);
174 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
176 ModuleBase_IViewer* aViewer = theWshop->viewer();
177 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
178 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
179 connect(aViewer, SIGNAL(viewTransformed(int)),
180 SLOT(onViewTransformed(int)));
181 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
182 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
183 myMenuMgr = new PartSet_MenuMgr(this);
184 myCustomPrs = new PartSet_CustomPrs(theWshop);
186 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
188 Events_Loop* aLoop = Events_Loop::loop();
189 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
190 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
191 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LICENSE_VALID));
193 registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
194 registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
195 Handle(PartSet_ResultGroupNameFilter) aCRFilter = new PartSet_ResultGroupNameFilter(myWorkshop);
196 std::set<std::string> aCRGroupNames;
197 aCRGroupNames.insert(ModelAPI_ResultConstruction::group());
198 aCRFilter->setGroupNames(aCRGroupNames);
199 registerSelectionFilter(SF_ResultGroupNameFilter, aCRFilter);
201 setDefaultConstraintShown();
203 Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
204 Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
206 Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
207 Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
209 Config_PropManager::registerProp("Visualization", "result_construction_color",
210 "Construction color",
212 ModelAPI_ResultConstruction::DEFAULT_COLOR());
214 Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
215 Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
217 Config_PropManager::registerProp("Visualization", "result_field_color", "Field color",
218 Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR());
220 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
221 "Reference shape wireframe color in operation", Config_Prop::Color,
222 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
223 Config_PropManager::registerProp("Visualization", "operation_result_color",
224 "Result shape wireframe color in operation", Config_Prop::Color,
225 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
226 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
227 "Multi selector item color in operation", Config_Prop::Color,
228 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
229 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
230 "Color of removed feature in operation", Config_Prop::Color,
231 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
232 Config_PropManager::registerProp("Visualization", "sketch_preview_plane",
233 "Color of sketch plane", Config_Prop::Color,
234 PartSet_CustomPrs::OPERATION_SKETCH_PLANE());
236 Config_PropManager::registerProp("Visualization", "hidden_face_transparency",
237 "Hidden faces transparency",
238 Config_Prop::DblSpin,
241 std::ostringstream aStream;
242 aStream << SketcherPrs_Tools::getDefaultArrowSize();
243 Config_PropManager::registerProp("Visualization", "dimension_arrow_size",
244 "Dimension arrow size", Config_Prop::IntSpin, aStream.str());
246 Config_PropManager::registerProp("Visualization", "dimension_font", "Dimension font",
247 Config_Prop::String, "Times-bold");
251 aStream << SketcherPrs_Tools::getDefaultTextHeight();
252 Config_PropManager::registerProp("Visualization", "dimension_value_size",
253 "Dimension value size", Config_Prop::IntSpin, aStream.str());
255 Config_PropManager::registerProp("Visualization", "sketch_dimension_color",
257 Config_Prop::Color, SKETCH_DIMENSION_COLOR);
259 Config_PropManager::registerProp("Visualization", "feature_objectbrowser_color",
260 "Feature items in Object Browser",
261 Config_Prop::Color, FEATURE_ITEM_COLOR);
263 Config_PropManager::registerProp("Visualization", "zoom_trihedron_arrows",
264 "Keep trihedron arrows view size constant", Config_Prop::Boolean, "false");
266 Config_PropManager::registerProp("Visualization", "axis_arrow_size",
267 "Trihedron arrows constant size", Config_Prop::IntSpin, "10");
269 Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
270 "Add parameter in parameters manager dialog",
271 Config_Prop::Shortcut, "Ctrl+A");
273 Config_PropManager::registerProp("Windows", "use_hide_faces_panel",
274 "Use HideFaces panel in operations", Config_Prop::Boolean, "false");
277 //******************************************************
278 PartSet_Module::~PartSet_Module()
281 delete myOverconstraintListener;
285 //******************************************************
286 void PartSet_Module::createFeatures()
288 ModuleBase_IModule::createFeatures();
289 myRoot = new PartSet_RootNode();
290 myRoot->setWorkshop(workshop());
291 ModuleBase_IModule::loadProprietaryPlugins();
295 //******************************************************
296 void PartSet_Module::storeSelection()
298 // cash is used only to restore selection, so it should be filled in storeSelection and
299 // after applying immediatelly cleared in restoreSelection
300 myCurrentSelection.clear();
301 sketchMgr()->storeSelection(PartSet_SketcherMgr::ST_SelectType, myCurrentSelection);
304 //******************************************************
305 void PartSet_Module::restoreSelection()
307 // cash is used only to restore selection, so it should be filled in storeSelection and
308 // after applying immediatelly cleared in restoreSelection
309 sketchMgr()->restoreSelection(myCurrentSelection);
310 myCurrentSelection.clear();
313 //******************************************************
314 void PartSet_Module::registerValidators()
316 //Registering of validators
317 SessionPtr aMgr = ModelAPI_Session::get();
318 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
319 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
320 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
321 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
322 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
323 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
324 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
325 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
326 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
327 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
328 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
329 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
330 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
331 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
332 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
333 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
334 aFactory->registerValidator("PartSet_DifferentPoints", new PartSet_DifferentPointsValidator);
335 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
336 aFactory->registerValidator("PartSet_MultyTranslationSelection",
337 new PartSet_MultyTranslationSelection);
338 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
339 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
340 aFactory->registerValidator("PartSet_IntersectionSelection", new PartSet_IntersectionSelection);
343 //******************************************************
344 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
345 const bool isToConnect)
347 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
350 //******************************************************
351 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
353 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
354 mySketchMgr->commitNestedSketch(theOperation);
356 /// deactivate of overconstraint listener should be performed after Sketch commit (#2176)
357 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
358 overconstraintListener()->setActive(false);
360 /// Restart sketcher operations automatically
361 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
362 getWorkshop()->selector()->clearSelection();
366 //******************************************************
367 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
369 /// Restart sketcher operations automatically
370 mySketchReentrantMgr->operationAborted(theOperation);
371 /// deactivate of overconstraint listener should be performed after Sketch abort (#2176)
372 if (PartSet_SketcherMgr::isSketchOperation(theOperation))
373 overconstraintListener()->setActive(false);
375 getWorkshop()->selector()->clearSelection();
378 //******************************************************
379 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
381 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
384 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
385 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
387 ModuleBase_ModelWidget* aFilledWidget = 0;
388 bool aPostonedWidgetActivation = false;
390 FeaturePtr aFeature = aFOperation->feature();
391 /// Restart sketcher operations automatically
392 /// it is important to call method of sketch reentrant manager before filling of PP
393 /// because it fills some created feature attributes, these new values should be used
394 /// to fill the property panel
395 mySketchReentrantMgr->operationStarted(theOperation);
397 aWorkshop->fillPropertyPanel(aFOperation);
398 // filling the operation values by the current selection
399 // if the operation can be committed after the controls filling, the method perform should
400 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
401 bool isOperationCommitted = false;
402 if (!aFOperation->isEditOperation()) {
403 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
404 // if there is a greed attribute, automatic commit by preselection
405 // for this feature is prohibited
406 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
407 if (currentOperation() != aFOperation)
408 isOperationCommitted = true;
410 if (aGreedAttributeId.empty()) {
411 // a signal should be emitted before the next widget activation
412 // because, the activation of the next widget will give a focus to the widget.
413 // As a result the value of the widget is initialized.
414 // And commit may happens until the value is entered.
416 if (mySketchReentrantMgr->canBeCommittedByPreselection())
417 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
418 // activate the next obligatory widget
419 if (!isOperationCommitted)
420 aPropertyPanel->activateNextWidget(aFilledWidget);
423 else { // there is a greed widget
424 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
425 std::string aFirstAttributeId = aWidgets.front()->attributeID();
426 // activate next widget after greeded if it is the first widget in the panel
427 // else the first panel widget is already activated by operation start
428 if (aFirstAttributeId == aGreedAttributeId)
429 aPostonedWidgetActivation = true;
432 } if (!isOperationCommitted) {
433 aWorkshop->connectToPropertyPanel(true);
434 updateSketcherOnStart(aFOperation);
435 updatePresentationsOnStart(aFOperation);
437 // the objects of the current operation should be deactivated
438 QObjectPtrList anObjects;
439 anObjects.append(aFeature);
440 std::list<ResultPtr> aResults;
441 ModelAPI_Tools::allResults(aFeature, aResults);
442 std::list<ResultPtr>::const_iterator aIt;
443 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
444 anObjects.append(*aIt);
446 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
447 for (; anIt != aLast; anIt++)
448 aWorkshop->deactivateActiveObject(*anIt, false);
449 if (anObjects.size() > 0) {
450 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
451 aDisplayer->updateViewer();
453 /// state of command actions should be updated after displayed objects modification because
454 /// deactivation(for example) of objects may influence on selection in the viewer
455 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
456 workshop()->updateCommandStatus();
458 if (aPostonedWidgetActivation) {
459 // if the widget is an empty in the chain of activated widgets, the current operation
460 // is restarted. It should be performed after functionality of the operation starting
461 aPropertyPanel->activateNextWidget(aFilledWidget);
466 //******************************************************
467 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
469 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
470 mySketchMgr->startSketch(theOperation);
472 // It is switched off because of
473 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
474 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
475 mySketchMgr->startNestedSketch(theOperation);
479 //******************************************************
480 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
482 ModuleBase_OperationFeature* aFOperation =
483 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
485 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
486 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
490 //******************************************************
491 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
493 ModuleBase_IModule::operationResumed(theOperation);
495 ModuleBase_OperationFeature* aFOperation =
496 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
498 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, false);
499 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, false);
503 //******************************************************
504 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
506 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
507 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
508 bool isModified = isModifiedArgs || isModifiedResults;
510 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
511 mySketchMgr->stopNestedSketch(theOperation);
513 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
514 setDefaultConstraintShown();
516 //VSV: Viewer is updated on feature update and redisplay
518 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
519 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
520 aDisplayer->updateViewer();
523 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
524 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
525 for (; anIt != aLast; anIt++) {
526 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
530 //******************************************************
531 ModuleBase_Operation* PartSet_Module::currentOperation() const
533 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
534 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
535 return anOpMgr->currentOperation();
538 //******************************************************
539 bool PartSet_Module::canUndo() const
541 bool aCanUndo = false;
542 SessionPtr aMgr = ModelAPI_Session::get();
543 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
544 aCanUndo = !aMgr->isOperation();
545 if (!aCanUndo) // check the enable state additionally by sketch manager
546 aCanUndo = aMgr->canUndo();
551 //******************************************************
552 bool PartSet_Module::canRedo() const
554 bool aCanRedo = false;
555 SessionPtr aMgr = ModelAPI_Session::get();
556 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
557 aCanRedo = !aMgr->isOperation();
558 if (!aCanRedo) // check the enable state additionally by sketch manager
559 aCanRedo = aMgr->canRedo();
564 //******************************************************
565 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
568 if (theActionId == "MOVE_CMD" || theActionId == "MOVE_SPLIT_CMD") {
569 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
571 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
572 // part features can not be moved in the history.
573 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
580 //******************************************************
581 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
583 // the sketch manager put the restriction to the objects erase
584 return mySketchMgr->canEraseObject(theObject);
587 //******************************************************
588 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
590 // the sketch manager put the restriction to the objects display
591 return mySketchMgr->canDisplayObject(theObject);
594 //******************************************************
595 bool PartSet_Module::canUsePreselection(const QString& thePreviousOperationKind,
596 const QString& theStartedOperationKind)
598 if (ModuleBase_IModule::canUsePreselection(thePreviousOperationKind, theStartedOperationKind))
601 return mySketchMgr->isNestedSketchFeature(theStartedOperationKind);
604 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
606 mySketchMgr->processHiddenObject(theObjects);
609 //******************************************************
610 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
612 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
614 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
615 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
616 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
617 if (isSketchOp || isNestedOp) {
618 // in active sketch operation it is possible to activate operation object in selection
619 // in the edit operation, e.g. points of the line can be moved when the line is edited
620 ModuleBase_OperationFeature* aFOperation =
621 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
622 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
627 //******************************************************
628 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
630 QMap<int, QAction*>& theMenuActions) const
632 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
635 //******************************************************
636 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
638 myMenuMgr->updateViewerMenu(theStdActions);
641 //******************************************************
642 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
644 bool isEnabledFixed = false;
645 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
646 mySketchReentrantMgr->isInternalEditActive())
647 isEnabledFixed = true;
648 return isEnabledFixed;
651 //******************************************************
652 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
654 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
655 if (anError.isEmpty())
656 anError = sketchMgr()->getFeatureError(theFeature);
661 //******************************************************
662 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
663 QStringList& theIds) const
665 myMenuMgr->grantedOperationIds(theOperation, theIds);
667 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
668 XGUI_Workshop* aWorkshop = getWorkshop();
669 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
673 //******************************************************
674 void PartSet_Module::activeSelectionModes(QIntList& theModes)
676 if (mySketchMgr->activeSketch().get())
677 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
679 theModes = XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes();
682 //******************************************************
683 void PartSet_Module::moduleSelectionModes(int theModesType, QIntList& theModes)
685 customSubShapesSelectionModes(theModes);
686 //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
687 //myWorkshop->module()->activeSelectionModes(theModes);
690 //******************************************************
691 void PartSet_Module::moduleSelectionFilters(const QIntList& theFilterTypes,
692 SelectMgr_ListOfFilter& theSelectionFilters)
694 bool isSketchActive = mySketchMgr->activeSketch().get();
696 std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)>::const_iterator aFiltersIt =
697 mySelectionFilters.begin();
698 for (; aFiltersIt != mySelectionFilters.end(); aFiltersIt++) {
699 int aFilterType = aFiltersIt->first;
700 // do not add not participating filters in given parameters
701 if (!theFilterTypes.contains(aFilterType))
704 // using sketch filters only if sketch operation is active
705 if (!isSketchActive &&
706 mySketchMgr->sketchSelectionFilter((ModuleBase_SelectionFilterType)aFilterType))
709 // using filtering of construction results only from faces panel
710 if (aFilterType == SF_ResultGroupNameFilter)
713 theSelectionFilters.Append(aFiltersIt->second);
717 //******************************************************
718 void PartSet_Module::customSubShapesSelectionModes(QIntList& theModes)
720 if (theModes.contains(TopAbs_FACE))
721 theModes.append(SketcherPrs_Tools::Sel_Sketch_Face);
722 if (theModes.contains(TopAbs_WIRE))
723 theModes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
725 if (mySketchMgr->activeSketch().get())
726 PartSet_SketcherMgr::sketchSelectionModes(mySketchMgr->activeSketch(), theModes);
729 //******************************************************
730 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
731 ObjectPtr& theObject, AttributePtr& theAttribute)
733 ObjectPtr anObject = theSelected->object();
734 GeomShapePtr aShape = theSelected->shape();
736 theAttribute = findAttribute(anObject, aShape);
737 // TODO: try to create result if object is an external object
738 theObject = anObject;
741 //******************************************************
742 bool PartSet_Module::isMouseOverWindow()
744 return mySketchMgr->isMouseOverWindow();
747 //******************************************************
748 bool PartSet_Module::isSketchNeutralPointActivated() const
750 bool isNeutralPoint = true;
751 if (sketchReentranceMgr()->isInternalEditActive())
752 isNeutralPoint = false;
753 if (myIsOperationIsLaunched)
754 isNeutralPoint = false;
756 return isNeutralPoint;
759 //******************************************************
760 void PartSet_Module::closeDocument()
762 myActivePartIndex = QModelIndex();
763 SketcherPrs_PositionMgr::get()->clearAll();
766 //******************************************************
767 void PartSet_Module::clearViewer()
769 myCustomPrs->clearPrs();
771 XGUI_Workshop* aWorkshop = getWorkshop();
772 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
773 aDisplayer->deactivateSelectionFilters(false);
776 //******************************************************
777 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
779 ModuleBase_OperationFeature* aFOperation =
780 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
784 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
785 // we have to manually activate the sketch label in edit mode
786 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
787 aPanel->activateWidget(aPanel->modelWidgets().first());
790 //******************************************************
791 bool PartSet_Module::createWidgets(const FeaturePtr& theFeature, const QString& theXmlRepr,
792 QList<ModuleBase_ModelWidget*>& theWidgets) const
794 bool aProcessed = false;
796 XGUI_Workshop* aWorkshop = getWorkshop();
797 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
798 if (mySketchMgr->activeSketch().get() && aPropertyPanel) {
799 ModuleBase_ISelection* aSelection = workshop()->selection();
800 // click on a point in sketch leads here with the point is highlighted, not yet selected
801 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
802 if (aPreselection.size() == 1) {
803 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
804 ObjectPtr anObject = aSelectedPrs->object();
806 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
807 GeomShapePtr aShape = aSelectedPrs->shape();
808 // click on the digit of dimension constrain comes here
809 // with an empty shape, so we need the check
810 if (aFeature == theFeature && aShape.get() && !aShape->isNull()) {
811 // if feature has only one result and shape of result is equal to selected shape
812 // this attribute is not processed. It is a case of Sketch Point.
813 if (aFeature->results().size() == 1) {
814 ResultPtr aResult = aFeature->results().front();
815 if (aResult.get() && aResult->shape()->isEqual(aShape))
818 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
819 std::pair<AttributePtr, int> anAttribute =
820 PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape, mySketchMgr->activeSketch());
821 if (anAttribute.first.get()) {
822 ModuleBase_WidgetFactory aFactory(theXmlRepr.toStdString(), workshop());
824 const std::string anAttributeId = anAttribute.first->id();
825 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
827 theWidgets = aFactory.getModelWidgets();
828 // it is possible that the point does not present in XML definition,
829 // in this case, we assume that it is not processed by this module
830 // e.g. "Intersection point" feature
831 aProcessed = !theWidgets.isEmpty();
839 //******************************************************
840 void PartSet_Module::onSelectionChanged()
842 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
846 bool isSketcherOp = false;
847 // An edit operation is enable only if the current opeation is the sketch operation
848 if (mySketchMgr->activeSketch()) {
849 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
850 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
853 // Editing of constraints can be done on selection
854 ModuleBase_ISelection* aSelect = myWorkshop->selection();
855 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
856 if (aSelected.size() == 1) {
857 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
858 ObjectPtr aObject = aPrs->object();
859 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
861 std::string aId = aFeature->getKind();
862 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
863 (aId == SketchPlugin_ConstraintLength::ID()) ||
864 (aId == SketchPlugin_ConstraintDistance::ID()) ||
865 (aId == SketchPlugin_ConstraintAngle::ID())) {
866 editFeature(aFeature);
873 //******************************************************
874 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
876 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
877 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
878 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
881 //******************************************************
882 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
884 Config_WidgetAPI* theWidgetApi)
886 ModuleBase_IWorkshop* aWorkshop = workshop();
887 ModuleBase_ModelWidget* aWgt = NULL;
888 if (theType == "sketch-start-label") {
889 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
890 theWidgetApi, myHasConstraintShown);
891 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
892 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
893 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
894 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
895 connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
896 connect(aLabelWgt, SIGNAL(autoConstraints(bool)),
897 sketchReentranceMgr(), SLOT(onAutoConstraints(bool)));
898 aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
900 } else if (theType == "sketch-2dpoint_selector") {
901 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
903 aPointWgt->setSketch(mySketchMgr->activeSketch());
904 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
906 }else if (theType == "sketch-2dpoint_flyout_selector") {
907 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
909 aPointWgt->setSketch(mySketchMgr->activeSketch());
910 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
912 } else if (theType == "sketch_shape_selector") {
913 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
914 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
915 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
916 aWgt = aShapeSelectorWgt;
917 } else if (theType == "sketch_multi_selector") {
918 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
919 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
920 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
921 aWgt = aShapeSelectorWgt;
923 else if (theType == "sketch_feature_point_selector") {
924 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
925 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
926 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
927 aWgt = aPointSelectorWgt;
929 else if (theType == "sketch-bspline_selector") {
930 PartSet_WidgetBSplinePoints* aBSplineWgt =
931 new PartSet_WidgetBSplinePoints(theParent, aWorkshop, theWidgetApi);
932 aBSplineWgt->setSketch(mySketchMgr->activeSketch());
935 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
936 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
937 } else if (theType == "export_file_selector") {
938 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
939 } else if (theType == "sketch_launcher") {
940 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
942 else if (theType == "module_choice") {
943 aWgt = new ModuleBase_WidgetChoice(theParent, theWidgetApi);
944 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
945 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
946 } else if (theType == "bspline-panel") {
947 PartSet_BSplineWidget* aPanel = new PartSet_BSplineWidget(theParent, theWidgetApi);
948 //aPanel->setFeature(theFeature);
954 //******************************************************
955 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
957 ModuleBase_ModelWidget* anActiveWidget = 0;
959 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
961 return anActiveWidget;
963 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
965 return anActiveWidget;
967 return aPanel->activeWidget(true);
970 //******************************************************
971 bool PartSet_Module::deleteObjects()
973 bool isProcessed = false;
975 XGUI_Workshop* aWorkshop = getWorkshop();
976 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
978 //SessionPtr aMgr = ModelAPI_Session::get();
979 // 1. check whether the delete should be processed in the module
980 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
981 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
982 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
983 if (isSketchOp || isNestedOp) {
985 // 2. find selected presentations
986 // selected objects should be collected before the current operation abort because
987 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
988 ModuleBase_ISelection* aSel = workshop()->selection();
989 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
990 // if there are no selected objects in the viewer, that means that the selection in another
991 // place cased this method. It is necessary to return the false value to understande in above
992 // method that delete is not processed
993 if (aSelectedObj.count() == 0)
996 // avoid delete of the objects, which are not belong to the current sketch
997 // in order to do not delete results of other sketches
998 QObjectPtrList aSketchObjects;
999 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
1000 for ( ; anIt != aLast; anIt++) {
1001 ObjectPtr anObject = *anIt;
1002 if (mySketchMgr->isObjectOfSketch(anObject)) {
1003 // sketch feature should be used in this list because workshop deletes features only
1004 // results are skipped
1005 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
1006 aSketchObjects.append(aSketchFeature);
1009 // if the selection contains only local selected presentations from other sketches,
1010 // the Delete operation should not be done at all
1011 if (aSketchObjects.size() == 0)
1014 // 3. start operation
1015 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
1016 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, this);
1018 // the active nested sketch operation should be aborted unconditionally
1019 // the Delete action should be additionally granted for the Sketch operation
1020 // in order to do not abort/commit it
1022 if (!anOpMgr->canStartOperation(anOpAction->id(), isCommitted))
1023 return true; // the objects are processed but can not be deleted
1025 anOpMgr->startOperation(anOpAction);
1027 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
1028 // the problem is in AIS Dimensions recompute
1029 // if a line and the dim are removed, line is the first
1030 // it causes the AIS recompute, where the base line is null,
1031 // the result is empty AIS in the viewer
1032 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
1034 // 4. delete features
1035 // sketch feature should be skipped, only sub-features can be removed
1036 // when sketch operation is active
1037 aWorkshop->deleteFeatures(aSketchObjects);
1038 // 5. stop operation
1039 anOpMgr->commitOperation();
1044 //******************************************************
1045 void PartSet_Module::editFeature(FeaturePtr theFeature)
1047 storeConstraintsState(theFeature->getKind());
1048 ModuleBase_IModule::editFeature(theFeature);
1051 //******************************************************
1052 bool PartSet_Module::canCommitOperation() const
1057 //******************************************************
1058 void PartSet_Module::launchOperation(const QString& theCmdId, const bool& isStartAfterCommitOnly)
1060 myIsOperationIsLaunched = true;
1061 storeConstraintsState(theCmdId.toStdString());
1062 updateConstraintsState(theCmdId.toStdString());
1064 ModuleBase_IModule::launchOperation(theCmdId, isStartAfterCommitOnly);
1066 myIsOperationIsLaunched = false;
1069 //******************************************************
1070 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
1072 if (myWorkshop->currentOperation() &&
1073 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
1074 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
1075 mySketchMgr->showConstraintStates();
1076 myHasConstraintShown = aShownStates;
1080 //******************************************************
1081 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
1083 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
1084 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
1085 // Show constraints if a constraint was anOperation
1086 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
1087 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
1088 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
1089 myHasConstraintShown[PartSet_Tools::Expressions]);
1093 //******************************************************
1094 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
1096 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
1097 if (!anAIS.IsNull()) {
1098 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1099 if (aFeature.get()) {
1100 bool aToUseZLayer = false;
1101 if (PartSet_Tools::findRefsToMeFeature(aFeature,SketchPlugin_Projection::ID()))
1102 aToUseZLayer = true;
1104 CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(aFeature);
1105 aToUseZLayer = (aParent.get() && (aParent->getKind() == SketchPlugin_Sketch::ID()));
1108 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
1109 if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
1110 aCtx->SetZLayer(anAIS, Graphic3d_ZLayerId_Top);
1112 aCtx->SetZLayer(anAIS, myVisualLayerId);
1118 //******************************************************
1119 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
1122 // it should be recomputed in order to disappear in the viewer if the corresponded object
1124 //if (myCustomPrs->isActive())
1125 // myCustomPrs->redisplay(theObject, false);
1128 //******************************************************
1129 void PartSet_Module::onViewTransformed(int theTrsfType)
1131 // Set length of arrows constant in pixel size
1132 // if the operation is panning or rotate or panglobal then do nothing
1133 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
1135 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1136 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
1137 if (aContext.IsNull())
1140 //Handle(V3d_View) aView = aViewer->activeView();
1142 XGUI_Workshop* aWorkshop = getWorkshop();
1143 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1144 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
1145 Handle(V3d_View) aView;
1147 V3d_ListOfView::Iterator aDefinedViews(aV3dViewer->DefinedViews());
1148 for (; aDefinedViews.More(); aDefinedViews.Next()) {
1149 Handle(V3d_View) aV = aDefinedViews.Value();
1150 double aS = aV->Scale();
1159 bool isModified = false;
1160 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1161 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1162 if (aCurrentOperation &&
1163 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1164 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1165 (aCurrentOperation->id() == "Measurement")))
1167 SketcherPrs_Tools::setArrowSize(aLen);
1168 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1169 aViewer->SetScale(aViewer->activeView(), aCurScale);
1171 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1172 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1174 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1175 foreach(AISObjectPtr aAIS, aPrsList) {
1176 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1178 Handle(PrsDim_Dimension) aDim = Handle(PrsDim_Dimension)::DownCast(aAisObj);
1179 if (!aDim.IsNull()) {
1180 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1181 aContext->Redisplay(aDim, false);
1187 // Manage trihedron arrows
1188 if (Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows")) {
1189 Handle(AIS_Trihedron) aTrihedron = aViewer->trihedron();
1190 if (!aTrihedron.IsNull()) {
1192 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1193 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1194 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1195 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1196 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1197 aContext->Redisplay(aTrihedron, false);
1202 aDisplayer->updateViewer();
1205 //******************************************************
1206 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1208 return myCustomPrs->isActive(theFlag);
1211 //******************************************************
1212 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1213 const ModuleBase_CustomizeFlag& theFlag,
1214 const bool theUpdateViewer)
1216 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1219 //******************************************************
1220 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1221 const bool theUpdateViewer)
1223 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1226 //******************************************************
1227 //bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1228 // std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1230 // bool aCustomized = false;
1232 // XGUI_Workshop* aWorkshop = getWorkshop();
1233 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1234 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1236 // return aCustomized;
1238 // if (!theResult.get()) {
1239 // std::vector<int> aColor;
1240 // XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1241 // if (!aColor.empty()) {
1242 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1245 // // customize dimentional constrains
1246 // sketchMgr()->customisePresentation(anObject);
1248 // return aCustomized;
1251 ////******************************************************
1252 //bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1253 // AISObjectPtr thePrs,
1254 // GeomCustomPrsPtr theCustomPrs)
1256 // bool aCustomized = false;
1258 // XGUI_Workshop* aWorkshop = getWorkshop();
1259 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1260 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1262 // return aCustomized;
1264 // std::vector<int> aColor;
1265 // bool aUseCustomColor = true;
1266 // if (aUseCustomColor)
1267 // myOverconstraintListener->getCustomColor(anObject, aColor);
1268 // // customize sketch symbol presentation
1269 // Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1270 // if (!anAISIO.IsNull()) {
1271 // if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1272 // Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1273 // if (!aPrs.IsNull()) {
1274 // aPrs->SetCustomColor(aColor);
1275 // aCustomized = true;
1277 // } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1278 // Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1279 // if (!aPrs.IsNull()) {
1280 // aPrs->SetCustomColor(aColor);
1281 // aCustomized = true;
1285 // // customize sketch dimension constraint presentation
1286 // if (!aCustomized) {
1287 // if (!aColor.empty()) { // otherwise presentation has the default color
1288 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1291 // return aCustomized;
1294 //******************************************************
1295 bool PartSet_Module::customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1296 const bool theUpdateViewer)
1298 bool isRedisplayed = false;
1299 if (myCustomPrs->isActive(theFlag))
1300 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1302 return isRedisplayed;
1305 //******************************************************
1306 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1308 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1310 QLabel* aLabel = aOB->activeDocLabel();
1311 aLabel->installEventFilter(myMenuMgr);
1312 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1313 SLOT(onActiveDocPopup(const QPoint&)));
1314 aOB->treeView()->setExpandsOnDoubleClick(false);
1315 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1316 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1318 Events_Loop* aLoop = Events_Loop::loop();
1319 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1323 //******************************************************
1324 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1326 SessionPtr aMgr = ModelAPI_Session::get();
1327 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1329 XGUI_Workshop* aWorkshop = getWorkshop();
1330 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1332 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1335 aMenu.addAction(aActivatePartAction);
1338 if (aMgr->activeDocument() == aMgr->moduleDocument()) {
1339 DocumentPtr aDoc = aMgr->moduleDocument();
1340 int aNbParts = aDoc->size(ModelAPI_ResultPart::group());
1341 bool aHaveToActivate = false;
1342 for (int i = 0; i < aNbParts; i++) {
1343 ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i);
1344 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1345 if (!aPartRes->partDoc().get()) {
1346 aHaveToActivate = true;
1350 if (aHaveToActivate) {
1351 QAction* aActivateAllPartAction = myMenuMgr->action("ACTIVATE_ALL_PARTS_CMD");
1352 aMenu.addAction(aActivateAllPartAction);
1357 aMenu.exec(aHeader->mapToGlobal(thePnt));
1360 //******************************************************
1361 AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject)
1363 Handle(AIS_InteractiveObject) anAISPrs = mySketchMgr->createPresentation(theObject);
1364 if (anAISPrs.IsNull()) {
1365 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1366 if (aResult.get()) {
1367 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
1368 if (aShapePtr.get() != NULL)
1369 anAISPrs = new ModuleBase_ResultPrs(aResult);
1372 FieldStepPtr aStep =
1373 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1375 anAISPrs = new PartSet_FieldStepPrs(aStep);
1380 if (!anAISPrs.IsNull()) {
1381 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
1382 if (!aShapePrs.IsNull())
1383 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
1385 anAIS = AISObjectPtr(new GeomAPI_AISObject());
1386 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
1387 customizePresentation(theObject, anAIS);
1392 //******************************************************
1393 double getResultDeflection(const ResultPtr& theResult)
1395 double aDeflection = ModelAPI_Tools::getDeflection(theResult);
1396 if (aDeflection < 0)
1397 aDeflection = PartSet_Tools::getDefaultDeflection(theResult);
1401 //******************************************************
1402 double getResultTransparency(const ResultPtr& theResult)
1404 double aTransparency = ModelAPI_Tools::getTransparency(theResult);
1405 if (aTransparency < 0)
1406 aTransparency = PartSet_Tools::getDefaultTransparency();
1407 return aTransparency;
1410 static AttributeImagePtr findImage(const ObjectPtr& theResult)
1412 AttributeImagePtr anImageAttr;
1414 if (theResult.get()) {
1415 ResultBodyPtr aResultBody =
1416 std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
1417 if (aResultBody.get()) {
1418 anImageAttr = aResultBody->data()->image(ModelAPI_ResultBody::IMAGE_ID());
1419 if (!anImageAttr.get() || !anImageAttr->hasTexture()) {
1420 // try to find an image attribute in parents
1421 ObjectPtr aParent = theResult->document()->parent(theResult);
1422 anImageAttr = findImage(aParent);
1430 //******************************************************
1431 void PartSet_Module::setTexture(const AISObjectPtr& thePrs,
1432 const ResultPtr& theResult)
1434 ResultBodyPtr aResultBody =
1435 std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
1436 if (!aResultBody.get())
1439 AttributeImagePtr anImageAttr = findImage(theResult);
1440 if (!anImageAttr.get() || !anImageAttr->hasTexture())
1443 int aWidth, aHeight;
1444 std::string aFormat;
1445 std::list<unsigned char> aByteList;
1446 anImageAttr->texture(aWidth, aHeight, aByteList, aFormat);
1448 Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
1449 if (!anAIS.IsNull()) {
1450 /// set color to white and change material aspect,
1451 /// in order to keep a natural apect of the image.
1452 thePrs->setColor(255, 255, 255);
1453 Quantity_Color myShadingColor(NCollection_Vec3<float>(1., 1., 1.));
1454 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
1455 if (!anAISShape.IsNull())
1457 auto myDrawer = anAISShape->Attributes();
1459 myDrawer->ShadingAspect()->SetColor(myShadingColor);
1460 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
1461 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
1462 aMatAspect.SetTransparency(0.0);
1463 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
1464 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
1466 //aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
1467 Handle(Image_PixMap) aPixmap = new Image_PixMap();
1468 aPixmap->InitTrash(Image_PixMap::ImgBGRA, aWidth, aHeight);
1469 std::list<unsigned char>::iterator aByteIter = aByteList.begin();
1470 for (int aLine = 0; aLine < aHeight; ++aLine) {
1471 // convert pixels from ARGB to renderer-compatible RGBA
1472 for (int aByte = 0; aByte < aWidth; ++aByte) {
1473 Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
1475 aPixmapBytes.b() = (Standard_Byte) *aByteIter++;
1476 aPixmapBytes.g() = (Standard_Byte) *aByteIter++;
1477 aPixmapBytes.r() = (Standard_Byte) *aByteIter++;
1478 aPixmapBytes.a() = (Standard_Byte) *aByteIter++;
1482 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
1483 (new Graphic3d_Texture2Dmanual(aPixmap));
1484 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
1486 anAISShape->SetDisplayMode(AIS_Shaded);
1491 //******************************************************
1492 void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
1493 const AISObjectPtr& thePrs) const
1495 if (mySketchMgr->isObjectOfSketch(theObject)) {
1496 mySketchMgr->customizeSketchPresentation(theObject, thePrs);
1499 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1500 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1501 if (aResult.get()) {
1502 std::vector<int> aColor;
1503 bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document());
1504 // Get user defined color for the object
1505 ModelAPI_Tools::getColor(aResult, aColor);
1507 bool isCustomized = false;
1508 if (aColor.empty() && aFeature.get()) {
1509 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1510 if (aCustPrs.get()) {
1511 isCustomized = aCustPrs->customisePresentation(aResult, thePrs);
1514 if (!isCustomized) {
1515 if (aColor.empty()) {
1516 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1518 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1522 if (aColor.empty()) {
1523 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1525 QColor aQColor(aColor[0], aColor[1], aColor[2]);
1527 QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
1528 thePrs->setColor(aNewColor.red(), aNewColor.green(), aNewColor.blue());
1530 thePrs->setDeflection(getResultDeflection(aResult));
1531 thePrs->setTransparency(getResultTransparency(aResult));
1533 /// set texture parameters, if any
1534 setTexture(thePrs, aResult);
1536 if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
1537 thePrs->setWidth(2);
1543 //******************************************************
1544 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1547 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1549 /// If last line finished on vertex the lines creation sequence has to be break
1550 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1552 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1553 // if there is an active widget, find the presented object in it
1554 if (!anActiveWidget)
1555 anActiveWidget = aPanel->preselectionWidget();
1557 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1559 if (aWidgetValidated)
1560 anObject = aWidgetValidated->findPresentedObject(theAIS);
1566 //******************************************************
1567 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1569 bool aCanBeShaged = true;
1571 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1573 aCanBeShaged = false;
1575 return aCanBeShaged;
1578 //******************************************************
1579 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1581 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1582 int aSelected = aObjects.size();
1583 SessionPtr aMgr = ModelAPI_Session::get();
1584 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1586 bool hasResult = false;
1587 bool hasFeature = false;
1588 bool hasParameter = false;
1589 bool hasCompositeOwner = false;
1590 bool hasResultInHistory = false;
1591 bool hasFolder = false;
1592 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1593 hasCompositeOwner, hasResultInHistory, hasFolder);
1595 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1596 if (aSelected == 1) {
1597 ObjectPtr aObject = aObjects.first();
1599 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1600 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1601 bool isPart = aPart.get() ||
1602 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1604 DocumentPtr aPartDoc;
1606 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1608 if (aPart.get()) // this may be null is Part feature is disabled
1609 aPartDoc = aPart->partDoc();
1611 theMenu->addAction(aActivatePartAction);
1612 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1614 } else if (aObject->document() == aMgr->activeDocument()) {
1615 if (hasParameter || hasFeature) {
1617 // disable Edit menu for groups under ImportResult feature
1618 bool isEnabled = true;
1619 if (aFeature.get() && aFeature->getKind() == "Group")
1621 std::shared_ptr<ModelAPI_CompositeFeature> anOwner =
1622 ModelAPI_Tools::compositeOwner (aFeature);
1624 if (anOwner.get() && anOwner->getKind() == "ImportResult")
1626 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1633 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1634 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1635 if (aCurrentOp && aFeature.get()) {
1636 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1637 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1645 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1646 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1647 theMenu->addSeparator();
1650 bool aNotDeactivate = (aCurrentOp == 0);
1651 if (!aNotDeactivate) {
1652 aActivatePartAction->setEnabled(false);
1656 //******************************************************
1657 #define EXPAND_PARENT(OBJ) \
1658 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1659 if (aObjIndex.isValid()) { \
1660 QModelIndex aParent = aObjIndex.parent(); \
1661 int aCount = aDataModel->rowCount(aParent); \
1663 aTreeView->setExpanded(aParent, true); \
1666 //******************************************************
1667 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1669 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1670 SessionPtr aMgr = ModelAPI_Session::get();
1671 if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation
1673 // Do not change activation of parts if an operation active
1674 static QStringList aAllowActivationList;
1675 if (aAllowActivationList.isEmpty())
1676 aAllowActivationList <<
1677 QString(PartSetPlugin_Part::ID().c_str()) <<
1678 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1679 QString(PartSetPlugin_Remove::ID().c_str());
1680 if (myWorkshop->currentOperation() &&
1681 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1683 XGUI_Workshop* aWorkshop = getWorkshop();
1684 bool needUpdate = false;
1685 XGUI_DataTree* aTreeView = 0;
1686 if (aWorkshop->objectBrowser()) {
1687 aTreeView = aWorkshop->objectBrowser()->treeView();
1688 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1689 QPalette aPalet = aLabel->palette();
1691 DocumentPtr aActiveDoc = aMgr->activeDocument();
1693 // Clear active part index if there is no Part documents
1694 // It could be not null if document was closed and opened a new
1695 // without closeDocument call
1696 if (aMgr->allOpenedDocuments().size() <= 1)
1697 myActivePartIndex = QModelIndex();
1699 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1700 QModelIndex aOldActive = myActivePartIndex;
1701 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1702 if (myActivePartIndex.isValid()) {
1703 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1705 aTreeView->setExpanded(myActivePartIndex, true);
1707 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1708 aTreeView->setExpanded(aOldActive, false);
1710 aLabel->setPalette(aPalet);
1712 aWorkshop->updateCommandStatus();
1714 // Update displayed objects in order to update active color
1715 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1716 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1718 foreach(ObjectPtr aObj, aObjects) {
1719 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1720 aObj->isDisabled() || (!aObj->isDisplayed());
1722 aDisplayer->redisplay(aObj, false);
1725 aDisplayer->updateViewer();
1726 // Update tree items if they are expanded
1728 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1730 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1731 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1732 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1733 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1735 ObjectPtr aConstrObj;
1736 ObjectPtr aResultObj;
1737 std::set<ObjectPtr>::const_iterator aIt;
1738 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1739 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1740 ObjectPtr aObject = (*aIt);
1741 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1742 && (aObject->document() != aRootDoc))
1743 aResultObj = aObject;
1744 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1745 && (aObject->document() != aRootDoc))
1746 aConstrObj = aObject;
1747 if (aResultObj.get() && aConstrObj.get())
1751 if (aResultObj.get() || aConstrObj.get()) {
1752 XGUI_Workshop* aWorkshop = getWorkshop();
1753 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1754 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1756 if (aResultObj.get()) {
1757 EXPAND_PARENT(aResultObj)
1759 if (aConstrObj.get()) {
1760 EXPAND_PARENT(aConstrObj)
1764 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1765 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1766 if (aSketch.get()) {
1767 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1768 if (PartSet_SketcherMgr::isSketchOperation(anOperation) &&
1769 mySketchMgr->previewSketchPlane()->isDisplayed())
1770 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1773 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LICENSE_VALID)) {
1774 std::shared_ptr<ModelAPI_FeaturesLicenseValidMessage> aMsg =
1775 std::dynamic_pointer_cast<ModelAPI_FeaturesLicenseValidMessage>(theMessage);
1776 myFeaturesValidLicense.insert(aMsg->features().begin(), aMsg->features().end());
1777 processProprietaryFeatures();
1781 //******************************************************
1782 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1784 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1786 SessionPtr aMgr = ModelAPI_Session::get();
1787 if (!theIndex.isValid()) {
1788 // It seems that this code is obsolete
1789 //aMgr->setActiveDocument(aMgr->moduleDocument());
1792 if (theIndex.column() != 1) // Use only first column
1795 XGUI_Workshop* aWorkshop = getWorkshop();
1796 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1797 // De not use non editable Indexes
1798 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1800 ObjectPtr aObj = aDataModel->object(theIndex);
1802 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1803 if (!aPart.get()) { // Probably this is Feature
1804 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1805 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1806 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1810 if (!aPart.get() && aObj->groupName() == ModelAPI_ResultParameter::group())
1812 QObjectPtrList aSelectedObjects = aWorkshop->objectBrowser()->selectedObjects();
1813 FeaturePtr aFeature;
1814 ResultParameterPtr aParam;
1815 foreach(ObjectPtr aSelected, aSelectedObjects) {
1816 aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aSelected);
1821 aFeature = ModelAPI_Feature::feature(aParam);
1824 editFeature(aFeature);
1828 if (aPart.get()) { // if this is a part
1829 if (aPart->partDoc() == aMgr->activeDocument()) {
1830 myMenuMgr->activatePartSet();
1832 myMenuMgr->activatePart(aPart);
1837 //******************************************************
1838 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1840 // z layer is created for all started operations in order to visualize operation AIS presentation
1842 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1843 if (aContext.IsNull())
1846 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1847 if (myVisualLayerId == 0) {
1848 if (myVisualLayerId == 0)
1849 aViewer->AddZLayer(myVisualLayerId);
1851 TColStd_SequenceOfInteger aZList;
1852 aViewer->GetAllZLayers(aZList);
1853 bool aFound = false;
1854 for (int i = 1; i <= aZList.Length(); i++) {
1855 if (aZList(i) == myVisualLayerId) {
1861 aViewer->AddZLayer(myVisualLayerId);
1863 // if there is an active operation with validated widget,
1864 // the filters of this widget should be activated in the created view
1865 myWorkshop->selectionActivate()->updateSelectionFilters();
1866 myWorkshop->selectionActivate()->updateSelectionModes();
1869 //******************************************************
1870 void PartSet_Module::widgetStateChanged(int thePreviousState)
1872 mySketchMgr->widgetStateChanged(thePreviousState);
1875 //******************************************************
1876 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1878 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1881 //******************************************************
1882 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1884 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1885 mySketchMgr->stopSketch(theOperation);
1889 //******************************************************
1890 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1892 GeomShapePtr aGeomShape;
1894 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1895 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1896 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1901 //******************************************************
1902 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1903 const GeomShapePtr& theGeomShape)
1905 AttributePtr anAttribute;
1906 GeomShapePtr aGeomShape = theGeomShape;
1907 if (!aGeomShape.get()) {
1908 // processing shape of result, e.g. sketch circle center is selected, this is a result
1909 // the geom shape is empty, the shape of result should be used
1910 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1911 if (aResult.get()) {
1912 aGeomShape = aResult->shape();
1916 if (aGeomShape.get()) {
1917 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1918 std::pair<AttributePtr, int> anAttrAndIndex =
1919 PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, mySketchMgr->activeSketch());
1920 return anAttrAndIndex.first;
1925 //******************************************************
1926 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1928 return sketchReentranceMgr()->reentrantMessage();
1931 //******************************************************
1932 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1934 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1937 //******************************************************
1938 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1941 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1945 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1946 if (!aChoiceTitle.isEmpty()) {
1947 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1950 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1952 aPanel->setWindowTitle(aChoiceTitle);
1956 //******************************************************
1957 XGUI_Workshop* PartSet_Module::getWorkshop() const
1959 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1960 return aConnector->workshop();
1963 void PartSet_Module::setDefaultConstraintShown()
1965 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1966 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1967 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1970 //******************************************************
1971 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1976 //******************************************************
1977 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1978 myCustomPrs->disableCustomMode(theMode);
1981 //******************************************************
1982 void PartSet_Module::enableCustomModes() {
1983 myCustomPrs->enableCustomModes();
1986 //******************************************************
1987 void PartSet_Module::onRemoveConflictingConstraints()
1989 const std::set<ObjectPtr>& aConstraints = myOverconstraintListener->objectsToRemove();
1990 std::set<ObjectPtr>::const_iterator anIt;
1992 XGUI_Workshop* aWorkshop = getWorkshop();
1993 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
1995 bool isAllowToNotify = ModuleBase_Preferences::resourceMgr()->booleanValue(SKETCH_TAB_NAME,
1996 "notify_change_constraint");
1998 if (isAllowToNotify) {
1999 anIt = aConstraints.begin();
2000 std::string aText("Conflict in constraints: \n");
2002 for (; anIt != aConstraints.end(); anIt++)
2004 ObjectPtr anObject = *anIt;
2005 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
2006 TCollection_AsciiString aStr(aFeature->name().c_str());
2007 std::string aName(aStr.ToCString());
2008 aText += aName + "\n";
2011 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
2012 ModuleBase_Tools::warningAboutConflict(aConnector->desktop(),
2016 ModuleBase_Operation* anOp = anOpMgr->currentOperation();
2017 if (sketchMgr()->isNestedSketchOperation(anOp)) {
2018 std::set<FeaturePtr> aFeatures;
2019 for (anIt = aConstraints.cbegin(); anIt != aConstraints.cend(); anIt++)
2020 aFeatures.insert(ModelAPI_Feature::feature(*anIt));
2022 ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2025 QObjectPtrList anObjectsList;
2026 for (anIt = aConstraints.cbegin(); anIt != aConstraints.cend(); anIt++)
2027 anObjectsList.append(*anIt);
2029 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
2030 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription);
2032 anOpMgr->startOperation(anOpAction);
2033 aWorkshop->deleteFeatures(anObjectsList);
2034 anOpMgr->commitOperation();
2036 ModuleBase_Tools::flushUpdated(sketchMgr()->activeSketch());