b311480e |
1 | // Created on: 2008-03-07 |
2 | // Created by: Vlad ROMASHKO |
973c2be1 |
3 | // Copyright (c) 2008-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
83ae3591 |
17 | #include <Message_Messenger.hxx> |
42cf5bc1 |
18 | #include <Standard_Type.hxx> |
42cf5bc1 |
19 | #include <TFunction_GraphNode.hxx> |
20 | #include <XmlMFunction_GraphNodeDriver.hxx> |
21 | #include <XmlObjMgt.hxx> |
22 | #include <XmlObjMgt_Persistent.hxx> |
7fd59977 |
23 | |
92efcf78 |
24 | IMPLEMENT_STANDARD_RTTIEXT(XmlMFunction_GraphNodeDriver,XmlMDF_ADriver) |
7fd59977 |
25 | IMPLEMENT_DOMSTRING (LastPreviousIndex, "lastprev") |
26 | IMPLEMENT_DOMSTRING (LastNextIndex, "lastnext") |
27 | IMPLEMENT_DOMSTRING (ExecutionStatus, "exec") |
28 | |
29 | //======================================================================= |
30 | //function : XmlMFunction_GraphNodeDriver |
31 | //purpose : Constructor |
32 | //======================================================================= |
83ae3591 |
33 | XmlMFunction_GraphNodeDriver::XmlMFunction_GraphNodeDriver(const Handle(Message_Messenger)& theMsgDriver) |
7fd59977 |
34 | : XmlMDF_ADriver (theMsgDriver, NULL) |
35 | { |
36 | |
37 | } |
38 | |
39 | //======================================================================= |
40 | //function : NewEmpty |
41 | //purpose : |
42 | //======================================================================= |
43 | Handle(TDF_Attribute) XmlMFunction_GraphNodeDriver::NewEmpty() const |
44 | { |
45 | return (new TFunction_GraphNode()); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : Paste |
50 | //purpose : persistent -> transient (retrieve) |
51 | //======================================================================= |
52 | Standard_Boolean XmlMFunction_GraphNodeDriver::Paste(const XmlObjMgt_Persistent& theSource, |
83ae3591 |
53 | const Handle(TDF_Attribute)& theTarget, |
54 | XmlObjMgt_RRelocationTable& ) const |
7fd59977 |
55 | { |
56 | Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theTarget); |
57 | |
58 | Standard_Integer aFirstIndPrev, aLastIndPrev, aFirstIndNext, aLastIndNext, aValue, ind; |
59 | const XmlObjMgt_Element& anElement = theSource; |
60 | |
61 | // Previous |
62 | // ======== |
63 | |
64 | // Read the FirstIndex; if the attribute is absent initialize to 1 |
65 | aFirstIndPrev = 1; // It is absent :-) because I didn't wrote it on the stage of writing the file. |
66 | |
67 | // Read the LastIndex; the attribute should present |
68 | if (!anElement.getAttribute(::LastPreviousIndex()).GetInteger(aLastIndPrev)) |
69 | { |
70 | TCollection_ExtendedString aMessageString = |
71 | TCollection_ExtendedString("Cannot retrieve the last index" |
72 | " for previous functions of GraphNode attribute"); |
83ae3591 |
73 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
74 | return Standard_False; |
75 | } |
76 | |
77 | if (aFirstIndPrev == aLastIndPrev) |
78 | { |
79 | Standard_Integer anInteger; |
80 | if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger)) |
81 | { |
82 | TCollection_ExtendedString aMessageString = |
83 | TCollection_ExtendedString("Cannot retrieve integer member" |
84 | " for previous functions of GraphNode attribute"); |
83ae3591 |
85 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
86 | return Standard_False; |
87 | } |
88 | G->AddPrevious(anInteger); |
89 | } |
90 | else |
91 | { |
92 | Standard_CString aValueStr = |
93 | Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString()); |
94 | |
95 | for (ind = aFirstIndPrev; ind <= aLastIndPrev; ind++) |
96 | { |
97 | if (!XmlObjMgt::GetInteger(aValueStr, aValue)) |
98 | { |
99 | TCollection_ExtendedString aMessageString = |
100 | TCollection_ExtendedString("Cannot retrieve integer member" |
101 | " for previous functions of GraphNode attribute as \"") |
102 | + aValueStr + "\""; |
83ae3591 |
103 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
104 | return Standard_False; |
105 | } |
106 | G->AddPrevious(aValue); |
107 | } |
108 | } |
109 | |
110 | |
111 | // Next |
112 | // ==== |
113 | |
114 | // Read the FirstIndex; if the attribute is absent initialize to 1 |
115 | aFirstIndNext = aLastIndPrev + 1; // It is absent :-) because I didn't wrote it on the stage of writing the file. |
116 | |
117 | // Read the LastIndex; the attribute should present |
118 | if (!anElement.getAttribute(::LastNextIndex()).GetInteger(aLastIndNext)) |
119 | { |
120 | TCollection_ExtendedString aMessageString = |
121 | TCollection_ExtendedString("Cannot retrieve the last index" |
122 | " for next functions of GraphNode attribute"); |
83ae3591 |
123 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
124 | return Standard_False; |
125 | } |
126 | aLastIndNext += aLastIndPrev; |
127 | |
128 | Standard_CString aValueStr = |
129 | Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString()); |
130 | |
131 | for (ind = 1; ind <= aLastIndNext; ind++) |
132 | { |
133 | if (!XmlObjMgt::GetInteger(aValueStr, aValue)) |
134 | { |
135 | TCollection_ExtendedString aMessageString = |
136 | TCollection_ExtendedString("Cannot retrieve integer member" |
137 | " for next functions of GraphNode attribute as \"") |
138 | + aValueStr + "\""; |
83ae3591 |
139 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
140 | return Standard_False; |
141 | } |
142 | if (ind < aFirstIndNext) |
143 | continue; |
144 | G->AddNext(aValue); |
145 | } |
146 | |
147 | // Execution status |
148 | Standard_Integer exec = 0; |
149 | if (!anElement.getAttribute(::ExecutionStatus()).GetInteger(exec)) |
150 | { |
151 | TCollection_ExtendedString aMessageString = |
152 | TCollection_ExtendedString("Cannot retrieve the execution status" |
153 | " for GraphNode attribute"); |
83ae3591 |
154 | myMessageDriver->Send (aMessageString, Message_Fail); |
7fd59977 |
155 | return Standard_False; |
156 | } |
157 | G->SetStatus((TFunction_ExecutionStatus) exec); |
158 | |
159 | return Standard_True; |
160 | } |
161 | |
162 | //======================================================================= |
163 | //function : Paste |
164 | //purpose : transient -> persistent (store) |
165 | //======================================================================= |
166 | void XmlMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource, |
167 | XmlObjMgt_Persistent& theTarget, |
168 | XmlObjMgt_SRelocationTable& ) const |
169 | { |
170 | Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(theSource); |
171 | |
172 | // Previous |
173 | // ======== |
174 | |
175 | theTarget.Element().setAttribute(::LastPreviousIndex(), G->GetPrevious().Extent()); |
176 | |
177 | TCollection_AsciiString aValueStr; |
178 | TColStd_MapIteratorOfMapOfInteger itrm(G->GetPrevious()); |
179 | for (; itrm.More(); itrm.Next()) |
180 | { |
181 | const Standard_Integer ID = itrm.Key(); |
182 | aValueStr += TCollection_AsciiString(ID); |
183 | aValueStr += ' '; |
184 | } |
6e448ab0 |
185 | |
186 | // add more spaces between "previous" and "next" ids to make them easily |
187 | // recognizable for human |
188 | aValueStr += " "; |
7fd59977 |
189 | |
190 | // Next |
191 | // ==== |
192 | |
193 | theTarget.Element().setAttribute(::LastNextIndex(), G->GetNext().Extent()); |
194 | |
195 | itrm.Initialize(G->GetNext()); |
196 | for (; itrm.More(); itrm.Next()) |
197 | { |
198 | const Standard_Integer ID = itrm.Key(); |
199 | aValueStr += TCollection_AsciiString(ID); |
200 | aValueStr += ' '; |
201 | } |
202 | |
203 | XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True); |
204 | |
205 | // Execution status |
206 | theTarget.Element().setAttribute(::ExecutionStatus(), (Standard_Integer) G->GetStatus()); |
207 | } |