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