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_WidgetFeaturePointSelector.h"
15 #include "PartSet_WidgetEditor.h"
16 #include "PartSet_WidgetFileSelector.h"
17 #include "PartSet_WidgetSketchCreator.h"
18 #include "PartSet_SketcherMgr.h"
19 #include "PartSet_SketcherReetntrantMgr.h"
20 #include "PartSet_ResultSketchPrs.h"
21 #include "PartSet_MenuMgr.h"
22 #include "PartSet_CustomPrs.h"
23 #include "PartSet_IconFactory.h"
24 #include "PartSet_WidgetChoice.h"
25 #include "PartSet_OverconstraintListener.h"
27 #include "PartSet_Filters.h"
28 #include "PartSet_FilterInfinite.h"
30 #include <PartSetPlugin_Remove.h>
31 #include <PartSetPlugin_Part.h>
32 #include <PartSetPlugin_Duplicate.h>
34 #include <ModuleBase_Operation.h>
35 #include <ModuleBase_OperationAction.h>
36 #include <ModuleBase_IViewer.h>
37 #include <ModuleBase_IViewWindow.h>
38 #include <ModuleBase_IPropertyPanel.h>
39 #include <ModuleBase_WidgetEditor.h>
40 #include <ModuleBase_WidgetValidated.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 <AIS_Dimension.hxx>
95 #include <AIS_InteractiveObject.hxx>
96 #include <StdSelect_TypeOfFace.hxx>
97 #include <TopoDS_Vertex.hxx>
99 #include <TopoDS_Shape.hxx>
100 #include <BRep_Tool.hxx>
103 #include <QMouseEvent>
106 #include <QApplication>
107 #include <QMessageBox>
108 #include <QMainWindow>
112 #include <GeomAlgoAPI_FaceBuilder.h>
113 #include <GeomDataAPI_Dir.h>
115 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
121 /*!Create and return new instance of XGUI_Module*/
122 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
124 return new PartSet_Module(theWshop);
127 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
128 : ModuleBase_IModule(theWshop),
130 myIsOperationIsLaunched(false)
132 new PartSet_IconFactory();
134 mySketchMgr = new PartSet_SketcherMgr(this);
135 mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
137 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
138 XGUI_Workshop* aWorkshop = aConnector->workshop();
140 ModuleBase_IViewer* aViewer = theWshop->viewer();
141 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
142 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
143 connect(aViewer, SIGNAL(viewTransformed(int)),
144 SLOT(onViewTransformed(int)));
145 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
146 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
147 myMenuMgr = new PartSet_MenuMgr(this);
148 myCustomPrs = new PartSet_CustomPrs(theWshop);
150 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
152 Events_Loop* aLoop = Events_Loop::loop();
153 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
155 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
156 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
158 setDefaultConstraintShown();
160 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
161 "Reference shape wireframe color in operation", Config_Prop::Color,
162 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
163 Config_PropManager::registerProp("Visualization", "operation_result_color",
164 "Result shape wireframe color in operation", Config_Prop::Color,
165 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
166 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
167 "Multi selector item color in operation", Config_Prop::Color,
168 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
169 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
170 "Color of removed feature in operation", Config_Prop::Color,
171 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
174 PartSet_Module::~PartSet_Module()
176 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
177 for (; aIt.More(); aIt.Next()) {
178 Handle(SelectMgr_Filter) aFilter = aIt.Value();
179 if (!aFilter.IsNull())
183 delete myOverconstraintListener;
186 void PartSet_Module::activateSelectionFilters()
188 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
189 for (; aIt.More(); aIt.Next()) {
190 Handle(SelectMgr_Filter) aFilter = aIt.Value();
191 if (!aFilter.IsNull())
192 myWorkshop->viewer()->addSelectionFilter(aFilter);
196 void PartSet_Module::deactivateSelectionFilters()
198 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
199 for (; aIt.More(); aIt.Next()) {
200 Handle(SelectMgr_Filter) aFilter = aIt.Value();
201 if (!aFilter.IsNull())
202 myWorkshop->viewer()->removeSelectionFilter(aFilter);
206 void PartSet_Module::storeSelection()
208 sketchMgr()->storeSelection();
211 void PartSet_Module::restoreSelection()
213 sketchMgr()->restoreSelection();
216 void PartSet_Module::registerValidators()
218 //Registering of validators
219 SessionPtr aMgr = ModelAPI_Session::get();
220 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
221 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
222 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
223 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
224 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
225 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
226 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
227 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
228 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
229 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
230 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
231 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
232 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
233 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
234 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
235 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
236 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
237 aFactory->registerValidator("PartSet_MultyTranslationSelection",
238 new PartSet_MultyTranslationSelection);
239 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
240 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
243 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
244 const bool isToConnect)
246 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
249 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
251 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
252 mySketchMgr->commitNestedSketch(theOperation);
255 /// Restart sketcher operations automatically
256 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
258 ModuleBase_OperationFeature* aFOperation =
259 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
260 if (aFOperation && !aFOperation->isEditOperation()) {
261 // the selection is cleared after commit the create operation
262 // in order to do not use the same selected objects in the restarted operation
263 // for common behaviour, the selection is cleared even if the operation is not restarted
264 getWorkshop()->selector()->clearSelection();
269 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
271 /// Restart sketcher operations automatically
272 mySketchReentrantMgr->operationAborted(theOperation);
275 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
277 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
280 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
281 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
283 ModuleBase_ModelWidget* aFilledWidget = 0;
284 bool aPostonedWidgetActivation = false;
286 FeaturePtr aFeature = aFOperation->feature();
287 /// Restart sketcher operations automatically
288 /// it is important to call method of sketch reentrant manager before filling of PP
289 /// because it fills some created feature attributes, these new values should be used
290 /// to fill the property panel
291 mySketchReentrantMgr->operationStarted(theOperation);
293 aWorkshop->fillPropertyPanel(aFOperation);
294 // filling the operation values by the current selection
295 // if the operation can be committed after the controls filling, the method perform should
296 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
297 bool isOperationCommitted = false;
298 if (!aFOperation->isEditOperation()) {
299 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
300 // if there is a greed attribute, automatic commit by preselection
301 // for this feature is prohibited
302 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
303 if (currentOperation() != aFOperation)
304 isOperationCommitted = true;
306 if (aGreedAttributeId.empty()) {
307 // a signal should be emitted before the next widget activation
308 // because, the activation of the next widget will give a focus to the widget.
309 // As a result the value of the widget is initialized.
310 // And commit may happens until the value is entered.
312 if (mySketchReentrantMgr->canBeCommittedByPreselection())
313 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
314 // activate the next obligatory widget
315 if (!isOperationCommitted)
316 aPropertyPanel->activateNextWidget(aFilledWidget);
319 else { // there is a greed widget
320 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
321 std::string aFirstAttributeId = aWidgets.front()->attributeID();
322 // activate next widget after greeded if it is the first widget in the panel
323 // else the first panel widget is already activated by operation start
324 if (aFirstAttributeId == aGreedAttributeId)
325 aPostonedWidgetActivation = true;
328 } if (!isOperationCommitted) {
329 aWorkshop->connectToPropertyPanel(true);
330 updateSketcherOnStart(aFOperation);
331 updatePresentationsOnStart(aFOperation);
333 // the objects of the current operation should be deactivated
334 QObjectPtrList anObjects;
335 anObjects.append(aFeature);
336 std::list<ResultPtr> aResults;
337 ModelAPI_Tools::allResults(aFeature, aResults);
338 std::list<ResultPtr>::const_iterator aIt;
339 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
340 anObjects.append(*aIt);
342 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
343 for (; anIt != aLast; anIt++)
344 aWorkshop->deactivateActiveObject(*anIt, false);
345 if (anObjects.size() > 0) {
346 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
347 aDisplayer->updateViewer();
349 /// state of command actions should be updated after displayed objects modification because
350 /// deactivation(for example) of objects may influence on selection in the viewer
351 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
352 workshop()->updateCommandStatus();
354 if (aPostonedWidgetActivation) {
355 // if the widget is an empty in the chain of activated widgets, the current operation
356 // is restarted. It should be performed after functionality of the operation starting
357 aPropertyPanel->activateNextWidget(aFilledWidget);
362 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
364 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
365 mySketchMgr->startSketch(theOperation);
367 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
368 mySketchMgr->startNestedSketch(theOperation);
372 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
374 ModuleBase_OperationFeature* aFOperation =
375 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
377 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
378 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
382 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
384 ModuleBase_IModule::operationResumed(theOperation);
386 ModuleBase_OperationFeature* aFOperation =
387 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
389 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
390 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
394 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
396 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
397 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
398 bool isModified = isModifiedArgs || isModifiedResults;
400 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
401 mySketchMgr->stopNestedSketch(theOperation);
403 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
404 setDefaultConstraintShown();
406 //VSV: Viewer is updated on feature update and redisplay
408 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
409 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
410 aDisplayer->updateViewer();
413 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
414 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
415 for (; anIt != aLast; anIt++) {
416 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
420 ModuleBase_Operation* PartSet_Module::currentOperation() const
422 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
423 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
424 return anOpMgr->currentOperation();
427 bool PartSet_Module::canUndo() const
429 bool aCanUndo = false;
430 SessionPtr aMgr = ModelAPI_Session::get();
431 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
432 aCanUndo = !aMgr->isOperation();
433 if (!aCanUndo) // check the enable state additionally by sketch manager
434 aCanUndo = aMgr->canUndo();
439 bool PartSet_Module::canRedo() const
441 bool aCanRedo = false;
442 SessionPtr aMgr = ModelAPI_Session::get();
443 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
444 aCanRedo = !aMgr->isOperation();
445 if (!aCanRedo) // check the enable state additionally by sketch manager
446 aCanRedo = aMgr->canRedo();
451 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
454 if (theActionId == "MOVE_CMD") {
455 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
457 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
458 // part features can not be moved in the history.
459 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
466 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
468 // the sketch manager put the restriction to the objects erase
469 return mySketchMgr->canEraseObject(theObject);
472 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
474 // the sketch manager put the restriction to the objects display
475 return mySketchMgr->canDisplayObject(theObject);
478 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
480 mySketchMgr->processHiddenObject(theObjects);
483 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
485 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
487 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
488 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
489 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
490 if (isSketchOp || isNestedOp) {
491 // in active sketch operation it is possible to activate operation object in selection
492 // in the edit operation, e.g. points of the line can be moved when the line is edited
493 ModuleBase_OperationFeature* aFOperation =
494 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
495 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
500 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
502 QMap<int, QAction*>& theMenuActions) const
504 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
507 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
509 myMenuMgr->updateViewerMenu(theStdActions);
512 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
514 bool isEnabledFixed = false;
515 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
516 mySketchReentrantMgr->isInternalEditStarted())
517 isEnabledFixed = true;
518 return isEnabledFixed;
521 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
523 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
524 if (anError.isEmpty())
525 anError = sketchMgr()->getFeatureError(theFeature);
530 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
531 QStringList& theIds) const
533 myMenuMgr->grantedOperationIds(theOperation, theIds);
535 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
536 XGUI_Workshop* aWorkshop = getWorkshop();
537 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
541 void PartSet_Module::activeSelectionModes(QIntList& theModes)
544 if (mySketchMgr->activeSketch().get())
545 PartSet_SketcherMgr::sketchSelectionModes(theModes);
548 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
550 if (theTypes.contains(TopAbs_FACE))
551 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
552 if (theTypes.contains(TopAbs_WIRE))
553 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
556 bool PartSet_Module::isMouseOverWindow()
558 return mySketchMgr->isMouseOverWindow();
561 bool PartSet_Module::isSketchNeutralPointActivated() const
563 bool isNeutralPoint = true;
564 if (sketchReentranceMgr()->isInternalEditStarted())
565 isNeutralPoint = false;
566 if (myIsOperationIsLaunched)
567 isNeutralPoint = false;
569 return isNeutralPoint;
572 void PartSet_Module::closeDocument()
574 myActivePartIndex = QModelIndex();
578 void PartSet_Module::clearViewer()
580 myCustomPrs->clearPrs();
582 XGUI_Workshop* aWorkshop = getWorkshop();
583 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
584 aDisplayer->deactivateSelectionFilters();
587 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
589 ModuleBase_OperationFeature* aFOperation =
590 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
594 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
595 // we have to manually activate the sketch label in edit mode
596 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
597 aPanel->activateWidget(aPanel->modelWidgets().first());
600 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
601 QList<ModuleBase_ModelWidget*>& theWidgets) const
603 bool aProcessed = false;
605 ModuleBase_OperationFeature* aFOperation =
606 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
607 XGUI_Workshop* aWorkshop = getWorkshop();
608 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
609 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
610 ModuleBase_ISelection* aSelection = workshop()->selection();
611 // click on a point in sketch leads here with the point is highlighted, not yet selected
612 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
613 if (aPreselection.size() == 1) {
614 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
615 ObjectPtr anObject = aSelectedPrs->object();
617 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
618 FeaturePtr anOpFeature = aFOperation->feature();
619 GeomShapePtr aShape = aSelectedPrs->shape();
620 // click on the digit of dimension constrain comes here
621 // with an empty shape, so we need the check
622 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
623 // if feature has only one result and shape of result is equal to selected shape
624 // this attribute is not processed. It is a case of Sketch Point.
625 if (aFeature->results().size() == 1) {
626 ResultPtr aResult = aFeature->results().front();
627 if (aResult.get() && aResult->shape()->isEqual(aShape))
630 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
631 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
632 mySketchMgr->activeSketch());
633 if (anAttribute.get()) {
634 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
635 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
637 const std::string anAttributeId = anAttribute->id();
638 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
640 theWidgets = aFactory.getModelWidgets();
641 // it is possible that the point does not present in XML definition,
642 // in this case, we assume that it is not processed by this module
643 // e.g. "Intersection point" feature
644 aProcessed = !theWidgets.isEmpty();
652 void PartSet_Module::onSelectionChanged()
654 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
658 bool isSketcherOp = false;
659 // An edit operation is enable only if the current opeation is the sketch operation
660 if (mySketchMgr->activeSketch()) {
661 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
662 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
665 // Editing of constraints can be done on selection
666 ModuleBase_ISelection* aSelect = myWorkshop->selection();
667 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
668 if (aSelected.size() == 1) {
669 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
670 ObjectPtr aObject = aPrs->object();
671 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
673 std::string aId = aFeature->getKind();
674 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
675 (aId == SketchPlugin_ConstraintLength::ID()) ||
676 (aId == SketchPlugin_ConstraintDistance::ID()) ||
677 (aId == SketchPlugin_ConstraintAngle::ID())) {
678 editFeature(aFeature);
685 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
687 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
688 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
689 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
692 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
694 Config_WidgetAPI* theWidgetApi)
696 ModuleBase_IWorkshop* aWorkshop = workshop();
697 XGUI_Workshop* aXUIWorkshop = getWorkshop();
698 ModuleBase_ModelWidget* aWgt = NULL;
699 if (theType == "sketch-start-label") {
700 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
701 theWidgetApi, myHasConstraintShown);
702 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
703 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
704 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
705 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
707 } else if (theType == "sketch-2dpoint_selector") {
708 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
710 aPointWgt->setSketch(mySketchMgr->activeSketch());
711 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
713 }else if (theType == "sketch-2dpoint_flyout_selector") {
714 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
716 aPointWgt->setSketch(mySketchMgr->activeSketch());
717 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
719 } else if (theType == "point2ddistance") {
720 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
721 aWorkshop, theWidgetApi);
722 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
724 } else if (theType == "sketch_shape_selector") {
725 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
726 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
727 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
728 aWgt = aShapeSelectorWgt;
729 } else if (theType == "sketch_multi_selector") {
730 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
731 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
732 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
733 aWgt = aShapeSelectorWgt;
735 else if (theType == "sketch_sub_shape_selector") {
736 PartSet_WidgetSubShapeSelector* aSubShapeSelectorWgt =
737 new PartSet_WidgetSubShapeSelector(theParent, aWorkshop, theWidgetApi);
738 aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
739 aWgt = aSubShapeSelectorWgt;
741 else if (theType == "sketch_feature_point_selector") {
742 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
743 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
744 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
745 aWgt = aPointSelectorWgt;
747 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
748 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
749 } else if (theType == "export_file_selector") {
750 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
751 } else if (theType == "sketch_launcher") {
752 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
753 } else if (theType == "module_choice") {
754 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
755 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
756 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
761 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
763 ModuleBase_ModelWidget* anActiveWidget = 0;
765 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
766 if (!anActiveWidget) {
767 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
769 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
770 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
773 return anActiveWidget;
776 bool PartSet_Module::deleteObjects()
778 bool isProcessed = false;
780 XGUI_Workshop* aWorkshop = getWorkshop();
781 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
783 //SessionPtr aMgr = ModelAPI_Session::get();
784 // 1. check whether the delete should be processed in the module
785 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
786 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
787 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
788 if (isSketchOp || isNestedOp) {
790 // 2. find selected presentations
791 // selected objects should be collected before the current operation abort because
792 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
793 ModuleBase_ISelection* aSel = workshop()->selection();
794 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
795 // if there are no selected objects in the viewer, that means that the selection in another
796 // place cased this method. It is necessary to return the false value to understande in above
797 // method that delete is not processed
798 if (aSelectedObj.count() == 0)
801 // avoid delete of the objects, which are not belong to the current sketch
802 // in order to do not delete results of other sketches
803 QObjectPtrList aSketchObjects;
804 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
805 for ( ; anIt != aLast; anIt++) {
806 ObjectPtr anObject = *anIt;
807 if (mySketchMgr->isObjectOfSketch(anObject)) {
808 // sketch feature should be used in this list because workshop deletes features only
809 // results are skipped
810 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
811 aSketchObjects.append(aSketchFeature);
814 // if the selection contains only local selected presentations from other sketches,
815 // the Delete operation should not be done at all
816 if (aSketchObjects.size() == 0)
819 // 3. start operation
820 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
821 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
823 // the active nested sketch operation should be aborted unconditionally
824 // the Delete action should be additionally granted for the Sketch operation
825 // in order to do not abort/commit it
826 if (!anOpMgr->canStartOperation(anOpAction->id()))
827 return true; // the objects are processed but can not be deleted
829 anOpMgr->startOperation(anOpAction);
831 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
832 // the problem is in AIS Dimensions recompute
833 // if a line and the dim are removed, line is the first
834 // it causes the AIS recompute, where the base line is null,
835 // the result is empty AIS in the viewer
836 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
838 // 4. delete features
839 // sketch feature should be skipped, only sub-features can be removed
840 // when sketch operation is active
841 aWorkshop->deleteFeatures(aSketchObjects);
843 anOpMgr->commitOperation();
848 void PartSet_Module::onFeatureTriggered()
850 // is commented for imp: Unpressing the button of the current action must behave like
851 // a validation if the entity can be created (instead of Cancel, as currently)
852 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
853 if (aCmd->isCheckable() && aCmd->isChecked()) {
854 // 1. check whether the delete should be processed in the module
855 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
856 bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
858 // in case if in the viewer nothing is displayed, the create operation should not be
859 // comitted even if all values of the feature are initialized
860 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
861 // the action information should be saved before the operation is aborted
862 // because this abort leads to update command status, which unchecks this action
863 anOperation->abort();
864 launchOperation(aCmd->data().toString());
868 ModuleBase_IModule::onFeatureTriggered();
871 void PartSet_Module::editFeature(FeaturePtr theFeature)
873 storeConstraintsState(theFeature->getKind());
874 ModuleBase_IModule::editFeature(theFeature);
877 bool PartSet_Module::canCommitOperation() const
882 void PartSet_Module::launchOperation(const QString& theCmdId)
884 myIsOperationIsLaunched = true;
885 storeConstraintsState(theCmdId.toStdString());
886 updateConstraintsState(theCmdId.toStdString());
888 ModuleBase_IModule::launchOperation(theCmdId);
890 myIsOperationIsLaunched = false;
893 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
895 if (myWorkshop->currentOperation() &&
896 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
897 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
898 mySketchMgr->showConstraintStates();
899 myHasConstraintShown = aShownStates;
903 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
905 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
906 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
907 // Show constraints if a constraint was anOperation
908 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
909 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
910 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
911 myHasConstraintShown[PartSet_Tools::Expressions]);
915 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
917 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
918 if (!anAIS.IsNull()) {
919 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
920 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
921 if (!aDim.IsNull()) {
922 aCtx->SetZLayer(aDim, myVisualLayerId);
924 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
926 aCtx->SetZLayer(aCons, myVisualLayerId);
931 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
934 // it should be recomputed in order to disappear in the viewer if the corresponded object
936 //if (myCustomPrs->isActive())
937 // myCustomPrs->redisplay(theObject, false);
940 void PartSet_Module::onViewTransformed(int theTrsfType)
942 // Set length of arrows constant in pixel size
943 // if the operation is panning or rotate or panglobal then do nothing
944 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
946 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
947 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
948 if (aContext.IsNull())
951 //Handle(V3d_View) aView = aViewer->activeView();
953 XGUI_Workshop* aWorkshop = getWorkshop();
954 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
955 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
956 Handle(V3d_View) aView;
958 for (aV3dViewer->InitDefinedViews();
959 aV3dViewer->MoreDefinedViews();
960 aV3dViewer->NextDefinedViews()) {
961 Handle(V3d_View) aV = aV3dViewer->DefinedView();
962 double aS = aV->Scale();
970 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
972 double aPrevLen = SketcherPrs_Tools::getArrowSize();
973 SketcherPrs_Tools::setArrowSize(aLen);
974 const double aPrevScale = aViewer->Scale(aViewer->activeView());
975 const double aCurScale = aViewer->activeView()->Camera()->Scale();
976 aViewer->SetScale(aViewer->activeView(), aCurScale);
977 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
978 bool isModified = false;
979 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
980 foreach (AISObjectPtr aAIS, aPrsList) {
981 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
983 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
984 if (!aDim.IsNull()) {
985 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
986 aContext->Redisplay(aDim, false);
991 aDisplayer->updateViewer();
994 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
996 return myCustomPrs->isActive(theFlag);
999 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1000 const ModuleBase_CustomizeFlag& theFlag,
1001 const bool theUpdateViewer)
1003 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1006 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1007 const bool theUpdateViewer)
1009 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1012 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1013 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1015 bool aCustomized = false;
1017 XGUI_Workshop* aWorkshop = getWorkshop();
1018 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1019 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1023 if (!theResult.get()) {
1024 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
1025 // customize sketch symbol presentation
1027 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1028 if (!anAISIO.IsNull()) {
1029 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1030 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1031 if (!aPrs.IsNull()) {
1032 std::vector<int> aColor;
1033 myOverconstraintListener->getConflictingColor(aColor);
1034 aPrs->SetConflictingConstraint(isConflicting, aColor);
1037 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1038 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1039 if (!aPrs.IsNull()) {
1040 std::vector<int> aColor;
1041 myOverconstraintListener->getConflictingColor(aColor);
1042 aPrs->SetConflictingConstraint(isConflicting, aColor);
1048 // customize sketch dimension constraint presentation
1050 std::vector<int> aColor;
1051 if (isConflicting) {
1052 myOverconstraintListener->getConflictingColor(aColor);
1055 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1056 if (!aColor.empty()) {
1057 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1061 // customize dimentional constrains
1062 sketchMgr()->customizePresentation(anObject);
1067 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1068 const bool theUpdateViewer)
1070 bool isRedisplayed = false;
1071 if (myCustomPrs->isActive(theFlag))
1072 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1074 return isRedisplayed;
1077 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1079 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1081 QLabel* aLabel = aOB->activeDocLabel();
1082 aLabel->installEventFilter(myMenuMgr);
1083 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1084 SLOT(onActiveDocPopup(const QPoint&)));
1085 aOB->treeView()->setExpandsOnDoubleClick(false);
1086 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1087 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1089 Events_Loop* aLoop = Events_Loop::loop();
1090 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1094 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1096 SessionPtr aMgr = ModelAPI_Session::get();
1097 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1099 XGUI_Workshop* aWorkshop = getWorkshop();
1100 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1102 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1105 aMenu.addAction(aActivatePartAction);
1106 aMenu.exec(aHeader->mapToGlobal(thePnt));
1109 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1111 return mySketchMgr->createPresentation(theResult);
1115 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1118 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1120 /// If last line finished on vertex the lines creation sequence has to be break
1121 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1123 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1124 // if there is an active widget, find the presented object in it
1125 if (!anActiveWidget)
1126 anActiveWidget = aPanel->preselectionWidget();
1128 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1130 if (aWidgetValidated)
1131 anObject = aWidgetValidated->findPresentedObject(theAIS);
1137 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1139 bool aCanBeShaged = true;
1141 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1143 aCanBeShaged = false;
1145 return aCanBeShaged;
1148 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1150 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1151 int aSelected = aObjects.size();
1152 SessionPtr aMgr = ModelAPI_Session::get();
1153 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1155 bool hasResult = false;
1156 bool hasFeature = false;
1157 bool hasParameter = false;
1158 bool hasCompositeOwner = false;
1159 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1162 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1163 if (aSelected == 1) {
1164 ObjectPtr aObject = aObjects.first();
1166 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1167 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1168 bool isPart = aPart.get() ||
1169 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1171 DocumentPtr aPartDoc;
1173 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1175 if (aPart.get()) // this may be null is Part feature is disabled
1176 aPartDoc = aPart->partDoc();
1178 theMenu->addAction(aActivatePartAction);
1179 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1181 } else if (aObject->document() == aMgr->activeDocument()) {
1182 if (hasParameter || hasFeature) {
1183 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1184 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1185 if (aCurrentOp && aFeature.get()) {
1186 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1187 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1194 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1195 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1196 theMenu->addSeparator();
1199 bool aNotDeactivate = (aCurrentOp == 0);
1200 if (!aNotDeactivate) {
1201 aActivatePartAction->setEnabled(false);
1205 #define EXPAND_PARENT(OBJ) \
1206 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1207 if (aObjIndex.isValid()) { \
1208 QModelIndex aParent = aObjIndex.parent(); \
1209 int aCount = aDataModel->rowCount(aParent); \
1211 aTreeView->setExpanded(aParent, true); \
1215 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1217 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1218 // Do not change activation of parts if an operation active
1219 static QStringList aAllowActivationList;
1220 if (aAllowActivationList.isEmpty())
1221 aAllowActivationList <<
1222 QString(PartSetPlugin_Part::ID().c_str()) <<
1223 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1224 QString(PartSetPlugin_Remove::ID().c_str());
1225 if (myWorkshop->currentOperation() &&
1226 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1228 XGUI_Workshop* aWorkshop = getWorkshop();
1229 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1230 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1231 QPalette aPalet = aLabel->palette();
1233 SessionPtr aMgr = ModelAPI_Session::get();
1234 DocumentPtr aActiveDoc = aMgr->activeDocument();
1235 if (myActivePartIndex.isValid())
1236 aTreeView->setExpanded(myActivePartIndex, false);
1237 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1238 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1239 if (myActivePartIndex.isValid())
1240 aTreeView->setExpanded(myActivePartIndex, true);
1242 aLabel->setPalette(aPalet);
1243 aWorkshop->updateCommandStatus();
1245 // Update displayed objects in order to update active color
1246 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1247 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1249 foreach(ObjectPtr aObj, aObjects) {
1250 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1251 aObj->isDisabled() || (!aObj->isDisplayed());
1253 aDisplayer->redisplay(aObj, false);
1255 aDisplayer->updateViewer();
1256 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1257 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1258 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1259 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1261 ObjectPtr aConstrObj;
1262 ObjectPtr aResultObj;
1263 std::set<ObjectPtr>::const_iterator aIt;
1264 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1265 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1266 ObjectPtr aObject = (*aIt);
1267 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1268 && (aObject->document() != aRootDoc))
1269 aResultObj = aObject;
1270 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1271 && (aObject->document() != aRootDoc))
1272 aConstrObj = aObject;
1273 if (aResultObj.get() && aConstrObj.get())
1277 if (aResultObj.get() || aConstrObj.get()) {
1278 XGUI_Workshop* aWorkshop = getWorkshop();
1279 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1280 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1282 if (aResultObj.get()) {
1283 EXPAND_PARENT(aResultObj)
1285 if (aConstrObj.get()) {
1286 EXPAND_PARENT(aConstrObj)
1292 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1294 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1296 SessionPtr aMgr = ModelAPI_Session::get();
1297 if (!theIndex.isValid()) {
1298 // It seems that this code is obsolete
1299 //aMgr->setActiveDocument(aMgr->moduleDocument());
1302 if (theIndex.column() != 0) // Use only first column
1305 XGUI_Workshop* aWorkshop = getWorkshop();
1306 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1307 // De not use non editable Indexes
1308 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1310 ObjectPtr aObj = aDataModel->object(theIndex);
1312 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1313 if (!aPart.get()) { // Probably this is Feature
1314 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1315 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1316 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1319 if (aPart.get()) { // if this is a part
1320 if (aPart->partDoc() == aMgr->activeDocument()) {
1321 myMenuMgr->activatePartSet();
1323 myMenuMgr->activatePart(aPart);
1329 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1331 // z layer is created for all started operations in order to visualize operation AIS presentation
1333 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1334 if (aContext.IsNull())
1337 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1338 if (myVisualLayerId == 0) {
1339 if (myVisualLayerId == 0)
1340 aViewer->AddZLayer(myVisualLayerId);
1342 TColStd_SequenceOfInteger aZList;
1343 aViewer->GetAllZLayers(aZList);
1344 bool aFound = false;
1345 for (int i = 1; i <= aZList.Length(); i++) {
1346 if (aZList(i) == myVisualLayerId) {
1352 aViewer->AddZLayer(myVisualLayerId);
1354 // if there is an active operation with validated widget,
1355 // the filters of this widget should be activated in the created view
1356 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1358 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1359 if (anActiveWidget) {
1360 ModuleBase_WidgetSelector* aWSelector =
1361 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1363 aWSelector->activateSelectionAndFilters(true);
1368 //******************************************************
1369 void PartSet_Module::widgetStateChanged(int thePreviousState)
1371 mySketchMgr->widgetStateChanged(thePreviousState);
1374 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1376 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1379 //******************************************************
1380 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1382 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1383 mySketchMgr->stopSketch(theOperation);
1387 //******************************************************
1388 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1390 GeomShapePtr aGeomShape;
1392 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1393 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1394 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1399 //******************************************************
1400 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1401 const GeomShapePtr& theGeomShape)
1403 AttributePtr anAttribute;
1404 GeomShapePtr aGeomShape = theGeomShape;
1405 if (!aGeomShape.get()) {
1406 // processing shape of result, e.g. sketch circle center is selected, this is a result
1407 // the geom shape is empty, the shape of result should be used
1408 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1409 if (aResult.get()) {
1410 aGeomShape = aResult->shape();
1414 if (aGeomShape.get()) {
1415 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1416 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1417 mySketchMgr->activeSketch());
1422 //******************************************************
1423 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1426 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1430 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1431 if (!aChoiceTitle.isEmpty()) {
1432 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1435 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1437 aPanel->setWindowTitle(aChoiceTitle);
1441 //******************************************************
1442 XGUI_Workshop* PartSet_Module::getWorkshop() const
1444 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1445 return aConnector->workshop();
1448 //******************************************************
1449 void PartSet_Module::setDefaultConstraintShown()
1451 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1452 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1453 myHasConstraintShown[PartSet_Tools::Expressions] = false;