1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetShapeSelector.cpp
4 // Created: 27 Nov 2014
5 // Author: Vitaly Smetannikov
7 #include "PartSet_WidgetShapeSelector.h"
9 #include <ModelAPI_AttributeRefAttr.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Validator.h>
12 #include <ModelAPI_RefAttrValidator.h>
13 #include <ModelAPI_ResultValidator.h>
15 #include <PartSet_Tools.h>
16 #include <SketchPlugin_Feature.h>
19 bool PartSet_WidgetShapeSelector::storeValueCustom() const
21 if (!mySelectedObject)
24 FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
25 if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
27 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
28 std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
29 if ((!aSPFeature) && (!myShape->isNull())) {
30 // Processing of external (non-sketch) object
31 ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
32 mySelectedObject, mySketch);
34 PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
35 that->mySelectedObject = aObj;
39 // Processing of sketch object
40 DataPtr aData = myFeature->data();
42 AttributePtr aAttr = aData->attribute(attributeID());
43 AttributeRefAttrPtr aRefAttr =
44 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
46 TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
47 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
49 // this is an alternative, whether the attribute should be set or object in the attribute
50 // the first check is the attribute because the object already exist
51 // the object is set only if there is no selected attribute
52 // test case is - preselection for distance operation, which contains two points selected on lines
54 aRefAttr->setAttr(aPntAttr);
55 else if (mySelectedObject)
56 aRefAttr->setObject(mySelectedObject);
57 updateObject(myFeature);
62 return ModuleBase_WidgetShapeSelector::storeValueCustom();
65 //********************************************************************
66 bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
68 // the method is redefined to analize the selected shape in validators
69 SessionPtr aMgr = ModelAPI_Session::get();
70 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
71 std::list<ModelAPI_Validator*> aValidators;
72 std::list<std::list<std::string> > anArguments;
73 aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
75 // Check the type of selected object
76 std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
78 for (; aValidator != aValidators.end(); aValidator++) {
79 const ModelAPI_ResultValidator* aResValidator =
80 dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
83 if (aResValidator->isValid(theObj)) {
92 // Check the acceptability of the object and shape as validator attribute
93 AttributePtr aPntAttr;
94 DataPtr aData = myFeature->data();
95 if (theShape.get() != NULL) {
96 AttributePtr aAttr = aData->attribute(attributeID());
97 AttributeRefAttrPtr aRefAttr =
98 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
100 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
101 aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObj, aShape, mySketch);
104 // Check the acceptability of the object as attribute
105 aValidator = aValidators.begin();
106 std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
107 for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
108 const ModelAPI_RefAttrValidator* aAttrValidator =
109 dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
110 if (aAttrValidator) {
111 if (aPntAttr.get() != NULL)
113 if (!aAttrValidator->isValid(myFeature, *aArgs, aPntAttr)) {
119 if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {