]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for issue #134. Make common validator that checks OCC positive values
authormpv <mikhail.ponikarov@opencascade.com>
Tue, 16 Sep 2014 07:04:29 +0000 (11:04 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Tue, 16 Sep 2014 07:04:29 +0000 (11:04 +0400)
13 files changed:
CMakeLists.txt
src/Config/plugins.xml
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/extrusion_widget.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomValidators/CMakeLists.txt [new file with mode: 0644]
src/GeomValidators/GeomValidators.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Positive.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Positive.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 8a6134b220d433f68b7509cb91ba8ef350a24136..7806682d431b020e44f52a6aaf6d786c837b61b2 100644 (file)
@@ -58,6 +58,7 @@ ADD_SUBDIRECTORY (src/PartSet)
 ADD_SUBDIRECTORY (src/XGUI)
 ADD_SUBDIRECTORY (src/GeomApp)
 ADD_SUBDIRECTORY (src/ExchangePlugin)
+ADD_SUBDIRECTORY (src/GeomValidators)
 
 IF(${HAVE_SALOME})
        ADD_SUBDIRECTORY (src/NewGeom)
index 7d6b81b6ffe948c4fa9467f0f4ee366cc34b3507..396f565a9f20fdf8a5c3f866270fa508a8056e51 100644 (file)
@@ -5,5 +5,6 @@
   <plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
   <plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
   <plugin library="SketchSolver"/>
+  <plugin library="GeomValidators"/>
   <plugin library="DFBrowser"/>
 </plugins>
index 6d4cd90fcc66c3e561fcfe5e0b8a150eb830b298..261b08746cbaff901c9b3c1b392f977c01539cb9 100644 (file)
@@ -10,12 +10,14 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     FeaturesPlugin_Plugin.cpp
     FeaturesPlugin_Extrusion.cpp
-       FeaturesPlugin_Boolean.cpp
+    FeaturesPlugin_Boolean.cpp
 )
 
-ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
-ADD_LIBRARY(FeaturesPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(FeaturesPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI)
+SET(XML_RESOURCES
+  plugin-Features.xml
+  extrusion_widget.xml
+  boolean_widget.xml
+)
 
 INCLUDE_DIRECTORIES(
   ../ModelAPI
@@ -23,11 +25,9 @@ INCLUDE_DIRECTORIES(
   ../GeomAlgoAPI
 )
 
-SET(XML_RESOURCES
-  plugin-Features.xml
-  extrusion_widget.xml
-  boolean_widget.xml
-)
+ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
+ADD_LIBRARY(FeaturesPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
+TARGET_LINK_LIBRARIES(FeaturesPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI)
 
 INSTALL(TARGETS FeaturesPlugin DESTINATION plugins)
 INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
index c0069ca67cfd56b2d851ad6e68fdff65e62430df..795db94f0ae424c825e0c658f6d90a463ecf7db5 100644 (file)
@@ -6,6 +6,8 @@
     activate="true"
     shape_types="face"
   />
-  <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion"/>
+  <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
+    <validator id="GeomValidators_Positive"/>
+  </doublevalue>
   <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
 </source>
index 26b230a2539915657f15b626987b49e24c286ada..41d7d8631aa6088ad7f151b5a7de54a36b2f2005 100644 (file)
@@ -11,7 +11,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_PointBuilder.h
     GeomAlgoAPI_SketchBuilder.h
     GeomAlgoAPI_Extrusion.h
-       GeomAlgoAPI_Boolean.h
+    GeomAlgoAPI_Boolean.h
 )
 
 SET(PROJECT_SOURCES
@@ -21,7 +21,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_PointBuilder.cpp
     GeomAlgoAPI_SketchBuilder.cpp
     GeomAlgoAPI_Extrusion.cpp
-       GeomAlgoAPI_Boolean.cpp
+    GeomAlgoAPI_Boolean.cpp
 )
 
 ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt
new file mode 100644 (file)
index 0000000..efb0b10
--- /dev/null
@@ -0,0 +1,28 @@
+INCLUDE(Common)
+
+SET(PROJECT_HEADERS
+    GeomValidators.h
+    GeomValidators_Positive.h
+)
+
+SET(PROJECT_SOURCES
+    GeomValidators_Positive.cpp
+)
+
+SET(PROJECT_LIBRARIES
+    ModelAPI 
+    Events 
+)
+
+
+
+ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS ${BOOST_DEFINITIONS})
+ADD_LIBRARY(GeomValidators SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+TARGET_LINK_LIBRARIES(GeomValidators ${PROJECT_LIBRARIES})
+
+INCLUDE_DIRECTORIES(
+  ../ModelAPI
+  ../Events
+)
+
+INSTALL(TARGETS GeomValidators DESTINATION plugins)
diff --git a/src/GeomValidators/GeomValidators.h b/src/GeomValidators/GeomValidators.h
new file mode 100644 (file)
index 0000000..0966a48
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef GEOMVALIDATORS_H
+#define GEOMVALIDATORS_H
+
+#if defined GEOMVALIDATORS_EXPORTS
+#if defined WIN32
+#define GEOMVALIDATORS_EXPORT              __declspec( dllexport )
+#else
+#define GEOMVALIDATORS_EXPORT
+#endif
+#else
+#if defined WIN32
+#define GEOMVALIDATORS_EXPORT              __declspec( dllimport )
+#else
+#define GEOMVALIDATORS_EXPORT
+#endif
+#endif
+
+#endif
diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp
new file mode 100644 (file)
index 0000000..935bce6
--- /dev/null
@@ -0,0 +1,27 @@
+// File:        GeomValidators_ValidatorPositive.cpp
+// Created:     16 Sep 2014
+// Author:      Mikhail PONIKAROV
+
+#include "GeomValidators_Positive.h"
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+/// Global instance for validators factory
+GeomValidators_Positive MY_INSTANCE;
+
+GeomValidators_Positive::GeomValidators_Positive()
+{
+  // this validator is registered in the factory on this library loading
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  aFactory->registerValidator("GeomValidators_Positive", &MY_INSTANCE);
+}
+
+bool GeomValidators_Positive::isValid(
+    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+{
+  boost::shared_ptr<ModelAPI_AttributeDouble> aDouble = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
+  return aDouble->isInitialized() && aDouble->value() > 1.e-5;
+}
diff --git a/src/GeomValidators/GeomValidators_Positive.h b/src/GeomValidators/GeomValidators_Positive.h
new file mode 100644 (file)
index 0000000..f526999
--- /dev/null
@@ -0,0 +1,27 @@
+// File:        GeomValidators_ValidatorPositive.h
+// Created:     16 Sep 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef GeomValidators_ValidatorPositive_H
+#define GeomValidators_ValidatorPositive_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_AttributeValidator.h>
+
+/**
+ * Validates that the double attribute is greater than 1.e-5
+ */
+class GeomValidators_Positive : public ModelAPI_AttributeValidator
+{
+public:
+  //! Constructor for only one instance per application: will register the validator
+  GeomValidators_Positive();
+  //! 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
index 90f54d5604785d6f5e08e72b605e5d5a007b6fce..1b0730b7632337cbc3ab9fba0005199bb0480f51 100644 (file)
@@ -29,8 +29,6 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
                               new SketchPlugin_DistanceAttrValidator);
-  aFactory->registerValidator("SketchPlugin_RadiusValidator",
-                              new SketchPlugin_RadiusValidator);
   aFactory->registerValidator("SketchPlugin_ResultPointValidator", new SketchPlugin_ResultPointValidator);
   aFactory->registerValidator("SketchPlugin_ResultLineValidator", new SketchPlugin_ResultLineValidator);
   aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator);
index 14f5aaa9bf69b4d5295157ef9ccd868ef4571d9b..94e5676f55f81fe56da609dedc5288e681207b1a 100644 (file)
@@ -43,11 +43,3 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   return true; // it may be not reference attribute, in this case, it is OK
 }
-
-bool SketchPlugin_RadiusValidator::isValid(
-    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
-{
-  boost::shared_ptr<ModelAPI_AttributeDouble> aDouble = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
-  return aDouble->isInitialized() && aDouble->value() > 1.e-5;
-}
index 8a5a82bb04a3f30f5bd76b90361a60548f778c28..ece17e599458521ebe075ebc4b23e284ee655b84 100644 (file)
@@ -22,18 +22,4 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
 
 };
 
-/**
- * It must be bigger than 1.e-5
- */
-class SketchPlugin_RadiusValidator : 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;
-
-};
-
 #endif
index 422db10583b24042a633af761c41b5f5e7538872..47b2ccbe3a563a1f58f1b7267eee42262545fe0b 100644 (file)
@@ -15,7 +15,7 @@
       <feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
         <point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
         <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius">
-          <validator id="SketchPlugin_RadiusValidator"/>
+          <validator id="GeomValidators_Positive"/>
         </point2ddistance>
       </feature>
       <feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon=":icons/arc.png">