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 bool isDone = 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);
60 //********************************************************************
61 bool ModuleBase_WidgetSelector::acceptSubShape(const TopoDS_Shape& theShape) const
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
70 TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
71 QIntList aShapeTypes = getShapeTypes();
73 QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
74 for (; anIt != aLast; anIt++) {
75 if (aShapeType == *anIt)
82 //********************************************************************
83 void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
85 updateSelectionName();
88 myWorkshop->activateSubShapesSelection(getShapeTypes());
90 myWorkshop->deactivateSubShapesSelection();
94 //********************************************************************
95 void ModuleBase_WidgetSelector::activateCustom()
97 connect(myWorkshop, SIGNAL(selectionChanged()), this,
98 SLOT(onSelectionChanged()), Qt::UniqueConnection);
100 activateSelection(true);
102 // Restore selection in the viewer by the attribute selection list
103 myWorkshop->setSelected(getAttributeSelection());
105 activateFilters(myWorkshop, true);
108 //********************************************************************
109 bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
111 GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
114 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
116 aShape = aResult->shape();
119 // Check that the selection corresponds to selection type
120 TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
121 aValid = acceptSubShape(aTopoShape);
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;
132 //********************************************************************
133 bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
137 getGeomSelection(thePrs, anObject, aShape);
139 setObject(anObject, aShape);
143 //********************************************************************
144 void ModuleBase_WidgetSelector::deactivate()
146 disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
147 activateSelection(false);
148 activateFilters(myWorkshop, false);