Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-07-21 |
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 | |
42cf5bc1 | 17 | |
18 | #include <BRep_TEdge.hxx> | |
19 | #include <BRepAdaptor_Surface.hxx> | |
20 | #include <BRepGProp.hxx> | |
21 | #include <BRepTools.hxx> | |
22 | #include <BRepTools_ShapeSet.hxx> | |
23 | #include <BRepTools_WireExplorer.hxx> | |
745c1386 | 24 | #include <BinTools.hxx> |
42cf5bc1 | 25 | #include <DBRep.hxx> |
7fd59977 | 26 | #include <DBRep_DrawableShape.hxx> |
7fd59977 | 27 | #include <Draw.hxx> |
42cf5bc1 | 28 | #include <Draw_Appli.hxx> |
29 | #include <Draw_ProgressIndicator.hxx> | |
7fd59977 | 30 | #include <Draw_Segment3D.hxx> |
7fd59977 | 31 | #include <gp_Ax2.hxx> |
7fd59977 | 32 | #include <GProp.hxx> |
33 | #include <GProp_GProps.hxx> | |
68ef63f9 | 34 | #include <NCollection_Vector.hxx> |
42cf5bc1 | 35 | #include <Poly_Triangulation.hxx> |
36 | #include <Precision.hxx> | |
37 | #include <Standard.hxx> | |
38 | #include <TColStd_Array1OfInteger.hxx> | |
7fd59977 | 39 | #include <TColStd_Array1OfReal.hxx> |
42cf5bc1 | 40 | #include <TopAbs.hxx> |
41 | #include <TopExp.hxx> | |
42 | #include <TopExp_Explorer.hxx> | |
43 | #include <TopoDS.hxx> | |
44 | #include <TopoDS_Compound.hxx> | |
45 | #include <TopoDS_Iterator.hxx> | |
46 | #include <TopoDS_Shape.hxx> | |
47 | #include <TopTools_Array1OfShape.hxx> | |
48 | #include <TopTools_ListOfShape.hxx> | |
49 | #include <TopTools_MapOfShape.hxx> | |
7fd59977 | 50 | |
7fd59977 | 51 | #include <stdio.h> |
42cf5bc1 | 52 | // memory management |
03155c18 | 53 | #ifdef _WIN32 |
7fd59977 | 54 | extern Draw_Viewer dout; |
55 | #endif | |
7fd59977 | 56 | |
57 | #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg])) | |
58 | #define Float(IArg) (strspn (Arg[IArg], "0123456789+-") != strlen (Arg[IArg])) | |
59 | ||
60 | ||
61 | //========================================== | |
0d969553 | 62 | // useful methods |
7fd59977 | 63 | //========================================== |
64 | ||
65 | Standard_EXPORT void DBRep_WriteColorOrientation () | |
66 | { | |
04232180 | 67 | std::cout << "\nrouge FORWARD"; |
68 | std::cout << "\nbleu REVERSED"; | |
69 | std::cout << "\nrose EXTERNAL"; | |
70 | std::cout << "\norange INTERNAL"<<std::endl; | |
7fd59977 | 71 | } |
72 | ||
73 | Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or) | |
74 | { | |
75 | Draw_Color col; | |
76 | switch (Or) { | |
77 | ||
78 | case TopAbs_FORWARD : | |
79 | col = Draw_rouge; | |
80 | break; | |
81 | ||
82 | case TopAbs_REVERSED : | |
83 | col = Draw_bleu; | |
84 | break; | |
85 | ||
86 | case TopAbs_EXTERNAL : | |
87 | col = Draw_rose; | |
88 | break; | |
89 | ||
90 | case TopAbs_INTERNAL : | |
91 | col = Draw_orange; | |
92 | break; | |
93 | ||
94 | } | |
95 | return col; | |
96 | } | |
97 | ||
98 | //========================================== | |
99 | // static variables | |
100 | //========================================== | |
101 | ||
102 | static Standard_Integer nbIsos = 2; | |
103 | static Standard_Real size = 100.; | |
104 | static Standard_Integer discret = 30; | |
105 | static Standard_Boolean disptriangles = Standard_False; | |
106 | static Standard_Boolean disppolygons = Standard_False; | |
c6541a0c D |
107 | static Standard_Real anglHLR = 35 * M_PI / 180; |
108 | static Standard_Real HAngMin = 1 * M_PI / 180; | |
109 | static Standard_Real HAngMax = 35 * M_PI / 180; | |
7fd59977 | 110 | static Standard_Boolean withHLR = Standard_False; |
111 | static Standard_Boolean withRg1 = Standard_True; | |
112 | static Standard_Boolean withRgN = Standard_False; | |
113 | static Standard_Boolean withHid = Standard_False; | |
114 | ||
115 | //======================================================================= | |
116 | // isos | |
117 | //======================================================================= | |
118 | ||
119 | static Standard_Integer isos (Draw_Interpretor& di, | |
120 | Standard_Integer NbArg, const char **Arg) | |
121 | { | |
122 | NbArg-- ; | |
123 | ||
124 | if (NbArg <= 0) { | |
125 | di << "Current number of isos : " << nbIsos << "\n" ; | |
126 | return 0 ; | |
127 | } | |
128 | ||
129 | Standard_Integer NbIsos = 0 ; | |
130 | Standard_Boolean Change = Standard_False ; | |
131 | if (!Characters (NbArg) && Float (NbArg)) return 1 ; | |
132 | if (!Characters (NbArg)) { | |
91322f44 | 133 | NbIsos = Draw::Atoi (Arg[NbArg]) ; |
7fd59977 | 134 | NbArg-- ; |
135 | Change = Standard_True ; | |
136 | } | |
137 | ||
138 | if (NbArg <= 0) { | |
139 | nbIsos = NbIsos ; | |
140 | di << "New current number of isos : " << nbIsos << "\n" ; | |
141 | } else { | |
142 | for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++) { | |
143 | Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ; | |
144 | if (!Shape1.IsNull()) { | |
145 | Handle (DBRep_DrawableShape) Shape2 = | |
146 | Handle (DBRep_DrawableShape)::DownCast (Shape1) ; | |
147 | if (!Shape2.IsNull()) { | |
148 | if (Change) { | |
149 | Shape2->ChangeNbIsos (NbIsos) ; | |
150 | } else { | |
151 | di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n"; | |
152 | } | |
153 | } | |
154 | } | |
155 | } | |
156 | if (Change) dout.RepaintAll() ; | |
157 | } | |
158 | ||
159 | return 0 ; | |
160 | } | |
161 | ||
162 | //======================================================================= | |
163 | // hlr | |
164 | //======================================================================= | |
165 | ||
166 | static Standard_Integer hlr (Draw_Interpretor& di, | |
167 | Standard_Integer n, const char **a) | |
168 | { | |
169 | if (n <= 1) { | |
170 | if (withHLR) { | |
171 | di << " HLR"; | |
172 | if (withRgN) di << " RgNLines"; | |
173 | else { | |
174 | if (withRg1) di << " Rg1Lines"; | |
175 | else di << " no RegLines"; | |
176 | } | |
177 | if (withHid) di << " HiddenLines"; | |
178 | else di << " no HiddenLines"; | |
179 | di << "\n"; | |
180 | if (withHLR) { | |
0d969553 | 181 | di << "Angle of discretization : "; |
586db386 | 182 | di << anglHLR * 180 / M_PI << " degrees\n"; |
7fd59977 | 183 | } |
184 | } | |
185 | else di << " wireframe"; | |
186 | di << "\n"; | |
187 | return 0 ; | |
188 | } | |
189 | ||
190 | if (n == 2) { | |
191 | if (!strcasecmp(a[1],"nohlr")) withHLR = Standard_False; | |
192 | else if (!strcasecmp(a[1],"hlr" )) withHLR = Standard_True; | |
193 | else if (!strcasecmp(a[1],"nohid")) withHid = Standard_False; | |
194 | else if (!strcasecmp(a[1],"hid" )) { | |
195 | withHLR = Standard_True; | |
196 | withHid = Standard_True; | |
197 | } | |
198 | else if (!strcasecmp(a[1],"norg1")) { | |
199 | withRg1 = Standard_False; | |
200 | withRgN = Standard_False; | |
201 | } | |
202 | else if (!strcasecmp(a[1],"rg1" )) { | |
203 | withHLR = Standard_True; | |
204 | withRg1 = Standard_True; | |
205 | withRgN = Standard_False; | |
206 | } | |
207 | else if (!strcasecmp(a[1],"norgn")) { | |
208 | withRgN = Standard_False; | |
209 | } | |
210 | else if (!strcasecmp(a[1],"rgn" )) { | |
211 | withHLR = Standard_True; | |
212 | withRg1 = Standard_True; | |
213 | withRgN = Standard_True; | |
214 | } | |
215 | else if (!strcasecmp(a[1],"ang" )) { | |
216 | di << "Angle de discretisation : "; | |
586db386 | 217 | di << anglHLR * 180 / M_PI << " degres\n"; |
7fd59977 | 218 | } |
219 | else return 1; | |
220 | } | |
221 | ||
222 | Standard_Integer nFirst = 2; | |
223 | ||
224 | if (n >= 3 && !strcasecmp(a[1],"ang" )) { | |
225 | nFirst = 3; | |
226 | if (n == 3) { | |
91322f44 | 227 | Standard_Real ang = Draw::Atof(a[2]); |
c6541a0c | 228 | anglHLR = ang * M_PI / 180; |
7fd59977 | 229 | if (anglHLR < HAngMin) anglHLR = HAngMin; |
230 | if (anglHLR > HAngMax) anglHLR = HAngMax; | |
231 | } | |
0d969553 | 232 | di << "Angle of discretization : "; |
586db386 | 233 | di << anglHLR * 180 / M_PI << " degrees\n"; |
7fd59977 | 234 | } |
235 | ||
236 | if (n >= nFirst + 1) { | |
237 | ||
238 | for (Standard_Integer i = nFirst ; i < n; i++) { | |
239 | Handle (Draw_Drawable3D) D = Draw::Get (a[i]) ; | |
240 | if (!D.IsNull()) { | |
241 | Handle (DBRep_DrawableShape) S = | |
242 | Handle (DBRep_DrawableShape)::DownCast (D) ; | |
243 | if (!S.IsNull()) { | |
244 | Standard_Boolean localHLR, localRg1, localRgN, localHid; | |
245 | Standard_Real localAng; | |
246 | S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid, | |
247 | localAng); | |
248 | if (!strcasecmp(a[1],"nohlr")) localHLR = Standard_False; | |
249 | else if (!strcasecmp(a[1],"hlr" )) localHLR = Standard_True; | |
250 | else if (!strcasecmp(a[1],"nohid")) localHid = Standard_False; | |
251 | else if (!strcasecmp(a[1],"hid" )) { | |
252 | localHLR = Standard_True; | |
253 | localHid = Standard_True; | |
254 | } | |
255 | else if (!strcasecmp(a[1],"norg1")) { | |
256 | localRg1 = Standard_False; | |
257 | localRgN = Standard_False; | |
258 | } | |
259 | else if (!strcasecmp(a[1],"rg1" )) { | |
260 | localHLR = Standard_True; | |
261 | localRg1 = Standard_True; | |
262 | localRgN = Standard_False; | |
263 | } | |
264 | else if (!strcasecmp(a[1],"norgn")) { | |
265 | localRgN = Standard_False; | |
266 | } | |
267 | else if (!strcasecmp(a[1],"rgn" )) { | |
268 | localHLR = Standard_True; | |
269 | localRg1 = Standard_True; | |
270 | localRgN = Standard_True; | |
271 | } | |
272 | else if (!strcasecmp(a[1],"ang" )) { | |
91322f44 | 273 | Standard_Real ang = Draw::Atof(a[2]); |
c6541a0c | 274 | localAng = ang * M_PI / 180; |
7fd59977 | 275 | } |
276 | else return 1; | |
277 | S->DisplayHLR(localHLR, localRg1, localRgN, localHid, | |
278 | localAng); | |
279 | } | |
280 | } | |
281 | } | |
282 | } | |
283 | dout.RepaintAll() ; | |
284 | ||
285 | return 0 ; | |
286 | } | |
287 | ||
288 | ||
289 | //======================================================================= | |
290 | // dispor, dispcon | |
291 | //======================================================================= | |
292 | ||
293 | static Standard_Integer dispor (Draw_Interpretor& , | |
294 | Standard_Integer n, const char** a) | |
295 | { | |
296 | Standard_Boolean d = !strcasecmp(a[0],"vori"); | |
297 | ||
298 | if (d) | |
299 | DBRep_WriteColorOrientation(); | |
300 | ||
301 | Standard_Integer i; | |
302 | for (i = 1; i < n; i++) { | |
303 | Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]); | |
304 | if (!d1.IsNull()) { | |
305 | Handle(DBRep_DrawableShape) d2 = | |
306 | Handle(DBRep_DrawableShape)::DownCast(d1); | |
307 | if (!d2.IsNull()) { | |
308 | d2->DisplayOrientation(d); | |
309 | Draw::Repaint(); | |
310 | } | |
311 | } | |
312 | } | |
313 | return 0; | |
314 | } | |
315 | ||
316 | //======================================================================= | |
317 | // discretisation | |
318 | //======================================================================= | |
319 | ||
320 | static Standard_Integer discretisation(Draw_Interpretor& di, | |
321 | Standard_Integer n, const char** a) | |
322 | { | |
323 | if (n <= 1) | |
324 | di << "Current number of points : "<<discret<<"\n"; | |
325 | else { | |
91322f44 | 326 | discret = Draw::Atoi(a[1]); |
7fd59977 | 327 | } |
328 | return 0; | |
329 | } | |
330 | ||
331 | ||
332 | //======================================================================= | |
333 | // triangles | |
334 | //======================================================================= | |
335 | ||
336 | static Standard_Integer triangles(Draw_Interpretor& , | |
337 | Standard_Integer n, const char** a) | |
338 | { | |
339 | if (n < 1) return 1; | |
340 | ||
341 | if (n == 1) { | |
342 | disptriangles = !disptriangles; | |
0797d9d3 | 343 | #ifdef OCCT_DEBUG |
04232180 | 344 | if (disptriangles) std::cout <<"Triangulations are always displayed"<<std::endl; |
345 | else std::cout <<"Triangulations are displayed only if there is no geometric representation"<<std::endl; | |
7fd59977 | 346 | #endif |
347 | } | |
348 | else { | |
349 | Standard_Integer i; | |
350 | for (i = 1; i <= n-1; i++) { | |
351 | Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]); | |
352 | if (!d1.IsNull()) { | |
353 | Handle(DBRep_DrawableShape) d2 = | |
354 | Handle(DBRep_DrawableShape)::DownCast(d1); | |
355 | if (!d2.IsNull()) { | |
356 | d2->DisplayTriangulation(!(d2->DisplayTriangulation())); | |
357 | } | |
358 | } | |
359 | } | |
360 | } | |
361 | ||
362 | Draw::Repaint(); | |
363 | return 0; | |
364 | } | |
365 | ||
366 | //======================================================================= | |
367 | // tclean | |
368 | //======================================================================= | |
369 | ||
370 | static Standard_Integer tclean(Draw_Interpretor& , | |
371 | Standard_Integer n, const char** a) | |
372 | { | |
4b114473 | 373 | if (n == 1) return 1; |
374 | ||
375 | Standard_Integer aStart = 1; | |
376 | Standard_Boolean toRemoveGeometry = Standard_False; | |
377 | if (strcmp(a[1], "-geom") == 0) | |
378 | { | |
379 | aStart++; | |
380 | toRemoveGeometry = Standard_True; | |
381 | } | |
382 | ||
383 | for (Standard_Integer i = aStart; i < n; i++) { | |
7fd59977 | 384 | TopoDS_Shape S = DBRep::Get(a[i]); |
4b114473 | 385 | if (toRemoveGeometry) |
386 | BRepTools::CleanGeometry(S); | |
387 | else | |
388 | BRepTools::Clean(S); | |
7fd59977 | 389 | } |
390 | return 0; | |
391 | } | |
392 | ||
393 | //======================================================================= | |
394 | // polygons | |
395 | //======================================================================= | |
396 | ||
397 | static Standard_Integer polygons(Draw_Interpretor& , | |
398 | Standard_Integer n, const char** a) | |
399 | { | |
400 | if (n < 1) return 1; | |
401 | ||
402 | if (n == 1) { | |
403 | disppolygons = !disppolygons; | |
0797d9d3 | 404 | #ifdef OCCT_DEBUG |
04232180 | 405 | if (disppolygons) std::cout <<"Polygons are always displayed"<<std::endl; |
406 | else std::cout <<"Polygons are displayed only if there is no geometric representation"<<std::endl; | |
7fd59977 | 407 | #endif |
408 | } | |
409 | else { | |
410 | Standard_Integer i; | |
411 | for (i = 1; i <= n-1; i++) { | |
412 | Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]); | |
413 | if (!d1.IsNull()) { | |
414 | Handle(DBRep_DrawableShape) d2 = | |
415 | Handle(DBRep_DrawableShape)::DownCast(d1); | |
416 | if (!d2.IsNull()) { | |
417 | d2->DisplayPolygons(!(d2->DisplayPolygons())); | |
418 | } | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | Draw::Repaint(); | |
424 | return 0; | |
425 | } | |
426 | ||
427 | ||
428 | //======================================================================= | |
429 | // compound | |
430 | //======================================================================= | |
431 | ||
432 | static Standard_Integer compound(Draw_Interpretor& , | |
433 | Standard_Integer n, const char** a) | |
434 | { | |
435 | if (n <= 1) return 1; | |
436 | BRep_Builder B; | |
437 | TopoDS_Compound C; | |
438 | B.MakeCompound(C); | |
439 | for (Standard_Integer i = 1; i < n-1; i++) { | |
440 | TopoDS_Shape S2 = DBRep::Get(a[i]); | |
441 | if (!S2.IsNull()) B.Add(C,S2); | |
442 | } | |
443 | DBRep::Set(a[n-1],C); | |
444 | return 0; | |
445 | } | |
446 | ||
447 | //======================================================================= | |
448 | // emptycopy | |
449 | //======================================================================= | |
450 | ||
451 | static Standard_Integer emptycopy(Draw_Interpretor& , | |
452 | Standard_Integer n, const char** a) | |
453 | { | |
454 | if (n <= 1) return 1; | |
455 | TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]); | |
456 | if (S.IsNull()) return 1; | |
457 | S.EmptyCopy(); | |
458 | DBRep::Set(a[1],S); | |
459 | return 0; | |
460 | } | |
461 | ||
462 | //======================================================================= | |
463 | // add | |
464 | //======================================================================= | |
465 | ||
466 | static Standard_Integer add(Draw_Interpretor& , | |
467 | Standard_Integer n, const char** a) | |
468 | { | |
469 | if (n < 3) return 1; | |
470 | BRep_Builder B; | |
471 | TopoDS_Shape S1 = DBRep::Get(a[1]); | |
472 | if (S1.IsNull()) return 1; | |
473 | TopoDS_Shape S2 = DBRep::Get(a[2]); | |
474 | if (S2.IsNull()) return 1; | |
475 | B.Add(S2,S1); | |
476 | DBRep::Set(a[2],S2); | |
477 | return 0; | |
478 | } | |
479 | ||
480 | //======================================================================= | |
481 | // explode | |
482 | //======================================================================= | |
483 | ||
484 | static Standard_Integer explode(Draw_Interpretor& di, | |
485 | Standard_Integer n, const char** a) | |
486 | { | |
487 | if (n <= 1) return 1; | |
488 | TopoDS_Shape S = DBRep::Get(a[1]); | |
489 | if (S.IsNull()) return 0; | |
490 | char newname[1024]; | |
491 | strcpy(newname,a[1]); | |
492 | char* p = newname; | |
493 | while (*p != '\0') p++; | |
494 | *p = '_'; | |
495 | p++; | |
496 | Standard_Integer i = 0; | |
497 | if (n == 2) { | |
498 | TopoDS_Iterator itr(S); | |
499 | while (itr.More()) { | |
500 | i++; | |
91322f44 | 501 | Sprintf(p,"%d",i); |
7fd59977 | 502 | DBRep::Set(newname,itr.Value()); |
503 | di.AppendElement(newname); | |
504 | itr.Next(); | |
505 | } | |
506 | } | |
507 | else { | |
508 | // explode a type | |
509 | TopAbs_ShapeEnum typ; | |
510 | switch (a[2][0]) { | |
511 | ||
512 | case 'C' : | |
513 | case 'c' : | |
514 | if ((a[2][1] == 'd')||(a[2][1] == 'D')) | |
515 | typ = TopAbs_COMPOUND; | |
516 | else | |
517 | typ = TopAbs_COMPSOLID; | |
518 | break; | |
519 | ||
520 | case 'S' : | |
521 | case 's' : | |
522 | if ((a[2][1] == 'O')||(a[2][1] == 'o')) | |
523 | typ = TopAbs_SOLID; | |
524 | else if ((a[2][1] == 'H')||(a[2][1] == 'h')) | |
525 | typ = TopAbs_SHELL; | |
526 | else | |
527 | return 1; | |
528 | break; | |
529 | ||
530 | case 'F' : | |
531 | case 'f' : | |
532 | typ = TopAbs_FACE; | |
533 | break; | |
534 | ||
535 | case 'W' : | |
536 | case 'w' : | |
537 | typ = TopAbs_WIRE; | |
538 | break; | |
539 | ||
540 | case 'E' : | |
541 | case 'e' : | |
542 | typ = TopAbs_EDGE; | |
543 | break; | |
544 | ||
545 | case 'V' : | |
546 | case 'v' : | |
547 | typ = TopAbs_VERTEX; | |
548 | break; | |
549 | ||
550 | default : | |
551 | return 1; | |
552 | } | |
553 | ||
554 | TopTools_MapOfShape M; | |
555 | M.Add(S); | |
556 | TopExp_Explorer ex(S,typ); | |
557 | for (; ex.More(); ex.Next()) { | |
558 | const TopoDS_Shape& Sx = ex.Current(); | |
559 | Standard_Boolean added = M.Add(Sx); | |
560 | if (added) { | |
561 | i++; | |
91322f44 | 562 | Sprintf(p,"%d",i); |
7fd59977 | 563 | DBRep::Set(newname,Sx); |
564 | di.AppendElement(newname); | |
565 | } | |
566 | } | |
567 | } | |
568 | return 0; | |
569 | } | |
570 | ||
571 | //======================================================================= | |
572 | // nexplode : stable numbered explode (from Serguey Nizhny) | |
573 | //======================================================================= | |
574 | ||
575 | static Standard_Integer nexplode(Draw_Interpretor& di, | |
576 | Standard_Integer n, const char** a) | |
577 | { | |
578 | if (n <= 2) return 1; | |
579 | TopoDS_Shape S = DBRep::Get(a[1]); | |
580 | if (S.IsNull()) return 0; | |
581 | char newname[1024]; | |
582 | strcpy(newname,a[1]); | |
583 | char* p = newname; | |
584 | while (*p != '\0') p++; | |
585 | *p = '_'; | |
586 | p++; | |
587 | TopAbs_ShapeEnum typ; | |
588 | // explode a type | |
589 | switch (a[2][0]) { | |
590 | case 'F' : | |
591 | case 'f' : | |
592 | typ = TopAbs_FACE; | |
593 | break; | |
594 | ||
595 | case 'E' : | |
596 | case 'e' : | |
597 | typ = TopAbs_EDGE; | |
598 | break; | |
599 | ||
b0fbc579 | 600 | case 'V' : |
601 | case 'v' : | |
602 | typ = TopAbs_VERTEX; | |
603 | break; | |
604 | ||
7fd59977 | 605 | default : |
606 | return 1; | |
607 | } | |
608 | TopTools_IndexedMapOfShape IMOStmp; | |
609 | TopTools_MapOfShape MShape; | |
610 | IMOStmp.Add(S); | |
611 | TopExp::MapShapes(S,typ,IMOStmp); | |
612 | TopExp_Explorer Exp(S,typ); | |
613 | Standard_Integer MaxShapes, Index = 0; | |
614 | MaxShapes = IMOStmp.Extent()-1; | |
615 | TopTools_Array1OfShape aShapes(1,MaxShapes); | |
616 | ||
617 | // explode | |
618 | while (Exp.More()) { | |
619 | if (MShape.Add(Exp.Current())) { | |
620 | Index++; | |
621 | aShapes.SetValue(Index,Exp.Current()); | |
622 | } | |
623 | Exp.Next(); | |
624 | } | |
b0fbc579 | 625 | // |
7fd59977 | 626 | TColStd_Array1OfInteger OrderInd(1,MaxShapes); |
b0fbc579 | 627 | gp_Pnt GPoint; |
7fd59977 | 628 | GProp_GProps GPr; |
7fd59977 | 629 | Standard_Integer aTemp; |
630 | TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z; | |
631 | Standard_Boolean NoSort = Standard_True; | |
b0fbc579 | 632 | // |
633 | // Computing of CentreOfMass for edge and face | |
634 | // and for vertex use its point | |
7fd59977 | 635 | for (Index=1; Index <= MaxShapes; Index++) { |
636 | OrderInd.SetValue(Index,Index); | |
b0fbc579 | 637 | const TopoDS_Shape& aS = aShapes(Index); |
638 | if (aS.ShapeType() != TopAbs_VERTEX) { | |
639 | BRepGProp::LinearProperties(aS, GPr); | |
640 | GPoint = GPr.CentreOfMass(); | |
641 | } | |
642 | else { | |
643 | GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS)); | |
644 | } | |
7fd59977 | 645 | MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 + |
646 | GPoint.Z()*0.9); | |
647 | } | |
648 | // Sorting | |
649 | while(NoSort) { | |
650 | NoSort = Standard_False; | |
651 | for (Index=1; Index < MaxShapes; Index++) { | |
652 | if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) { | |
653 | aTemp = OrderInd(Index); | |
654 | OrderInd(Index) = OrderInd(Index+1); | |
655 | OrderInd(Index+1) = aTemp; | |
656 | NoSort = Standard_True; | |
657 | } | |
658 | } | |
659 | } | |
660 | // Check of equality of MidXYZ | |
661 | for (Index=1; Index < MaxShapes; Index++) { | |
662 | if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index))) | |
586db386 | 663 | di<<"Warning! For this shape the results may be incorrect.\n"; |
7fd59977 | 664 | } |
665 | ||
666 | for (Index=1 ;Index <= MaxShapes; Index++) { | |
91322f44 | 667 | Sprintf(p,"%d",Index); |
7fd59977 | 668 | DBRep::Set(newname,aShapes(OrderInd(Index))); |
669 | di.AppendElement(newname); | |
670 | } | |
671 | ||
672 | return 0; | |
673 | } | |
674 | ||
675 | //======================================================================= | |
676 | // exwire | |
677 | //======================================================================= | |
678 | ||
679 | static Standard_Integer exwire(Draw_Interpretor& , | |
680 | Standard_Integer n, const char** a) | |
681 | { | |
682 | if (n <= 1) return 1; | |
683 | TopoDS_Shape S = DBRep::Get(a[1]); | |
684 | if (S.IsNull()) return 0; | |
685 | if (S.ShapeType() != TopAbs_WIRE) return 0; | |
686 | char newname[1024]; | |
687 | strcpy(newname,a[1]); | |
688 | char* p = newname; | |
689 | while (*p != '\0') p++; | |
690 | *p = '_'; | |
691 | p++; | |
692 | Standard_Integer i = 0; | |
693 | BRepTools_WireExplorer ex(TopoDS::Wire(S)); | |
694 | while (ex.More()) { | |
695 | i++; | |
91322f44 | 696 | Sprintf(p,"%d",i); |
7fd59977 | 697 | DBRep::Set(newname,ex.Current()); |
698 | ex.Next(); | |
699 | } | |
700 | return 0; | |
701 | } | |
702 | ||
703 | //======================================================================= | |
704 | // invert | |
705 | //======================================================================= | |
706 | ||
707 | static Standard_Integer invert(Draw_Interpretor& , | |
708 | Standard_Integer n, const char** a) | |
709 | { | |
710 | if (n <= 1) return 1; | |
711 | TopoDS_Shape S = DBRep::Get(a[1]); | |
712 | if (S.IsNull()) return 0; | |
713 | ||
714 | BRep_Builder B; | |
715 | TopoDS_Shape NS = S.EmptyCopied(); | |
ab860031 | 716 | NS.Closed (S.Closed()); |
7fd59977 | 717 | |
ab860031 | 718 | TopoDS_Iterator itr(S); |
7fd59977 | 719 | while (itr.More()) { |
720 | B.Add(NS,itr.Value().Reversed()); | |
721 | itr.Next(); | |
722 | } | |
723 | DBRep::Set(a[1],NS); | |
724 | ||
725 | return 0; | |
726 | } | |
727 | ||
728 | //======================================================================= | |
729 | // orientation, reverse, complement | |
730 | //======================================================================= | |
731 | ||
732 | static Standard_Integer orientation(Draw_Interpretor& , | |
733 | Standard_Integer n, const char** a) | |
734 | { | |
735 | if (n <= 1) return 1; | |
736 | Standard_Integer cas = 0; | |
7fd59977 | 737 | TopAbs_Orientation ori=TopAbs_FORWARD; |
7fd59977 | 738 | Standard_Integer last = n; |
739 | if (!strcasecmp(a[0],"orientation")) { | |
740 | if (n <= 2) return 1; | |
741 | last--; | |
742 | switch (*a[n-1]) { | |
743 | ||
744 | case 'F' : | |
745 | ori = TopAbs_FORWARD; | |
746 | break; | |
747 | ||
748 | case 'R' : | |
749 | ori = TopAbs_REVERSED; | |
750 | break; | |
751 | ||
752 | case 'I' : | |
753 | ori = TopAbs_INTERNAL; | |
754 | break; | |
755 | ||
756 | case 'E' : | |
757 | ori = TopAbs_EXTERNAL; | |
758 | break; | |
759 | } | |
760 | } | |
761 | ||
762 | else if (!strcasecmp(a[0],"treverse")) { | |
763 | cas = -1; | |
764 | } | |
765 | ||
766 | else if (!strcasecmp(a[0],"complement")) { | |
767 | cas = -2; | |
768 | } | |
769 | ||
770 | for (Standard_Integer i = 1; i < last; i++) { | |
771 | TopoDS_Shape S = DBRep::Get(a[i]); | |
772 | if (!S.IsNull()) { | |
773 | if (cas == -2) | |
774 | S.Complement(); | |
775 | else if (cas == -1) | |
776 | S.Reverse(); | |
777 | else | |
778 | S.Orientation(ori); | |
779 | DBRep::Set(a[i],S); | |
780 | } | |
781 | } | |
782 | return 0; | |
783 | } | |
784 | ||
785 | #include <TCollection_AsciiString.hxx> | |
786 | ||
787 | //======================================================================= | |
0d969553 | 788 | // numshapes same as nbshapes but the output is cout |
7fd59977 | 789 | //======================================================================= |
790 | ||
791 | static Standard_Integer numshapes(Draw_Interpretor& di, | |
792 | Standard_Integer n, const char** a) | |
793 | { | |
794 | if (n < 2) return 1; | |
795 | ||
796 | Standard_Integer i; | |
797 | TopExp_Explorer ex; | |
798 | for (i = 1; i < n; i++) { | |
799 | TopoDS_Shape S = DBRep::Get(a[i]); | |
800 | if (!S.IsNull()) { | |
801 | BRepTools_ShapeSet BS; | |
802 | BS.Add(S); | |
803 | di <<"Number of shapes in "<<a[i]<<"\n"; | |
804 | TCollection_AsciiString Astr; | |
805 | BS.DumpExtent(Astr); | |
806 | di <<Astr.ToCString(); | |
807 | di << "\n" ; | |
808 | } | |
809 | } | |
810 | ||
811 | return 0; | |
812 | } | |
813 | ||
bfff00a8 | 814 | //======================================================================= |
815 | // function : DumpExtent | |
816 | // purpose : Dumps the number of sub-shapes in <aStr>. | |
817 | //======================================================================= | |
818 | static void DumpExtent(const TopoDS_Shape& aS, | |
819 | TCollection_AsciiString& aStr) | |
820 | { | |
821 | const int aNbTypes=8; | |
822 | const char *pNames[aNbTypes+1]={ | |
823 | " SHAPE : ", | |
824 | " COMPOUND : ", | |
825 | " COMPSOLID : ", | |
826 | " SOLID : ", | |
827 | " SHELL : ", | |
828 | " FACE : ", | |
829 | " WIRE : ", | |
830 | " EDGE : ", | |
831 | " VERTEX : " | |
832 | }; | |
833 | Standard_Integer i, aNb, aNbSh; | |
834 | TopAbs_ShapeEnum aType; | |
835 | TopTools_IndexedMapOfShape aM; | |
836 | // | |
837 | aNbSh=0; | |
838 | // | |
839 | for (i=aNbTypes-1; i>=0; --i) { | |
840 | aM.Clear(); | |
841 | aType=(TopAbs_ShapeEnum)i; | |
842 | TopExp::MapShapes(aS, aType, aM); | |
843 | aNb=aM.Extent(); | |
844 | aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n"; | |
845 | aNbSh+=aNb; | |
846 | } | |
847 | aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n"; | |
848 | } | |
849 | ||
7fd59977 | 850 | //======================================================================= |
851 | // nbshapes | |
852 | //======================================================================= | |
853 | ||
854 | static Standard_Integer nbshapes(Draw_Interpretor& di, | |
bfff00a8 | 855 | Standard_Integer n, const char** a) |
7fd59977 | 856 | { |
857 | if (n < 2) return 1; | |
858 | ||
859 | Standard_Integer i; | |
bfff00a8 | 860 | Standard_Boolean aTotal; |
7fd59977 | 861 | TopExp_Explorer ex; |
bfff00a8 | 862 | // |
863 | aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False; | |
864 | // | |
7fd59977 | 865 | for (i = 1; i < n; i++) { |
866 | TopoDS_Shape S = DBRep::Get(a[i]); | |
867 | if (!S.IsNull()) { | |
7fd59977 | 868 | di<<"Number of shapes in "<<a[i]<<"\n"; |
869 | TCollection_AsciiString Astr; | |
bfff00a8 | 870 | if (aTotal) { |
871 | DumpExtent(S, Astr); | |
872 | } else { | |
873 | BRepTools_ShapeSet BS; | |
874 | BS.Add(S); | |
875 | BS.DumpExtent(Astr); | |
876 | } | |
7fd59977 | 877 | di<<Astr.ToCString(); |
878 | } | |
879 | } | |
880 | ||
881 | return 0; | |
882 | } | |
883 | ||
884 | //======================================================================= | |
885 | // | |
886 | //======================================================================= | |
887 | ||
888 | static Standard_Integer countshapes(Draw_Interpretor& di, | |
889 | Standard_Integer n, const char** a) | |
890 | { | |
891 | if (n < 2) return 1; | |
892 | ||
893 | Standard_Integer i; | |
894 | TopExp_Explorer ex; | |
895 | for (i = 1; i < n; i++) { | |
896 | TopoDS_Shape Sh = DBRep::Get(a[i]); | |
897 | Standard_Integer nbElem = 0; | |
898 | if (!Sh.IsNull()) { | |
899 | di <<"Number of shapes in "<<a[i]<<"\n"; | |
900 | TopTools_MapOfShape M; | |
901 | ||
902 | for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) { | |
903 | const TopoDS_Shape& S = ex.Current(); | |
904 | Standard_Boolean added = M.Add(S); | |
905 | if (added) { | |
906 | nbElem++; | |
907 | } | |
908 | } | |
909 | di << " VERTEX : " << nbElem << "\n"; | |
910 | nbElem = 0; | |
911 | ||
912 | for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) { | |
913 | const TopoDS_Shape& S = ex.Current(); | |
914 | Standard_Boolean added = M.Add(S); | |
915 | if (added) { | |
916 | nbElem++; | |
917 | } | |
918 | } | |
919 | di << " EDGE : " << nbElem << "\n"; | |
920 | nbElem = 0; | |
921 | ||
922 | for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) { | |
923 | const TopoDS_Shape& S = ex.Current(); | |
924 | Standard_Boolean added = M.Add(S); | |
925 | if (added) { | |
926 | nbElem++; | |
927 | } | |
928 | } | |
929 | di << " WIRE : " << nbElem << "\n"; | |
930 | nbElem = 0; | |
931 | ||
932 | for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) { | |
933 | const TopoDS_Shape& S = ex.Current(); | |
934 | Standard_Boolean added = M.Add(S); | |
935 | if (added) { | |
936 | nbElem++; | |
937 | } | |
938 | } | |
939 | di << " FACE : " << nbElem << "\n"; | |
940 | nbElem = 0; | |
941 | ||
942 | for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) { | |
943 | const TopoDS_Shape& S = ex.Current(); | |
944 | Standard_Boolean added = M.Add(S); | |
945 | if (added) { | |
946 | nbElem++; | |
947 | } | |
948 | } | |
949 | di << " SHELL : " << nbElem << "\n"; | |
950 | nbElem = 0; | |
951 | ||
952 | for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) { | |
953 | const TopoDS_Shape& S = ex.Current(); | |
954 | Standard_Boolean added = M.Add(S); | |
955 | if (added) { | |
956 | nbElem++; | |
957 | } | |
958 | } | |
959 | di << " SOLID : " << nbElem << "\n"; | |
960 | nbElem = 0; | |
961 | ||
962 | for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) { | |
963 | const TopoDS_Shape& S = ex.Current(); | |
964 | Standard_Boolean added = M.Add(S); | |
965 | if (added) { | |
966 | nbElem++; | |
967 | } | |
968 | } | |
969 | di << " COMPSOLID : " << nbElem << "\n"; | |
970 | nbElem = 0; | |
971 | ||
972 | for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) { | |
973 | const TopoDS_Shape& S = ex.Current(); | |
974 | Standard_Boolean added = M.Add(S); | |
975 | if (added) { | |
976 | nbElem++; | |
977 | } | |
978 | } | |
979 | di << " COMPOUND : " << nbElem << "\n"; | |
980 | nbElem = 0; | |
981 | ||
982 | di << " SHAPE : " << M.Extent() << "\n"; | |
983 | di << "\n" ; | |
984 | } | |
985 | } | |
986 | ||
987 | return 0; | |
988 | } | |
989 | ||
ebfb9ce2 | 990 | //======================================================================= |
991 | // | |
992 | //======================================================================= | |
993 | void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n) | |
994 | { | |
995 | Standard_Integer i; | |
996 | for(i = 2; i < n; i++) { | |
997 | if (strstr ( a[i], "free" )) { | |
998 | if(a[i][0] == '-') { | |
999 | Sh.Free(Standard_False); | |
1000 | } | |
1001 | else { | |
1002 | Sh.Free(Standard_True); | |
1003 | } | |
1004 | } | |
1005 | if (strstr ( a[i], "modified" )) { | |
1006 | if(a[i][0] == '-') { | |
1007 | Sh.Modified(Standard_False); | |
1008 | } | |
1009 | else { | |
1010 | Sh.Modified(Standard_True); | |
1011 | } | |
1012 | } | |
1013 | if (strstr ( a[i], "checked" )) { | |
1014 | if(a[i][0] == '-') { | |
1015 | Sh.Checked(Standard_False); | |
1016 | } | |
1017 | else { | |
1018 | Sh.Checked(Standard_True); | |
1019 | } | |
1020 | } | |
1021 | if (strstr ( a[i], "orientable" )) { | |
1022 | if(a[i][0] == '-') { | |
1023 | Sh.Orientable(Standard_False); | |
1024 | } | |
1025 | else { | |
1026 | Sh.Orientable(Standard_True); | |
1027 | } | |
1028 | } | |
1029 | if (strstr ( a[i], "closed" )) { | |
1030 | if(a[i][0] == '-') { | |
1031 | Sh.Closed(Standard_False); | |
1032 | } | |
1033 | else { | |
1034 | Sh.Closed(Standard_True); | |
1035 | } | |
1036 | } | |
1037 | if (strstr ( a[i], "infinite" )) { | |
1038 | if(a[i][0] == '-') { | |
1039 | Sh.Infinite(Standard_False); | |
1040 | } | |
1041 | else { | |
1042 | Sh.Infinite(Standard_True); | |
1043 | } | |
1044 | } | |
1045 | if (strstr ( a[i], "convex" )) { | |
1046 | if(a[i][0] == '-') { | |
1047 | Sh.Convex(Standard_False); | |
1048 | } | |
1049 | else { | |
1050 | Sh.Convex(Standard_True); | |
1051 | } | |
1052 | } | |
1053 | if (strstr ( a[i], "locked" )) { | |
1054 | if(a[i][0] == '-') { | |
1055 | Sh.Locked(Standard_False); | |
1056 | } | |
1057 | else { | |
1058 | Sh.Locked(Standard_True); | |
1059 | } | |
1060 | } | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | //======================================================================= | |
1065 | // | |
1066 | //======================================================================= | |
1067 | static Standard_Integer setFlags(Draw_Interpretor& , | |
1068 | Standard_Integer n, const char** a) | |
1069 | { | |
1070 | if (n < 3) return 1; | |
1071 | ||
1072 | TopExp_Explorer ex; | |
1073 | TopoDS_Shape Sh = DBRep::Get(a[1]); | |
1074 | ||
1075 | if (Sh.IsNull()) return 1; | |
1076 | ||
1077 | setProp(Sh, a, n); | |
1078 | for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) { | |
1079 | TopoDS_Shape S = ex.Current(); | |
1080 | setProp(S, a, n); | |
1081 | } | |
1082 | ||
1083 | for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) { | |
1084 | TopoDS_Shape S = ex.Current(); | |
1085 | setProp(S, a, n); | |
1086 | } | |
1087 | ||
1088 | for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) { | |
1089 | TopoDS_Shape S = ex.Current(); | |
1090 | setProp(S, a, n); | |
1091 | } | |
1092 | ||
1093 | return 0; | |
1094 | } | |
1095 | ||
7fd59977 | 1096 | //======================================================================= |
1097 | //memory management | |
1098 | //======================================================================= | |
1099 | static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) { | |
1100 | Standard::Purge(); | |
1101 | return 0; | |
1102 | } | |
1103 | //======================================================================= | |
1104 | ||
1105 | //======================================================================= | |
1106 | // check | |
1107 | //======================================================================= | |
1108 | ||
1109 | static Standard_Integer check(Draw_Interpretor& , | |
1110 | Standard_Integer n, const char** a) | |
1111 | { | |
1112 | if (n < 2) return 1; | |
1113 | ||
1114 | Standard_Integer i; | |
1115 | TopExp_Explorer ex; | |
1116 | for (i = 1; i < n; i++) { | |
1117 | TopoDS_Shape S = DBRep::Get(a[i]); | |
1118 | TopoDS_Shape C; | |
1119 | if (S.IsNull()) continue; | |
1120 | for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) { | |
1121 | C = ex.Current(); | |
1122 | C.Checked(Standard_False); | |
1123 | BRepTools::Update(C); | |
1124 | } | |
1125 | } | |
1126 | ||
1127 | return 0; | |
1128 | } | |
1129 | ||
1130 | //======================================================================= | |
1131 | // normals | |
1132 | //======================================================================= | |
68ef63f9 | 1133 | static Standard_Integer normals (Draw_Interpretor& theDI, |
1134 | Standard_Integer theArgNum, | |
1135 | const char** theArgs) | |
7fd59977 | 1136 | { |
68ef63f9 | 1137 | if (theArgNum < 2) |
1138 | { | |
1139 | std::cout << "Syntax error: wrong number of arguments!\n"; | |
1140 | theDI.PrintHelp (theArgs[0]); | |
1141 | return 1; | |
1142 | } | |
7fd59977 | 1143 | |
68ef63f9 | 1144 | TopoDS_Shape aShape = DBRep::Get (theArgs[1]); |
1145 | if (aShape.IsNull()) | |
1146 | { | |
1147 | std::cout << "Error: shape with name " << theArgs[1] << " is not found\n"; | |
1148 | return 1; | |
1149 | } | |
7fd59977 | 1150 | |
68ef63f9 | 1151 | Standard_Boolean toUseMesh = Standard_False; |
1152 | Standard_Real aLength = 10.0; | |
1153 | Standard_Integer aNbAlongU = 1, aNbAlongV = 1; | |
93964cc2 | 1154 | Standard_Boolean bPrint = Standard_False; |
68ef63f9 | 1155 | for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter) |
1156 | { | |
1157 | TCollection_AsciiString aParam (theArgs[anArgIter]); | |
1158 | aParam.LowerCase(); | |
1159 | if (anArgIter == 2 | |
1160 | && aParam.IsRealValue()) | |
1161 | { | |
1162 | aLength = aParam.RealValue(); | |
1163 | if (Abs (aLength) <= gp::Resolution()) | |
1164 | { | |
1165 | std::cout << "Syntax error: length should not be zero\n"; | |
1166 | return 1; | |
1167 | } | |
1168 | } | |
1169 | else if (aParam == "-usemesh" | |
1170 | || aParam == "-mesh") | |
1171 | { | |
1172 | toUseMesh = Standard_True; | |
7fd59977 | 1173 | } |
68ef63f9 | 1174 | else if (aParam == "-length" |
1175 | || aParam == "-len") | |
1176 | { | |
1177 | ++anArgIter; | |
1178 | aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0; | |
1179 | if (Abs(aLength) <= gp::Resolution()) | |
1180 | { | |
1181 | std::cout << "Syntax error: length should not be zero\n"; | |
1182 | return 1; | |
1183 | } | |
1184 | } | |
1185 | else if (aParam == "-nbalongu" | |
1186 | || aParam == "-nbu") | |
1187 | { | |
1188 | ++anArgIter; | |
1189 | aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
1190 | if (aNbAlongU < 1) | |
1191 | { | |
1192 | std::cout << "Syntax error: NbAlongU should be >=1\n"; | |
1193 | return 1; | |
1194 | } | |
1195 | } | |
1196 | else if (aParam == "-nbalongv" | |
1197 | || aParam == "-nbv") | |
1198 | { | |
1199 | ++anArgIter; | |
1200 | aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
1201 | if (aNbAlongV < 1) | |
1202 | { | |
1203 | std::cout << "Syntax error: NbAlongV should be >=1\n"; | |
1204 | return 1; | |
1205 | } | |
1206 | } | |
1207 | else if (aParam == "-nbalong" | |
1208 | || aParam == "-nbuv") | |
1209 | { | |
1210 | ++anArgIter; | |
1211 | aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0; | |
1212 | aNbAlongV = aNbAlongU; | |
1213 | if (aNbAlongU < 1) | |
1214 | { | |
1215 | std::cout << "Syntax error: NbAlong should be >=1\n"; | |
1216 | return 1; | |
1217 | } | |
1218 | } | |
93964cc2 | 1219 | else if (aParam == "-print") |
1220 | { | |
1221 | bPrint = Standard_True; | |
1222 | } | |
68ef63f9 | 1223 | else |
1224 | { | |
93964cc2 | 1225 | std::cout << "Syntax error: unknown argument '" << aParam << "'\n"; |
68ef63f9 | 1226 | return 1; |
1227 | } | |
1228 | } | |
7fd59977 | 1229 | |
68ef63f9 | 1230 | DBRep_WriteColorOrientation(); |
7fd59977 | 1231 | |
68ef63f9 | 1232 | NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals; |
1233 | if (toUseMesh) | |
1234 | { | |
1235 | DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength); | |
1236 | } | |
1237 | else | |
1238 | { | |
1239 | DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV); | |
1240 | } | |
7fd59977 | 1241 | |
68ef63f9 | 1242 | for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next()) |
1243 | { | |
93964cc2 | 1244 | Standard_Boolean bReverse = Standard_False; |
1245 | TopAbs_Orientation aFaceOri = aFaceIt.Key().Orientation(); | |
1246 | const Draw_Color aColor = DBRep_ColorOrientation (aFaceOri); | |
1247 | if (aFaceOri == TopAbs_REVERSED) | |
1248 | bReverse = Standard_True; | |
1249 | ||
68ef63f9 | 1250 | for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next()) |
1251 | { | |
1252 | const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value(); | |
1253 | Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor); | |
1254 | dout << aSeg; | |
93964cc2 | 1255 | if (bPrint) |
1256 | { | |
1257 | // Make the normal vector from the points | |
1258 | gp_Vec aV(aVec.first, aVec.second); | |
1259 | if (bReverse) | |
1260 | aV.Reverse(); | |
1261 | ||
1262 | // Print values of the vector avoiding printing "-0" values | |
1263 | theDI << "(" << (aV.X() == 0 ? 0 : aV.X()) << ", " | |
1264 | << (aV.Y() == 0 ? 0 : aV.Y()) << ", " | |
1265 | << (aV.Z() == 0 ? 0 : aV.Z()) << ")\n"; | |
1266 | } | |
68ef63f9 | 1267 | } |
7fd59977 | 1268 | } |
68ef63f9 | 1269 | |
7fd59977 | 1270 | return 0; |
1271 | } | |
1272 | ||
7fd59977 | 1273 | //======================================================================= |
1274 | //function : Set | |
1275 | //purpose : | |
1276 | //======================================================================= | |
1277 | void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S) | |
1278 | { | |
1279 | Handle(DBRep_DrawableShape) D = | |
1280 | new DBRep_DrawableShape(S, | |
1281 | Draw_vert, | |
1282 | Draw_jaune, | |
1283 | Draw_rouge, | |
1284 | Draw_bleu, | |
1285 | size, | |
1286 | nbIsos, | |
1287 | discret); | |
1288 | D->DisplayTriangulation(disptriangles); | |
1289 | D->DisplayPolygons(disppolygons); | |
1290 | D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR); | |
1291 | Draw::Set(Name,D); | |
1292 | } | |
1293 | //======================================================================= | |
1c8fc6be | 1294 | //function : getShape |
1295 | //purpose : | |
7fd59977 | 1296 | //======================================================================= |
1c8fc6be | 1297 | TopoDS_Shape DBRep::getShape (Standard_CString& theName, |
1298 | TopAbs_ShapeEnum theType, | |
1299 | Standard_Boolean theToComplain) | |
7fd59977 | 1300 | { |
1c8fc6be | 1301 | const Standard_Boolean toPick = theName[0] == '.'; |
1302 | Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName)); | |
1303 | if (aDrawable.IsNull()) | |
1304 | { | |
1305 | return TopoDS_Shape(); | |
1306 | } | |
1307 | ||
1308 | TopoDS_Shape aShape = aDrawable->Shape(); | |
1309 | if (theType != TopAbs_SHAPE | |
1310 | && theType != aShape.ShapeType() | |
1311 | && toPick) | |
1312 | { | |
1313 | // try to find prom pick | |
1314 | Standard_Real u, v; | |
1315 | DBRep_DrawableShape::LastPick (aShape, u, v); | |
1316 | } | |
1317 | if (theType != TopAbs_SHAPE | |
1318 | && theType != aShape.ShapeType()) | |
1319 | { | |
1320 | if (theToComplain) | |
1321 | { | |
1322 | std::cout << theName << " is not a "; | |
1323 | TopAbs::Print (theType, std::cout); | |
1324 | std::cout << " but a "; | |
1325 | TopAbs::Print (aShape.ShapeType(), std::cout); | |
1326 | std::cout << std::endl; | |
7fd59977 | 1327 | } |
1c8fc6be | 1328 | return TopoDS_Shape(); |
7fd59977 | 1329 | } |
1c8fc6be | 1330 | return aShape; |
7fd59977 | 1331 | } |
1332 | ||
1333 | static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv) | |
1334 | { | |
caee80f3 | 1335 | for ( Standard_Integer i=1; i < argc; i++ ) |
1336 | { | |
7fd59977 | 1337 | Standard_Boolean turn = Standard_True; |
1338 | if ( argv[i][0] == '-' ) turn = Standard_False; | |
1339 | else if ( argv[i][0] != '+' ) continue; | |
caee80f3 | 1340 | |
1341 | TCollection_AsciiString anArgCase (argv[i]); | |
1342 | anArgCase.LowerCase(); | |
1343 | if (anArgCase == "-tcloutput") | |
1344 | { | |
1345 | Draw_ProgressIndicator::DefaultTclOutput() = Standard_True; | |
1346 | return 0; | |
1347 | } | |
1348 | else if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn; | |
7fd59977 | 1349 | else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn; |
caee80f3 | 1350 | else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc ) |
1351 | { | |
68299304 | 1352 | Standard_Address aPtr = 0; |
1353 | if (sscanf (argv[++i], "%p", &aPtr) == 1) | |
1354 | Draw_ProgressIndicator::StopIndicator() = aPtr; | |
7fd59977 | 1355 | return 0; |
1356 | } | |
1357 | } | |
1358 | di << "Progress Indicator defaults: text mode is "; | |
1359 | if ( Draw_ProgressIndicator::DefaultTextMode() ) { | |
1360 | di<<"ON"; | |
1361 | } else { | |
1362 | di<<"OFF"; | |
1363 | } | |
1364 | di<<", graphical mode is "; | |
1365 | if ( Draw_ProgressIndicator::DefaultGraphMode() ) { | |
1366 | di<<"ON"; | |
1367 | } else { | |
1368 | di<<"OFF"; | |
1369 | } | |
1370 | di<< "\n"; | |
1371 | return 0; | |
1372 | } | |
1373 | ||
745c1386 | 1374 | //======================================================================= |
1375 | // binsave | |
1376 | //======================================================================= | |
1377 | ||
1378 | static Standard_Integer binsave(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
1379 | { | |
1380 | if (n <= 2) return 1; | |
1381 | ||
1382 | TopoDS_Shape aShape = DBRep::Get (a[1]); | |
1383 | if (aShape.IsNull()) | |
1384 | { | |
1385 | di << a[1] << " is not a shape"; | |
1386 | return 1; | |
1387 | } | |
1388 | ||
1389 | if (!BinTools::Write (aShape, a[2])) | |
1390 | { | |
1391 | di << "Cannot write to the file " << a[2]; | |
1392 | return 1; | |
1393 | } | |
1394 | ||
1395 | di << a[1]; | |
1396 | return 0; | |
1397 | } | |
1398 | ||
1399 | //======================================================================= | |
1400 | // binrestore | |
1401 | //======================================================================= | |
1402 | ||
1403 | static Standard_Integer binrestore(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
1404 | { | |
1405 | if (n <= 2) return 1; | |
1406 | ||
1407 | TopoDS_Shape aShape; | |
1408 | if (!BinTools::Read (aShape, a[1])) | |
1409 | { | |
1410 | di << "Cannot read from the file " << a[1]; | |
1411 | return 1; | |
1412 | } | |
1413 | ||
1414 | DBRep::Set (a[2], aShape); | |
1415 | di << a[2]; | |
1416 | return 0; | |
1417 | } | |
1418 | ||
09543c2d | 1419 | //======================================================================= |
1420 | // removeinternals | |
1421 | //======================================================================= | |
1422 | static Standard_Integer removeInternals (Draw_Interpretor& di, | |
1423 | Standard_Integer n, | |
1424 | const char** a) | |
1425 | { | |
1426 | if (n < 2) | |
1427 | { | |
1428 | di.PrintHelp (a[0]); | |
1429 | return 1; | |
1430 | } | |
1431 | ||
1432 | TopoDS_Shape aShape = DBRep::Get (a[1]); | |
1433 | if (aShape.IsNull()) | |
1434 | { | |
1435 | di << a[1] << "is a null shape\n"; | |
1436 | return 1; | |
1437 | } | |
1438 | ||
1439 | Standard_Boolean isForce = Standard_False; | |
1440 | if (n > 2) | |
1441 | { | |
1442 | isForce = (Draw::Atoi (a[2]) != 0); | |
1443 | } | |
1444 | ||
1445 | BRepTools::RemoveInternals (aShape, isForce); | |
1446 | ||
1447 | DBRep::Set (a[1], aShape); | |
1448 | ||
1449 | return 0; | |
1450 | } | |
1451 | ||
7fd59977 | 1452 | //======================================================================= |
1453 | //function : BasicCommands | |
1454 | //purpose : | |
1455 | //======================================================================= | |
1456 | ||
1457 | static Standard_Boolean done = Standard_False; | |
1458 | void DBRep::BasicCommands(Draw_Interpretor& theCommands) | |
1459 | { | |
1460 | if (done) return; | |
1461 | done = Standard_True; | |
1462 | Draw::Commands(theCommands); | |
1463 | ||
1464 | const char* g = "Basic shape commands"; | |
1465 | ||
1466 | theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g); | |
1467 | theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g); | |
1468 | theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g); | |
1469 | theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g); | |
4b114473 | 1470 | theCommands.Add("tclean", "tclean [-geom] [name1]..., depending on using or not key -geom, \n" |
1471 | "\t erase geometry objects from shapes - key is used or \n" | |
1472 | "\t erase triangulations and polygons on triangulations from shapes - key is omitted \n", | |
1473 | __FILE__, tclean, g); | |
7fd59977 | 1474 | theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g); |
1475 | theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g); | |
1476 | theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g); | |
1477 | theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g); | |
ca4e36ae | 1478 | theCommands.Add("add", |
1479 | "add what where" | |
1480 | "\n adds shape \"what\" to shape \"where\" ", | |
1481 | __FILE__,add,g); | |
7fd59977 | 1482 | theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g); |
b0fbc579 | 1483 | theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g); |
7fd59977 | 1484 | theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g); |
1485 | theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g); | |
1486 | theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g); | |
1487 | ||
1488 | theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g); | |
1489 | theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g); | |
1490 | theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g); | |
1491 | theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g); | |
93964cc2 | 1492 | theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh] [-print], display normals",__FILE__,normals,g); |
bfff00a8 | 1493 | theCommands.Add("nbshapes", |
1494 | "\n nbshapes s - shows the number of sub-shapes in <s>;\n nbshapes s -t - shows the number of sub-shapes in <s> counting the same sub-shapes with different location as different sub-shapes.", | |
1495 | __FILE__,nbshapes,g); | |
7fd59977 | 1496 | theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g); |
1497 | theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g); | |
ebfb9ce2 | 1498 | theCommands.Add("setflags", |
1499 | "setflags shape_name flag1[flag2...]\n sets flags for shape(free, modidfied, checked, orientable, closed, infinite, convex, locked), for exmple <setflags a free> or <setflags a -free> if necessary unflag ", | |
1500 | __FILE__,setFlags,g); | |
7fd59977 | 1501 | |
1502 | // theCommands.Add("dumpmmgt", | |
1503 | // "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g); | |
1504 | theCommands.Add("purgemmgt", | |
0d969553 | 1505 | "returns the free memory from the system to the memory manager", |
7fd59977 | 1506 | __FILE__,purgemmgt,g); |
1507 | ||
1508 | // Add command for DRAW-specific ProgressIndicator | |
caee80f3 | 1509 | theCommands.Add ( "XProgress", |
1510 | "XProgress [+|-t] [+|-g] [-tclOutput]" | |
1511 | "\n\t\t: The options are:" | |
1512 | "\n\t\t: +|-t, +|-g : switch on/off textual and graphical mode of Progress Indicator" | |
1513 | "\n\t\t: -tclOutput : switch on data output mode in tcl" | |
1514 | "\n\t\t: Allows to control the output form of Progress Indicator", | |
1515 | XProgress,"DE: General"); | |
745c1386 | 1516 | |
1517 | theCommands.Add("binsave", "binsave shape filename\n" | |
1518 | "\t\tsave the shape in the binary format file", | |
1519 | __FILE__, binsave, g); | |
1520 | theCommands.Add("binrestore", "binrestore filename shape\n" | |
1521 | "\t\trestore the shape from the binary format file", | |
1522 | __FILE__, binrestore, g); | |
09543c2d | 1523 | |
1524 | theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]" | |
1525 | "\n\t\t Removes sub-shapes with internal orientation from the shape.\n" | |
1526 | "\n\t\t Force flag disables the check on topological connectivity and" | |
1527 | "removes all internal sub-shapes\n", | |
1528 | __FILE__, removeInternals, g); | |
7fd59977 | 1529 | } |
1530 | ||
1531 | //======================================================================= | |
1532 | //function : HLRMode | |
1533 | //purpose : | |
1534 | //======================================================================= | |
1535 | ||
1536 | Standard_Boolean DBRep::HLRMode() | |
1537 | { return withHLR; } | |
1538 | ||
1539 | //======================================================================= | |
1540 | //function : Rg1Mode | |
1541 | //purpose : | |
1542 | //======================================================================= | |
1543 | ||
1544 | Standard_Boolean DBRep::Rg1Mode() | |
1545 | { return withRg1; } | |
1546 | ||
1547 | //======================================================================= | |
1548 | //function : RgNMode | |
1549 | //purpose : | |
1550 | //======================================================================= | |
1551 | ||
1552 | Standard_Boolean DBRep::RgNMode() | |
1553 | { return withRgN; } | |
1554 | ||
1555 | //======================================================================= | |
1556 | //function : HidMode | |
1557 | //purpose : | |
1558 | //======================================================================= | |
1559 | ||
1560 | Standard_Boolean DBRep::HidMode() | |
1561 | { return withHid; } | |
1562 | ||
1563 | //======================================================================= | |
1564 | //function : HLRAngle | |
1565 | //purpose : | |
1566 | //======================================================================= | |
1567 | ||
1568 | Standard_Real DBRep::HLRAngle() | |
1569 | { return anglHLR; } | |
1570 | ||
1571 | //======================================================================= | |
1572 | //function : | |
1573 | //purpose : save and restore shapes | |
1574 | //======================================================================= | |
1575 | ||
1576 | static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d) | |
1577 | { | |
1578 | return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape)); | |
1579 | } | |
1580 | ||
04232180 | 1581 | static void ssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS) |
7fd59977 | 1582 | { |
1583 | Handle(DBRep_DrawableShape) | |
1584 | N = Handle(DBRep_DrawableShape)::DownCast(d); | |
1585 | BRep_Builder B; | |
1586 | BRepTools_ShapeSet S(B); | |
1587 | if(!Draw::GetProgressBar().IsNull()) | |
1588 | S.SetProgress(Draw::GetProgressBar()); | |
1589 | S.Add(N->Shape()); | |
1590 | S.Write(OS); | |
1591 | if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak()) | |
1592 | return; | |
1593 | S.Write(N->Shape(),OS); | |
1594 | } | |
1595 | ||
04232180 | 1596 | static Handle(Draw_Drawable3D) srestore (std::istream& IS) |
7fd59977 | 1597 | { |
1598 | BRep_Builder B; | |
1599 | BRepTools_ShapeSet S(B); | |
1600 | if(!Draw::GetProgressBar().IsNull()) | |
1601 | S.SetProgress(Draw::GetProgressBar()); | |
1602 | S.Read(IS); | |
1603 | Handle(DBRep_DrawableShape) N; | |
1604 | if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak()) | |
1605 | return N; | |
1606 | TopoDS_Shape theShape; | |
1607 | S.Read(theShape,IS ); | |
1608 | N = new DBRep_DrawableShape(theShape, | |
1609 | Draw_vert, | |
1610 | Draw_jaune, | |
1611 | Draw_rouge, | |
1612 | Draw_bleu, | |
1613 | size, | |
1614 | nbIsos, | |
1615 | discret); | |
1616 | N->DisplayTriangulation(disptriangles); | |
1617 | N->DisplayPolygons(disppolygons); | |
1618 | N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR); | |
1619 | ||
1620 | return N; | |
1621 | } | |
1622 | ||
1623 | ||
1624 | static Draw_SaveAndRestore ssr("DBRep_DrawableShape", | |
1625 | stest,ssave,srestore); | |
1626 | ||
1627 | ||
1628 | void dumps (const TopoDS_Shape& S) | |
1629 | { | |
04232180 | 1630 | BRepTools::Dump(S,std::cout); |
7fd59977 | 1631 | } |
1632 | ||
1633 | //======================================================================= | |
1634 | //function : NbIsos | |
1635 | //purpose : | |
1636 | //======================================================================= | |
1637 | ||
1638 | Standard_Integer DBRep::NbIsos() | |
1639 | { return nbIsos; } | |
1640 | ||
1641 | ||
1642 | //======================================================================= | |
1643 | //function : Discretisation | |
1644 | //purpose : | |
1645 | //======================================================================= | |
1646 | ||
1647 | Standard_Integer DBRep::Discretisation() | |
1648 | { return discret; } |