label="Plane face"
tooltip="Select a planar face"
shape_types="face">
- <selection_filter id="FaceFilter" parameters="plane"/>
+ <validator id="ModuleBase_ValidatorFace" parameters="plane"/>
</shape_selector>
<doublevalue id="distance"
label="Distance"
ModuleBase_IViewer.h
ModuleBase_WidgetLineEdit.h
ModuleBase_WidgetMultiSelector.h
+ ModuleBase_ValidatorFace.h
ModuleBase_ValidatorLinearEdge.h
ModuleBase_ValidatorLinearEdgeOrVertex.h
ModuleBase_ViewerFilters.h
ModuleBase_DoubleSpinBox.cpp
ModuleBase_WidgetLineEdit.cpp
ModuleBase_WidgetMultiSelector.cpp
+ ModuleBase_ValidatorFace.cpp
ModuleBase_ValidatorLinearEdge.cpp
ModuleBase_ValidatorLinearEdgeOrVertex.cpp
ModuleBase_ViewerFilters.cpp
--- /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
#include "ModuleBase.h"
#include "ModelAPI_AttributeValidator.h"
-#include <StdSelect_TypeOfEdge.hxx>
-
/**
* \ingroup Validators
* A validator of selection
MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const;
protected:
- /// Convert string to StdSelect_TypeOfFace value
+ /// Convert string to TypeOfEdge value
/// \param theType a string value
static TypeOfEdge edgeType(const std::string& theType);
};
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
std::list<ModelAPI_Validator*> aValidators;
std::list<std::list<std::string> > anArguments;
- aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+ aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments);
DataPtr aData = myFeature->data();
AttributePtr anAttribute = myFeature->attribute(attributeID());
#include <ModuleBase_FilterNoConsructionSubShapes.h>
#include <ModuleBase_ValidatorLinearEdge.h>
#include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
+#include <ModuleBase_ValidatorFace.h>
#include <PartSet_FilterSketchEntity.h>
aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
new ModuleBase_ValidatorLinearEdgeOrVertex);
+ aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace);
}
void PartSet_Module::registerFilters()