]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Union of validator and filter functionalities.
authornds <natalia.donis@opencascade.com>
Fri, 20 Mar 2015 12:31:45 +0000 (15:31 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 20 Mar 2015 12:31:45 +0000 (15:31 +0300)
FaceFilter is replaced on ModuleBase_ValidatorFace

src/ConstructionPlugin/plane_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ValidatorFace.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ValidatorFace.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_ValidatorLinearEdge.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/PartSet/PartSet_Module.cpp

index 7600c1b19808c6db8f505ea22b511053d1bf114d..193bfe01913791cdd4715e10e503606fc5eefcfe 100644 (file)
@@ -7,7 +7,7 @@
                       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" 
index 4508cf3c46b7af2148a938b2b7b2bd0f06f79b45..0b76254af3ae6a28cab1ac9f95e24625c7526eea 100644 (file)
@@ -37,6 +37,7 @@ SET(PROJECT_HEADERS
        ModuleBase_IViewer.h
        ModuleBase_WidgetLineEdit.h
        ModuleBase_WidgetMultiSelector.h
+       ModuleBase_ValidatorFace.h
        ModuleBase_ValidatorLinearEdge.h
        ModuleBase_ValidatorLinearEdgeOrVertex.h
        ModuleBase_ViewerFilters.h
@@ -82,6 +83,7 @@ SET(PROJECT_SOURCES
        ModuleBase_DoubleSpinBox.cpp
        ModuleBase_WidgetLineEdit.cpp
        ModuleBase_WidgetMultiSelector.cpp
+       ModuleBase_ValidatorFace.cpp
        ModuleBase_ValidatorLinearEdge.cpp
        ModuleBase_ValidatorLinearEdgeOrVertex.cpp
        ModuleBase_ViewerFilters.cpp
diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.cpp b/src/ModuleBase/ModuleBase_ValidatorFace.cpp
new file mode 100644 (file)
index 0000000..fbc389b
--- /dev/null
@@ -0,0 +1,63 @@
+// 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;
+}
diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.h b/src/ModuleBase/ModuleBase_ValidatorFace.h
new file mode 100644 (file)
index 0000000..9923c9c
--- /dev/null
@@ -0,0 +1,34 @@
+// 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
index f88527abfffda8d02c9e84c48e71d7f7e3a0fe22..a2b3159360a6d3a420801505d8b1d06bf7717ffc 100644 (file)
@@ -10,8 +10,6 @@
 #include "ModuleBase.h"
 #include "ModelAPI_AttributeValidator.h"
 
-#include <StdSelect_TypeOfEdge.hxx>
-
 /**
 * \ingroup Validators
 * A validator of selection
@@ -35,7 +33,7 @@ class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator
   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);
 };
index 84a15322e4d9db42dd8351bed057d5e1435f2140..a5ddfb7047199767f5446cef01d431989333eb43 100644 (file)
@@ -57,7 +57,7 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const
   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());
index 489db5aedf56b3af06dac40d0715b675cce1bae2..8406ad191422b4c809b547077f28d78cc08e83cd 100644 (file)
@@ -23,6 +23,7 @@
 #include <ModuleBase_FilterNoConsructionSubShapes.h>
 #include <ModuleBase_ValidatorLinearEdge.h>
 #include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
+#include <ModuleBase_ValidatorFace.h>
 
 #include <PartSet_FilterSketchEntity.h>
 
@@ -133,6 +134,7 @@ void PartSet_Module::registerValidators()
   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()