bf48a1ee3ecb61932b15c9260e46d45bf058109b
[occt.git] / src / TDataStd / TDataStd_Expression.cxx
1 // Created on: 1997-12-16
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TDataStd_Expression.hxx>
18
19 #include <Standard_Dump.hxx>
20 #include <Standard_GUID.hxx>
21 #include <Standard_Type.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TCollection_ExtendedString.hxx>
24 #include <TDataStd_Variable.hxx>
25 #include <TDF_Attribute.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_ListIteratorOfAttributeList.hxx>
28 #include <TDF_RelocationTable.hxx>
29
30 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Expression,TDF_Attribute)
31
32 //=======================================================================
33 //function : GetID
34 //purpose  : 
35 //=======================================================================
36 const Standard_GUID& TDataStd_Expression::GetID() 
37 {  
38   static Standard_GUID TDataStd_ExpressionID("ce24146a-8e57-11d1-8953-080009dc4425");
39   return TDataStd_ExpressionID;
40 }
41
42 //=======================================================================
43 //function : Set
44 //purpose  : 
45 //=======================================================================
46
47 Handle(TDataStd_Expression) TDataStd_Expression::Set(const TDF_Label& L) 
48 {  
49   Handle(TDataStd_Expression) A;
50   if (!L.FindAttribute (TDataStd_Expression::GetID(), A)) {
51     A = new TDataStd_Expression (); 
52     L.AddAttribute(A);
53   }
54   return A;
55 }
56
57 //=======================================================================
58 //function : TDataStd_Expression
59 //purpose  : 
60 //=======================================================================
61
62 TDataStd_Expression::TDataStd_Expression()
63 {
64 }
65
66
67 //=======================================================================
68 //function : Name
69 //purpose  : 
70 //=======================================================================
71 TCollection_ExtendedString TDataStd_Expression::Name () const 
72 {  
73   return myExpression; // ->String();
74 }
75
76 //=======================================================================
77 //function : SetExpression
78 //purpose  : 
79 //=======================================================================
80
81 void TDataStd_Expression::SetExpression(const TCollection_ExtendedString& E)
82 {
83   // OCC2932 correction
84   if(myExpression == E) return;
85
86   Backup();
87   myExpression = E;
88 }
89
90 //=======================================================================
91 //function : GetExpression
92 //purpose  : 
93 //=======================================================================
94
95 const TCollection_ExtendedString& TDataStd_Expression::GetExpression () const
96 {
97   return myExpression;
98 }
99
100 //=======================================================================
101 //function : GetVariables
102 //purpose  : 
103 //=======================================================================
104
105 TDF_AttributeList& TDataStd_Expression::GetVariables()
106 {
107   return myVariables;
108 }
109
110 //=======================================================================
111 //function : ID
112 //purpose  : 
113 //=======================================================================
114
115 const Standard_GUID& TDataStd_Expression::ID() const
116 {
117   return GetID();
118 }
119
120 //=======================================================================
121 //function : Restore
122 //purpose  : 
123 //=======================================================================
124
125 void TDataStd_Expression::Restore(const Handle(TDF_Attribute)& With) 
126 {  
127   Handle(TDataStd_Expression) EXPR = Handle(TDataStd_Expression)::DownCast (With);
128   myExpression = EXPR->GetExpression();
129
130   Handle(TDataStd_Variable) V;
131   myVariables.Clear();
132   for (TDF_ListIteratorOfAttributeList it (EXPR->GetVariables()); it.More(); it.Next()) {
133     V = Handle(TDataStd_Variable)::DownCast(it.Value());
134     myVariables.Append(V);
135   }
136 }
137
138 //=======================================================================
139 //function : NewEmpty
140 //purpose  : 
141 //=======================================================================
142
143 Handle(TDF_Attribute) TDataStd_Expression::NewEmpty() const
144 {
145   return new TDataStd_Expression();
146 }
147
148 //=======================================================================
149 //function : Paste
150 //purpose  : 
151 //=======================================================================
152
153 void TDataStd_Expression::Paste(const Handle(TDF_Attribute)& Into,
154                                  const Handle(TDF_RelocationTable)& RT) const
155 {  
156   Handle(TDataStd_Expression) EXPR = Handle(TDataStd_Expression)::DownCast (Into); 
157   EXPR->SetExpression(myExpression);  
158   Handle(TDataStd_Variable) V1;
159   for (TDF_ListIteratorOfAttributeList it (myVariables); it.More(); it.Next()) {
160     V1 = Handle(TDataStd_Variable)::DownCast(it.Value());
161     Handle(TDF_Attribute) V2;
162     RT->HasRelocation (V1,V2);
163     EXPR->GetVariables().Append(V2);
164   }
165 }
166
167 //=======================================================================
168 //function : Dump
169 //purpose  : 
170 //=======================================================================
171
172 Standard_OStream& TDataStd_Expression::Dump(Standard_OStream& anOS) const
173
174   anOS << "Expression";
175   return anOS;
176 }
177
178 //=======================================================================
179 //function : DumpJson
180 //purpose  : 
181 //=======================================================================
182 void TDataStd_Expression::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
183 {
184   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
185
186   OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
187
188   OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myExpression)
189
190   for (TDF_AttributeList::Iterator aVariableIt (myVariables); aVariableIt.More(); aVariableIt.Next())
191   {
192     const Handle(TDF_Attribute)& anAttribute = aVariableIt.Value();
193     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anAttribute.get())
194   }
195 }