1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "PartSet_Module.h"
4 #include "PartSet_WidgetSketchLabel.h"
5 #include "PartSet_Validators.h"
6 #include "PartSet_Tools.h"
7 #include "PartSet_PreviewPlanes.h"
8 #include "PartSet_WidgetPoint2d.h"
9 #include "PartSet_WidgetPoint2dDistance.h"
10 #include "PartSet_WidgetPoint2DFlyout.h"
11 #include "PartSet_WidgetShapeSelector.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetSubShapeSelector.h"
14 #include "PartSet_WidgetEditor.h"
15 #include "PartSet_WidgetFileSelector.h"
16 #include "PartSet_WidgetSketchCreator.h"
17 #include "PartSet_SketcherMgr.h"
18 #include "PartSet_SketcherReetntrantMgr.h"
19 #include "PartSet_ResultSketchPrs.h"
20 #include "PartSet_MenuMgr.h"
21 #include "PartSet_CustomPrs.h"
22 #include "PartSet_IconFactory.h"
23 #include "PartSet_WidgetChoice.h"
24 #include "PartSet_OverconstraintListener.h"
26 #include "PartSet_Filters.h"
27 #include "PartSet_FilterInfinite.h"
29 #include <PartSetPlugin_Remove.h>
30 #include <PartSetPlugin_Part.h>
31 #include <PartSetPlugin_Duplicate.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationAction.h>
35 #include <ModuleBase_IViewer.h>
36 #include <ModuleBase_IViewWindow.h>
37 #include <ModuleBase_IPropertyPanel.h>
38 #include <ModuleBase_WidgetEditor.h>
39 #include <ModuleBase_WidgetValidated.h>
40 #include <ModuleBase_FilterFactory.h>
41 #include <ModuleBase_Tools.h>
42 #include <ModuleBase_OperationFeature.h>
43 #include <ModuleBase_WidgetFactory.h>
44 #include <ModuleBase_OperationDescription.h>
45 #include <ModuleBase_ViewerPrs.h>
47 #include <ModelAPI_Object.h>
48 #include <ModelAPI_Events.h>
49 #include <ModelAPI_Validator.h>
50 #include <ModelAPI_Data.h>
51 #include <ModelAPI_Session.h>
52 #include <ModelAPI_ResultBody.h>
53 #include <ModelAPI_AttributeString.h>
54 #include <ModelAPI_AttributeSelectionList.h>
55 #include <ModelAPI_Tools.h>
57 #include <GeomDataAPI_Point2D.h>
58 #include <GeomDataAPI_Point.h>
59 #include <GeomDataAPI_Dir.h>
61 #include <XGUI_Displayer.h>
62 #include <XGUI_Workshop.h>
63 #include <XGUI_OperationMgr.h>
64 #include <XGUI_PropertyPanel.h>
65 #include <XGUI_ModuleConnector.h>
66 #include <XGUI_ContextMenuMgr.h>
67 #include <XGUI_Tools.h>
68 #include <XGUI_ObjectsBrowser.h>
69 #include <XGUI_SelectionMgr.h>
70 #include <XGUI_DataModel.h>
71 #include <XGUI_ErrorMgr.h>
72 #include <XGUI_CustomPrs.h>
73 #include <XGUI_SelectionMgr.h>
74 #include <XGUI_ActionsMgr.h>
76 #include <SketchPlugin_Feature.h>
77 #include <SketchPlugin_Sketch.h>
78 #include <SketchPlugin_ConstraintAngle.h>
79 #include <SketchPlugin_ConstraintLength.h>
80 #include <SketchPlugin_ConstraintDistance.h>
81 #include <SketchPlugin_ConstraintParallel.h>
82 #include <SketchPlugin_ConstraintPerpendicular.h>
83 #include <SketchPlugin_ConstraintRadius.h>
85 #include <SketcherPrs_SymbolPrs.h>
86 #include <SketcherPrs_Coincident.h>
87 #include <SketcherPrs_Tools.h>
89 #include <Events_Loop.h>
90 #include <Config_PropManager.h>
91 #include <Config_Keywords.h>
93 #include <StdSelect_TypeOfFace.hxx>
94 #include <TopoDS_Vertex.hxx>
96 #include <TopoDS_Shape.hxx>
97 #include <BRep_Tool.hxx>
98 #include <AIS_Dimension.hxx>
101 #include <QMouseEvent>
104 #include <QApplication>
105 #include <QMessageBox>
106 #include <QMainWindow>
110 #include <GeomAlgoAPI_FaceBuilder.h>
111 #include <GeomDataAPI_Dir.h>
113 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
119 /*!Create and return new instance of XGUI_Module*/
120 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
122 return new PartSet_Module(theWshop);
125 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
126 : ModuleBase_IModule(theWshop),
128 myIsOperationIsLaunched(false)
130 new PartSet_IconFactory();
132 mySketchMgr = new PartSet_SketcherMgr(this);
133 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
135 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
136 XGUI_Workshop* aWorkshop = aConnector->workshop();
138 ModuleBase_IViewer* aViewer = theWshop->viewer();
139 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
140 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
141 connect(aViewer, SIGNAL(viewTransformed(int)),
142 SLOT(onViewTransformed(int)));
143 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
144 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
145 myMenuMgr = new PartSet_MenuMgr(this);
146 myCustomPrs = new PartSet_CustomPrs(theWshop);
148 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
150 Events_Loop* aLoop = Events_Loop::loop();
151 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
153 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
154 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
156 setDefaultConstraintShown();
158 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
159 "Reference shape wireframe color in operation", Config_Prop::Color,
160 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
161 Config_PropManager::registerProp("Visualization", "operation_result_color",
162 "Result shape wireframe color in operation", Config_Prop::Color,
163 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
164 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
165 "Multi selector item color in operation", Config_Prop::Color,
166 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
169 PartSet_Module::~PartSet_Module()
171 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
172 for (; aIt.More(); aIt.Next()) {
173 Handle(SelectMgr_Filter) aFilter = aIt.Value();
174 if (!aFilter.IsNull())
178 delete myOverconstraintListener;
181 void PartSet_Module::activateSelectionFilters()
183 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
184 for (; aIt.More(); aIt.Next()) {
185 Handle(SelectMgr_Filter) aFilter = aIt.Value();
186 if (!aFilter.IsNull())
187 myWorkshop->viewer()->addSelectionFilter(aFilter);
191 void PartSet_Module::deactivateSelectionFilters()
193 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
194 for (; aIt.More(); aIt.Next()) {
195 Handle(SelectMgr_Filter) aFilter = aIt.Value();
196 if (!aFilter.IsNull())
197 myWorkshop->viewer()->removeSelectionFilter(aFilter);
201 void PartSet_Module::storeSelection()
203 sketchMgr()->storeSelection();
206 void PartSet_Module::restoreSelection()
208 sketchMgr()->restoreSelection();
211 void PartSet_Module::registerValidators()
213 //Registering of validators
214 SessionPtr aMgr = ModelAPI_Session::get();
215 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
216 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
217 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
218 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
219 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
220 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
221 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
222 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
223 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
224 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
225 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
226 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
227 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
228 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
229 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
230 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
231 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
234 void PartSet_Module::registerFilters()
236 //Registering of selection filters
237 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
238 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
241 void PartSet_Module::registerProperties()
243 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::Double,
245 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
246 Config_Prop::Integer, SKETCH_WIDTH);
247 Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
248 "Rotate to plane when selected", Config_Prop::Boolean, "false");
251 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
252 const bool isToConnect)
254 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
257 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
259 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
260 mySketchMgr->commitNestedSketch(theOperation);
263 /// Restart sketcher operations automatically
264 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
266 ModuleBase_OperationFeature* aFOperation =
267 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
268 if (aFOperation && !aFOperation->isEditOperation()) {
269 // the selection is cleared after commit the create operation
270 // in order to do not use the same selected objects in the restarted operation
271 // for common behaviour, the selection is cleared even if the operation is not restarted
272 getWorkshop()->selector()->clearSelection();
277 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
279 /// Restart sketcher operations automatically
280 mySketchReentrantMgr->operationAborted(theOperation);
283 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
285 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
288 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
289 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
291 ModuleBase_ModelWidget* aFilledWidget = 0;
292 bool aPostonedWidgetActivation = false;
294 FeaturePtr aFeature = aFOperation->feature();
295 /// Restart sketcher operations automatically
296 /// it is important to call method of sketch reentrant manager before filling of PP
297 /// because it fills some created feature attributes, these new values should be used
298 /// to fill the property panel
299 mySketchReentrantMgr->operationStarted(theOperation);
301 aWorkshop->fillPropertyPanel(aFOperation);
302 // filling the operation values by the current selection
303 // if the operation can be committed after the controls filling, the method perform should
304 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
305 bool isOperationCommitted = false;
306 if (!aFOperation->isEditOperation()) {
307 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
308 // if there is a greed attribute, automatic commit by preselection
309 // for this feature is prohibited
310 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
311 if (currentOperation() != aFOperation)
312 isOperationCommitted = true;
314 if (aGreedAttributeId.empty()) {
315 // a signal should be emitted before the next widget activation
316 // because, the activation of the next widget will give a focus to the widget.
317 // As a result the value of the widget is initialized.
318 // And commit may happens until the value is entered.
320 if (mySketchReentrantMgr->canBeCommittedByPreselection())
321 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
322 // activate the next obligatory widget
323 if (!isOperationCommitted)
324 aPropertyPanel->activateNextWidget(aFilledWidget);
327 else { // there is a greed widget
328 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
329 std::string aFirstAttributeId = aWidgets.front()->attributeID();
330 // activate next widget after greeded if it is the first widget in the panel
331 // else the first panel widget is already activated by operation start
332 if (aFirstAttributeId == aGreedAttributeId)
333 aPostonedWidgetActivation = true;
336 } if (!isOperationCommitted) {
337 workshop()->updateCommandStatus();
338 aWorkshop->connectToPropertyPanel(true);
339 updateSketcherOnStart(aFOperation);
340 updatePresentationsOnStart(aFOperation);
342 // the objects of the current operation should be deactivated
343 QObjectPtrList anObjects;
344 anObjects.append(aFeature);
345 std::list<ResultPtr> aResults;
346 ModelAPI_Tools::allResults(aFeature, aResults);
347 std::list<ResultPtr>::const_iterator aIt;
348 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
349 anObjects.append(*aIt);
351 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
352 for (; anIt != aLast; anIt++)
353 aWorkshop->deactivateActiveObject(*anIt, false);
354 if (anObjects.size() > 0) {
355 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
356 aDisplayer->updateViewer();
359 if (aPostonedWidgetActivation) {
360 // if the widget is an empty in the chain of activated widgets, the current operation
361 // is restarted. It should be performed after functionality of the operation starting
362 aPropertyPanel->activateNextWidget(aFilledWidget);
367 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
369 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
370 mySketchMgr->startSketch(theOperation);
372 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
373 mySketchMgr->startNestedSketch(theOperation);
377 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
379 ModuleBase_OperationFeature* aFOperation =
380 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
382 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
383 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
387 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
389 ModuleBase_IModule::operationResumed(theOperation);
391 ModuleBase_OperationFeature* aFOperation =
392 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
394 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
395 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
399 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
401 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
402 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
403 bool isModified = isModifiedArgs || isModifiedResults;
405 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
406 mySketchMgr->stopNestedSketch(theOperation);
408 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
409 setDefaultConstraintShown();
411 //VSV: Viewer is updated on feature update and redisplay
413 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
414 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
415 aDisplayer->updateViewer();
418 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
419 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
420 for (; anIt != aLast; anIt++) {
421 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
425 ModuleBase_Operation* PartSet_Module::currentOperation() const
427 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
428 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
429 return anOpMgr->currentOperation();
432 bool PartSet_Module::canUndo() const
434 bool aCanUndo = false;
435 SessionPtr aMgr = ModelAPI_Session::get();
436 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
437 aCanUndo = !aMgr->isOperation();
438 if (!aCanUndo) // check the enable state additionally by sketch manager
439 aCanUndo = aMgr->canUndo();
444 bool PartSet_Module::canRedo() const
446 bool aCanRedo = false;
447 SessionPtr aMgr = ModelAPI_Session::get();
448 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
449 aCanRedo = !aMgr->isOperation();
450 if (!aCanRedo) // check the enable state additionally by sketch manager
451 aCanRedo = aMgr->canRedo();
456 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
459 if (theActionId == "MOVE_CMD") {
460 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
462 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
463 // part features can not be moved in the history.
464 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
471 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
473 // the sketch manager put the restriction to the objects erase
474 return mySketchMgr->canEraseObject(theObject);
477 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
479 // the sketch manager put the restriction to the objects display
480 return mySketchMgr->canDisplayObject(theObject);
483 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
485 mySketchMgr->processHiddenObject(theObjects);
488 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
490 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
492 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
493 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
494 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
495 if (isSketchOp || isNestedOp) {
496 // in active sketch operation it is possible to activate operation object in selection
497 // in the edit operation, e.g. points of the line can be moved when the line is edited
498 ModuleBase_OperationFeature* aFOperation =
499 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
500 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
505 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
507 QMap<int, QAction*>& theMenuActions) const
509 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
512 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
514 myMenuMgr->updateViewerMenu(theStdActions);
517 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
519 bool isEnabledFixed = false;
520 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
521 mySketchReentrantMgr->isInternalEditStarted())
522 isEnabledFixed = true;
523 return isEnabledFixed;
526 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
528 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
529 if (anError.isEmpty())
530 anError = sketchMgr()->getFeatureError(theFeature);
535 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
536 QStringList& theIds) const
538 myMenuMgr->grantedOperationIds(theOperation, theIds);
540 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
541 XGUI_Workshop* aWorkshop = getWorkshop();
542 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
546 void PartSet_Module::activeSelectionModes(QIntList& theModes)
549 if (mySketchMgr->activeSketch().get())
550 PartSet_SketcherMgr::sketchSelectionModes(theModes);
553 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
555 if (theTypes.contains(TopAbs_FACE))
556 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
557 if (theTypes.contains(TopAbs_WIRE))
558 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
561 bool PartSet_Module::isMouseOverWindow()
563 return mySketchMgr->isMouseOverWindow();
566 bool PartSet_Module::isSketchNeutralPointActivated() const
568 bool isNeutralPoint = true;
569 if (sketchReentranceMgr()->isInternalEditStarted())
570 isNeutralPoint = false;
571 if (myIsOperationIsLaunched)
572 isNeutralPoint = false;
574 return isNeutralPoint;
577 void PartSet_Module::closeDocument()
582 void PartSet_Module::clearViewer()
584 myCustomPrs->clearPrs();
586 XGUI_Workshop* aWorkshop = getWorkshop();
587 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
588 aDisplayer->deactivateSelectionFilters();
591 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
593 ModuleBase_OperationFeature* aFOperation =
594 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
598 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
599 // we have to manually activate the sketch label in edit mode
600 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
601 aPanel->activateWidget(aPanel->modelWidgets().first());
604 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
605 QList<ModuleBase_ModelWidget*>& theWidgets) const
607 bool aProcessed = false;
609 ModuleBase_OperationFeature* aFOperation =
610 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
611 XGUI_Workshop* aWorkshop = getWorkshop();
612 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
613 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
614 ModuleBase_ISelection* aSelection = workshop()->selection();
615 // click on a point in sketch leads here with the point is highlighted, not yet selected
616 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
617 if (aPreselection.size() == 1) {
618 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
619 ObjectPtr anObject = aSelectedPrs->object();
621 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
622 FeaturePtr anOpFeature = aFOperation->feature();
623 GeomShapePtr aShape = aSelectedPrs->shape();
624 // click on the digit of dimension constrain comes here
625 // with an empty shape, so we need the check
626 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
627 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
628 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
629 mySketchMgr->activeSketch());
630 if (anAttribute.get()) {
631 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
632 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
634 const std::string anAttributeId = anAttribute->id();
635 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
637 theWidgets = aFactory.getModelWidgets();
638 // it is possible that the point does not present in XML definition,
639 // in this case, we assume that it is not processed by this module
640 // e.g. "Intersection point" feature
641 aProcessed = !theWidgets.isEmpty();
649 void PartSet_Module::onSelectionChanged()
651 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
655 bool isSketcherOp = false;
656 // An edit operation is enable only if the current opeation is the sketch operation
657 if (mySketchMgr->activeSketch()) {
658 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
659 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
662 // Editing of constraints can be done on selection
663 ModuleBase_ISelection* aSelect = myWorkshop->selection();
664 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
665 if (aSelected.size() == 1) {
666 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
667 ObjectPtr aObject = aPrs->object();
668 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
670 std::string aId = aFeature->getKind();
671 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
672 (aId == SketchPlugin_ConstraintLength::ID()) ||
673 (aId == SketchPlugin_ConstraintDistance::ID()) ||
674 (aId == SketchPlugin_ConstraintAngle::ID())) {
675 editFeature(aFeature);
682 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
684 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
685 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
686 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
689 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
691 Config_WidgetAPI* theWidgetApi)
693 ModuleBase_IWorkshop* aWorkshop = workshop();
694 XGUI_Workshop* aXUIWorkshop = getWorkshop();
695 ModuleBase_ModelWidget* aWgt = NULL;
696 if (theType == "sketch-start-label") {
697 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
698 theWidgetApi, myHasConstraintShown);
699 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
700 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
701 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
702 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
704 } else if (theType == "sketch-2dpoint_selector") {
705 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
707 aPointWgt->setSketch(mySketchMgr->activeSketch());
708 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
710 }else if (theType == "sketch-2dpoint_flyout_selector") {
711 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
713 aPointWgt->setSketch(mySketchMgr->activeSketch());
714 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
716 } else if (theType == "point2ddistance") {
717 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
718 aWorkshop, theWidgetApi);
719 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
721 } else if (theType == "sketch_shape_selector") {
722 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
723 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
724 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
725 aWgt = aShapeSelectorWgt;
726 } else if (theType == "sketch_multi_selector") {
727 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
728 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
729 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
730 aWgt = aShapeSelectorWgt;
732 else if (theType == "sketch_sub_shape_selector") {
733 PartSet_WidgetSubShapeSelector* aSubShapeSelectorWgt =
734 new PartSet_WidgetSubShapeSelector(theParent, aWorkshop, theWidgetApi);
735 aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
736 aWgt = aSubShapeSelectorWgt;
738 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
739 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
740 } else if (theType == "export_file_selector") {
741 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
742 } else if (theType == "sketch_launcher") {
743 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
744 } else if (theType == "module_choice") {
745 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
746 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
747 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
752 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
754 ModuleBase_ModelWidget* anActiveWidget = 0;
756 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
757 if (!anActiveWidget) {
758 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
760 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
761 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
764 return anActiveWidget;
767 bool PartSet_Module::deleteObjects()
769 bool isProcessed = false;
771 XGUI_Workshop* aWorkshop = getWorkshop();
772 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
774 //SessionPtr aMgr = ModelAPI_Session::get();
775 // 1. check whether the delete should be processed in the module
776 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
777 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
778 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
779 if (isSketchOp || isNestedOp) {
781 // 2. find selected presentations
782 // selected objects should be collected before the current operation abort because
783 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
784 ModuleBase_ISelection* aSel = workshop()->selection();
785 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
786 // if there are no selected objects in the viewer, that means that the selection in another
787 // place cased this method. It is necessary to return the false value to understande in above
788 // method that delete is not processed
789 if (aSelectedObj.count() == 0)
792 // avoid delete of the objects, which are not belong to the current sketch
793 // in order to do not delete results of other sketches
794 QObjectPtrList aSketchObjects;
795 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
796 for ( ; anIt != aLast; anIt++) {
797 ObjectPtr anObject = *anIt;
798 if (mySketchMgr->isObjectOfSketch(anObject)) {
799 // sketch feature should be used in this list because workshop deletes features only
800 // results are skipped
801 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
802 aSketchObjects.append(aSketchFeature);
805 // if the selection contains only local selected presentations from other sketches,
806 // the Delete operation should not be done at all
807 if (aSketchObjects.size() == 0)
810 // 3. start operation
811 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
812 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
814 // the active nested sketch operation should be aborted unconditionally
815 // the Delete action should be additionally granted for the Sketch operation
816 // in order to do not abort/commit it
817 if (!anOpMgr->canStartOperation(anOpAction->id()))
818 return true; // the objects are processed but can not be deleted
820 anOpMgr->startOperation(anOpAction);
822 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
823 // the problem is in AIS Dimensions recompute
824 // if a line and the dim are removed, line is the first
825 // it causes the AIS recompute, where the base line is null,
826 // the result is empty AIS in the viewer
827 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
829 // 4. delete features
830 // sketch feature should be skipped, only sub-features can be removed
831 // when sketch operation is active
832 aWorkshop->deleteFeatures(aSketchObjects);
834 anOpMgr->commitOperation();
839 void PartSet_Module::onFeatureTriggered()
841 // is commented for imp: Unpressing the button of the current action must behave like
842 // a validation if the entity can be created (instead of Cancel, as currently)
843 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
844 if (aCmd->isCheckable() && aCmd->isChecked()) {
845 // 1. check whether the delete should be processed in the module
846 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
847 bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
849 // in case if in the viewer nothing is displayed, the create operation should not be
850 // comitted even if all values of the feature are initialized
851 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
852 // the action information should be saved before the operation is aborted
853 // because this abort leads to update command status, which unchecks this action
854 anOperation->abort();
855 launchOperation(aCmd->data().toString());
859 ModuleBase_IModule::onFeatureTriggered();
862 void PartSet_Module::editFeature(FeaturePtr theFeature)
864 storeConstraintsState(theFeature->getKind());
865 ModuleBase_IModule::editFeature(theFeature);
868 bool PartSet_Module::canCommitOperation() const
873 void PartSet_Module::launchOperation(const QString& theCmdId)
875 myIsOperationIsLaunched = true;
876 storeConstraintsState(theCmdId.toStdString());
877 updateConstraintsState(theCmdId.toStdString());
879 ModuleBase_IModule::launchOperation(theCmdId);
881 myIsOperationIsLaunched = false;
884 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
886 if (myWorkshop->currentOperation() &&
887 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
888 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
889 mySketchMgr->showConstraintStates();
890 myHasConstraintShown = aShownStates;
894 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
896 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
897 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
898 // Show constraints if a constraint was anOperation
899 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
900 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
901 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
902 myHasConstraintShown[PartSet_Tools::Expressions]);
906 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
908 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
909 if (!anAIS.IsNull()) {
910 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
911 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
912 if (!aDim.IsNull()) {
913 aCtx->SetZLayer(aDim, myVisualLayerId);
915 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
917 aCtx->SetZLayer(aCons, myVisualLayerId);
922 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
925 // it should be recomputed in order to disappear in the viewer if the corresponded object
927 //if (myCustomPrs->isActive())
928 // myCustomPrs->redisplay(theObject, false);
931 void PartSet_Module::onViewTransformed(int theTrsfType)
933 // Set length of arrows constant in pixel size
934 // if the operation is panning or rotate or panglobal then do nothing
935 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
937 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
938 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
939 if (aContext.IsNull())
942 //Handle(V3d_View) aView = aViewer->activeView();
944 XGUI_Workshop* aWorkshop = getWorkshop();
945 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
946 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
947 Handle(V3d_View) aView;
949 for (aV3dViewer->InitDefinedViews();
950 aV3dViewer->MoreDefinedViews();
951 aV3dViewer->NextDefinedViews()) {
952 Handle(V3d_View) aV = aV3dViewer->DefinedView();
953 double aS = aV->Scale();
961 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
963 double aPrevLen = SketcherPrs_Tools::getArrowSize();
964 SketcherPrs_Tools::setArrowSize(aLen);
965 const double aPrevScale = aViewer->Scale(aViewer->activeView());
966 const double aCurScale = aViewer->activeView()->Camera()->Scale();
967 aViewer->SetScale(aViewer->activeView(), aCurScale);
968 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
969 bool isModified = false;
970 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
971 foreach (AISObjectPtr aAIS, aPrsList) {
972 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
974 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
975 if (!aDim.IsNull()) {
976 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
977 aContext->Redisplay(aDim, false);
982 aDisplayer->updateViewer();
985 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
987 return myCustomPrs->isActive(theFlag);
990 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
991 const ModuleBase_CustomizeFlag& theFlag,
992 const bool theUpdateViewer)
994 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
997 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
998 const bool theUpdateViewer)
1000 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1003 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1004 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1006 bool aCustomized = false;
1008 XGUI_Workshop* aWorkshop = getWorkshop();
1009 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1010 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1014 if (!theResult.get()) {
1015 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
1016 // customize sketch symbol presentation
1018 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1019 if (!anAISIO.IsNull()) {
1020 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1021 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1022 if (!aPrs.IsNull()) {
1023 std::vector<int> aColor;
1024 myOverconstraintListener->getConflictingColor(aColor);
1025 aPrs->SetConflictingConstraint(isConflicting, aColor);
1028 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1029 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1030 if (!aPrs.IsNull()) {
1031 std::vector<int> aColor;
1032 myOverconstraintListener->getConflictingColor(aColor);
1033 aPrs->SetConflictingConstraint(isConflicting, aColor);
1039 // customize sketch dimension constraint presentation
1041 std::vector<int> aColor;
1042 if (isConflicting) {
1043 myOverconstraintListener->getConflictingColor(aColor);
1046 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1047 if (!aColor.empty()) {
1048 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1052 // customize dimentional constrains
1053 sketchMgr()->customizePresentation(anObject);
1058 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1059 const bool theUpdateViewer)
1061 bool isRedisplayed = false;
1062 if (myCustomPrs->isActive(theFlag))
1063 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1065 return isRedisplayed;
1068 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1070 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1072 QLabel* aLabel = aOB->activeDocLabel();
1073 aLabel->installEventFilter(myMenuMgr);
1074 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1075 SLOT(onActiveDocPopup(const QPoint&)));
1076 //QPalette aPalet = aLabel->palette();
1077 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
1078 //aLabel->setPalette(aPalet);
1079 aOB->treeView()->setExpandsOnDoubleClick(false);
1080 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1081 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1085 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1087 SessionPtr aMgr = ModelAPI_Session::get();
1088 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1090 XGUI_Workshop* aWorkshop = getWorkshop();
1091 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1093 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1096 aMenu.addAction(aActivatePartAction);
1097 aMenu.exec(aHeader->mapToGlobal(thePnt));
1100 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1102 return mySketchMgr->createPresentation(theResult);
1106 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1109 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1111 /// If last line finished on vertex the lines creation sequence has to be break
1112 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1114 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1115 // if there is an active widget, find the presented object in it
1116 if (!anActiveWidget)
1117 anActiveWidget = aPanel->preselectionWidget();
1119 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1121 if (aWidgetValidated)
1122 anObject = aWidgetValidated->findPresentedObject(theAIS);
1128 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1130 bool aCanBeShaged = true;
1132 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1134 aCanBeShaged = false;
1136 return aCanBeShaged;
1139 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1141 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1142 int aSelected = aObjects.size();
1143 SessionPtr aMgr = ModelAPI_Session::get();
1144 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1146 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1147 if (aSelected == 1) {
1148 bool hasResult = false;
1149 bool hasFeature = false;
1150 bool hasParameter = false;
1151 bool hasCompositeOwner = false;
1152 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1154 ObjectPtr aObject = aObjects.first();
1156 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1157 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1158 bool isPart = aPart.get() ||
1159 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1161 DocumentPtr aPartDoc;
1163 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1165 if (aPart.get()) // this may be null is Part feature is disabled
1166 aPartDoc = aPart->partDoc();
1168 theMenu->addAction(aActivatePartAction);
1169 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1171 } else if (aObject->document() == aMgr->activeDocument()) {
1172 if (hasParameter || hasFeature) {
1173 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1174 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1175 if (aCurrentOp && aFeature.get()) {
1176 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1177 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1182 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1184 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1187 bool aNotDeactivate = (aCurrentOp == 0);
1188 if (!aNotDeactivate) {
1189 aActivatePartAction->setEnabled(false);
1193 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1195 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1196 // Do not change activation of parts if an operation active
1197 static QStringList aAllowActivationList;
1198 if (aAllowActivationList.isEmpty())
1199 aAllowActivationList <<
1200 QString(PartSetPlugin_Part::ID().c_str()) <<
1201 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1202 QString(PartSetPlugin_Remove::ID().c_str());
1203 if (myWorkshop->currentOperation() &&
1204 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1206 XGUI_Workshop* aWorkshop = getWorkshop();
1207 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1208 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1209 QPalette aPalet = aLabel->palette();
1211 SessionPtr aMgr = ModelAPI_Session::get();
1212 DocumentPtr aActiveDoc = aMgr->activeDocument();
1213 if (aActivePartIndex.isValid())
1214 aTreeView->setExpanded(aActivePartIndex, false);
1215 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1216 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1217 if (aActivePartIndex.isValid())
1218 aTreeView->setExpanded(aActivePartIndex, true);
1220 aLabel->setPalette(aPalet);
1221 aWorkshop->updateCommandStatus();
1223 // Update displayed objects in order to update active color
1224 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1225 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1227 foreach(ObjectPtr aObj, aObjects) {
1228 //TODO: replace by redisplay event.
1229 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1230 aObj->isDisabled() || (!aObj->isDisplayed());
1232 aDisplayer->redisplay(aObj, false);
1234 aDisplayer->updateViewer();
1238 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1240 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1242 SessionPtr aMgr = ModelAPI_Session::get();
1243 if (!theIndex.isValid()) {
1244 aMgr->setActiveDocument(aMgr->moduleDocument());
1247 if (theIndex.column() != 0) // Use only first column
1250 XGUI_Workshop* aWorkshop = getWorkshop();
1251 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1252 // De not use non editable Indexes
1253 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1255 ObjectPtr aObj = aDataModel->object(theIndex);
1257 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1258 if (!aPart.get()) { // Probably this is Feature
1259 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1260 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1261 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1264 if (aPart.get()) { // if this is a part
1265 if (aPart->partDoc() == aMgr->activeDocument()) {
1266 myMenuMgr->activatePartSet();
1274 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1276 // z layer is created for all started operations in order to visualize operation AIS presentation
1278 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1279 if (aContext.IsNull())
1282 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1283 if (myVisualLayerId == 0) {
1284 if (myVisualLayerId == 0)
1285 aViewer->AddZLayer(myVisualLayerId);
1287 TColStd_SequenceOfInteger aZList;
1288 aViewer->GetAllZLayers(aZList);
1289 bool aFound = false;
1290 for (int i = 1; i <= aZList.Length(); i++) {
1291 if (aZList(i) == myVisualLayerId) {
1297 aViewer->AddZLayer(myVisualLayerId);
1299 // if there is an active operation with validated widget,
1300 // the filters of this widget should be activated in the created view
1301 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1303 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1304 if (anActiveWidget) {
1305 ModuleBase_WidgetSelector* aWSelector =
1306 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1308 aWSelector->activateSelectionAndFilters(true);
1313 //******************************************************
1314 void PartSet_Module::widgetStateChanged(int thePreviousState)
1316 mySketchMgr->widgetStateChanged(thePreviousState);
1319 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1321 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1324 //******************************************************
1325 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1327 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1328 mySketchMgr->stopSketch(theOperation);
1332 //******************************************************
1333 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1335 GeomShapePtr aGeomShape;
1337 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1338 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1339 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1344 //******************************************************
1345 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1346 const GeomShapePtr& theGeomShape)
1348 AttributePtr anAttribute;
1349 GeomShapePtr aGeomShape = theGeomShape;
1350 if (!aGeomShape.get()) {
1351 // processing shape of result, e.g. sketch circle center is selected, this is a result
1352 // the geom shape is empty, the shape of result should be used
1353 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1354 if (aResult.get()) {
1355 aGeomShape = aResult->shape();
1359 if (aGeomShape.get()) {
1360 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1361 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1362 mySketchMgr->activeSketch());
1367 //******************************************************
1368 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1371 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1375 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1376 if (!aChoiceTitle.isEmpty()) {
1377 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1380 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1382 aPanel->setWindowTitle(aChoiceTitle);
1386 //******************************************************
1387 XGUI_Workshop* PartSet_Module::getWorkshop() const
1389 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1390 return aConnector->workshop();
1393 //******************************************************
1394 void PartSet_Module::setDefaultConstraintShown()
1396 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1397 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1398 myHasConstraintShown[PartSet_Tools::Expressions] = false;