1 // Created on: 2001-09-11
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <XmlMXCAFDoc_LocationDriver.ixx>
18 #include <XCAFDoc_Location.hxx>
19 #include <XmlObjMgt_Document.hxx>
20 #include <XmlObjMgt_DOMString.hxx>
21 #include <XmlObjMgt_Persistent.hxx>
22 #include <XmlObjMgt.hxx>
23 #include <XmlObjMgt_GP.hxx>
24 #include <TopLoc_Datum3D.hxx>
26 #include <XmlMNaming.hxx>
27 #include <TopTools_LocationSet.hxx>
29 IMPLEMENT_DOMSTRING (DatumString, "datum")
30 IMPLEMENT_DOMSTRING (LocationString, "location")
31 IMPLEMENT_DOMSTRING (PowerString, "power")
32 IMPLEMENT_DOMSTRING (TrsfString, "trsf")
33 IMPLEMENT_DOMSTRING (LocIdString, "locId")
35 //=======================================================================
36 //function : XmlMXCAFDoc_LocationDriver
37 //purpose : Constructor
38 //=======================================================================
39 XmlMXCAFDoc_LocationDriver::XmlMXCAFDoc_LocationDriver
40 (const Handle(CDM_MessageDriver)& theMsgDriver)
41 : XmlMDF_ADriver (theMsgDriver, "xcaf", "Location")
45 //=======================================================================
48 //=======================================================================
49 Handle(TDF_Attribute) XmlMXCAFDoc_LocationDriver::NewEmpty() const
51 return (new XCAFDoc_Location());
54 //=======================================================================
57 //=======================================================================
58 Standard_Boolean XmlMXCAFDoc_LocationDriver::Paste
59 (const XmlObjMgt_Persistent& theSource,
60 const Handle(TDF_Attribute)& theTarget,
61 XmlObjMgt_RRelocationTable& theRelocTable) const
64 Translate (theSource.Element(), aLoc, theRelocTable);
66 Handle(XCAFDoc_Location) aT = Handle(XCAFDoc_Location)::DownCast (theTarget);
72 //=======================================================================
75 //=======================================================================
76 void XmlMXCAFDoc_LocationDriver::Paste
77 (const Handle(TDF_Attribute)& theSource,
78 XmlObjMgt_Persistent& theTarget,
79 XmlObjMgt_SRelocationTable& theRelocTable) const
81 Handle(XCAFDoc_Location) aS = Handle(XCAFDoc_Location)::DownCast(theSource);
82 XmlObjMgt_Element anElem = theTarget.Element();
83 Translate (aS->Get(), anElem, theRelocTable);
86 //=======================================================================
87 //function : Translate
88 //purpose : .. from Transient to Persistent
89 //=======================================================================
90 void XmlMXCAFDoc_LocationDriver::Translate (const TopLoc_Location& theLoc,
91 XmlObjMgt_Element& theParent,
92 XmlObjMgt_SRelocationTable& theMap) const
94 if (theLoc.IsIdentity())
99 // The location is not identity
100 if( myLocations == 0 )
102 #ifdef XMLMXCAFDOC_DEB
103 cout<<"Pointer to LocationSet is NULL\n";
108 // Create Location element
109 XmlObjMgt_Document aDoc = theParent.getOwnerDocument();
110 XmlObjMgt_Element aLocElem = aDoc.createElement(::LocationString());
112 Standard_Integer anId = myLocations->Add(theLoc);
114 aLocElem.setAttribute (::LocIdString(), anId);
115 theParent.appendChild (aLocElem);
118 // In earlier version of this driver a datums from location stored in
119 // the relocation table, but now it's not necessary
120 // (try to uncomment it if some problems appear)
122 Handle(TopLoc_Datum3D) aDatum = theLoc.FirstDatum();
124 if(!theMap.Contains(aDatum)) {
129 // Add next Location from the list
130 Translate (theLoc.NextLocation(), aLocElem, theMap);
133 //=======================================================================
134 //function : Translate
135 //purpose : .. from Persistent to Transient
136 //=======================================================================
137 Standard_Boolean XmlMXCAFDoc_LocationDriver::Translate
138 (const XmlObjMgt_Element& theParent,
139 TopLoc_Location& theLoc,
140 XmlObjMgt_RRelocationTable& theMap) const
142 XmlObjMgt_Element aLocElem =
143 XmlObjMgt::FindChildByName (theParent, ::LocationString());
144 if (aLocElem == NULL)
145 return Standard_False;
147 Standard_Integer aFileVer = XmlMNaming::DocumentVersion();
148 if( aFileVer > 5 && myLocations == 0 )
150 return Standard_False;
153 Standard_Integer aPower;
154 Handle(TopLoc_Datum3D) aDatum;
159 Standard_Integer anId;
160 aLocElem.getAttribute (::LocIdString()).GetInteger (anId);
162 const TopLoc_Location& aLoc = myLocations->Location(anId);
163 aPower = aLoc.FirstPower();
164 aDatum = aLoc.FirstDatum();
168 aLocElem.getAttribute (::PowerString()).GetInteger (aPower);
171 XmlObjMgt_Persistent aPD (aLocElem, ::DatumString());
173 Standard_Integer aDatumID;
174 aLocElem.getAttribute (::DatumString()).GetInteger (aDatumID);
175 if (aDatumID > 0 && theMap.IsBound (aDatumID))
176 aDatum = (Handle(TopLoc_Datum3D)&) theMap.Find (aDatumID);
178 return Standard_False;
181 XmlObjMgt_GP::Translate (aPD.Element().getAttribute(::TrsfString()), aTrsf);
182 aDatum = new TopLoc_Datum3D (aTrsf);
183 theMap.Bind (aPD.Id(), aDatum);
188 TopLoc_Location aNextLoc;
189 Translate (aLocElem, aNextLoc, theMap);
191 // Calculate the result
192 theLoc = aNextLoc * TopLoc_Location (aDatum).Powered (aPower);
193 return Standard_True;