From 2895c0fa0d69afc25ef86a300ef00d850a3df832 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 16 Nov 2016 17:20:37 +0300 Subject: [PATCH] Issue #1865 : initial implementation of fields results and high level API --- src/CollectionAPI/CMakeLists.txt | 2 + src/CollectionAPI/CollectionAPI.i | 3 + src/CollectionAPI/CollectionAPI_Field.cpp | 155 ++++++++++++++++++ src/CollectionAPI/CollectionAPI_Field.h | 93 +++++++++++ .../CollectionPlugin_Field.cpp | 5 +- src/Model/CMakeLists.txt | 2 + src/Model/Model_AttributeTables.cpp | 2 +- src/Model/Model_AttributeTables.h | 2 +- src/Model/Model_Document.cpp | 6 + src/Model/Model_Document.h | 3 + src/Model/Model_Objects.cpp | 20 +++ src/Model/Model_Objects.h | 3 + src/Model/Model_ResultField.cpp | 46 ++++++ src/Model/Model_ResultField.h | 41 +++++ src/ModelAPI/CMakeLists.txt | 2 + src/ModelAPI/ModelAPI.i | 3 + src/ModelAPI/ModelAPI_AttributeTables.h | 6 +- src/ModelAPI/ModelAPI_Document.h | 4 + src/ModelAPI/ModelAPI_ResultField.cpp | 17 ++ src/ModelAPI/ModelAPI_ResultField.h | 47 ++++++ src/ModelAPI/ModelAPI_swig.h | 1 + src/ModelHighAPI/CMakeLists.txt | 2 + src/ModelHighAPI/ModelHighAPI.i | 1 + .../ModelHighAPI_ComponentValue.cpp | 75 +++++++++ .../ModelHighAPI_ComponentValue.h | 46 ++++++ src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 17 +- src/ModelHighAPI/ModelHighAPI_Dumper.h | 4 + src/ModelHighAPI/ModelHighAPI_Integer.cpp | 6 + src/ModelHighAPI/ModelHighAPI_Integer.h | 5 +- src/ModelHighAPI/ModelHighAPI_Tools.cpp | 51 ++++++ src/ModelHighAPI/ModelHighAPI_Tools.h | 16 ++ src/ModelHighAPI/ModelHighAPI_swig.h | 1 + 32 files changed, 678 insertions(+), 9 deletions(-) create mode 100644 src/CollectionAPI/CollectionAPI_Field.cpp create mode 100644 src/CollectionAPI/CollectionAPI_Field.h create mode 100644 src/Model/Model_ResultField.cpp create mode 100644 src/Model/Model_ResultField.h create mode 100644 src/ModelAPI/ModelAPI_ResultField.cpp create mode 100644 src/ModelAPI/ModelAPI_ResultField.h create mode 100644 src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp create mode 100644 src/ModelHighAPI/ModelHighAPI_ComponentValue.h diff --git a/src/CollectionAPI/CMakeLists.txt b/src/CollectionAPI/CMakeLists.txt index 9d43f619f..cbe69c1f0 100644 --- a/src/CollectionAPI/CMakeLists.txt +++ b/src/CollectionAPI/CMakeLists.txt @@ -5,10 +5,12 @@ INCLUDE(Common) SET(PROJECT_HEADERS CollectionAPI.h CollectionAPI_Group.h + CollectionAPI_Field.h ) SET(PROJECT_SOURCES CollectionAPI_Group.cpp + CollectionAPI_Field.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/CollectionAPI/CollectionAPI.i b/src/CollectionAPI/CollectionAPI.i index 0fbf143e0..6bdd141e2 100644 --- a/src/CollectionAPI/CollectionAPI.i +++ b/src/CollectionAPI/CollectionAPI.i @@ -10,6 +10,7 @@ #include "CollectionAPI.h" #include "CollectionAPI_Group.h" + #include "CollectionAPI_Field.h" #endif // CollectionAPI_swig_H_ %} @@ -28,6 +29,8 @@ // shared pointers %shared_ptr(CollectionAPI_Group) +%shared_ptr(CollectionAPI_Field) // all supported interfaces %include "CollectionAPI_Group.h" +%include "CollectionAPI_Field.h" diff --git a/src/CollectionAPI/CollectionAPI_Field.cpp b/src/CollectionAPI/CollectionAPI_Field.cpp new file mode 100644 index 000000000..b0441e485 --- /dev/null +++ b/src/CollectionAPI/CollectionAPI_Field.cpp @@ -0,0 +1,155 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: CollectionAPI_Field.cpp +// Created: 16 Nov 2016 +// Author: Mikhail Ponikarov + +#include "CollectionAPI_Field.h" + +#include +#include +#include +#include +#include +#include +#include + +#include // for std::transform + +//================================================================================================= +CollectionAPI_Field::CollectionAPI_Field(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================= +CollectionAPI_Field::~CollectionAPI_Field() +{ +} + +//================================================================================================= +void CollectionAPI_Field::setSelection(const std::list& theFieldList) +{ + fillAttribute(theFieldList, myselection); + execute(); +} + +//================================================================================================= +void CollectionAPI_Field::setComponentsNum(const ModelHighAPI_Integer& theNum) +{ + fillAttribute(theNum, mycomponentsNum); + execute(); +} + +//================================================================================================= +void CollectionAPI_Field::setComponentsNames(const std::list& theNames) +{ + fillAttribute(theNames, mycomponentsNames); + execute(); +} + +//================================================================================================= +void CollectionAPI_Field::setValuesType(const std::string& theType) +{ + fillAttribute(int(valueTypeByStr(theType)), myvaluesType); + execute(); +} + +//================================================================================================= +void CollectionAPI_Field::setStepsNum(const ModelHighAPI_Integer& theSteps) +{ + fillAttribute(theSteps, mystepsNum); + execute(); +} + +//================================================================================================= +void CollectionAPI_Field::setStamps(const std::list& theStamps) +{ + fillAttribute(theStamps, mystamps); + execute(); +} + +//================================================================================================= +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(); +} + +//================================================================================================= +void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + theDumper<value()))<<", " + <value()<<", "; + theDumper<tables(); aStep++) { + theDumper<value(aStep)<<", ["; + for(int aRow = 0; aRow < myvalues->rows(); aRow++) { + if (aRow != 0) + theDumper<<", "; + theDumper<<"["; + for(int aCol = 0; aCol < myvalues->columns(); aCol++) { + if (aCol != 0) + theDumper<<", "; + switch(myvalues->type()) { + case ModelAPI_AttributeTables::BOOLEAN: + theDumper<value(aRow, aCol, aStep).myBool; + break; + case ModelAPI_AttributeTables::INTEGER: + theDumper<value(aRow, aCol, aStep).myInt; + break; + case ModelAPI_AttributeTables::DOUBLE: + theDumper<value(aRow, aCol, aStep).myDouble; + break; + case ModelAPI_AttributeTables::STRING: + theDumper<value(aRow, aCol, aStep).myStr; + break; + } + } + theDumper<<"]"; + } + theDumper<<")"<& thePart, + const ModelHighAPI_Integer& theStepsNum, + std::string& theComponentType, + const int theComponentsNum, + const std::list& theComponentNames, + const std::list& theSelectionList) +{ + std::shared_ptr aFeature = thePart->addFeature(CollectionAPI_Field::ID()); + std::shared_ptr aField(new CollectionAPI_Field(aFeature)); + aField->setStepsNum(theStepsNum); + aField->setValuesType(theComponentType); + aField->setComponentsNum(theComponentsNum); + aField->setComponentsNames(theComponentNames); + aField->setSelection(theSelectionList); + + return aField; +} diff --git a/src/CollectionAPI/CollectionAPI_Field.h b/src/CollectionAPI/CollectionAPI_Field.h new file mode 100644 index 000000000..8f0b5ecab --- /dev/null +++ b/src/CollectionAPI/CollectionAPI_Field.h @@ -0,0 +1,93 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: CollectionAPI_Field.h +// Created: 16 Nov 2016 +// Author: Mikhail Ponikarov + +#ifndef CollectionAPI_Field_H_ +#define CollectionAPI_Field_H_ + +#include "CollectionAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Dumper; +class ModelHighAPI_Selection; +class ModelHighAPI_Integer; +class ModelHighAPI_ComponentValue; + +/// \class CollectionAPI_Field +/// \inField CPPHighAPI +/// \brief Interface for Field feature. +class CollectionAPI_Field: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + COLLECTIONAPI_EXPORT + explicit CollectionAPI_Field(const std::shared_ptr& theFeature); + + /// Destructor. + COLLECTIONAPI_EXPORT + virtual ~CollectionAPI_Field(); + + INTERFACE_7(CollectionPlugin_Field::ID(), + selection, CollectionPlugin_Field::SELECTED_ID(), + ModelAPI_AttributeSelectionList, /** Field selection list*/, + componentsNum, CollectionPlugin_Field::COMPONENTS_NB_ID(), + ModelAPI_AttributeInteger, /** Number of components integer */, + componentsNames, CollectionPlugin_Field::COMPONENTS_NAMES_ID(), + ModelAPI_AttributeStringArray, /** Names of components list of strings */, + valuesType, CollectionPlugin_Field::VALUES_TYPE_ID(), + ModelAPI_AttributeInteger, /** Type of the values enumeration */, + stepsNum, CollectionPlugin_Field::STEPS_NB_ID(), + ModelAPI_AttributeInteger, /** Number of steps integer */, + stamps, CollectionPlugin_Field::STAMPS_ID(), + ModelAPI_AttributeIntArray, /** Identifiers of stamps */, + values, CollectionPlugin_Field::VALUES_ID(), ModelAPI_AttributeTables /** Table of values */, + ) + + /// Set selected objects. + COLLECTIONAPI_EXPORT + void setSelection(const std::list& theFieldList); + /// Set number of components + COLLECTIONAPI_EXPORT + void setComponentsNum(const ModelHighAPI_Integer& theNum); + /// Set names of components + COLLECTIONAPI_EXPORT + void setComponentsNames(const std::list& theNames); + /// Set type of values + COLLECTIONAPI_EXPORT + void setValuesType(const std::string& theType); + /// Set number of steps + COLLECTIONAPI_EXPORT + void setStepsNum(const ModelHighAPI_Integer& theSteps); + /// Set stamps identifiers + COLLECTIONAPI_EXPORT + void setStamps(const std::list& theStamps); + /// Sets the 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 + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on Field object. +typedef std::shared_ptr FieldPtr; + +/// \inField CPPHighAPI +/// \brief Create Field feature. +COLLECTIONAPI_EXPORT +FieldPtr addField(const std::shared_ptr& thePart, + const ModelHighAPI_Integer& theStepsNum, + std::string& theComponentType, + const int theComponentsNum, + const std::list& theComponentNames, + const std::list& theSelectionList); + +#endif // CollectionAPI_Field_H_ diff --git a/src/CollectionPlugin/CollectionPlugin_Field.cpp b/src/CollectionPlugin/CollectionPlugin_Field.cpp index d3ef250e3..bc2daf57e 100644 --- a/src/CollectionPlugin/CollectionPlugin_Field.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Field.cpp @@ -13,6 +13,7 @@ #include #include #include +#include CollectionPlugin_Field::CollectionPlugin_Field() { @@ -32,7 +33,7 @@ void CollectionPlugin_Field::initAttributes() void CollectionPlugin_Field::execute() { if (results().empty() || firstResult()->isDisabled()) { // just create result if not exists - //ResultPtr aField = document()->createField(data()); - //setResult(aField); + ResultPtr aField = document()->createField(data()); + setResult(aField); } } diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index d7f1441ed..fe49abf6a 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS Model_ResultCompSolid.h Model_ResultConstruction.h Model_ResultPart.h + Model_ResultField.h Model_ResultGroup.h Model_ResultParameter.h Model_FeatureValidator.h @@ -70,6 +71,7 @@ SET(PROJECT_SOURCES Model_ResultCompSolid.cpp Model_ResultConstruction.cpp Model_ResultPart.cpp + Model_ResultField.cpp Model_ResultGroup.cpp Model_ResultParameter.cpp Model_FeatureValidator.cpp diff --git a/src/Model/Model_AttributeTables.cpp b/src/Model/Model_AttributeTables.cpp index b6c2c4e8c..923caa3d7 100644 --- a/src/Model/Model_AttributeTables.cpp +++ b/src/Model/Model_AttributeTables.cpp @@ -163,7 +163,7 @@ void Model_AttributeTables::setType(ModelAPI_AttributeTables::ValueType theType) } } -const ModelAPI_AttributeTables::ValueType& Model_AttributeTables::type(ValueType) const +const ModelAPI_AttributeTables::ValueType& Model_AttributeTables::type() const { return myType; } diff --git a/src/Model/Model_AttributeTables.h b/src/Model/Model_AttributeTables.h index 311b94751..8752ffa72 100644 --- a/src/Model/Model_AttributeTables.h +++ b/src/Model/Model_AttributeTables.h @@ -44,7 +44,7 @@ public: /// Defines the tyoe of values in the table. If it differs from the current, erases the content. MODEL_EXPORT virtual void setType(ValueType theType); /// Defines the tyoe of values in the table. If it differs from the current, erases the content. - MODEL_EXPORT virtual const ValueType& type(ValueType) const; + MODEL_EXPORT virtual const ValueType& type() const; /// Defines the value by the index in the tables set (indexes are zero-based). MODEL_EXPORT virtual void setValue( const Value theValue, const int theRow, const int theColumn, const int theTable = 0); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 61331514c..c8b567cf7 100755 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -1170,6 +1170,12 @@ std::shared_ptr Model_Document::createGroup( return myObjs->createGroup(theFeatureData, theIndex); } +std::shared_ptr Model_Document::createField( + const std::shared_ptr& theFeatureData, const int theIndex) +{ + return myObjs->createField(theFeatureData, theIndex); +} + std::shared_ptr Model_Document::createParameter( const std::shared_ptr& theFeatureData, const int theIndex) { diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 0fe3b2988..80daeb237 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -174,6 +174,9 @@ class Model_Document : public ModelAPI_Document /// Creates a group result MODEL_EXPORT virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0); + /// Creates a field result + MODEL_EXPORT virtual std::shared_ptr createField( + const std::shared_ptr& theFeatureData, const int theIndex = 0); /// Creates a parameter result MODEL_EXPORT virtual std::shared_ptr createParameter( const std::shared_ptr& theFeatureData, const int theIndex = 0); diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 715bc6896..164b08820 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1008,6 +1009,23 @@ std::shared_ptr Model_Objects::createGroup( return aResult; } +std::shared_ptr Model_Objects::createField( + const std::shared_ptr& theFeatureData, const int theIndex) +{ + TDF_Label aLab = resultLabel(theFeatureData, theIndex); + TDataStd_Comment::Set(aLab, ModelAPI_ResultField::group().c_str()); + ObjectPtr anOldObject = object(aLab); + std::shared_ptr aResult; + if (anOldObject.get()) { + aResult = std::dynamic_pointer_cast(anOldObject); + } + if (!aResult.get()) { + aResult = std::shared_ptr(new Model_ResultField(theFeatureData)); + storeResult(theFeatureData, aResult, theIndex); + } + return aResult; +} + std::shared_ptr Model_Objects::createParameter( const std::shared_ptr& theFeatureData, const int theIndex) { @@ -1106,6 +1124,8 @@ void Model_Objects::updateResults(FeaturePtr theFeature) break; } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) { aNewBody = createGroup(theFeature->data(), aResIndex); + } else if (aGroup->Get() == ModelAPI_ResultField::group().c_str()) { + aNewBody = createField(theFeature->data(), aResIndex); } else if (aGroup->Get() == ModelAPI_ResultParameter::group().c_str()) { theFeature->attributeChanged("expression"); // just produce a value break; diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index 23ae72453..af366689b 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -116,6 +116,9 @@ class Model_Objects /// Creates a group result std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0); + /// Creates a field result + std::shared_ptr createField( + const std::shared_ptr& theFeatureData, const int theIndex = 0); /// Creates a parameter result std::shared_ptr createParameter( const std::shared_ptr& theFeatureData, const int theIndex = 0); diff --git a/src/Model/Model_ResultField.cpp b/src/Model/Model_ResultField.cpp new file mode 100644 index 000000000..15509ef21 --- /dev/null +++ b/src/Model/Model_ResultField.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_ResultField.cpp +// Created: 08 Jul 2014 +// Author: Mikhail PONIKAROV + +#include +#include + +#include + +#include + +Model_ResultField::Model_ResultField(std::shared_ptr theOwnerData) +{ + myOwnerData = theOwnerData; +} + +void Model_ResultField::colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault) +{ + theSection = "Visualization"; + theName = "result_field_color"; + theDefault = DEFAULT_COLOR(); +} + +std::shared_ptr Model_ResultField::shape() +{ + std::shared_ptr aResult; + if (myOwnerData) { + AttributeSelectionListPtr aList = myOwnerData->selectionList("selected"); + if (aList) { + std::list > aSubs; + for(int a = aList->size() - 1; a >= 0; a--) { + std::shared_ptr aSelection = aList->value(a)->value(); + if (aSelection && !aSelection->isNull()) { + aSubs.push_back(aSelection); + } + } + if (!aSubs.empty()) { + aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs); + } + } + } + return aResult; +} diff --git a/src/Model/Model_ResultField.h b/src/Model/Model_ResultField.h new file mode 100644 index 000000000..b8954287e --- /dev/null +++ b/src/Model/Model_ResultField.h @@ -0,0 +1,41 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_ResultField.h +// Created: 16 Nov 2016 +// Author: Mikhail PONIKAROV + +#ifndef Model_ResultField_H_ +#define Model_ResultField_H_ + +#include "Model.h" +#include + +/**\class Model_ResultField + * \ingroup DataModel + * \brief The fields result. + * + * Provides a compound of selected elements, without storage, one the fly. + */ +class Model_ResultField : public ModelAPI_ResultField +{ + std::shared_ptr myOwnerData; ///< data of owner of this result +public: + + /// Retuns the parameters of color definition in the resources config manager + MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, + std::string& theDefault); + + /// Returns the compound of selected entities + MODEL_EXPORT virtual std::shared_ptr shape(); + + /// Removes the stored builders + MODEL_EXPORT virtual ~Model_ResultField() {} + +protected: + /// Makes a body on the given feature data + Model_ResultField(std::shared_ptr theOwnerData); + + friend class Model_Objects; +}; + +#endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 011828a4c..6fbe8f77e 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -38,6 +38,7 @@ SET(PROJECT_HEADERS ModelAPI_ResultBody.h ModelAPI_ResultCompSolid.h ModelAPI_ResultConstruction.h + ModelAPI_ResultField.h ModelAPI_ResultGroup.h ModelAPI_ResultParameter.h ModelAPI_ResultPart.h @@ -78,6 +79,7 @@ SET(PROJECT_SOURCES ModelAPI_ResultBody.cpp ModelAPI_ResultCompSolid.cpp ModelAPI_ResultConstruction.cpp + ModelAPI_ResultField.cpp ModelAPI_ResultGroup.cpp ModelAPI_ResultPart.cpp ModelAPI_ResultParameter.cpp diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index d4f81591a..b0cab6686 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -66,6 +66,7 @@ %shared_ptr(ModelAPI_ResultBody) %shared_ptr(ModelAPI_ResultPart) %shared_ptr(ModelAPI_ResultGroup) +%shared_ptr(ModelAPI_ResultField) %shared_ptr(ModelAPI_ResultParameter) %shared_ptr(ModelAPI_ResultCompSolid) @@ -102,6 +103,7 @@ %include "ModelAPI_ResultBody.h" %include "ModelAPI_ResultPart.h" %include "ModelAPI_ResultGroup.h" +%include "ModelAPI_ResultField.h" %include "ModelAPI_ResultParameter.h" %include "ModelAPI_Tools.h" %include "ModelAPI_ResultCompSolid.h" @@ -127,6 +129,7 @@ template std::shared_ptr shared_ptr_cast(std::shared_ptr %template(modelAPI_ResultPart) shared_ptr_cast; %template(modelAPI_ResultParameter) shared_ptr_cast; %template(modelAPI_ResultGroup) shared_ptr_cast; +%template(modelAPI_ResultField) shared_ptr_cast; %template(modelAPI_ResultCompSolid) shared_ptr_cast; // Attribute casts diff --git a/src/ModelAPI/ModelAPI_AttributeTables.h b/src/ModelAPI/ModelAPI_AttributeTables.h index 1fe3e9614..253489785 100644 --- a/src/ModelAPI/ModelAPI_AttributeTables.h +++ b/src/ModelAPI/ModelAPI_AttributeTables.h @@ -55,13 +55,13 @@ public: /// Defines the tyoe of values in the table. If it differs from the current, erases the content. MODELAPI_EXPORT virtual void setType(ValueType theType) = 0; /// Defines the tyoe of values in the table. If it differs from the current, erases the content. - MODELAPI_EXPORT virtual const ValueType& type(ValueType) const = 0; + MODELAPI_EXPORT virtual const ValueType& type() const = 0; /// Defines the value by the index in the tables set (indexes are zero-based). MODELAPI_EXPORT virtual void setValue( - const Value theValue, const int theRow, const int theColumn, const int theTable = 1) = 0; + const Value theValue, const int theRow, const int theColumn, const int theTable = 0) = 0; /// Returns the value by the index (indexes are zero-based). MODELAPI_EXPORT virtual Value value( - const int theRow, const int theColumn, const int theTable = 1) = 0; + const int theRow, const int theColumn, const int theTable = 0) = 0; /// Returns the type of this class of attributes MODELAPI_EXPORT static std::string typeId() diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 8e6f138ad..90b87621b 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -23,6 +23,7 @@ class ModelAPI_ResultConstruction; class ModelAPI_ResultBody; class ModelAPI_ResultPart; class ModelAPI_ResultGroup; +class ModelAPI_ResultField; class ModelAPI_ResultParameter; class ModelAPI_Data; class GeomAPI_Shape; @@ -140,6 +141,9 @@ public: //! Creates a group result virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; + //! Creates a field result + virtual std::shared_ptr createField( + const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; //! Creates a parameter result virtual std::shared_ptr createParameter( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; diff --git a/src/ModelAPI/ModelAPI_ResultField.cpp b/src/ModelAPI/ModelAPI_ResultField.cpp new file mode 100644 index 000000000..20fd5c454 --- /dev/null +++ b/src/ModelAPI/ModelAPI_ResultField.cpp @@ -0,0 +1,17 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_ResultField.cpp +// Created: 16 Nov 2016 +// Author: Mikhail PONIKAROV + +#include "ModelAPI_ResultField.h" + +ModelAPI_ResultField::~ModelAPI_ResultField() +{ + +} + +std::string ModelAPI_ResultField::groupName() +{ + return group(); +} diff --git a/src/ModelAPI/ModelAPI_ResultField.h b/src/ModelAPI/ModelAPI_ResultField.h new file mode 100644 index 000000000..65888b555 --- /dev/null +++ b/src/ModelAPI/ModelAPI_ResultField.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_ResultField.hxx +// Created: 16 Nov 2016 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_ResultField_H_ +#define ModelAPI_ResultField_H_ + +#include "ModelAPI_Result.h" +#include +#include +#include + +/**\class ModelAPI_ResultField + * \ingroup DataModel + * \brief The fields result. + * + * Provides a compound of selected elements, without storage, one the fly. + */ +class ModelAPI_ResultField : public ModelAPI_Result +{ +public: + MODELAPI_EXPORT virtual ~ModelAPI_ResultField(); + /// Returns the group identifier of this result + MODELAPI_EXPORT virtual std::string groupName(); + + /// Returns the group identifier of this result + inline static std::string group() + { + static std::string MY_GROUP = "Fields"; + return MY_GROUP; + } + + /// default color for a result body + inline static const std::string& DEFAULT_COLOR() + { + static const std::string RESULT_GROUP_COLOR("150,150,180"); + return RESULT_GROUP_COLOR; + } + +}; + +//! Pointer on feature object +typedef std::shared_ptr ResultFieldPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_swig.h b/src/ModelAPI/ModelAPI_swig.h index cfc4ce703..157cf66ee 100644 --- a/src/ModelAPI/ModelAPI_swig.h +++ b/src/ModelAPI/ModelAPI_swig.h @@ -43,6 +43,7 @@ #include "ModelAPI_ResultPart.h" #include "ModelAPI_ResultParameter.h" #include "ModelAPI_ResultGroup.h" + #include "ModelAPI_ResultField.h" #include "ModelAPI_Tools.h" #include "ModelAPI_ResultCompSolid.h" diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 9607e5fa2..76e151451 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -12,6 +12,7 @@ SET(PROJECT_HEADERS ModelHighAPI_RefAttr.h ModelHighAPI_Reference.h ModelHighAPI_Selection.h + ModelHighAPI_ComponentValue.h ModelHighAPI_Services.h ModelHighAPI_Tools.h ModelHighAPI_FeatureStore.h @@ -25,6 +26,7 @@ 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 2ad5dc461..0d2daf0f3 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -319,6 +319,7 @@ %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 new file mode 100644 index 000000000..9c2096854 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp @@ -0,0 +1,75 @@ +// 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 new file mode 100644 index 000000000..d7dd41cbf --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_ComponentValue.h @@ -0,0 +1,46 @@ +// 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 09338cc1c..1176de251 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -833,8 +834,22 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& theArray) +{ + myDumpBuffer<<"["; + for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) { + + myDumpBuffer<<"\""<value(anIndex)<<"\""; + if (anIndex != 0) + myDumpBuffer<<", "; + } + + myDumpBuffer<<"]"; + return *this; +} + /// Dump std::endl -MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, std::basic_ostream& (*theEndl)(std::basic_ostream&)) { diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index d12454861..ee432d271 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -35,6 +35,7 @@ class ModelAPI_AttributeRefList; class ModelAPI_AttributeSelection; class ModelAPI_AttributeSelectionList; class ModelAPI_AttributeString; +class ModelAPI_AttributeStringArray; class ModelAPI_CompositeFeature; class ModelAPI_Document; class ModelAPI_Entity; @@ -214,6 +215,9 @@ public: /// Dump AttributeReference MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theReference); + /// Dump AttributeStringArray + MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& + operator<<(const std::shared_ptr& theArray); /// Clear dump buffer MODELHIGHAPI_EXPORT diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.cpp b/src/ModelHighAPI/ModelHighAPI_Integer.cpp index 3742dc5fa..fc17205d6 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Integer.cpp @@ -43,3 +43,9 @@ void ModelHighAPI_Integer::fillAttribute( case VT_STRING: theAttribute->setText(myString); return; } } + +int ModelHighAPI_Integer::intValue() const +{ + // needed for array of integer, which supports no text + return myInt; +} diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.h b/src/ModelHighAPI/ModelHighAPI_Integer.h index 35fb0d77f..111e8fbf4 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.h +++ b/src/ModelHighAPI/ModelHighAPI_Integer.h @@ -25,7 +25,7 @@ class ModelHighAPI_Integer public: /// Constructor for int MODELHIGHAPI_EXPORT - ModelHighAPI_Integer(int theValue = 0.); + ModelHighAPI_Integer(int theValue = 0); /// Constructor for std::string MODELHIGHAPI_EXPORT ModelHighAPI_Integer(const std::string & theValue); @@ -40,6 +40,9 @@ public: MODELHIGHAPI_EXPORT virtual void fillAttribute(const std::shared_ptr & theAttribute) const; + /// Returns a value (must be used only for attributes which support no text) + MODELHIGHAPI_EXPORT virtual int intValue() const; + private: enum VariantType { VT_INT, VT_STRING } myVariantType; int myInt; diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 76b914b19..119a0a1eb 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -194,12 +195,36 @@ void fillAttribute(const std::string & theValue, { theAttribute->setValue(theValue); } + +//-------------------------------------------------------------------------------------- void fillAttribute(const char * theValue, const std::shared_ptr & theAttribute) { theAttribute->setValue(theValue); } +//-------------------------------------------------------------------------------------- +void fillAttribute(const std::list & theValue, + const std::shared_ptr & theAttribute) +{ + theAttribute->setSize(int(theValue.size())); + + int anIndex = 0; + for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex) + theAttribute->setValue(anIndex, *it); +} + +//-------------------------------------------------------------------------------------- +void fillAttribute(const std::list & theValue, + const std::shared_ptr & theAttribute) +{ + theAttribute->setSize(int(theValue.size())); + + int anIndex = 0; + for (auto it = theValue.begin(); it != theValue.end(); ++it, ++anIndex) + theAttribute->setValue(anIndex, it->intValue()); // use only values, no text support in array +} + //================================================================================================== GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr) { @@ -260,6 +285,32 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection return aShapeType; } +//-------------------------------------------------------------------------------------- +ModelAPI_AttributeTables::ValueType valueTypeByStr(const std::string& theValueTypeStr) +{ + std::string aType = theValueTypeStr; + std::transform(aType.begin(), aType.end(), aType.begin(), ::tolower); + if (aType == "boolean") + return ModelAPI_AttributeTables::BOOLEAN; + else if (aType == "integer") + return ModelAPI_AttributeTables::INTEGER; + else if (aType == "string") + return ModelAPI_AttributeTables::STRING; + return ModelAPI_AttributeTables::DOUBLE; // default +} + +//-------------------------------------------------------------------------------------- +std::string strByValueType(const ModelAPI_AttributeTables::ValueType theType) +{ + switch(theType) { + case ModelAPI_AttributeTables::BOOLEAN: return "BOOLEAN"; + case ModelAPI_AttributeTables::INTEGER: return "INTEGER"; + case ModelAPI_AttributeTables::DOUBLE: return "DOUBLE"; + case ModelAPI_AttributeTables::STRING: return "STRING"; + } + return ""; // bad case +} + /// stores the features information, recoursively stores sub-documetns features std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, std::map >& theStore, diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index 74198a3cf..fc59e5edc 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -10,6 +10,7 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI.h" +#include #include @@ -36,6 +37,7 @@ class ModelAPI_AttributeRefList; class ModelAPI_AttributeSelection; class ModelAPI_AttributeSelectionList; class ModelAPI_AttributeString; +class ModelAPI_AttributeStringArray; class ModelAPI_Object; //-------------------------------------------------------------------------------------- class ModelHighAPI_Double; @@ -124,12 +126,26 @@ MODELHIGHAPI_EXPORT void fillAttribute(const char * theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +void fillAttribute(const std::list & theValue, + const std::shared_ptr & theAttribute); + +MODELHIGHAPI_EXPORT +void fillAttribute(const std::list & theValue, + const std::shared_ptr & theAttribute); + MODELHIGHAPI_EXPORT GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr); MODELHIGHAPI_EXPORT GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection); +MODELHIGHAPI_EXPORT +ModelAPI_AttributeTables::ValueType valueTypeByStr(const std::string& theValueTypeStr); + +MODELHIGHAPI_EXPORT +std::string strByValueType(const ModelAPI_AttributeTables::ValueType theType); + /// Performs the high level API dump, then closes all and executes the script: /// model must be recreated fully, with all attributes /// \returns true if check is well done diff --git a/src/ModelHighAPI/ModelHighAPI_swig.h b/src/ModelHighAPI/ModelHighAPI_swig.h index c9230d49e..250b8f866 100644 --- a/src/ModelHighAPI/ModelHighAPI_swig.h +++ b/src/ModelHighAPI/ModelHighAPI_swig.h @@ -20,6 +20,7 @@ #include "ModelHighAPI_RefAttr.h" #include "ModelHighAPI_Reference.h" #include "ModelHighAPI_Selection.h" + #include "ModelHighAPI_ComponentValue.h" #include "ModelHighAPI_Services.h" #include "ModelHighAPI_Tools.h" -- 2.39.2