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