1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetSelector.h
4 // Created: 19 June 2015
5 // Author: Natalia ERMOLAEVA
7 #include <ModuleBase_WidgetSelector.h>
9 #include <ModuleBase_ISelection.h>
10 #include <ModuleBase_IWorkshop.h>
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)
21 //********************************************************************
22 ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
26 //TODO: nds stabilization hotfix
27 void ModuleBase_WidgetSelector::disconnectSignals()
29 disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
32 //********************************************************************
33 void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
35 GeomShapePtr& theShape)
37 ModuleBase_ISelection* aSelection = myWorkshop->selection();
38 theObject = aSelection->getResult(thePrs);
39 theShape = aSelection->getShape(thePrs);
42 //********************************************************************
43 void ModuleBase_WidgetSelector::onSelectionChanged()
47 QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
48 ModuleBase_ISelection::AllControls);
49 setSelection(aSelected);
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);
59 //********************************************************************
60 bool ModuleBase_WidgetSelector::acceptSubShape(const TopoDS_Shape& theShape) const
63 if (theShape.IsNull()) {
64 aValid = true; // do not check the shape type if the shape is empty
65 // extrusion uses a sketch object selectected in Object browser
69 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
70 QIntList aShapeTypes = getShapeTypes();
72 QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
73 for (; anIt != aLast; anIt++) {
74 if (aShapeType == *anIt)
81 //********************************************************************
82 void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
84 updateSelectionName();
87 myWorkshop->activateSubShapesSelection(getShapeTypes());
89 myWorkshop->deactivateSubShapesSelection();
93 //********************************************************************
94 void ModuleBase_WidgetSelector::activateCustom()
96 connect(myWorkshop, SIGNAL(selectionChanged()), this,
97 SLOT(onSelectionChanged()), Qt::UniqueConnection);
99 activateSelection(true);
101 // Restore selection in the viewer by the attribute selection list
102 myWorkshop->setSelected(getAttributeSelection());
104 activateFilters(myWorkshop, true);
107 //********************************************************************
108 bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
110 GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
112 // if there is no selected shape, the method returns true
116 // Check that the selection corresponds to selection type
117 TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
118 aValid = acceptSubShape(aTopoShape);
121 // In order to avoid selection of the same object
122 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
123 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
124 aValid = aSelectedFeature != myFeature;
129 //********************************************************************
130 bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
134 getGeomSelection(thePrs, anObject, aShape);
136 setObject(anObject, aShape);
140 //********************************************************************
141 void ModuleBase_WidgetSelector::deactivate()
143 disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
144 activateSelection(false);
145 activateFilters(myWorkshop, false);