]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSelector.cpp
Salome HOME
Focus regression in shape selector. Distance - select 1st object, focus is still...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetSelector.h
4 // Created:     19 June 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <ModuleBase_WidgetSelector.h>
8
9 #include <ModuleBase_ISelection.h>
10 #include <ModuleBase_IWorkshop.h>
11
12 ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
13                                                      ModuleBase_IWorkshop* theWorkshop,
14                                                      const Config_WidgetAPI* theData,
15                                                      const std::string& theParentId)
16  : ModuleBase_WidgetValidated(theParent, theData, theParentId),
17    myWorkshop(theWorkshop)
18 {
19 }
20
21 //********************************************************************
22 ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
23 {
24 }
25
26 //TODO: nds stabilization hotfix
27 void ModuleBase_WidgetSelector::disconnectSignals()
28 {
29   disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
30 }
31
32 //********************************************************************
33 void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
34                                                       ObjectPtr& theObject,
35                                                       GeomShapePtr& theShape)
36 {
37   ModuleBase_ISelection* aSelection = myWorkshop->selection();
38   theObject = aSelection->getResult(thePrs);
39   theShape = aSelection->getShape(thePrs);
40 }
41
42 //********************************************************************
43 void ModuleBase_WidgetSelector::onSelectionChanged()
44 {
45   clearAttribute();
46
47   QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
48                                                               ModuleBase_ISelection::AllControls);
49   bool isDone = setSelection(aSelected);
50
51   emit valuesChanged();
52   // the updateObject method should be called to flush the updated sigal. The workshop listens it,
53   // calls validators for the feature and, as a result, updates the Apply button state.
54   updateObject(myFeature);
55
56   if (isDone)
57     updateFocus();
58 }
59
60 //********************************************************************
61 bool ModuleBase_WidgetSelector::acceptSubShape(const TopoDS_Shape& theShape) const
62 {
63   bool aValid = true;
64   if (theShape.IsNull()) {
65     aValid = true; // do not check the shape type if the shape is empty
66     // extrusion uses a sketch object selectected in Object browser
67   }
68   else {
69     aValid = false;
70     TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
71     QIntList aShapeTypes = getShapeTypes();
72
73     QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
74     for (; anIt != aLast; anIt++) {
75       if (aShapeType == *anIt)
76         aValid = true;
77     }
78   }
79   return aValid;
80 }
81
82 //********************************************************************
83 void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
84 {
85   updateSelectionName();
86
87   if (toActivate) {
88     myWorkshop->activateSubShapesSelection(getShapeTypes());
89   } else {
90     myWorkshop->deactivateSubShapesSelection();
91   }
92 }
93
94 //********************************************************************
95 void ModuleBase_WidgetSelector::activateCustom()
96 {
97   connect(myWorkshop, SIGNAL(selectionChanged()), this,
98           SLOT(onSelectionChanged()), Qt::UniqueConnection);
99   
100   activateSelection(true);
101
102   // Restore selection in the viewer by the attribute selection list
103   myWorkshop->setSelected(getAttributeSelection());
104
105   activateFilters(myWorkshop, true);
106 }
107
108 //********************************************************************
109 bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
110 {
111   GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
112   bool aValid = true;
113   if (!aShape.get()) {
114     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
115     if (aResult.get())
116       aShape = aResult->shape();
117   }
118   if (aShape.get()) {
119     // Check that the selection corresponds to selection type
120     TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
121     aValid = acceptSubShape(aTopoShape);
122   }
123   if (aValid) {
124     // In order to avoid selection of the same object
125     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
126     FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
127     aValid = aSelectedFeature != myFeature;
128   }
129   return aValid;
130 }
131
132 //********************************************************************
133 bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
134 {
135   ObjectPtr anObject;
136   GeomShapePtr aShape;
137   getGeomSelection(thePrs, anObject, aShape);
138
139   setObject(anObject, aShape);
140   return true;
141 }
142
143 //********************************************************************
144 void ModuleBase_WidgetSelector::deactivate()
145 {
146   disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
147   activateSelection(false);
148   activateFilters(myWorkshop, false);
149 }