Model_AttributeRefAttr.h
Model_AttributeRefList.h
Model_AttributeBoolean.h
- Model_AttributeColor.h
+ Model_AttributeIntArray.h
Model_AttributeString.h
Model_AttributeInteger.h
Model_AttributeSelection.h
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
- Model_AttributeColor.cpp
+ Model_AttributeIntArray.cpp
Model_AttributeString.cpp
Model_AttributeInteger.cpp
Model_AttributeSelection.cpp
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: Model_AttributeColor.cpp
-// Created: 6 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#include <Model_AttributeColor.h>
-#include <ModelAPI_AttributeString.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
-
-#include <Standard_TypeDef.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TDataStd_Integer.hxx>
-#include <TDataStd_Name.hxx>
-
-#include <string>
-
-void Model_AttributeColor::setValues(const int theRed,
- const int theGreen,
- const int theBlue)
-{
- if (!myIsInitialized || myRed->Get() != theRed ||
- myGreen->Get() != theGreen || myBlue->Get() != theBlue) {
- myRed->Set(theRed);
- myGreen->Set(theGreen);
- myBlue->Set(theBlue);
-
- owner()->data()->sendAttributeUpdated(this);
- }
-}
-
-void Model_AttributeColor::setValuesRandom()
-{
- setValues(300, 150, 40);
-}
-
-void Model_AttributeColor::values(int& theRed, int& theGreen, int& theBlue)
-{
- theRed = myRed->Get();
- theGreen = myGreen->Get();
- theBlue = myBlue->Get();
-}
-
-Model_AttributeColor::Model_AttributeColor(TDF_Label& theLabel)
-{
- // check the attribute could be already presented in this doc (after load document)
- myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myRed) == Standard_True;
- if (!myIsInitialized) {
- // create attribute: not initialized by value yet, just zero
- myRed = TDataStd_Integer::Set(theLabel, 0);
- myGreen = TDataStd_Integer::Set(theLabel, 0);
- myBlue = TDataStd_Integer::Set(theLabel, 0);
- }
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: Model_AttributeColor.h
-// Created: 6 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef MODEL_ATTRIBUTECOLOR_H_
-#define MODEL_ATTRIBUTECOLOR_H_
-
-#include <Model.h>
-#include <ModelAPI_AttributeColor.h>
-
-#include <TDF_Label.hxx>
-#include <TDataStd_Integer.hxx>
-
-#include <string>
-
-/**\class Model_AttributeColor
- * \ingroup DataModel
- * \brief Attribute that contains three integer values which define the color.
- */
-
-class Model_AttributeColor : public ModelAPI_AttributeColor
-{
- Handle_TDataStd_Integer myRed;
- Handle_TDataStd_Integer myGreen;
- Handle_TDataStd_Integer myBlue;
- public:
- /// Defines the color value
- /// \param theRed the red part of the color
- /// \param theRed the green part of the color
- /// \param theRed the blue part of the color
- MODELAPI_EXPORT virtual void setValues(const int theRed,
- const int theGreen,
- const int theBlue);
-
- /// Fills the attribute values by a random color
- MODELAPI_EXPORT virtual void setValuesRandom();
-
- /// Returns the color value
- MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue);
-
- protected:
- /// Initializes attibutes
- Model_AttributeColor(TDF_Label& theLabel);
-
- friend class Model_Data;
-};
-
-#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeIntArray.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <Model_AttributeIntArray.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_Name.hxx>
+
+#include <string>
+
+int Model_AttributeIntArray::size()
+{
+ return myArray.IsNull() ? 0 : myArray->Length();
+}
+
+void Model_AttributeIntArray::setSize(const int theSize)
+{
+ if (myArray.IsNull()) { // 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_IntegerArray::Set(myLab, 0, theSize);
+ 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_HArray1OfInteger) aNewArray = new TColStd_HArray1OfInteger(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_IntegerArray::GetID());
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ }
+ }
+}
+
+void Model_AttributeIntArray::setValue(const int theIndex,
+ const int theValue)
+{
+ if (myArray->Value(theIndex) != theValue) {
+ myArray->SetValue(theIndex, theValue);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+int Model_AttributeIntArray::value(const int theIndex)
+{
+ return myArray->Value(theIndex);
+}
+
+Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
+{
+ myLab = theLabel;
+ // check the attribute could be already presented in this doc (after load document)
+ myIsInitialized =
+ myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeIntArray.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef MODEL_ATTRIBUTEINTARRAY_H_
+#define MODEL_ATTRIBUTEINTARRAY_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeIntArray.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_IntegerArray.hxx>
+
+#include <string>
+
+/**\class Model_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ * Represented as array in OCCT. Empty array means that this attribute does not exists.
+ */
+
+class Model_AttributeIntArray : public ModelAPI_AttributeIntArray
+{
+ /// The OCCT array that keeps all values.
+ Handle_TDataStd_IntegerArray myArray;
+ /// Stores the label as a field to set array if size is not null (null array is buggy in OCAF)
+ TDF_Label myLab;
+ 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 int theValue);
+
+ /// Returns the value by the index
+ MODEL_EXPORT virtual int value(const int theIndex);
+
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeIntArray(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeString.h>
#include <Model_AttributeSelection.h>
#include <Model_AttributeSelectionList.h>
-#include <Model_AttributeColor.h>
+#include <Model_AttributeIntArray.h>
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
anAttr = new Model_AttributeRefAttr(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefList::type()) {
anAttr = new Model_AttributeRefList(anAttrLab);
- } else if (theAttrType == ModelAPI_AttributeColor::type()) {
- anAttr = new Model_AttributeColor(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeIntArray::type()) {
+ anAttr = new Model_AttributeIntArray(anAttrLab);
}
// create also GeomData attributes here because only here the OCAF strucure is known
else if (theAttrType == GeomData_Point::type()) {
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
{
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Object.h>
/// Returns the attribute that contains real value with double precision
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
string(const std::string& theID);
+ /// Returns the attribute that contains integer values array
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
+ intArray(const std::string& theID);
+
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
#include <Model_ResultBody.h>
#include <Model_Data.h>
#include <Model_Document.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TDataStd_Name.hxx>
{
// append the color attribute
DataPtr aData = data();
- aData->addAttribute(COLOR_ID(), ModelAPI_AttributeColor::type());
- // set the default value
- bool anIsRandomColor = Config_PropManager::boolean("Visualization", "random_result_color",
- "true");
- AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>
- (aData->attribute(COLOR_ID()));
- if (anIsRandomColor)
- aColorAttr->setValuesRandom();
- else {
- std::vector<int> aRGB;
- aRGB = Config_PropManager::color("Visualization", "result_body_color", RESULT_BODY_COLOR);
- aColorAttr->setValues(aRGB[0], aRGB[1], aRGB[2]);
- }
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+ AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
+ std::vector<int> aRGB;
+ aRGB = Config_PropManager::color("Visualization", "result_body_color", RESULT_BODY_COLOR);
+ aColorAttr->setSize(3);
+ aColorAttr->setValue(0, aRGB[0]);
+ aColorAttr->setValue(1, aRGB[1]);
+ aColorAttr->setValue(2, aRGB[2]);
}
void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
ModelAPI.h
ModelAPI_Attribute.h
ModelAPI_AttributeBoolean.h
- ModelAPI_AttributeColor.h
+ ModelAPI_AttributeIntArray.h
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeDouble.h
ModelAPI_AttributeInteger.h
SET(PROJECT_SOURCES
ModelAPI_Attribute.cpp
ModelAPI_AttributeBoolean.cpp
- ModelAPI_AttributeColor.cpp
+ ModelAPI_AttributeIntArray.cpp
ModelAPI_AttributeDocRef.cpp
ModelAPI_AttributeDouble.cpp
ModelAPI_AttributeInteger.cpp
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_AttributeColor.cpp
-// Created: 6 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#include <ModelAPI_AttributeColor.h>
-
-
-std::string ModelAPI_AttributeColor::attributeType()
-{
- return type();
-}
-
-/// To virtually destroy the fields of successors
-ModelAPI_AttributeColor::~ModelAPI_AttributeColor()
-{
-}
-
-ModelAPI_AttributeColor::ModelAPI_AttributeColor()
-{
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_AttributeColor.h
-// Created: 6 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModelAPI_AttributeColor_H_
-#define ModelAPI_AttributeColor_H_
-
-#include <ModelAPI.h>
-#include <ModelAPI_Attribute.h>
-
-#include <string>
-
-
-/**\class ModelAPI_AttributeColor
- * \ingroup DataModel
- * \brief API for the attribute that contains color (int, int, int). The color is in the range [0, 255]
- * There is an opportunity to fill the attribute by a random color
- */
-
-class ModelAPI_AttributeColor : public ModelAPI_Attribute
-{
- public:
- /// Defines the color value
- /// \param theRed the red part of the color
- /// \param theRed the green part of the color
- /// \param theRed the blue part of the color
- MODELAPI_EXPORT virtual void setValues(const int theRed,
- const int theGreen,
- const int theBlue) = 0;
-
- /// Fills the attribute values by a random color
- MODELAPI_EXPORT virtual void setValuesRandom() = 0;
-
- /// Returns the color value
- MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue) = 0;
-
- /// Returns the type of this class of attributes
- MODELAPI_EXPORT static std::string type()
- {
- return "Color";
- }
-
- /// 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_AttributeColor();
-
- protected:
- /// Objects are created for features automatically
- MODELAPI_EXPORT ModelAPI_AttributeColor();
-};
-
-//! Pointer on double attribute
-typedef std::shared_ptr<ModelAPI_AttributeColor> AttributeColorPtr;
-
-#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_AttributeIntArray.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <ModelAPI_AttributeIntArray.h>
+
+
+std::string ModelAPI_AttributeIntArray::attributeType()
+{
+ return type();
+}
+
+/// To virtually destroy the fields of successors
+ModelAPI_AttributeIntArray::~ModelAPI_AttributeIntArray()
+{
+}
+
+ModelAPI_AttributeIntArray::ModelAPI_AttributeIntArray()
+{
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_AttributeIntArray.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModelAPI_AttributeIntArray_H_
+#define ModelAPI_AttributeIntArray_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+
+/**\class ModelAPI_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ */
+
+class ModelAPI_AttributeIntArray : 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 int theValue) = 0;
+
+ /// Returns the value by the index
+ MODELAPI_EXPORT virtual int value(const int theIndex) = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type()
+ {
+ return "IntArray";
+ }
+
+ /// 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_AttributeIntArray();
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeIntArray();
+};
+
+//! Pointer on double attribute
+typedef std::shared_ptr<ModelAPI_AttributeIntArray> AttributeIntArrayPtr;
+
+#endif
class ModelAPI_Feature;
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
+class ModelAPI_AttributeIntArray;
class ModelAPI_Object;
class GeomAPI_Shape;
virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
/// Returns the attribute that contains boolean value
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 generic attribute by identifier
/// \param theID identifier of the attribute
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModuleBase_ResultPrs.h>
// correct the result's color it it has the attribute
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
- int aRed, aGreen, aBlue;
-
- AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(
- aResult->data()->attribute(ModelAPI_Result::COLOR_ID()));
- aColorAttr->values(aRed, aGreen, aBlue);
- anAISObj->setColor(aRed, aGreen, aBlue);
+ AttributeIntArrayPtr aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() && aColorAttr->size()) {
+ int aRed = aColorAttr->value(0);
+ int aGreen = aColorAttr->value(1);
+ int aBlue = aColorAttr->value(2);
+ anAISObj->setColor(aRed, aGreen, aBlue);
+ }
}
else {
// Customization of presentation
#include <QDialog>
#include <QHBoxLayout>
#include <QtxColorButton.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
{
// 1. find the initial value of the color
- AttributeColorPtr aColorAttr;
+ AttributeIntArrayPtr aColorAttr;
foreach(ObjectPtr anObj, theObjects) {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
if (aResult.get() != NULL) {
- AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
- if (anAttr.get() != NULL)
- aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
}
}
// there is no object with the color attribute
- if (aColorAttr.get() == NULL)
+ if (aColorAttr.get() == NULL || aColorAttr->size() == 0)
return;
- int aRed, aGreen, aBlue;
- aColorAttr->values(aRed, aGreen, aBlue);
+ int aRed = aColorAttr->value(0);
+ int aGreen = aColorAttr->value(1);
+ int aBlue = aColorAttr->value(2);
// 2. show the dialog to change the value
QDialog aDlg;
foreach(ObjectPtr anObj, theObjects) {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
if (aResult.get() != NULL) {
- AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
- if (anAttr.get() != NULL) {
- aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
- if (aColorAttr.get() != NULL)
- aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+ aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() != NULL) {
+ if (!aColorAttr->size()) {
+ aColorAttr->setSize(3);
+ }
+ aColorAttr->setValue(0, aRedResult);
+ aColorAttr->setValue(1, aGreenResult);
+ aColorAttr->setValue(2, aBlueResult);
}
}
}