0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / XCAFDoc / XCAFDoc_DimTol.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <XCAFDoc_DimTol.hxx>
15
16 #include <Standard_Dump.hxx>
17 #include <Standard_GUID.hxx>
18 #include <Standard_Type.hxx>
19 #include <TCollection_HAsciiString.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <TDF_Label.hxx>
22 #include <TDF_RelocationTable.hxx>
23
24 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_DimTol,TDF_Attribute)
25
26 //=======================================================================
27 //function : XCAFDoc_DimTol
28 //purpose  : 
29 //=======================================================================
30 XCAFDoc_DimTol::XCAFDoc_DimTol()
31 {
32 }
33
34
35 //=======================================================================
36 //function : GetID
37 //purpose  : 
38 //=======================================================================
39
40 const Standard_GUID& XCAFDoc_DimTol::GetID() 
41 {
42   static Standard_GUID DGTID ("58ed092d-44de-11d8-8776-001083004c77");
43   //static Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b");
44   return DGTID; 
45   //return ID;
46 }
47
48
49 //=======================================================================
50 //function : Set
51 //purpose  : 
52 //=======================================================================
53
54 Handle(XCAFDoc_DimTol) XCAFDoc_DimTol::Set(const TDF_Label& label,
55                                            const Standard_Integer kind,
56                                            const Handle(TColStd_HArray1OfReal)& aVal,
57                                            const Handle(TCollection_HAsciiString)& aName,
58                                            const Handle(TCollection_HAsciiString)& aDescription) 
59 {
60   Handle(XCAFDoc_DimTol) A;
61   if (!label.FindAttribute(XCAFDoc_DimTol::GetID(), A)) {
62     A = new XCAFDoc_DimTol();
63     label.AddAttribute(A);
64   }
65   A->Set(kind,aVal,aName,aDescription); 
66   return A;
67 }
68
69
70 //=======================================================================
71 //function : Set
72 //purpose  : 
73 //=======================================================================
74
75 void XCAFDoc_DimTol::Set(const Standard_Integer kind,
76                          const Handle(TColStd_HArray1OfReal)& aVal,
77                          const Handle(TCollection_HAsciiString)& aName,
78                          const Handle(TCollection_HAsciiString)& aDescription) 
79 {
80   Backup();
81   myKind = kind;
82   myVal = aVal;
83   myName = aName;
84   myDescription = aDescription;
85 }
86
87
88 //=======================================================================
89 //function : GetKind
90 //purpose  : 
91 //=======================================================================
92
93 Standard_Integer XCAFDoc_DimTol::GetKind() const
94 {
95   return myKind;
96 }
97
98
99 //=======================================================================
100 //function : GetVal
101 //purpose  : 
102 //=======================================================================
103
104 Handle(TColStd_HArray1OfReal) XCAFDoc_DimTol::GetVal() const
105 {
106   return myVal;
107 }
108
109
110 //=======================================================================
111 //function : GetName
112 //purpose  : 
113 //=======================================================================
114
115 Handle(TCollection_HAsciiString) XCAFDoc_DimTol::GetName() const
116 {
117   return myName;
118 }
119
120
121 //=======================================================================
122 //function : GetDescription
123 //purpose  : 
124 //=======================================================================
125
126 Handle(TCollection_HAsciiString) XCAFDoc_DimTol::GetDescription() const
127 {
128   return myDescription;
129 }
130
131
132 //=======================================================================
133 //function : ID
134 //purpose  : 
135 //=======================================================================
136
137 const Standard_GUID& XCAFDoc_DimTol::ID() const
138 {
139   return GetID();
140 }
141
142
143 //=======================================================================
144 //function : Restore
145 //purpose  : 
146 //=======================================================================
147
148 void XCAFDoc_DimTol::Restore(const Handle(TDF_Attribute)& With) 
149 {
150   myKind = Handle(XCAFDoc_DimTol)::DownCast(With)->GetKind();
151   myVal = Handle(XCAFDoc_DimTol)::DownCast(With)->GetVal();
152   myName = Handle(XCAFDoc_DimTol)::DownCast(With)->GetName();
153   myDescription = Handle(XCAFDoc_DimTol)::DownCast(With)->GetDescription();
154 }
155
156
157 //=======================================================================
158 //function : NewEmpty
159 //purpose  : 
160 //=======================================================================
161
162 Handle(TDF_Attribute) XCAFDoc_DimTol::NewEmpty() const
163 {
164   return new XCAFDoc_DimTol();
165 }
166
167
168 //=======================================================================
169 //function : Paste
170 //purpose  : 
171 //=======================================================================
172
173 void XCAFDoc_DimTol::Paste(const Handle(TDF_Attribute)& Into,
174                            const Handle(TDF_RelocationTable)& /*RT*/) const
175 {
176   Handle(XCAFDoc_DimTol)::DownCast(Into)->Set(myKind,myVal,myName,myDescription);
177 }
178
179 //=======================================================================
180 //function : DumpJson
181 //purpose  : 
182 //=======================================================================
183 void XCAFDoc_DimTol::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
184 {
185   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
186
187   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
188
189   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myKind)
190
191   for (TColStd_Array1OfReal::Iterator aValIt (myVal->Array1()); aValIt.More(); aValIt.Next())
192   {
193     const Standard_Real& aValue = aValIt.Value();
194     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aValue)
195   }
196   
197   OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName.get())
198   OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myDescription.get())
199 }