Salome HOME
Issue #1865 : Implementation and test python interface for the field feature
authormpv <mpv@opencascade.com>
Thu, 17 Nov 2016 16:53:11 +0000 (19:53 +0300)
committermpv <mpv@opencascade.com>
Thu, 17 Nov 2016 16:53:11 +0000 (19:53 +0300)
16 files changed:
src/CollectionAPI/CollectionAPI.i
src/CollectionAPI/CollectionAPI_Field.cpp
src/CollectionAPI/CollectionAPI_Field.h
src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/CollectionPlugin_Field.h
src/CollectionPlugin/Test/TestField.py [new file with mode: 0644]
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Feature.h
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp [deleted file]
src/ModelHighAPI/ModelHighAPI_ComponentValue.h [deleted file]
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/ModelHighAPI/ModelHighAPI_swig.h
src/PythonAPI/model/collection/__init__.py

index 6bdd141e20a64c2f6dc875f801a000a9a02a8679..d7f158eeb1b9feed195f1f5376def05ee0d4eb81 100644 (file)
 #endif // CollectionAPI_swig_H_
 %}
 
+%{
+  #include "ModelHighAPI_swig.h"
+
+  // fix for SWIG v2.0.4
+  #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj))
+%}
+
 %include "doxyhelp.i"
 
 // import other modules
 
 // standard definitions
 %include "typemaps.i"
+%include "std_list.i"
+%include "std_string.i"
 %include "std_shared_ptr.i"
 
+%template(StringList) std::list<std::string>;
+%template(IntegerList) std::list<int>;
+%template(DoubleList) std::list<double>;
+%template(BooleanList) std::list<bool>;
+%template(StringListList) std::list<std::list<std::string> >;
+%template(IntegerListList) std::list<std::list<int> >;
+%template(DoubleListList) std::list<std::list<double> >;
+%template(BooleanListList) std::list<std::list<bool> >;
+
 // shared pointers
 %shared_ptr(CollectionAPI_Group)
 %shared_ptr(CollectionAPI_Field)
index b0441e4859231c540113c2bc819f4f5064669e42..4c8cd32649eda3e8cf93b0d369d3ffa4ed387eb4 100644 (file)
@@ -10,7 +10,6 @@
 #include <ModelHighAPI_Integer.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
-#include <ModelHighAPI_ComponentValue.h>
 #include <ModelAPI_AttributeTables.h>
 #include <ModelAPI_AttributeStringArray.h>
 
@@ -53,6 +52,7 @@ void CollectionAPI_Field::setComponentsNames(const std::list<std::string>& theNa
 void CollectionAPI_Field::setValuesType(const std::string& theType)
 {
   fillAttribute(int(valueTypeByStr(theType)), myvaluesType);
+  myvalues->setType(valueTypeByStr(theType));
   execute();
 }
 
@@ -60,6 +60,7 @@ void CollectionAPI_Field::setValuesType(const std::string& theType)
 void CollectionAPI_Field::setStepsNum(const ModelHighAPI_Integer& theSteps)
 {
   fillAttribute(theSteps, mystepsNum);
+  mystamps->setSize(theSteps.intValue());
   execute();
 }
 
@@ -71,36 +72,44 @@ void CollectionAPI_Field::setStamps(const std::list<ModelHighAPI_Integer>& theSt
 }
 
 //=================================================================================================
-void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum,
-  const ModelHighAPI_Integer& theStamp,
-  const std::list<std::list<ModelHighAPI_ComponentValue> >& theComponents)
-{
-  // set the table size to be sure the values are up to date
-  myvalues->setSize(myselection->size() + 1 /* with defaults */,
-    mycomponentsNum->value(), mystepsNum->value());
-
-  // set values one by one
-  int aRowIndex = 0;
-  std::list<std::list<ModelHighAPI_ComponentValue> >::const_iterator 
-    aRowsIter = theComponents.begin();
-  for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) {
-    int aColIndex = 0;
-    std::list<ModelHighAPI_ComponentValue>::const_iterator aColIter = aRowsIter->begin();
-    for(; aColIter != aRowsIter->end(); aColIter++, aColIndex++) {
-      aColIter->fill(myvalues, theStepNum.intValue(), aColIndex, aRowIndex);
-    }
-  }
-  execute();
+#define addStepImplementation(type, fieldType, type2, fieldType2, type3, fieldType3) \
+void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum, \
+  const ModelHighAPI_Integer& theStamp, \
+  const std::list<std::list<type> >& theComponents) \
+{ \
+  myvalues->setSize(myselection->size() + 1, \
+    mycomponentsNum->value(), mystepsNum->value()); \
+  mystamps->setValue(theStepNum.intValue(), theStamp.intValue()); \
+  int aRowIndex = 0; \
+  std::list<std::list<type> >::const_iterator \
+    aRowsIter = theComponents.begin(); \
+  for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) { \
+    int aColIndex = 0; \
+    std::list<type>::const_iterator aColIter = aRowsIter->begin(); \
+    for(; aColIter != aRowsIter->end(); aColIter++, aColIndex++) { \
+      ModelAPI_AttributeTables::Value aVal; \
+      aVal.fieldType = *aColIter; \
+      aVal.fieldType2 = type2(*aColIter); \
+      aVal.fieldType3 = type3(*aColIter); \
+      myvalues->setValue(aVal, aRowIndex, aColIndex, theStepNum.intValue()); \
+    } \
+  } \
+  execute(); \
 }
 
+addStepImplementation(double, myDouble, int, myInt, bool, myBool);
+addStepImplementation(int, myInt, double, myDouble, bool, myBool);
+addStepImplementation(bool, myBool, int, myInt, double, myDouble);
+addStepImplementation(std::string, myStr, std::string, myStr, std::string, myStr);
+
 //=================================================================================================
 void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
 {
   FeaturePtr aBase = feature();
   const std::string& aDocName = theDumper.name(aBase->document());
 
-  theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<mystepsNum<<", "
-    <<strByValueType(ModelAPI_AttributeTables::ValueType(myvaluesType->value()))<<", "
+  theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<mystepsNum->value()<<", \""
+    <<strByValueType(ModelAPI_AttributeTables::ValueType(myvaluesType->value()))<<"\", "
     <<mycomponentsNum->value()<<", ";
   theDumper<<mycomponentsNames<<", ";
   theDumper<<myselection<<")"<<std::endl;
@@ -114,7 +123,7 @@ void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
       for(int aCol = 0; aCol < myvalues->columns(); aCol++) {
         if (aCol != 0)
           theDumper<<", ";
-        switch(myvalues->type()) {
+        switch(myvaluesType->value()) {
         case ModelAPI_AttributeTables::BOOLEAN:
           theDumper<<myvalues->value(aRow, aCol, aStep).myBool;
           break;
@@ -125,20 +134,20 @@ void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
           theDumper<<myvalues->value(aRow, aCol, aStep).myDouble;
           break;
         case ModelAPI_AttributeTables::STRING:
-          theDumper<<myvalues->value(aRow, aCol, aStep).myStr;
+          theDumper<<'"'<<myvalues->value(aRow, aCol, aStep).myStr<<'"';
           break;
         }
       }
       theDumper<<"]";
     }
-    theDumper<<")"<<std::endl;
+    theDumper<<"])"<<std::endl;
   }
 }
 
 //=================================================================================================
 FieldPtr addField(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const ModelHighAPI_Integer& theStepsNum,
-                  std::string& theComponentType,
+                  const std::string& theComponentType,
                   const int theComponentsNum,
                   const std::list<std::string>& theComponentNames,
                   const std::list<ModelHighAPI_Selection>& theSelectionList)
index 8f0b5ecab28541d3843d5ff2e6ef62d26afdfbd2..8d38cb1ffdd2e3673acfdba435225bf9e5c6b40a 100644 (file)
@@ -67,10 +67,22 @@ public:
   /// Set stamps identifiers
   COLLECTIONAPI_EXPORT
   void setStamps(const std::list<ModelHighAPI_Integer>& theStamps);
-  /// Sets the values of specific step
+  /// Sets the double values of specific step
   COLLECTIONAPI_EXPORT
   void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
-    const std::list<std::list<ModelHighAPI_ComponentValue> >& theComponents);
+    const std::list<std::list<double> >& theComponents);
+  /// Sets the integer values of specific step
+  COLLECTIONAPI_EXPORT
+  void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
+    const std::list<std::list<int> >& theComponents);
+  /// Sets the string values of specific step
+  COLLECTIONAPI_EXPORT
+  void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
+    const std::list<std::list<std::string> >& theComponents);
+  /// Sets the boolean values of specific step
+  COLLECTIONAPI_EXPORT
+  void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
+    const std::list<std::list<bool> >& theComponents);
 
   /// Dump wrapped feature
   COLLECTIONAPI_EXPORT
@@ -85,7 +97,7 @@ typedef std::shared_ptr<CollectionAPI_Field> FieldPtr;
 COLLECTIONAPI_EXPORT
 FieldPtr addField(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const ModelHighAPI_Integer& theStepsNum,
-                  std::string& theComponentType,
+                  const std::string& theComponentType,
                   const int theComponentsNum,
                   const std::list<std::string>& theComponentNames,
                   const std::list<ModelHighAPI_Selection>& theSelectionList);
index 69df0403470b4d94093f2c06f51673885b683a52..a32fb8e9901d322598441427dfcdf74defce38e4 100644 (file)
@@ -62,4 +62,5 @@ INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 
 ADD_UNIT_TESTS(
                TestGroup.py
+               TestField.py
 )
index 162720f9186b56e02b643132e02c2f6d1efce0ae..6e06a849b59502f034eca03f37002b12b9b0ff35 100644 (file)
@@ -29,7 +29,7 @@
 class CollectionPlugin_Field : public ModelAPI_Feature
 {
  public:
-  /// Extrusion kind
+  /// Feature kind
   inline static const std::string& ID()
   {
     static const std::string MY_FIELD_ID("Field");
diff --git a/src/CollectionPlugin/Test/TestField.py b/src/CollectionPlugin/Test/TestField.py
new file mode 100644 (file)
index 0000000..5a1a66a
--- /dev/null
@@ -0,0 +1,190 @@
+"""
+      TestBoolean.py
+      Unit test of FeaturesPlugin_Group class
+
+      class FeaturesPlugin_Group
+        static const std::string MY_GROUP_ID("Group");
+        static const std::string MY_GROUP_LIST_ID("group_list");
+
+        data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+from GeomAPI import *
+
+__updated__ = "2014-12-16"
+
+aSession = ModelAPI_Session.get()
+# Create a part for extrusions & boolean
+aSession.startOperation()
+aPartFeature = aSession.moduleDocument().addFeature("Part")
+aSession.finishOperation()
+aPart = aSession.activeDocument()
+#=========================================================================
+# Create a sketch with triangle and extrude it
+#=========================================================================
+aSession.startOperation()
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
+aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
+aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
+aLineAStartPoint.setValue(-100., 0.)
+aLineAEndPoint.setValue(100., 0.)
+aLineBStartPoint.setValue(100., 0.)
+aLineBEndPoint.setValue(0., 173.2)
+aLineCStartPoint.setValue(0., 173.2)
+aLineCEndPoint.setValue(-100., 0.)
+aSession.finishOperation()
+# Build sketch faces
+aSession.startOperation()
+aSketchResult = aTriangleSketchFeature.firstResult()
+aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")).pnt()
+dirX = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")).dir()
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")).dir()
+aSketchFaces = ShapeList()
+GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, norm, aSketchEdges, aSketchFaces)
+# Create extrusion on them
+anExtrusionFt = aPart.addFeature("Extrusion")
+anExtrusionFt.selectionList("base").append(aSketchResult, aSketchFaces[0])
+anExtrusionFt.string("CreationMethod").setValue("BySizes")
+anExtrusionFt.real("to_size").setValue(50)
+anExtrusionFt.real("from_size").setValue(50)
+anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
+anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
+anExtrusionFt.execute()
+aSession.finishOperation()
+anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
+#=========================================================================
+# Create doubles field on vertices
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("vertex")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/From_Face_1_1")
+aField.integer("components_nb").setValue(2) # two components
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(2)
+aComponentNames.setValue(0, "temperatue")
+aComponentNames.setValue(1, "porosity")
+aField.integer("type").setValue(2) # double
+aField.integer("steps_nb").setValue(1) # one step
+aStamps = aField.intArray("stamps")
+aStamps.setSize(1)
+aStamps.setValue(0, 10)
+aTables = aField.tables("values")
+aTables.setType(2)
+aTables.setSize(1 + 3, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue(20, 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue(35, 1, 0, 0)
+aTables.setValue(27, 2, 0, 0)
+aTables.setValue(28, 3, 0, 0)
+aTables.setValue(0.5, 0, 1, 0)
+aTables.setValue(0.55, 1, 1, 0)
+aTables.setValue(0.39, 2, 1, 0)
+aTables.setValue(0.40, 3, 1, 0)
+aSession.finishOperation()
+#=========================================================================
+# Create strings field on faces
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("face")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
+aField.integer("components_nb").setValue(1) # one component
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(1)
+aComponentNames.setValue(0, "description")
+aField.integer("type").setValue(3) # string
+aField.integer("steps_nb").setValue(2) # two steps
+aStamps = aField.intArray("stamps")
+aStamps.setSize(2)
+aStamps.setValue(0, 1)
+aStamps.setValue(1, 3)
+aTables = aField.tables("values")
+aTables.setType(3)
+aTables.setSize(1 + 1, 1, 2) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue("-default-", 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue("-default-", 0, 0, 1)
+aTables.setValue("Face one", 1, 0, 0)
+aTables.setValue("Face two", 1, 0, 1)
+aSession.finishOperation()
+
+aFieldResult = aField.firstResult()
+assert(aFieldResult)
+#=========================================================================
+# Create integer field on faces
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("face")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
+aField.integer("components_nb").setValue(1) # one component
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(1)
+aComponentNames.setValue(0, "description")
+aField.integer("type").setValue(1) # integer
+aField.integer("steps_nb").setValue(1) # one step
+aStamps = aField.intArray("stamps")
+aStamps.setSize(1)
+aStamps.setValue(0, 0)
+aTables = aField.tables("values")
+aTables.setType(1)
+aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue(0, 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue(2, 1, 0, 0)
+aSession.finishOperation()
+
+aFieldResult = aField.firstResult()
+assert(aFieldResult)
+
+#=========================================================================
+# Create Boolean field on faces
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("face")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
+aField.integer("components_nb").setValue(1) # one component
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(1)
+aComponentNames.setValue(0, "description")
+aField.integer("type").setValue(0) # boolean
+aField.integer("steps_nb").setValue(1) # one step
+aStamps = aField.intArray("stamps")
+aStamps.setSize(1)
+aStamps.setValue(0, 0)
+aTables = aField.tables("values")
+aTables.setType(0)
+aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue(True, 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue(False, 1, 0, 0)
+aSession.finishOperation()
+
+aFieldResult = aField.firstResult()
+assert(aFieldResult)
+
+import model
+assert(model.checkPythonDump())
index b0cab6686e48afc0c7a4afb5c0d97422313c3d76..6fd73dedba08d1c0fc98e94f641159c4fd032477 100644 (file)
 %shared_ptr(ModelAPI_ResultParameter)
 %shared_ptr(ModelAPI_ResultCompSolid)
 
+%typecheck(SWIG_TYPECHECK_POINTER) const ModelAPI_AttributeTables::Value {
+  $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input) || PyBool_Check($input)) ? 1 : 0;
+}
+
+// Tables Value reading as int, double, boolean or string
+%typemap(in) const ModelAPI_AttributeTables::Value {
+  if (PyInt_Check($input)) {
+    $1.myInt = int(PyInt_AsLong($input));
+    $1.myDouble = double(PyInt_AsLong($input));
+    $1.myBool = PyInt_AsLong($input) != 0;
+  } else if (PyFloat_Check($input)) {
+    $1.myInt = int(PyFloat_AsDouble($input));
+    $1.myDouble = PyFloat_AsDouble($input);
+  } else if (PyBool_Check($input)) {
+    $1.myBool = $input == Py_True;
+  } else if (PyString_Check($input)) {
+    $1.myStr = PyString_AsString($input);
+  } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
+  } else {
+    PyErr_SetString(PyExc_ValueError, "Tables value must be int, double, string or bool.");
+    return NULL;
+  }
+}
+
 // all supported interfaces
 %include "ModelAPI_Entity.h"
 %include "ModelAPI_Document.h"
index 66eb18225d371b0cd2ba02b94a0b50581c36a0dc..b993ea254eb5b22430670cdef19eca1ea8a52fa8 100644 (file)
@@ -175,6 +175,11 @@ class ModelAPI_Feature : public ModelAPI_Object
   {
     return data()->integer(theID);
   }
+  /// Returns the integer array attribute by the identifier
+  inline std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID)
+  {
+    return data()->intArray(theID);
+  }
   /// Returns the reference attribute by the identifier
   inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
   {
@@ -205,6 +210,16 @@ class ModelAPI_Feature : public ModelAPI_Object
   {
     return data()->string(theID);
   }
+  /// Returns the string array attribute by the identifier
+  inline std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID)
+  {
+    return data()->stringArray(theID);
+  }
+  /// Returns the tables attribute by the identifier
+  inline std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID)
+  {
+    return data()->tables(theID);
+  }
   /// Returns the attribute by the identifier
   inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
   {
index 76e151451c1d22e415e101f62a41091a9dbf20c0..9607e5fa2fbc8616f882ad1a45ccb455c935f78a 100644 (file)
@@ -12,7 +12,6 @@ SET(PROJECT_HEADERS
   ModelHighAPI_RefAttr.h
   ModelHighAPI_Reference.h
   ModelHighAPI_Selection.h
-  ModelHighAPI_ComponentValue.h
   ModelHighAPI_Services.h
   ModelHighAPI_Tools.h
   ModelHighAPI_FeatureStore.h
@@ -26,7 +25,6 @@ SET(PROJECT_SOURCES
   ModelHighAPI_RefAttr.cpp
   ModelHighAPI_Reference.cpp
   ModelHighAPI_Selection.cpp
-  ModelHighAPI_ComponentValue.cpp
   ModelHighAPI_Services.cpp
   ModelHighAPI_Tools.cpp
   ModelHighAPI_FeatureStore.cpp
index 0d2daf0f31f1f8c7da8fa880d4a3345889e3c071..e7b448bc39d2453618b32173645607a3ce7551b1 100644 (file)
 %template(RefAttrList) std::list<ModelHighAPI_RefAttr>;
 %template(RefList) std::list<ModelHighAPI_Reference>;
 
+
 // fix compilarion error: ‘res*’ was not declared in this scope
 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
 %typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
 %include "ModelHighAPI_RefAttr.h"
 %include "ModelHighAPI_Reference.h"
 %include "ModelHighAPI_Selection.h"
-%include "ModelHighAPI_ComponentValue.h"
 %include "ModelHighAPI_Services.h"
 %include "ModelHighAPI_Macro.h"
 %include "ModelHighAPI_Tools.h"
diff --git a/src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp b/src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp
deleted file mode 100644 (file)
index 9c20968..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : ModelHighAPI_ComponentValue.cpp
-// Purpose:
-//
-// History:
-// 29/03/16 - Sergey POKHODENKO - Creation of the file
-
-//--------------------------------------------------------------------------------------
-#include "ModelHighAPI_ComponentValue.h"
-
-#include <ModelAPI_AttributeInteger.h>
-
-#include <sstream>
-
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const bool theValue)
-  : myType(ModelAPI_AttributeTables::BOOLEAN)
-{
-  // initialize everything since in python there may be problem with correct typification
-  myValue.myBool = theValue;
-  myValue.myInt = theValue ? 1 : 0;
-  myValue.myDouble = theValue ? 1. : 0.;
-  myValue.myStr = theValue ? "True" : "False";
-}
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const int theValue)
-  : myType(ModelAPI_AttributeTables::INTEGER)
-{
-  // initialize everything since in python there may be problem with correct typification
-  myValue.myBool = theValue == 0 ? false : true;
-  myValue.myInt = theValue;
-  myValue.myDouble = theValue;
-  std::ostringstream s;
-  s << theValue;
-  myValue.myStr = s.str();
-}
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const double theValue)
-  : myType(ModelAPI_AttributeTables::DOUBLE)
-{
-  // initialize everything since in python there may be problem with correct typification
-  myValue.myBool = theValue == 0. ? false : true;
-  myValue.myInt = int(theValue);
-  myValue.myDouble = theValue;
-  std::ostringstream s;
-  s << theValue;
-  myValue.myStr = s.str();
-}
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const std::string& theValue)
-  : myType(ModelAPI_AttributeTables::STRING)
-{
-  myValue.myBool = (theValue.empty() || theValue == "False" || theValue == "0") ? false : true;
-
-  std::stringstream stream1(theValue);
-  myValue.myInt = 0;
-  stream1 >> myValue.myInt;
-  std::stringstream stream2(theValue);
-  myValue.myDouble = 0.;
-  stream2 >> myValue.myDouble;
-
-  myValue.myStr = theValue;
-}
-
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::~ModelHighAPI_ComponentValue()
-{
-}
-
-//--------------------------------------------------------------------------------------
-void ModelHighAPI_ComponentValue::fill(const std::shared_ptr<ModelAPI_AttributeTables>& theAttr,
-    const int theTable, const int theColumn, const int theRow) const
-{
-  theAttr->setValue(myValue, theRow, theColumn, theTable);
-}
diff --git a/src/ModelHighAPI/ModelHighAPI_ComponentValue.h b/src/ModelHighAPI/ModelHighAPI_ComponentValue.h
deleted file mode 100644 (file)
index d7dd41c..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : ModelHighAPI_ComponentValue.h
-// Purpose:
-//
-// History:
-// 16/11/16 - Mikhail Ponikarov - Creation of the file
-
-#ifndef SRC_MODELHIGHAPI_ModelHighAPI_ComponentValue_H_
-#define SRC_MODELHIGHAPI_ModelHighAPI_ComponentValue_H_
-
-//--------------------------------------------------------------------------------------
-#include "ModelHighAPI.h"
-
-#include <ModelAPI_AttributeTables.h>
-
-//--------------------------------------------------------------------------------------
-/**\class ModelHighAPI_ComponentValue
- * \ingroup CPPHighAPI
- * \brief Class for filling ModelAPI_AttributeTable elements
- */
-class ModelHighAPI_ComponentValue
-{
-public:
-  /// Constructor for Boolean
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const bool theValue = false);
-  /// Constructor for int
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const int theValue);
-  /// Constructor for double
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const double theValue);
-  /// Constructor for std::string
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const std::string & theValue);
-  /// Destructor
-  MODELHIGHAPI_EXPORT virtual ~ModelHighAPI_ComponentValue();
-
-  /// Sets value to the table
-  MODELHIGHAPI_EXPORT virtual void fill(const std::shared_ptr<ModelAPI_AttributeTables>& theAttr,
-    const int theTable, const int theColumn, const int theRow) const;
-
-private:
-  ModelAPI_AttributeTables::ValueType myType; ///< type of the value set
-  ModelAPI_AttributeTables::Value myValue; ///< value itself
-};
-
-//--------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------
-#endif /* SRC_MODELHIGHAPI_ModelHighAPI_ComponentValue_H_ */
index 1176de251e001ef09757c5da6134a53f99c1ee79..1ea7a1f828e4610628a38eba8d95e4238f50a1f4 100644 (file)
@@ -839,10 +839,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
 {
   myDumpBuffer<<"[";
   for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) {
-
-    myDumpBuffer<<"\""<<theArray->value(anIndex)<<"\"";
     if (anIndex != 0)
       myDumpBuffer<<", ";
+
+    myDumpBuffer<<"\""<<theArray->value(anIndex)<<"\"";
   }
 
   myDumpBuffer<<"]";
index 99f992f49712a81d700b23f259128ac981521f13..c42072510617eaa52e828893798bc993e3092c8b 100644 (file)
@@ -21,7 +21,9 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeTables.h>
 #include <ModelAPI_Validator.h>
 
 #include <GeomDataAPI_Dir.h>
@@ -266,6 +268,35 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(theAttr);
     for(int a = 0; a < anAttr->size(); a++)
       aResult<<anAttr->value(a)<<" ";
+  } else if (aType == ModelAPI_AttributeStringArray::typeId()) {
+    AttributeStringArrayPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeStringArray>(theAttr);
+    for(int a = 0; a < anAttr->size(); a++)
+      aResult<<"'"<<anAttr->value(a)<<"'"<<" ";
+  } else if (aType == ModelAPI_AttributeTables::typeId()) {
+    AttributeTablesPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeTables>(theAttr);
+    aResult<<anAttr->tables()<<"x"<<anAttr->rows()<<"x"<<anAttr->columns()<<" ";
+    for(int aTab = 0; aTab < anAttr->tables(); aTab++) {
+      for(int aRow = 0; aRow < anAttr->rows(); aRow++) {
+        for( int aCol = 0; aCol < anAttr->columns(); aCol++) {
+          switch(anAttr->type()) {
+          case ModelAPI_AttributeTables::BOOLEAN:
+            aResult<<anAttr->value(aRow, aCol, aTab).myBool<<" ";
+            break;
+          case ModelAPI_AttributeTables::INTEGER:
+            aResult<<anAttr->value(aRow, aCol, aTab).myInt<<" ";
+            break;
+          case ModelAPI_AttributeTables::DOUBLE:
+            aResult<<anAttr->value(aRow, aCol, aTab).myDouble<<" ";
+            break;
+          case ModelAPI_AttributeTables::STRING:
+            aResult<<"'"<<anAttr->value(aRow, aCol, aTab).myStr.c_str()<<"' ";
+            break;
+          }
+        }
+      }
+    }
   } else if (aType == GeomDataAPI_Point::typeId()) {
     AttributePointPtr anAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttr);
     double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()};
index 250b8f8666c6515a60e07f28f8555235b453513a..c9230d49ef728b4bfd1af5784d03ebd4668d7a58 100644 (file)
@@ -20,7 +20,6 @@
   #include "ModelHighAPI_RefAttr.h"
   #include "ModelHighAPI_Reference.h"
   #include "ModelHighAPI_Selection.h"
-  #include "ModelHighAPI_ComponentValue.h"
   #include "ModelHighAPI_Services.h"
   #include "ModelHighAPI_Tools.h"
 
index 4189aac1066b156d823c37837f5391f724a1ece4..5c3e2548621eeac7c08cab22bf7952bdbd66d7ea 100644 (file)
@@ -1,4 +1,4 @@
 """Package for Collection plugin for the Parametric Geometry API of the Modeler.
 """
 
-from CollectionAPI import addGroup
+from CollectionAPI import addGroup, addField