0031353: TDocStd_Application does not have api to set progress indicator
[occt.git] / src / TopTools / TopTools_LocationSet.cxx
CommitLineData
b311480e 1// Created on: 1993-07-16
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
71598a83 18#include <GeomTools.hxx>
7fd59977 19#include <gp_Ax3.hxx>
20#include <gp_Vec.hxx>
42cf5bc1 21#include <Message_ProgressSentry.hxx>
7fd59977 22#include <Precision.hxx>
42cf5bc1 23#include <Standard_OutOfRange.hxx>
24#include <Standard_Stream.hxx>
25#include <TopLoc_Location.hxx>
26#include <TopTools_LocationSet.hxx>
7fd59977 27
28//=======================================================================
29//function : TopTools_LocationSet
30//purpose :
31//=======================================================================
7fd59977 32TopTools_LocationSet::TopTools_LocationSet()
33{
34}
35
36
37//=======================================================================
38//function : Clear
39//purpose :
40//=======================================================================
41
42void TopTools_LocationSet::Clear()
43{
44 myMap.Clear();
45}
46
47
48//=======================================================================
49//function : Add
50//purpose :
51//=======================================================================
52
53Standard_Integer TopTools_LocationSet::Add(const TopLoc_Location& L)
54{
55 if (L.IsIdentity()) return 0;
56 Standard_Integer n = myMap.FindIndex(L);
57 if (n > 0) return n;
58 TopLoc_Location N = L;
59 do {
60 myMap.Add(N.FirstDatum());
61 N = N.NextLocation();
62 } while (!N.IsIdentity());
63 return myMap.Add(L);
64}
65
66
67//=======================================================================
68//function : Location
69//purpose :
70//=======================================================================
71
72const TopLoc_Location& TopTools_LocationSet::Location
73 (const Standard_Integer I)const
74{
75 static TopLoc_Location identity;
76 if (I <= 0 || I > myMap.Extent()) return identity;
77 return myMap(I);
78}
79
80
81//=======================================================================
82//function : Index
83//purpose :
84//=======================================================================
85
86Standard_Integer TopTools_LocationSet::Index(const TopLoc_Location& L) const
87{
88 if (L.IsIdentity()) return 0;
89 return myMap.FindIndex(L);
90}
91
92//=======================================================================
93//function : Write
94//purpose :
95//=======================================================================
96
97static void WriteTrsf(const gp_Trsf& T,
98 Standard_OStream& OS,
99 const Standard_Boolean compact)
100{
101 gp_XYZ V = T.TranslationPart();
102 gp_Mat M = T.VectorialPart();
103
104 if (!compact) OS << "( ";
04232180 105 OS << std::setw(15) << M(1,1) << " ";
106 OS << std::setw(15) << M(1,2) << " ";
107 OS << std::setw(15) << M(1,3) << " ";
108 OS << std::setw(15) << V.Coord(1) << " ";
7fd59977 109 if (!compact) OS << " )";
110 OS << "\n";
111 if (!compact) OS << "( ";
04232180 112 OS << std::setw(15) << M(2,1) << " ";
113 OS << std::setw(15) << M(2,2) << " ";
114 OS << std::setw(15) << M(2,3) << " ";
115 OS << std::setw(15) << V.Coord(2) << " ";
7fd59977 116 if (!compact) OS << " )";
117 OS << "\n";
118 if (!compact) OS << "( ";
04232180 119 OS << std::setw(15) << M(3,1) << " ";
120 OS << std::setw(15) << M(3,2) << " ";
121 OS << std::setw(15) << M(3,3) << " ";
122 OS << std::setw(15) << V.Coord(3) << " ";
7fd59977 123 if (!compact) OS << " )";
124 OS << "\n";
125}
126
127//=======================================================================
128//function : Dump
129//purpose :
130//=======================================================================
131
132void TopTools_LocationSet::Dump(Standard_OStream& OS) const
133{
134 Standard_Integer i, nbLoc = myMap.Extent();
135
136 OS << "\n\n";
137 OS << "\n -------";
138 OS << "\n Dump of "<< nbLoc << " Locations";
139 OS << "\n -------\n\n";
140
141 for (i = 1; i <= nbLoc; i++) {
142 TopLoc_Location L = myMap(i);
04232180 143 OS << std::setw(5) << i << " : \n";
7fd59977 144
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);
150 if (elementary) {
151 OS << "Elementary location\n";
152 }
153 else {
154 OS << "Complex : L"<<myMap.FindIndex(L1);
155 if (p != 1) OS <<"^"<<p;
156 while (!L2.IsIdentity()) {
157 L1 = L2.FirstDatum();
158 p = L2.FirstPower();
159 L2 = L2.NextLocation();
160 OS << " * L" << myMap.FindIndex(L1);
161 if (p != 1) OS << "^"<<p;
162 }
163 OS <<"\n";
164 }
165 WriteTrsf(L.Transformation(),OS,Standard_False);
166 }
167}
168
169//=======================================================================
170//function : Write
171//purpose :
172//=======================================================================
173
6d8f9f4a 174void TopTools_LocationSet::Write (Standard_OStream& OS,
175 const Handle(Message_ProgressIndicator) &theProgress) const
7fd59977 176{
177
60be1f9b 178 std::streamsize prec = OS.precision(15);
7fd59977 179
180 Standard_Integer i, nbLoc = myMap.Extent();
181 OS << "Locations " << nbLoc << "\n";
182
183 //OCC19559
6d8f9f4a 184 Message_ProgressSentry PS(theProgress, "Locations", 0, nbLoc, 1);
7fd59977 185 for (i = 1; i <= nbLoc && PS.More(); i++, PS.Next()) {
7fd59977 186 TopLoc_Location L = myMap(i);
187
188
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);
194 if (elementary) {
195 OS << "1\n";
196 WriteTrsf(L.Transformation(),OS,Standard_True);
197 }
198 else {
199 OS << "2 ";
200 OS << " "<<myMap.FindIndex(L1) << " "<<p;
201 while (!L2.IsIdentity()) {
202 L1 = L2.FirstDatum();
203 p = L2.FirstPower();
204 L2 = L2.NextLocation();
205 OS << " "<<myMap.FindIndex(L1) << " "<<p;
206 }
207 OS << " 0\n";
208 }
209 }
210 OS.precision(prec);
211}
212
213//=======================================================================
214//function : Read
215//purpose :
216//=======================================================================
217
218static void ReadTrsf(gp_Trsf& T,
219 Standard_IStream& IS)
220{
221 Standard_Real V1[3],V2[3],V3[3];
222 Standard_Real V[3];
223
71598a83 224 GeomTools::GetReal(IS, V1[0]);
225 GeomTools::GetReal(IS, V1[1]);
226 GeomTools::GetReal(IS, V1[2]);
227 GeomTools::GetReal(IS, V[0]);
228
229 GeomTools::GetReal(IS, V2[0]);
230 GeomTools::GetReal(IS, V2[1]);
231 GeomTools::GetReal(IS, V2[2]);
232 GeomTools::GetReal(IS, V[1]);
233
234 GeomTools::GetReal(IS, V3[0]);
235 GeomTools::GetReal(IS, V3[1]);
236 GeomTools::GetReal(IS, V3[2]);
237 GeomTools::GetReal(IS, V[2]);
7fd59977 238
239 T.SetValues(V1[0],V1[1],V1[2],V[0],
240 V2[0],V2[1],V2[2],V[1],
7a8c6a36 241 V3[0],V3[1],V3[2],V[2]);
7fd59977 242 return;
243}
244//=======================================================================
245//function : Read
246//purpose :
247//=======================================================================
248
6d8f9f4a 249void TopTools_LocationSet::Read (Standard_IStream& IS, const Handle(Message_ProgressIndicator) &theProgress)
7fd59977 250{
251 myMap.Clear();
252
253 char buffer[255];
254 Standard_Integer l1,p;
255
256 IS >> buffer;
257 if (strcmp(buffer,"Locations")) {
04232180 258 std::cout << "Not a location table "<<std::endl;
7fd59977 259 return;
260 }
261
262 Standard_Integer i, nbLoc;
263 IS >> nbLoc;
264
265 TopLoc_Location L;
266 gp_Trsf T;
267
268 //OCC19559
6d8f9f4a 269 Message_ProgressSentry PS(theProgress, "Locations", 0, nbLoc, 1);
7fd59977 270 for (i = 1; i <= nbLoc&& PS.More(); i++, PS.Next()) {
7fd59977 271 Standard_Integer typLoc;
272 IS >> typLoc;
273
274 if (typLoc == 1) {
275 ReadTrsf(T,IS);
276 L = T;
277 }
278
279 else if (typLoc == 2) {
280 L = TopLoc_Location();
281 IS >> l1;
282 while (l1 != 0) {
283 IS >> p;
284 TopLoc_Location L1 = myMap(l1);
285 L = L1.Powered(p) *L;
286 IS >> l1;
287 }
288 }
289
290 if (!L.IsIdentity()) myMap.Add(L);
291 }
292}