0024830: Remove redundant keyword 'mutable' in CDL declarations
[occt.git] / src / XmlMNaming / XmlMNaming_NamingDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-08-31
2// Created by: Julia DOROVSKIKH
973c2be1 3// Copyright (c) 2001-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
16#include <XmlMNaming_NamingDriver.ixx>
17
18#include <XmlObjMgt.hxx>
19#include <XmlMNaming.hxx>
20#include <TNaming_Name.hxx>
21#include <TNaming_Naming.hxx>
22#include <TNaming_NamedShape.hxx>
23#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
7dcac1df 24#include <TNaming_Iterator.hxx>
7fd59977 25#include <TDF_Tool.hxx>
26
27//=======================================================================
28static TopAbs_ShapeEnum ShapeEnumFromString (const XmlObjMgt_DOMString&);
29static TNaming_NameType NameTypeFromString (const XmlObjMgt_DOMString&);
30
31static const XmlObjMgt_DOMString& ShapeEnumToString (const TopAbs_ShapeEnum);
32static const XmlObjMgt_DOMString& NameTypeToString (const TNaming_NameType);
33
34IMPLEMENT_DOMSTRING (IndexString, "index")
35IMPLEMENT_DOMSTRING (StopNamedShapeString, "stopNS")
36IMPLEMENT_DOMSTRING (TypeString, "nametype")
37IMPLEMENT_DOMSTRING (ShapeTypeString, "shapetype")
38IMPLEMENT_DOMSTRING (ArgumentsString, "arguments")
39IMPLEMENT_DOMSTRING (ContextLabelString, "contextlabel")
7dcac1df 40IMPLEMENT_DOMSTRING (OrientString, "orientation")
7fd59977 41
42IMPLEMENT_DOMSTRING (NTUnknownString, "unknown")
43IMPLEMENT_DOMSTRING (NTIdentityString, "identity")
44IMPLEMENT_DOMSTRING (NTModifUntilString, "modifuntil")
45IMPLEMENT_DOMSTRING (NTGenerationString, "generation")
46IMPLEMENT_DOMSTRING (NTIntersectionString, "intersection")
47IMPLEMENT_DOMSTRING (NTUnionString, "union")
48IMPLEMENT_DOMSTRING (NTSubtractionString, "subtraction")
49IMPLEMENT_DOMSTRING (NTConstShapeString, "constshape")
50IMPLEMENT_DOMSTRING (NTFilterByNeighString, "filterbyneigh")
51IMPLEMENT_DOMSTRING (NTOrientationString, "orientation")
1ec8a59e 52IMPLEMENT_DOMSTRING (NTWireInString, "wirein")
53IMPLEMENT_DOMSTRING (NTShellInString, "shellin")
7fd59977 54
55IMPLEMENT_DOMSTRING (ShCompoundString, "compound")
56IMPLEMENT_DOMSTRING (ShCompsolidString, "compsolid")
57IMPLEMENT_DOMSTRING (ShSolidString, "solid")
58IMPLEMENT_DOMSTRING (ShShellString, "shell")
59IMPLEMENT_DOMSTRING (ShFaceString, "face")
60IMPLEMENT_DOMSTRING (ShWireString, "wire")
61IMPLEMENT_DOMSTRING (ShEdgeString, "edge")
62IMPLEMENT_DOMSTRING (ShVertexString, "vertex")
63IMPLEMENT_DOMSTRING (ShShapeString, "shape")
64
65//=======================================================================
66//function : XmlMNaming_NamingDriver
67//purpose : Constructor
68//=======================================================================
69XmlMNaming_NamingDriver::XmlMNaming_NamingDriver
70 (const Handle(CDM_MessageDriver)& theMsgDriver)
71 : XmlMDF_ADriver (theMsgDriver, NULL)
72{}
73
74//=======================================================================
75//function : NewEmpty
76//purpose :
77//=======================================================================
78Handle(TDF_Attribute) XmlMNaming_NamingDriver::NewEmpty() const
79{
80 return (new TNaming_Naming());
81}
82
83//=======================================================================
84//function : Paste
85//purpose : persistent -> transient (retrieve)
86//=======================================================================
87Standard_Boolean XmlMNaming_NamingDriver::Paste
88 (const XmlObjMgt_Persistent& theSource,
89 const Handle(TDF_Attribute)& theTarget,
90 XmlObjMgt_RRelocationTable& theRelocTable) const
91{
92 const XmlObjMgt_Element& anElem = theSource;
93 Handle(TNaming_Naming) aNg = Handle(TNaming_Naming)::DownCast(theTarget);
94
95 TNaming_Name& aNgName = aNg->ChangeName();
96
97 // type and shape type
98 aNgName.Type (NameTypeFromString (anElem.getAttribute(::TypeString())));
99 aNgName.ShapeType(ShapeEnumFromString(anElem.getAttribute(::ShapeTypeString())));
100
101 Standard_Integer aNb;
102 Handle(TNaming_NamedShape) NS;
103 TCollection_ExtendedString aMsgString;
104
105 XmlObjMgt_DOMString aDOMStr = anElem.getAttribute(::ArgumentsString());
106 if (aDOMStr != NULL)
107 {
108 Standard_CString aGs = Standard_CString(aDOMStr.GetString());
109
110 // first argument
111 if (!XmlObjMgt::GetInteger(aGs, aNb))
112 {
113 aMsgString = TCollection_ExtendedString
114 ("XmlMNaming_NamingDriver: Cannot retrieve reference "
115 "on first Argument from \"") + aDOMStr + "\"";
116 WriteMessage (aMsgString);
117 return Standard_False;
118 }
119 while (aNb > 0)
120 {
121 if (theRelocTable.IsBound(aNb))
122 NS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
123 else
124 {
125 NS = new TNaming_NamedShape;
126 theRelocTable.Bind(aNb, NS);
127 }
128 aNgName.Append(NS);
129
130 // next argument
131 if (!XmlObjMgt::GetInteger(aGs, aNb)) aNb = 0;
132 }
133 }
134
135 // stop named shape
136 aDOMStr = anElem.getAttribute(::StopNamedShapeString());
137 if (aDOMStr != NULL)
138 {
139 if (!aDOMStr.GetInteger(aNb))
140 {
141 aMsgString = TCollection_ExtendedString
142 ("XmlMNaming_NamingDriver: Cannot retrieve reference "
143 "on StopNamedShape from \"") + aDOMStr + "\"";
144 WriteMessage (aMsgString);
145 return Standard_False;
146 }
147 if (aNb > 0)
148 {
149 if (theRelocTable.IsBound(aNb))
150 NS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
151 else
152 {
153 NS = new TNaming_NamedShape;
154 theRelocTable.Bind(aNb, NS);
155 }
156 aNgName.StopNamedShape(NS);
157 }
158 }
159
160 // index
161 aDOMStr = anElem.getAttribute(::IndexString());
162 if (!aDOMStr.GetInteger(aNb))
163 {
164 aMsgString = TCollection_ExtendedString
165 ("XmlMNaming_NamingDriver: Cannot retrieve "
166 "integer value of Index from \"") + aDOMStr + "\"";
167 WriteMessage (aMsgString);
168 return Standard_False;
169 }
170 aNgName.Index(aNb);
171//
172#ifdef DEB
173 //cout << "CurDocVersion = " << XmlMNaming::DocumentVersion() <<endl;
174#endif
175 if(XmlMNaming::DocumentVersion() > 3) {
176 XmlObjMgt_DOMString aDomEntry = anElem.getAttribute(::ContextLabelString());
177 if (aDomEntry != NULL)
178 {
179 TCollection_AsciiString anEntry;
180 if (XmlObjMgt::GetTagEntryString (aDomEntry, anEntry) == Standard_False)
181 {
182 TCollection_ExtendedString aMessage =
183 TCollection_ExtendedString ("Cannot retrieve Entry from \"")
184 + aDomEntry + '\"';
185 WriteMessage (aMessage);
186 return Standard_False;
187 }
188
189 // find label by entry
190 TDF_Label tLab; // Null label.
191 if (anEntry.Length() > 0) {
192 TDF_Tool::Label(aNg->Label().Data(), anEntry, tLab, Standard_True);
193 aNgName.ContextLabel(tLab);
194#ifdef DEB
195 cout << "Retrieving Context Label = " << anEntry.ToCString() <<endl;
196#endif
197 }
198 }
199#ifdef DEB
200 else
201 cout << "Retrieving Context Label is NULL" <<endl;
202#endif
7dcac1df 203
204 if(XmlMNaming::DocumentVersion() > 4 && XmlMNaming::DocumentVersion() < 7) {
205 // Orientation processing - converting from old format
206 Handle(TNaming_NamedShape) aNS;
207 if (aNg->Label().FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
208 //const TDF_Label& aLab = aNS->Label();
209 TNaming_Iterator itL (aNS);
210 for (; itL.More(); itL.Next()) {
211 const TopoDS_Shape& S = itL.NewShape();
212 if (S.IsNull()) continue;
213 if(aNS->Evolution() == TNaming_SELECTED) {
214 if (itL.More() && itL.NewShape().ShapeType() != TopAbs_VERTEX &&
215 !itL.OldShape().IsNull() && itL.OldShape().ShapeType() == TopAbs_VERTEX ) {//OR-N
216 TopAbs_Orientation OrientationToApply = itL.OldShape().Orientation();
217 aNgName.Orientation(OrientationToApply);
218 }
219 }
220 }
221 }
222 }
223 if(XmlMNaming::DocumentVersion() > 6) {
224 aDOMStr = anElem.getAttribute(::OrientString());
225 if (!aDOMStr.GetInteger(aNb))
226 {
227 aMsgString = TCollection_ExtendedString
228 ("XmlMNaming_NamingDriver: Cannot retrieve "
229 "integer value of orientation from \"") + aDOMStr + "\"";
230 WriteMessage (aMsgString);
231 return Standard_False;
232 }
233 aNgName.Orientation((TopAbs_Orientation)aNb);
234 }
235 // or. end
7fd59977 236 }
237#ifdef DEB
238 else if(XmlMNaming::DocumentVersion() == -1)
239 cout << "Current DocVersion field is not initialized. " <<endl;
240 else
241 cout << "Current DocVersion = " << XmlMNaming::DocumentVersion() <<endl;
242#endif
243 return Standard_True;
244}
245
246//=======================================================================
247//function : Paste
248//purpose : transient -> persistent (store)
249//=======================================================================
250void XmlMNaming_NamingDriver::Paste
251 (const Handle(TDF_Attribute)& theSource,
252 XmlObjMgt_Persistent& theTarget,
253 XmlObjMgt_SRelocationTable& theRelocTable) const
254{
255 Handle(TNaming_Naming) aNg = Handle(TNaming_Naming)::DownCast(theSource);
256 XmlObjMgt_Element& anElem = theTarget;
257 const TNaming_Name& aNgName = aNg->GetName();
258
259 // type and shape type
260 anElem.setAttribute(::TypeString(), NameTypeToString(aNgName.Type()));
261 anElem.setAttribute(::ShapeTypeString(), ShapeEnumToString(aNgName.ShapeType()));
262
263 Standard_Integer aNb;
264
265 // arguments
266 Standard_Integer NbArgs = aNgName.Arguments().Extent();
267 if (NbArgs > 0)
268 {
269 TCollection_AsciiString anArgsStr;
270 for (TNaming_ListIteratorOfListOfNamedShape it (aNgName.Arguments()); it.More(); it.Next())
271 {
272 Handle(TNaming_NamedShape) anArg = it.Value();
273 aNb = 0;
274 if (!anArg.IsNull())
275 {
276 aNb = theRelocTable.FindIndex(anArg);
277 if (aNb == 0)
278 {
279 aNb = theRelocTable.Add(anArg);
280 }
281 anArgsStr += TCollection_AsciiString(aNb) + " ";
282 }
283 else anArgsStr += "0 ";
284 }
285 anElem.setAttribute(::ArgumentsString(), anArgsStr.ToCString());
286 }
287
288 // stop named shape
289 Handle(TNaming_NamedShape) aSNS = aNgName.StopNamedShape();
290 if (!aSNS.IsNull())
291 {
292 aNb = theRelocTable.FindIndex(aSNS);
293 if (aNb == 0)
294 {
295 aNb = theRelocTable.Add(aSNS);
296 }
297 anElem.setAttribute(::StopNamedShapeString(), aNb);
298 }
299
300 // index
301 anElem.setAttribute(::IndexString(), aNgName.Index());
302
303 // context label
304 TCollection_AsciiString anEntry;
305 if(!aNgName.ContextLabel().IsNull())
306 TDF_Tool::Entry(aNgName.ContextLabel(), anEntry);
307 XmlObjMgt_DOMString aDOMString;
308 XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
309 anElem.setAttribute(::ContextLabelString(), aDOMString);
310#ifdef DEB
311 cout << "XmlMNaming_NamingDriver::Store: ContextLabel Entry = " << anEntry << endl;
312 if (aDOMString != NULL)
313 {
314 Standard_CString aStr = Standard_CString(aDOMString.GetString());
315 cout << "XmlMNaming_NamingDriver::Store: ContextLabel DOMString = " << aStr << endl;
316 } else
317 cout << "XmlMNaming_NamingDriver::Store: aDOMString is NULL" <<endl;
318#endif
319
7dcac1df 320 // orientation
321 anElem.setAttribute(::OrientString(), (Standard_Integer)aNgName.Orientation());
322
7fd59977 323}
324
325//=======================================================================
326//function : ShapeEnumToString
327//purpose :
328//=======================================================================
329static const XmlObjMgt_DOMString& ShapeEnumToString (const TopAbs_ShapeEnum theE)
330{
331 switch (theE)
332 {
333 case TopAbs_COMPOUND : return ::ShCompoundString();
334 case TopAbs_COMPSOLID : return ::ShCompsolidString();
335 case TopAbs_SOLID : return ::ShSolidString();
336 case TopAbs_SHELL : return ::ShShellString();
337 case TopAbs_FACE : return ::ShFaceString();
338 case TopAbs_WIRE : return ::ShWireString();
339 case TopAbs_EDGE : return ::ShEdgeString();
340 case TopAbs_VERTEX : return ::ShVertexString();
341 case TopAbs_SHAPE : return ::ShShapeString();
342 }
343 static XmlObjMgt_DOMString aNullString;
344 return aNullString; // To avoid compilation error message.
345}
346
347//=======================================================================
348//function : NameTypeToString
349//purpose :
350//=======================================================================
351static const XmlObjMgt_DOMString& NameTypeToString (const TNaming_NameType theE)
352{
353 switch (theE)
354 {
355 case TNaming_UNKNOWN : return ::NTUnknownString();
356 case TNaming_IDENTITY : return ::NTIdentityString();
357 case TNaming_MODIFUNTIL : return ::NTModifUntilString();
358 case TNaming_GENERATION : return ::NTGenerationString();
359 case TNaming_INTERSECTION : return ::NTIntersectionString();
360 case TNaming_UNION : return ::NTUnionString();
361 case TNaming_SUBSTRACTION : return ::NTSubtractionString();
362 case TNaming_CONSTSHAPE : return ::NTConstShapeString();
363 case TNaming_FILTERBYNEIGHBOURGS : return ::NTFilterByNeighString();
364 case TNaming_ORIENTATION : return ::NTOrientationString();
365 case TNaming_WIREIN : return ::NTWireInString();
1ec8a59e 366 case TNaming_SHELLIN : return ::NTShellInString();
7fd59977 367 default:
368 Standard_DomainError::Raise("TNaming_NameType; enum term unknown ");
369 }
370 static XmlObjMgt_DOMString aNullString;
371 return aNullString; // To avoid compilation error message.
372}
373
374//=======================================================================
375//function : ShapeEnumFromString
376//purpose :
377//=======================================================================
378static TopAbs_ShapeEnum ShapeEnumFromString (const XmlObjMgt_DOMString& theString)
379{
380 TopAbs_ShapeEnum aResult = TopAbs_SHAPE;
381 if (!theString.equals (::ShShapeString()))
382 {
383 if (theString.equals (::ShCompoundString()))
384 aResult = TopAbs_COMPOUND;
385 else if (theString.equals (::ShCompsolidString()))
386 aResult = TopAbs_COMPSOLID;
387 else if (theString.equals (::ShSolidString()))
388 aResult = TopAbs_SOLID;
389 else if (theString.equals (::ShShellString()))
390 aResult = TopAbs_SHELL;
391 else if (theString.equals (::ShFaceString()))
392 aResult = TopAbs_FACE;
393 else if (theString.equals (::ShWireString()))
394 aResult = TopAbs_WIRE;
395 else if (theString.equals (::ShEdgeString()))
396 aResult = TopAbs_EDGE;
397 else if (theString.equals (::ShVertexString()))
398 aResult = TopAbs_VERTEX;
399 else
400 Standard_DomainError::Raise
401 ("TopAbs_ShapeEnum; string value without enum term equivalence");
402 }
403 return aResult;
404}
405
406//=======================================================================
407//function : NameTypeFromString
408//purpose :
409//=======================================================================
410static TNaming_NameType NameTypeFromString (const XmlObjMgt_DOMString& theString)
411{
412 TNaming_NameType aResult = TNaming_UNKNOWN;
413 if (!theString.equals (::NTUnknownString()))
414 {
415 if (theString.equals (::NTIdentityString()))
416 aResult = TNaming_IDENTITY;
417 else if (theString.equals (::NTModifUntilString()))
418 aResult = TNaming_MODIFUNTIL;
419 else if (theString.equals (::NTGenerationString()))
420 aResult = TNaming_GENERATION;
421 else if (theString.equals (::NTIntersectionString()))
422 aResult = TNaming_INTERSECTION;
423 else if (theString.equals (::NTUnionString()))
424 aResult = TNaming_UNION;
425 else if (theString.equals (::NTSubtractionString()))
426 aResult = TNaming_SUBSTRACTION;
427 else if (theString.equals (::NTConstShapeString()))
428 aResult = TNaming_CONSTSHAPE;
429 else if (theString.equals (::NTFilterByNeighString()))
430 aResult = TNaming_FILTERBYNEIGHBOURGS;
431 else if (theString.equals (::NTOrientationString()))
432 aResult = TNaming_ORIENTATION;
433 else if (theString.equals (::NTWireInString()))
434 aResult = TNaming_WIREIN;
1ec8a59e 435 else if (theString.equals (::NTShellInString()))
436 aResult = TNaming_SHELLIN;
7fd59977 437 else
438 Standard_DomainError::Raise
439 ("TNaming_NameType; string value without enum term equivalence");
440 }
441 return aResult;
442}