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_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetMultiSelector.h"
12 #include "PartSet_WidgetSubShapeSelector.h"
13 #include "PartSet_WidgetFeaturePointSelector.h"
14 #include "PartSet_WidgetEditor.h"
15 #include "PartSet_WidgetFileSelector.h"
16 #include "PartSet_WidgetSketchCreator.h"
17 #include "PartSet_SketcherMgr.h"
18 #include "PartSet_SketcherReentrantMgr.h"
19 #include "PartSet_ResultSketchPrs.h"
20 #include "PartSet_MenuMgr.h"
21 #include "PartSet_CustomPrs.h"
22 #include "PartSet_IconFactory.h"
23 #include "PartSet_WidgetChoice.h"
24 #include "PartSet_OverconstraintListener.h"
26 #include "PartSet_Filters.h"
27 #include "PartSet_FilterInfinite.h"
29 #include <PartSetPlugin_Remove.h>
30 #include <PartSetPlugin_Part.h>
31 #include <PartSetPlugin_Duplicate.h>
33 #include <ModuleBase_Operation.h>
34 #include <ModuleBase_OperationAction.h>
35 #include <ModuleBase_IViewer.h>
36 #include <ModuleBase_IViewWindow.h>
37 #include <ModuleBase_IPropertyPanel.h>
38 #include <ModuleBase_WidgetEditor.h>
39 #include <ModuleBase_WidgetValidated.h>
40 #include <ModuleBase_Tools.h>
41 #include <ModuleBase_OperationFeature.h>
42 #include <ModuleBase_WidgetFactory.h>
43 #include <ModuleBase_OperationDescription.h>
44 #include <ModuleBase_ViewerPrs.h>
46 #include <ModelAPI_Object.h>
47 #include <ModelAPI_Events.h>
48 #include <ModelAPI_Validator.h>
49 #include <ModelAPI_Data.h>
50 #include <ModelAPI_Session.h>
51 #include <ModelAPI_ResultBody.h>
52 #include <ModelAPI_AttributeString.h>
53 #include <ModelAPI_AttributeSelectionList.h>
54 #include <ModelAPI_Tools.h>
55 #include <ModelAPI_ResultConstruction.h>
57 #include <GeomDataAPI_Point2D.h>
58 #include <GeomDataAPI_Point.h>
59 #include <GeomDataAPI_Dir.h>
61 #include <XGUI_Displayer.h>
62 #include <XGUI_Workshop.h>
63 #include <XGUI_OperationMgr.h>
64 #include <XGUI_PropertyPanel.h>
65 #include <XGUI_ModuleConnector.h>
66 #include <XGUI_ContextMenuMgr.h>
67 #include <XGUI_Tools.h>
68 #include <XGUI_ObjectsBrowser.h>
69 #include <XGUI_SelectionMgr.h>
70 #include <XGUI_DataModel.h>
71 #include <XGUI_ErrorMgr.h>
72 #include <XGUI_CustomPrs.h>
73 #include <XGUI_SelectionMgr.h>
74 #include <XGUI_ActionsMgr.h>
76 #include <SketchPlugin_Feature.h>
77 #include <SketchPlugin_Sketch.h>
78 #include <SketchPlugin_ConstraintAngle.h>
79 #include <SketchPlugin_ConstraintLength.h>
80 #include <SketchPlugin_ConstraintDistance.h>
81 #include <SketchPlugin_ConstraintParallel.h>
82 #include <SketchPlugin_ConstraintPerpendicular.h>
83 #include <SketchPlugin_ConstraintRadius.h>
85 #include <SketcherPrs_SymbolPrs.h>
86 #include <SketcherPrs_Coincident.h>
87 #include <SketcherPrs_Tools.h>
89 #include <Events_Loop.h>
90 #include <Config_PropManager.h>
91 #include <Config_Keywords.h>
93 #include <AIS_Dimension.hxx>
94 #include <AIS_InteractiveObject.hxx>
95 #include <StdSelect_TypeOfFace.hxx>
96 #include <TopoDS_Vertex.hxx>
98 #include <TopoDS_Shape.hxx>
99 #include <BRep_Tool.hxx>
102 #include <QMouseEvent>
105 #include <QApplication>
106 #include <QMessageBox>
107 #include <QMainWindow>
111 #include <GeomAlgoAPI_FaceBuilder.h>
112 #include <GeomDataAPI_Dir.h>
114 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
120 /*!Create and return new instance of XGUI_Module*/
121 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
123 return new PartSet_Module(theWshop);
126 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
127 : ModuleBase_IModule(theWshop),
129 myIsOperationIsLaunched(false)
131 new PartSet_IconFactory();
133 mySketchMgr = new PartSet_SketcherMgr(this);
134 mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
136 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
137 XGUI_Workshop* aWorkshop = aConnector->workshop();
139 ModuleBase_IViewer* aViewer = theWshop->viewer();
140 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
141 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
142 connect(aViewer, SIGNAL(viewTransformed(int)),
143 SLOT(onViewTransformed(int)));
144 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
145 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
146 myMenuMgr = new PartSet_MenuMgr(this);
147 myCustomPrs = new PartSet_CustomPrs(theWshop);
149 myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
151 Events_Loop* aLoop = Events_Loop::loop();
152 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
154 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
155 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
157 setDefaultConstraintShown();
159 Config_PropManager::registerProp("Visualization", "operation_parameter_color",
160 "Reference shape wireframe color in operation", Config_Prop::Color,
161 PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
162 Config_PropManager::registerProp("Visualization", "operation_result_color",
163 "Result shape wireframe color in operation", Config_Prop::Color,
164 PartSet_CustomPrs::OPERATION_RESULT_COLOR());
165 Config_PropManager::registerProp("Visualization", "operation_highlight_color",
166 "Multi selector item color in operation", Config_Prop::Color,
167 PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
168 Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
169 "Color of removed feature in operation", Config_Prop::Color,
170 PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
173 PartSet_Module::~PartSet_Module()
175 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
176 for (; aIt.More(); aIt.Next()) {
177 Handle(SelectMgr_Filter) aFilter = aIt.Value();
178 if (!aFilter.IsNull())
182 delete myOverconstraintListener;
185 void PartSet_Module::activateSelectionFilters()
187 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
188 for (; aIt.More(); aIt.Next()) {
189 Handle(SelectMgr_Filter) aFilter = aIt.Value();
190 if (!aFilter.IsNull())
191 myWorkshop->viewer()->addSelectionFilter(aFilter);
195 void PartSet_Module::deactivateSelectionFilters()
197 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
198 for (; aIt.More(); aIt.Next()) {
199 Handle(SelectMgr_Filter) aFilter = aIt.Value();
200 if (!aFilter.IsNull())
201 myWorkshop->viewer()->removeSelectionFilter(aFilter);
205 void PartSet_Module::storeSelection()
207 sketchMgr()->storeSelection();
210 void PartSet_Module::restoreSelection()
212 sketchMgr()->restoreSelection();
215 void PartSet_Module::registerValidators()
217 //Registering of validators
218 SessionPtr aMgr = ModelAPI_Session::get();
219 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
220 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
221 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
222 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
223 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
224 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
225 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
226 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
227 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
228 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
229 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
230 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
231 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
232 aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
233 aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
234 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
235 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
236 aFactory->registerValidator("PartSet_MultyTranslationSelection",
237 new PartSet_MultyTranslationSelection);
238 aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
239 aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
242 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
243 const bool isToConnect)
245 mySketchMgr->connectToPropertyPanel(theWidget, isToConnect);
248 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
250 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
251 mySketchMgr->commitNestedSketch(theOperation);
254 /// Restart sketcher operations automatically
255 if (!mySketchReentrantMgr->operationCommitted(theOperation)) {
257 ModuleBase_OperationFeature* aFOperation =
258 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
259 if (aFOperation && !aFOperation->isEditOperation()) {
260 // the selection is cleared after commit the create operation
261 // in order to do not use the same selected objects in the restarted operation
262 // for common behaviour, the selection is cleared even if the operation is not restarted
263 getWorkshop()->selector()->clearSelection();
268 void PartSet_Module::operationAborted(ModuleBase_Operation* theOperation)
270 /// Restart sketcher operations automatically
271 mySketchReentrantMgr->operationAborted(theOperation);
274 void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
276 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
279 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(workshop());
280 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
282 ModuleBase_ModelWidget* aFilledWidget = 0;
283 bool aPostonedWidgetActivation = false;
285 FeaturePtr aFeature = aFOperation->feature();
286 /// Restart sketcher operations automatically
287 /// it is important to call method of sketch reentrant manager before filling of PP
288 /// because it fills some created feature attributes, these new values should be used
289 /// to fill the property panel
290 mySketchReentrantMgr->operationStarted(theOperation);
292 aWorkshop->fillPropertyPanel(aFOperation);
293 // filling the operation values by the current selection
294 // if the operation can be committed after the controls filling, the method perform should
295 // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
296 bool isOperationCommitted = false;
297 if (!aFOperation->isEditOperation()) {
298 std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(workshop(), aFeature);
299 // if there is a greed attribute, automatic commit by preselection
300 // for this feature is prohibited
301 aFilledWidget = aFOperation->activateByPreselection(aGreedAttributeId);
302 if (currentOperation() != aFOperation)
303 isOperationCommitted = true;
305 if (aGreedAttributeId.empty()) {
306 // a signal should be emitted before the next widget activation
307 // because, the activation of the next widget will give a focus to the widget.
308 // As a result the value of the widget is initialized.
309 // And commit may happens until the value is entered.
311 if (mySketchReentrantMgr->canBeCommittedByPreselection())
312 isOperationCommitted = mySketchMgr->operationActivatedByPreselection();
313 // activate the next obligatory widget
314 if (!isOperationCommitted)
315 aPropertyPanel->activateNextWidget(aFilledWidget);
318 else { // there is a greed widget
319 const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
320 std::string aFirstAttributeId = aWidgets.front()->attributeID();
321 // activate next widget after greeded if it is the first widget in the panel
322 // else the first panel widget is already activated by operation start
323 if (aFirstAttributeId == aGreedAttributeId)
324 aPostonedWidgetActivation = true;
327 } if (!isOperationCommitted) {
328 aWorkshop->connectToPropertyPanel(true);
329 updateSketcherOnStart(aFOperation);
330 updatePresentationsOnStart(aFOperation);
332 // the objects of the current operation should be deactivated
333 QObjectPtrList anObjects;
334 anObjects.append(aFeature);
335 std::list<ResultPtr> aResults;
336 ModelAPI_Tools::allResults(aFeature, aResults);
337 std::list<ResultPtr>::const_iterator aIt;
338 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
339 anObjects.append(*aIt);
341 QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
342 for (; anIt != aLast; anIt++)
343 aWorkshop->deactivateActiveObject(*anIt, false);
344 if (anObjects.size() > 0) {
345 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
346 aDisplayer->updateViewer();
348 /// state of command actions should be updated after displayed objects modification because
349 /// deactivation(for example) of objects may influence on selection in the viewer
350 /// State of command actions may depend on selection in the viewer(e.g. Sketch)
351 workshop()->updateCommandStatus();
353 if (aPostonedWidgetActivation) {
354 // if the widget is an empty in the chain of activated widgets, the current operation
355 // is restarted. It should be performed after functionality of the operation starting
356 aPropertyPanel->activateNextWidget(aFilledWidget);
361 void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation)
363 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
364 mySketchMgr->startSketch(theOperation);
366 else if (sketchMgr()->isNestedSketchOperation(theOperation)) {
367 mySketchMgr->startNestedSketch(theOperation);
371 void PartSet_Module::updatePresentationsOnStart(ModuleBase_Operation* theOperation)
373 ModuleBase_OperationFeature* aFOperation =
374 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
376 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
377 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
381 void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
383 ModuleBase_IModule::operationResumed(theOperation);
385 ModuleBase_OperationFeature* aFOperation =
386 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
388 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
389 myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
393 void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
395 bool isModifiedArgs = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false);
396 bool isModifiedResults = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
397 bool isModified = isModifiedArgs || isModifiedResults;
399 if (sketchMgr()->isNestedSketchOperation(theOperation)) {
400 mySketchMgr->stopNestedSketch(theOperation);
402 else if (PartSet_SketcherMgr::isSketchOperation(theOperation))
403 setDefaultConstraintShown();
405 //VSV: Viewer is updated on feature update and redisplay
407 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
408 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
409 aDisplayer->updateViewer();
412 QMap<PartSet_Tools::ConstraintVisibleState, bool>::const_iterator
413 anIt = myHasConstraintShown.begin(), aLast = myHasConstraintShown.end();
414 for (; anIt != aLast; anIt++) {
415 mySketchMgr->updateBySketchParameters(anIt.key(), anIt.value());
419 ModuleBase_Operation* PartSet_Module::currentOperation() const
421 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
422 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
423 return anOpMgr->currentOperation();
426 bool PartSet_Module::canUndo() const
428 bool aCanUndo = false;
429 SessionPtr aMgr = ModelAPI_Session::get();
430 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
431 aCanUndo = !aMgr->isOperation();
432 if (!aCanUndo) // check the enable state additionally by sketch manager
433 aCanUndo = aMgr->canUndo();
438 bool PartSet_Module::canRedo() const
440 bool aCanRedo = false;
441 SessionPtr aMgr = ModelAPI_Session::get();
442 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
443 aCanRedo = !aMgr->isOperation();
444 if (!aCanRedo) // check the enable state additionally by sketch manager
445 aCanRedo = aMgr->canRedo();
450 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
453 if (theActionId == "MOVE_CMD") {
454 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
456 ResultPtr aResult = ModuleBase_Tools::firstResult(aFeature);
457 // part features can not be moved in the history.
458 if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group())
465 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
467 // the sketch manager put the restriction to the objects erase
468 return mySketchMgr->canEraseObject(theObject);
471 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
473 // the sketch manager put the restriction to the objects display
474 return mySketchMgr->canDisplayObject(theObject);
477 /*void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
479 mySketchMgr->processHiddenObject(theObjects);
482 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
484 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
486 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
487 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
488 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
489 if (isSketchOp || isNestedOp) {
490 // in active sketch operation it is possible to activate operation object in selection
491 // in the edit operation, e.g. points of the line can be moved when the line is edited
492 ModuleBase_OperationFeature* aFOperation =
493 dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
494 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
499 bool PartSet_Module::addViewerMenu(const QMap<QString, QAction*>& theStdActions,
501 QMap<int, QAction*>& theMenuActions) const
503 return myMenuMgr->addViewerMenu(theStdActions, theParent, theMenuActions);
506 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
508 myMenuMgr->updateViewerMenu(theStdActions);
511 bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
513 bool isEnabledFixed = false;
514 if (theActionId == XGUI_ActionsMgr::AcceptAll &&
515 mySketchReentrantMgr->isInternalEditActive())
516 isEnabledFixed = true;
517 return isEnabledFixed;
520 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
522 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
523 if (anError.isEmpty())
524 anError = sketchMgr()->getFeatureError(theFeature);
529 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
530 QStringList& theIds) const
532 myMenuMgr->grantedOperationIds(theOperation, theIds);
534 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
535 XGUI_Workshop* aWorkshop = getWorkshop();
536 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
540 void PartSet_Module::activeSelectionModes(QIntList& theModes)
543 if (mySketchMgr->activeSketch().get())
544 PartSet_SketcherMgr::sketchSelectionModes(theModes);
547 void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
549 if (theTypes.contains(TopAbs_FACE))
550 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Face);
551 if (theTypes.contains(TopAbs_WIRE))
552 theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
555 void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
556 ObjectPtr& theObject, AttributePtr& theAttribute)
558 ObjectPtr anObject = theSelected->object();
559 GeomShapePtr aShape = theSelected->shape();
561 theAttribute = findAttribute(anObject, aShape);
562 // TODO: try to create result if object is an external object
563 theObject = anObject;
566 bool PartSet_Module::isMouseOverWindow()
568 return mySketchMgr->isMouseOverWindow();
571 bool PartSet_Module::isSketchNeutralPointActivated() const
573 bool isNeutralPoint = true;
574 if (sketchReentranceMgr()->isInternalEditActive())
575 isNeutralPoint = false;
576 if (myIsOperationIsLaunched)
577 isNeutralPoint = false;
579 return isNeutralPoint;
582 void PartSet_Module::closeDocument()
584 myActivePartIndex = QModelIndex();
588 void PartSet_Module::clearViewer()
590 myCustomPrs->clearPrs();
592 XGUI_Workshop* aWorkshop = getWorkshop();
593 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
594 aDisplayer->deactivateSelectionFilters();
597 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
599 ModuleBase_OperationFeature* aFOperation =
600 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
604 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
605 // we have to manually activate the sketch label in edit mode
606 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation()))
607 aPanel->activateWidget(aPanel->modelWidgets().first());
610 bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
611 QList<ModuleBase_ModelWidget*>& theWidgets) const
613 bool aProcessed = false;
615 ModuleBase_OperationFeature* aFOperation =
616 dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
617 XGUI_Workshop* aWorkshop = getWorkshop();
618 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
619 if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
620 ModuleBase_ISelection* aSelection = workshop()->selection();
621 // click on a point in sketch leads here with the point is highlighted, not yet selected
622 QList<ModuleBase_ViewerPrsPtr> aPreselection = aSelection->getHighlighted();
623 if (aPreselection.size() == 1) {
624 ModuleBase_ViewerPrsPtr aSelectedPrs = aPreselection[0];
625 ObjectPtr anObject = aSelectedPrs->object();
627 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
628 FeaturePtr anOpFeature = aFOperation->feature();
629 GeomShapePtr aShape = aSelectedPrs->shape();
630 // click on the digit of dimension constrain comes here
631 // with an empty shape, so we need the check
632 if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
633 // if feature has only one result and shape of result is equal to selected shape
634 // this attribute is not processed. It is a case of Sketch Point.
635 if (aFeature->results().size() == 1) {
636 ResultPtr aResult = aFeature->results().front();
637 if (aResult.get() && aResult->shape()->isEqual(aShape))
640 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
641 AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
642 mySketchMgr->activeSketch());
643 if (anAttribute.get()) {
644 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
645 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
647 const std::string anAttributeId = anAttribute->id();
648 aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
650 theWidgets = aFactory.getModelWidgets();
651 // it is possible that the point does not present in XML definition,
652 // in this case, we assume that it is not processed by this module
653 // e.g. "Intersection point" feature
654 aProcessed = !theWidgets.isEmpty();
662 void PartSet_Module::onSelectionChanged()
664 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
668 bool isSketcherOp = false;
669 // An edit operation is enable only if the current opeation is the sketch operation
670 if (mySketchMgr->activeSketch()) {
671 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
672 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
675 // Editing of constraints can be done on selection
676 ModuleBase_ISelection* aSelect = myWorkshop->selection();
677 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected();
678 if (aSelected.size() == 1) {
679 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
680 ObjectPtr aObject = aPrs->object();
681 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
683 std::string aId = aFeature->getKind();
684 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
685 (aId == SketchPlugin_ConstraintLength::ID()) ||
686 (aId == SketchPlugin_ConstraintDistance::ID()) ||
687 (aId == SketchPlugin_ConstraintAngle::ID())) {
688 editFeature(aFeature);
695 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
697 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
698 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
699 anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
702 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType,
704 Config_WidgetAPI* theWidgetApi)
706 ModuleBase_IWorkshop* aWorkshop = workshop();
707 XGUI_Workshop* aXUIWorkshop = getWorkshop();
708 ModuleBase_ModelWidget* aWgt = NULL;
709 if (theType == "sketch-start-label") {
710 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
711 theWidgetApi, myHasConstraintShown);
712 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
713 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
714 connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
715 mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
717 } else if (theType == "sketch-2dpoint_selector") {
718 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
720 aPointWgt->setSketch(mySketchMgr->activeSketch());
721 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
723 }else if (theType == "sketch-2dpoint_flyout_selector") {
724 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
726 aPointWgt->setSketch(mySketchMgr->activeSketch());
727 connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
729 } else if (theType == "sketch_shape_selector") {
730 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
731 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
732 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
733 aWgt = aShapeSelectorWgt;
734 } else if (theType == "sketch_multi_selector") {
735 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
736 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi);
737 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
738 aWgt = aShapeSelectorWgt;
740 else if (theType == "sketch_sub_shape_selector") {
741 PartSet_WidgetSubShapeSelector* aSubShapeSelectorWgt =
742 new PartSet_WidgetSubShapeSelector(theParent, aWorkshop, theWidgetApi);
743 aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
744 aWgt = aSubShapeSelectorWgt;
746 else if (theType == "sketch_feature_point_selector") {
747 PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
748 new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
749 aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
750 aWgt = aPointSelectorWgt;
752 else if (theType == WDG_DOUBLEVALUE_EDITOR) {
753 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
754 } else if (theType == "export_file_selector") {
755 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi);
756 } else if (theType == "sketch_launcher") {
757 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi);
758 } else if (theType == "module_choice") {
759 aWgt = new PartSet_WidgetChoice(theParent, theWidgetApi);
760 connect(aWgt, SIGNAL(itemSelected(ModuleBase_ModelWidget*, int)),
761 this, SLOT(onChoiceChanged(ModuleBase_ModelWidget*, int)));
766 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
768 ModuleBase_ModelWidget* anActiveWidget = 0;
770 anActiveWidget = mySketchReentrantMgr->internalActiveWidget();
771 if (!anActiveWidget) {
772 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
774 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
775 anActiveWidget = aPanel ? aPanel->activeWidget() : 0;
778 return anActiveWidget;
781 bool PartSet_Module::deleteObjects()
783 bool isProcessed = false;
785 XGUI_Workshop* aWorkshop = getWorkshop();
786 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
788 //SessionPtr aMgr = ModelAPI_Session::get();
789 // 1. check whether the delete should be processed in the module
790 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
791 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
792 isNestedOp = sketchMgr()->isNestedSketchOperation(anOperation);
793 if (isSketchOp || isNestedOp) {
795 // 2. find selected presentations
796 // selected objects should be collected before the current operation abort because
797 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
798 ModuleBase_ISelection* aSel = workshop()->selection();
799 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
800 // if there are no selected objects in the viewer, that means that the selection in another
801 // place cased this method. It is necessary to return the false value to understande in above
802 // method that delete is not processed
803 if (aSelectedObj.count() == 0)
806 // avoid delete of the objects, which are not belong to the current sketch
807 // in order to do not delete results of other sketches
808 QObjectPtrList aSketchObjects;
809 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
810 for ( ; anIt != aLast; anIt++) {
811 ObjectPtr anObject = *anIt;
812 if (mySketchMgr->isObjectOfSketch(anObject)) {
813 // sketch feature should be used in this list because workshop deletes features only
814 // results are skipped
815 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
816 aSketchObjects.append(aSketchFeature);
819 // if the selection contains only local selected presentations from other sketches,
820 // the Delete operation should not be done at all
821 if (aSketchObjects.size() == 0)
824 // 3. start operation
825 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
826 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
828 // the active nested sketch operation should be aborted unconditionally
829 // the Delete action should be additionally granted for the Sketch operation
830 // in order to do not abort/commit it
831 if (!anOpMgr->canStartOperation(anOpAction->id()))
832 return true; // the objects are processed but can not be deleted
834 anOpMgr->startOperation(anOpAction);
836 // WORKAROUND, should be done to avoid viewer highlight update after deletetion of objects
837 // the problem is in AIS Dimensions recompute
838 // if a line and the dim are removed, line is the first
839 // it causes the AIS recompute, where the base line is null,
840 // the result is empty AIS in the viewer
841 XGUI_Tools::workshop(myWorkshop)->selector()->clearSelection();
843 // 4. delete features
844 // sketch feature should be skipped, only sub-features can be removed
845 // when sketch operation is active
846 aWorkshop->deleteFeatures(aSketchObjects);
848 anOpMgr->commitOperation();
853 void PartSet_Module::onFeatureTriggered()
855 // is commented for imp: Unpressing the button of the current action must behave like
856 // a validation if the entity can be created (instead of Cancel, as currently)
857 /*QAction* aCmd = dynamic_cast<QAction*>(sender());
858 if (aCmd->isCheckable() && aCmd->isChecked()) {
859 // 1. check whether the delete should be processed in the module
860 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
861 bool isNestedOp = myModule->sketchMgr()->isNestedCreateOperation(anOperation);
863 // in case if in the viewer nothing is displayed, the create operation should not be
864 // comitted even if all values of the feature are initialized
865 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
866 // the action information should be saved before the operation is aborted
867 // because this abort leads to update command status, which unchecks this action
868 anOperation->abort();
869 launchOperation(aCmd->data().toString());
873 ModuleBase_IModule::onFeatureTriggered();
876 void PartSet_Module::editFeature(FeaturePtr theFeature)
878 storeConstraintsState(theFeature->getKind());
879 ModuleBase_IModule::editFeature(theFeature);
882 bool PartSet_Module::canCommitOperation() const
887 void PartSet_Module::launchOperation(const QString& theCmdId)
889 myIsOperationIsLaunched = true;
890 storeConstraintsState(theCmdId.toStdString());
891 updateConstraintsState(theCmdId.toStdString());
893 ModuleBase_IModule::launchOperation(theCmdId);
895 myIsOperationIsLaunched = false;
898 void PartSet_Module::storeConstraintsState(const std::string& theFeatureKind)
900 if (myWorkshop->currentOperation() &&
901 myWorkshop->currentOperation()->id().toStdString() == SketchPlugin_Sketch::ID()) {
902 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& aShownStates =
903 mySketchMgr->showConstraintStates();
904 myHasConstraintShown = aShownStates;
908 void PartSet_Module::updateConstraintsState(const std::string& theFeatureKind)
910 if (PartSet_SketcherMgr::constraintsIdList().contains(theFeatureKind.c_str()) ||
911 PartSet_SketcherMgr::replicationsIdList().contains(theFeatureKind.c_str())) {
912 // Show constraints if a constraint was anOperation
913 mySketchMgr->updateBySketchParameters(PartSet_Tools::Geometrical, true);
914 mySketchMgr->updateBySketchParameters(PartSet_Tools::Dimensional, true);
915 mySketchMgr->updateBySketchParameters(PartSet_Tools::Expressions,
916 myHasConstraintShown[PartSet_Tools::Expressions]);
920 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
922 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
923 if (!anAIS.IsNull()) {
924 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
925 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
926 if (!aDim.IsNull()) {
927 aCtx->SetZLayer(aDim, myVisualLayerId);
929 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
931 aCtx->SetZLayer(aCons, myVisualLayerId);
936 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
939 // it should be recomputed in order to disappear in the viewer if the corresponded object
941 //if (myCustomPrs->isActive())
942 // myCustomPrs->redisplay(theObject, false);
945 void PartSet_Module::onViewTransformed(int theTrsfType)
947 // Set length of arrows constant in pixel size
948 // if the operation is panning or rotate or panglobal then do nothing
949 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
951 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
952 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
953 if (aContext.IsNull())
956 //Handle(V3d_View) aView = aViewer->activeView();
958 XGUI_Workshop* aWorkshop = getWorkshop();
959 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
960 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
961 Handle(V3d_View) aView;
963 for (aV3dViewer->InitDefinedViews();
964 aV3dViewer->MoreDefinedViews();
965 aV3dViewer->NextDefinedViews()) {
966 Handle(V3d_View) aV = aV3dViewer->DefinedView();
967 double aS = aV->Scale();
975 double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
977 double aPrevLen = SketcherPrs_Tools::getArrowSize();
978 SketcherPrs_Tools::setArrowSize(aLen);
979 const double aPrevScale = aViewer->Scale(aViewer->activeView());
980 const double aCurScale = aViewer->activeView()->Camera()->Scale();
981 aViewer->SetScale(aViewer->activeView(), aCurScale);
982 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
983 bool isModified = false;
984 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
985 foreach (AISObjectPtr aAIS, aPrsList) {
986 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
988 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
989 if (!aDim.IsNull()) {
990 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
991 aContext->Redisplay(aDim, false);
996 aDisplayer->updateViewer();
999 bool PartSet_Module::isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const
1001 return myCustomPrs->isActive(theFlag);
1004 void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature,
1005 const ModuleBase_CustomizeFlag& theFlag,
1006 const bool theUpdateViewer)
1008 myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
1011 void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
1012 const bool theUpdateViewer)
1014 myCustomPrs->deactivate(theFlag, theUpdateViewer);
1017 bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
1018 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
1020 bool aCustomized = false;
1022 XGUI_Workshop* aWorkshop = getWorkshop();
1023 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1024 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1028 if (!theResult.get()) {
1029 std::vector<int> aColor;
1030 XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
1031 if (!aColor.empty()) {
1032 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1035 // customize dimentional constrains
1036 sketchMgr()->customizePresentation(anObject);
1041 bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
1042 AISObjectPtr thePrs,
1043 GeomCustomPrsPtr theCustomPrs)
1045 bool aCustomized = false;
1047 XGUI_Workshop* aWorkshop = getWorkshop();
1048 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1049 ObjectPtr anObject = aDisplayer->getObject(thePrs);
1053 std::vector<int> aColor;
1054 bool aUseCustomColor = true;
1055 if (aUseCustomColor)
1056 myOverconstraintListener->getCustomColor(anObject, aColor);
1057 // customize sketch symbol presentation
1058 Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
1059 if (!anAISIO.IsNull()) {
1060 if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
1061 Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
1062 if (!aPrs.IsNull()) {
1063 aPrs->SetCustomColor(aColor);
1066 } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
1067 Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
1068 if (!aPrs.IsNull()) {
1069 aPrs->SetCustomColor(aColor);
1074 // customize sketch dimension constraint presentation
1076 if (!aColor.empty()) { // otherwise presentation has the default color
1077 aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
1083 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
1084 const bool theUpdateViewer)
1086 bool isRedisplayed = false;
1087 if (myCustomPrs->isActive(theFlag))
1088 isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
1090 return isRedisplayed;
1093 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
1095 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
1097 QLabel* aLabel = aOB->activeDocLabel();
1098 aLabel->installEventFilter(myMenuMgr);
1099 connect(aLabel, SIGNAL(customContextMenuRequested(const QPoint&)),
1100 SLOT(onActiveDocPopup(const QPoint&)));
1101 aOB->treeView()->setExpandsOnDoubleClick(false);
1102 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
1103 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
1105 Events_Loop* aLoop = Events_Loop::loop();
1106 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1110 void PartSet_Module::onActiveDocPopup(const QPoint& thePnt)
1112 SessionPtr aMgr = ModelAPI_Session::get();
1113 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1115 XGUI_Workshop* aWorkshop = getWorkshop();
1116 QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
1118 aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1121 aMenu.addAction(aActivatePartAction);
1122 aMenu.exec(aHeader->mapToGlobal(thePnt));
1125 Handle(AIS_InteractiveObject) PartSet_Module::createPresentation(const ResultPtr& theResult)
1127 return mySketchMgr->createPresentation(theResult);
1131 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
1134 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1136 /// If last line finished on vertex the lines creation sequence has to be break
1137 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1139 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
1140 // if there is an active widget, find the presented object in it
1141 if (!anActiveWidget)
1142 anActiveWidget = aPanel->preselectionWidget();
1144 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
1146 if (aWidgetValidated)
1147 anObject = aWidgetValidated->findPresentedObject(theAIS);
1153 bool PartSet_Module::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
1155 bool aCanBeShaged = true;
1157 Handle(PartSet_ResultSketchPrs) aPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theAIS);
1159 aCanBeShaged = false;
1161 return aCanBeShaged;
1164 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1166 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1167 int aSelected = aObjects.size();
1168 SessionPtr aMgr = ModelAPI_Session::get();
1169 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1171 bool hasResult = false;
1172 bool hasFeature = false;
1173 bool hasParameter = false;
1174 bool hasCompositeOwner = false;
1175 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
1178 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1179 if (aSelected == 1) {
1180 ObjectPtr aObject = aObjects.first();
1182 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1183 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1184 bool isPart = aPart.get() ||
1185 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1187 DocumentPtr aPartDoc;
1189 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1191 if (aPart.get()) // this may be null is Part feature is disabled
1192 aPartDoc = aPart->partDoc();
1194 theMenu->addAction(aActivatePartAction);
1195 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1197 } else if (aObject->document() == aMgr->activeDocument()) {
1198 if (hasParameter || hasFeature) {
1199 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1200 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1201 if (aCurrentOp && aFeature.get()) {
1202 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1203 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1210 myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
1211 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1212 theMenu->addSeparator();
1215 bool aNotDeactivate = (aCurrentOp == 0);
1216 if (!aNotDeactivate) {
1217 aActivatePartAction->setEnabled(false);
1221 #define EXPAND_PARENT(OBJ) \
1222 QModelIndex aObjIndex = aDataModel->objectIndex(OBJ); \
1223 if (aObjIndex.isValid()) { \
1224 QModelIndex aParent = aObjIndex.parent(); \
1225 int aCount = aDataModel->rowCount(aParent); \
1227 aTreeView->setExpanded(aParent, true); \
1231 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1233 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1234 // Do not change activation of parts if an operation active
1235 static QStringList aAllowActivationList;
1236 if (aAllowActivationList.isEmpty())
1237 aAllowActivationList <<
1238 QString(PartSetPlugin_Part::ID().c_str()) <<
1239 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1240 QString(PartSetPlugin_Remove::ID().c_str());
1241 if (myWorkshop->currentOperation() &&
1242 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1244 XGUI_Workshop* aWorkshop = getWorkshop();
1245 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1246 QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1247 QPalette aPalet = aLabel->palette();
1249 SessionPtr aMgr = ModelAPI_Session::get();
1250 DocumentPtr aActiveDoc = aMgr->activeDocument();
1251 if (myActivePartIndex.isValid())
1252 aTreeView->setExpanded(myActivePartIndex, false);
1253 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1254 myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1255 if (myActivePartIndex.isValid())
1256 aTreeView->setExpanded(myActivePartIndex, true);
1258 aLabel->setPalette(aPalet);
1259 aWorkshop->updateCommandStatus();
1261 // Update displayed objects in order to update active color
1262 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1263 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1265 foreach(ObjectPtr aObj, aObjects) {
1266 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1267 aObj->isDisabled() || (!aObj->isDisplayed());
1269 aDisplayer->redisplay(aObj, false);
1271 aDisplayer->updateViewer();
1272 } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
1273 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
1274 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
1275 std::set<ObjectPtr> aObjects = aUpdMsg->objects();
1277 ObjectPtr aConstrObj;
1278 ObjectPtr aResultObj;
1279 std::set<ObjectPtr>::const_iterator aIt;
1280 DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
1281 for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
1282 ObjectPtr aObject = (*aIt);
1283 if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
1284 && (aObject->document() != aRootDoc))
1285 aResultObj = aObject;
1286 if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
1287 && (aObject->document() != aRootDoc))
1288 aConstrObj = aObject;
1289 if (aResultObj.get() && aConstrObj.get())
1293 if (aResultObj.get() || aConstrObj.get()) {
1294 XGUI_Workshop* aWorkshop = getWorkshop();
1295 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1296 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1298 if (aResultObj.get()) {
1299 EXPAND_PARENT(aResultObj)
1301 if (aConstrObj.get()) {
1302 EXPAND_PARENT(aConstrObj)
1308 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1310 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1312 SessionPtr aMgr = ModelAPI_Session::get();
1313 if (!theIndex.isValid()) {
1314 // It seems that this code is obsolete
1315 //aMgr->setActiveDocument(aMgr->moduleDocument());
1318 if (theIndex.column() != 0) // Use only first column
1321 XGUI_Workshop* aWorkshop = getWorkshop();
1322 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1323 // De not use non editable Indexes
1324 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1326 ObjectPtr aObj = aDataModel->object(theIndex);
1328 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1329 if (!aPart.get()) { // Probably this is Feature
1330 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1331 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1332 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1335 if (aPart.get()) { // if this is a part
1336 if (aPart->partDoc() == aMgr->activeDocument()) {
1337 myMenuMgr->activatePartSet();
1339 myMenuMgr->activatePart(aPart);
1345 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1347 // z layer is created for all started operations in order to visualize operation AIS presentation
1349 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1350 if (aContext.IsNull())
1353 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1354 if (myVisualLayerId == 0) {
1355 if (myVisualLayerId == 0)
1356 aViewer->AddZLayer(myVisualLayerId);
1358 TColStd_SequenceOfInteger aZList;
1359 aViewer->GetAllZLayers(aZList);
1360 bool aFound = false;
1361 for (int i = 1; i <= aZList.Length(); i++) {
1362 if (aZList(i) == myVisualLayerId) {
1368 aViewer->AddZLayer(myVisualLayerId);
1370 // if there is an active operation with validated widget,
1371 // the filters of this widget should be activated in the created view
1372 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1374 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1375 if (anActiveWidget) {
1376 ModuleBase_WidgetSelector* aWSelector =
1377 dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1379 aWSelector->activateSelectionAndFilters(true);
1384 //******************************************************
1385 void PartSet_Module::widgetStateChanged(int thePreviousState)
1387 mySketchMgr->widgetStateChanged(thePreviousState);
1390 bool PartSet_Module::processEnter(const std::string& thePreviousAttributeID)
1392 return mySketchReentrantMgr->processEnter(thePreviousAttributeID);
1395 //******************************************************
1396 void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation)
1398 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
1399 mySketchMgr->stopSketch(theOperation);
1403 //******************************************************
1404 GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
1406 GeomShapePtr aGeomShape;
1408 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
1409 if (anOperation && sketchMgr()->isNestedSketchOperation(anOperation)) {
1410 aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
1415 //******************************************************
1416 AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
1417 const GeomShapePtr& theGeomShape)
1419 AttributePtr anAttribute;
1420 GeomShapePtr aGeomShape = theGeomShape;
1421 if (!aGeomShape.get()) {
1422 // processing shape of result, e.g. sketch circle center is selected, this is a result
1423 // the geom shape is empty, the shape of result should be used
1424 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1425 if (aResult.get()) {
1426 aGeomShape = aResult->shape();
1430 if (aGeomShape.get()) {
1431 TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
1432 return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
1433 mySketchMgr->activeSketch());
1438 //******************************************************
1439 std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
1441 return sketchReentranceMgr()->reentrantMessage();
1444 //******************************************************
1445 void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
1447 sketchReentranceMgr()->setReentrantPreSelection(theMessage);
1450 //******************************************************
1451 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
1454 PartSet_WidgetChoice* aChoiceWidget = dynamic_cast<PartSet_WidgetChoice*>(theWidget);
1458 QString aChoiceTitle = aChoiceWidget->getPropertyPanelTitle(theIndex);
1459 if (!aChoiceTitle.isEmpty()) {
1460 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1463 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
1465 aPanel->setWindowTitle(aChoiceTitle);
1469 //******************************************************
1470 XGUI_Workshop* PartSet_Module::getWorkshop() const
1472 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
1473 return aConnector->workshop();
1476 //******************************************************
1477 void PartSet_Module::setDefaultConstraintShown()
1479 myHasConstraintShown[PartSet_Tools::Geometrical] = true;
1480 myHasConstraintShown[PartSet_Tools::Dimensional] = true;
1481 myHasConstraintShown[PartSet_Tools::Expressions] = false;