Salome HOME
Change color action for a body object
[modules/shaper.git] / src / Model / Model_AttributeColor.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeColor.cpp
4 // Created:     6 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <Model_AttributeColor.h>
8 #include <ModelAPI_AttributeString.h>
9 #include <ModelAPI_Attribute.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Object.h>
12
13 #include <Standard_TypeDef.hxx>
14 #include <TCollection_AsciiString.hxx>
15 #include <TCollection_ExtendedString.hxx>
16 #include <TDataStd_Integer.hxx>
17 #include <TDataStd_Name.hxx>
18
19 #include <string>
20
21 void Model_AttributeColor::setValues(const int theRed,
22                                      const int theGreen,
23                                      const int theBlue)
24 {
25   if (!myIsInitialized || myRed->Get() != theRed ||
26       myGreen->Get() != theGreen || myBlue->Get() != theBlue) {
27     myRed->Set(theRed);
28     myGreen->Set(theGreen);
29     myBlue->Set(theBlue);
30
31     owner()->data()->sendAttributeUpdated(this);
32   }
33 }
34
35 void Model_AttributeColor::setValuesRandom()
36 {
37   setValues(300, 150, 40);
38 }
39
40 void Model_AttributeColor::values(int& theRed, int& theGreen, int& theBlue)
41 {
42   theRed = myRed->Get();
43   theGreen = myGreen->Get();
44   theBlue = myBlue->Get();
45 }
46
47 Model_AttributeColor::Model_AttributeColor(TDF_Label& theLabel)
48 {
49   // check the attribute could be already presented in this doc (after load document)
50   myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myRed) == Standard_True;
51   if (!myIsInitialized) {
52     // create attribute: not initialized by value yet, just zero
53     myRed = TDataStd_Integer::Set(theLabel, 0);
54     myGreen = TDataStd_Integer::Set(theLabel, 0);
55     myBlue = TDataStd_Integer::Set(theLabel, 0);
56   }
57 }