]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create validators for constraint operations
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 9 Jul 2014 12:38:41 +0000 (16:38 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 9 Jul 2014 12:38:41 +0000 (16:38 +0400)
src/ModuleBase/ModuleBase_SelectionValidator.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Validators.cpp [new file with mode: 0644]
src/PartSet/PartSet_Validators.h [new file with mode: 0644]
src/SketchPlugin/CMakeLists.txt

index ff0c0a669b689bd049bb7d9469c53cb5fa3a5f6c..1dd38013969915e35045a4c2caa5412651f7f1e8 100644 (file)
@@ -11,7 +11,7 @@
 #include <ModelAPI_Validator.h>
 
 
-class MODULEBASE_EXPORT ModuleBase_SelectionValidator: public ModelAPI_Validator
+class ModuleBase_SelectionValidator: public ModelAPI_Validator
 {
 public:
   virtual bool isValid(const ModuleBase_ISelection* theSelection) const = 0;
index 3114ef9449e2f914f26712c5e8c9a891e2bf1c90..2824363e1d4d8b3a9c3f7039774e30b880546eb3 100644 (file)
@@ -9,10 +9,12 @@
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
 #include <PartSet_WidgetSketchLabel.h>
+#include <PartSet_Validators.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_Validator.h>
 
 #include <ModelAPI_Data.h>
 #include <GeomDataAPI_Point2D.h>
@@ -102,6 +104,16 @@ void PartSet_Module::createFeatures()
   Config_ModuleReader aXMLReader = Config_ModuleReader();
   aXMLReader.readAll();
   myFeaturesInFiles = aXMLReader.featuresInFiles();
+
+  //!! Test registering of validators
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  
+  aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
+  aFactory->assignValidator("PartSet_DistanceValidator", "SketchConstraintDistance");
+
+  aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
+  aFactory->assignValidator("PartSet_LengthValidator", "SketchConstraintLength");
 }
 
 void PartSet_Module::featureCreated(QAction* theFeature)
diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp
new file mode 100644 (file)
index 0000000..296f8da
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        PartSet_Validators.cpp
+// Created:     09 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include "PartSet_Validators.h"
+
+#include <list>
+
+
+int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType)
+{
+  std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+  std::list<ModuleBase_ViewerPrs>::iterator it;
+  ModuleBase_ViewerPrs aPrs;
+  int aCount = 0;
+  for (it = aList.begin(); it != aList.end(); ++it) {
+    aPrs = *it;
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (!aShape.IsNull()) {
+      if (aShape.ShapeType() == theType)
+        aCount++;
+    }
+  }
+  return aCount;
+}
+
+bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNb(theSelection, TopAbs_VERTEX);
+  return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+  int aCount = shapesNb(theSelection, TopAbs_EDGE);
+  return (aCount == 1);
+}
\ No newline at end of file
diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h
new file mode 100644 (file)
index 0000000..10cdcf2
--- /dev/null
@@ -0,0 +1,25 @@
+// File:        PartSet_Validators.h
+// Created:     09 July 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef PartSet_Validators_H
+#define PartSet_Validators_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_SelectionValidator.h>
+#include <ModuleBase_ISelection.h>
+
+class PartSet_DistanceValidator: public ModuleBase_SelectionValidator
+{
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+class PartSet_LengthValidator: public ModuleBase_SelectionValidator
+{
+public:
+  PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+#endif
index 2bbac462f940c751ece8b64baf53f40b23b029ba..1f5228ffd5211df9269fb9271963cfbf7d8f605e 100644 (file)
@@ -54,6 +54,7 @@ INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoAPI
   ../GeomDataAPI
+  ../ModuleBase
 )
 
 INSTALL(TARGETS SketchPlugin DESTINATION plugins)