b311480e |
1 | // Created on: 2008-03-07 |
2 | // Created by: Vlad ROMASHKO |
3 | // Copyright (c) 2008-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | #include <XmlMFunction_GraphNodeDriver.ixx> |
22 | #include <XmlObjMgt.hxx> |
23 | |
24 | #include <TFunction_GraphNode.hxx> |
25 | #include <TColStd_MapIteratorOfMapOfInteger.hxx> |
26 | |
27 | IMPLEMENT_DOMSTRING (LastPreviousIndex, "lastprev") |
28 | IMPLEMENT_DOMSTRING (LastNextIndex, "lastnext") |
29 | IMPLEMENT_DOMSTRING (ExecutionStatus, "exec") |
30 | |
31 | //======================================================================= |
32 | //function : XmlMFunction_GraphNodeDriver |
33 | //purpose : Constructor |
34 | //======================================================================= |
35 | XmlMFunction_GraphNodeDriver::XmlMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
36 | : XmlMDF_ADriver (theMsgDriver, NULL) |
37 | { |
38 | |
39 | } |
40 | |
41 | //======================================================================= |
42 | //function : NewEmpty |
43 | //purpose : |
44 | //======================================================================= |
45 | Handle(TDF_Attribute) XmlMFunction_GraphNodeDriver::NewEmpty() const |
46 | { |
47 | return (new TFunction_GraphNode()); |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : Paste |
52 | //purpose : persistent -> transient (retrieve) |
53 | //======================================================================= |
54 | Standard_Boolean XmlMFunction_GraphNodeDriver::Paste(const XmlObjMgt_Persistent& theSource, |
55 | const Handle(TDF_Attribute)& theTarget, |
56 | XmlObjMgt_RRelocationTable& ) const |
57 | { |
58 | Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theTarget); |
59 | |
60 | Standard_Integer aFirstIndPrev, aLastIndPrev, aFirstIndNext, aLastIndNext, aValue, ind; |
61 | const XmlObjMgt_Element& anElement = theSource; |
62 | |
63 | // Previous |
64 | // ======== |
65 | |
66 | // Read the FirstIndex; if the attribute is absent initialize to 1 |
67 | aFirstIndPrev = 1; // It is absent :-) because I didn't wrote it on the stage of writing the file. |
68 | |
69 | // Read the LastIndex; the attribute should present |
70 | if (!anElement.getAttribute(::LastPreviousIndex()).GetInteger(aLastIndPrev)) |
71 | { |
72 | TCollection_ExtendedString aMessageString = |
73 | TCollection_ExtendedString("Cannot retrieve the last index" |
74 | " for previous functions of GraphNode attribute"); |
75 | WriteMessage (aMessageString); |
76 | return Standard_False; |
77 | } |
78 | |
79 | if (aFirstIndPrev == aLastIndPrev) |
80 | { |
81 | Standard_Integer anInteger; |
82 | if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger)) |
83 | { |
84 | TCollection_ExtendedString aMessageString = |
85 | TCollection_ExtendedString("Cannot retrieve integer member" |
86 | " for previous functions of GraphNode attribute"); |
87 | WriteMessage (aMessageString); |
88 | return Standard_False; |
89 | } |
90 | G->AddPrevious(anInteger); |
91 | } |
92 | else |
93 | { |
94 | Standard_CString aValueStr = |
95 | Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString()); |
96 | |
97 | for (ind = aFirstIndPrev; ind <= aLastIndPrev; ind++) |
98 | { |
99 | if (!XmlObjMgt::GetInteger(aValueStr, aValue)) |
100 | { |
101 | TCollection_ExtendedString aMessageString = |
102 | TCollection_ExtendedString("Cannot retrieve integer member" |
103 | " for previous functions of GraphNode attribute as \"") |
104 | + aValueStr + "\""; |
105 | WriteMessage (aMessageString); |
106 | return Standard_False; |
107 | } |
108 | G->AddPrevious(aValue); |
109 | } |
110 | } |
111 | |
112 | |
113 | // Next |
114 | // ==== |
115 | |
116 | // Read the FirstIndex; if the attribute is absent initialize to 1 |
117 | aFirstIndNext = aLastIndPrev + 1; // It is absent :-) because I didn't wrote it on the stage of writing the file. |
118 | |
119 | // Read the LastIndex; the attribute should present |
120 | if (!anElement.getAttribute(::LastNextIndex()).GetInteger(aLastIndNext)) |
121 | { |
122 | TCollection_ExtendedString aMessageString = |
123 | TCollection_ExtendedString("Cannot retrieve the last index" |
124 | " for next functions of GraphNode attribute"); |
125 | WriteMessage (aMessageString); |
126 | return Standard_False; |
127 | } |
128 | aLastIndNext += aLastIndPrev; |
129 | |
130 | Standard_CString aValueStr = |
131 | Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString()); |
132 | |
133 | for (ind = 1; ind <= aLastIndNext; ind++) |
134 | { |
135 | if (!XmlObjMgt::GetInteger(aValueStr, aValue)) |
136 | { |
137 | TCollection_ExtendedString aMessageString = |
138 | TCollection_ExtendedString("Cannot retrieve integer member" |
139 | " for next functions of GraphNode attribute as \"") |
140 | + aValueStr + "\""; |
141 | WriteMessage (aMessageString); |
142 | return Standard_False; |
143 | } |
144 | if (ind < aFirstIndNext) |
145 | continue; |
146 | G->AddNext(aValue); |
147 | } |
148 | |
149 | // Execution status |
150 | Standard_Integer exec = 0; |
151 | if (!anElement.getAttribute(::ExecutionStatus()).GetInteger(exec)) |
152 | { |
153 | TCollection_ExtendedString aMessageString = |
154 | TCollection_ExtendedString("Cannot retrieve the execution status" |
155 | " for GraphNode attribute"); |
156 | WriteMessage (aMessageString); |
157 | return Standard_False; |
158 | } |
159 | G->SetStatus((TFunction_ExecutionStatus) exec); |
160 | |
161 | return Standard_True; |
162 | } |
163 | |
164 | //======================================================================= |
165 | //function : Paste |
166 | //purpose : transient -> persistent (store) |
167 | //======================================================================= |
168 | void XmlMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource, |
169 | XmlObjMgt_Persistent& theTarget, |
170 | XmlObjMgt_SRelocationTable& ) const |
171 | { |
172 | Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theSource); |
173 | |
174 | // Previous |
175 | // ======== |
176 | |
177 | theTarget.Element().setAttribute(::LastPreviousIndex(), G->GetPrevious().Extent()); |
178 | |
179 | TCollection_AsciiString aValueStr; |
180 | TColStd_MapIteratorOfMapOfInteger itrm(G->GetPrevious()); |
181 | for (; itrm.More(); itrm.Next()) |
182 | { |
183 | const Standard_Integer ID = itrm.Key(); |
184 | aValueStr += TCollection_AsciiString(ID); |
185 | aValueStr += ' '; |
186 | } |
187 | aValueStr += "\n"; |
188 | |
189 | // Next |
190 | // ==== |
191 | |
192 | theTarget.Element().setAttribute(::LastNextIndex(), G->GetNext().Extent()); |
193 | |
194 | itrm.Initialize(G->GetNext()); |
195 | for (; itrm.More(); itrm.Next()) |
196 | { |
197 | const Standard_Integer ID = itrm.Key(); |
198 | aValueStr += TCollection_AsciiString(ID); |
199 | aValueStr += ' '; |
200 | } |
201 | |
202 | XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True); |
203 | |
204 | // Execution status |
205 | theTarget.Element().setAttribute(::ExecutionStatus(), (Standard_Integer) G->GetStatus()); |
206 | } |