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