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_WidgetPoint2d.h"
8 #include "PartSet_WidgetPoint2dDistance.h"
9 #include "PartSet_WidgetPoint2DFlyout.h"
10 #include "PartSet_WidgetShapeSelector.h"
11 #include "PartSet_WidgetPoint2dAngle.h"
12 #include "PartSet_WidgetMultiSelector.h"
13 #include "PartSet_WidgetEditor.h"
14 #include "PartSet_WidgetFileSelector.h"
15 #include "PartSet_WidgetSketchCreator.h"
16 #include "PartSet_SketcherMgr.h"
17 #include "PartSet_MenuMgr.h"
18 #include "PartSet_CustomPrs.h"
19 #include "PartSet_IconFactory.h"
21 #include "PartSet_Filters.h"
22 #include "PartSet_FilterInfinite.h"
24 #include <PartSetPlugin_Remove.h>
25 #include <PartSetPlugin_Part.h>
26 #include <PartSetPlugin_Duplicate.h>
28 #include <ModuleBase_Operation.h>
29 #include <ModuleBase_OperationAction.h>
30 #include <ModuleBase_IViewer.h>
31 #include <ModuleBase_IViewWindow.h>
32 #include <ModuleBase_IPropertyPanel.h>
33 #include <ModuleBase_WidgetEditor.h>
34 #include <ModuleBase_WidgetValidated.h>
35 #include <ModuleBase_FilterFactory.h>
36 #include <ModuleBase_Tools.h>
37 #include <ModuleBase_OperationFeature.h>
39 #include <GeomValidators_ShapeType.h>
40 #include <GeomValidators_Finite.h>
41 #include <GeomValidators_Face.h>
42 #include <GeomValidators_ConstructionComposite.h>
43 #include <GeomValidators_ZeroOffset.h>
44 #include <GeomValidators_BooleanArguments.h>
45 #include <GeomValidators_Different.h>
46 #include <GeomValidators_PartitionArguments.h>
49 #include <ModelAPI_Object.h>
50 #include <ModelAPI_Events.h>
51 #include <ModelAPI_Validator.h>
52 #include <ModelAPI_Data.h>
53 #include <ModelAPI_Session.h>
54 #include <GeomValidators_DifferentShapes.h>
55 #include <ModelAPI_ResultBody.h>
56 #include <ModelAPI_AttributeString.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>
74 #include <SketchPlugin_Feature.h>
75 #include <SketchPlugin_Sketch.h>
76 #include <SketchPlugin_Line.h>
77 #include <SketchPlugin_Arc.h>
78 #include <SketchPlugin_Circle.h>
79 #include <SketchPlugin_Point.h>
80 #include <SketchPlugin_ConstraintAngle.h>
81 #include <SketchPlugin_ConstraintLength.h>
82 #include <SketchPlugin_ConstraintDistance.h>
83 #include <SketchPlugin_ConstraintParallel.h>
84 #include <SketchPlugin_ConstraintPerpendicular.h>
85 #include <SketchPlugin_ConstraintRadius.h>
87 #include <SketcherPrs_SymbolPrs.h>
88 #include <SketcherPrs_Tools.h>
90 #include <Events_Loop.h>
91 #include <Config_PropManager.h>
92 #include <Config_Keywords.h>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <TopoDS_Vertex.hxx>
97 #include <TopoDS_Shape.hxx>
98 #include <BRep_Tool.hxx>
99 #include <AIS_Dimension.hxx>
102 #include <QMouseEvent>
105 #include <QApplication>
106 #include <QMessageBox>
107 #include <QMainWindow>
110 #include <GeomAlgoAPI_FaceBuilder.h>
111 #include <GeomDataAPI_Dir.h>
113 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
119 /*!Create and return new instance of XGUI_Module*/
120 extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(ModuleBase_IWorkshop* theWshop)
122 return new PartSet_Module(theWshop);
125 PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
126 : ModuleBase_IModule(theWshop),
127 myRestartingMode(RM_None), myVisualLayerId(0), myHasConstraintShown(true),
128 myIsInternalEditOperation(false)
130 new PartSet_IconFactory();
132 mySketchMgr = new PartSet_SketcherMgr(this);
134 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
135 XGUI_Workshop* aWorkshop = aConnector->workshop();
137 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
138 connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
139 connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
140 this, SLOT(onOperationActivatedByPreselection()));
142 ModuleBase_IViewer* aViewer = theWshop->viewer();
143 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
144 this, SLOT(onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
145 connect(aViewer, SIGNAL(viewTransformed(int)),
146 SLOT(onViewTransformed(int)));
147 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
148 SLOT(onViewCreated(ModuleBase_IViewWindow*)));
150 myMenuMgr = new PartSet_MenuMgr(this);
151 myCustomPrs = new PartSet_CustomPrs(theWshop);
153 Events_Loop* aLoop = Events_Loop::loop();
154 aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
156 mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop));
157 mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop));
160 PartSet_Module::~PartSet_Module()
162 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
163 for (; aIt.More(); aIt.Next()) {
164 Handle(SelectMgr_Filter) aFilter = aIt.Value();
165 if (!aFilter.IsNull())
171 void PartSet_Module::activateSelectionFilters()
173 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
174 for (; aIt.More(); aIt.Next()) {
175 Handle(SelectMgr_Filter) aFilter = aIt.Value();
176 if (!aFilter.IsNull())
177 myWorkshop->viewer()->addSelectionFilter(aFilter);
181 void PartSet_Module::deactivateSelectionFilters()
183 SelectMgr_ListIteratorOfListOfFilter aIt(mySelectionFilters);
184 for (; aIt.More(); aIt.Next()) {
185 Handle(SelectMgr_Filter) aFilter = aIt.Value();
186 if (!aFilter.IsNull())
187 myWorkshop->viewer()->removeSelectionFilter(aFilter);
191 void PartSet_Module::registerValidators()
193 //Registering of validators
194 SessionPtr aMgr = ModelAPI_Session::get();
195 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
196 aFactory->registerValidator("PartSet_DistanceSelection", new PartSet_DistanceSelection);
197 aFactory->registerValidator("PartSet_LengthSelection", new PartSet_LengthSelection);
198 aFactory->registerValidator("PartSet_PerpendicularSelection", new PartSet_PerpendicularSelection);
199 aFactory->registerValidator("PartSet_ParallelSelection", new PartSet_ParallelSelection);
200 aFactory->registerValidator("PartSet_RadiusSelection", new PartSet_RadiusSelection);
201 aFactory->registerValidator("PartSet_RigidSelection", new PartSet_RigidSelection);
202 aFactory->registerValidator("PartSet_CoincidentSelection", new PartSet_CoincidentSelection);
203 aFactory->registerValidator("PartSet_HVDirSelection", new PartSet_HVDirSelection);
204 aFactory->registerValidator("PartSet_TangentSelection", new PartSet_TangentSelection);
205 aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
206 aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
207 aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
208 aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
209 aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
211 aFactory->registerValidator("GeomValidators_DifferentShapes", new GeomValidators_DifferentShapes);
212 aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
213 aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
214 aFactory->registerValidator("GeomValidators_Finite", new GeomValidators_Finite);
216 aFactory->registerValidator("GeomValidators_ConstructionComposite",
217 new GeomValidators_ConstructionComposite);
219 aFactory->registerValidator("GeomValidators_ZeroOffset",
220 new GeomValidators_ZeroOffset);
222 aFactory->registerValidator("GeomValidators_BooleanArguments",
223 new GeomValidators_BooleanArguments);
225 aFactory->registerValidator("PartSet_SketchEntityValidator",
226 new PartSet_SketchEntityValidator);
228 aFactory->registerValidator("GeomValidators_Different",
229 new GeomValidators_Different);
231 aFactory->registerValidator("GeomValidators_PartitionArguments",
232 new GeomValidators_PartitionArguments);
235 void PartSet_Module::registerFilters()
237 //Registering of selection filters
238 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
239 ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
242 void PartSet_Module::registerProperties()
244 Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
246 Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
247 Config_Prop::Integer, SKETCH_WIDTH);
250 void PartSet_Module::onOperationCommitted(ModuleBase_Operation* theOperation)
252 if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
253 mySketchMgr->commitNestedSketch(theOperation);
256 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
259 // the selection is cleared after commit the create operation
260 // in order to do not use the same selected objects in the restarted operation
261 // for common behaviour, the selection is cleared even if the operation is not restarted
262 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
263 XGUI_Workshop* aWorkshop = aConnector->workshop();
264 aWorkshop->selector()->clearSelection();
266 /// Restart sketcher operations automatically
267 FeaturePtr aFeature = aFOperation->feature();
268 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
269 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
270 if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
271 myRestartingMode == RM_EmptyFeatureUsed)) {
272 myLastOperationId = aFOperation->id();
273 myLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature() : FeaturePtr();
274 if (!sketchMgr()->sketchSolverError()) {
275 if (!aFOperation->isEditOperation()) {
276 FeaturePtr anOperationFeature = aFOperation->feature();
277 if (anOperationFeature.get() != NULL) {
278 editFeature(anOperationFeature);
279 myIsInternalEditOperation = true;
280 onInternalActivateFirstWidgetSelection();
282 // activate the last active widget in the Property Panel
283 if (!myPreviousAttributeID.empty()) {
284 ModuleBase_Operation* anEditOperation = currentOperation();
285 if (anEditOperation) {
286 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
287 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
288 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
289 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
290 if (aWidgets[i]->attributeID() == myPreviousAttributeID)
291 aPreviousAttributeWidget = aWidgets[i];
293 // If the current widget is a selector, do nothing, it processes the mouse press
294 if (aPreviousAttributeWidget && !aPreviousAttributeWidget->isViewerSelector())
295 aPreviousAttributeWidget->focusTo();
301 // the flag should be reset before start to do not react to the widget deactivate
302 myIsInternalEditOperation = false;
303 launchOperation(myLastOperationId);
304 breakOperationSequence();
310 void PartSet_Module::breakOperationSequence()
312 myLastOperationId = "";
313 myLastFeature = FeaturePtr();
314 myRestartingMode = RM_None;
317 void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation)
319 myIsInternalEditOperation = false;
320 breakOperationSequence();
323 void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
325 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
326 mySketchMgr->startSketch(theOperation);
328 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
329 mySketchMgr->startNestedSketch(theOperation);
332 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
334 myCustomPrs->activate(aFOperation->feature(), true);
337 void PartSet_Module::onOperationResumed(ModuleBase_Operation* theOperation)
339 ModuleBase_IModule::onOperationResumed(theOperation);
341 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
343 myCustomPrs->activate(aFOperation->feature(), true);
346 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
348 bool isModified = myCustomPrs->deactivate(false);
350 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
351 mySketchMgr->stopSketch(theOperation);
353 else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
354 mySketchMgr->stopNestedSketch(theOperation);
357 //VSV: Viewer is updated on feature update and redisplay
359 // XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
360 // XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
361 // aDisplayer->updateViewer();
363 mySketchMgr->onShowConstraintsToggle(myHasConstraintShown);
366 ModuleBase_Operation* PartSet_Module::currentOperation() const
368 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
369 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
370 return anOpMgr->currentOperation();
373 bool PartSet_Module::canUndo() const
375 bool aCanUndo = false;
376 SessionPtr aMgr = ModelAPI_Session::get();
377 if (aMgr->hasModuleDocument() && aMgr->canUndo()) {
378 aCanUndo = !aMgr->isOperation();
379 if (!aCanUndo) // check the enable state additionally by sketch manager
380 aCanUndo = aMgr->canUndo();
385 bool PartSet_Module::canRedo() const
387 bool aCanRedo = false;
388 SessionPtr aMgr = ModelAPI_Session::get();
389 if (aMgr->hasModuleDocument() && aMgr->canRedo()) {
390 aCanRedo = !aMgr->isOperation();
391 if (!aCanRedo) // check the enable state additionally by sketch manager
392 aCanRedo = aMgr->canRedo();
397 bool PartSet_Module::canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const
400 if (theActionId == "DELETE_CMD" || theActionId == "MOVE_CMD") {
401 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
403 // part features are removed in the PartSet module only.
404 if (aFeature->getKind() == PartSetPlugin_Part::ID())
411 bool PartSet_Module::canCommitOperation() const
413 return mySketchMgr->canCommitOperation();
416 bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const
418 // the sketch manager put the restriction to the objects erase
419 return mySketchMgr->canEraseObject(theObject);
422 bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
424 // the sketch manager put the restriction to the objects display
425 return mySketchMgr->canDisplayObject(theObject);
428 bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
430 bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
432 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
433 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
434 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
435 if (isSketchOp || isNestedOp) {
436 // in active sketch operation it is possible to activate operation object in selection
437 // in the edit operation, e.g. points of the line can be moved when the line is edited
438 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
439 aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
444 bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const
446 return myMenuMgr->addViewerMenu(theMenu, theStdActions);
449 void PartSet_Module::updateViewerMenu(const QMap<QString, QAction*>& theStdActions)
451 myMenuMgr->updateViewerMenu(theStdActions);
454 QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
456 QString anError = ModuleBase_IModule::getFeatureError(theFeature);
458 if (anError.isEmpty())
459 anError = sketchMgr()->getFeatureError(theFeature);
461 if (anError.isEmpty()) {
462 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
463 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
465 if (anOpMgr->isValidationLocked()) {
466 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
467 (anOpMgr->currentOperation());
468 if (!aFOperation || theFeature == aFOperation->feature())
469 anError = "Validation is locked by the current operation";
475 void PartSet_Module::grantedOperationIds(ModuleBase_Operation* theOperation,
476 QStringList& theIds) const
478 myMenuMgr->grantedOperationIds(theOperation, theIds);
480 if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
481 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
482 XGUI_Workshop* aWorkshop = aConnector->workshop();
484 theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
488 void PartSet_Module::activeSelectionModes(QIntList& theModes)
491 if (mySketchMgr->activeSketch().get())
492 PartSet_SketcherMgr::sketchSelectionModes(theModes);
495 bool PartSet_Module::isMouseOverWindow()
497 return mySketchMgr->isMouseOverWindow();
500 void PartSet_Module::closeDocument()
505 void PartSet_Module::clearViewer()
507 myCustomPrs->clearPrs();
509 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
510 XGUI_Workshop* aWorkshop = aConnector->workshop();
511 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
512 aDisplayer->deactivateSelectionFilters();
515 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
517 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
521 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
522 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation())) {
523 // we have to manually activate the sketch label in edit mode
524 aPanel->activateWidget(aPanel->modelWidgets().first());
528 // Restart last operation type
529 if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
530 ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
531 if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
532 // Initialise new line with first point equal to end of previous
533 PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
535 std::shared_ptr<ModelAPI_Data> aData = myLastFeature->data();
536 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
537 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
539 aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
540 PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(),
541 aWgt->attributeID(), aPoint->x(), aPoint->y());
542 aPanel->activateNextWidget(aPnt2dWgt);
550 void PartSet_Module::onSelectionChanged()
552 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
556 bool isSketcherOp = false;
557 // An edit operation is enable only if the current opeation is the sketch operation
558 if (mySketchMgr->activeSketch()) {
559 if (PartSet_Tools::sketchPlane(mySketchMgr->activeSketch()))
560 isSketcherOp = PartSet_SketcherMgr::isSketchOperation(aOperation);
563 // Editing of constraints can be done on selection
564 ModuleBase_ISelection* aSelect = myWorkshop->selection();
565 QList<ModuleBase_ViewerPrs> aSelected = aSelect->getSelected();
566 if (aSelected.size() == 1) {
567 ModuleBase_ViewerPrs aPrs = aSelected.first();
568 ObjectPtr aObject = aPrs.object();
569 FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
571 std::string aId = aFeature->getKind();
572 if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
573 (aId == SketchPlugin_ConstraintLength::ID()) ||
574 (aId == SketchPlugin_ConstraintDistance::ID()) ||
575 (aId == SketchPlugin_ConstraintAngle::ID())) {
576 editFeature(aFeature);
583 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
585 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
586 XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
587 anOpMgr->onKeyReleased(theEvent);
590 void PartSet_Module::onEnterReleased()
592 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
593 (currentOperation());
594 if (/*!aFOperation->isEditOperation() || */myIsInternalEditOperation)
595 myRestartingMode = RM_EmptyFeatureUsed;
598 void PartSet_Module::onOperationActivatedByPreselection()
600 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
601 if(anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
602 // Set final definitions if they are necessary
603 //propertyPanelDefined(aOperation);
605 /// Commit sketcher operations automatically
606 anOperation->commit();
610 void PartSet_Module::onNoMoreWidgets(const std::string& thePreviousAttributeID)
612 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
614 if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
615 if (myRestartingMode != RM_Forbided) {
616 myRestartingMode = RM_LastFeatureUsed;
617 myPreviousAttributeID = thePreviousAttributeID;
619 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
620 XGUI_Workshop* aWorkshop = aConnector->workshop();
621 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
622 // do nothing if the feature can not be applyed
623 if (anOpMgr->isApplyEnabled())
624 anOperation->commit();
629 void PartSet_Module::onInternalActivateFirstWidgetSelection()
631 if (!myIsInternalEditOperation)
634 ModuleBase_ModelWidget* aFirstWidget = activeWidget();
635 ModuleBase_IPropertyPanel* aPanel = currentOperation()->propertyPanel();
636 if (aFirstWidget != aPanel->activeWidget()) {
637 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aFirstWidget);
639 aWSelector->activateSelectionAndFilters(true);
643 void PartSet_Module::onVertexSelected()
645 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
646 if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
647 /// If last line finished on vertex the lines creation sequence has to be break
648 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
649 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
650 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
651 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
652 bool aFoundWidget = false;
653 bool aFoundObligatory = false;
654 for (; anIt != aLast && !aFoundObligatory; anIt++) {
656 aFoundWidget = *anIt == anActiveWidget;
658 aFoundObligatory = (*anIt)->isObligatory();
660 if (!aFoundObligatory)
661 myRestartingMode = RM_Forbided;
665 ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
666 Config_WidgetAPI* theWidgetApi, std::string theParentId)
668 ModuleBase_IWorkshop* aWorkshop = workshop();
669 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
670 XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
671 ModuleBase_ModelWidget* aWgt = NULL;
672 if (theType == "sketch-start-label") {
673 PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
674 theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
675 connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
676 mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
677 connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
678 mySketchMgr, SLOT(onShowConstraintsToggle(bool)));
680 } else if (theType == "sketch-2dpoint_selector") {
681 PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
682 theWidgetApi, theParentId);
683 aPointWgt->setSketch(mySketchMgr->activeSketch());
684 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
686 } else if (theType == "sketch-2dpoint_flyout_selector") {
687 PartSet_WidgetPoint2DFlyout* aPointWgt = new PartSet_WidgetPoint2DFlyout(theParent, aWorkshop,
688 theWidgetApi, theParentId);
689 aPointWgt->setSketch(mySketchMgr->activeSketch());
690 connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
692 } else if (theType == "point2ddistance") {
693 PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
694 aWorkshop, theWidgetApi, theParentId);
695 aDistanceWgt->setSketch(mySketchMgr->activeSketch());
697 } else if(theType == "point2dangle") {
698 PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent,
699 aWorkshop, theWidgetApi, theParentId);
700 anAngleWgt->setSketch(mySketchMgr->activeSketch());
702 } else if (theType == "sketch_shape_selector") {
703 PartSet_WidgetShapeSelector* aShapeSelectorWgt =
704 new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId);
705 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
706 aWgt = aShapeSelectorWgt;
707 } else if (theType == "sketch_multi_selector") {
708 PartSet_WidgetMultiSelector* aShapeSelectorWgt =
709 new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId);
710 aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
711 aWgt = aShapeSelectorWgt;
712 } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
713 aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId);
714 } else if (theType == "export_file_selector") {
715 aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId);
716 } else if (theType == "sketch_launcher") {
717 aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId);
722 ModuleBase_ModelWidget* PartSet_Module::activeWidget() const
724 ModuleBase_ModelWidget* anActiveWidget = 0;
725 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
727 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
728 anActiveWidget = aPanel->activeWidget();
729 if (myIsInternalEditOperation && (!anActiveWidget || !anActiveWidget->isViewerSelector())) {
730 // finds the first widget which can accept a value
731 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
732 ModuleBase_ModelWidget* aFirstWidget = 0;
733 ModuleBase_ModelWidget* aWgt;
734 QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
735 for (aWIt = aWidgets.begin(); aWIt != aWidgets.end() && !aFirstWidget; ++aWIt) {
737 if (aWgt->canSetValue())
741 anActiveWidget = aFirstWidget;
745 return anActiveWidget;
748 bool PartSet_Module::deleteObjects()
750 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
751 XGUI_Workshop* aWorkshop = aConnector->workshop();
752 XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
754 //SessionPtr aMgr = ModelAPI_Session::get();
755 // 1. check whether the delete should be processed in the module
756 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
757 bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
758 isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
759 if (isSketchOp || isNestedOp) {
760 // 2. find selected presentations
761 // selected objects should be collected before the current operation abort because
762 // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
763 ModuleBase_ISelection* aSel = workshop()->selection();
764 QObjectPtrList aSelectedObj = aSel->selectedPresentations();
765 // if there are no selected objects in the viewer, that means that the selection in another
766 // place cased this method. It is necessary to return the false value to understande in above
767 // method that delete is not processed
768 if (aSelectedObj.count() == 0)
771 // avoid delete of the objects, which are not belong to the current sketch
772 // in order to do not delete results of other sketches
773 QObjectPtrList aSketchObjects;
774 QObjectPtrList::const_iterator anIt = aSelectedObj.begin(), aLast = aSelectedObj.end();
775 for ( ; anIt != aLast; anIt++) {
776 ObjectPtr anObject = *anIt;
777 if (mySketchMgr->isObjectOfSketch(anObject)) {
778 // sketch feature should be used in this list because workshop deletes features only
779 // results are skipped
780 FeaturePtr aSketchFeature = ModelAPI_Feature::feature(anObject);
781 aSketchObjects.append(aSketchFeature);
784 // if the selection contains only local selected presentations from other sketches,
785 // the Delete operation should not be done at all
786 if (aSketchObjects.size() == 0)
789 // 3. start operation
790 QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
791 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, this);
793 // the active nested sketch operation should be aborted unconditionally
794 // the Delete action should be additionally granted for the Sketch operation
795 // in order to do not abort/commit it
796 if (!anOpMgr->canStartOperation(anOpAction->id()))
797 return true; // the objects are processed but can not be deleted
799 anOpMgr->startOperation(anOpAction);
801 // 4. delete features
802 // sketch feature should be skipped, only sub-features can be removed
803 // when sketch operation is active
804 aWorkshop->deleteFeatures(aSketchObjects);
806 anOpMgr->commitOperation();
809 bool isPartRemoved = false;
810 // Delete part with help of PartSet plugin
811 // TODO: the deleted objects has to be processed by multiselection
812 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
813 if (aObjects.size() == 1) {
814 ObjectPtr aObj = aObjects.first();
815 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
816 if (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID())) {
817 // Remove feature should be created in the document of the part results
818 ResultPtr aPartResult = aFeature->firstResult();
819 if (aPartResult.get()) {
820 std::shared_ptr<ModelAPI_ResultPart> aPart =
821 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartResult);
822 DocumentPtr aPartDoc = aPart->partDoc();
823 if (aPartDoc.get()) {
824 ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction
825 (PartSetPlugin_Remove::ID().c_str(), this);
826 if (!anOpMgr->canStartOperation(anOpAction->id()))
827 return true; // the objects are processed but can not be deleted
829 anOpMgr->startOperation(anOpAction);
831 FeaturePtr aFeature = aPartDoc->addFeature(PartSetPlugin_Remove::ID());
834 anOpMgr->commitOperation();
835 isPartRemoved = true;
840 return isPartRemoved;
845 void PartSet_Module::onFeatureTriggered()
847 QAction* aCmd = dynamic_cast<QAction*>(sender());
848 if (aCmd->isCheckable() && aCmd->isChecked()) {
849 // 1. check whether the delete should be processed in the module
850 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
851 bool isNestedOp = PartSet_SketcherMgr::isNestedCreateOperation(anOperation);
853 // in case if in the viewer nothing is displayed, the create operation should not be
854 // comitted even if all values of the feature are initialized
855 if (!mySketchMgr->canDisplayCurrentCreatedFeature()) {
856 // the action information should be saved before the operation is aborted
857 // because this abort leads to update command status, which unchecks this action
858 anOperation->abort();
859 launchOperation(aCmd->data().toString());
863 ModuleBase_IModule::onFeatureTriggered();
866 void PartSet_Module::launchOperation(const QString& theCmdId)
868 if (PartSet_SketcherMgr::constraintsIdList().contains(theCmdId)) {
869 // Show constraints if a constraint was anOperation
870 myHasConstraintShown = mySketchMgr->isConstraintsShown();
871 mySketchMgr->onShowConstraintsToggle(true);
873 ModuleBase_IModule::launchOperation(theCmdId);
877 void PartSet_Module::onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS)
879 Handle(AIS_InteractiveObject) anAIS = theAIS->impl<Handle(AIS_InteractiveObject)>();
880 if (!anAIS.IsNull()) {
881 Handle(AIS_InteractiveContext) aCtx = anAIS->GetContext();
882 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAIS);
883 if (!aDim.IsNull()) {
884 aCtx->SetZLayer(aDim, myVisualLayerId);
886 Handle(SketcherPrs_SymbolPrs) aCons = Handle(SketcherPrs_SymbolPrs)::DownCast(anAIS);
888 aCtx->SetZLayer(aCons, myVisualLayerId);
893 void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
896 // it should be recomputed in order to disappear in the viewer if the corresponded object
898 //if (myCustomPrs->isActive())
899 // myCustomPrs->redisplay(theObject, false);
902 void PartSet_Module::onViewTransformed(int theTrsfType)
904 // Set length of arrows constant in pixel size
905 // if the operation is panning or rotate or panglobal then do nothing
906 if ((theTrsfType == 1) || (theTrsfType == 3) || (theTrsfType == 4))
908 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
909 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
910 if (aContext.IsNull())
913 //Handle(V3d_View) aView = aViewer->activeView();
915 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
916 XGUI_Workshop* aWorkshop = aConnector->workshop();
917 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
918 Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
919 Handle(V3d_View) aView;
921 for (aV3dViewer->InitDefinedViews();
922 aV3dViewer->MoreDefinedViews();
923 aV3dViewer->NextDefinedViews()) {
924 Handle(V3d_View) aV = aV3dViewer->DefinedView();
925 double aS = aV->Scale();
933 double aLen = aView->Convert(20);
935 double aPrevLen = SketcherPrs_Tools::getArrowSize();
936 SketcherPrs_Tools::setArrowSize(aLen);
937 const double aPrevScale = aViewer->Scale(aViewer->activeView());
938 const double aCurScale = aViewer->activeView()->Camera()->Scale();
939 aViewer->SetScale(aViewer->activeView(), aCurScale);
940 SketcherPrs_Tools::setTextHeight (aCurScale / aPrevScale * SketcherPrs_Tools::getTextHeight());
941 bool isModified = false;
942 QList<AISObjectPtr> aPrsList = aDisplayer->displayedPresentations();
943 foreach (AISObjectPtr aAIS, aPrsList) {
944 Handle(AIS_InteractiveObject) aAisObj = aAIS->impl<Handle(AIS_InteractiveObject)>();
946 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(aAisObj);
947 if (!aDim.IsNull()) {
948 aDim->DimensionAspect()->ArrowAspect()->SetLength(aLen);
949 aContext->Redisplay(aDim, false);
954 aDisplayer->updateViewer();
957 bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
959 bool isRedisplayed = false;
960 if (myCustomPrs->isActive())
961 isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
963 return isRedisplayed;
966 void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
968 XGUI_ObjectsBrowser* aOB = dynamic_cast<XGUI_ObjectsBrowser*>(theObjectBrowser);
970 //QLineEdit* aLabel = aOB->activeDocLabel();
971 //QPalette aPalet = aLabel->palette();
972 //aPalet.setColor(QPalette::Text, QColor(0, 72, 140));
973 //aLabel->setPalette(aPalet);
974 aOB->treeView()->setExpandsOnDoubleClick(false);
975 connect(aOB->treeView(), SIGNAL(doubleClicked(const QModelIndex&)),
976 SLOT(onTreeViewDoubleClick(const QModelIndex&)));
980 ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
983 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
985 /// If last line finished on vertex the lines creation sequence has to be break
986 ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
987 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
988 // if there is an active widget, find the presented object in it
990 anActiveWidget = aPanel->preselectionWidget();
992 ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
994 if (aWidgetValidated)
995 anObject = aWidgetValidated->findPresentedObject(theAIS);
1000 void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
1002 QObjectPtrList aObjects = myWorkshop->selection()->selectedObjects();
1003 int aSelected = aObjects.size();
1004 SessionPtr aMgr = ModelAPI_Session::get();
1005 QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
1006 QAction* aActivatePartSetAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
1008 ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
1009 if (aSelected == 1) {
1010 bool hasResult = false;
1011 bool hasFeature = false;
1012 bool hasParameter = false;
1013 bool hasSubFeature = false;
1014 ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, hasSubFeature);
1016 ObjectPtr aObject = aObjects.first();
1018 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1019 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
1020 bool isPart = aPart.get() ||
1021 (aFeature.get() && (aFeature->getKind() == PartSetPlugin_Part::ID()));
1023 DocumentPtr aPartDoc;
1025 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
1027 if (aPart.get()) // this may be null is Part feature is disabled
1028 aPartDoc = aPart->partDoc();
1030 theMenu->addAction(aActivatePartAction);
1031 aActivatePartAction->setEnabled((aMgr->activeDocument() != aPartDoc));
1033 } else if (aObject->document() == aMgr->activeDocument()) {
1034 if (hasParameter || hasFeature) {
1035 myMenuMgr->action("EDIT_CMD")->setEnabled(true);
1036 theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
1037 if (aCurrentOp && aFeature.get()) {
1038 if (aCurrentOp->id().toStdString() == aFeature->getKind())
1039 myMenuMgr->action("EDIT_CMD")->setEnabled(false);
1044 ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1046 theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
1047 } else { // If feature is 0 the it means that selected root object (document)
1048 theMenu->addAction(aActivatePartSetAction);
1049 aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1051 } else if (aSelected == 0) {
1052 // if there is no selection then it means that upper label is selected
1053 QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
1054 if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
1055 theMenu->addAction(aActivatePartSetAction);
1056 aActivatePartSetAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
1058 bool aNotDeactivate = (aCurrentOp == 0);
1059 if (!aNotDeactivate) {
1060 aActivatePartAction->setEnabled(false);
1061 aActivatePartSetAction->setEnabled(false);
1065 void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMessage)
1067 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
1068 // Do not change activation of parts if an operation active
1069 static QStringList aAllowActivationList;
1070 if (aAllowActivationList.isEmpty())
1071 aAllowActivationList <<
1072 QString(PartSetPlugin_Part::ID().c_str()) <<
1073 QString(PartSetPlugin_Duplicate::ID().c_str()) <<
1074 QString(PartSetPlugin_Remove::ID().c_str());
1075 if (myWorkshop->currentOperation() &&
1076 (!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
1078 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1079 XGUI_Workshop* aWorkshop = aConnector->workshop();
1080 XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
1081 QLineEdit* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
1082 QPalette aPalet = aLabel->palette();
1084 SessionPtr aMgr = ModelAPI_Session::get();
1085 DocumentPtr aActiveDoc = aMgr->activeDocument();
1086 if (aActivePartIndex.isValid())
1087 aTreeView->setExpanded(aActivePartIndex, false);
1088 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1089 aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
1090 if (aActivePartIndex.isValid())
1091 aTreeView->setExpanded(aActivePartIndex, true);
1093 aLabel->setPalette(aPalet);
1094 aWorkshop->updateCommandStatus();
1096 // Update displayed objects in order to update active color
1097 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1098 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1100 foreach(ObjectPtr aObj, aObjects) {
1101 //TODO: replace by redisplay event.
1102 aHidden = !aObj->data() || !aObj->data()->isValid() ||
1103 aObj->isDisabled() || (!aObj->isDisplayed());
1105 aDisplayer->redisplay(aObj, false);
1107 aDisplayer->updateViewer();
1111 void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
1113 if (myWorkshop->currentOperation()) // Do not change activation of parts if an operation active
1115 SessionPtr aMgr = ModelAPI_Session::get();
1116 if (!theIndex.isValid()) {
1117 aMgr->setActiveDocument(aMgr->moduleDocument());
1120 if (theIndex.column() != 0) // Use only first column
1123 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
1124 XGUI_Workshop* aWorkshop = aConnector->workshop();
1125 XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
1126 // De not use non editable Indexes
1127 if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
1129 ObjectPtr aObj = aDataModel->object(theIndex);
1131 ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1132 if (!aPart.get()) { // Probably this is Feature
1133 FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1134 if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
1135 aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
1138 if (aPart.get()) { // if this is a part
1139 if (aPart->partDoc() == aMgr->activeDocument()) {
1140 myMenuMgr->activatePartSet();
1148 void PartSet_Module::onViewCreated(ModuleBase_IViewWindow*)
1150 // z layer is created for all started operations in order to visualize operation AIS presentation
1152 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
1153 if (aContext.IsNull())
1156 Handle(V3d_Viewer) aViewer = aContext->CurrentViewer();
1157 if (myVisualLayerId == 0) {
1158 if (myVisualLayerId == 0)
1159 aViewer->AddZLayer(myVisualLayerId);
1161 TColStd_SequenceOfInteger aZList;
1162 aViewer->GetAllZLayers(aZList);
1163 bool aFound = false;
1164 for (int i = 1; i <= aZList.Length(); i++) {
1165 if (aZList(i) == myVisualLayerId) {
1171 aViewer->AddZLayer(myVisualLayerId);
1173 // if there is an active operation with validated widget,
1174 // the filters of this widget should be activated in the created view
1175 ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
1177 ModuleBase_ModelWidget* anActiveWidget = activeWidget();
1178 if (anActiveWidget) {
1179 ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>(anActiveWidget);
1181 aWSelector->activateSelectionAndFilters(true);