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