1 // Created on: 1993-07-16
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_Stream.hxx>
18 #include <TopTools_LocationSet.ixx>
19 #include <TopLoc_Location.hxx>
20 #include <Message_ProgressSentry.hxx>
22 #include <GeomTools.hxx>
25 #include <Precision.hxx>
27 //=======================================================================
28 //function : TopTools_LocationSet
30 //=======================================================================
32 TopTools_LocationSet::TopTools_LocationSet()
37 //=======================================================================
40 //=======================================================================
42 void TopTools_LocationSet::Clear()
48 //=======================================================================
51 //=======================================================================
53 Standard_Integer TopTools_LocationSet::Add(const TopLoc_Location& L)
55 if (L.IsIdentity()) return 0;
56 Standard_Integer n = myMap.FindIndex(L);
58 TopLoc_Location N = L;
60 myMap.Add(N.FirstDatum());
62 } while (!N.IsIdentity());
67 //=======================================================================
70 //=======================================================================
72 const TopLoc_Location& TopTools_LocationSet::Location
73 (const Standard_Integer I)const
75 static TopLoc_Location identity;
76 if (I <= 0 || I > myMap.Extent()) return identity;
81 //=======================================================================
84 //=======================================================================
86 Standard_Integer TopTools_LocationSet::Index(const TopLoc_Location& L) const
88 if (L.IsIdentity()) return 0;
89 return myMap.FindIndex(L);
92 //=======================================================================
95 //=======================================================================
97 static void WriteTrsf(const gp_Trsf& T,
99 const Standard_Boolean compact)
101 gp_XYZ V = T.TranslationPart();
102 gp_Mat M = T.VectorialPart();
104 if (!compact) OS << "( ";
105 OS << setw(15) << M(1,1) << " ";
106 OS << setw(15) << M(1,2) << " ";
107 OS << setw(15) << M(1,3) << " ";
108 OS << setw(15) << V.Coord(1) << " ";
109 if (!compact) OS << " )";
111 if (!compact) OS << "( ";
112 OS << setw(15) << M(2,1) << " ";
113 OS << setw(15) << M(2,2) << " ";
114 OS << setw(15) << M(2,3) << " ";
115 OS << setw(15) << V.Coord(2) << " ";
116 if (!compact) OS << " )";
118 if (!compact) OS << "( ";
119 OS << setw(15) << M(3,1) << " ";
120 OS << setw(15) << M(3,2) << " ";
121 OS << setw(15) << M(3,3) << " ";
122 OS << setw(15) << V.Coord(3) << " ";
123 if (!compact) OS << " )";
127 //=======================================================================
130 //=======================================================================
132 void TopTools_LocationSet::Dump(Standard_OStream& OS) const
134 Standard_Integer i, nbLoc = myMap.Extent();
138 OS << "\n Dump of "<< nbLoc << " Locations";
139 OS << "\n -------\n\n";
141 for (i = 1; i <= nbLoc; i++) {
142 TopLoc_Location L = myMap(i);
143 OS << setw(5) << i << " : \n";
145 TopLoc_Location L2 = L.NextLocation();
146 Standard_Boolean simple = L2.IsIdentity();
147 Standard_Integer p = L.FirstPower();
148 TopLoc_Location L1 = L.FirstDatum();
149 Standard_Boolean elementary = (simple && p == 1);
151 OS << "Elementary location\n";
154 OS << "Complex : L"<<myMap.FindIndex(L1);
155 if (p != 1) OS <<"^"<<p;
156 while (!L2.IsIdentity()) {
157 L1 = L2.FirstDatum();
159 L2 = L2.NextLocation();
160 OS << " * L" << myMap.FindIndex(L1);
161 if (p != 1) OS << "^"<<p;
165 WriteTrsf(L.Transformation(),OS,Standard_False);
169 //=======================================================================
172 //=======================================================================
174 void TopTools_LocationSet::Write(Standard_OStream& OS) const
177 std::streamsize prec = OS.precision(15);
179 Standard_Integer i, nbLoc = myMap.Extent();
180 OS << "Locations " << nbLoc << "\n";
183 Message_ProgressSentry PS(GetProgress(), "Locations", 0, nbLoc, 1);
184 for (i = 1; i <= nbLoc && PS.More(); i++, PS.Next()) {
185 TopLoc_Location L = myMap(i);
188 TopLoc_Location L2 = L.NextLocation();
189 Standard_Boolean simple = L2.IsIdentity();
190 Standard_Integer p = L.FirstPower();
191 TopLoc_Location L1 = L.FirstDatum();
192 Standard_Boolean elementary = (simple && p == 1);
195 WriteTrsf(L.Transformation(),OS,Standard_True);
199 OS << " "<<myMap.FindIndex(L1) << " "<<p;
200 while (!L2.IsIdentity()) {
201 L1 = L2.FirstDatum();
203 L2 = L2.NextLocation();
204 OS << " "<<myMap.FindIndex(L1) << " "<<p;
212 //=======================================================================
215 //=======================================================================
217 static void ReadTrsf(gp_Trsf& T,
218 Standard_IStream& IS)
220 Standard_Real V1[3],V2[3],V3[3];
223 GeomTools::GetReal(IS, V1[0]);
224 GeomTools::GetReal(IS, V1[1]);
225 GeomTools::GetReal(IS, V1[2]);
226 GeomTools::GetReal(IS, V[0]);
228 GeomTools::GetReal(IS, V2[0]);
229 GeomTools::GetReal(IS, V2[1]);
230 GeomTools::GetReal(IS, V2[2]);
231 GeomTools::GetReal(IS, V[1]);
233 GeomTools::GetReal(IS, V3[0]);
234 GeomTools::GetReal(IS, V3[1]);
235 GeomTools::GetReal(IS, V3[2]);
236 GeomTools::GetReal(IS, V[2]);
238 T.SetValues(V1[0],V1[1],V1[2],V[0],
239 V2[0],V2[1],V2[2],V[1],
240 V3[0],V3[1],V3[2],V[2],
241 Precision::Angular(),
242 Precision::Confusion());
245 //=======================================================================
248 //=======================================================================
250 void TopTools_LocationSet::Read(Standard_IStream& IS)
255 Standard_Integer l1,p;
258 if (strcmp(buffer,"Locations")) {
259 cout << "Not a location table "<<endl;
263 Standard_Integer i, nbLoc;
270 Message_ProgressSentry PS(GetProgress(), "Locations", 0, nbLoc, 1);
271 for (i = 1; i <= nbLoc&& PS.More(); i++, PS.Next()) {
272 Standard_Integer typLoc;
280 else if (typLoc == 2) {
281 L = TopLoc_Location();
285 TopLoc_Location L1 = myMap(l1);
286 L = L1.Powered(p) *L;
291 if (!L.IsIdentity()) myMap.Add(L);
295 //=======================================================================
296 //function : GetProgress
298 //=======================================================================
300 Handle(Message_ProgressIndicator) TopTools_LocationSet::GetProgress() const
305 //=======================================================================
306 //function : SetProgress
308 //=======================================================================
310 void TopTools_LocationSet::SetProgress(const Handle(Message_ProgressIndicator)& PR)