tooltip="Select a second point"
shape_types="vertex">
<selection_filter id="NoConstructionSubShapesFilter"/>
- <validator id="PartSet_DifferentObjects"/>
+ <validator id="PartSet_DifferentShapes"/>
</shape_selector>
</source>
ModelAPI_ResultValidator.h
ModelAPI_Session.h
ModelAPI_Tools.h
+ ModelAPI_ShapeValidator.h
ModelAPI_Validator.h
)
ModelAPI_ResultGroup.cpp
ModelAPI_ResultPart.cpp
ModelAPI_Session.cpp
+ ModelAPI_ShapeValidator.cpp
ModelAPI_Tools.cpp
)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_ShapeValidator.cpp
+// Created: 2 Feb 2015
+// Author: Natalia ERMOLAEVA
+
+#include "ModelAPI_ShapeValidator.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include "ModelAPI_Object.h"
+
+bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
+ const AttributePtr& theAttribute,
+ const GeomShapePtr& theShape) const
+{
+ std::string aCurrentAttributeId = theAttribute->id();
+ // get all feature attributes
+ std::list<AttributePtr> anAttrs =
+ theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ if (anAttrs.size() > 0 && theShape.get() != NULL) {
+ std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ AttributePtr anAttribute = *anAttr;
+ // take into concideration only other attributes
+ if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
+ AttributeSelectionPtr aSelectionAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
+ // the shape of the attribute should be not the same
+ if (aSelectionAttribute.get() != NULL && theShape->isEqual(aSelectionAttribute->value())) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_ShapeValidator.h
+// Created: 2 Feb 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModelAPI_ShapeValidator_H
+#define ModelAPI_ShapeValidator_H
+
+#include <ModelAPI.h>
+
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
+
+#include <GeomAPI_Shape.h>
+
+/**
+ * Generic validator for any attribute of a feature.
+ */
+class ModelAPI_ShapeValidator : public ModelAPI_Validator
+{
+public:
+ /// returns True if the attribute is valid. It checks whether the feature of the attribute
+ /// does not contain a selection attribute filled with the same shape
+ /// \param theFeature a feature to check
+ /// \param theAttribute an attribute to check
+ /// \param theShape a shape
+ MODELAPI_EXPORT bool isValid(const FeaturePtr& theFeature, const AttributePtr& theAttribute,
+ const GeomShapePtr& theShape) const;
+};
+
+#endif
#include <ModelAPI_Validator.h>
#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_ShapeValidator.h>
#include <Config_WidgetAPI.h>
#include <Events_Error.h>
return false;
}
}
+ else {
+ const ModelAPI_ShapeValidator* aShapeValidator =
+ dynamic_cast<const ModelAPI_ShapeValidator*>(*aValidator);
+ if (aShapeValidator) {
+ DataPtr aData = myFeature->data();
+ AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
+ if (!aShapeValidator->isValid(myFeature, aSelectAttr, theShape)) {
+ return false;
+ }
+ }
+ }
}
return true;
}
\ No newline at end of file
#include <ModelAPI_Validator.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_ShapeValidator.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Point.h>
aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
+ aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
}