0024428: Implementation of LGPL license
[occt.git] / src / GeometryTest / GeometryTest_TestProjCommands.cxx
1 // Created on: 2011-06-30
2 // Created by: jgv@ROLEX
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <GeometryTest.hxx>
17 #include <Geom_Curve.hxx>
18 #include <Geom_Surface.hxx>
19 #include <GeomAPI_ProjectPointOnSurf.hxx>
20
21 #include <DBRep.hxx>
22 #include <DBRep_DrawableShape.hxx>
23 #include <Draw_Interpretor.hxx>
24 #include <Draw_Appli.hxx>
25 #include <DrawTrSurf.hxx>
26 #include <Draw_Marker3D.hxx>
27
28 #include <stdio.h>
29 #ifdef WNT
30 Standard_IMPORT Draw_Viewer dout;
31 #endif
32
33 //=======================================================================
34 //function : xdistcs
35 //purpose  : 
36 //=======================================================================
37 static Standard_Integer xdistcs(Draw_Interpretor& , Standard_Integer n, const char** a)
38 {
39   if (n<5) {
40     cout<<" Use xdistcs c s t1 t2 nbp"<<endl;
41     return 0;
42   }
43   //
44   Standard_Boolean bRet;
45   Standard_Integer i, aNbP, iSize;
46   Standard_Real aTol, aD, aT, aT1, aT2, dT;
47   gp_Pnt aP;
48   Handle(Geom_Curve) aC;
49   Handle(Geom_Surface) aS;
50   GeomAPI_ProjectPointOnSurf aPPS;
51   Handle(Draw_Marker3D) aMr;
52   Draw_Color aColor(Draw_rouge);
53   //
54   aTol=1.e-7;
55   //
56   aC=DrawTrSurf::GetCurve(a[1]);
57   if (aC.IsNull()) {
58     cout<<a[1]<<" is null curve"<<endl;
59     return 0;
60   }
61   //
62   aS=DrawTrSurf::GetSurface(a[2]);
63   if (aS.IsNull()) {
64     cout<<a[2]<<" is null"<<endl;
65     return 0;
66   }
67   //
68   aT1=Draw::Atof(a[3]);
69   aT2=Draw::Atof(a[4]);
70   //
71   aNbP=10;
72   if (n>5) {
73     aNbP=Draw::Atoi(a[5]);
74   }
75   //
76   iSize=3;
77   //
78   dT=(aT2-aT1)/(aNbP-1);
79   for (i=0; i<aNbP; ++i) {
80     aT=aT1+i*dT;
81     if (i==aNbP-1) {
82       aT=aT2;
83     }
84     //
85     aC->D0(aT, aP);
86     aPPS.Init(aP, aS, aTol);
87     bRet=aPPS.IsDone();
88     if (!bRet) {
89       cout<<" GeomAPI_ProjectPointOnSurf failed"<<endl;
90       return 0;
91     }
92     //
93     aD=aPPS.LowerDistance();
94     printf(" T=%lg\tD=%lg\n", aT, aD);
95     //
96     aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize);
97     dout << aMr;
98   }
99   //
100   return 0;
101 }
102
103 //=======================================================================
104 //function : TestProjCommands
105 //purpose  : 
106 //=======================================================================
107
108 void  GeometryTest::TestProjCommands(Draw_Interpretor& theCommands)
109 {
110   
111   static Standard_Boolean loaded = Standard_False;
112   if (loaded) return;
113   loaded = Standard_True;
114   
115   DrawTrSurf::BasicCommands(theCommands);
116   
117   const char* g;
118   
119   g = "Testing of projection (geometric objects)";
120   
121   theCommands.Add("xdistcs", "xdistcs c s t1 t2 nbp", __FILE__, xdistcs, g);
122 }