A sketch shape validator for parallel/perpendicular constraints.
#include "ModelAPI_Object.h"
bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject,
const AttributePtr& theAttribute,
const GeomShapePtr& theShape) const
{
/// 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 theArguments a filter parameters
+ /// \param theObject an object
/// \param theAttribute an attribute to check
/// \param theShape a shape
- MODELAPI_EXPORT bool isValid(const FeaturePtr& theFeature, const AttributePtr& theAttribute,
+ MODELAPI_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject, const AttributePtr& theAttribute,
const GeomShapePtr& theShape) const;
};
if (aShapeValidator) {
DataPtr aData = myFeature->data();
AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
- if (!aShapeValidator->isValid(myFeature, aSelectAttr, theShape)) {
+ if (!aShapeValidator->isValid(myFeature, *aArgs, theObj, aSelectAttr, theShape)) {
return false;
}
}
SketchPlugin_ConstraintPerpendicular.h
SketchPlugin_ConstraintRadius.h
SketchPlugin_ConstraintRigid.h
+ SketchPlugin_ShapeValidator.h
SketchPlugin_Validators.h
SketchPlugin_ResultValidators.h
)
SketchPlugin_ConstraintPerpendicular.cpp
SketchPlugin_ConstraintRadius.cpp
SketchPlugin_ConstraintRigid.cpp
+ SketchPlugin_ShapeValidator.cpp
SketchPlugin_Validators.cpp
SketchPlugin_ResultValidators.cpp
)
#include <SketchPlugin_ConstraintRigid.h>
#include <SketchPlugin_Validators.h>
#include <SketchPlugin_ResultValidators.h>
+#include <SketchPlugin_ShapeValidator.h>
#include <Events_Loop.h>
#include <GeomDataAPI_Dir.h>
aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
+ aFactory->registerValidator("SketchPlugin_ShapeValidator",
+ new SketchPlugin_ShapeValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: Model_ResultValidators.cpp
+// Created: 27 Feb 2015
+// Author: Natalia ERMOLAEVA
+
+#include "SketchPlugin_ShapeValidator.h"
+#include "SketchPlugin_Feature.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_ResultValidator.h>
+
+bool SketchPlugin_ShapeValidator::isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject,
+ const AttributePtr& theAttribute,
+ const GeomShapePtr& theShape) const
+{
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
+
+ // if the shapes are equal, that means that the given shape is a result.
+ // if the result is selected, the
+ if (aShape->isEqual(theShape))
+ return true;
+
+ // found a non-external argument on the feature
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+ bool aHasNullParam = false;
+ bool aHasNonExternalParams = false;
+ for (; anIt != aLast; anIt++) {
+ std::string aParamA = *anIt;
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA));
+ if (anAttr) {
+ FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object());
+ if (anOtherFeature.get() != NULL) {
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(anOtherFeature);
+ if (aSketchFeature) {
+ aHasNonExternalParams = !aSketchFeature->isExternal();
+ }
+ }
+ else
+ aHasNullParam = true;
+ }
+ }
+ if (aHasNullParam || aHasNonExternalParams)
+ return true;
+ return false;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: Model_ResultValidators.h
+// Created: 27 Feb 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef SketchPlugin_ShapeValidator_H
+#define SketchPlugin_ShapeValidator_H
+
+#include <SketchPlugin.h>
+#include <ModelAPI_ShapeValidator.h>
+#include <ModelAPI_Object.h>
+
+/**\class SketchPlugin_ResultPointValidator
+ * \ingroup Validators
+ * \brief Validator for the points selection
+ *
+ * Allows to select points only.
+ */
+class SketchPlugin_ShapeValidator : public ModelAPI_ShapeValidator
+{
+public:
+ // returns true if there is an empty or non-external shape on the feature.
+ // in the given shape or in the list of attribute shapes
+ /// \param theFeature a feature to check
+ /// \param theArguments a filter parameters
+ /// \param theObject an object
+ /// \param theAttribute an attribute to check
+ /// \param theShape a shape
+ SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
+ const std::list<std::string>& theArguments,
+ const ObjectPtr& theObject, const AttributePtr& theAttribute,
+ const GeomShapePtr& theShape) const;
+};
+
+#endif
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select a line" shape_types="edge">
<selection_filter id="EdgeFilter" parameters="line"/>
+ <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line"
shape_types="edge">
<selection_filter id="EdgeFilter" parameters="line"/>
<validator id="SketchPlugin_DifferentObjects"/>
+ <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
</sketch_constraint_shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select an line"
shape_types="edge">
- <selection_filter id="EdgeFilter" parameters="line"/>
+ <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
+ <selection_filter id="EdgeFilter" parameters="line"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB"
label="Last line" tooltip="Select an line"
shape_types="edge">
<validator id="SketchPlugin_DifferentObjects"/>
- <selection_filter id="EdgeFilter" parameters="line"/>
+ <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
+ <selection_filter id="EdgeFilter" parameters="line"/>
</sketch_constraint_shape_selector>
<validator id="PartSet_PerpendicularValidator"/>
</feature>