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 for (aV3dViewer->InitDefinedViews();
1148 aV3dViewer->MoreDefinedViews();
1149 aV3dViewer->NextDefinedViews()) {
1150 Handle(V3d_View) aV = aV3dViewer->DefinedView();
1151 double aS = aV->Scale();
1160 bool isModified = false;
1161 double aLen = aView->Convert(SketcherPrs_Tools::getConfigArrowSize());
1162 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
1163 if (aCurrentOperation &&
1164 (PartSet_SketcherMgr::isSketchOperation(aCurrentOperation) ||
1165 sketchMgr()->isNestedSketchOperation(aCurrentOperation) ||
1166 (aCurrentOperation->id() == "Measurement")))
1168 SketcherPrs_Tools::setArrowSize(aLen);
1169 const double aCurScale = aViewer->activeView()->Camera()->Scale();
1170 aViewer->SetScale(aViewer->activeView(), aCurScale);
1172 QList<Handle(AIS_InteractiveObject)> aPrsList = aDisplayer->displayedPresentations();
1173 foreach(Handle(AIS_InteractiveObject) aAisObj, aPrsList) {
1175 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
1176 foreach(AISObjectPtr aAIS, aPrsList) {
1177 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
1179 Handle(PrsDim_Dimension) aDim = Handle(PrsDim_Dimension)::DownCast(aAisObj);
1180 if (!aDim.IsNull()) {
1181 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
1182 aContext->Redisplay(aDim, false);
1188 // Manage trihedron arrows
1189 if (Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows")) {
1190 Handle(AIS_Trihedron) aTrihedron = aViewer->trihedron();
1191 if (!aTrihedron.IsNull()) {
1193 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1194 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1195 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1196 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1197 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1198 aContext->Redisplay(aTrihedron, false);
1203 aDisplayer->updateViewer();
1206 //******************************************************
1207 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1209 return myCustomPrs->isActive(theFlag);
1212 //******************************************************
1213 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1214 const ModuleBase_CustomizeFlag& theFlag,
1215 const bool theUpdateViewer)
1217 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1220 //******************************************************
1221 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1222 const bool theUpdateViewer)
1224 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1227 //******************************************************
1228 //bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1229 // std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1231 // bool aCustomized = false;
1233 // XGUI_Workshop* aWorkshop = getWorkshop();
1234 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1235 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1237 // return aCustomized;
1239 // if (!theResult.get()) {
1240 // std::vector<int> aColor;
1241 // XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1242 // if (!aColor.empty()) {
1243 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1246 // // customize dimentional constrains
1247 // sketchMgr()->customisePresentation(anObject);
1249 // return aCustomized;
1252 ////******************************************************
1253 //bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1254 // AISObjectPtr thePrs,
1255 // GeomCustomPrsPtr theCustomPrs)
1257 // bool aCustomized = false;
1259 // XGUI_Workshop* aWorkshop = getWorkshop();
1260 // XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1261 // ObjectPtr anObject = aDisplayer->getObject(thePrs);
1263 // return aCustomized;
1265 // std::vector<int> aColor;
1266 // bool aUseCustomColor = true;
1267 // if (aUseCustomColor)
1268 // myOverconstraintListener->getCustomColor(anObject, aColor);
1269 // // customize sketch symbol presentation
1270 // Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1271 // if (!anAISIO.IsNull()) {
1272 // if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1273 // Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1274 // if (!aPrs.IsNull()) {
1275 // aPrs->SetCustomColor(aColor);
1276 // aCustomized = true;
1278 // } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1279 // Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1280 // if (!aPrs.IsNull()) {
1281 // aPrs->SetCustomColor(aColor);
1282 // aCustomized = true;
1286 // // customize sketch dimension constraint presentation
1287 // if (!aCustomized) {
1288 // if (!aColor.empty()) { // otherwise presentation has the default color
1289 // aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1292 // return aCustomized;
1295 //******************************************************
1296 bool PartSet_Module::customizeFeature(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1297 const bool theUpdateViewer)
1299 bool isRedisplayed = false;
1300 if (myCustomPrs->isActive(theFlag))
1301 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1303 return isRedisplayed;
1306 //******************************************************
1307 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1309 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1311 QLabel* aLabel = aOB->activeDocLabel();
1312 aLabel->installEventFilter(myMenuMgr);
1313 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1314 SLOT(onActiveDocPopup(const QPoint&)));
1315 aOB->treeView()->setExpandsOnDoubleClick(false);
1316 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1317 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1319 Events_Loop* aLoop = Events_Loop::loop();
1320 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1324 //******************************************************
1325 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1327 SessionPtr aMgr = ModelAPI_Session::get();
1328 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1330 XGUI_Workshop* aWorkshop = getWorkshop();
1331 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1333 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1336 aMenu.addAction(aActivatePartAction);
1339 if (aMgr->activeDocument() == aMgr->moduleDocument()) {
1340 DocumentPtr aDoc = aMgr->moduleDocument();
1341 int aNbParts = aDoc->size(ModelAPI_ResultPart::group());
1342 bool aHaveToActivate = false;
1343 for (int i = 0; i < aNbParts; i++) {
1344 ObjectPtr aObj = aDoc->object(ModelAPI_ResultPart::group(), i);
1345 ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1346 if (!aPartRes->partDoc().get()) {
1347 aHaveToActivate = true;
1351 if (aHaveToActivate) {
1352 QAction* aActivateAllPartAction = myMenuMgr->action("ACTIVATE_ALL_PARTS_CMD");
1353 aMenu.addAction(aActivateAllPartAction);
1358 aMenu.exec(aHeader->mapToGlobal(thePnt));
1361 //******************************************************
1362 AISObjectPtr PartSet_Module::createPresentation(const ObjectPtr& theObject)
1364 Handle(AIS_InteractiveObject) anAISPrs = mySketchMgr->createPresentation(theObject);
1365 if (anAISPrs.IsNull()) {
1366 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1367 if (aResult.get()) {
1368 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
1369 if (aShapePtr.get() != NULL)
1370 anAISPrs = new ModuleBase_ResultPrs(aResult);
1373 FieldStepPtr aStep =
1374 std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(theObject);
1376 anAISPrs = new PartSet_FieldStepPrs(aStep);
1381 if (!anAISPrs.IsNull()) {
1382 Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(anAISPrs);
1383 if (!aShapePrs.IsNull())
1384 ModuleBase_Tools::setPointBallHighlighting((AIS_Shape*)aShapePrs.get());
1386 anAIS = AISObjectPtr(new GeomAPI_AISObject());
1387 anAIS->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
1388 customizePresentation(theObject, anAIS);
1393 //******************************************************
1394 double getResultDeflection(const ResultPtr& theResult)
1396 double aDeflection = ModelAPI_Tools::getDeflection(theResult);
1397 if (aDeflection < 0)
1398 aDeflection = PartSet_Tools::getDefaultDeflection(theResult);
1402 //******************************************************
1403 double getResultTransparency(const ResultPtr& theResult)
1405 double aTransparency = ModelAPI_Tools::getTransparency(theResult);
1406 if (aTransparency < 0)
1407 aTransparency = PartSet_Tools::getDefaultTransparency();
1408 return aTransparency;
1411 static AttributeImagePtr findImage(const ObjectPtr& theResult)
1413 AttributeImagePtr anImageAttr;
1415 if (theResult.get()) {
1416 ResultBodyPtr aResultBody =
1417 std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
1418 if (aResultBody.get()) {
1419 anImageAttr = aResultBody->data()->image(ModelAPI_ResultBody::IMAGE_ID());
1420 if (!anImageAttr.get() || !anImageAttr->hasTexture()) {
1421 // try to find an image attribute in parents
1422 ObjectPtr aParent = theResult->document()->parent(theResult);
1423 anImageAttr = findImage(aParent);
1431 //******************************************************
1432 void PartSet_Module::setTexture(const AISObjectPtr& thePrs,
1433 const ResultPtr& theResult)
1435 ResultBodyPtr aResultBody =
1436 std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
1437 if (!aResultBody.get())
1440 AttributeImagePtr anImageAttr = findImage(theResult);
1441 if (!anImageAttr.get() || !anImageAttr->hasTexture())
1444 int aWidth, aHeight;
1445 std::string aFormat;
1446 std::list<unsigned char> aByteList;
1447 anImageAttr->texture(aWidth, aHeight, aByteList, aFormat);
1449 Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
1450 if (!anAIS.IsNull()) {
1451 /// set color to white and change material aspect,
1452 /// in order to keep a natural apect of the image.
1453 thePrs->setColor(255, 255, 255);
1454 Quantity_Color myShadingColor(NCollection_Vec3<float>(1., 1., 1.));
1455 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
1456 if (!anAISShape.IsNull())
1458 auto myDrawer = anAISShape->Attributes();
1460 myDrawer->ShadingAspect()->SetColor(myShadingColor);
1461 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
1462 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
1463 aMatAspect.SetTransparency(0.0);
1464 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
1465 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
1467 //aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
1468 Handle(Image_PixMap) aPixmap = new Image_PixMap();
1469 aPixmap->InitTrash(Image_PixMap::ImgBGRA, aWidth, aHeight);
1470 std::list<unsigned char>::iterator aByteIter = aByteList.begin();
1471 for (int aLine = 0; aLine < aHeight; ++aLine) {
1472 // convert pixels from ARGB to renderer-compatible RGBA
1473 for (int aByte = 0; aByte < aWidth; ++aByte) {
1474 Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
1476 aPixmapBytes.b() = (Standard_Byte) *aByteIter++;
1477 aPixmapBytes.g() = (Standard_Byte) *aByteIter++;
1478 aPixmapBytes.r() = (Standard_Byte) *aByteIter++;
1479 aPixmapBytes.a() = (Standard_Byte) *aByteIter++;
1483 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
1484 (new Graphic3d_Texture2Dmanual(aPixmap));
1485 anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
1487 anAISShape->SetDisplayMode(AIS_Shaded);
1492 //******************************************************
1493 void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
1494 const AISObjectPtr& thePrs) const
1496 if (mySketchMgr->isObjectOfSketch(theObject)) {
1497 mySketchMgr->customizeSketchPresentation(theObject, thePrs);
1500 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1501 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1502 if (aResult.get()) {
1503 std::vector<int> aColor;
1504 bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document());
1505 // Get user defined color for the object
1506 ModelAPI_Tools::getColor(aResult, aColor);
1508 bool isCustomized = false;
1509 if (aColor.empty() && aFeature.get()) {
1510 GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
1511 if (aCustPrs.get()) {
1512 isCustomized = aCustPrs->customisePresentation(aResult, thePrs);
1515 if (!isCustomized) {
1516 if (aColor.empty()) {
1517 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1519 thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1523 if (aColor.empty()) {
1524 PartSet_Tools::getDefaultColor(aResult, false, aColor);
1526 QColor aQColor(aColor[0], aColor[1], aColor[2]);
1528 QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
1529 thePrs->setColor(aNewColor.red(), aNewColor.green(), aNewColor.blue());
1531 thePrs->setDeflection(getResultDeflection(aResult));
1532 thePrs->setTransparency(getResultTransparency(aResult));
1534 /// set texture parameters, if any
1535 setTexture(thePrs, aResult);
1537 if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
1538 thePrs->setWidth(2);
1544 //******************************************************
1545 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1548 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1550 /// If last line finished on vertex the lines creation sequence has to be break
1551 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1553 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1554 // if there is an active widget, find the presented object in it
1555 if (!anActiveWidget)
1556 anActiveWidget = aPanel->preselectionWidget();
1558 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1560 if (aWidgetValidated)
1561 anObject = aWidgetValidated->findPresentedObject(theAIS);
1567 //******************************************************
1568 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1570 bool aCanBeShaged = true;
1572 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1574 aCanBeShaged = false;
1576 return aCanBeShaged;
1579 //******************************************************
1580 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1582 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1583 int aSelected = aObjects.size();
1584 SessionPtr aMgr = ModelAPI_Session::get();
1585 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1587 bool hasResult = false;
1588 bool hasFeature = false;
1589 bool hasParameter = false;
1590 bool hasCompositeOwner = false;
1591 bool hasResultInHistory = false;
1592 bool hasFolder = false;
1593 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1594 hasCompositeOwner, hasResultInHistory, hasFolder);
1596 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1597 if (aSelected == 1) {
1598 ObjectPtr aObject = aObjects.first();
1600 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1601 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1602 bool isPart = aPart.get() ||
1603 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1605 DocumentPtr aPartDoc;
1607 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1609 if (aPart.get()) // this may be null is Part feature is disabled
1610 aPartDoc = aPart->partDoc();
1612 theMenu->addAction(aActivatePartAction);
1613 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1615 } else if (aObject->document() == aMgr->activeDocument()) {
1616 if (hasParameter || hasFeature) {
1618 // disable Edit menu for groups under ImportResult feature
1619 bool isEnabled = true;
1620 if (aFeature.get() && aFeature->getKind() == "Group")
1622 std::shared_ptr<ModelAPI_CompositeFeature> anOwner =
1623 ModelAPI_Tools::compositeOwner (aFeature);
1625 if (anOwner.get() && anOwner->getKind() == "ImportResult")
1627 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1634 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1635 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1636 if (aCurrentOp && aFeature.get()) {
1637 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1638 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1646 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1647 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1648 theMenu->addSeparator();
1651 bool aNotDeactivate = (aCurrentOp == 0);
1652 if (!aNotDeactivate) {
1653 aActivatePartAction->setEnabled(false);
1657 //******************************************************
1658 #define EXPAND_PARENT(OBJ) \
1659 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1660 if (aObjIndex.isValid()) { \
1661 QModelIndex aParent = aObjIndex.parent(); \
1662 int aCount = aDataModel->rowCount(aParent); \
1664 aTreeView->setExpanded(aParent, true); \
1667 //******************************************************
1668 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1670 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1671 SessionPtr aMgr = ModelAPI_Session::get();
1672 if (!aMgr->hasModuleDocument()) // if document is closed, do not call the document creation
1674 // Do not change activation of parts if an operation active
1675 static QStringList aAllowActivationList;
1676 if (aAllowActivationList.isEmpty())
1677 aAllowActivationList <<
1678 QString(PartSetPlugin_Part::ID().c_str()) <<
1679 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1680 QString(PartSetPlugin_Remove::ID().c_str());
1681 if (myWorkshop->currentOperation() &&
1682 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1684 XGUI_Workshop* aWorkshop = getWorkshop();
1685 bool needUpdate = false;
1686 XGUI_DataTree* aTreeView = 0;
1687 if (aWorkshop->objectBrowser()) {
1688 aTreeView = aWorkshop->objectBrowser()->treeView();
1689 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1690 QPalette aPalet = aLabel->palette();
1692 DocumentPtr aActiveDoc = aMgr->activeDocument();
1694 // Clear active part index if there is no Part documents
1695 // It could be not null if document was closed and opened a new
1696 // without closeDocument call
1697 if (aMgr->allOpenedDocuments().size() <= 1)
1698 myActivePartIndex = QModelIndex();
1700 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1701 QModelIndex aOldActive = myActivePartIndex;
1702 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc, 0);
1703 if (myActivePartIndex.isValid()) {
1704 needUpdate = aTreeView->isExpanded(myActivePartIndex);
1706 aTreeView->setExpanded(myActivePartIndex, true);
1708 if ((aOldActive != myActivePartIndex) && (aOldActive.isValid()))
1709 aTreeView->setExpanded(aOldActive, false);
1711 aLabel->setPalette(aPalet);
1713 aWorkshop->updateCommandStatus();
1715 // Update displayed objects in order to update active color
1716 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1717 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1719 foreach(ObjectPtr aObj, aObjects) {
1720 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1721 aObj->isDisabled() || (!aObj->isDisplayed());
1723 aDisplayer->redisplay(aObj, false);
1726 aDisplayer->updateViewer();
1727 // Update tree items if they are expanded
1729 aTreeView->viewport()->update(aTreeView->viewport()->rect());
1731 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1732 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1733 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1734 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1736 ObjectPtr aConstrObj;
1737 ObjectPtr aResultObj;
1738 std::set<ObjectPtr>::const_iterator aIt;
1739 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1740 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1741 ObjectPtr aObject = (*aIt);
1742 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1743 && (aObject->document() != aRootDoc))
1744 aResultObj = aObject;
1745 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1746 && (aObject->document() != aRootDoc))
1747 aConstrObj = aObject;
1748 if (aResultObj.get() && aConstrObj.get())
1752 if (aResultObj.get() || aConstrObj.get()) {
1753 XGUI_Workshop* aWorkshop = getWorkshop();
1754 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1755 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1757 if (aResultObj.get()) {
1758 EXPAND_PARENT(aResultObj)
1760 if (aConstrObj.get()) {
1761 EXPAND_PARENT(aConstrObj)
1765 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
1766 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
1767 if (aSketch.get()) {
1768 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1769 if (PartSet_SketcherMgr::isSketchOperation(anOperation) &&
1770 mySketchMgr->previewSketchPlane()->isDisplayed())
1771 mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
1774 else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LICENSE_VALID)) {
1775 std::shared_ptr<ModelAPI_FeaturesLicenseValidMessage> aMsg =
1776 std::dynamic_pointer_cast<ModelAPI_FeaturesLicenseValidMessage>(theMessage);
1777 myFeaturesValidLicense.insert(aMsg->features().begin(), aMsg->features().end());
1778 processProprietaryFeatures();
1782 //******************************************************
1783 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1785 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1787 SessionPtr aMgr = ModelAPI_Session::get();
1788 if (!theIndex.isValid()) {
1789 // It seems that this code is obsolete
1790 //aMgr->setActiveDocument(aMgr->moduleDocument());
1793 if (theIndex.column() != 1) // Use only first column
1796 XGUI_Workshop* aWorkshop = getWorkshop();
1797 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1798 // De not use non editable Indexes
1799 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1801 ObjectPtr aObj = aDataModel->object(theIndex);
1803 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1804 if (!aPart.get()) { // Probably this is Feature
1805 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1806 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1807 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1811 if (!aPart.get() && aObj->groupName() == ModelAPI_ResultParameter::group())
1813 QObjectPtrList aObjects = aWorkshop->objectBrowser()->selectedObjects();
1814 FeaturePtr aFeature;
1815 ResultParameterPtr aParam;
1816 foreach(ObjectPtr aObj, aObjects) {
1817 aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObj);
1822 aFeature = ModelAPI_Feature::feature(aParam);
1825 editFeature(aFeature);
1829 if (aPart.get()) { // if this is a part
1830 if (aPart->partDoc() == aMgr->activeDocument()) {
1831 myMenuMgr->activatePartSet();
1833 myMenuMgr->activatePart(aPart);
1838 //******************************************************
1839 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1841 // z layer is created for all started operations in order to visualize operation AIS presentation
1843 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1844 if (aContext.IsNull())
1847 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1848 if (myVisualLayerId == 0) {
1849 if (myVisualLayerId == 0)
1850 aViewer->AddZLayer(myVisualLayerId);
1852 TColStd_SequenceOfInteger aZList;
1853 aViewer->GetAllZLayers(aZList);
1854 bool aFound = false;
1855 for (int i = 1; i <= aZList.Length(); i++) {
1856 if (aZList(i) == myVisualLayerId) {
1862 aViewer->AddZLayer(myVisualLayerId);
1864 // if there is an active operation with validated widget,
1865 // the filters of this widget should be activated in the created view
1866 myWorkshop->selectionActivate()->updateSelectionFilters();
1867 myWorkshop->selectionActivate()->updateSelectionModes();
1870 //******************************************************
1871 void PartSet_Module::widgetStateChanged(int thePreviousState)
1873 mySketchMgr->widgetStateChanged(thePreviousState);
1876 //******************************************************
1877 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1879 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1882 //******************************************************
1883 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1885 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1886 mySketchMgr->stopSketch(theOperation);
1890 //******************************************************
1891 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1893 GeomShapePtr aGeomShape;
1895 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1896 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1897 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1902 //******************************************************
1903 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1904 const GeomShapePtr& theGeomShape)
1906 AttributePtr anAttribute;
1907 GeomShapePtr aGeomShape = theGeomShape;
1908 if (!aGeomShape.get()) {
1909 // processing shape of result, e.g. sketch circle center is selected, this is a result
1910 // the geom shape is empty, the shape of result should be used
1911 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1912 if (aResult.get()) {
1913 aGeomShape = aResult->shape();
1917 if (aGeomShape.get()) {
1918 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1919 std::pair<AttributePtr, int> anAttrAndIndex =
1920 PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, mySketchMgr->activeSketch());
1921 return anAttrAndIndex.first;
1926 //******************************************************
1927 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1929 return sketchReentranceMgr()->reentrantMessage();
1932 //******************************************************
1933 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1935 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1938 //******************************************************
1939 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1942 ModuleBase_WidgetChoice* aChoiceWidget = dynamic_cast<ModuleBase_WidgetChoice*>(theWidget);
1946 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1947 if (!aChoiceTitle.isEmpty()) {
1948 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1951 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1953 aPanel->setWindowTitle(aChoiceTitle);
1957 //******************************************************
1958 XGUI_Workshop* PartSet_Module::getWorkshop() const
1960 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1961 return aConnector->workshop();
1964 void PartSet_Module::setDefaultConstraintShown()
1966 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1967 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1968 myHasConstraintShown[PartSet_Tools::Expressions] = false;
1971 //******************************************************
1972 ModuleBase_ITreeNode* PartSet_Module::rootNode() const
1977 //******************************************************
1978 void PartSet_Module::disableCustomMode(ModuleBase_CustomizeFlag theMode) {
1979 myCustomPrs->disableCustomMode(theMode);
1982 //******************************************************
1983 void PartSet_Module::enableCustomModes() {
1984 myCustomPrs->enableCustomModes();
1987 //******************************************************
1988 void PartSet_Module::onRemoveConflictingConstraints()
1990 const std::set<ObjectPtr>& aConstraints = myOverconstraintListener->objectsToRemove();
1991 std::set<ObjectPtr>::const_iterator anIt;
1993 XGUI_Workshop* aWorkshop = getWorkshop();
1994 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
1996 bool isAllowToNotify = ModuleBase_Preferences::resourceMgr()->booleanValue(SKETCH_TAB_NAME,
1997 "notify_change_constraint");
1999 if (isAllowToNotify) {
2000 anIt = aConstraints.begin();
2001 std::string aText("Conflict in constraints: \n");
2003 for (; anIt != aConstraints.end(); anIt++)
2005 ObjectPtr anObject = *anIt;
2006 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
2007 TCollection_AsciiString aStr(aFeature->name().c_str());
2008 std::string aName(aStr.ToCString());
2009 aText += aName + "\n";
2012 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
2013 ModuleBase_Tools::warningAboutConflict(aConnector->desktop(),
2017 ModuleBase_Operation* anOp = anOpMgr->currentOperation();
2018 if (sketchMgr()->isNestedSketchOperation(anOp)) {
2019 std::set<FeaturePtr> aFeatures;
2020 for (anIt = aConstraints.cbegin(); anIt != aConstraints.cend(); anIt++)
2021 aFeatures.insert(ModelAPI_Feature::feature(*anIt));
2023 ModelAPI_Tools::removeFeaturesAndReferences(aFeatures);
2026 QObjectPtrList anObjectsList;
2027 for (anIt = aConstraints.cbegin(); anIt != aConstraints.cend(); anIt++)
2028 anObjectsList.append(*anIt);
2030 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
2031 ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription);
2033 anOpMgr->startOperation(anOpAction);
2034 aWorkshop->deleteFeatures(anObjectsList);
2035 anOpMgr->commitOperation();
2037 ModuleBase_Tools::flushUpdated(sketchMgr()->activeSketch());