]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Union of validator and filter functionalities.
authornds <natalia.donis@opencascade.com>
Mon, 23 Mar 2015 12:57:03 +0000 (15:57 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 23 Mar 2015 12:57:03 +0000 (15:57 +0300)
This is moving of ModuleBase validators to the GeomValidator project

31 files changed:
src/ConstructionPlugin/axis_widget.xml
src/ConstructionPlugin/plane_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_ConstructionComposite.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_ConstructionComposite.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Edge.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Edge.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_EdgeOrVertex.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_EdgeOrVertex.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Face.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Face.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Tools.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Tools.h [new file with mode: 0644]
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ValidatorFace.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorFace.h [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdge.h [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h [deleted file]
src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h [deleted file]
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 435a2e7b38242583d3debda97a558b9f9dcf111d..38638ecf59aca9a4297041c2ef54a9aca7d4dddf 100644 (file)
@@ -8,14 +8,14 @@
         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>
index 193bfe01913791cdd4715e10e503606fc5eefcfe..4300f5f6f2538f51c5796168ba46dd8cea26f874 100644 (file)
@@ -7,7 +7,7 @@
                       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" 
index 51263163459b727449b3e67f666bd782e0b76c3a..3a07a17cbbf265f6c6f072ceb97ada89bbcfea0c 100644 (file)
@@ -4,27 +4,41 @@ INCLUDE(Common)
 
 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)
diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.cpp b/src/GeomValidators/GeomValidators_ConstructionComposite.cpp
new file mode 100644 (file)
index 0000000..fea2319
--- /dev/null
@@ -0,0 +1,48 @@
+// 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;
+}
diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.h b/src/GeomValidators/GeomValidators_ConstructionComposite.h
new file mode 100644 (file)
index 0000000..abe123f
--- /dev/null
@@ -0,0 +1,28 @@
+// 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
diff --git a/src/GeomValidators/GeomValidators_Edge.cpp b/src/GeomValidators/GeomValidators_Edge.cpp
new file mode 100644 (file)
index 0000000..0518f4a
--- /dev/null
@@ -0,0 +1,65 @@
+// 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;
+}
diff --git a/src/GeomValidators/GeomValidators_Edge.h b/src/GeomValidators/GeomValidators_Edge.h
new file mode 100644 (file)
index 0000000..5b29a82
--- /dev/null
@@ -0,0 +1,43 @@
+// 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
diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp b/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp
new file mode 100644 (file)
index 0000000..642d1cd
--- /dev/null
@@ -0,0 +1,62 @@
+// 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;
+}
diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.h b/src/GeomValidators/GeomValidators_EdgeOrVertex.h
new file mode 100644 (file)
index 0000000..52b7add
--- /dev/null
@@ -0,0 +1,30 @@
+// 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
diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp
new file mode 100644 (file)
index 0000000..6f26086
--- /dev/null
@@ -0,0 +1,63 @@
+// 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;
+}
diff --git a/src/GeomValidators/GeomValidators_Face.h b/src/GeomValidators/GeomValidators_Face.h
new file mode 100644 (file)
index 0000000..2ff4955
--- /dev/null
@@ -0,0 +1,34 @@
+// 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
diff --git a/src/GeomValidators/GeomValidators_Tools.cpp b/src/GeomValidators/GeomValidators_Tools.cpp
new file mode 100644 (file)
index 0000000..f98088e
--- /dev/null
@@ -0,0 +1,36 @@
+// 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;
+  }
+}
diff --git a/src/GeomValidators/GeomValidators_Tools.h b/src/GeomValidators/GeomValidators_Tools.h
new file mode 100644 (file)
index 0000000..bb1db66
--- /dev/null
@@ -0,0 +1,23 @@
+// 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
index 5dcc4090847854c573fe73a7cb3cdbec443a0ad8..b623713fc7ef550ae99d708c8e438e319631705e 100644 (file)
@@ -37,10 +37,6 @@ SET(PROJECT_HEADERS
        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
@@ -84,10 +80,6 @@ SET(PROJECT_SOURCES
        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
@@ -108,6 +100,7 @@ SET(PROJECT_LIBRARIES
        ModelAPI
        GeomAPI
        GeomAlgoAPI
+       GeomValidators
        ${QT_LIBRARIES}
        ${CAS_VIEWER}
        ${CAS_KERNEL}
@@ -135,6 +128,7 @@ INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
     ${CMAKE_SOURCE_DIR}/src/GeomAPI
     ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
+    ${CMAKE_SOURCE_DIR}/src/GeomValidators
     ${SUIT_INCLUDE}
 )
 
diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.cpp b/src/ModuleBase/ModuleBase_ValidatorFace.cpp
deleted file mode 100644 (file)
index fbc389b..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// 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
deleted file mode 100644 (file)
index 9923c9c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp
deleted file mode 100644 (file)
index cf2d280..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// 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;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h
deleted file mode 100644 (file)
index a2b3159..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// 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
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp
deleted file mode 100644 (file)
index b9c8ce1..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// 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;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h
deleted file mode 100644 (file)
index 0df6c88..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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
diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp
deleted file mode 100644 (file)
index 7a6ab98..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// 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;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h
deleted file mode 100644 (file)
index 1338fce..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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
index 265a9e42c22da4776159d4c3bd8fcf9a5e8c141a..d88a844102c216ab4cacd0b1cb9cf20a324d1dc5 100644 (file)
@@ -18,6 +18,7 @@
 #include <Events_Message.h>
 #include <GeomAPI_Interface.h>
 #include <GeomAPI_Shape.h>
+#include <GeomValidators_Tools.h>
 
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Data.h>
@@ -271,29 +272,6 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shap
   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
 {
@@ -323,7 +301,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
     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));
@@ -398,7 +376,7 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
   AttributePtr anAttribute = myFeature->attribute(attributeID());
 
   if (isBackup) {
-    myObject = getObject(anAttribute);
+    myObject = GeomValidators_Tools::getObject(anAttribute);
     myShape = getShape();
     myRefAttribute = NULL;
     myIsObject = false;
@@ -426,7 +404,7 @@ bool ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityO
   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;
 
index 2c5e253b3dbd08a32c957f5083346cd3ff5099b1..bcf13cbf1d0393192223d4c8131964f3694e94ad 100644 (file)
@@ -89,10 +89,6 @@ Q_OBJECT
   /// 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
index 326fb1c617c8d63001749973073fd1fca40ed34d..bdbc48c5208fccb1cd8dc26216aa923d43269dc8 100644 (file)
@@ -46,6 +46,7 @@ SET(PROJECT_LIBRARIES
     ModuleBase
     Config
     GeomAPI
+    GeomValidators
     ${QT_LIBRARIES}
     ${CAS_KERNEL}
     ${CAS_SHAPE}
@@ -78,6 +79,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI
                     ${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}
index 9646b8398677cffaeb97f6256ab2622d74b920c6..0b2e410b160e640a4df884d4605cbb9cb6701534 100644 (file)
 #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>
 
@@ -131,13 +131,13 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
 
-  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);
index b246046d509408010fc3d474693d38225ed23082..85b0dd3eca700f983f09cbb2d8d32fabdfe70932 100644 (file)
@@ -11,6 +11,7 @@
 #include <BRep_Tool.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <GeomAbs_CurveType.hxx>
+#include <GeomValidators_Tools.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_WidgetShapeSelector.h>
 
@@ -119,7 +120,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
 
   // 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) {
@@ -132,7 +133,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
       // 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;
     }
index 992bd6bdbd491ff5c1310ef2923577985236c474..22ce7d27eda3dce82e05a8039a73bad2c22198c1 100644 (file)
@@ -63,6 +63,7 @@ SET(PROJECT_LIBRARIES
     Config
     GeomAPI
     GeomAlgoAPI
+    GeomValidators
     ModelAPI
     SketcherPrs
     ${CAS_KERNEL}
@@ -84,6 +85,7 @@ INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoAPI
   ../GeomDataAPI
+  ../GeomValidators
   ../SketcherPrs
 )
 
index ec5e929abb7d0b6101fe2e35f0e583d71f05f1ba..32a0b30b57cc3028c1311c8b1c5935d5c46841c8 100644 (file)
@@ -12,7 +12,7 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Session.h>
 
-//#include <ModuleBase_ValidatorLinearEdge.h>
+#include <GeomValidators_Edge.h>
 
 #include <GeomDataAPI_Point2D.h>
 
@@ -35,33 +35,22 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   } else {
     // 1. check whether the references object is a linear
     ObjectPtr anObject = aRefAttr->object();
-    /*
-    const ModelAPI_AttributeValidator* aCircleValidator = 
-      dynamic_cast<ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
+
+    const ModelAPI_AttributeValidator* anEdgeValidator = 
+      dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
     std::list<std::string> anArguments;
     anArguments.push_back("circle");
-    bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
+    bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+    // the circle line is not a valid case
     if (anEdgeValid)
       return false;
       
     anArguments.clear();
     anArguments.push_back("line");
-    bool anEdgeValid = aCircleValidator->isValid(aRefAttr, anArguments);
+    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;*/
-
-    /*const ModelAPI_ResultValidator* anArcValidator = aFactory->validator("ModuleBase_ValidatorLinearEdge");
-    //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)
-      return true;*/
+      return true;
 
     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
@@ -71,65 +60,3 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   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;
-//}
index ff2183425529a7e001e9b3978497afee51154bf4..f686d3e6ebe97a5e75cefcee21b313b3fd2b7f04 100644 (file)
@@ -22,31 +22,8 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
   //! 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
index 498db23ddb4dfb0913f16779cf4081b67ebcdf95..1c7974d6db8ce0a37dc876c5c85e93ddcb342c42 100644 (file)
@@ -56,7 +56,7 @@
               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" 
@@ -66,7 +66,7 @@
           <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"/>
@@ -82,7 +82,7 @@
         <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="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+        <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">
@@ -95,7 +95,7 @@
         <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="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="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  -->