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>
56 #include <ModelAPI_ResultConstruction.h>
58 #include <GeomDataAPI_Point2D.h>
59 #include <GeomDataAPI_Point.h>
60 #include <GeomDataAPI_Dir.h>
62 #include <XGUI_Displayer.h>
63 #include <XGUI_Workshop.h>
64 #include <XGUI_OperationMgr.h>
65 #include <XGUI_PropertyPanel.h>
66 #include <XGUI_ModuleConnector.h>
67 #include <XGUI_ContextMenuMgr.h>
68 #include <XGUI_Tools.h>
69 #include <XGUI_ObjectsBrowser.h>
70 #include <XGUI_SelectionMgr.h>
71 #include <XGUI_DataModel.h>
72 #include <XGUI_ErrorMgr.h>
73 #include <XGUI_CustomPrs.h>
74 #include <XGUI_SelectionMgr.h>
75 #include <XGUI_ActionsMgr.h>
77 #include <SketchPlugin_Feature.h>
78 #include <SketchPlugin_Sketch.h>
79 #include <SketchPlugin_ConstraintAngle.h>
80 #include <SketchPlugin_ConstraintLength.h>
81 #include <SketchPlugin_ConstraintDistance.h>
82 #include <SketchPlugin_ConstraintParallel.h>
83 #include <SketchPlugin_ConstraintPerpendicular.h>
84 #include <SketchPlugin_ConstraintRadius.h>
86 #include <SketcherPrs_SymbolPrs.h>
87 #include <SketcherPrs_Coincident.h>
88 #include <SketcherPrs_Tools.h>
90 #include <Events_Loop.h>
91 #include <Config_PropManager.h>
92 #include <Config_Keywords.h>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <TopoDS_Vertex.hxx>
97 #include <TopoDS_Shape.hxx>
98 #include <BRep_Tool.hxx>
99 #include <AIS_Dimension.hxx>
102 #include <QMouseEvent>
105 #include <QApplication>
106 #include <QMessageBox>
107 #include <QMainWindow>
111 #include <GeomAlgoAPI_FaceBuilder.h>
112 #include <GeomDataAPI_Dir.h>
114 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
120 /*!Create and return new instance of XGUI_Module*/
121 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
123 return new PartSet_Module(theWshop);
126 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
127 : ModuleBase_IModule(theWshop),
129 myIsOperationIsLaunched(false)
131 new PartSet_IconFactory();
133 mySketchMgr = new PartSet_SketcherMgr(this);
134 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
136 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
137 XGUI_Workshop* aWorkshop = aConnector->workshop();
139 ModuleBase_IViewer* aViewer = theWshop->viewer();
140 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
141 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
142 connect(aViewer, SIGNAL(viewTransformed(int)),
143 SLOT(onViewTransformed(int)));
144 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
145 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
146 myMenuMgr = new PartSet_MenuMgr(this);
147 myCustomPrs = new PartSet_CustomPrs(theWshop);
149 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
151 Events_Loop* aLoop = Events_Loop::loop();
152 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
154 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
155 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
157 setDefaultConstraintShown();
159 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
160 "Reference shape wireframe color in operation", Config_Prop::Color,
161 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
162 Config_PropManager::registerProp("Visualization", "operation_result_color",
163 "Result shape wireframe color in operation", Config_Prop::Color,
164 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
165 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
166 "Multi selector item color in operation", Config_Prop::Color,
167 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
170 PartSet_Module::~PartSet_Module()
172 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
173 for (; aIt.More(); aIt.Next()) {
174 Handle(SelectMgr_Filter) aFilter = aIt.Value();
175 if (!aFilter.IsNull())
179 delete myOverconstraintListener;
182 void PartSet_Module::activateSelectionFilters()
184 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
185 for (; aIt.More(); aIt.Next()) {
186 Handle(SelectMgr_Filter) aFilter = aIt.Value();
187 if (!aFilter.IsNull())
188 myWorkshop->viewer()->addSelectionFilter(aFilter);
192 void PartSet_Module::deactivateSelectionFilters()
194 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
195 for (; aIt.More(); aIt.Next()) {
196 Handle(SelectMgr_Filter) aFilter = aIt.Value();
197 if (!aFilter.IsNull())
198 myWorkshop->viewer()->removeSelectionFilter(aFilter);
202 void PartSet_Module::storeSelection()
204 sketchMgr()->storeSelection();
207 void PartSet_Module::restoreSelection()
209 sketchMgr()->restoreSelection();
212 void PartSet_Module::registerValidators()
214 //Registering of validators
215 SessionPtr aMgr = ModelAPI_Session::get();
216 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
217 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
218 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
219 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
220 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
221 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
222 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
223 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
224 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
225 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
226 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
227 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
228 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
229 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
230 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
231 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
232 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
235 void PartSet_Module::registerFilters()
237 //Registering of selection filters
238 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
239 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
242 void PartSet_Module::registerProperties()
244 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::Double,
246 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
247 Config_Prop::Integer, SKETCH_WIDTH);
248 Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
249 "Rotate to plane when selected", Config_Prop::Boolean, "false");
252 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
253 const bool isToConnect)
255 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
258 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
260 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
261 mySketchMgr->commitNestedSketch(theOperation);
264 /// Restart sketcher operations automatically
265 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
267 ModuleBase_OperationFeature* aFOperation =
268 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
269 if (aFOperation && !aFOperation->isEditOperation()) {
270 // the selection is cleared after commit the create operation
271 // in order to do not use the same selected objects in the restarted operation
272 // for common behaviour, the selection is cleared even if the operation is not restarted
273 getWorkshop()->selector()->clearSelection();
278 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
280 /// Restart sketcher operations automatically
281 mySketchReentrantMgr->operationAborted(theOperation);
284 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
286 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
289 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
290 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
292 ModuleBase_ModelWidget* aFilledWidget = 0;
293 bool aPostonedWidgetActivation = false;
295 FeaturePtr aFeature = aFOperation->feature();
296 /// Restart sketcher operations automatically
297 /// it is important to call method of sketch reentrant manager before filling of PP
298 /// because it fills some created feature attributes, these new values should be used
299 /// to fill the property panel
300 mySketchReentrantMgr->operationStarted(theOperation);
302 aWorkshop->fillPropertyPanel(aFOperation);
303 // filling the operation values by the current selection
304 // if the operation can be committed after the controls filling, the method perform should
305 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
306 bool isOperationCommitted = false;
307 if (!aFOperation->isEditOperation()) {
308 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
309 // if there is a greed attribute, automatic commit by preselection
310 // for this feature is prohibited
311 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
312 if (currentOperation() != aFOperation)
313 isOperationCommitted = true;
315 if (aGreedAttributeId.empty()) {
316 // a signal should be emitted before the next widget activation
317 // because, the activation of the next widget will give a focus to the widget.
318 // As a result the value of the widget is initialized.
319 // And commit may happens until the value is entered.
321 if (mySketchReentrantMgr->canBeCommittedByPreselection())
322 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
323 // activate the next obligatory widget
324 if (!isOperationCommitted)
325 aPropertyPanel->activateNextWidget(aFilledWidget);
328 else { // there is a greed widget
329 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
330 std::string aFirstAttributeId = aWidgets.front()->attributeID();
331 // activate next widget after greeded if it is the first widget in the panel
332 // else the first panel widget is already activated by operation start
333 if (aFirstAttributeId == aGreedAttributeId)
334 aPostonedWidgetActivation = true;
337 } if (!isOperationCommitted) {
338 workshop()->updateCommandStatus();
339 aWorkshop->connectToPropertyPanel(true);
340 updateSketcherOnStart(aFOperation);
341 updatePresentationsOnStart(aFOperation);
343 // the objects of the current operation should be deactivated
344 QObjectPtrList anObjects;
345 anObjects.append(aFeature);
346 std::list<ResultPtr> aResults;
347 ModelAPI_Tools::allResults(aFeature, aResults);
348 std::list<ResultPtr>::const_iterator aIt;
349 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
350 anObjects.append(*aIt);
352 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
353 for (; anIt != aLast; anIt++)
354 aWorkshop->deactivateActiveObject(*anIt, false);
355 if (anObjects.size() > 0) {
356 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
357 aDisplayer->updateViewer();
360 if (aPostonedWidgetActivation) {
361 // if the widget is an empty in the chain of activated widgets, the current operation
362 // is restarted. It should be performed after functionality of the operation starting
363 aPropertyPanel->activateNextWidget(aFilledWidget);
368 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
370 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
371 mySketchMgr->startSketch(theOperation);
373 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
374 mySketchMgr->startNestedSketch(theOperation);
378 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
380 ModuleBase_OperationFeature* aFOperation =
381 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
383 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
384 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
388 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
390 ModuleBase_IModule::operationResumed(theOperation);
392 ModuleBase_OperationFeature* aFOperation =
393 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
395 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
396 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
400 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
402 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
403 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
404 bool isModified = isModifiedArgs || isModifiedResults;
406 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
407 mySketchMgr->stopNestedSketch(theOperation);
409 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
410 setDefaultConstraintShown();
412 //VSV: Viewer is updated on feature update and redisplay
414 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
415 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
416 aDisplayer->updateViewer();
419 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
420 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
421 for (; anIt != aLast; anIt++) {
422 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
426 ModuleBase_Operation* PartSet_Module::currentOperation() const
428 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
429 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
430 return anOpMgr->currentOperation();
433 bool PartSet_Module::canUndo() const
435 bool aCanUndo = false;
436 SessionPtr aMgr = ModelAPI_Session::get();
437 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
438 aCanUndo = !aMgr->isOperation();
439 if (!aCanUndo) // check the enable state additionally by sketch manager
440 aCanUndo = aMgr->canUndo();
445 bool PartSet_Module::canRedo() const
447 bool aCanRedo = false;
448 SessionPtr aMgr = ModelAPI_Session::get();
449 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
450 aCanRedo = !aMgr->isOperation();
451 if (!aCanRedo) // check the enable state additionally by sketch manager
452 aCanRedo = aMgr->canRedo();
457 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
460 if (theActionId == "MOVE_CMD") {
461 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
463 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
464 // part features can not be moved in the history.
465 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
472 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
474 // the sketch manager put the restriction to the objects erase
475 return mySketchMgr->canEraseObject(theObject);
478 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
480 // the sketch manager put the restriction to the objects display
481 return mySketchMgr->canDisplayObject(theObject);
484 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
486 mySketchMgr->processHiddenObject(theObjects);
489 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
491 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
493 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
494 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
495 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
496 if (isSketchOp || isNestedOp) {
497 // in active sketch operation it is possible to activate operation object in selection
498 // in the edit operation, e.g. points of the line can be moved when the line is edited
499 ModuleBase_OperationFeature* aFOperation =
500 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
501 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
506 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
508 QMap<int, QAction*>& theMenuActions) const
510 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
513 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
515 myMenuMgr->updateViewerMenu(theStdActions);
518 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
520 bool isEnabledFixed = false;
521 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
522 mySketchReentrantMgr->isInternalEditStarted())
523 isEnabledFixed = true;
524 return isEnabledFixed;
527 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
529 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
530 if (anError.isEmpty())
531 anError = sketchMgr()->getFeatureError(theFeature);
536 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
537 QStringList& theIds) const
539 myMenuMgr->grantedOperationIds(theOperation, theIds);
541 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
542 XGUI_Workshop* aWorkshop = getWorkshop();
543 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
547 void PartSet_Module::activeSelectionModes(QIntList& theModes)
550 if (mySketchMgr->activeSketch().get())
551 PartSet_SketcherMgr::sketchSelectionModes(theModes);
554 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
556 if (theTypes.contains(TopAbs_FACE))
557 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
558 if (theTypes.contains(TopAbs_WIRE))
559 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
562 bool PartSet_Module::isMouseOverWindow()
564 return mySketchMgr->isMouseOverWindow();
567 bool PartSet_Module::isSketchNeutralPointActivated() const
569 bool isNeutralPoint = true;
570 if (sketchReentranceMgr()->isInternalEditStarted())
571 isNeutralPoint = false;
572 if (myIsOperationIsLaunched)
573 isNeutralPoint = false;
575 return isNeutralPoint;
578 void PartSet_Module::closeDocument()
583 void PartSet_Module::clearViewer()
585 myCustomPrs->clearPrs();
587 XGUI_Workshop* aWorkshop = getWorkshop();
588 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
589 aDisplayer->deactivateSelectionFilters();
592 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
594 ModuleBase_OperationFeature* aFOperation =
595 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
599 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
600 // we have to manually activate the sketch label in edit mode
601 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
602 aPanel->activateWidget(aPanel->modelWidgets().first());
605 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
606 QList<ModuleBase_ModelWidget*>& theWidgets) const
608 bool aProcessed = false;
610 ModuleBase_OperationFeature* aFOperation =
611 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
612 XGUI_Workshop* aWorkshop = getWorkshop();
613 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
614 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
615 ModuleBase_ISelection* aSelection = workshop()->selection();
616 // click on a point in sketch leads here with the point is highlighted, not yet selected
617 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
618 if (aPreselection.size() == 1) {
619 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
620 ObjectPtr anObject = aSelectedPrs->object();
622 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
623 FeaturePtr anOpFeature = aFOperation->feature();
624 GeomShapePtr aShape = aSelectedPrs->shape();
625 // click on the digit of dimension constrain comes here
626 // with an empty shape, so we need the check
627 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
628 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
629 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
630 mySketchMgr->activeSketch());
631 if (anAttribute.get()) {
632 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
633 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
635 const std::string anAttributeId = anAttribute->id();
636 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
638 theWidgets = aFactory.getModelWidgets();
639 // it is possible that the point does not present in XML definition,
640 // in this case, we assume that it is not processed by this module
641 // e.g. "Intersection point" feature
642 aProcessed = !theWidgets.isEmpty();
650 void PartSet_Module::onSelectionChanged()
652 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
656 bool isSketcherOp = false;
657 // An edit operation is enable only if the current opeation is the sketch operation
658 if (mySketchMgr->activeSketch()) {
659 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
660 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
663 // Editing of constraints can be done on selection
664 ModuleBase_ISelection* aSelect = myWorkshop->selection();
665 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
666 if (aSelected.size() == 1) {
667 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
668 ObjectPtr aObject = aPrs->object();
669 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
671 std::string aId = aFeature->getKind();
672 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
673 (aId == SketchPlugin_ConstraintLength::ID()) ||
674 (aId == SketchPlugin_ConstraintDistance::ID()) ||
675 (aId == SketchPlugin_ConstraintAngle::ID())) {
676 editFeature(aFeature);
683 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
685 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
686 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
687 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
690 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
692 Config_WidgetAPI* theWidgetApi)
694 ModuleBase_IWorkshop* aWorkshop = workshop();
695 XGUI_Workshop* aXUIWorkshop = getWorkshop();
696 ModuleBase_ModelWidget* aWgt = NULL;
697 if (theType == "sketch-start-label") {
698 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
699 theWidgetApi, myHasConstraintShown);
700 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
701 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
702 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
703 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
705 } else if (theType == "sketch-2dpoint_selector") {
706 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
708 aPointWgt->setSketch(mySketchMgr->activeSketch());
709 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
711 }else if (theType == "sketch-2dpoint_flyout_selector") {
712 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
714 aPointWgt->setSketch(mySketchMgr->activeSketch());
715 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
717 } else if (theType == "point2ddistance") {
718 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
719 aWorkshop, theWidgetApi);
720 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
722 } else if (theType == "sketch_shape_selector") {
723 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
724 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
725 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
726 aWgt = aShapeSelectorWgt;
727 } else if (theType == "sketch_multi_selector") {
728 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
729 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
730 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
731 aWgt = aShapeSelectorWgt;
733 else if (theType == "sketch_sub_shape_selector") {
734 PartSet_WidgetSubShapeSelector* aSubShapeSelectorWgt =
735 new PartSet_WidgetSubShapeSelector(theParent, aWorkshop, theWidgetApi);
736 aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
737 aWgt = aSubShapeSelectorWgt;
739 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
740 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
741 } else if (theType == "export_file_selector") {
742 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
743 } else if (theType == "sketch_launcher") {
744 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
745 } else if (theType == "module_choice") {
746 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
747 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
748 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
753 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
755 ModuleBase_ModelWidget* anActiveWidget = 0;
757 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
758 if (!anActiveWidget) {
759 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
761 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
762 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
765 return anActiveWidget;
768 bool PartSet_Module::deleteObjects()
770 bool isProcessed = false;
772 XGUI_Workshop* aWorkshop = getWorkshop();
773 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
775 //SessionPtr aMgr = ModelAPI_Session::get();
776 // 1. check whether the delete should be processed in the module
777 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
778 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
779 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
780 if (isSketchOp || isNestedOp) {
782 // 2. find selected presentations
783 // selected objects should be collected before the current operation abort because
784 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
785 ModuleBase_ISelection* aSel = workshop()->selection();
786 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
787 // if there are no selected objects in the viewer, that means that the selection in another
788 // place cased this method. It is necessary to return the false value to understande in above
789 // method that delete is not processed
790 if (aSelectedObj.count() == 0)
793 // avoid delete of the objects, which are not belong to the current sketch
794 // in order to do not delete results of other sketches
795 QObjectPtrList aSketchObjects;
796 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
797 for ( ; anIt != aLast; anIt++) {
798 ObjectPtr anObject = *anIt;
799 if (mySketchMgr->isObjectOfSketch(anObject)) {
800 // sketch feature should be used in this list because workshop deletes features only
801 // results are skipped
802 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
803 aSketchObjects.append(aSketchFeature);
806 // if the selection contains only local selected presentations from other sketches,
807 // the Delete operation should not be done at all
808 if (aSketchObjects.size() == 0)
811 // 3. start operation
812 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
813 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
815 // the active nested sketch operation should be aborted unconditionally
816 // the Delete action should be additionally granted for the Sketch operation
817 // in order to do not abort/commit it
818 if (!anOpMgr->canStartOperation(anOpAction->id()))
819 return true; // the objects are processed but can not be deleted
821 anOpMgr->startOperation(anOpAction);
823 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
824 // the problem is in AIS Dimensions recompute
825 // if a line and the dim are removed, line is the first
826 // it causes the AIS recompute, where the base line is null,
827 // the result is empty AIS in the viewer
828 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
830 // 4. delete features
831 // sketch feature should be skipped, only sub-features can be removed
832 // when sketch operation is active
833 aWorkshop->deleteFeatures(aSketchObjects);
835 anOpMgr->commitOperation();
840 void PartSet_Module::onFeatureTriggered()
842 // is commented for imp: Unpressing the button of the current action must behave like
843 // a validation if the entity can be created (instead of Cancel, as currently)
844 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
845 if (aCmd->isCheckable() && aCmd->isChecked()) {
846 // 1. check whether the delete should be processed in the module
847 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
848 bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
850 // in case if in the viewer nothing is displayed, the create operation should not be
851 // comitted even if all values of the feature are initialized
852 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
853 // the action information should be saved before the operation is aborted
854 // because this abort leads to update command status, which unchecks this action
855 anOperation->abort();
856 launchOperation(aCmd->data().toString());
860 ModuleBase_IModule::onFeatureTriggered();
863 void PartSet_Module::editFeature(FeaturePtr theFeature)
865 storeConstraintsState(theFeature->getKind());
866 ModuleBase_IModule::editFeature(theFeature);
869 bool PartSet_Module::canCommitOperation() const
874 void PartSet_Module::launchOperation(const QString& theCmdId)
876 myIsOperationIsLaunched = true;
877 storeConstraintsState(theCmdId.toStdString());
878 updateConstraintsState(theCmdId.toStdString());
880 ModuleBase_IModule::launchOperation(theCmdId);
882 myIsOperationIsLaunched = false;
885 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
887 if (myWorkshop->currentOperation() &&
888 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
889 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
890 mySketchMgr->showConstraintStates();
891 myHasConstraintShown = aShownStates;
895 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
897 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
898 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
899 // Show constraints if a constraint was anOperation
900 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
901 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
902 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
903 myHasConstraintShown[PartSet_Tools::Expressions]);
907 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
909 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
910 if (!anAIS.IsNull()) {
911 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
912 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
913 if (!aDim.IsNull()) {
914 aCtx->SetZLayer(aDim, myVisualLayerId);
916 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
918 aCtx->SetZLayer(aCons, myVisualLayerId);
923 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
926 // it should be recomputed in order to disappear in the viewer if the corresponded object
928 //if (myCustomPrs->isActive())
929 // myCustomPrs->redisplay(theObject, false);
932 void PartSet_Module::onViewTransformed(int theTrsfType)
934 // Set length of arrows constant in pixel size
935 // if the operation is panning or rotate or panglobal then do nothing
936 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
938 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
939 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
940 if (aContext.IsNull())
943 //Handle(V3d_View) aView = aViewer->activeView();
945 XGUI_Workshop* aWorkshop = getWorkshop();
946 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
947 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
948 Handle(V3d_View) aView;
950 for (aV3dViewer->InitDefinedViews();
951 aV3dViewer->MoreDefinedViews();
952 aV3dViewer->NextDefinedViews()) {
953 Handle(V3d_View) aV = aV3dViewer->DefinedView();
954 double aS = aV->Scale();
962 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
964 double aPrevLen = SketcherPrs_Tools::getArrowSize();
965 SketcherPrs_Tools::setArrowSize(aLen);
966 const double aPrevScale = aViewer->Scale(aViewer->activeView());
967 const double aCurScale = aViewer->activeView()->Camera()->Scale();
968 aViewer->SetScale(aViewer->activeView(), aCurScale);
969 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
970 bool isModified = false;
971 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
972 foreach (AISObjectPtr aAIS, aPrsList) {
973 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
975 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
976 if (!aDim.IsNull()) {
977 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
978 aContext->Redisplay(aDim, false);
983 aDisplayer->updateViewer();
986 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
988 return myCustomPrs->isActive(theFlag);
991 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
992 const ModuleBase_CustomizeFlag& theFlag,
993 const bool theUpdateViewer)
995 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
998 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
999 const bool theUpdateViewer)
1001 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1004 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1005 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1007 bool aCustomized = false;
1009 XGUI_Workshop* aWorkshop = getWorkshop();
1010 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1011 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1015 if (!theResult.get()) {
1016 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
1017 // customize sketch symbol presentation
1019 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1020 if (!anAISIO.IsNull()) {
1021 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1022 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1023 if (!aPrs.IsNull()) {
1024 std::vector<int> aColor;
1025 myOverconstraintListener->getConflictingColor(aColor);
1026 aPrs->SetConflictingConstraint(isConflicting, aColor);
1029 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1030 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1031 if (!aPrs.IsNull()) {
1032 std::vector<int> aColor;
1033 myOverconstraintListener->getConflictingColor(aColor);
1034 aPrs->SetConflictingConstraint(isConflicting, aColor);
1040 // customize sketch dimension constraint presentation
1042 std::vector<int> aColor;
1043 if (isConflicting) {
1044 myOverconstraintListener->getConflictingColor(aColor);
1047 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1048 if (!aColor.empty()) {
1049 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1053 // customize dimentional constrains
1054 sketchMgr()->customizePresentation(anObject);
1059 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1060 const bool theUpdateViewer)
1062 bool isRedisplayed = false;
1063 if (myCustomPrs->isActive(theFlag))
1064 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1066 return isRedisplayed;
1069 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1071 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1073 QLabel* aLabel = aOB->activeDocLabel();
1074 aLabel->installEventFilter(myMenuMgr);
1075 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1076 SLOT(onActiveDocPopup(const QPoint&)));
1077 aOB->treeView()->setExpandsOnDoubleClick(false);
1078 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1079 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1081 Events_Loop* aLoop = Events_Loop::loop();
1082 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1086 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1088 SessionPtr aMgr = ModelAPI_Session::get();
1089 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1091 XGUI_Workshop* aWorkshop = getWorkshop();
1092 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1094 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1097 aMenu.addAction(aActivatePartAction);
1098 aMenu.exec(aHeader->mapToGlobal(thePnt));
1101 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1103 return mySketchMgr->createPresentation(theResult);
1107 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1110 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1112 /// If last line finished on vertex the lines creation sequence has to be break
1113 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1115 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1116 // if there is an active widget, find the presented object in it
1117 if (!anActiveWidget)
1118 anActiveWidget = aPanel->preselectionWidget();
1120 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1122 if (aWidgetValidated)
1123 anObject = aWidgetValidated->findPresentedObject(theAIS);
1129 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1131 bool aCanBeShaged = true;
1133 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1135 aCanBeShaged = false;
1137 return aCanBeShaged;
1140 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1142 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1143 int aSelected = aObjects.size();
1144 SessionPtr aMgr = ModelAPI_Session::get();
1145 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1147 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1148 if (aSelected == 1) {
1149 bool hasResult = false;
1150 bool hasFeature = false;
1151 bool hasParameter = false;
1152 bool hasCompositeOwner = false;
1153 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1155 ObjectPtr aObject = aObjects.first();
1157 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1158 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1159 bool isPart = aPart.get() ||
1160 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1162 DocumentPtr aPartDoc;
1164 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1166 if (aPart.get()) // this may be null is Part feature is disabled
1167 aPartDoc = aPart->partDoc();
1169 theMenu->addAction(aActivatePartAction);
1170 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1172 } else if (aObject->document() == aMgr->activeDocument()) {
1173 if (hasParameter || hasFeature) {
1174 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1175 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1176 if (aCurrentOp && aFeature.get()) {
1177 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1178 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1183 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1185 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1188 bool aNotDeactivate = (aCurrentOp == 0);
1189 if (!aNotDeactivate) {
1190 aActivatePartAction->setEnabled(false);
1194 #define EXPAND_PARENT(OBJ) \
1195 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1196 if (aObjIndex.isValid()) { \
1197 QModelIndex aParent = aObjIndex.parent(); \
1198 int aCount = aDataModel->rowCount(aParent); \
1200 aTreeView->setExpanded(aParent, true); \
1204 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1206 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1207 // Do not change activation of parts if an operation active
1208 static QStringList aAllowActivationList;
1209 if (aAllowActivationList.isEmpty())
1210 aAllowActivationList <<
1211 QString(PartSetPlugin_Part::ID().c_str()) <<
1212 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1213 QString(PartSetPlugin_Remove::ID().c_str());
1214 if (myWorkshop->currentOperation() &&
1215 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1217 XGUI_Workshop* aWorkshop = getWorkshop();
1218 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1219 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1220 QPalette aPalet = aLabel->palette();
1222 SessionPtr aMgr = ModelAPI_Session::get();
1223 DocumentPtr aActiveDoc = aMgr->activeDocument();
1224 if (aActivePartIndex.isValid())
1225 aTreeView->setExpanded(aActivePartIndex, false);
1226 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1227 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1228 if (aActivePartIndex.isValid())
1229 aTreeView->setExpanded(aActivePartIndex, true);
1231 aLabel->setPalette(aPalet);
1232 aWorkshop->updateCommandStatus();
1234 // Update displayed objects in order to update active color
1235 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1236 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1238 foreach(ObjectPtr aObj, aObjects) {
1239 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1240 aObj->isDisabled() || (!aObj->isDisplayed());
1242 aDisplayer->redisplay(aObj, false);
1244 aDisplayer->updateViewer();
1245 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1246 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1247 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1248 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1250 ObjectPtr aConstrObj;
1251 ObjectPtr aResultObj;
1252 std::set<ObjectPtr>::const_iterator aIt;
1253 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1254 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1255 ObjectPtr aObject = (*aIt);
1256 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1257 && (aObject->document() != aRootDoc))
1258 aResultObj = aObject;
1259 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1260 && (aObject->document() != aRootDoc))
1261 aConstrObj = aObject;
1262 if (aResultObj.get() && aConstrObj.get())
1266 if (aResultObj.get() || aConstrObj.get()) {
1267 XGUI_Workshop* aWorkshop = getWorkshop();
1268 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1269 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1271 if (aResultObj.get()) {
1272 EXPAND_PARENT(aResultObj)
1274 if (aConstrObj.get()) {
1275 EXPAND_PARENT(aConstrObj)
1281 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1283 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1285 SessionPtr aMgr = ModelAPI_Session::get();
1286 if (!theIndex.isValid()) {
1287 aMgr->setActiveDocument(aMgr->moduleDocument());
1290 if (theIndex.column() != 0) // Use only first column
1293 XGUI_Workshop* aWorkshop = getWorkshop();
1294 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1295 // De not use non editable Indexes
1296 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1298 ObjectPtr aObj = aDataModel->object(theIndex);
1300 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1301 if (!aPart.get()) { // Probably this is Feature
1302 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1303 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1304 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1307 if (aPart.get()) { // if this is a part
1308 if (aPart->partDoc() == aMgr->activeDocument()) {
1309 myMenuMgr->activatePartSet();
1311 myMenuMgr->activatePart(aPart);
1317 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1319 // z layer is created for all started operations in order to visualize operation AIS presentation
1321 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1322 if (aContext.IsNull())
1325 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1326 if (myVisualLayerId == 0) {
1327 if (myVisualLayerId == 0)
1328 aViewer->AddZLayer(myVisualLayerId);
1330 TColStd_SequenceOfInteger aZList;
1331 aViewer->GetAllZLayers(aZList);
1332 bool aFound = false;
1333 for (int i = 1; i <= aZList.Length(); i++) {
1334 if (aZList(i) == myVisualLayerId) {
1340 aViewer->AddZLayer(myVisualLayerId);
1342 // if there is an active operation with validated widget,
1343 // the filters of this widget should be activated in the created view
1344 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1346 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1347 if (anActiveWidget) {
1348 ModuleBase_WidgetSelector* aWSelector =
1349 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1351 aWSelector->activateSelectionAndFilters(true);
1356 //******************************************************
1357 void PartSet_Module::widgetStateChanged(int thePreviousState)
1359 mySketchMgr->widgetStateChanged(thePreviousState);
1362 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1364 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1367 //******************************************************
1368 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1370 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1371 mySketchMgr->stopSketch(theOperation);
1375 //******************************************************
1376 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1378 GeomShapePtr aGeomShape;
1380 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1381 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1382 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1387 //******************************************************
1388 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1389 const GeomShapePtr& theGeomShape)
1391 AttributePtr anAttribute;
1392 GeomShapePtr aGeomShape = theGeomShape;
1393 if (!aGeomShape.get()) {
1394 // processing shape of result, e.g. sketch circle center is selected, this is a result
1395 // the geom shape is empty, the shape of result should be used
1396 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1397 if (aResult.get()) {
1398 aGeomShape = aResult->shape();
1402 if (aGeomShape.get()) {
1403 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1404 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1405 mySketchMgr->activeSketch());
1410 //******************************************************
1411 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1414 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1418 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1419 if (!aChoiceTitle.isEmpty()) {
1420 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1423 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1425 aPanel->setWindowTitle(aChoiceTitle);
1429 //******************************************************
1430 XGUI_Workshop* PartSet_Module::getWorkshop() const
1432 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1433 return aConnector->workshop();
1436 //******************************************************
1437 void PartSet_Module::setDefaultConstraintShown()
1439 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1440 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1441 myHasConstraintShown[PartSet_Tools::Expressions] = false;