0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / XmlMFunction / XmlMFunction_GraphNodeDriver.cxx
CommitLineData
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>
7fd59977 19#include <TColStd_MapIteratorOfMapOfInteger.hxx>
42cf5bc1 20#include <TDF_Attribute.hxx>
21#include <TFunction_GraphNode.hxx>
22#include <XmlMFunction_GraphNodeDriver.hxx>
23#include <XmlObjMgt.hxx>
24#include <XmlObjMgt_Persistent.hxx>
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(XmlMFunction_GraphNodeDriver,XmlMDF_ADriver)
7fd59977 27IMPLEMENT_DOMSTRING (LastPreviousIndex, "lastprev")
28IMPLEMENT_DOMSTRING (LastNextIndex, "lastnext")
29IMPLEMENT_DOMSTRING (ExecutionStatus, "exec")
30
31//=======================================================================
32//function : XmlMFunction_GraphNodeDriver
33//purpose : Constructor
34//=======================================================================
83ae3591 35XmlMFunction_GraphNodeDriver::XmlMFunction_GraphNodeDriver(const Handle(Message_Messenger)& theMsgDriver)
7fd59977 36 : XmlMDF_ADriver (theMsgDriver, NULL)
37{
38
39}
40
41//=======================================================================
42//function : NewEmpty
43//purpose :
44//=======================================================================
45Handle(TDF_Attribute) XmlMFunction_GraphNodeDriver::NewEmpty() const
46{
47 return (new TFunction_GraphNode());
48}
49
50//=======================================================================
51//function : Paste
52//purpose : persistent -> transient (retrieve)
53//=======================================================================
54Standard_Boolean XmlMFunction_GraphNodeDriver::Paste(const XmlObjMgt_Persistent& theSource,
83ae3591 55 const Handle(TDF_Attribute)& theTarget,
56 XmlObjMgt_RRelocationTable& ) const
7fd59977 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");
83ae3591 75 myMessageDriver->Send (aMessageString, Message_Fail);
7fd59977 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");
83ae3591 87 myMessageDriver->Send (aMessageString, Message_Fail);
7fd59977 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 + "\"";
83ae3591 105 myMessageDriver->Send (aMessageString, Message_Fail);
7fd59977 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");
83ae3591 125 myMessageDriver->Send (aMessageString, Message_Fail);
7fd59977 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 + "\"";
83ae3591 141 myMessageDriver->Send (aMessageString, Message_Fail);
7fd59977 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");
83ae3591 156 myMessageDriver->Send (aMessageString, Message_Fail);
7fd59977 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//=======================================================================
168void 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 }
6e448ab0 187
188 // add more spaces between "previous" and "next" ids to make them easily
189 // recognizable for human
190 aValueStr += " ";
7fd59977 191
192 // Next
193 // ====
194
195 theTarget.Element().setAttribute(::LastNextIndex(), G->GetNext().Extent());
196
197 itrm.Initialize(G->GetNext());
198 for (; itrm.More(); itrm.Next())
199 {
200 const Standard_Integer ID = itrm.Key();
201 aValueStr += TCollection_AsciiString(ID);
202 aValueStr += ' ';
203 }
204
205 XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
206
207 // Execution status
208 theTarget.Element().setAttribute(::ExecutionStatus(), (Standard_Integer) G->GetStatus());
209}