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