From: mpv Date: Tue, 15 Nov 2016 12:40:47 +0000 (+0300) Subject: Issue #1865 : initial implementation of the "Fields" feature and additional attribute... X-Git-Tag: V_2.6.0~88 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5f9a7eb3856371da8d52bc0b5665764abc928c7c;p=modules%2Fshaper.git Issue #1865 : initial implementation of the "Fields" feature and additional attributes for it. --- diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index c9acd7da1..081f5bc5e 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -7,11 +7,13 @@ SET(PROJECT_HEADERS CollectionPlugin.h CollectionPlugin_Plugin.h CollectionPlugin_Group.h + CollectionPlugin_Field.h ) SET(PROJECT_SOURCES CollectionPlugin_Plugin.cpp CollectionPlugin_Group.cpp + CollectionPlugin_Field.cpp ) SET(XML_RESOURCES diff --git a/src/CollectionPlugin/CollectionPlugin_Field.cpp b/src/CollectionPlugin/CollectionPlugin_Field.cpp new file mode 100644 index 000000000..d3ef250e3 --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_Field.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: CollectionPlugin_Field.cpp +// Created: 08 Oct 2014 +// Author: Sergey BELASH + +#include "CollectionPlugin_Field.h" + +#include +#include +#include +#include +#include +#include +#include + +CollectionPlugin_Field::CollectionPlugin_Field() +{ +} + +void CollectionPlugin_Field::initAttributes() +{ + data()->addAttribute(SELECTED_ID(), ModelAPI_AttributeSelectionList::typeId()); + data()->addAttribute(COMPONENTS_NB_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(COMPONENTS_NAMES_ID(), ModelAPI_AttributeStringArray::typeId()); + data()->addAttribute(VALUES_TYPE_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(STEPS_NB_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(STAMPS_ID(), ModelAPI_AttributeIntArray::typeId()); + data()->addAttribute(VALUES_ID(), ModelAPI_AttributeTables::typeId()); +} + +void CollectionPlugin_Field::execute() +{ + if (results().empty() || firstResult()->isDisabled()) { // just create result if not exists + //ResultPtr aField = document()->createField(data()); + //setResult(aField); + } +} diff --git a/src/CollectionPlugin/CollectionPlugin_Field.h b/src/CollectionPlugin/CollectionPlugin_Field.h new file mode 100644 index 000000000..162720f91 --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_Field.h @@ -0,0 +1,102 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: CollectionPlugin_Group.h +// Created: 14 Nov 2016 +// Author: Mikhail PONIKAROV + +#ifndef COLLECTIONPLUGIN_FIELD_H_ +#define COLLECTIONPLUGIN_FIELD_H_ + +#include "CollectionPlugin.h" +#include +#include + +/**\class CollectionPlugin_Field + * \ingroup Plugins + * \brief Feature for selection of sub-shapes of some shapes and assigning data on them. + * + * There is a set of containers that contains the following data that may be inserted by the user: + * + * Selected sub-shapes (like in Groups). + * Number of components for each selection. + * Components names + * Type of values: Boolean, Integer, Double or String. + * Number of steps: for each step (indexes are zero-based) the values below are multiplied. + * Stamp: integer identifier per each step + * Defaul values for each components + * Values for each component and each selected sub-shape: all are of specific type. + */ +class CollectionPlugin_Field : public ModelAPI_Feature +{ + public: + /// Extrusion kind + inline static const std::string& ID() + { + static const std::string MY_FIELD_ID("Field"); + return MY_FIELD_ID; + } + /// attribute name of selected entities list + inline static const std::string& SELECTED_ID() + { + static const std::string MY_SELECTED_ID("selected"); + return MY_SELECTED_ID; + } + /// attribute name of components number + inline static const std::string& COMPONENTS_NB_ID() + { + static const std::string MY_COMPONENTS_NB_ID("components_nb"); + return MY_COMPONENTS_NB_ID; + } + /// attribute name of componenets titles array + inline static const std::string& COMPONENTS_NAMES_ID() + { + static const std::string MY_COMPONENTS_NAMES_ID("components_names"); + return MY_COMPONENTS_NAMES_ID; + } + /// attribute name of values types integer identifier + inline static const std::string& VALUES_TYPE_ID() + { + static const std::string MY_VALUES_TYPE_ID("type"); + return MY_VALUES_TYPE_ID; + } + /// attribute name of number of steps + inline static const std::string& STEPS_NB_ID() + { + static const std::string MY_STEPS_NB_ID("steps_nb"); + return MY_STEPS_NB_ID; + } + /// attribute name of stamps integer array + inline static const std::string& STAMPS_ID() + { + static const std::string MY_STAMPS_ID("stamps"); + return MY_STAMPS_ID; + } + /// attribute name of list of tables that contain deafult values (row 0) and the custom values + inline static const std::string& VALUES_ID() + { + static const std::string MY_VALUES_ID("values"); + return MY_VALUES_ID; + } + + /// Returns the kind of a feature + COLLECTIONPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = CollectionPlugin_Field::ID(); + return MY_KIND; + } + + /// Creates a new field result if needed + COLLECTIONPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + COLLECTIONPLUGIN_EXPORT virtual void initAttributes(); + + /// Result of fields is created on the fly and don't stored to the document + COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} + + /// Use plugin manager for features creation + CollectionPlugin_Field(); + +}; + +#endif diff --git a/src/CollectionPlugin/CollectionPlugin_Group.h b/src/CollectionPlugin/CollectionPlugin_Group.h index b569ebfd6..81f503360 100644 --- a/src/CollectionPlugin/CollectionPlugin_Group.h +++ b/src/CollectionPlugin/CollectionPlugin_Group.h @@ -41,7 +41,7 @@ class CollectionPlugin_Group : public ModelAPI_Feature return MY_KIND; } - /// Creates a new part document if needed + /// Creates a new group result if needed COLLECTIONPLUGIN_EXPORT virtual void execute(); /// Request for initialization of data model of the feature: adding all attributes diff --git a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp index 87c0dda93..6732c4c73 100644 --- a/src/CollectionPlugin/CollectionPlugin_Plugin.cpp +++ b/src/CollectionPlugin/CollectionPlugin_Plugin.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -22,8 +23,11 @@ FeaturePtr CollectionPlugin_Plugin::createFeature(std::string theFeatureID) { if (theFeatureID == CollectionPlugin_Group::ID()) { return FeaturePtr(new CollectionPlugin_Group); + }else if (theFeatureID == CollectionPlugin_Field::ID()) { + return FeaturePtr(new CollectionPlugin_Field); } + // feature of such kind is not found return FeaturePtr(); } diff --git a/src/CollectionPlugin/CollectionPlugin_Plugin.h b/src/CollectionPlugin/CollectionPlugin_Plugin.h index 383fe5989..ebb3cb2c6 100644 --- a/src/CollectionPlugin/CollectionPlugin_Plugin.h +++ b/src/CollectionPlugin/CollectionPlugin_Plugin.h @@ -1,8 +1,8 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> // File: CollectionPlugin_Plugin.hxx -// Created: 07 July 2014 -// Author: Vitaly SMETANNIKOV +// Created: 14 Nov 2016 +// Author: Mikhail PONIKAROV #ifndef CollectionPlugin_Plugin_H_ #define CollectionPlugin_Plugin_H_ diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 8b7f5bf3a..d7f1441ed 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -19,9 +19,11 @@ SET(PROJECT_HEADERS Model_AttributeBoolean.h Model_AttributeIntArray.h Model_AttributeString.h + Model_AttributeStringArray.h Model_AttributeInteger.h Model_AttributeSelection.h Model_AttributeSelectionList.h + Model_AttributeTables.h Model_BodyBuilder.h Model_Events.h Model_Expression.h @@ -54,9 +56,11 @@ SET(PROJECT_SOURCES Model_AttributeBoolean.cpp Model_AttributeIntArray.cpp Model_AttributeString.cpp + Model_AttributeStringArray.cpp Model_AttributeInteger.cpp Model_AttributeSelection.cpp Model_AttributeSelectionList.cpp + Model_AttributeTables.cpp Model_BodyBuilder.cpp Model_Events.cpp Model_Expression.cpp diff --git a/src/Model/Model_AttributeStringArray.cpp b/src/Model/Model_AttributeStringArray.cpp new file mode 100644 index 000000000..82f35c511 --- /dev/null +++ b/src/Model/Model_AttributeStringArray.cpp @@ -0,0 +1,76 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_AttributeStringArray.cpp +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#include "Model_AttributeStringArray.h" + +#include +#include + +#include + +//================================================================================================== +int Model_AttributeStringArray::size() +{ + if (myArray.IsNull() || !myArray->IsValid()) { + // this could be on undo and then redo creation of the attribute + // in result creation it may be uninitialized + myIsInitialized = + myLab.FindAttribute(TDataStd_ExtStringArray::GetID(), myArray) == Standard_True; + } + // checking the validity because attribute (as a field) may be presented, + // but without label: it is undoed + return (myArray.IsNull() || !myArray->IsValid()) ? 0 : myArray->Length(); +} + +//================================================================================================== +void Model_AttributeStringArray::setSize(const int theSize) +{ + if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet + if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array) + myArray = TDataStd_ExtStringArray::Set(myLab, 0, theSize - 1); + owner()->data()->sendAttributeUpdated(this); + } + } else { // reset the old array + if (theSize) { + if (theSize != myArray->Length()) { // old data is not keept, a new array is created + Handle(TColStd_HArray1OfExtendedString) aNewArray = + new TColStd_HArray1OfExtendedString(0, theSize - 1); + myArray->ChangeArray(aNewArray); + owner()->data()->sendAttributeUpdated(this); + } + } else { // size is zero => array must be erased + if (!myArray.IsNull()) { + myArray.Nullify(); + myLab.ForgetAttribute(TDataStd_ExtStringArray::GetID()); + owner()->data()->sendAttributeUpdated(this); + } + } + } +} + +//================================================================================================== +void Model_AttributeStringArray::setValue(const int theIndex, + const std::string theValue) +{ + if (!myArray->Value(theIndex).IsEqual(theValue.c_str())) { + myArray->SetValue(theIndex, theValue.c_str()); + owner()->data()->sendAttributeUpdated(this); + } +} + +//================================================================================================== +std::string Model_AttributeStringArray::value(const int theIndex) +{ + return TCollection_AsciiString(myArray->Value(theIndex)).ToCString(); +} + +//================================================================================================== +Model_AttributeStringArray::Model_AttributeStringArray(TDF_Label& theLabel) +{ + myLab = theLabel; + myIsInitialized = + myLab.FindAttribute(TDataStd_ExtStringArray::GetID(), myArray) == Standard_True; +} diff --git a/src/Model/Model_AttributeStringArray.h b/src/Model/Model_AttributeStringArray.h new file mode 100644 index 000000000..5d8132cb4 --- /dev/null +++ b/src/Model/Model_AttributeStringArray.h @@ -0,0 +1,48 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_AttributeStringArray.h +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#ifndef Model_AttributeStringArray_H_ +#define Model_AttributeStringArray_H_ + +#include +#include +#include +#include + +/// \class Model_AttributeStringArray +/// \ingroup DataModel +/// \brief API for the attribute that contains several strings in the array inside. +class Model_AttributeStringArray: public ModelAPI_AttributeStringArray +{ +public: + /// Returns the size of the array (zero means that it is empty) + MODEL_EXPORT virtual int size(); + + /// Sets the new size of the array. The previous data is erased. + MODEL_EXPORT virtual void setSize(const int theSize); + + /// Defines the value of the array by index [0; size-1] + MODEL_EXPORT virtual void setValue(const int theIndex, + const std::string theValue); + + /// Returns the value by the index + MODEL_EXPORT virtual std::string value(const int theIndex); + +protected: + /// Objects are created for features automatically + MODEL_EXPORT Model_AttributeStringArray(TDF_Label& theLabel); + +private: + /// The OCCT array that keeps all values. + Handle_TDataStd_ExtStringArray myArray; + + /// Stores the label as a field to set array if size is not null (null array is buggy in OCAF) + TDF_Label myLab; + + friend class Model_Data; +}; + +#endif diff --git a/src/Model/Model_AttributeTables.cpp b/src/Model/Model_AttributeTables.cpp new file mode 100644 index 000000000..b6c2c4e8c --- /dev/null +++ b/src/Model/Model_AttributeTables.cpp @@ -0,0 +1,256 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_AttributeTables.cpp +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#include "Model_AttributeTables.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +// returns the array attribute GUID for the given type +#define MY_ARRAY_ID(type) \ +((type) == ModelAPI_AttributeTables::DOUBLE ? TDataStd_RealArray::GetID(): \ +((type) == ModelAPI_AttributeTables::BOOLEAN ? TDataStd_BooleanArray::GetID(): \ +((type) == ModelAPI_AttributeTables::INTEGER? TDataStd_IntegerArray::GetID(): \ +TDataStd_ExtStringArray::GetID()))) + +int Model_AttributeTables::rows() +{ + return myRows; +} + +int Model_AttributeTables::columns() +{ + return myCols; +} + +int Model_AttributeTables::tables() +{ + return myTables; +} + +void Model_AttributeTables::setSize(const int theRows, const int theColumns, const int theTables) +{ + if (theRows != myRows || theColumns != myCols || theTables != myTables) { + owner()->data()->sendAttributeUpdated(this); + int aSize = myRows * myCols * myTables; + int aNewSize = theRows * theColumns * theTables; + if (aSize == 0 && aNewSize == 0) { + // nothing to do + } else if (aNewSize == 0) { + // remove old array + myLab.ForgetAttribute(MY_ARRAY_ID(myType)); + } else { + // prepare new arrays + Handle(TColStd_HArray1OfReal) anOldDouble, aNewDouble = + (myType == ModelAPI_AttributeTables::DOUBLE) ? + new TColStd_HArray1OfReal(0, aNewSize - 1) : Handle(TColStd_HArray1OfReal)(); + Handle(TColStd_HArray1OfByte) anOldBool, aNewBool = + (myType == ModelAPI_AttributeTables::BOOLEAN) ? + new TColStd_HArray1OfByte(0, aNewSize - 1) : Handle(TColStd_HArray1OfByte)(); + Handle(TColStd_HArray1OfInteger) anOldInt, aNewInt = + (myType == ModelAPI_AttributeTables::INTEGER) ? + new TColStd_HArray1OfInteger(0, aNewSize - 1) : Handle(TColStd_HArray1OfInteger)(); + Handle(TColStd_HArray1OfExtendedString) anOldStr, aNewStr = + (myType == ModelAPI_AttributeTables::STRING) ? + new TColStd_HArray1OfExtendedString(0, aNewSize - 1) : + Handle(TColStd_HArray1OfExtendedString)(); + if (aSize != 0) { // copy the previous values into new positions, otherwise default values + Handle(TDF_Attribute) anArray; + myLab.FindAttribute(MY_ARRAY_ID(myType), anArray); + switch(myType) { + case ModelAPI_AttributeTables::DOUBLE: + anOldDouble = Handle(TDataStd_RealArray)::DownCast(anArray)->Array(); + break; + case ModelAPI_AttributeTables::BOOLEAN: + anOldBool = Handle(TDataStd_BooleanArray)::DownCast(anArray)->InternalArray(); + break; + case ModelAPI_AttributeTables::INTEGER: + anOldInt = Handle(TDataStd_IntegerArray)::DownCast(anArray)->Array(); + break; + case ModelAPI_AttributeTables::STRING: + anOldStr = Handle(TDataStd_ExtStringArray)::DownCast(anArray)->Array(); + break; + } + } + for(int aTable = 0; aTable < theTables; aTable++) { + for(int aColumn = 0; aColumn < theColumns; aColumn++) { + for(int aRow = 0; aRow < theRows; aRow++) { + int anOldIndex, anIndex = aTable * theRows * theColumns + aRow * theColumns + aColumn; + bool aRestore = aTable < myTables && aColumn < myCols && aRow < myRows; + if (aRestore) + anOldIndex = aTable * myRows * myCols + aRow * myCols + aColumn; + switch(myType) { + case ModelAPI_AttributeTables::DOUBLE: { + aNewDouble->SetValue(anIndex, aRestore ? anOldDouble->Value(anOldIndex) : 0.); + break; + } + case ModelAPI_AttributeTables::BOOLEAN: { + aNewBool->SetValue(anIndex, aRestore ? anOldBool->Value(anOldIndex) : Standard_False); + break; + } + case ModelAPI_AttributeTables::INTEGER: { + aNewInt->SetValue(anIndex, aRestore ? anOldInt->Value(anOldIndex) : 0); + break; + } + case ModelAPI_AttributeTables::STRING: { + aNewStr->SetValue(anIndex, aRestore ? anOldStr->Value(anOldIndex) : ""); + break; + } + } + } + } + } + // store the new array + switch(myType) { + case ModelAPI_AttributeTables::DOUBLE: + TDataStd_RealArray::Set(myLab, 0, aNewSize - 1)->ChangeArray(aNewDouble); + break; + case ModelAPI_AttributeTables::BOOLEAN: + TDataStd_BooleanArray::Set(myLab, 0, aNewSize - 1)->SetInternalArray(aNewBool); + break; + case ModelAPI_AttributeTables::INTEGER: + TDataStd_IntegerArray::Set(myLab, 0, aNewSize - 1)->ChangeArray(aNewInt); + break; + case ModelAPI_AttributeTables::STRING: + TDataStd_ExtStringArray::Set(myLab, 0, aNewSize - 1)->ChangeArray(aNewStr); + break; + } + } + // store the new sizes + myRows = theRows; + myCols = theColumns; + myTables = theTables; + myProp->Clear(); + myProp->Append(int(myType)); // default + myProp->Append(myTables); + myProp->Append(myRows); + myProp->Append(myCols); + owner()->data()->sendAttributeUpdated(this); + } +} + +void Model_AttributeTables::setType(ModelAPI_AttributeTables::ValueType theType) +{ + if (myType != theType) { + // remove the old attr + int aSize = myRows * myCols * myTables; + if (aSize != 0) { + myLab.ForgetAttribute(MY_ARRAY_ID(theType)); + myType = theType; + int aTables = myTables; + myTables = 0; // to let setSize know that there is no old array + setSize(myRows, myCols, myTables); + } else { + myType = theType; + owner()->data()->sendAttributeUpdated(this); + } + } +} + +const ModelAPI_AttributeTables::ValueType& Model_AttributeTables::type(ValueType) const +{ + return myType; +} + +void Model_AttributeTables::setValue(const ModelAPI_AttributeTables::Value theValue, + const int theRow, const int theColumn, const int theTable) +{ + int anIndex = theTable * myRows * myCols + theRow * myCols + theColumn; + Handle(TDF_Attribute) anArray; + myLab.FindAttribute(MY_ARRAY_ID(myType), anArray); + switch(myType) { + case ModelAPI_AttributeTables::DOUBLE: { + Handle(TDataStd_RealArray)::DownCast(anArray)->SetValue(anIndex, theValue.myDouble); + break; + } + case ModelAPI_AttributeTables::BOOLEAN: { + Handle(TDataStd_BooleanArray)::DownCast(anArray)->SetValue(anIndex, theValue.myBool); + break; + } + case ModelAPI_AttributeTables::INTEGER: { + Handle(TDataStd_IntegerArray)::DownCast(anArray)->SetValue(anIndex, theValue.myInt); + break; + } + case ModelAPI_AttributeTables::STRING: { + Handle(TDataStd_ExtStringArray)::DownCast(anArray)->SetValue(anIndex, theValue.myStr.c_str()); + break; + } + } + owner()->data()->sendAttributeUpdated(this); +} + +ModelAPI_AttributeTables::Value Model_AttributeTables::value( + const int theRow, const int theColumn, const int theTable) +{ + ModelAPI_AttributeTables::Value aResult; + int anIndex = theTable * myRows * myCols + theRow * myCols + theColumn; + Handle(TDF_Attribute) anArray; + myLab.FindAttribute(MY_ARRAY_ID(myType), anArray); + switch(myType) { + case ModelAPI_AttributeTables::DOUBLE: { + aResult.myDouble = Handle(TDataStd_RealArray)::DownCast(anArray)->Value(anIndex); + break; + } + case ModelAPI_AttributeTables::BOOLEAN: { + aResult.myBool = Handle(TDataStd_BooleanArray)::DownCast(anArray)->Value(anIndex) == + Standard_True; + break; + } + case ModelAPI_AttributeTables::INTEGER: { + aResult.myInt = Handle(TDataStd_IntegerArray)::DownCast(anArray)->Value(anIndex); + break; + } + case ModelAPI_AttributeTables::STRING: { + aResult.myStr = TCollection_AsciiString(Handle(TDataStd_ExtStringArray)::DownCast(anArray)-> + Value(anIndex)).ToCString(); + break; + } + } + return aResult; +} + + +//================================================================================================== +Model_AttributeTables::Model_AttributeTables(TDF_Label& theLabel) +{ + myLab = theLabel; + reinit(); +} + +void Model_AttributeTables::reinit() +{ + // check the attribute could be already presented in this doc (after load document) + myIsInitialized = + myLab.FindAttribute(TDataStd_IntegerList::GetID(), myProp) == Standard_True; + if (!myIsInitialized) { + myProp = TDataStd_IntegerList::Set(myLab); + myProp->Append(int(Model_AttributeTables::DOUBLE)); // default + myProp->Append(0); + myProp->Append(0); + myProp->Append(0); + } + TColStd_ListIteratorOfListOfInteger aListIter(myProp->List()); + myType = ModelAPI_AttributeTables::ValueType(aListIter.Value()); + aListIter.Next(); + myTables = aListIter.Value(); + aListIter.Next(); + myRows = aListIter.Value(); + aListIter.Next(); + myCols = aListIter.Value(); +} diff --git a/src/Model/Model_AttributeTables.h b/src/Model/Model_AttributeTables.h new file mode 100644 index 000000000..311b94751 --- /dev/null +++ b/src/Model/Model_AttributeTables.h @@ -0,0 +1,81 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_AttributeTables.h +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#ifndef Model_AttributeTables_H_ +#define Model_AttributeTables_H_ + +#include "Model.h" + +#include + +#include +#include + +#include + +/// \class Model_AttributeTables +/// \ingroup DataModel +/// \brief API for the attribute that contains tables of some values type. +/// +/// The type of values can be changed. But all the values in the tables must have the same one +/// type. The currently allowed types now are: Boolean, Integer, Double, String. +/// By default there is only one table, but it may be increased/decreased by adding/removing +/// tables one by one. +/// The number of rows and columns are equal in all tables. If table, row or column is added, +/// the previous values are kept unchanged. New cells are filled by zero, false or empty strings. +class Model_AttributeTables: public ModelAPI_AttributeTables +{ +public: + /// Returns the number of rows in the table + MODEL_EXPORT virtual int rows(); + /// Returns the number of columns in the table + MODEL_EXPORT virtual int columns(); + /// Returns the number of tables + MODEL_EXPORT virtual int tables(); + + /// Sets the new size of the tables set. This method tries to keep old values if number of + /// rows, columns or tables is increased. + MODEL_EXPORT virtual void setSize( + const int theRows, const int theColumns, const int theTables = 1); + + /// 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; + /// 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); + /// Returns the value by the index (indexes are zero-based). + MODEL_EXPORT virtual Value value( + const int theRow, const int theColumn, const int theTable = 0); + +protected: + /// Objects are created for features automatically + MODEL_EXPORT Model_AttributeTables(TDF_Label& theLabel); + /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc) + virtual void reinit(); + +private: + /// The OCCT array that keeps all values. Indexes are computed as: + /// TableNum * NbRows * NbColumns + RowNum * NbColumns + ColNum + //Handle_TDF_Attribute myArray; + + /// Container that stores properties of the tables set: type, nbtables, nbrows, nbcolumns + /// If sizes are zero, myArray IsNull and vice-versa + Handle_TDataStd_IntegerList myProp; + + /// cashed main properties + int myTables, myRows, myCols; + /// cashed main properties + ModelAPI_AttributeTables::ValueType myType; + + /// Stores the label as a field + TDF_Label myLab; + + friend class Model_Data; +}; + +#endif diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index ce5ab2f90..4cfc34a59 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -15,9 +15,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -133,6 +135,8 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin anAttr = new Model_AttributeBoolean(anAttrLab); } else if (theAttrType == Model_AttributeString::typeId()) { anAttr = new Model_AttributeString(anAttrLab); + } else if (theAttrType == Model_AttributeStringArray::typeId()) { + anAttr = new Model_AttributeStringArray(anAttrLab); } else if (theAttrType == ModelAPI_AttributeReference::typeId()) { anAttr = new Model_AttributeReference(anAttrLab); } else if (theAttrType == ModelAPI_AttributeSelection::typeId()) { @@ -149,6 +153,8 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin anAttr = new Model_AttributeIntArray(anAttrLab); } else if (theAttrType == ModelAPI_AttributeDoubleArray::typeId()) { anAttr = new Model_AttributeDoubleArray(anAttrLab); + } else if (theAttrType == ModelAPI_AttributeTables::typeId()) { + anAttr = new Model_AttributeTables(anAttrLab); } // create also GeomData attributes here because only here the OCAF structure is known else if (theAttrType == GeomData_Point::typeId()) { @@ -203,6 +209,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string); +GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeStringArray, stringArray); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList); @@ -211,6 +218,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttrList, refattrlist); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray); GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray); +GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeTables, tables); std::shared_ptr Model_Data::attribute(const std::string& theID) { diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index f78f2d263..30b7b3486 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,12 @@ class Model_Data : public ModelAPI_Data /// Returns the attribute that contains integer values array MODEL_EXPORT virtual std::shared_ptr intArray(const std::string& theID); + /// Returns the attribute that contains string values array + MODEL_EXPORT virtual std::shared_ptr + stringArray(const std::string& theID); + /// Returns the attribute that contains string values array + MODEL_EXPORT virtual std::shared_ptr + tables(const std::string& theID); /// Returns the generic attribute by identifier /// \param theID identifier of the attribute diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index d0890d819..011828a4c 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -21,6 +21,8 @@ SET(PROJECT_HEADERS ModelAPI_AttributeSelection.h ModelAPI_AttributeSelectionList.h ModelAPI_AttributeString.h + ModelAPI_AttributeStringArray.h + ModelAPI_AttributeTables.h ModelAPI_AttributeValidator.h ModelAPI_BodyBuilder.h ModelAPI_CompositeFeature.h @@ -60,6 +62,8 @@ SET(PROJECT_SOURCES ModelAPI_AttributeSelection.cpp ModelAPI_AttributeSelectionList.cpp ModelAPI_AttributeString.cpp + ModelAPI_AttributeStringArray.cpp + ModelAPI_AttributeTables.cpp ModelAPI_BodyBuilder.cpp ModelAPI_CompositeFeature.cpp ModelAPI_Data.cpp diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 23c6d8043..d4f81591a 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -49,6 +49,7 @@ %shared_ptr(ModelAPI_AttributeInteger) %shared_ptr(ModelAPI_AttributeIntArray) %shared_ptr(ModelAPI_AttributeString) +%shared_ptr(ModelAPI_AttributeStringArray) %shared_ptr(ModelAPI_AttributeReference) %shared_ptr(ModelAPI_AttributeRefAttr) %shared_ptr(ModelAPI_AttributeRefList) @@ -56,6 +57,7 @@ %shared_ptr(ModelAPI_AttributeBoolean) %shared_ptr(ModelAPI_AttributeSelection) %shared_ptr(ModelAPI_AttributeSelectionList) +%shared_ptr(ModelAPI_AttributeTables) %shared_ptr(ModelAPI_Validator) %shared_ptr(ModelAPI_AttributeValidator) %shared_ptr(ModelAPI_FeatureValidator) @@ -83,6 +85,7 @@ %include "ModelAPI_AttributeInteger.h" %include "ModelAPI_AttributeIntArray.h" %include "ModelAPI_AttributeString.h" +%include "ModelAPI_AttributeStringArray.h" %include "ModelAPI_AttributeReference.h" %include "ModelAPI_AttributeRefAttr.h" %include "ModelAPI_AttributeBoolean.h" @@ -90,6 +93,7 @@ %include "ModelAPI_AttributeSelectionList.h" %include "ModelAPI_AttributeRefList.h" %include "ModelAPI_AttributeRefAttrList.h" +%include "ModelAPI_AttributeTables.h" %include "ModelAPI_Validator.h" %include "ModelAPI_AttributeValidator.h" %include "ModelAPI_FeatureValidator.h" @@ -132,6 +136,7 @@ template std::shared_ptr shared_ptr_cast(std::shared_ptr %template(modelAPI_AttributeInteger) shared_ptr_cast; %template(modelAPI_AttributeIntArray) shared_ptr_cast; %template(modelAPI_AttributeString) shared_ptr_cast; +%template(modelAPI_AttributeStringArray) shared_ptr_cast; %template(modelAPI_AttributeReference) shared_ptr_cast; %template(modelAPI_AttributeRefAttr) shared_ptr_cast; %template(modelAPI_AttributeBoolean) shared_ptr_cast; @@ -139,3 +144,4 @@ template std::shared_ptr shared_ptr_cast(std::shared_ptr %template(modelAPI_AttributeSelectionList) shared_ptr_cast; %template(modelAPI_AttributeRefList) shared_ptr_cast; %template(modelAPI_AttributeRefAttrList) shared_ptr_cast; +%template(modelAPI_AttributeTables) shared_ptr_cast; diff --git a/src/ModelAPI/ModelAPI_AttributeStringArray.cpp b/src/ModelAPI/ModelAPI_AttributeStringArray.cpp new file mode 100644 index 000000000..b6b64e564 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeStringArray.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_AttributeStringArray.cpp +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#include "ModelAPI_AttributeStringArray.h" + +//================================================================================================== +std::string ModelAPI_AttributeStringArray::attributeType() +{ + return typeId(); +} + +//================================================================================================== +ModelAPI_AttributeStringArray::~ModelAPI_AttributeStringArray() +{ +} + +//================================================================================================== +ModelAPI_AttributeStringArray::ModelAPI_AttributeStringArray() +{ +} diff --git a/src/ModelAPI/ModelAPI_AttributeStringArray.h b/src/ModelAPI/ModelAPI_AttributeStringArray.h new file mode 100644 index 000000000..5598ae355 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeStringArray.h @@ -0,0 +1,54 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_AttributeStringArray.h +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#ifndef ModelAPI_AttributeStringArray_H_ +#define ModelAPI_AttributeStringArray_H_ + +#include +#include + +#include + +/// \class ModelAPI_AttributeStringArray +/// \ingroup DataModel +/// \brief API for the attribute that contains several strings in the array inside. +class ModelAPI_AttributeStringArray: public ModelAPI_Attribute +{ +public: + /// Returns the size of the array (zero means that it is empty) + MODELAPI_EXPORT virtual int size() = 0; + + /// Sets the new size of the array. The previous data is erased. + MODELAPI_EXPORT virtual void setSize(const int theSize) = 0; + + /// Defines the value of the array by index [0; size-1] + MODELAPI_EXPORT virtual void setValue(const int theIndex, + const std::string theValue) = 0; + + /// Returns the value by the index + MODELAPI_EXPORT virtual std::string value(const int theIndex) = 0; + + /// Returns the type of this class of attributes + MODELAPI_EXPORT static std::string typeId() + { + return "StringArray"; + } + + /// Returns the type of this class of attributes, not static method + MODELAPI_EXPORT virtual std::string attributeType(); + + /// To virtually destroy the fields of successors + MODELAPI_EXPORT virtual ~ModelAPI_AttributeStringArray(); + +protected: + /// Objects are created for features automatically + MODELAPI_EXPORT ModelAPI_AttributeStringArray(); +}; + +/// Pointer on string attribute +typedef std::shared_ptr AttributeStringArrayPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_AttributeTables.cpp b/src/ModelAPI/ModelAPI_AttributeTables.cpp new file mode 100644 index 000000000..b581f8d05 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeTables.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_AttributeStringArray.cpp +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#include "ModelAPI_AttributeTables.h" + +//================================================================================================== +std::string ModelAPI_AttributeTables::attributeType() +{ + return typeId(); +} + +//================================================================================================== +ModelAPI_AttributeTables::~ModelAPI_AttributeTables() +{ +} + +//================================================================================================== +ModelAPI_AttributeTables::ModelAPI_AttributeTables() +{ +} diff --git a/src/ModelAPI/ModelAPI_AttributeTables.h b/src/ModelAPI/ModelAPI_AttributeTables.h new file mode 100644 index 000000000..1fe3e9614 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeTables.h @@ -0,0 +1,84 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModelAPI_AttributeTables.h +// Created: 14 Nov 2016 +// Author: Mikhail Ponikarov + +#ifndef ModelAPI_AttributeTables_H_ +#define ModelAPI_AttributeTables_H_ + +#include +#include + +#include + +/// \class ModelAPI_AttributeTables +/// \ingroup DataModel +/// \brief API for the attribute that contains tables of some values type. +/// +/// The type of values can be changed. But all the values in the tables must have the same one +/// type. The currently allowed types now are: Boolean, Integer, Double, String. +/// By default there is only one table, but it may be increased/decreased by adding/removing +/// tables one by one. +/// The number of rows and columns are equal in all tables. If table, row or column is added, +/// the previous values are kept unchanged. New cells are filled by zero, false or empty strings. +class ModelAPI_AttributeTables: public ModelAPI_Attribute +{ +public: + /// Type of the value in the table + enum ValueType { + BOOLEAN, + INTEGER, + DOUBLE, + STRING + }; + + struct Value { + bool myBool; + int myInt; + double myDouble; + std::string myStr; + }; + + /// Returns the number of rows in the table + MODELAPI_EXPORT virtual int rows() = 0; + /// Returns the number of columns in the table + MODELAPI_EXPORT virtual int columns() = 0; + /// Returns the number of tables + MODELAPI_EXPORT virtual int tables() = 0; + + /// Sets the new size of the tables set. This method tries to keep old values if number of + /// rows, columns or tables is increased. + MODELAPI_EXPORT virtual void setSize( + const int theRows, const int theColumns, const int theTables = 1) = 0; + + /// 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; + /// 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; + /// 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; + + /// Returns the type of this class of attributes + MODELAPI_EXPORT static std::string typeId() + { + return "Tables"; + } + /// Returns the type of this class of attributes, not static method + MODELAPI_EXPORT virtual std::string attributeType(); + /// To virtually destroy the fields of successors + MODELAPI_EXPORT virtual ~ModelAPI_AttributeTables(); + +protected: + /// Objects are created for features automatically + MODELAPI_EXPORT ModelAPI_AttributeTables(); +}; + +/// Pointer on double attribute +typedef std::shared_ptr AttributeTablesPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index b5ee9cadd..da5161421 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -28,12 +28,14 @@ class ModelAPI_AttributeRefList; class ModelAPI_AttributeRefAttrList; class ModelAPI_AttributeBoolean; class ModelAPI_AttributeString; +class ModelAPI_AttributeStringArray; class ModelAPI_Document; class ModelAPI_Attribute; class ModelAPI_Feature; class ModelAPI_AttributeSelection; class ModelAPI_AttributeSelectionList; class ModelAPI_AttributeIntArray; +class ModelAPI_AttributeTables; class ModelAPI_Object; class GeomAPI_Shape; @@ -90,6 +92,10 @@ class MODELAPI_EXPORT ModelAPI_Data virtual std::shared_ptr string(const std::string& theID) = 0; /// Returns the attribute that contains integer values array virtual std::shared_ptr intArray(const std::string& theID) = 0; + /// Returns the attribute that contains string values array + virtual std::shared_ptr stringArray(const std::string& theID) = 0; + /// Returns the attribute that contains tables + virtual std::shared_ptr tables(const std::string& theID) = 0; /// Returns the generic attribute by identifier /// \param theID identifier of the attribute diff --git a/src/ModelAPI/ModelAPI_swig.h b/src/ModelAPI/ModelAPI_swig.h index ec816d77c..cfc4ce703 100644 --- a/src/ModelAPI/ModelAPI_swig.h +++ b/src/ModelAPI/ModelAPI_swig.h @@ -25,10 +25,12 @@ #include "ModelAPI_AttributeInteger.h" #include "ModelAPI_AttributeIntArray.h" #include "ModelAPI_AttributeString.h" + #include "ModelAPI_AttributeStringArray.h" #include "ModelAPI_AttributeReference.h" #include "ModelAPI_AttributeRefAttr.h" #include "ModelAPI_AttributeSelection.h" #include "ModelAPI_AttributeSelectionList.h" + #include "ModelAPI_AttributeTables.h" #include "ModelAPI_AttributeValidator.h" #include "ModelAPI_Validator.h" #include "ModelAPI_FeatureValidator.h"