- ObjectPtr aObject = theValue.object();
- ObjectPtr aCurrentObject = getObject();
- if ((!aCurrentObject) && (!aObject))
- return false;
-
- // Check that the selected object is result (others can not be accepted)
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
- if (!aRes)
- return false;
-
- if (myFeature) {
- // We can not select a result of our feature
- const std::list<std::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aRes)
- return false;
- }
- }
- // Check that object belongs to active document or PartSet
- DocumentPtr aDoc = aRes->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument()))
- return false;
-
- // Check that the result has a shape
- GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
- if (!aShape)
- return false;
-
- // Get sub-shapes from local selection
- if (!theValue.shape().IsNull()) {
- aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(theValue.shape()));
- }
-
- // Check that the selection corresponds to selection type
- if (!acceptSubShape(aShape))
- return false;
-// if (!acceptObjectShape(aObject))
-// return false;
-
- // Check whether the value is valid for the viewer selection filters
- Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
- if (!anOwner.IsNull()) {
- SelectMgr_ListOfFilter aFilters;
- selectionFilters(myWorkshop, aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- const Handle(SelectMgr_Filter)& aFilter = aIt.Value();
- if (!aFilter->IsOk(anOwner))
- return false;
- }
- }
- if (isValid(aObject, aShape)) {
- setObject(aObject, aShape);
- return true;
- }
- return false;
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
-{
- if (storeAttributeValues(theObj, theShape))
- updateObject(myFeature);
-
- if (theObj) {
- raisePanel();
- }
- updateSelectionName();
- emit valuesChanged();
-}
-
-//********************************************************************
-//bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const
-//{
-// ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theResult);
-//
-// // Check that the shape of necessary type
-// std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
-// if (!aShapePtr)
-// return false;
-// TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
-// if (aShape.IsNull())
-// return false;
-//
-// TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
-// if (aShapeType == TopAbs_COMPOUND) {
-// foreach (QString aType,
-// myShapeTypes) {
-// TopExp_Explorer aEx(aShape, shapeType(aType));
-// if (aEx.More())
-// return true;
-// }
-// } else {
-// foreach (QString aType, myShapeTypes) {
-// if (shapeType(aType) == aShapeType)
-// return true;
-// }
-// }
-// return false;
-//}
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const
-{
- TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
- foreach (QString aType, myShapeTypes) {
- if (aShape.ShapeType() == shapeType(aType))
- return true;
- }
- return false;
-}
-
-//********************************************************************
-ObjectPtr ModuleBase_WidgetShapeSelector::getObject() const
-{
- ObjectPtr anObject;
-
- DataPtr aData = myFeature->data();
- if (aData.get() == NULL)
- return anObject;
-
- AttributeSelectionPtr aSelect = aData->selection(attributeID());
- if (aSelect) {
- anObject = aSelect->context();
- } else {
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- anObject = aRefAttr->object();
- } else {
- AttributeReferencePtr aRef = aData->reference(attributeID());
- if (aRef) {
- anObject = aRef->value();
- }
- }