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 #include <ModelAPI_ResultConstruction.h>
14 ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
15 ModuleBase_IWorkshop* theWorkshop,
16 const Config_WidgetAPI* theData,
17 const std::string& theParentId)
18 : ModuleBase_WidgetValidated(theParent, theData, theParentId),
19 myWorkshop(theWorkshop)
23 //********************************************************************
24 ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
28 //TODO: nds stabilization hotfix
29 void ModuleBase_WidgetSelector::disconnectSignals()
31 disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
34 //********************************************************************
35 void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs,
37 GeomShapePtr& theShape)
39 ModuleBase_ISelection* aSelection = myWorkshop->selection();
40 theObject = aSelection->getResult(thePrs);
41 theShape = aSelection->getShape(thePrs);
44 //********************************************************************
45 void ModuleBase_WidgetSelector::onSelectionChanged()
49 QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
50 ModuleBase_ISelection::AllControls);
51 bool isDone = setSelection(aSelected);
54 // the updateObject method should be called to flush the updated sigal. The workshop listens it,
55 // calls validators for the feature and, as a result, updates the Apply button state.
56 updateObject(myFeature);
62 //********************************************************************
63 bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape,
64 const ResultPtr& theResult) const
68 GeomShapePtr aShape = theShape;
69 if (!aShape.get() && theResult.get()) {
71 aShape = theResult->shape();
73 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
75 // Check that the selection corresponds to selection type
76 TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
77 aShapeType = aTopoShape.ShapeType();
80 QIntList aShapeTypes = getShapeTypes();
81 QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
82 for (; anIt != aLast; anIt++) {
83 if (aShapeType == *anIt)
85 else if (*anIt == TopAbs_FACE) {
86 // try to process the construction shape only if there is no a selected shape in the viewer
87 if (!theShape.get() && theResult.get()) {
88 ResultConstructionPtr aCResult =
89 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
90 aValid = aCResult.get() && aCResult->facesNum() > 0;
97 //********************************************************************
98 void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
100 updateSelectionName();
103 myWorkshop->activateSubShapesSelection(getShapeTypes());
105 myWorkshop->deactivateSubShapesSelection();
109 //********************************************************************
110 void ModuleBase_WidgetSelector::activateCustom()
112 connect(myWorkshop, SIGNAL(selectionChanged()), this,
113 SLOT(onSelectionChanged()), Qt::UniqueConnection);
115 activateSelection(true);
117 // Restore selection in the viewer by the attribute selection list
118 myWorkshop->setSelected(getAttributeSelection());
120 activateFilters(myWorkshop, true);
123 //********************************************************************
124 bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
126 GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
127 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
128 bool aValid = acceptSubShape(aShape, aResult);
131 // In order to avoid selection of the same object
132 ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
133 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
134 aValid = aSelectedFeature != myFeature;
139 //********************************************************************
140 bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
144 getGeomSelection(thePrs, anObject, aShape);
146 setObject(anObject, aShape);
150 //********************************************************************
151 void ModuleBase_WidgetSelector::deactivate()
153 disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
154 activateSelection(false);
155 activateFilters(myWorkshop, false);