icon=":icons/point.png"
tooltip="Select a first point"
shape_types="vertex">
- <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
+ <validator id="GeomValidators_ConstructionComposite"/>
</shape_selector>
<shape_selector id="SecondPoint"
label="Second point"
icon=":icons/point.png"
tooltip="Select a second point"
shape_types="vertex">
- <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
+ <validator id="GeomValidators_ConstructionComposite"/>
<validator id="PartSet_DifferentShapes"/>
</shape_selector>
</box>
label="Plane face"
tooltip="Select a planar face"
shape_types="face">
- <validator id="ModuleBase_ValidatorFace" parameters="plane"/>
+ <validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<doublevalue id="distance"
label="Distance"
icon=":icons/sketch.png"
tooltip="Select a sketch face"
type_choice="Faces">
- <validator id="PartSet_SketchEntityValidator"/>
+ <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
</multi_selector>
<doublevalue
id="size"
SET(PROJECT_HEADERS
GeomValidators.h
+ GeomValidators_ConstructionComposite.h
+ GeomValidators_Edge.h
+ GeomValidators_EdgeOrVertex.h
+ GeomValidators_Face.h
GeomValidators_Positive.h
+ GeomValidators_Tools.h
)
SET(PROJECT_SOURCES
+ GeomValidators_ConstructionComposite.cpp
+ GeomValidators_Edge.cpp
+ GeomValidators_EdgeOrVertex.cpp
+ GeomValidators_Face.cpp
GeomValidators_Positive.cpp
+ GeomValidators_Tools.cpp
)
SET(PROJECT_LIBRARIES
ModelAPI
- Events
+ Events
+ GeomAPI
)
-ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS)
+ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(GeomValidators SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(GeomValidators ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
- ../ModelAPI
- ../Events
+ ${CAS_INCLUDE_DIRS}
+ ${CMAKE_SOURCE_DIR}/src/ModelAPI
+ ${CMAKE_SOURCE_DIR}/src/Events
+ ${CMAKE_SOURCE_DIR}/src/GeomAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
)
INSTALL(TARGETS GeomValidators DESTINATION plugins)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "GeomValidators_ConstructionComposite.h"
+
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_ResultConstruction.h"
+#include "ModelAPI_CompositeFeature.h"
+
+bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+ AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theAttribute);
+ if (aSelectionAttr.get() == NULL)
+ return aValid;
+
+ ResultPtr aResult = aSelectionAttr->context();
+ GeomShapePtr aShape = aSelectionAttr->value();
+ // global selection should be ignored, the filter processes only selected sub-shapes
+ // that means, that the shape of the context result is equal to the shape value
+ ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShapePtr = aResult->shape();
+ // it is important to call isEqual of the shape of result.
+ // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
+ // GeomAPI_Shape. It is important to use the realization of the isEqual method from
+ // GeomAPI_Vertex class
+ aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
+ }
+ if (!aValid) {
+ ResultConstructionPtr aConstr =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+ if (aConstr != NULL) {
+ // it provides selection only on compositie features, construction without composite
+ // feature is not selectable
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+ aValid = aComposite && aComposite->numberOfSubs() > 0;
+ }
+ else {
+ // non-construction results should be accepted by this filter, e.g. body results
+ aValid = true;
+ }
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_ConstructionComposite.h
+// Created: 20 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_ConstructionComposite_H
+#define GeomValidators_ConstructionComposite_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_ConstructionComposite : public ModelAPI_AttributeValidator
+{
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_ConstructionComposite() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_Edge.h"
+#include "GeomValidators_Tools.h"
+
+#include <GeomAPI_Curve.h>
+#include <Events_Error.h>
+#include <ModelAPI_Result.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <string>
+#include <map>
+
+
+typedef std::map<std::string, GeomValidators_Edge::TypeOfEdge> EdgeTypes;
+static EdgeTypes MyEdgeTypes;
+
+GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType)
+{
+ if (MyEdgeTypes.size() == 0) {
+ MyEdgeTypes["line"] = Line;
+ MyEdgeTypes["circle"] = Circle;
+ }
+ std::string aType = std::string(theType.c_str());
+ if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
+ return MyEdgeTypes[aType];
+
+ Events_Error::send("Edge type defined in XML is not implemented!");
+ return AnyEdge;
+}
+
+bool GeomValidators_Edge::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ TypeOfEdge anEdgeType = AnyEdge;
+ if (theArguments.size() == 1) {
+ std::string anArgument = theArguments.front();
+ anEdgeType = edgeType(anArgument);
+ }
+
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShape = aResult->shape();
+ if (aShape.get() != NULL && aShape->isEdge()) {
+ aValid = anEdgeType == AnyEdge;
+ if (!aValid) {
+ bool isCircle = GeomAPI_Curve(aShape).isCircle();
+ aValid = (isCircle && anEdgeType == Circle) ||
+ (!isCircle && anEdgeType == Line);
+ }
+ }
+ }
+ }
+ else {
+ //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Edge.h
+// Created: 19 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Edge_H
+#define GeomValidators_Edge_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <string>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_Edge : public ModelAPI_AttributeValidator
+{
+ public:
+ // the edge type
+ enum TypeOfEdge
+ {
+ AnyEdge,
+ Line,
+ Circle
+ };
+
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_Edge() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+protected:
+ /// Convert string to TypeOfEdge value
+ /// \param theType a string value
+ static TypeOfEdge edgeType(const std::string& theType);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_EdgeOrVertex.h"
+#include "GeomValidators_Tools.h"
+#include "GeomValidators_Edge.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_Result.h"
+
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Curve.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <Events_Error.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <QString>
+#include <QMap>
+
+
+bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ // 1. check whether the attribute is a linear edge
+ // there is a check whether the feature contains a point and a linear edge or two point values
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+ const GeomValidators_Edge* aLinearEdgeValidator =
+ dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+
+ std::list<std::string> anArguments;
+ anArguments.push_back("line");
+ aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
+ if (!aValid) {
+ //2. check whether the attribute is a vertex
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShape = aResult->shape();
+ if (aShape.get() != NULL) {
+ aValid = aShape->isVertex();
+ }
+ }
+ }
+ else {
+ AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (anAttr.get() != NULL) {
+ AttributePtr aRefAttr = anAttr->attr();
+ aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
+ }
+ }
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_EdgeOrVertex.h
+// Created: 19 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_EdgeOrVertex_H
+#define GeomValidators_EdgeOrVertex_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_EdgeOrVertex : public ModelAPI_AttributeValidator
+{
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_EdgeOrVertex() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_Face.h"
+#include "GeomValidators_Tools.h"
+
+#include "ModelAPI_AttributeSelection.h"
+
+#include <GeomAPI_Face.h>
+
+#include <Events_Error.h>
+
+#include <QString>
+#include <QMap>
+
+typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
+static FaceTypes MyFaceTypes;
+
+GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType)
+{
+ if (MyFaceTypes.size() == 0) {
+ MyFaceTypes["plane"] = GeomAbs_Plane;
+ MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
+ }
+ std::string aType = std::string(theType.c_str());
+ if (MyFaceTypes.find(aType) != MyFaceTypes.end())
+ return MyFaceTypes[aType];
+
+ Events_Error::send("Face type defined in XML is not implemented!");
+ return GeomAbs_Plane;
+}
+
+bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
+ if (theArguments.size() == 1) {
+ std::string anArgument = theArguments.front();
+ aFaceType = faceType(anArgument);
+ }
+
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+ if (anObject.get() != NULL) {
+ AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theAttribute);
+ std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
+ std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
+ if (aGeomFace.get() != NULL) {
+ switch(aFaceType) {
+ case GeomAbs_Plane:
+ aValid = aGeomFace->isPlanar();
+ break;
+ case GeomAbs_Cylinder:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Face.h
+// Created: 20 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Face_H
+#define GeomValidators_Face_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <GeomAbs_SurfaceType.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_Face : public ModelAPI_AttributeValidator
+{
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_Face() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+protected:
+ /// Convert string to TypeOfFace value
+ /// \param theType a string value
+ GEOMVALIDATORS_EXPORT static GeomAbs_SurfaceType faceType(const std::string& theType);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Tools.cpp
+// Created: 06 Aug 2014
+// Author: Vitaly Smetannikov
+
+#include "GeomValidators_Tools.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_AttributeReference.h"
+
+namespace GeomValidators_Tools {
+
+ ObjectPtr getObject(const AttributePtr& theAttribute)
+ {
+ 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();
+ }
+ if (anAttrType == ModelAPI_AttributeSelection::type()) {
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ if (anAttr != NULL && anAttr->isInitialized())
+ anObject = anAttr->context();
+ }
+ if (anAttrType == ModelAPI_AttributeReference::type()) {
+ AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ if (anAttr.get() != NULL && anAttr->isInitialized())
+ anObject = anAttr->value();
+ }
+ return anObject;
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Tools.h
+// Created: 23 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Tools_HeaderFile
+#define GeomValidators_Tools_HeaderFile
+
+#include "GeomValidators.h"
+#include "ModelAPI_Object.h"
+#include "ModelAPI_Attribute.h"
+
+
+namespace GeomValidators_Tools
+{
+ // Returns the object from the attribute
+ /// \param theObj an object
+ GEOMVALIDATORS_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
+
+};
+
+#endif
ModelAPI_FeatureValidator.h
ModelAPI_Object.h
ModelAPI_Plugin.h
- ModelAPI_RefAttrValidator.h
ModelAPI_Result.h
ModelAPI_ResultBody.h
ModelAPI_ResultConstruction.h
ModelAPI_ResultGroup.h
ModelAPI_ResultParameters.h
ModelAPI_ResultPart.h
- ModelAPI_ResultValidator.h
ModelAPI_Session.h
ModelAPI_Tools.h
ModelAPI_ShapeValidator.h
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_RefAttrValidator.h
-// Created: 5 Aug 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_RefAttrValidator_H
-#define ModelAPI_RefAttrValidator_H
-
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeValidator.h>
-
-/**\class ModelAPI_RefAttrValidator
- * \ingroup DataModel
- * Used for filtering out the object that can be used for reference attribute value
- */
-class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator
-{
-public:
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_ResultValidators.h
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_ResultValidators_H
-#define ModelAPI_ResultValidators_H
-
-#include "ModelAPI_Validator.h"
-#include "ModelAPI_Object.h"
-
-/**\class ModelAPI_ResultValidator
- * \ingroup DataModel
- * \brief The base class for selection filter for results of features.
- *
- * The referenced arguments of feature is normally results displayed in the viewer or by the
- * selection attribute. This filter allows to filter out the results not usable as this argument.
- */
-class ModelAPI_ResultValidator : public ModelAPI_Validator
-{
-public:
- /// The abstract method for implementation in the specific validator.
- /// \param theObject the checked object as an argument
- /// \returns true if object is OK for this filter
- virtual bool isValid(const ObjectPtr theObject) const = 0;
-};
-
-#endif
ModuleBase_IViewer.h
ModuleBase_WidgetLineEdit.h
ModuleBase_WidgetMultiSelector.h
- ModuleBase_ValidatorFace.h
- ModuleBase_ValidatorLinearEdge.h
- ModuleBase_ValidatorLinearEdgeOrVertex.h
- ModuleBase_ValidatorNoConstructionSubShapes.h
ModuleBase_ViewerFilters.h
ModuleBase_ResultPrs.h
ModuleBase_IViewWindow.h
ModuleBase_DoubleSpinBox.cpp
ModuleBase_WidgetLineEdit.cpp
ModuleBase_WidgetMultiSelector.cpp
- ModuleBase_ValidatorFace.cpp
- ModuleBase_ValidatorLinearEdge.cpp
- ModuleBase_ValidatorLinearEdgeOrVertex.cpp
- ModuleBase_ValidatorNoConstructionSubShapes.cpp
ModuleBase_ViewerFilters.cpp
ModuleBase_ResultPrs.cpp
ModuleBase_WidgetLabel.cpp
ModelAPI
GeomAPI
GeomAlgoAPI
+ GeomValidators
${QT_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
${CMAKE_SOURCE_DIR}/src/GeomAPI
${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomValidators
${SUIT_INCLUDE}
)
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorFace.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-
-#include "ModelAPI_AttributeSelection.h"
-
-#include <GeomAPI_Face.h>
-
-#include <Events_Error.h>
-
-#include <QString>
-#include <QMap>
-
-typedef QMap<QString, GeomAbs_SurfaceType> FaceTypes;
-static FaceTypes MyFaceTypes;
-
-GeomAbs_SurfaceType ModuleBase_ValidatorFace::faceType(const std::string& theType)
-{
- if (MyFaceTypes.count() == 0) {
- MyFaceTypes["plane"] = GeomAbs_Plane;
- MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
- }
- QString aType = QString(theType.c_str()).toLower();
- if (MyFaceTypes.contains(aType))
- return MyFaceTypes[aType];
-
- Events_Error::send("Face type defined in XML is not implemented!");
- return GeomAbs_Plane;
-}
-
-bool ModuleBase_ValidatorFace::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
-
- GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
- if (theArguments.size() == 1) {
- std::string anArgument = theArguments.front();
- aFaceType = faceType(anArgument);
- }
-
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
- if (anObject.get() != NULL) {
- AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (theAttribute);
- std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
- std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
- if (aGeomFace.get() != NULL) {
- switch(aFaceType) {
- case GeomAbs_Plane:
- aValid = aGeomFace->isPlanar();
- break;
- case GeomAbs_Cylinder:
- break;
- default:
- break;
- }
- }
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorFace.h
-// Created: 20 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorFace_H
-#define ModuleBase_ValidatorFace_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-#include <GeomAbs_SurfaceType.hxx>
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorFace : public ModelAPI_AttributeValidator
-{
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorFace() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-protected:
- /// Convert string to TypeOfFace value
- /// \param theType a string value
- static GeomAbs_SurfaceType faceType(const std::string& theType);
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorLinearEdge.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-
-#include <GeomAPI_Curve.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-typedef QMap<QString, ModuleBase_ValidatorLinearEdge::TypeOfEdge> EdgeTypes;
-static EdgeTypes MyEdgeTypes;
-
-ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType)
-{
- if (MyEdgeTypes.count() == 0) {
- MyEdgeTypes["line"] = Line;
- MyEdgeTypes["circle"] = Circle;
- }
- QString aType = QString(theType.c_str()).toLower();
- if (MyEdgeTypes.contains(aType))
- return MyEdgeTypes[aType];
-
- Events_Error::send("Edge type defined in XML is not implemented!");
- return AnyEdge;
-}
-
-bool ModuleBase_ValidatorLinearEdge::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
-
- TypeOfEdge anEdgeType = AnyEdge;
- if (theArguments.size() == 1) {
- std::string anArgument = theArguments.front();
- anEdgeType = edgeType(anArgument);
- }
-
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
- if (anObject.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShape = aResult->shape();
- if (aShape.get() != NULL && aShape->isEdge()) {
- aValid = anEdgeType == AnyEdge;
- if (!aValid) {
- bool isCircle = GeomAPI_Curve(aShape).isCircle();
- aValid = (isCircle && anEdgeType == Circle) ||
- (!isCircle && anEdgeType == Line);
- }
- }
- }
- }
- else {
- //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorLinearEdge.h
-// Created: 19 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorLinearEdge_H
-#define ModuleBase_ValidatorLinearEdge_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator
-{
- public:
- // the edge type
- enum TypeOfEdge
- {
- AnyEdge,
- Line,
- Circle
- };
-
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdge() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-protected:
- /// Convert string to TypeOfEdge value
- /// \param theType a string value
- static TypeOfEdge edgeType(const std::string& theType);
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorLinearEdgeOrVertex.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-#include "ModuleBase_ValidatorLinearEdge.h"
-
-#include "ModelAPI_AttributeRefAttr.h"
-
-#include <ModelAPI_Session.h>
-
-#include <GeomAPI_Curve.h>
-#include <GeomDataAPI_Point2D.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
-
- // 1. check whether the attribute is a linear edge
- // there is a check whether the feature contains a point and a linear edge or two point values
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
- const ModuleBase_ValidatorLinearEdge* aLinearEdgeValidator =
- dynamic_cast<const ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
-
- std::list<std::string> anArguments;
- anArguments.push_back("line");
- aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
- if (!aValid) {
- //2. check whether the attribute is a vertex
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
- if (anObject.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShape = aResult->shape();
- if (aShape.get() != NULL) {
- aValid = aShape->isVertex();
- }
- }
- }
- else {
- AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anAttr.get() != NULL) {
- AttributePtr aRefAttr = anAttr->attr();
- aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
- }
- }
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorLinearEdgeOrVertex.h
-// Created: 19 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorLinearEdgeOrVertex_H
-#define ModuleBase_ValidatorLinearEdgeOrVertex_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorLinearEdgeOrVertex : public ModelAPI_AttributeValidator
-{
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdgeOrVertex() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-#include "ModuleBase_ValidatorNoConstructionSubShapes.h"
-
-#include "ModelAPI_AttributeSelection.h"
-#include "ModelAPI_ResultConstruction.h"
-#include "ModelAPI_CompositeFeature.h"
-
-bool ModuleBase_ValidatorNoConstructionSubShapes::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
- AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (theAttribute);
- if (aSelectionAttr.get() == NULL)
- return aValid;
-
- ResultPtr aResult = aSelectionAttr->context();
- GeomShapePtr aShape = aSelectionAttr->value();
- // global selection should be ignored, the filter processes only selected sub-shapes
- // that means, that the shape of the context result is equal to the shape value
- ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShapePtr = aResult->shape();
- // it is important to call isEqual of the shape of result.
- // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
- // GeomAPI_Shape. It is important to use the realization of the isEqual method from
- // GeomAPI_Vertex class
- aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
- }
- if (!aValid) {
- ResultConstructionPtr aConstr =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
- if (aConstr != NULL) {
- // it provides selection only on compositie features, construction without composite
- // feature is not selectable
- FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
- CompositeFeaturePtr aComposite =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
- aValid = aComposite && aComposite->numberOfSubs() > 0;
- }
- else {
- // non-construction results should be accepted by this filter, e.g. body results
- aValid = true;
- }
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorNoConstructionSubShapes.h
-// Created: 20 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorNoConstructionSubShapes_H
-#define ModuleBase_ValidatorNoConstructionSubShapes_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorNoConstructionSubShapes : public ModelAPI_AttributeValidator
-{
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorNoConstructionSubShapes() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-};
-
-#endif
#include <Events_Message.h>
#include <GeomAPI_Interface.h>
#include <GeomAPI_Shape.h>
+#include <GeomValidators_Tools.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_ShapeValidator.h>
return false;
}
-ObjectPtr ModuleBase_WidgetShapeSelector::getObject(const AttributePtr& theAttribute)
-{
- 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();
- }
- if (anAttrType == ModelAPI_AttributeSelection::type()) {
- AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- if (anAttr != NULL && anAttr->isInitialized())
- anObject = anAttr->context();
- }
- if (anAttrType == ModelAPI_AttributeReference::type()) {
- AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
- if (anAttr.get() != NULL && anAttr->isInitialized())
- anObject = anAttr->value();
- }
- return anObject;
-}
-
-
//********************************************************************
GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
{
isNameUpdated = true;
}
if (!isNameUpdated) {
- ObjectPtr anObject = getObject(myFeature->attribute(attributeID()));
+ ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
if (anObject.get() != NULL) {
std::string aName = anObject->data()->name();
myTextLine->setText(QString::fromStdString(aName));
AttributePtr anAttribute = myFeature->attribute(attributeID());
if (isBackup) {
- myObject = getObject(anAttribute);
+ myObject = GeomValidators_Tools::getObject(anAttribute);
myShape = getShape();
myRefAttribute = NULL;
myIsObject = false;
ModuleBase_ViewerPrs aPrs;
myWorkshop->selection()->fillPresentation(aPrs, theOwner);
ObjectPtr aObject = aPrs.object();
- ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID()));
+ ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
if ((!aCurrentObject) && (!aObject))
return false;
/// The methiod called when widget is deactivated
virtual void deactivate();
- // Get the object from the attribute
- /// \param theObj an object
- static ObjectPtr getObject(const AttributePtr& theAttribute);
-
public slots:
/// Activate or deactivate selection
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeValidator.h>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
return aValid;
}
-//********************************************************************
-bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const
-{
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
-
- // Check the type of selected object
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- bool isValid = true;
- for (; aValidator != aValidators.end(); aValidator++) {
- const ModelAPI_ResultValidator* aResValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
- if (aResValidator) {
- isValid = false;
- if (aResValidator->isValid(theObj)) {
- isValid = true;
- break;
- }
- }
- }
- return isValid;
-}
-
-#define VALIDATOR_FILTER
void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
const bool toActivate) const
{
ModuleBase_IViewer* aViewer = theWorkshop->viewer();
-#ifdef VALIDATOR_FILTER
Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
if (toActivate)
aViewer->addSelectionFilter(aSelFilter);
else
aViewer->removeSelectionFilter(aSelFilter);
-#else
- // apply filters loaded from the XML definition of the widget
- ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFactoryFilters;
- aFactory->filters(parentID(), attributeID(), aFactoryFilters);
- SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters);
- for (; aFactoryIt.More(); aFactoryIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value();
- if (aSelFilter.IsNull())
- continue;
- if (toActivate)
- aViewer->addSelectionFilter(aSelFilter);
- else
- aViewer->removeSelectionFilter(aSelFilter);
- }
-#endif
-}
-
-void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
- SelectMgr_ListOfFilter& theFilters) const
-{
- ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFilters;
- aFactory->filters(parentID(), attributeID(), aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
- if (aSelFilter.IsNull())
- continue;
-
- theFilters.Append(aSelFilter);
- }
}
// \return true if all validators return that the attribute is valid
bool isValidAttribute() const;
- /// Check the selected with validators if installed
- /// \param theObj the object for checking
- /// \param theShape the shape for checking
- virtual bool isValid(ObjectPtr theObj, GeomShapePtr theShape) const;
-
/// It obtains selection filters from the workshop and activates them in the active viewer
/// \param theWorkshop an active workshop
/// \param toActivate a flag about activation or deactivation the filters
virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
-
- /// Fills the given list with all widget filters.
- /// \param theWorkshop an active workshop
- /// \param theFilters a list of filters
- void selectionFilters(ModuleBase_IWorkshop* theWorkshop,
- SelectMgr_ListOfFilter& theFilters) const;
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
ModuleBase
Config
GeomAPI
+ GeomValidators
${QT_LIBRARIES}
${CAS_KERNEL}
${CAS_SHAPE}
${CMAKE_SOURCE_DIR}/src/SketchPlugin
${CMAKE_SOURCE_DIR}/src/FeaturesPlugin
${CMAKE_SOURCE_DIR}/src/GeomAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomValidators
${CMAKE_SOURCE_DIR}/src/AppElements
${CAS_INCLUDE_DIRS}
${SUIT_INCLUDE}
#include <ModuleBase_FilterMulti.h>
#include <ModuleBase_FilterCustom.h>
#include <ModuleBase_FilterNoConsructionSubShapes.h>
-#include <ModuleBase_ValidatorLinearEdge.h>
-#include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
-#include <ModuleBase_ValidatorFace.h>
-#include <ModuleBase_ValidatorNoConstructionSubShapes.h>
+#include <GeomValidators_Edge.h>
+#include <GeomValidators_EdgeOrVertex.h>
+#include <GeomValidators_Face.h>
+#include <GeomValidators_ConstructionComposite.h>
#include <PartSet_FilterSketchEntity.h>
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);
- aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
- aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
- new ModuleBase_ValidatorLinearEdgeOrVertex);
- aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace);
+ aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
+ aFactory->registerValidator("GeomValidators_EdgeOrVertex",
+ new GeomValidators_EdgeOrVertex);
+ aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
- aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
- new ModuleBase_ValidatorNoConstructionSubShapes);
+ aFactory->registerValidator("GeomValidators_ConstructionComposite",
+ new GeomValidators_ConstructionComposite);
aFactory->registerValidator("PartSet_SketchEntityValidator",
new PartSet_SketchEntityValidator);
#include <BRep_Tool.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAbs_CurveType.hxx>
+#include <GeomValidators_Tools.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_WidgetShapeSelector.h>
// 1. check whether the object of the attribute is not among the feature attributes
// find the attribute's object
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
+ ObjectPtr anObject = GeomValidators_Tools::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 = ModuleBase_WidgetShapeSelector::getObject(anAttr);
+ ObjectPtr aCurObject = GeomValidators_Tools::getObject(anAttr);
if (aCurObject && aCurObject == anObject)
return false;
}
bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
{
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-
- // it filters only selection list attributes
- if (aSelectionListAttr.get() == NULL)
- return true;
-
- std::string aType = aSelectionListAttr->selectionType().c_str();
-
- // all context objects should be sketch entities
bool isSketchEntities = true;
- int aSize = aSelectionListAttr->size();
- for (int i = 0; i < aSelectionListAttr->size(); i++) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
- ObjectPtr anObject = aSelectAttr->context();
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID();
+ std::set<std::string> anEntityKinds;
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+ for (; anIt != aLast; anIt++) {
+ anEntityKinds.insert(*anIt);
}
- return isSketchEntities;
-}
-bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
-{
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- return aFeature->getKind() == SketchPlugin_Sketch::ID();
+ 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 (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 isSketchEntities;
}
#include <ModuleBase_SelectionValidator.h>
#include <ModuleBase_ISelection.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeValidator.h>
/*
* Selector validators
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
*/
-class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
{
public:
//! Returns true if the attribute is good for the feature attribute
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
*/
-class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator
+class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator
{
public:
//! Returns true if the attribute is good for the feature attribute
const std::list<std::string>& theArguments) const;
};
-/**
-* \ingroup Validators
-* A Validator which validates tha selected object is a Sketch
-*/
-class PartSet_SketchValidator : public ModelAPI_ResultValidator
-{
- public:
- /// Returns True if the given object is a sketch
- /// \param theObject an object
- virtual bool isValid(const ObjectPtr theObject) const;
-};
-
#endif
\ No newline at end of file
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
SketchPlugin_ConstraintFillet.h
SketchPlugin_ShapeValidator.h
SketchPlugin_Validators.h
- SketchPlugin_ResultValidators.h
)
SET(PROJECT_SOURCES
SketchPlugin_ConstraintFillet.cpp
SketchPlugin_ShapeValidator.cpp
SketchPlugin_Validators.cpp
- SketchPlugin_ResultValidators.cpp
)
SET(PROJECT_LIBRARIES
Config
GeomAPI
GeomAlgoAPI
+ GeomValidators
ModelAPI
SketcherPrs
${CAS_KERNEL}
../GeomAPI
../GeomAlgoAPI
../GeomDataAPI
+ ../GeomValidators
../SketcherPrs
)
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintVertical.h>
#include <SketchPlugin_Validators.h>
-#include <SketchPlugin_ResultValidators.h>
#include <SketchPlugin_ShapeValidator.h>
#include <Events_Loop.h>
new SketchPlugin_DistanceAttrValidator);
//aFactory->registerValidator("SketchPlugin_DifferentObjects",
// new SketchPlugin_DifferentObjectsValidator);
- 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);
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: Model_ResultValidators.cpp
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#include "SketchPlugin_ResultValidators.h"
-
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Tools.h>
-#include <GeomAPI_Curve.h>
-
-ResultPtr result(const ObjectPtr theObject)
-{
- return std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-}
-
-bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isVertex();
-}
-
-bool SketchPlugin_ResultLineValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isLine();
-}
-
-bool SketchPlugin_ResultArcValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: Model_ResultValidators.h
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef Model_ResultValidators_H
-#define Model_ResultValidators_H
-
-#include <SketchPlugin.h>
-#include <ModelAPI_ResultValidator.h>
-#include <ModelAPI_Object.h>
-
-/**\class SketchPlugin_ResultPointValidator
- * \ingroup Validators
- * \brief Validator for the points selection
- *
- * Allows to select points only.
- */
-class SketchPlugin_ResultPointValidator : public ModelAPI_ResultValidator
-{
-public:
- /// Returns true if theObject is a point
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultLineValidator
- * \ingroup Validators
- * \brief Validator for the linear segments selection
- *
- * Allows to select linear segments only.
- */
-class SketchPlugin_ResultLineValidator : public ModelAPI_ResultValidator
-{
-public:
- /// Returns true if theObject is a line
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultArcValidator
- * \ingroup Validators
- * \brief Validator for the circular segments selection
- *
- * Allows to select circular segments only.
- */
-class SketchPlugin_ResultArcValidator : public ModelAPI_ResultValidator
-{
- public:
- /// Returns true if theObject is an arc
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-#endif
#include <ModelAPI_Result.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_ResultValidator.h>
bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
#include "SketchPlugin_ConstraintDistance.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Session.h>
+
+#include <GeomValidators_Edge.h>
+
#include <GeomDataAPI_Point2D.h>
bool SketchPlugin_DistanceAttrValidator::isValid(
} else {
// 1. check whether the references object is a linear
ObjectPtr anObject = aRefAttr->object();
- const ModelAPI_ResultValidator* anArcValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
- bool anArcValid = anArcValidator->isValid(anObject);
- if (anArcValid)
- return false;
- // If the object is not a line then it is accepted. It can be a point feature selected
- const ModelAPI_ResultValidator* aLineValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
- bool aLineValid = aLineValidator->isValid(anObject);
- if (!aLineValid)
+ const ModelAPI_AttributeValidator* anEdgeValidator =
+ dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+ std::list<std::string> anArguments;
+ anArguments.push_back("circle");
+ bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+ // the circle line is not a valid case
+ if (anEdgeValid)
+ return false;
+
+ anArguments.clear();
+ anArguments.push_back("line");
+ anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+ // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
+ if (!anEdgeValid)
return true;
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
// If it is a line then we have to check that first attribute id not a line
std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
if (aPoint)
}
return false;
}
-
-//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
-// const std::list<std::string>& theArguments,
-// const ObjectPtr& theObject) const
-//{
-// std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
-// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
-// std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-// for(; anAttr != anAttrs.end(); anAttr++) {
-// if (*anAttr) {
-// std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
-// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-// // check the object is already presented
-// if (aRef->isObject() && aRef->object() == theObject)
-// return false;
-// }
-// }
-// return true;
-//}
-
-//bool SketchPlugin_DifferentObjectsValidator::isValid(
-// const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
-//{
-// std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
-// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-// if (anOrigAttr && anOrigAttr->isObject()) {
-// const ObjectPtr& anObj = theAttribute->owner();
-// const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
-//
-// std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
-// aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
-// std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-// for(; anAttr != anAttrs.end(); anAttr++) {
-// if (*anAttr && *anAttr != theAttribute) {
-// std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
-// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-// // check the object is already presented
-// if (aRef->isObject() && aRef->object() == anOrigAttr->object())
-// return false;
-// }
-// }
-// }
-// return true;
-//}
-
-//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
-// const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
-//{
-// std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
-// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
-// std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-// for(; anAttr != anAttrs.end(); anAttr++) {
-// if (*anAttr) {
-// std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
-// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-// // check the object is already presented
-// if (!aRef->isObject() && aRef->attr() == theAttribute)
-// return false;
-// }
-// }
-// return true;
-//}
#define SketchPlugin_Validators_H
#include "SketchPlugin.h"
-#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_AttributeValidator.h>
/**\class SketchPlugin_DistanceAttrValidator
* \ingroup Validators
*
* It just checks that distance is greater than zero.
*/
-class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
+class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
{
public:
//! returns true if attribute is valid
//! \param theAttribute the checked attribute
//! \param theArguments arguments of the attribute
- virtual bool isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
};
-/**\class SketchPlugin_DifferentObjectsValidator
- * \ingroup Validators
- *
- * Check that there is no same object was already selected in the feature.
- * For an example: to avoid perpendicularity on line and the same line.
- */
-// Use PartSet_DifferentObjectsValidator
-//class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
-//{
-// public:
-// //! returns true if attribute is valid
-// //! \param theAttribute the checked attribute
-// //! \param theArguments arguments of the attribute
-// virtual bool isValid(
-// const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
-// //! Returns true if object is good for the feature attribute
-// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-// const ObjectPtr& theObject) const;
-// //! Returns true if the attribute is good for the feature attribute
-// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-// const AttributePtr& theAttribute) const;
-//};
-
#endif
tooltip="Select point, line end point, line, center of circle or arc."
shape_types="edge vertex">
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
- <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+ <validator id="GeomValidators_EdgeOrVertex"/>
</sketch_shape_selector>/>
<sketch_shape_selector
id="ConstraintEntityB"
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
- <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+ <validator id="GeomValidators_EdgeOrVertex"/>
</sketch_shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
<shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line"
shape_types="edge" >
- <validator id="SketchPlugin_ResultLine"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
- <validator id="SketchPlugin_ResultLine"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">
<label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
<shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc"
shape_types="edge">
- <validator id="SketchPlugin_ResultArc"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="circle"/>
+ <validator id="GeomValidators_Edge" parameters="circle"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
<feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select a line" shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" 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">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
</sketch_constraint_shape_selector>
label="First line" tooltip="Select an line"
shape_types="edge">
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB"
shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
<validator id="PartSet_PerpendicularValidator"/>
</feature>
<feature id="SketchConstraintRigid" title="Fixed" tooltip="Fix an object" icon=":icons/fixed.png">
<shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object"
shape_types="edge vertex">
- <validator id="SketchPlugin_ResultPoint"/>
- <validator id="SketchPlugin_ResultLine"/>
- <validator id="SketchPlugin_ResultArc"/>
+ <validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
</shape_selector>
<validator id="PartSet_RigidValidator"/>
</feature>
<feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line" icon=":icons/horisontal.png">
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
</feature>
<!-- SketchConstraintVertical -->
<feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line" icon=":icons/vertical.png">
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
</feature>
<!-- SketchConstraintEqual -->