0022312: Translation of french commentaries in OCCT files
[occt.git] / src / BRepTest / BRepTest_BasicCommands.cxx
CommitLineData
7fd59977 1// File: BRepTest_BasicCommands.cxx
2// Created: Tue Dec 13 09:48:16 1994
3// Author: Jacques GOUSSARD
4// <jag@phobox>
5
6#include <Standard_Stream.hxx>
7#include <Standard_Macro.hxx>
8
9#include <BRepTest.hxx>
10
11#include <DBRep.hxx>
12#include <Draw_Appli.hxx>
13#include <Draw_Interpretor.hxx>
14#include <Draw_Box.hxx>
15
16#include <BRepBuilderAPI.hxx>
17#include <BRepBuilderAPI_FindPlane.hxx>
18#include <BRepBuilderAPI_Copy.hxx>
19#include <BRepBuilderAPI_Transform.hxx>
20#include <BRepBuilderAPI_GTransform.hxx>
21#include <BRepBuilderAPI_NurbsConvert.hxx>
22#include <gp_Ax2.hxx>
23#include <gp_Mat.hxx>
24#include <gp_GTrsf.hxx>
25#include <BRepOffsetAPI_NormalProjection.hxx>
26#include <BRepLib.hxx>
27#include <BRep_Builder.hxx>
28#include <BRepBndLib.hxx>
29#include <Bnd_Box.hxx>
30#include <TopExp_Explorer.hxx>
31#include <TopoDS.hxx>
32#include <BRepTools_WireExplorer.hxx>
33
34#include <GCPnts_QuasiUniformAbscissa.hxx>
35#include <Geom2dAdaptor_Curve.hxx>
36#include <GeomAdaptor_Curve.hxx>
37#include <ProjLib_ComputeApproxOnPolarSurface.hxx>
38#include <DrawTrSurf.hxx>
39
40
41#include <Draw_Segment3D.hxx>
42#include <Draw_Marker3D.hxx>
43#include <Draw_MarkerShape.hxx>
44
45#include <TopoDS_Face.hxx>
46#include <TopoDS_Edge.hxx>
47#include <TopoDS_Vertex.hxx>
48#include <BRep_Tool.hxx>
49#include <TopTools_ListOfShape.hxx>
50
51#include <stdio.h>
52
53Standard_IMPORT Draw_Viewer dout;
54
55
56
57//=======================================================================
58// addpcurve
59//=======================================================================
60
61static Standard_Integer addpcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
62{
63 if(n < 4) return 1;
64 TopoDS_Shape E = DBRep::Get(a[1]);
65 if (E.IsNull()) return 1;
66 Handle(Geom2d_Curve) PC = DrawTrSurf::GetCurve2d(a[2]);
67 TopoDS_Shape F = DBRep::Get(a[3]);
68 Standard_Real tol = 1.e-7;
69 if (n > 4) {
70 tol = atof(a[4]);
71 }
72 BRep_Builder BB;
73 BB.UpdateEdge(TopoDS::Edge(E), PC, TopoDS::Face(F),tol);
74 DBRep::Set(a[1], E);
75 return 0;
76}
77
78
79//=======================================================================
80// transform
81//=======================================================================
82
83static Standard_Integer transform(Draw_Interpretor& di,Standard_Integer n,const char** a)
84{
85 if (n <= 1) return 1;
86
87 gp_Trsf T;
88 Standard_Integer last = n;
89
90 if (!strcmp(a[0],"reset")) {
91 }
92 else if (!strcmp(a[0],"tmove")) {
93 if (n < 3) return 1;
94 TopoDS_Shape SL = DBRep::Get(a[n-1]);
95 if (SL.IsNull()) return 0;
96 T = SL.Location().Transformation();
97 last = n-1;
98 }
99 else if (!strcmp(a[0],"ttranslate")) {
100 if (n < 5) return 1;
101 T.SetTranslation(gp_Vec(atof(a[n-3]),atof(a[n-2]),atof(a[n-1])));
102 last = n-3;
103 }
104 else if (!strcmp(a[0],"trotate")) {
105 if (n < 9) return 1;
106 T.SetRotation(gp_Ax1(gp_Pnt(atof(a[n-7]),atof(a[n-6]),atof(a[n-5])),
107 gp_Vec(atof(a[n-4]),atof(a[n-3]),atof(a[n-2]))),
108 atof(a[n-1])* PI180);
109 last = n-7;
110 }
111 else if (!strcmp(a[0],"tmirror")) {
112 if (n < 8) return 1;
113 T.SetMirror(gp_Ax2(gp_Pnt(atof(a[n-6]),atof(a[n-5]),atof(a[n-4])),
114 gp_Vec(atof(a[n-3]),atof(a[n-2]),atof(a[n-1]))));
115 last = n-6;
116 }
117 else if (!strcmp(a[0],"tscale")) {
118 if (n < 6) return 1;
119 T.SetScale(gp_Pnt(atof(a[n-4]),atof(a[n-3]),atof(a[n-2])),atof(a[n-1]));
120 last = n-4;
121
122 }
123
124 if (T.Form() == gp_Identity) {
125 TopLoc_Location L;
126 for (Standard_Integer i = 1; i < last; i++) {
127 TopoDS_Shape S = DBRep::Get(a[i]);
128 if (S.IsNull()) {
129 //cout << a[i] << " is not a valid shape" << endl;
130 di << a[i] << " is not a valid shape" << "\n";
131 }
132 else {
133 DBRep::Set(a[i],S.Located(L));
134 }
135 }
136 }
137 else {
138 BRepBuilderAPI_Transform trf(T);
139 for (Standard_Integer i = 1; i < last; i++) {
140 TopoDS_Shape S = DBRep::Get(a[i]);
141 if (S.IsNull()) {
142 //cout << a[i] << " is not a valid shape" << endl;
143 di << a[i] << " is not a valid shape" << "\n";
144 }
145 else {
146 trf.Perform(S);
147 if (trf.IsDone()){
148 DBRep::Set(a[i],trf.Shape());
149 }
150 else {
151 return 1;
152 }
153 }
154 }
155 }
156 return 0;
157}
158
159
160///=======================================================================
161// gtransform
162//=======================================================================
163
164static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a)
165{
166 if (n <= 1) return 1;
167
168 Standard_Integer last = n;
169
170 gp_Trsf T;
171 gp_GTrsf GT(T);
172
173// gp_Mat rot(atof(a[last-3]),0,0,0,atof(a[last-2]),0,0,0,atof(a[last-1]));
174 gp_Mat rot(atof(a[3]),0,0,0,atof(a[4]),0,0,0,atof(a[5]));
175 GT.SetVectorialPart(rot);
176 last -= 3;
177 BRepBuilderAPI_GTransform gtrf(GT);
178 BRepBuilderAPI_NurbsConvert nbscv;
179 // for (Standard_Integer i = 1; i < last; i++) {
180 // TopoDS_Shape S = DBRep::Get(a[i]);
181 TopoDS_Shape S = DBRep::Get(a[2]);
182 if (S.IsNull()) {
183 //cout << a[2] << " is not a valid shape" << endl;
184 di << a[2] << " is not a valid shape" << "\n";
185 }
186 else {
187 gtrf.Perform(S);
188 if (gtrf.IsDone()){
189 DBRep::Set(a[1],gtrf.Shape());
190 }
191 else {
192 return 1;
193 }
194 }
195
196 return 0;
197}
198
199//=======================================================================
200// tcopy
201//=======================================================================
202
203static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a)
204{
205 Standard_Boolean copyGeom = Standard_True;
206 Standard_Integer iFirst = 1; // index of first shape argument
207
208 if (n > 1 && a[1][0] == '-' && a[1][1] == 'n' )
209 {
210 copyGeom = Standard_False;
211 iFirst = 2;
212 }
213
214 if (n < 3 || (n - iFirst) % 2) {
215 cout << "Use: " << a[0] << " [-n(ogeom)] shape1 copy1 [shape2 copy2 [...]]" << endl;
216 cout << "Option -n forbids copying of geometry (it will be shared)" << endl;
217 return 1;
218 }
219
220 BRepBuilderAPI_Copy cop;
221 Standard_Integer nbPairs = (n - iFirst) / 2;
222 for (Standard_Integer i=0; i < nbPairs; i++) {
223 cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom);
224 DBRep::Set(a[i+iFirst+1],cop.Shape());
225 di << a[i+iFirst+1] << " ";
226 }
227 return 0;
228}
229
230
231//=======================================================================
232// NurbsConvert
233//=======================================================================
234
235static Standard_Integer nurbsconvert(Draw_Interpretor& di,Standard_Integer n,const char** a)
236{
237 if (n < 3) return 1;
238 if ((n-1)%2 != 0) return 1;
239 BRepBuilderAPI_NurbsConvert nbscv;
240 for (Standard_Integer i=0; i<(n-1)/2; i++) {
241 TopoDS_Shape S = DBRep::Get(a[2*i+2]);
242 if (S.IsNull()) {
243 //cout << a[2*i+2] << " is not a valid shape" << endl;
244 di << a[2*i+2] << " is not a valid shape" << "\n";
245 }
246 else {
247 nbscv.Perform(S);
248 if (nbscv.IsDone()){
249 DBRep::Set(a[2*i+1],nbscv.Shape());
250 }
251 else {
252 return 1;
253 }
254 }
255 }
256
257 return 0;
258
259}
260
261//=======================================================================
262// make a 3D edge curve
263//=======================================================================
264
265static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a)
266{
267
268 Standard_Boolean CurveDone ;
269
270 if (n < 3) return 1;
271 Standard_Real Tolerance = atof(a[2]) ;
272
273 TopoDS_Shape S = DBRep::Get(a[1]);
274
275 if (S.IsNull()) return 1;
276
277 CurveDone =
278 BRepLib::BuildCurves3d(S,
279 Tolerance) ;
280 return 0 ;
281}
282
283//=======================================================================
284// sameparameter
285//=======================================================================
286
287static Standard_Integer sameparameter(Draw_Interpretor& ,Standard_Integer n,const char** a)
288{
289 if (n < 2) return 1;
290 Standard_Real tol = 1.e-7;
291 TopoDS_Shape S = DBRep::Get(a[1]);
292 if (S.IsNull()) return 1;
293 Standard_Boolean force = !strcmp(a[0],"fsameparameter");
294 if (n == 3) tol = atof(a[2]);
295
296 BRepLib::SameParameter(S,tol,force);
297
298 DBRep::Set(a[1],S);
299 return 0;
300}
301//=======================================================================
302//function : updatetol
303//purpose :
304//=======================================================================
305static Standard_Integer updatetol(Draw_Interpretor& ,Standard_Integer n,const char** a)
306{
307 if (n < 2) return 1;
308
309 TopoDS_Shape S = DBRep::Get(a[1]);
310 if (S.IsNull()) return 1;
311
312 if (n==2) BRepLib::UpdateTolerances(S);
313 else BRepLib::UpdateTolerances(S,Standard_True);
314 DBRep::Set(a[1],S);
315 return 0;
316
317}
318
319//=======================================================================
320//function : OrienSolid
321//purpose :
322//=======================================================================
323static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a)
324{
325 if (n < 2) return 1;
326
327 TopoDS_Shape S = DBRep::Get(a[1]);
328 if (S.IsNull()) return 1;
329 if (S.ShapeType()!=TopAbs_SOLID) return 1;
330
331 BRepLib::OrientClosedSolid(TopoDS::Solid(S));
332
333 DBRep::Set(a[1],S);
334 return 0;
335
336}
337
338//=======================================================================
339//function : boundingstr
340//purpose :
341//=======================================================================
342static Standard_Integer boundingstr(Draw_Interpretor& di,Standard_Integer n,const char** a)
343{
344 if (n < 2) return 1;
345 TopoDS_Shape S = DBRep::Get(a[1]);
346 if (S.IsNull()) return 1;
347 Bnd_Box B;
348 BRepBndLib::Add(S,B);
349 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
350 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
351 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
352 if (n >= 8) {
353 Draw::Set(a[2],axmin) ;
354 Draw::Set(a[3],aymin) ;
355 Draw::Set(a[4],azmin) ;
356 Draw::Set(a[5],axmax) ;
357 Draw::Set(a[6],aymax) ;
358 Draw::Set(a[7],azmax) ;
359 }
360 return 0;
361}
362
363//=======================================================================
364//function : bounding
365//purpose :
366//=======================================================================
367static Standard_Integer bounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
368{
369 if (n < 2) return 1;
370 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
371 Bnd_Box B; Handle(Draw_Box) DB;
372
373 if (n == 2) {
374 TopoDS_Shape S = DBRep::Get(a[1]);
375 if (S.IsNull()) return 1;
376 BRepBndLib::Add(S,B);
377 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
378 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
379 dout<<DB;
380 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
381 }
382 else if (n == 7) {
383 axmin=atof(a[1]);
384 aymin=atof(a[2]);
385 azmin=atof(a[3]);
386 axmax=atof(a[4]);
387 aymax=atof(a[5]);
388 azmax=atof(a[6]);
389 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
390 dout<<DB;
391 }
392 return 0;
393}
394//=======================================================================
395//function : findplane
396//purpose :
397//=======================================================================
398static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a)
399{
400 if (n < 3) return 1;
401 TopoDS_Shape S = DBRep::Get(a[1]);
402 if (S.IsNull()) return 1;
403 Standard_Real tolerance = 1.0e-5 ;
404 BRepBuilderAPI_FindPlane a_plane_finder(S,
405 tolerance) ;
406 if (a_plane_finder.Found()) {
407 //cout << " a plane is found " ;
408 di << " a plane is found \n";
409 DrawTrSurf::Set(a[2],a_plane_finder.Plane()) ;
410 }
411 return 0 ;
412}
413//=======================================================================
414//function : precision
415//purpose :
416//=======================================================================
417
418static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a)
419{
420 n--;
421
422 if ( n == 0) {
423 //cout << " Current Precision = " << BRepBuilderAPI::Precision() << endl;
424 di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n";
425 }
426 else {
427 BRepBuilderAPI::Precision(atof(a[1]));
428 }
429 return 0;
430}
431
432
433//=======================================================================
434//function : reperage shape (Int lin Shape) + pointe double click + maxtol
435//purpose :
436//=======================================================================
437#include <IntCurvesFace_ShapeIntersector.hxx>
438#include <gp_Lin.hxx>
439
440static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a)
441{
442 Standard_Integer details=0;
443 if(narg<2) return 1;
444 if(narg==3) details=1;
445 const char *id1 = a[1];
446 TopoDS_Shape TheShape1 = DBRep::Get(id1);
447
448 //cout << "Pick positions with button "<<endl;
449 di << "Pick positions with button "<< "\n";
450 Standard_Integer id,X,Y,b;
451 gp_Trsf T;
452 gp_Pnt P1,P2;
453 dout.Select(id,X,Y,b);
454
455 dout.GetTrsf(id,T);
456 T.Invert();
457 Standard_Real z = dout.Zoom(id);
458 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0);
459 P2.Transform(T);
460 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0);
461 P1.Transform(T);
462
463
464 gp_Ax1 Axe(P1,gp_Vec(P1,P2));
465 IntCurvesFace_ShapeIntersector Inter;
466 Inter.Load(TheShape1,1e-7);
467
468 Inter.Perform(Axe,-RealLast(),RealLast());
469
470 //cout<<"\n --> ";
471 di <<"\n --> ";
472 if(Inter.NbPnt()) {
473 for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) {
474 Standard_Integer numface=1;
475 TopExp_Explorer ExF;
476 for(ExF.Init(TheShape1,TopAbs_FACE);
477 ExF.More();
478 ExF.Next(),numface++) {
479 TopoDS_Face Face=TopoDS::Face(ExF.Current());
480 if(Face.IsEqual(Inter.Face(i))) {
481 //cout<<" "<<a[1]<<"_"<<numface;
482 di<<" "<<a[1]<<"_"<<numface;
483 continue;
484 }
485 }
486 const gp_Pnt& P = Inter.Pnt(i);
487 Standard_Real PMin = Inter.WParameter(i);
488 if(details) {
489 //cout<<" w:"<<PMin<<endl;
490 di<<" w:"<<PMin<< "\n";
491 }
492 if(Inter.Transition(i) == IntCurveSurface_In) {
493 if(Inter.State(i) == TopAbs_IN) {
494 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2);
495 dout << p; dout.Flush();
496 }
497 else if(Inter.State(i) == TopAbs_ON) {
498 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2);
499 dout << p; dout.Flush();
500 }
501 }
502 else {
503 if(Inter.Transition(i) == IntCurveSurface_Out) {
504 if(Inter.State(i) == TopAbs_IN) {
505 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2);
506 dout << p; dout.Flush();
507 }
508 else if(Inter.State(i) == TopAbs_ON) {
509 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2);
510 dout << p; dout.Flush();
511 }
512 }
513 }
514 }
515 }
516 //cout<<endl;
517 di << "\n";
518 return(0);
519}
520
521
522static Standard_Integer maxtolerance(Draw_Interpretor& theCommands,
523 Standard_Integer n, const char** a) {
524 if(n<2) return(1);
525 TopoDS_Shape TheShape = DBRep::Get(a[1]);
526 if(TheShape.IsNull()) return(1);
527
528 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
529 Standard_Integer nbF,nbE,nbV;
530 TMF=TME=TMV=-RealLast();
531 TmF=TmE=TmV=RealLast();
532 nbF=nbE=nbV=0;
533
534 TopExp_Explorer ExF;
535 for(ExF.Init(TheShape,TopAbs_FACE);
536 ExF.More();
537 ExF.Next()) {
538 TopoDS_Face Face=TopoDS::Face(ExF.Current());
539 T=BRep_Tool::Tolerance(Face);
540 if(T>TMF) TMF=T;
541 if(T<TmF) TmF=T;
542 nbF++;
543 }
544 TopExp_Explorer ExE;
545 for(ExE.Init(TheShape,TopAbs_EDGE);
546 ExE.More();
547 ExE.Next()) {
548 TopoDS_Edge Edge=TopoDS::Edge(ExE.Current());
549 T=BRep_Tool::Tolerance(Edge);
550 if(T>TME) TME=T;
551 if(T<TmE) TmE=T;
552 nbE++;
553 }
554 TopExp_Explorer ExV;
555 for(ExV.Init(TheShape,TopAbs_VERTEX);
556 ExV.More();
557 ExV.Next()) {
558 TopoDS_Vertex Vertex=TopoDS::Vertex(ExV.Current());
559 T=BRep_Tool::Tolerance(Vertex);
560 if(T>TMV) TMV=T;
561 if(T<TmV) TmV=T;
562 nbV++;
563 }
564
565// printf("\n## Tolerances sur le shape %s (nbFaces:%3d nbEdges:%3d nbVtx:%3d)\n",a[1],nbF,nbE,nbV);
566// if(TmF<=TMF) printf("\n Face : Min %+5.8e Max %+5.8e \n ",TmF,TMF);
567// if(TmE<=TME) printf("\n Edge : Min %+5.8e Max %+5.8e \n ",TmE,TME);
568// if(TmV<=TMV) printf("\n Vertex : Min %+5.8e Max %+5.8e \n\n ",TmV,TMV);
569
570#ifndef WNT
571 Standard_SStream sss;
572 sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF
573 << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ;
574 sss.precision(5);
575 sss.setf(ios::scientific);
576 if(TmF<=TMF) sss << "\n Face : Min " << setw(8) << TmF <<" Max " << setw(8) << TMF << " \n ";
577 if(TmE<=TME) sss << "\n Edge : Min " << setw(8) << TmE <<" Max " << setw(8) << TME << " \n ";
578 if(TmV<=TMV) sss << "\n Vertex : Min " << setw(8) << TmV <<" Max " << setw(8) << TMV << " \n ";
579 theCommands << sss;
580#endif
581 return(0);
582}
583
584
585static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) {
586 //cout << "Pick positions with button "<<endl;
587 di << "Pick positions with button "<< "\n";
588
589 Standard_Integer id,X,Y,b;
590 gp_Trsf T;
591 gp_Pnt P1,P2,PP1,PP2;
592
593 //-----------------------------------------------------------
594 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
595 T.Invert();
596 Standard_Real z = dout.Zoom(id);
597 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
598 P1.Transform(T);
599
600 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
601 T.Invert(); z = dout.Zoom(id);
602
603 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
604 P2.Transform(T);
605 Standard_Real xa,ya,za;
606 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
607 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
608 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
609 P1.SetCoord(xa,ya,za);
610 Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(),
611 P1.Y(),
612 P1.Z()),
613 Draw_Square,Draw_blanc,1);
614
615 dout << D0;
616 dout.Flush();
617 //-----------------------------------------------------------
618 dout.Select(id,X,Y,b);
619 dout.GetTrsf(id,T);
620 T.Invert();
621 z = dout.Zoom(id);
622 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
623 PP1.Transform(T);
624 dout.Select(id,X,Y,b);
625 dout.GetTrsf(id,T);
626 T.Invert();
627 z = dout.Zoom(id);
628 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
629 PP2.Transform(T);
630 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
631 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
632 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
633 PP1.SetCoord(xa,ya,za);
634 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc);
635 dout << d;
636 dout.Flush();
637 //cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<endl;
638 di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n";
639
640 static Standard_Integer nboxvecdp=0;
641 //cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
642 //cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<endl;
643
644 //cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
645 // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
646 // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<endl;
647
648 di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
649 di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n";
650
651 di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
652 +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
653 +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n";
654 return(0);
655}
656//=======================================================================
657// nproject
658//=======================================================================
659
660#include <TopTools_SequenceOfShape.hxx>
661 static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
662{
663 if ( n < 4) return 1;
664 TopoDS_Shape InpShape;
665 Standard_Integer arg = 2, i;
666 TopTools_SequenceOfShape Args;
667
668 Standard_Real Tol = 1.e-4;
669 Standard_Real Tol2d;
670 Standard_Real MaxDistance = 1.e-3;
671 GeomAbs_Shape Continuity = GeomAbs_C2;
672 Standard_Integer MaxDeg = 14;
673 Standard_Integer MaxSeg = 16;
674
675 while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){
676 Args.Append(InpShape);
677 arg++;
678 }
679 if(Args.Length() < 2) return 1;
680
681 BRepOffsetAPI_NormalProjection OrtProj(Args.Last());
682
683 for(i = 1; i < Args.Length(); i++)
684 OrtProj.Add(Args(i));
685
686 if(n > arg)
687 if (!strcmp(a[arg],"-g")) {
688 OrtProj.SetLimit(Standard_False);
689 arg++;
690 }
691
692 if(n > arg)
693 if (!strcmp(a[arg],"-d")) {
694 arg++;
695 if(n > arg)
696 MaxDistance = atof(a[arg++]);
697 OrtProj.SetMaxDistance(MaxDistance);
698 }
699 if(n > arg) {
700 Tol = Max(atof(a[arg++]),1.e-10);
701 }
702
703 if(n > arg) {
704 if (atoi(a[arg]) == 0) Continuity = GeomAbs_C0;
705 else if (atoi(a[arg]) == 1) Continuity = GeomAbs_C1;
706 arg++;
707 }
708
709
710 if(n > arg) {
711 MaxDeg = atoi(a[arg++]);
712 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
713 }
714
715 if(n > arg) MaxSeg = atoi(a[arg]);
716
717 Tol2d = Pow(Tol, 2./3);
718
719 OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg);
720 OrtProj.Build();
721 TopTools_ListOfShape Wire;
722 Standard_Boolean IsWire=OrtProj.BuildWire(Wire);
723 if (IsWire) {
724 //cout << " BuildWire OK " << endl;
725 di << " BuildWire OK " << "\n";
726 }
727 DBRep::Set(a[1], OrtProj.Shape());
728 return 0;
729}
730
731//==========================================================================
732//function : wexplo
733// exploration d un wire
734//==========================================================================
735static Standard_Integer wexplo (Draw_Interpretor&,
736 Standard_Integer argc, const char** argv)
737{
738 char name[100];
739 if (argc < 2) return 1;
740
741 TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE);
742 TopoDS_Shape C2 ;
743
744 if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE);
745
746 if (C1.IsNull()) return 1;
747
748 BRepTools_WireExplorer we;
749 if (C2.IsNull()) we.Init(TopoDS::Wire(C1));
750 else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2));
751
752 Standard_Integer k = 1;
753 while (we.More()) {
754 TopoDS_Edge E = we.Current();
755 sprintf(name,"WEDGE_%d",k);
756 DBRep::Set(name,E);
757 we.Next();
758 k++;
759 }
760
761 return 0;
762}
763
764
765
766void BRepTest::BasicCommands(Draw_Interpretor& theCommands)
767{
768 static Standard_Boolean done = Standard_False;
769 if (done) return;
770 done = Standard_True;
771
772 DBRep::BasicCommands(theCommands);
773
774 const char* g = "TOPOLOGY Basic shape commands";
775
776 theCommands.Add("addpcurve",
777 "addpcurve edge 2dcurve face [tol (default 1.e-7)]",
778 __FILE__,
779 addpcurve,g);
780
781 theCommands.Add("reset",
782 "reset name1 name2..., remove location",
783 __FILE__,
784 transform,g);
785
786 theCommands.Add("tmove",
787 "tmove name1 name2 ... name(location)",
788 __FILE__,
789 transform,g);
790
791 theCommands.Add("ttranslate",
792 "tmove name1 name2 ... dx dy dz",
793 __FILE__,
794 transform,g);
795
796 theCommands.Add("trotate","trotate name1 name2 ... x y z dx dy dz angle",
797 __FILE__,
798 transform,g);
799
800 theCommands.Add("tmirror",
801 "tmirror name x y z dx dy dz",
802 __FILE__,
803 transform,g);
804
805 theCommands.Add("tscale",
806 "tscale name x y z scale",
807 __FILE__,
808 transform,g);
809
810 theCommands.Add("tcopy",
811 "tcopy [-n(ogeom)] name1 result1 [name2 result2 ...]",
812 __FILE__,
813 tcopy,g);
814
815 theCommands.Add("precision",
816 "precision [preci]",
817 __FILE__,
818 precision,g);
819
820 theCommands.Add("mkedgecurve",
821 "mkedgecurve name tolerance",
822 __FILE__,
823 mkedgecurve,g);
824
825 theCommands.Add("fsameparameter",
826 "fsameparameter shapename [tol (default 1.e-7)], \nforce le sameparameter sur toutes les aretes du shape",
827 __FILE__,
828 sameparameter,g);
829
830 theCommands.Add("sameparameter",
831 "sameparameter shapename [tol (default 1.e-7)]",
832 __FILE__,
833 sameparameter,g);
834
835 theCommands.Add("updatetolerance",
836 "updatetolerance myShape [param] \n if [param] is absent - not verify of face tolerance, else - perform it",
837 __FILE__,
838 updatetol,g);
839
840 theCommands.Add("solidorientation",
841 "orientsolid myClosedSolid",
842 __FILE__,
843 orientsolid,g);
844
845 theCommands.Add("bounding",
846 "bounding shape [ xmin ymin zmin xmax ymax zmax] ; draw bounds",
847 __FILE__,
848 bounding,g);
849
850 theCommands.Add("boundingstr",
851 "boundingstr shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box",
852 __FILE__,
853 boundingstr,g);
854
855 theCommands.Add("nurbsconvert",
856 "nurbsconvert result name [result name]",
857 __FILE__,
858 nurbsconvert,g);
859
860 theCommands.Add("deform",
861 "deform newname name CoeffX CoeffY CoeffZ",
862 __FILE__,
863 deform,g);
864
865 theCommands.Add("findplane",
866 "findplane name planename ",
867 __FILE__,
868 findplane,g) ;
869
870 theCommands.Add("maxtolerance",
871 "maxtolerance shape ",
872 __FILE__,
873 maxtolerance,g) ;
874
875 theCommands.Add("reperageshape",
876 "reperage shape -> list of shape (result of interstion shape , line)",
877 __FILE__,
878 reperageshape,g) ;
879
880 theCommands.Add("vecdc",
881 "vecdc + Pointe double click ",
882 __FILE__,
883 vecdc,g) ;
884
885 theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]",
886 __FILE__,
887 nproject,g);
888
889 theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i",
890 __FILE__,
891 wexplo,g);
892}