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