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());
171 PartSet_Module::~PartSet_Module()
173 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
174 for (; aIt.More(); aIt.Next()) {
175 Handle(SelectMgr_Filter) aFilter = aIt.Value();
176 if (!aFilter.IsNull())
180 delete myOverconstraintListener;
183 void PartSet_Module::activateSelectionFilters()
185 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
186 for (; aIt.More(); aIt.Next()) {
187 Handle(SelectMgr_Filter) aFilter = aIt.Value();
188 if (!aFilter.IsNull())
189 myWorkshop->viewer()->addSelectionFilter(aFilter);
193 void PartSet_Module::deactivateSelectionFilters()
195 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
196 for (; aIt.More(); aIt.Next()) {
197 Handle(SelectMgr_Filter) aFilter = aIt.Value();
198 if (!aFilter.IsNull())
199 myWorkshop->viewer()->removeSelectionFilter(aFilter);
203 void PartSet_Module::storeSelection()
205 sketchMgr()->storeSelection();
208 void PartSet_Module::restoreSelection()
210 sketchMgr()->restoreSelection();
213 void PartSet_Module::registerValidators()
215 //Registering of validators
216 SessionPtr aMgr = ModelAPI_Session::get();
217 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
218 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
219 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
220 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
221 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
222 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
223 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
224 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
225 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
226 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
227 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
228 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
229 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
230 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
231 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
232 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
233 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
234 aFactory->registerValidator("PartSet_MultyTranslationSelection",
235 new PartSet_MultyTranslationSelection);
236 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
237 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
240 void PartSet_Module::registerProperties()
242 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::Double,
244 Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
245 Config_Prop::Integer, SKETCH_WIDTH);
246 Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
247 "Rotate to plane when selected", Config_Prop::Boolean, "false");
250 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
251 const bool isToConnect)
253 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
256 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
258 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
259 mySketchMgr->commitNestedSketch(theOperation);
262 /// Restart sketcher operations automatically
263 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
265 ModuleBase_OperationFeature* aFOperation =
266 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
267 if (aFOperation && !aFOperation->isEditOperation()) {
268 // the selection is cleared after commit the create operation
269 // in order to do not use the same selected objects in the restarted operation
270 // for common behaviour, the selection is cleared even if the operation is not restarted
271 getWorkshop()->selector()->clearSelection();
276 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
278 /// Restart sketcher operations automatically
279 mySketchReentrantMgr->operationAborted(theOperation);
282 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
284 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
287 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
288 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
290 ModuleBase_ModelWidget* aFilledWidget = 0;
291 bool aPostonedWidgetActivation = false;
293 FeaturePtr aFeature = aFOperation->feature();
294 /// Restart sketcher operations automatically
295 /// it is important to call method of sketch reentrant manager before filling of PP
296 /// because it fills some created feature attributes, these new values should be used
297 /// to fill the property panel
298 mySketchReentrantMgr->operationStarted(theOperation);
300 aWorkshop->fillPropertyPanel(aFOperation);
301 // filling the operation values by the current selection
302 // if the operation can be committed after the controls filling, the method perform should
303 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
304 bool isOperationCommitted = false;
305 if (!aFOperation->isEditOperation()) {
306 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
307 // if there is a greed attribute, automatic commit by preselection
308 // for this feature is prohibited
309 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
310 if (currentOperation() != aFOperation)
311 isOperationCommitted = true;
313 if (aGreedAttributeId.empty()) {
314 // a signal should be emitted before the next widget activation
315 // because, the activation of the next widget will give a focus to the widget.
316 // As a result the value of the widget is initialized.
317 // And commit may happens until the value is entered.
319 if (mySketchReentrantMgr->canBeCommittedByPreselection())
320 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
321 // activate the next obligatory widget
322 if (!isOperationCommitted)
323 aPropertyPanel->activateNextWidget(aFilledWidget);
326 else { // there is a greed widget
327 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
328 std::string aFirstAttributeId = aWidgets.front()->attributeID();
329 // activate next widget after greeded if it is the first widget in the panel
330 // else the first panel widget is already activated by operation start
331 if (aFirstAttributeId == aGreedAttributeId)
332 aPostonedWidgetActivation = true;
335 } if (!isOperationCommitted) {
336 aWorkshop->connectToPropertyPanel(true);
337 updateSketcherOnStart(aFOperation);
338 updatePresentationsOnStart(aFOperation);
340 // the objects of the current operation should be deactivated
341 QObjectPtrList anObjects;
342 anObjects.append(aFeature);
343 std::list<ResultPtr> aResults;
344 ModelAPI_Tools::allResults(aFeature, aResults);
345 std::list<ResultPtr>::const_iterator aIt;
346 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
347 anObjects.append(*aIt);
349 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
350 for (; anIt != aLast; anIt++)
351 aWorkshop->deactivateActiveObject(*anIt, false);
352 if (anObjects.size() > 0) {
353 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
354 aDisplayer->updateViewer();
356 /// state of command actions should be updated after displayed objects modification because
357 /// deactivation(for example) of objects may influence on selection in the viewer
358 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
359 workshop()->updateCommandStatus();
361 if (aPostonedWidgetActivation) {
362 // if the widget is an empty in the chain of activated widgets, the current operation
363 // is restarted. It should be performed after functionality of the operation starting
364 aPropertyPanel->activateNextWidget(aFilledWidget);
369 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
371 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
372 mySketchMgr->startSketch(theOperation);
374 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
375 mySketchMgr->startNestedSketch(theOperation);
379 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
381 ModuleBase_OperationFeature* aFOperation =
382 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
384 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
385 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
389 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
391 ModuleBase_IModule::operationResumed(theOperation);
393 ModuleBase_OperationFeature* aFOperation =
394 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
396 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
397 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
401 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
403 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
404 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
405 bool isModified = isModifiedArgs || isModifiedResults;
407 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
408 mySketchMgr->stopNestedSketch(theOperation);
410 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
411 setDefaultConstraintShown();
413 //VSV: Viewer is updated on feature update and redisplay
415 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
416 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
417 aDisplayer->updateViewer();
420 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
421 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
422 for (; anIt != aLast; anIt++) {
423 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
427 ModuleBase_Operation* PartSet_Module::currentOperation() const
429 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
430 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
431 return anOpMgr->currentOperation();
434 bool PartSet_Module::canUndo() const
436 bool aCanUndo = false;
437 SessionPtr aMgr = ModelAPI_Session::get();
438 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
439 aCanUndo = !aMgr->isOperation();
440 if (!aCanUndo) // check the enable state additionally by sketch manager
441 aCanUndo = aMgr->canUndo();
446 bool PartSet_Module::canRedo() const
448 bool aCanRedo = false;
449 SessionPtr aMgr = ModelAPI_Session::get();
450 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
451 aCanRedo = !aMgr->isOperation();
452 if (!aCanRedo) // check the enable state additionally by sketch manager
453 aCanRedo = aMgr->canRedo();
458 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
461 if (theActionId == "MOVE_CMD") {
462 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
464 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
465 // part features can not be moved in the history.
466 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
473 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
475 // the sketch manager put the restriction to the objects erase
476 return mySketchMgr->canEraseObject(theObject);
479 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
481 // the sketch manager put the restriction to the objects display
482 return mySketchMgr->canDisplayObject(theObject);
485 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
487 mySketchMgr->processHiddenObject(theObjects);
490 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
492 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
494 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
495 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
496 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
497 if (isSketchOp || isNestedOp) {
498 // in active sketch operation it is possible to activate operation object in selection
499 // in the edit operation, e.g. points of the line can be moved when the line is edited
500 ModuleBase_OperationFeature* aFOperation =
501 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
502 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
507 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
509 QMap<int, QAction*>& theMenuActions) const
511 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
514 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
516 myMenuMgr->updateViewerMenu(theStdActions);
519 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
521 bool isEnabledFixed = false;
522 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
523 mySketchReentrantMgr->isInternalEditStarted())
524 isEnabledFixed = true;
525 return isEnabledFixed;
528 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
530 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
531 if (anError.isEmpty())
532 anError = sketchMgr()->getFeatureError(theFeature);
537 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
538 QStringList& theIds) const
540 myMenuMgr->grantedOperationIds(theOperation, theIds);
542 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
543 XGUI_Workshop* aWorkshop = getWorkshop();
544 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
548 void PartSet_Module::activeSelectionModes(QIntList& theModes)
551 if (mySketchMgr->activeSketch().get())
552 PartSet_SketcherMgr::sketchSelectionModes(theModes);
555 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
557 if (theTypes.contains(TopAbs_FACE))
558 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
559 if (theTypes.contains(TopAbs_WIRE))
560 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
563 bool PartSet_Module::isMouseOverWindow()
565 return mySketchMgr->isMouseOverWindow();
568 bool PartSet_Module::isSketchNeutralPointActivated() const
570 bool isNeutralPoint = true;
571 if (sketchReentranceMgr()->isInternalEditStarted())
572 isNeutralPoint = false;
573 if (myIsOperationIsLaunched)
574 isNeutralPoint = false;
576 return isNeutralPoint;
579 void PartSet_Module::closeDocument()
581 myActivePartIndex = QModelIndex();
585 void PartSet_Module::clearViewer()
587 myCustomPrs->clearPrs();
589 XGUI_Workshop* aWorkshop = getWorkshop();
590 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
591 aDisplayer->deactivateSelectionFilters();
594 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
596 ModuleBase_OperationFeature* aFOperation =
597 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
601 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
602 // we have to manually activate the sketch label in edit mode
603 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
604 aPanel->activateWidget(aPanel->modelWidgets().first());
607 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
608 QList<ModuleBase_ModelWidget*>& theWidgets) const
610 bool aProcessed = false;
612 ModuleBase_OperationFeature* aFOperation =
613 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
614 XGUI_Workshop* aWorkshop = getWorkshop();
615 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
616 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
617 ModuleBase_ISelection* aSelection = workshop()->selection();
618 // click on a point in sketch leads here with the point is highlighted, not yet selected
619 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
620 if (aPreselection.size() == 1) {
621 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
622 ObjectPtr anObject = aSelectedPrs->object();
624 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
625 FeaturePtr anOpFeature = aFOperation->feature();
626 GeomShapePtr aShape = aSelectedPrs->shape();
627 // click on the digit of dimension constrain comes here
628 // with an empty shape, so we need the check
629 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
630 // if feature has only one result and shape of result is equal to selected shape
631 // this attribute is not processed. It is a case of Sketch Point.
632 if (aFeature->results().size() == 1) {
633 ResultPtr aResult = aFeature->results().front();
634 if (aResult.get() && aResult->shape()->isEqual(aShape))
637 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
638 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
639 mySketchMgr->activeSketch());
640 if (anAttribute.get()) {
641 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
642 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
644 const std::string anAttributeId = anAttribute->id();
645 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
647 theWidgets = aFactory.getModelWidgets();
648 // it is possible that the point does not present in XML definition,
649 // in this case, we assume that it is not processed by this module
650 // e.g. "Intersection point" feature
651 aProcessed = !theWidgets.isEmpty();
659 void PartSet_Module::onSelectionChanged()
661 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
665 bool isSketcherOp = false;
666 // An edit operation is enable only if the current opeation is the sketch operation
667 if (mySketchMgr->activeSketch()) {
668 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
669 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
672 // Editing of constraints can be done on selection
673 ModuleBase_ISelection* aSelect = myWorkshop->selection();
674 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
675 if (aSelected.size() == 1) {
676 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
677 ObjectPtr aObject = aPrs->object();
678 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
680 std::string aId = aFeature->getKind();
681 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
682 (aId == SketchPlugin_ConstraintLength::ID()) ||
683 (aId == SketchPlugin_ConstraintDistance::ID()) ||
684 (aId == SketchPlugin_ConstraintAngle::ID())) {
685 editFeature(aFeature);
692 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
694 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
695 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
696 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
699 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
701 Config_WidgetAPI* theWidgetApi)
703 ModuleBase_IWorkshop* aWorkshop = workshop();
704 XGUI_Workshop* aXUIWorkshop = getWorkshop();
705 ModuleBase_ModelWidget* aWgt = NULL;
706 if (theType == "sketch-start-label") {
707 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
708 theWidgetApi, myHasConstraintShown);
709 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
710 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
711 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
712 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
714 } else if (theType == "sketch-2dpoint_selector") {
715 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
717 aPointWgt->setSketch(mySketchMgr->activeSketch());
718 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
720 }else if (theType == "sketch-2dpoint_flyout_selector") {
721 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
723 aPointWgt->setSketch(mySketchMgr->activeSketch());
724 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
726 } else if (theType == "point2ddistance") {
727 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
728 aWorkshop, theWidgetApi);
729 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
731 } else if (theType == "sketch_shape_selector") {
732 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
733 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
734 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
735 aWgt = aShapeSelectorWgt;
736 } else if (theType == "sketch_multi_selector") {
737 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
738 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
739 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
740 aWgt = aShapeSelectorWgt;
742 else if (theType == "sketch_sub_shape_selector") {
743 PartSet_WidgetSubShapeSelector* aSubShapeSelectorWgt =
744 new PartSet_WidgetSubShapeSelector(theParent, aWorkshop, theWidgetApi);
745 aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
746 aWgt = aSubShapeSelectorWgt;
748 else if (theType == "sketch_feature_point_selector") {
749 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
750 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
751 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
752 aWgt = aPointSelectorWgt;
754 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
755 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
756 } else if (theType == "export_file_selector") {
757 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
758 } else if (theType == "sketch_launcher") {
759 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
760 } else if (theType == "module_choice") {
761 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
762 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
763 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
768 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
770 ModuleBase_ModelWidget* anActiveWidget = 0;
772 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
773 if (!anActiveWidget) {
774 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
776 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
777 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
780 return anActiveWidget;
783 bool PartSet_Module::deleteObjects()
785 bool isProcessed = false;
787 XGUI_Workshop* aWorkshop = getWorkshop();
788 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
790 //SessionPtr aMgr = ModelAPI_Session::get();
791 // 1. check whether the delete should be processed in the module
792 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
793 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
794 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
795 if (isSketchOp || isNestedOp) {
797 // 2. find selected presentations
798 // selected objects should be collected before the current operation abort because
799 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
800 ModuleBase_ISelection* aSel = workshop()->selection();
801 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
802 // if there are no selected objects in the viewer, that means that the selection in another
803 // place cased this method. It is necessary to return the false value to understande in above
804 // method that delete is not processed
805 if (aSelectedObj.count() == 0)
808 // avoid delete of the objects, which are not belong to the current sketch
809 // in order to do not delete results of other sketches
810 QObjectPtrList aSketchObjects;
811 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
812 for ( ; anIt != aLast; anIt++) {
813 ObjectPtr anObject = *anIt;
814 if (mySketchMgr->isObjectOfSketch(anObject)) {
815 // sketch feature should be used in this list because workshop deletes features only
816 // results are skipped
817 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
818 aSketchObjects.append(aSketchFeature);
821 // if the selection contains only local selected presentations from other sketches,
822 // the Delete operation should not be done at all
823 if (aSketchObjects.size() == 0)
826 // 3. start operation
827 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
828 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
830 // the active nested sketch operation should be aborted unconditionally
831 // the Delete action should be additionally granted for the Sketch operation
832 // in order to do not abort/commit it
833 if (!anOpMgr->canStartOperation(anOpAction->id()))
834 return true; // the objects are processed but can not be deleted
836 anOpMgr->startOperation(anOpAction);
838 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
839 // the problem is in AIS Dimensions recompute
840 // if a line and the dim are removed, line is the first
841 // it causes the AIS recompute, where the base line is null,
842 // the result is empty AIS in the viewer
843 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
845 // 4. delete features
846 // sketch feature should be skipped, only sub-features can be removed
847 // when sketch operation is active
848 aWorkshop->deleteFeatures(aSketchObjects);
850 anOpMgr->commitOperation();
855 void PartSet_Module::onFeatureTriggered()
857 // is commented for imp: Unpressing the button of the current action must behave like
858 // a validation if the entity can be created (instead of Cancel, as currently)
859 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
860 if (aCmd->isCheckable() && aCmd->isChecked()) {
861 // 1. check whether the delete should be processed in the module
862 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
863 bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
865 // in case if in the viewer nothing is displayed, the create operation should not be
866 // comitted even if all values of the feature are initialized
867 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
868 // the action information should be saved before the operation is aborted
869 // because this abort leads to update command status, which unchecks this action
870 anOperation->abort();
871 launchOperation(aCmd->data().toString());
875 ModuleBase_IModule::onFeatureTriggered();
878 void PartSet_Module::editFeature(FeaturePtr theFeature)
880 storeConstraintsState(theFeature->getKind());
881 ModuleBase_IModule::editFeature(theFeature);
884 bool PartSet_Module::canCommitOperation() const
889 void PartSet_Module::launchOperation(const QString& theCmdId)
891 myIsOperationIsLaunched = true;
892 storeConstraintsState(theCmdId.toStdString());
893 updateConstraintsState(theCmdId.toStdString());
895 ModuleBase_IModule::launchOperation(theCmdId);
897 myIsOperationIsLaunched = false;
900 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
902 if (myWorkshop->currentOperation() &&
903 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
904 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
905 mySketchMgr->showConstraintStates();
906 myHasConstraintShown = aShownStates;
910 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
912 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
913 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
914 // Show constraints if a constraint was anOperation
915 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
916 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
917 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
918 myHasConstraintShown[PartSet_Tools::Expressions]);
922 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
924 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
925 if (!anAIS.IsNull()) {
926 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
927 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
928 if (!aDim.IsNull()) {
929 aCtx->SetZLayer(aDim, myVisualLayerId);
931 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
933 aCtx->SetZLayer(aCons, myVisualLayerId);
938 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
941 // it should be recomputed in order to disappear in the viewer if the corresponded object
943 //if (myCustomPrs->isActive())
944 // myCustomPrs->redisplay(theObject, false);
947 void PartSet_Module::onViewTransformed(int theTrsfType)
949 // Set length of arrows constant in pixel size
950 // if the operation is panning or rotate or panglobal then do nothing
951 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
953 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
954 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
955 if (aContext.IsNull())
958 //Handle(V3d_View) aView = aViewer->activeView();
960 XGUI_Workshop* aWorkshop = getWorkshop();
961 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
962 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
963 Handle(V3d_View) aView;
965 for (aV3dViewer->InitDefinedViews();
966 aV3dViewer->MoreDefinedViews();
967 aV3dViewer->NextDefinedViews()) {
968 Handle(V3d_View) aV = aV3dViewer->DefinedView();
969 double aS = aV->Scale();
977 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
979 double aPrevLen = SketcherPrs_Tools::getArrowSize();
980 SketcherPrs_Tools::setArrowSize(aLen);
981 const double aPrevScale = aViewer->Scale(aViewer->activeView());
982 const double aCurScale = aViewer->activeView()->Camera()->Scale();
983 aViewer->SetScale(aViewer->activeView(), aCurScale);
984 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
985 bool isModified = false;
986 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
987 foreach (AISObjectPtr aAIS, aPrsList) {
988 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
990 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
991 if (!aDim.IsNull()) {
992 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
993 aContext->Redisplay(aDim, false);
998 aDisplayer->updateViewer();
1001 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1003 return myCustomPrs->isActive(theFlag);
1006 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1007 const ModuleBase_CustomizeFlag& theFlag,
1008 const bool theUpdateViewer)
1010 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1013 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1014 const bool theUpdateViewer)
1016 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1019 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1020 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1022 bool aCustomized = false;
1024 XGUI_Workshop* aWorkshop = getWorkshop();
1025 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1026 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1030 if (!theResult.get()) {
1031 bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
1032 // customize sketch symbol presentation
1034 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1035 if (!anAISIO.IsNull()) {
1036 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1037 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1038 if (!aPrs.IsNull()) {
1039 std::vector<int> aColor;
1040 myOverconstraintListener->getConflictingColor(aColor);
1041 aPrs->SetConflictingConstraint(isConflicting, aColor);
1044 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1045 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1046 if (!aPrs.IsNull()) {
1047 std::vector<int> aColor;
1048 myOverconstraintListener->getConflictingColor(aColor);
1049 aPrs->SetConflictingConstraint(isConflicting, aColor);
1055 // customize sketch dimension constraint presentation
1057 std::vector<int> aColor;
1058 if (isConflicting) {
1059 myOverconstraintListener->getConflictingColor(aColor);
1062 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1063 if (!aColor.empty()) {
1064 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1068 // customize dimentional constrains
1069 sketchMgr()->customizePresentation(anObject);
1074 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1075 const bool theUpdateViewer)
1077 bool isRedisplayed = false;
1078 if (myCustomPrs->isActive(theFlag))
1079 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1081 return isRedisplayed;
1084 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1086 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1088 QLabel* aLabel = aOB->activeDocLabel();
1089 aLabel->installEventFilter(myMenuMgr);
1090 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1091 SLOT(onActiveDocPopup(const QPoint&)));
1092 aOB->treeView()->setExpandsOnDoubleClick(false);
1093 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1094 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1096 Events_Loop* aLoop = Events_Loop::loop();
1097 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1101 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1103 SessionPtr aMgr = ModelAPI_Session::get();
1104 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1106 XGUI_Workshop* aWorkshop = getWorkshop();
1107 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1109 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1112 aMenu.addAction(aActivatePartAction);
1113 aMenu.exec(aHeader->mapToGlobal(thePnt));
1116 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1118 return mySketchMgr->createPresentation(theResult);
1122 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1125 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1127 /// If last line finished on vertex the lines creation sequence has to be break
1128 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1130 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1131 // if there is an active widget, find the presented object in it
1132 if (!anActiveWidget)
1133 anActiveWidget = aPanel->preselectionWidget();
1135 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1137 if (aWidgetValidated)
1138 anObject = aWidgetValidated->findPresentedObject(theAIS);
1144 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1146 bool aCanBeShaged = true;
1148 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1150 aCanBeShaged = false;
1152 return aCanBeShaged;
1155 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1157 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1158 int aSelected = aObjects.size();
1159 SessionPtr aMgr = ModelAPI_Session::get();
1160 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1162 bool hasResult = false;
1163 bool hasFeature = false;
1164 bool hasParameter = false;
1165 bool hasCompositeOwner = false;
1166 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1169 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1170 if (aSelected == 1) {
1171 ObjectPtr aObject = aObjects.first();
1173 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1174 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1175 bool isPart = aPart.get() ||
1176 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1178 DocumentPtr aPartDoc;
1180 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1182 if (aPart.get()) // this may be null is Part feature is disabled
1183 aPartDoc = aPart->partDoc();
1185 theMenu->addAction(aActivatePartAction);
1186 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1188 } else if (aObject->document() == aMgr->activeDocument()) {
1189 if (hasParameter || hasFeature) {
1190 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1191 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1192 if (aCurrentOp && aFeature.get()) {
1193 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1194 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1201 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1202 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1203 theMenu->addSeparator();
1206 bool aNotDeactivate = (aCurrentOp == 0);
1207 if (!aNotDeactivate) {
1208 aActivatePartAction->setEnabled(false);
1212 #define EXPAND_PARENT(OBJ) \
1213 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1214 if (aObjIndex.isValid()) { \
1215 QModelIndex aParent = aObjIndex.parent(); \
1216 int aCount = aDataModel->rowCount(aParent); \
1218 aTreeView->setExpanded(aParent, true); \
1222 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1224 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1225 // Do not change activation of parts if an operation active
1226 static QStringList aAllowActivationList;
1227 if (aAllowActivationList.isEmpty())
1228 aAllowActivationList <<
1229 QString(PartSetPlugin_Part::ID().c_str()) <<
1230 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1231 QString(PartSetPlugin_Remove::ID().c_str());
1232 if (myWorkshop->currentOperation() &&
1233 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1235 XGUI_Workshop* aWorkshop = getWorkshop();
1236 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1237 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1238 QPalette aPalet = aLabel->palette();
1240 SessionPtr aMgr = ModelAPI_Session::get();
1241 DocumentPtr aActiveDoc = aMgr->activeDocument();
1242 if (myActivePartIndex.isValid())
1243 aTreeView->setExpanded(myActivePartIndex, false);
1244 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1245 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1246 if (myActivePartIndex.isValid())
1247 aTreeView->setExpanded(myActivePartIndex, true);
1249 aLabel->setPalette(aPalet);
1250 aWorkshop->updateCommandStatus();
1252 // Update displayed objects in order to update active color
1253 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1254 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1256 foreach(ObjectPtr aObj, aObjects) {
1257 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1258 aObj->isDisabled() || (!aObj->isDisplayed());
1260 aDisplayer->redisplay(aObj, false);
1262 aDisplayer->updateViewer();
1263 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1264 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1265 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1266 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1268 ObjectPtr aConstrObj;
1269 ObjectPtr aResultObj;
1270 std::set<ObjectPtr>::const_iterator aIt;
1271 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1272 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1273 ObjectPtr aObject = (*aIt);
1274 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1275 && (aObject->document() != aRootDoc))
1276 aResultObj = aObject;
1277 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1278 && (aObject->document() != aRootDoc))
1279 aConstrObj = aObject;
1280 if (aResultObj.get() && aConstrObj.get())
1284 if (aResultObj.get() || aConstrObj.get()) {
1285 XGUI_Workshop* aWorkshop = getWorkshop();
1286 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1287 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1289 if (aResultObj.get()) {
1290 EXPAND_PARENT(aResultObj)
1292 if (aConstrObj.get()) {
1293 EXPAND_PARENT(aConstrObj)
1299 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1301 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1303 SessionPtr aMgr = ModelAPI_Session::get();
1304 if (!theIndex.isValid()) {
1305 // It seems that this code is obsolete
1306 //aMgr->setActiveDocument(aMgr->moduleDocument());
1309 if (theIndex.column() != 0) // Use only first column
1312 XGUI_Workshop* aWorkshop = getWorkshop();
1313 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1314 // De not use non editable Indexes
1315 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1317 ObjectPtr aObj = aDataModel->object(theIndex);
1319 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1320 if (!aPart.get()) { // Probably this is Feature
1321 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1322 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1323 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1326 if (aPart.get()) { // if this is a part
1327 if (aPart->partDoc() == aMgr->activeDocument()) {
1328 myMenuMgr->activatePartSet();
1330 myMenuMgr->activatePart(aPart);
1336 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1338 // z layer is created for all started operations in order to visualize operation AIS presentation
1340 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1341 if (aContext.IsNull())
1344 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1345 if (myVisualLayerId == 0) {
1346 if (myVisualLayerId == 0)
1347 aViewer->AddZLayer(myVisualLayerId);
1349 TColStd_SequenceOfInteger aZList;
1350 aViewer->GetAllZLayers(aZList);
1351 bool aFound = false;
1352 for (int i = 1; i <= aZList.Length(); i++) {
1353 if (aZList(i) == myVisualLayerId) {
1359 aViewer->AddZLayer(myVisualLayerId);
1361 // if there is an active operation with validated widget,
1362 // the filters of this widget should be activated in the created view
1363 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1365 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1366 if (anActiveWidget) {
1367 ModuleBase_WidgetSelector* aWSelector =
1368 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1370 aWSelector->activateSelectionAndFilters(true);
1375 //******************************************************
1376 void PartSet_Module::widgetStateChanged(int thePreviousState)
1378 mySketchMgr->widgetStateChanged(thePreviousState);
1381 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1383 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1386 //******************************************************
1387 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1389 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1390 mySketchMgr->stopSketch(theOperation);
1394 //******************************************************
1395 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1397 GeomShapePtr aGeomShape;
1399 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1400 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1401 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1406 //******************************************************
1407 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1408 const GeomShapePtr& theGeomShape)
1410 AttributePtr anAttribute;
1411 GeomShapePtr aGeomShape = theGeomShape;
1412 if (!aGeomShape.get()) {
1413 // processing shape of result, e.g. sketch circle center is selected, this is a result
1414 // the geom shape is empty, the shape of result should be used
1415 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1416 if (aResult.get()) {
1417 aGeomShape = aResult->shape();
1421 if (aGeomShape.get()) {
1422 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1423 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1424 mySketchMgr->activeSketch());
1429 //******************************************************
1430 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1433 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1437 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1438 if (!aChoiceTitle.isEmpty()) {
1439 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1442 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1444 aPanel->setWindowTitle(aChoiceTitle);
1448 //******************************************************
1449 XGUI_Workshop* PartSet_Module::getWorkshop() const
1451 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1452 return aConnector->workshop();
1455 //******************************************************
1456 void PartSet_Module::setDefaultConstraintShown()
1458 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1459 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1460 myHasConstraintShown[PartSet_Tools::Expressions] = false;