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.
18 #include <GeomTools.hxx>
21 #include <Message_ProgressIndicator.hxx>
22 #include <Message_ProgressSentry.hxx>
23 #include <Precision.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <Standard_Stream.hxx>
26 #include <TopLoc_Location.hxx>
27 #include <TopTools_LocationSet.hxx>
29 //=======================================================================
30 //function : TopTools_LocationSet
32 //=======================================================================
33 TopTools_LocationSet::TopTools_LocationSet()
38 //=======================================================================
41 //=======================================================================
43 void TopTools_LocationSet::Clear()
49 //=======================================================================
52 //=======================================================================
54 Standard_Integer TopTools_LocationSet::Add(const TopLoc_Location& L)
56 if (L.IsIdentity()) return 0;
57 Standard_Integer n = myMap.FindIndex(L);
59 TopLoc_Location N = L;
61 myMap.Add(N.FirstDatum());
63 } while (!N.IsIdentity());
68 //=======================================================================
71 //=======================================================================
73 const TopLoc_Location& TopTools_LocationSet::Location
74 (const Standard_Integer I)const
76 static TopLoc_Location identity;
77 if (I <= 0 || I > myMap.Extent()) return identity;
82 //=======================================================================
85 //=======================================================================
87 Standard_Integer TopTools_LocationSet::Index(const TopLoc_Location& L) const
89 if (L.IsIdentity()) return 0;
90 return myMap.FindIndex(L);
93 //=======================================================================
96 //=======================================================================
98 static void WriteTrsf(const gp_Trsf& T,
100 const Standard_Boolean compact)
102 gp_XYZ V = T.TranslationPart();
103 gp_Mat M = T.VectorialPart();
105 if (!compact) OS << "( ";
106 OS << setw(15) << M(1,1) << " ";
107 OS << setw(15) << M(1,2) << " ";
108 OS << setw(15) << M(1,3) << " ";
109 OS << setw(15) << V.Coord(1) << " ";
110 if (!compact) OS << " )";
112 if (!compact) OS << "( ";
113 OS << setw(15) << M(2,1) << " ";
114 OS << setw(15) << M(2,2) << " ";
115 OS << setw(15) << M(2,3) << " ";
116 OS << setw(15) << V.Coord(2) << " ";
117 if (!compact) OS << " )";
119 if (!compact) OS << "( ";
120 OS << setw(15) << M(3,1) << " ";
121 OS << setw(15) << M(3,2) << " ";
122 OS << setw(15) << M(3,3) << " ";
123 OS << setw(15) << V.Coord(3) << " ";
124 if (!compact) OS << " )";
128 //=======================================================================
131 //=======================================================================
133 void TopTools_LocationSet::Dump(Standard_OStream& OS) const
135 Standard_Integer i, nbLoc = myMap.Extent();
139 OS << "\n Dump of "<< nbLoc << " Locations";
140 OS << "\n -------\n\n";
142 for (i = 1; i <= nbLoc; i++) {
143 TopLoc_Location L = myMap(i);
144 OS << setw(5) << i << " : \n";
146 TopLoc_Location L2 = L.NextLocation();
147 Standard_Boolean simple = L2.IsIdentity();
148 Standard_Integer p = L.FirstPower();
149 TopLoc_Location L1 = L.FirstDatum();
150 Standard_Boolean elementary = (simple && p == 1);
152 OS << "Elementary location\n";
155 OS << "Complex : L"<<myMap.FindIndex(L1);
156 if (p != 1) OS <<"^"<<p;
157 while (!L2.IsIdentity()) {
158 L1 = L2.FirstDatum();
160 L2 = L2.NextLocation();
161 OS << " * L" << myMap.FindIndex(L1);
162 if (p != 1) OS << "^"<<p;
166 WriteTrsf(L.Transformation(),OS,Standard_False);
170 //=======================================================================
173 //=======================================================================
175 void TopTools_LocationSet::Write(Standard_OStream& OS) const
178 std::streamsize prec = OS.precision(15);
180 Standard_Integer i, nbLoc = myMap.Extent();
181 OS << "Locations " << nbLoc << "\n";
184 Message_ProgressSentry PS(GetProgress(), "Locations", 0, nbLoc, 1);
185 for (i = 1; i <= nbLoc && PS.More(); i++, PS.Next()) {
186 TopLoc_Location L = myMap(i);
189 TopLoc_Location L2 = L.NextLocation();
190 Standard_Boolean simple = L2.IsIdentity();
191 Standard_Integer p = L.FirstPower();
192 TopLoc_Location L1 = L.FirstDatum();
193 Standard_Boolean elementary = (simple && p == 1);
196 WriteTrsf(L.Transformation(),OS,Standard_True);
200 OS << " "<<myMap.FindIndex(L1) << " "<<p;
201 while (!L2.IsIdentity()) {
202 L1 = L2.FirstDatum();
204 L2 = L2.NextLocation();
205 OS << " "<<myMap.FindIndex(L1) << " "<<p;
213 //=======================================================================
216 //=======================================================================
218 static void ReadTrsf(gp_Trsf& T,
219 Standard_IStream& IS)
221 Standard_Real V1[3],V2[3],V3[3];
224 GeomTools::GetReal(IS, V1[0]);
225 GeomTools::GetReal(IS, V1[1]);
226 GeomTools::GetReal(IS, V1[2]);
227 GeomTools::GetReal(IS, V[0]);
229 GeomTools::GetReal(IS, V2[0]);
230 GeomTools::GetReal(IS, V2[1]);
231 GeomTools::GetReal(IS, V2[2]);
232 GeomTools::GetReal(IS, V[1]);
234 GeomTools::GetReal(IS, V3[0]);
235 GeomTools::GetReal(IS, V3[1]);
236 GeomTools::GetReal(IS, V3[2]);
237 GeomTools::GetReal(IS, V[2]);
239 T.SetValues(V1[0],V1[1],V1[2],V[0],
240 V2[0],V2[1],V2[2],V[1],
241 V3[0],V3[1],V3[2],V[2]);
244 //=======================================================================
247 //=======================================================================
249 void TopTools_LocationSet::Read(Standard_IStream& IS)
254 Standard_Integer l1,p;
257 if (strcmp(buffer,"Locations")) {
258 cout << "Not a location table "<<endl;
262 Standard_Integer i, nbLoc;
269 Message_ProgressSentry PS(GetProgress(), "Locations", 0, nbLoc, 1);
270 for (i = 1; i <= nbLoc&& PS.More(); i++, PS.Next()) {
271 Standard_Integer typLoc;
279 else if (typLoc == 2) {
280 L = TopLoc_Location();
284 TopLoc_Location L1 = myMap(l1);
285 L = L1.Powered(p) *L;
290 if (!L.IsIdentity()) myMap.Add(L);
294 //=======================================================================
295 //function : GetProgress
297 //=======================================================================
299 Handle(Message_ProgressIndicator) TopTools_LocationSet::GetProgress() const
304 //=======================================================================
305 //function : SetProgress
307 //=======================================================================
309 void TopTools_LocationSet::SetProgress(const Handle(Message_ProgressIndicator)& PR)