#include <GeomAdaptor_Curve.hxx>
#include <GeomAbs_CurveType.hxx>
#include <ModuleBase_ISelection.h>
+#include <ModuleBase_WidgetShapeSelector.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Object.h>
#include <SketchPlugin_Sketch.h>
// 1. check whether the object of the attribute is not among the feature attributes
// find the attribute's object
- ObjectPtr anObject = getObject(theAttribute);
+ ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
// check whether the object is not among other feature attributes
if (anObject.get() != NULL) {
// the function parameter attribute should be skipped
if (anAttr.get() == NULL || anAttr->id() == theAttribute->id())
continue;
- ObjectPtr aCurObject = getObject(anAttr);
+ ObjectPtr aCurObject = ModuleBase_WidgetShapeSelector::getObject(anAttr);
if (aCurObject && aCurObject == anObject)
return false;
}
return true;
}
}
+ return true;
}
bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr& theAttribute) const
return true;
}
-ObjectPtr PartSet_DifferentObjectsValidator::getObject(const AttributePtr& theAttribute) const
+bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
{
- ObjectPtr anObject;
- std::string anAttrType = theAttribute->attributeType();
- if (anAttrType == ModelAPI_AttributeRefAttr::type()) {
- AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anAttr != NULL && anAttr->isObject())
- anObject = anAttr->object();
+ bool isSketchEntities = true;
+ std::set<std::string> anEntityKinds;
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+ for (; anIt != aLast; anIt++) {
+ anEntityKinds.insert(*anIt);
}
- if (anAttrType == ModelAPI_AttributeSelection::type()) {
- AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- if (anAttr != NULL && anAttr->isInitialized())
- anObject = anAttr->context();
+
+ std::string anAttributeType = theAttribute->attributeType();
+ if (anAttributeType == ModelAPI_AttributeSelectionList::type()) {
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ // it filters only selection list attributes
+ std::string aType = aSelectionListAttr->selectionType().c_str();
+ // all context objects should be sketch entities
+ int aSize = aSelectionListAttr->size();
+ for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ ObjectPtr anObject = aSelectAttr->context();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+ }
}
- if (anAttrType == ModelAPI_AttributeReference::type()) {
- AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
- if (anAttr.get() != NULL && anAttr->isInitialized())
- anObject = anAttr->value();
+ if (anAttributeType == ModelAPI_AttributeRefAttr::type()) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ isSketchEntities = false;
+ if (aRef->isObject()) {
+ ObjectPtr anObject = aRef->object();
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if (aFeature.get() != NULL)
+ isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+ }
+ }
}
- return anObject;
-}
-bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
-{
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- return aFeature->getKind() == SketchPlugin_Sketch::ID();
+ return isSketchEntities;
}