Salome HOME
Issue #1540: Added attribute for array of double.
authordbv <dbv@opencascade.com>
Fri, 8 Jul 2016 12:44:20 +0000 (15:44 +0300)
committerdbv <dbv@opencascade.com>
Fri, 8 Jul 2016 12:44:20 +0000 (15:44 +0300)
src/Model/CMakeLists.txt
src/Model/Model_AttributeDoubleArray.cpp [new file with mode: 0644]
src/Model/Model_AttributeDoubleArray.h [new file with mode: 0644]
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_AttributeDoubleArray.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_AttributeDoubleArray.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_swig.h

index 11d98c4271efc7bc03f1aad1af71450751bfd98a..d94f595e030d42e5b26b2824115e8ae6d046bbcf 100644 (file)
@@ -10,6 +10,7 @@ SET(PROJECT_HEADERS
     Model_Session.h
     Model_Data.h
     Model_AttributeDouble.h
+    Model_AttributeDoubleArray.h
     Model_AttributeDocRef.h
     Model_AttributeReference.h
     Model_AttributeRefAttr.h
@@ -44,6 +45,7 @@ SET(PROJECT_SOURCES
     Model_Session.cpp
     Model_Data.cpp
     Model_AttributeDouble.cpp
+    Model_AttributeDoubleArray.cpp
     Model_AttributeDocRef.cpp
     Model_AttributeReference.cpp
     Model_AttributeRefAttr.cpp
diff --git a/src/Model/Model_AttributeDoubleArray.cpp b/src/Model/Model_AttributeDoubleArray.cpp
new file mode 100644 (file)
index 0000000..3a6b2ad
--- /dev/null
@@ -0,0 +1,77 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        Model_AttributeDoubleArray.cpp
+// Created:     08 July 2016
+// Author:      Dmitry Bobylev
+
+#include "Model_AttributeDoubleArray.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <TColStd_HArray1OfReal.hxx>
+
+#include <string>
+
+//==================================================================================================
+int Model_AttributeDoubleArray::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_RealArray::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_AttributeDoubleArray::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_RealArray::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_HArray1OfReal) aNewArray = new TColStd_HArray1OfReal(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_RealArray::GetID());
+        owner()->data()->sendAttributeUpdated(this);
+      }
+    }
+  }
+}
+
+//==================================================================================================
+void Model_AttributeDoubleArray::setValue(const int theIndex,
+                                          const double theValue)
+{
+  if (myArray->Value(theIndex) != theValue) {
+    myArray->SetValue(theIndex, theValue);
+    owner()->data()->sendAttributeUpdated(this);
+  }
+}
+
+//==================================================================================================
+double Model_AttributeDoubleArray::value(const int theIndex)
+{
+  return myArray->Value(theIndex);
+}
+
+//==================================================================================================
+Model_AttributeDoubleArray::Model_AttributeDoubleArray(TDF_Label& theLabel)
+{
+  myLab = theLabel;
+  // check the attribute could be already presented in this doc (after load document)
+  myIsInitialized =
+    myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;
+}
diff --git a/src/Model/Model_AttributeDoubleArray.h b/src/Model/Model_AttributeDoubleArray.h
new file mode 100644 (file)
index 0000000..74d9606
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        Model_AttributeDoubleArray.h
+// Created:     08 July 2016
+// Author:      Dmitry Bobylev
+
+#ifndef Model_AttributeDoubleArray_H_
+#define Model_AttributeDoubleArray_H_
+
+#include "Model.h"
+
+#include <ModelAPI_AttributeDoubleArray.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_RealArray.hxx>
+
+#include <string>
+
+/// \class Model_AttributeDoubleArray
+/// \ingroup DataModel
+/// \brief API for the attribute that contains several double in the array inside.
+class Model_AttributeDoubleArray: public ModelAPI_AttributeDoubleArray
+{
+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 double theValue);
+
+  /// Returns the value by the index
+  MODEL_EXPORT virtual double value(const int theIndex);
+
+protected:
+  /// Initializes attibutes
+  Model_AttributeDoubleArray(TDF_Label& theLabel);
+
+private:
+  /// The OCCT array that keeps all values.
+  Handle_TDataStd_RealArray 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
index 402dbd67982d5353a6d92e69e8175e62bf15cdd1..fe4ec99dbc8ddc9877ad1389edcfce3f49e78057 100644 (file)
@@ -8,6 +8,7 @@
 #include <Model_AttributeDocRef.h>
 #include <Model_AttributeInteger.h>
 #include <Model_AttributeDouble.h>
+#include <Model_AttributeDoubleArray.h>
 #include <Model_AttributeReference.h>
 #include <Model_AttributeRefAttr.h>
 #include <Model_AttributeRefList.h>
@@ -151,7 +152,9 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin
     anAttr = new Model_AttributeRefAttrList(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeIntArray::typeId()) {
     anAttr = new Model_AttributeIntArray(anAttrLab);
-  } 
+  } else if (theAttrType == ModelAPI_AttributeDoubleArray::typeId()) {
+    anAttr = new Model_AttributeDoubleArray(anAttrLab);
+  }
   // create also GeomData attributes here because only here the OCAF structure is known
   else if (theAttrType == GeomData_Point::typeId()) {
     GeomData_Point* anAttribute = new GeomData_Point();
@@ -211,6 +214,7 @@ GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
 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);
 
 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
 {
index e505d375165731acd0fbd6b7ae75afd03132d667..c8a5a03d8d043b7a5ab392199010761bdeda676a 100644 (file)
@@ -86,6 +86,8 @@ class Model_Data : public ModelAPI_Data
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID);
   /// Returns the attribute that contains real value with double precision
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID);
+  /// Returns the attribute that contains double values array
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeDoubleArray> realArray(const std::string& theID);
   /// Returns the attribute that contains integer value
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeInteger>
     integer(const std::string& theID);
index 27298e20e11eb9eee2904c776a11ffea179a2437..60036bc80df724a67aeba9462d08d4a482442048 100644 (file)
@@ -12,6 +12,7 @@ SET(PROJECT_HEADERS
     ModelAPI_AttributeIntArray.h
     ModelAPI_AttributeDocRef.h
     ModelAPI_AttributeDouble.h
+    ModelAPI_AttributeDoubleArray.h
     ModelAPI_AttributeInteger.h
     ModelAPI_AttributeRefAttr.h
     ModelAPI_AttributeReference.h
@@ -50,6 +51,7 @@ SET(PROJECT_SOURCES
     ModelAPI_AttributeIntArray.cpp
     ModelAPI_AttributeDocRef.cpp
     ModelAPI_AttributeDouble.cpp
+    ModelAPI_AttributeDoubleArray.cpp
     ModelAPI_AttributeInteger.cpp
     ModelAPI_AttributeRefAttr.cpp
     ModelAPI_AttributeReference.cpp
index b8fcaaa9def05582d3620e2704d2676a09d2f14a..23c6d804365baa13edd81d377c3d67fe6bc23bac 100644 (file)
@@ -45,6 +45,7 @@
 %shared_ptr(ModelAPI_Attribute)
 %shared_ptr(ModelAPI_AttributeDocRef)
 %shared_ptr(ModelAPI_AttributeDouble)
+%shared_ptr(ModelAPI_AttributeDoubleArray)
 %shared_ptr(ModelAPI_AttributeInteger)
 %shared_ptr(ModelAPI_AttributeIntArray)
 %shared_ptr(ModelAPI_AttributeString)
@@ -78,6 +79,7 @@
 %include "ModelAPI_Attribute.h"
 %include "ModelAPI_AttributeDocRef.h"
 %include "ModelAPI_AttributeDouble.h"
+%include "ModelAPI_AttributeDoubleArray.h"
 %include "ModelAPI_AttributeInteger.h"
 %include "ModelAPI_AttributeIntArray.h"
 %include "ModelAPI_AttributeString.h"
 %include "ModelAPI_Tools.h"
 %include "ModelAPI_ResultCompSolid.h"
 
-// std::list -> [] 
+// std::list -> []
 %template(StringList) std::list<std::string>;
 %template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
 %template(ResultList) std::list<std::shared_ptr<ModelAPI_Result> >;
@@ -126,6 +128,7 @@ template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr
 // Attribute casts
 %template(modelAPI_AttributeDocRef)        shared_ptr_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
 %template(modelAPI_AttributeDouble)        shared_ptr_cast<ModelAPI_AttributeDouble, ModelAPI_Attribute>;
+%template(modelAPI_AttributeDoubleArray)   shared_ptr_cast<ModelAPI_AttributeDoubleArray, ModelAPI_Attribute>;
 %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>;
diff --git a/src/ModelAPI/ModelAPI_AttributeDoubleArray.cpp b/src/ModelAPI/ModelAPI_AttributeDoubleArray.cpp
new file mode 100644 (file)
index 0000000..73aa272
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_AttributeDoubleArray.cpp
+// Created:     8 July 2016
+// Author:      Dmitry Bobylev
+
+#include "ModelAPI_AttributeDoubleArray.h"
+
+//==================================================================================================
+std::string ModelAPI_AttributeDoubleArray::attributeType()
+{
+  return typeId();
+}
+
+//==================================================================================================
+ModelAPI_AttributeDoubleArray::~ModelAPI_AttributeDoubleArray()
+{
+}
+
+//==================================================================================================
+ModelAPI_AttributeDoubleArray::ModelAPI_AttributeDoubleArray()
+{
+}
diff --git a/src/ModelAPI/ModelAPI_AttributeDoubleArray.h b/src/ModelAPI/ModelAPI_AttributeDoubleArray.h
new file mode 100644 (file)
index 0000000..5106904
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_AttributeDoubleArray.h
+// Created:     08 July 2016
+// Author:      Dmitry Bobylev
+
+#ifndef ModelAPI_AttributeDoubleArray_H_
+#define ModelAPI_AttributeDoubleArray_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+/// \class ModelAPI_AttributeDoubleArray
+/// \ingroup DataModel
+/// \brief API for the attribute that contains several double in the array inside.
+class ModelAPI_AttributeDoubleArray: 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 double theValue) = 0;
+
+  /// Returns the value by the index
+  MODELAPI_EXPORT virtual double value(const int theIndex) = 0;
+
+  /// Returns the type of this class of attributes
+  MODELAPI_EXPORT static std::string typeId()
+  {
+    return "DoubleArray";
+  }
+
+  /// 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_AttributeDoubleArray();
+
+protected:
+  /// Objects are created for features automatically
+  MODELAPI_EXPORT ModelAPI_AttributeDoubleArray();
+};
+
+/// Pointer on double attribute
+typedef std::shared_ptr<ModelAPI_AttributeDoubleArray> AttributeDoubleArrayPtr;
+
+#endif
index 320dffb4035b640acc63fa219fa7731a2b34cd10..71e9aee9d631201cbfb632a55811b6882ab1c707 100644 (file)
@@ -21,6 +21,7 @@ class ModelAPI_Attribute;
 class ModelAPI_AttributeDocRef;
 class ModelAPI_AttributeInteger;
 class ModelAPI_AttributeDouble;
+class ModelAPI_AttributeDoubleArray;
 class ModelAPI_AttributeReference;
 class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeRefList;
@@ -65,6 +66,8 @@ class MODELAPI_EXPORT ModelAPI_Data
   virtual std::shared_ptr<ModelAPI_AttributeDocRef> document(const std::string& theID) = 0;
   /// Returns the attribute that contains real value with double precision
   virtual std::shared_ptr<ModelAPI_AttributeDouble> real(const std::string& theID) = 0;
+  /// Returns the attribute that contains double values array
+  virtual std::shared_ptr<ModelAPI_AttributeDoubleArray> realArray(const std::string& theID) = 0;
   /// Returns the attribute that contains integer value
   virtual std::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
   /// Returns the attribute that contains reference to a feature
index 377d1182db3fa9e420df505ce19f08318618463a..ec816d77cb33455aaf0a5a1468620c262cbd9eca 100644 (file)
@@ -21,6 +21,7 @@
   #include "ModelAPI_Attribute.h"
   #include "ModelAPI_AttributeDocRef.h"
   #include "ModelAPI_AttributeDouble.h"
+  #include "ModelAPI_AttributeDoubleArray.h"
   #include "ModelAPI_AttributeInteger.h"
   #include "ModelAPI_AttributeIntArray.h"
   #include "ModelAPI_AttributeString.h"