From fa502f7882cc1c782b63e936e36f061f6c7cf913 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 17 Nov 2016 19:53:11 +0300 Subject: [PATCH] Issue #1865 : Implementation and test python interface for the field feature --- src/CollectionAPI/CollectionAPI.i | 18 ++ src/CollectionAPI/CollectionAPI_Field.cpp | 63 +++--- src/CollectionAPI/CollectionAPI_Field.h | 18 +- src/CollectionPlugin/CMakeLists.txt | 1 + src/CollectionPlugin/CollectionPlugin_Field.h | 2 +- src/CollectionPlugin/Test/TestField.py | 190 ++++++++++++++++++ src/ModelAPI/ModelAPI.i | 24 +++ src/ModelAPI/ModelAPI_Feature.h | 15 ++ src/ModelHighAPI/CMakeLists.txt | 2 - src/ModelHighAPI/ModelHighAPI.i | 2 +- .../ModelHighAPI_ComponentValue.cpp | 75 ------- .../ModelHighAPI_ComponentValue.h | 46 ----- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 4 +- .../ModelHighAPI_FeatureStore.cpp | 31 +++ src/ModelHighAPI/ModelHighAPI_swig.h | 1 - src/PythonAPI/model/collection/__init__.py | 2 +- 16 files changed, 335 insertions(+), 159 deletions(-) create mode 100644 src/CollectionPlugin/Test/TestField.py delete mode 100644 src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp delete mode 100644 src/ModelHighAPI/ModelHighAPI_ComponentValue.h diff --git a/src/CollectionAPI/CollectionAPI.i b/src/CollectionAPI/CollectionAPI.i index 6bdd141e2..d7f158eeb 100644 --- a/src/CollectionAPI/CollectionAPI.i +++ b/src/CollectionAPI/CollectionAPI.i @@ -15,6 +15,13 @@ #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 @@ -25,8 +32,19 @@ // standard definitions %include "typemaps.i" +%include "std_list.i" +%include "std_string.i" %include "std_shared_ptr.i" +%template(StringList) std::list; +%template(IntegerList) std::list; +%template(DoubleList) std::list; +%template(BooleanList) std::list; +%template(StringListList) std::list >; +%template(IntegerListList) std::list >; +%template(DoubleListList) std::list >; +%template(BooleanListList) std::list >; + // shared pointers %shared_ptr(CollectionAPI_Group) %shared_ptr(CollectionAPI_Field) diff --git a/src/CollectionAPI/CollectionAPI_Field.cpp b/src/CollectionAPI/CollectionAPI_Field.cpp index b0441e485..4c8cd3264 100644 --- a/src/CollectionAPI/CollectionAPI_Field.cpp +++ b/src/CollectionAPI/CollectionAPI_Field.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -53,6 +52,7 @@ void CollectionAPI_Field::setComponentsNames(const std::list& 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& theSt } //================================================================================================= -void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum, - const ModelHighAPI_Integer& theStamp, - const std::list >& 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 >::const_iterator - aRowsIter = theComponents.begin(); - for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) { - int aColIndex = 0; - std::list::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 >& theComponents) \ +{ \ + myvalues->setSize(myselection->size() + 1, \ + mycomponentsNum->value(), mystepsNum->value()); \ + mystamps->setValue(theStepNum.intValue(), theStamp.intValue()); \ + int aRowIndex = 0; \ + std::list >::const_iterator \ + aRowsIter = theComponents.begin(); \ + for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) { \ + int aColIndex = 0; \ + std::list::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<value()))<<", " + theDumper<value()<<", \"" + <value()))<<"\", " <value()<<", "; theDumper<columns(); aCol++) { if (aCol != 0) theDumper<<", "; - switch(myvalues->type()) { + switch(myvaluesType->value()) { case ModelAPI_AttributeTables::BOOLEAN: theDumper<value(aRow, aCol, aStep).myBool; break; @@ -125,20 +134,20 @@ void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const theDumper<value(aRow, aCol, aStep).myDouble; break; case ModelAPI_AttributeTables::STRING: - theDumper<value(aRow, aCol, aStep).myStr; + theDumper<<'"'<value(aRow, aCol, aStep).myStr<<'"'; break; } } theDumper<<"]"; } - theDumper<<")"<& thePart, const ModelHighAPI_Integer& theStepsNum, - std::string& theComponentType, + const std::string& theComponentType, const int theComponentsNum, const std::list& theComponentNames, const std::list& theSelectionList) diff --git a/src/CollectionAPI/CollectionAPI_Field.h b/src/CollectionAPI/CollectionAPI_Field.h index 8f0b5ecab..8d38cb1ff 100644 --- a/src/CollectionAPI/CollectionAPI_Field.h +++ b/src/CollectionAPI/CollectionAPI_Field.h @@ -67,10 +67,22 @@ public: /// Set stamps identifiers COLLECTIONAPI_EXPORT void setStamps(const std::list& 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 >& theComponents); + const std::list >& theComponents); + /// Sets the integer values of specific step + COLLECTIONAPI_EXPORT + void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp, + const std::list >& theComponents); + /// Sets the string values of specific step + COLLECTIONAPI_EXPORT + void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp, + const std::list >& theComponents); + /// Sets the boolean values of specific step + COLLECTIONAPI_EXPORT + void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp, + const std::list >& theComponents); /// Dump wrapped feature COLLECTIONAPI_EXPORT @@ -85,7 +97,7 @@ typedef std::shared_ptr FieldPtr; COLLECTIONAPI_EXPORT FieldPtr addField(const std::shared_ptr& thePart, const ModelHighAPI_Integer& theStepsNum, - std::string& theComponentType, + const std::string& theComponentType, const int theComponentsNum, const std::list& theComponentNames, const std::list& theSelectionList); diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index 69df04034..a32fb8e99 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -62,4 +62,5 @@ INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) ADD_UNIT_TESTS( TestGroup.py + TestField.py ) diff --git a/src/CollectionPlugin/CollectionPlugin_Field.h b/src/CollectionPlugin/CollectionPlugin_Field.h index 162720f91..6e06a849b 100644 --- a/src/CollectionPlugin/CollectionPlugin_Field.h +++ b/src/CollectionPlugin/CollectionPlugin_Field.h @@ -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 index 000000000..5a1a66aba --- /dev/null +++ b/src/CollectionPlugin/Test/TestField.py @@ -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()) diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index b0cab6686..6fd73dedb 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -70,6 +70,30 @@ %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" diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 66eb18225..b993ea254 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -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 intArray(const std::string& theID) + { + return data()->intArray(theID); + } /// Returns the reference attribute by the identifier inline std::shared_ptr 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 stringArray(const std::string& theID) + { + return data()->stringArray(theID); + } + /// Returns the tables attribute by the identifier + inline std::shared_ptr tables(const std::string& theID) + { + return data()->tables(theID); + } /// Returns the attribute by the identifier inline std::shared_ptr attribute(const std::string& theID) { diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 76e151451..9607e5fa2 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -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 diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 0d2daf0f3..e7b448bc3 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -216,6 +216,7 @@ %template(RefAttrList) std::list; %template(RefList) std::list; + // fix compilarion error: ‘res*’ was not declared in this scope %typemap(freearg) const std::list & {} %typemap(freearg) const std::list > & {} @@ -319,7 +320,6 @@ %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 index 9c2096854..000000000 --- a/src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp +++ /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 - -#include - -//-------------------------------------------------------------------------------------- -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& 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 index d7dd41cbf..000000000 --- a/src/ModelHighAPI/ModelHighAPI_ComponentValue.h +++ /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 - -//-------------------------------------------------------------------------------------- -/**\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& 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_ */ diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 1176de251..1ea7a1f82 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -839,10 +839,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( { myDumpBuffer<<"["; for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) { - - myDumpBuffer<<"\""<value(anIndex)<<"\""; if (anIndex != 0) myDumpBuffer<<", "; + + myDumpBuffer<<"\""<value(anIndex)<<"\""; } myDumpBuffer<<"]"; diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index 99f992f49..c42072510 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -21,7 +21,9 @@ #include #include #include +#include #include +#include #include #include @@ -266,6 +268,35 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { std::dynamic_pointer_cast(theAttr); for(int a = 0; a < anAttr->size(); a++) aResult<value(a)<<" "; + } else if (aType == ModelAPI_AttributeStringArray::typeId()) { + AttributeStringArrayPtr anAttr = + std::dynamic_pointer_cast(theAttr); + for(int a = 0; a < anAttr->size(); a++) + aResult<<"'"<value(a)<<"'"<<" "; + } else if (aType == ModelAPI_AttributeTables::typeId()) { + AttributeTablesPtr anAttr = + std::dynamic_pointer_cast(theAttr); + aResult<tables()<<"x"<rows()<<"x"<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<value(aRow, aCol, aTab).myBool<<" "; + break; + case ModelAPI_AttributeTables::INTEGER: + aResult<value(aRow, aCol, aTab).myInt<<" "; + break; + case ModelAPI_AttributeTables::DOUBLE: + aResult<value(aRow, aCol, aTab).myDouble<<" "; + break; + case ModelAPI_AttributeTables::STRING: + aResult<<"'"<value(aRow, aCol, aTab).myStr.c_str()<<"' "; + break; + } + } + } + } } else if (aType == GeomDataAPI_Point::typeId()) { AttributePointPtr anAttr = std::dynamic_pointer_cast(theAttr); double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()}; diff --git a/src/ModelHighAPI/ModelHighAPI_swig.h b/src/ModelHighAPI/ModelHighAPI_swig.h index 250b8f866..c9230d49e 100644 --- a/src/ModelHighAPI/ModelHighAPI_swig.h +++ b/src/ModelHighAPI/ModelHighAPI_swig.h @@ -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" diff --git a/src/PythonAPI/model/collection/__init__.py b/src/PythonAPI/model/collection/__init__.py index 4189aac10..5c3e25486 100644 --- a/src/PythonAPI/model/collection/__init__.py +++ b/src/PythonAPI/model/collection/__init__.py @@ -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 -- 2.39.2