0028574: Get rid of the TestTopOpe* packages
[occt.git] / src / BRepTest / BRepTest_SurfaceCommands.cxx
1 // Created on: 1993-07-22
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <stdio.h>
18 #include <BRepTest.hxx>
19 #include <GeometryTest.hxx>
20
21 #include <DrawTrSurf.hxx>
22 #include <DBRep.hxx>
23 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
25
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepLib.hxx>
29 #include <BRepTools_Quilt.hxx>
30 #include <BRepAdaptor_Curve.hxx>
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRepBuilderAPI_MakeShell.hxx>
33 #include <BRepBuilderAPI.hxx>
34 #include <BRepBuilderAPI_Sewing.hxx>
35 #include <BRepOffsetAPI_FindContigousEdges.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <Geom_Surface.hxx>
40 #include <Geom2d_TrimmedCurve.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_SequenceOfShape.hxx>
43 #include <Precision.hxx>
44 #include <Draw_ProgressIndicator.hxx>
45 #include <NCollection_Vector.hxx>
46 #include <BRepBuilderAPI_FastSewing.hxx>
47
48 #include <GeomAPI_ProjectPointOnSurf.hxx>
49
50 #ifdef _WIN32
51 //#define strcasecmp strcmp Already defined
52 #include <stdio.h>
53 #endif
54
55 //-----------------------------------------------------------------------
56 // suppressarg : suppress a[d],modifie na--
57 //-----------------------------------------------------------------------
58 static void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d) 
59 {
60   for(Standard_Integer i=d;i<na;i++) {
61     a[i]=a[i+1];
62     a[i+1]=NULL;
63   }
64   na--;
65 }
66
67
68 //=======================================================================
69 // mkface
70 //=======================================================================
71
72 static Standard_Integer mkface(Draw_Interpretor& , Standard_Integer n, const char** a)
73 {
74   if (n < 3) return 1;
75   
76   Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
77   if (S.IsNull()) {
78     cout << a[2] << " is not a surface" << endl;
79     return 1;
80   }
81   
82   Standard_Boolean mkface = a[0][2] == 'f';
83   TopoDS_Shape res;
84
85   Standard_Boolean Segment = Standard_False;
86   if ( !mkface && (n == 4 || n == 8)) {
87     Segment = !strcmp(a[n-1],"1");
88     n--;
89   }
90
91   if (n == 3) {
92     if (mkface)
93       res = BRepBuilderAPI_MakeFace(S, Precision::Confusion());
94     else
95       res = BRepBuilderAPI_MakeShell(S,Segment);
96   }
97   else if (n <= 5) {
98     if (!mkface) return 1;
99     Standard_Boolean orient = (n  == 4);
100     TopoDS_Shape W = DBRep::Get(a[3],TopAbs_WIRE);
101     if (W.IsNull()) return 1;
102     res = BRepBuilderAPI_MakeFace(S,TopoDS::Wire(W),orient);
103   }
104   else {
105     if (mkface)
106       res = BRepBuilderAPI_MakeFace(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),Precision::Confusion());
107     else
108       res = BRepBuilderAPI_MakeShell(S,Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]),
109                               Segment);
110   }
111   
112   DBRep::Set(a[1],res);
113   return 0;
114 }
115
116 //=======================================================================
117 // quilt
118 //=======================================================================
119
120 static Standard_Integer quilt(Draw_Interpretor& , Standard_Integer n, const char** a)
121 {
122   if (n < 4) return 1;
123   BRepTools_Quilt Q;
124
125   Standard_Integer i = 2;
126   while (i < n) {
127     TopoDS_Shape S = DBRep::Get(a[i]);
128     if (!S.IsNull()) {
129       if (S.ShapeType() == TopAbs_EDGE) {
130         if (i+1 < n) {
131           TopoDS_Shape E = DBRep::Get(a[i+1]);
132           if (!E.IsNull()) {
133             if (E.ShapeType() == TopAbs_EDGE) {
134               i++;
135               Q.Bind(TopoDS::Edge(S),TopoDS::Edge(E));
136             }
137           }
138         }
139       }
140       if (S.ShapeType() == TopAbs_VERTEX) {
141         if (i+1 < n) {
142           TopoDS_Shape E = DBRep::Get(a[i+1]);
143           if (!E.IsNull()) {
144             if (E.ShapeType() == TopAbs_VERTEX) {
145               i++;
146               Q.Bind(TopoDS::Vertex(S),TopoDS::Vertex(E));
147             }
148           }
149         }
150       }
151       else {
152         Q.Add(S);
153       }
154     }
155     i++;
156   }
157
158   DBRep::Set(a[1],Q.Shells());
159   return 0;
160 }
161
162
163 //=======================================================================
164 // mksurface
165 //=======================================================================
166
167 static Standard_Integer mksurface(Draw_Interpretor& , Standard_Integer n, const char** a)
168 {
169   if (n < 3) return 1;
170
171   TopoDS_Shape S = DBRep::Get(a[2],TopAbs_FACE);
172   if (S.IsNull()) return 1;
173   TopLoc_Location L;
174   Handle(Geom_Surface) C = BRep_Tool::Surface(TopoDS::Face(S),L);
175
176
177   DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
178   return 0;
179 }
180
181 //=======================================================================
182 // mkplane
183 //=======================================================================
184
185 static Standard_Integer mkplane(Draw_Interpretor& theDI, Standard_Integer n, const char** a)
186 {
187   if (n < 3) return 1;
188
189   TopoDS_Shape S = DBRep::Get(a[2],TopAbs_WIRE);
190   if (S.IsNull()) return 1;
191
192   Standard_Boolean OnlyPlane = Standard_False;
193   if ( n == 4) {
194     OnlyPlane =  !strcmp(a[3],"1");
195   }
196
197   BRepBuilderAPI_MakeFace aMF(TopoDS::Wire(S), OnlyPlane);
198
199   switch(aMF.Error())
200   {
201   case BRepBuilderAPI_FaceDone:
202     DBRep::Set(a[1],aMF.Face());
203     break;
204   case BRepLib_NoFace:
205     theDI << "Error. mkplane has been finished with \"No Face\" status.\n";
206     break;
207   case BRepLib_NotPlanar:
208     theDI << "Error. mkplane has been finished with \"Not Planar\" status.\n";
209     break;
210   case BRepLib_CurveProjectionFailed:
211     theDI << "Error. mkplane has been finished with \"Fail in projection curve\" status.\n";
212     break;
213   case BRepLib_ParametersOutOfRange:
214     theDI << "Error. mkplane has been finished with \"Parameters are out of range\" status.\n";
215     break;
216   default:
217     theDI << "Error. Undefined status. Please check the code.\n";
218     break;
219   }
220
221   return 0;
222 }
223
224 //=======================================================================
225 // pcurve
226 //=======================================================================
227 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
228 Standard_IMPORT void DBRep_WriteColorOrientation ();
229 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
230
231 static Standard_Integer pcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
232 {
233   Standard_Boolean mute = Standard_False;
234   for(Standard_Integer ia=1;ia<n;ia++) {
235     if (!strcasecmp(a[ia],"-mute")) {
236       suppressarg(n,a,ia);
237       mute = Standard_True;
238     }
239   }
240
241   if (n == 2) {
242     // pcurves of a face
243     TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
244     if (S.IsNull()) return 1;
245
246     if (!mute) DBRep_WriteColorOrientation();
247     Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
248
249     char* name = new char[100];
250     Standard_Real f,l;
251     S.Orientation(TopAbs_FORWARD);
252     TopExp_Explorer ex(S,TopAbs_EDGE);
253     for (Standard_Integer i=1; ex.More(); ex.Next(), i++) {
254       const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
255         (TopoDS::Edge(ex.Current()),TopoDS::Face(S),f,l);
256       if ( c.IsNull() ) {
257         cout << "Error: Edge " << i << " does not have pcurve" << endl;
258         continue;
259       }
260       col = DBRep_ColorOrientation(ex.Current().Orientation());
261       DrawTrSurf_CurveColor(col);
262
263       Sprintf(name,"%s_%d",a[1],i);
264       DrawTrSurf::Set(name,new Geom2d_TrimmedCurve(c,f,l));
265     }
266     DrawTrSurf_CurveColor(savecol);
267
268   }
269   else if (n >= 4) {
270     TopoDS_Shape SE = DBRep::Get(a[2],TopAbs_EDGE);
271     if (SE.IsNull()) return 1;
272     TopoDS_Shape SF = DBRep::Get(a[3],TopAbs_FACE);
273     if (SF.IsNull()) return 1;
274
275     Draw_Color col, savecol = DrawTrSurf_CurveColor(Draw_rouge);
276     Standard_Real f,l;
277     const Handle(Geom2d_Curve) c = BRep_Tool::CurveOnSurface
278       (TopoDS::Edge(SE),TopoDS::Face(SF),f,l);
279
280     col = DBRep_ColorOrientation(SE.Orientation());
281     DrawTrSurf_CurveColor(col);
282     DrawTrSurf::Set(a[1],new Geom2d_TrimmedCurve(c,f,l));
283     DrawTrSurf_CurveColor(savecol);
284   }
285   else { 
286     return 1;
287   }
288     
289   return 0;
290 }
291
292 //=======================================================================
293 // sewing
294 //=======================================================================
295
296 static Standard_Integer sewing (Draw_Interpretor& theDi, 
297                                 Standard_Integer theArgc, const char** theArgv)
298 {
299   BRepBuilderAPI_Sewing aSewing;
300   Standard_Integer aPar = 1;
301   TopTools_SequenceOfShape aSeq;
302
303   Standard_Real aTol = 1.0e-06;
304   Standard_Boolean aSewingMode = Standard_True;
305   Standard_Boolean anAnalysisMode = Standard_True;
306   Standard_Boolean aCuttingMode = Standard_True;
307   Standard_Boolean aNonManifoldMode = Standard_False;
308   Standard_Boolean aSameParameterMode = Standard_True;
309   Standard_Boolean aFloatingEdgesMode = Standard_False;
310   Standard_Boolean aFaceMode = Standard_True;
311   Standard_Boolean aSetMinTol = Standard_False;
312   Standard_Real aMinTol = 0.;
313   Standard_Real aMaxTol = Precision::Infinite();
314
315   for (Standard_Integer i = 2; i < theArgc; i++)
316   {
317     if (theArgv[i][0] == '-' || theArgv[i][0] == '+')
318     {
319       Standard_Boolean aVal = (theArgv[i][0] == '+' ? Standard_True : Standard_False);
320       switch (tolower(theArgv[i][1]))
321       {
322       case 'm':
323         {
324           if (tolower(theArgv[i][2]) == 'i' && i+1 < theArgc)
325           {
326             if (Draw::Atof (theArgv[i+1]))
327             {
328               aMinTol = Draw::Atof (theArgv[++i]);
329               aSetMinTol = Standard_True;
330             }
331             else
332             {
333               theDi << "Error! min tolerance can't possess the null value\n";
334               return (1);
335             }
336           }
337           if (tolower(theArgv[i][2]) == 'a' && i+1 < theArgc)
338           {
339             if (Draw::Atof (theArgv[i+1]))
340               aMaxTol = Draw::Atof (theArgv[++i]);
341             else
342             {
343               theDi << "Error! max tolerance can't possess the null value\n";
344               return (1);
345             }
346           }
347         }
348         break;
349       case 's': aSewingMode = aVal; break;
350       case 'a': anAnalysisMode = aVal; break;
351       case 'c': aCuttingMode = aVal; break;
352       case 'n': aNonManifoldMode = aVal; break;
353       case 'p': aSameParameterMode = aVal; break;
354       case 'e': aFloatingEdgesMode = aVal; break;
355       case 'f': aFaceMode = aVal; break;
356       }
357     }
358     else
359     {
360       TopoDS_Shape aShape = DBRep::Get (theArgv[i]);
361       if (!aShape.IsNull())
362       {
363         aSeq.Append (aShape);
364         aPar++;
365       }
366       else
367       {
368         if (Draw::Atof (theArgv[i]))
369           aTol = Draw::Atof (theArgv[i]);
370       }
371     }
372   }
373    
374   if (aPar < 2)
375   {
376     theDi << "Use: " << theArgv[0] << " result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]\n";
377     theDi << "To set user's value of min/max tolerances the following syntax is used: +<parameter> <value>\n";
378     theDi << "- parameters are identified by letters:\n";
379     theDi << "  mint - min tolerance\n";
380     theDi << "  maxt - max tolerance\n";
381     theDi << "Switches allow to tune other parameters of Sewing\n";
382     theDi << "The following syntax is used: <symbol><parameter>\n";
383     theDi << "- symbol may be - to set parameter off, + to set on\n";
384     theDi << "- parameters are identified by letters:\n";
385     theDi << "  s - mode for creating sewed shape\n";
386     theDi << "  a - mode for analysis of input shapes\n";
387     theDi << "  c - mode for cutting of free edges\n";
388     theDi << "  n - mode for non manifold processing\n";
389     theDi << "  p - mode for same parameter processing for edges\n";
390     theDi << "  e - mode for sewing floating edges\n";
391     theDi << "  f - mode for sewing faces\n";
392     return (1);
393   }
394     
395   if (!aSetMinTol)
396     aMinTol = aTol*1e-4;
397   if (aTol < Precision::Confusion())
398     aTol = Precision::Confusion();
399   if (aMinTol < Precision::Confusion())
400     aMinTol = Precision::Confusion();
401   if (aMinTol > aTol)
402   {
403     theDi << "Error! min tolerance can't exceed working tolerance\n";
404     return (1);
405   }
406   if (aMaxTol < aTol)
407   {
408     theDi << "Error! max tolerance can't be less than working tolerance\n";
409     return (1);
410   }
411
412   aSewing.Init (aTol, aSewingMode, anAnalysisMode, aCuttingMode, aNonManifoldMode);
413   aSewing.SetSameParameterMode (aSameParameterMode);
414   aSewing.SetFloatingEdgesMode (aFloatingEdgesMode);
415   aSewing.SetFaceMode (aFaceMode);
416   aSewing.SetMinTolerance (aMinTol);
417   aSewing.SetMaxTolerance (aMaxTol);
418
419   for (Standard_Integer i = 1; i <= aSeq.Length(); i++)
420     aSewing.Add(aSeq.Value(i));
421   
422   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDi, 1);
423   aSewing.Perform (aProgress);
424   aSewing.Dump();
425
426   const TopoDS_Shape& aRes = aSewing.SewedShape();
427   if (!aRes.IsNull())
428     DBRep::Set(theArgv[1], aRes);
429   return 0;
430 }
431
432 //=======================================================================
433 //function : fastsewing
434 //purpose  : 
435 //=======================================================================
436 Standard_Integer fastsewing (Draw_Interpretor& theDI, 
437                             Standard_Integer theNArg, 
438                             const char** theArgVal)
439 {
440   if(theNArg < 3)
441   {
442     //                0         1       2     3         4
443     theDI << "Use: fastsewing result [-tol <value>] <list_of_faces>\n";
444     return 1;
445   }
446
447   BRepBuilderAPI_FastSewing aFS;
448
449   Standard_Integer aStartIndex = 2;
450
451   if(!strcmp(theArgVal[aStartIndex], "-tol"))
452   {
453     aFS.SetTolerance(Draw::Atof (theArgVal[aStartIndex+1]));
454     aStartIndex = 4;
455   }
456
457   for(Standard_Integer i = aStartIndex; i < theNArg; i++)
458   {
459     TopoDS_Shape aS = DBRep::Get(theArgVal[i]);
460     
461     if(!aFS.Add(aS))
462     {
463       theDI << "Face is not added. See statuses.\n";
464     }
465   }
466
467   BRepBuilderAPI_FastSewing::FS_VARStatuses aStatus = aFS.GetStatuses();
468
469   if(aStatus)
470   {
471     theDI << "Error: There are some problems while adding (" <<
472                         (static_cast<Standard_Integer>(aStatus)) << ")\n";
473     aFS.GetStatuses(&cout);
474   }
475
476   aFS.Perform();
477
478   aStatus = aFS.GetStatuses();
479
480   if(aStatus)
481   {
482     theDI << "Error: There are some problems while performing (" <<
483                         (static_cast<Standard_Integer>(aStatus)) << ")\n";
484     aFS.GetStatuses(&cout);
485   }
486
487   DBRep::Set(theArgVal[1], aFS.GetResult());
488
489   return 0;
490 }
491
492 //=======================================================================
493 // continuity
494 //=======================================================================
495
496 static Standard_Integer continuity (Draw_Interpretor& , 
497                                     Standard_Integer n, const char** a)
498 {
499   if (n < 2) return (1);
500
501   BRepOffsetAPI_FindContigousEdges aFind;
502
503   TopoDS_Shape sh = DBRep::Get(a[1]);
504   Standard_Integer i=1;
505   if (sh.IsNull()) {
506     if (n < 3) return (1);
507     Standard_Real tol = Draw::Atof(a[1]);
508     aFind.Init(tol, Standard_False);
509     i = 2;
510   }
511   
512   while (i < n) {
513     sh = DBRep::Get(a[i]);
514     aFind.Add(sh);
515     i++;
516   }
517
518   aFind.Perform();
519   aFind.Dump();
520
521   return 0;
522 }
523
524 //=======================================================================
525 // encoderegularity
526 //=======================================================================
527 static Standard_Integer encoderegularity (Draw_Interpretor& , 
528                                           Standard_Integer n, const char** a)
529
530 {
531   if (n < 2) return 1;
532   TopoDS_Shape sh = DBRep::Get(a[1]);
533   if (sh.IsNull()) return 1;
534   if (n==2) 
535     BRepLib::EncodeRegularity(sh);
536   else {
537     Standard_Real Tol = Draw::Atof(a[2]);
538     Tol *= M_PI/180.;
539     BRepLib::EncodeRegularity(sh, Tol);
540   }
541   return 0;
542 }
543
544 static Standard_Integer getedgeregul
545   (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
546 {
547   if( argc < 3)
548   {
549     cout<<"Invalid number of arguments. Should be: checkedgeregularity edge face1 [face2]"<<endl;
550     return 1;
551   }
552   
553   TopoDS_Shape anEdge =  DBRep::Get(argv[1],TopAbs_EDGE);
554   TopoDS_Shape aFace1 = DBRep::Get(argv[2],TopAbs_FACE);
555   TopoDS_Shape aFace2 = (argc > 3  ? DBRep::Get(argv[3],TopAbs_FACE) : aFace1);
556   if( anEdge.IsNull() || aFace1.IsNull() || aFace2.IsNull())
557   {
558     cout<<"Invalid number of arguments. Should be: getedgeregularity edge face1 [face2]"<<endl;
559     return 1;
560   }
561  
562   GeomAbs_Shape aRegularity = BRep_Tool::Continuity(TopoDS::Edge(anEdge), TopoDS::Face(aFace1),  TopoDS::Face(aFace2));
563   TCollection_AsciiString aStrReg("Regularity of edge : ");
564   switch( aRegularity)
565   {
566     default:
567     case GeomAbs_C0 : aStrReg += "C0"; break;
568     case GeomAbs_G1 : aStrReg += "G1"; break;
569     case GeomAbs_C1 : aStrReg += "C1"; break;
570     case GeomAbs_G2 : aStrReg += "G2"; break;
571     case GeomAbs_C2 : aStrReg += "C2"; break;
572     case GeomAbs_C3 : aStrReg += "C3"; break;
573     case GeomAbs_CN : aStrReg += "CN"; break;
574   };
575
576   di<<aStrReg.ToCString()<<"\n";
577   return 0; // Done
578 }
579
580 //=======================================================================
581 //function : projponf
582 //purpose  : 
583 //=======================================================================
584 static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
585 {
586   if (n < 3 || n > 5) {
587     di << "Project point on the face.\n";
588     di << "Usage: projponf face pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n";
589     return 1;
590   }
591   // get face
592   TopoDS_Shape aS = DBRep::Get(a[1]);
593   if (aS.IsNull()) {
594     di << "the face is a null shape\n";
595     return 0;
596   }
597   //
598   if (aS.ShapeType() != TopAbs_FACE) {
599     di << "not a face\n";
600     return 0;
601   }
602   //
603   const TopoDS_Face& aFace = *(TopoDS_Face*)&aS;
604   //
605   // get point
606   gp_Pnt aP;
607   DrawTrSurf::GetPoint(a[2], aP);
608   //
609   // get projection options
610   // default values;
611   Extrema_ExtAlgo anExtAlgo = Extrema_ExtAlgo_Grad;
612   Extrema_ExtFlag anExtFlag = Extrema_ExtFlag_MINMAX;
613   //
614   for (Standard_Integer i = 3; i < n; ++i) {
615     if (!strcasecmp(a[i], "-min")) {
616       anExtFlag = Extrema_ExtFlag_MIN;
617     }
618     else if (!strcasecmp(a[i], "-max")) {
619       anExtFlag = Extrema_ExtFlag_MAX;
620     }
621     else if (!strcasecmp(a[i], "-minmax")) {
622       anExtFlag = Extrema_ExtFlag_MINMAX;
623     }
624     else if (!strcasecmp(a[i], "-t")) {
625       anExtAlgo = Extrema_ExtAlgo_Tree;
626     }
627     else if (!strcasecmp(a[i], "-g")) {
628       anExtAlgo = Extrema_ExtAlgo_Grad;
629     }
630   }
631   //
632   // get surface
633   TopLoc_Location aLoc;
634   const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aLoc);
635   // move point to surface location
636   aP.Transform(aLoc.Transformation().Inverted());
637   //
638   // get bounds of the surface
639   Standard_Real aUMin, aUMax, aVMin, aVMax;
640   aSurf->Bounds(aUMin, aUMax, aVMin, aVMax);
641   //
642   // initialize projector
643   GeomAPI_ProjectPointOnSurf aProjPS;
644   aProjPS.Init(aSurf, aUMin, aUMax, aVMin, aVMax);
645   // set the options
646   aProjPS.SetExtremaAlgo(anExtAlgo);
647   aProjPS.SetExtremaFlag(anExtFlag);
648   // perform projection
649   aProjPS.Perform(aP);
650   //
651   if (aProjPS.NbPoints()) {
652     // lower distance
653     Standard_Real aDist = aProjPS.LowerDistance();
654     // lower distance parameters
655     Standard_Real U, V;
656     aProjPS.LowerDistanceParameters(U, V);
657     // nearest point
658     gp_Pnt aPProj = aProjPS.NearestPoint();
659     // translate projection point to face location
660     aPProj.Transform(aLoc.Transformation());
661     //
662     // print the projection values
663     di << "proj dist = " << aDist << "\n";
664     di << "uvproj = " << U << " " << V << "\n";
665     di << "pproj = " << aPProj.X() << " " << aPProj.Y() << " " << aPProj.Z() << "\n";
666   }
667   else {
668     if (!aProjPS.IsDone()) {
669       di << "projection failed\n";
670     }
671     else {
672       di << "no projection found\n";
673     }
674   }
675   return 0;
676 }
677
678 //=======================================================================
679 //function : SurfaceCommands
680 //purpose  : 
681 //=======================================================================
682
683 void  BRepTest::SurfaceCommands(Draw_Interpretor& theCommands)
684 {
685   static Standard_Boolean done = Standard_False;
686   if (done) return;
687   done = Standard_True;
688
689   DBRep::BasicCommands(theCommands);
690   GeometryTest::SurfaceCommands(theCommands);
691
692   const char* g = "Surface topology commands";
693
694   theCommands.Add("mkface",
695                   "mkface facename surfacename [ufirst ulast vfirst vlast] [wire [norient]]",
696                   __FILE__,mkface,g);
697
698   theCommands.Add("mkshell",
699                   "mkshell shellname surfacename [ufirst ulast vfirst vlast] [segment 0/1]",
700                   __FILE__,mkface,g);
701
702   theCommands.Add("quilt",
703                   "quilt compoundname shape1 edgeshape2  edgeshape1... shape2  edgeshape3 edgeshape1or2 ... shape3 ...",
704                   __FILE__,quilt,g);
705   
706   theCommands.Add("mksurface",
707                   "mksurface surfacename facename",
708                   __FILE__,mksurface,g);
709
710   theCommands.Add("mkplane",
711                   "mkplane facename wirename [OnlyPlane 0/1]",
712                   __FILE__,mkplane,g);
713
714   theCommands.Add("pcurve",
715                   "pcurve [name edgename] facename",
716                   __FILE__,pcurve,g);
717
718   theCommands.Add("sewing",
719                   "sewing result [tolerance] shape1 shape2 ... [min tolerance] [max tolerance] [switches]",
720                   __FILE__,sewing, g);
721
722   theCommands.Add("continuity", 
723                   "continuity [tolerance] shape1 shape2 ...",
724                   __FILE__,continuity, g);
725
726   theCommands.Add("encoderegularity", 
727                   "encoderegularity shape [tolerance (in degree)]",
728                   __FILE__,encoderegularity, g);
729
730   theCommands.Add ("fastsewing", "fastsewing result [-tol <value>] <list_of_faces>", 
731                                                 __FILE__, fastsewing, g);
732   theCommands.Add ("getedgeregularity", "getedgeregularity edge face1 [face2]",  __FILE__,getedgeregul,g);
733
734   theCommands.Add ("projponf",
735                    "projponf face pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n"
736                    "\t\tProject point on the face.",
737                    __FILE__, projponf, g);
738 }
739