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
--- /dev/null
+// 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 <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeStringArray.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeTables.h>
+
+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);
+ }
+}
--- /dev/null
+// 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 <ModelAPI_Feature.h>
+#include <GeomAPI_Shape.h>
+
+/**\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
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
#include <CollectionPlugin_Plugin.h>
#include <CollectionPlugin_Group.h>
+#include <CollectionPlugin_Field.h>
#include <ModelAPI_Session.h>
#include <string>
{
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();
}
// 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_
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
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
--- /dev/null
+// 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 <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <TColStd_HArray1OfExtendedString.hxx>
+
+//==================================================================================================
+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;
+}
--- /dev/null
+// 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 <Model.h>
+#include <ModelAPI_AttributeStringArray.h>
+#include <TDataStd_ExtStringArray.hxx>
+#include <TDF_Label.hxx>
+
+/// \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
--- /dev/null
+// 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 <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TDataStd_RealArray.hxx>
+#include <TDataStd_BooleanArray.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_ExtStringArray.hxx>
+
+#include <TColStd_HArray1OfReal.hxx>
+#include <TColStd_HArray1OfByte.hxx>
+#include <TColStd_HArray1OfInteger.hxx>
+#include <TColStd_HArray1OfExtendedString.hxx>
+
+#include <string>
+
+// 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();
+}
--- /dev/null
+// 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 <ModelAPI_AttributeTables.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_IntegerList.hxx>
+
+#include <string>
+
+/// \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
#include <Model_AttributeRefAttrList.h>
#include <Model_AttributeBoolean.h>
#include <Model_AttributeString.h>
+#include <Model_AttributeStringArray.h>
#include <Model_AttributeSelection.h>
#include <Model_AttributeSelectionList.h>
#include <Model_AttributeIntArray.h>
+#include <Model_AttributeTables.h>
#include <Model_Events.h>
#include <Model_Expression.h>
#include <ModelAPI_Feature.h>
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()) {
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()) {
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);
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<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
{
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeRefAttrList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
/// Returns the attribute that contains integer values array
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
intArray(const std::string& theID);
+ /// Returns the attribute that contains string values array
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeStringArray>
+ stringArray(const std::string& theID);
+ /// Returns the attribute that contains string values array
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeTables>
+ tables(const std::string& theID);
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
ModelAPI_AttributeSelection.h
ModelAPI_AttributeSelectionList.h
ModelAPI_AttributeString.h
+ ModelAPI_AttributeStringArray.h
+ ModelAPI_AttributeTables.h
ModelAPI_AttributeValidator.h
ModelAPI_BodyBuilder.h
ModelAPI_CompositeFeature.h
ModelAPI_AttributeSelection.cpp
ModelAPI_AttributeSelectionList.cpp
ModelAPI_AttributeString.cpp
+ ModelAPI_AttributeStringArray.cpp
+ ModelAPI_AttributeTables.cpp
ModelAPI_BodyBuilder.cpp
ModelAPI_CompositeFeature.cpp
ModelAPI_Data.cpp
%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)
%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)
%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"
%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"
%template(modelAPI_AttributeInteger) shared_ptr_cast<ModelAPI_AttributeInteger, ModelAPI_Attribute>;
%template(modelAPI_AttributeIntArray) shared_ptr_cast<ModelAPI_AttributeIntArray, ModelAPI_Attribute>;
%template(modelAPI_AttributeString) shared_ptr_cast<ModelAPI_AttributeString, ModelAPI_Attribute>;
+%template(modelAPI_AttributeStringArray) shared_ptr_cast<ModelAPI_AttributeStringArray, ModelAPI_Attribute>;
%template(modelAPI_AttributeReference) shared_ptr_cast<ModelAPI_AttributeReference, ModelAPI_Attribute>;
%template(modelAPI_AttributeRefAttr) shared_ptr_cast<ModelAPI_AttributeRefAttr, ModelAPI_Attribute>;
%template(modelAPI_AttributeBoolean) shared_ptr_cast<ModelAPI_AttributeBoolean, ModelAPI_Attribute>;
%template(modelAPI_AttributeSelectionList) shared_ptr_cast<ModelAPI_AttributeSelectionList, ModelAPI_Attribute>;
%template(modelAPI_AttributeRefList) shared_ptr_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
%template(modelAPI_AttributeRefAttrList) shared_ptr_cast<ModelAPI_AttributeRefAttrList, ModelAPI_Attribute>;
+%template(modelAPI_AttributeTables) shared_ptr_cast<ModelAPI_AttributeTables, ModelAPI_Attribute>;
--- /dev/null
+// 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()
+{
+}
--- /dev/null
+// 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 <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+/// \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<ModelAPI_AttributeStringArray> AttributeStringArrayPtr;
+
+#endif
--- /dev/null
+// 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()
+{
+}
--- /dev/null
+// 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 <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+/// \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<ModelAPI_AttributeTables> AttributeTablesPtr;
+
+#endif
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;
virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
/// Returns the attribute that contains integer values array
virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
+ /// Returns the attribute that contains string values array
+ virtual std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID) = 0;
+ /// Returns the attribute that contains tables
+ virtual std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
#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"