1 // Created on: 2004-06-15
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2004-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.
17 #include <BinTools.hxx>
18 #include <BinTools_LocationSet.hxx>
21 #include <Precision.hxx>
22 #include <Standard_ErrorHandler.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <TopLoc_Location.hxx>
26 //=======================================================================
27 //function : operator >> (gp_Trsf& T)
29 //=======================================================================
30 static Standard_IStream& operator >>(Standard_IStream& IS, gp_Trsf& T)
32 Standard_Real V1[3],V2[3],V3[3];
35 BinTools::GetReal(IS, V1[0]);
36 BinTools::GetReal(IS, V1[1]);
37 BinTools::GetReal(IS, V1[2]);
38 BinTools::GetReal(IS, V[0]);
40 BinTools::GetReal(IS, V2[0]);
41 BinTools::GetReal(IS, V2[1]);
42 BinTools::GetReal(IS, V2[2]);
43 BinTools::GetReal(IS, V[1]);
45 BinTools::GetReal(IS, V3[0]);
46 BinTools::GetReal(IS, V3[1]);
47 BinTools::GetReal(IS, V3[2]);
48 BinTools::GetReal(IS, V[2]);
50 T.SetValues(V1[0],V1[1],V1[2],V[0],
51 V2[0],V2[1],V2[2],V[1],
52 V3[0],V3[1],V3[2],V[2]);
56 //=======================================================================
57 //function : operator << (gp_Trsf& T)
59 //=======================================================================
60 static Standard_OStream& operator <<(Standard_OStream& OS,const gp_Trsf& T)
62 gp_XYZ V = T.TranslationPart();
63 gp_Mat M = T.VectorialPart();
65 BinTools::PutReal(OS, M(1,1));
66 BinTools::PutReal(OS, M(1,2));
67 BinTools::PutReal(OS, M(1,3));
68 BinTools::PutReal(OS,V.Coord(1));
70 BinTools::PutReal(OS, M(2,1));
71 BinTools::PutReal(OS, M(2,2));
72 BinTools::PutReal(OS, M(2,3));
73 BinTools::PutReal(OS,V.Coord(2));
75 BinTools::PutReal(OS, M(3,1));
76 BinTools::PutReal(OS, M(3,2));
77 BinTools::PutReal(OS, M(3,3));
78 BinTools::PutReal(OS,V.Coord(3));
83 //=======================================================================
84 //function : BinTools_LocationSet
86 //=======================================================================
88 BinTools_LocationSet::BinTools_LocationSet()
93 //=======================================================================
96 //=======================================================================
98 void BinTools_LocationSet::Clear()
104 //=======================================================================
107 //=======================================================================
109 Standard_Integer BinTools_LocationSet::Add(const TopLoc_Location& L)
111 if (L.IsIdentity()) return 0;
112 Standard_Integer n = myMap.FindIndex(L);
114 TopLoc_Location N = L;
116 myMap.Add(N.FirstDatum());
117 N = N.NextLocation();
118 } while (!N.IsIdentity());
123 //=======================================================================
124 //function : Location
126 //=======================================================================
128 const TopLoc_Location& BinTools_LocationSet::Location
129 (const Standard_Integer I)const
131 static TopLoc_Location identity;
132 if (I == 0) return identity;
133 else return myMap(I);
137 //=======================================================================
140 //=======================================================================
142 Standard_Integer BinTools_LocationSet::Index(const TopLoc_Location& L) const
144 if (L.IsIdentity()) return 0;
145 return myMap.FindIndex(L);
148 //=======================================================================
149 //function : NbLocations
151 //=======================================================================
153 Standard_Integer BinTools_LocationSet::NbLocations() const
155 return myMap.Extent();
158 //=======================================================================
159 //function : Write locations
161 //=======================================================================
163 void BinTools_LocationSet::Write(Standard_OStream& OS) const
166 Standard_Integer i, nbLoc = myMap.Extent();
167 OS << "Locations "<< nbLoc << "\n";
170 for (i = 1; i <= nbLoc; i++) {
171 TopLoc_Location L = myMap(i);
173 TopLoc_Location L2 = L.NextLocation();
174 Standard_Boolean simple = L2.IsIdentity();
175 Standard_Integer p = L.FirstPower();
176 TopLoc_Location L1 = L.FirstDatum();
177 Standard_Boolean elementary = (simple && p == 1);
180 OS.put((Standard_Byte)1); // 1
181 OS << L.Transformation();
184 OS.put((Standard_Byte)2); // 2
185 BinTools::PutInteger(OS, myMap.FindIndex(L1));
186 BinTools::PutInteger(OS, p);
187 while (!L2.IsIdentity()) {
188 L1 = L2.FirstDatum();
190 L2 = L2.NextLocation();
191 BinTools::PutInteger(OS, myMap.FindIndex(L1));
192 BinTools::PutInteger(OS, p);
195 BinTools::PutInteger(OS, 0);
199 catch(Standard_Failure const& anException) {
200 Standard_SStream aMsg;
201 aMsg << "EXCEPTION in BinTools_LocatioSet::Write(..)" << std::endl;
202 aMsg << anException << std::endl;
203 throw Standard_Failure(aMsg.str().c_str());
207 //=======================================================================
210 //=======================================================================
211 void BinTools_LocationSet::Read(Standard_IStream& IS)
216 Standard_Integer l1,p;
219 if (IS.fail() || (strcmp(buffer,"Locations"))) {
220 Standard_SStream aMsg;
221 aMsg << "BinTools_LocationSet::Read: Not a location table"<<std::endl;
222 throw Standard_Failure(aMsg.str().c_str());
226 Standard_Integer i, nbLoc;
228 IS.get();// remove lf
234 for (i = 1; i <= nbLoc; i++) {
236 const Standard_Byte aTypLoc = (Standard_Byte)IS.get();
242 else if (aTypLoc == 2) {
243 L = TopLoc_Location();
244 BinTools::GetInteger(IS, l1); //Index
246 BinTools::GetInteger(IS, p);
247 TopLoc_Location L1 = myMap(l1);
248 L = L1.Powered(p) *L;
249 BinTools::GetInteger(IS, l1);
252 Standard_SStream aMsg;
253 aMsg << "Unexpected location's type = " << aTypLoc << std::endl;
254 throw Standard_Failure(aMsg.str().c_str());
256 if (!L.IsIdentity()) myMap.Add(L);
259 catch(Standard_Failure const& anException) {
260 Standard_SStream aMsg;
261 aMsg << "EXCEPTION in BinTools_LocationSet::Read(..)" << std::endl;
262 aMsg << anException << std::endl;
263 throw Standard_Failure(aMsg.str().c_str());