0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / GeometryTest / GeometryTest_TestProjCommands.cxx
CommitLineData
b311480e 1// Created on: 2011-06-30
2// Created by: jgv@ROLEX
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
38f33510
J
20
21#include <GeometryTest.hxx>
22#include <Geom_Curve.hxx>
23#include <Geom_Surface.hxx>
24#include <GeomAPI_ProjectPointOnSurf.hxx>
25
26#include <DBRep.hxx>
27#include <DBRep_DrawableShape.hxx>
28#include <Draw_Interpretor.hxx>
29#include <Draw_Appli.hxx>
30#include <DrawTrSurf.hxx>
31#include <Draw_Marker3D.hxx>
32
33#include <stdio.h>
34#ifdef WNT
35Standard_IMPORT Draw_Viewer dout;
36#endif
37
38//=======================================================================
39//function : xdistcs
40//purpose :
41//=======================================================================
42static Standard_Integer xdistcs(Draw_Interpretor& , Standard_Integer n, const char** a)
43{
44 if (n<5) {
45 cout<<" Use xdistcs c s t1 t2 nbp"<<endl;
46 return 0;
47 }
48 //
49 Standard_Boolean bRet;
50 Standard_Integer i, aNbP, iSize;
51 Standard_Real aTol, aD, aT, aT1, aT2, dT;
52 gp_Pnt aP;
53 Handle(Geom_Curve) aC;
54 Handle(Geom_Surface) aS;
55 GeomAPI_ProjectPointOnSurf aPPS;
56 Handle(Draw_Marker3D) aMr;
57 Draw_Color aColor(Draw_rouge);
58 //
59 aTol=1.e-7;
60 //
61 aC=DrawTrSurf::GetCurve(a[1]);
62 if (aC.IsNull()) {
63 cout<<a[1]<<" is null curve"<<endl;
64 return 0;
65 }
66 //
67 aS=DrawTrSurf::GetSurface(a[2]);
68 if (aS.IsNull()) {
69 cout<<a[2]<<" is null"<<endl;
70 return 0;
71 }
72 //
91322f44 73 aT1=Draw::Atof(a[3]);
74 aT2=Draw::Atof(a[4]);
38f33510
J
75 //
76 aNbP=10;
77 if (n>5) {
91322f44 78 aNbP=Draw::Atoi(a[5]);
38f33510
J
79 }
80 //
81 iSize=3;
82 //
83 dT=(aT2-aT1)/(aNbP-1);
84 for (i=0; i<aNbP; ++i) {
85 aT=aT1+i*dT;
86 if (i==aNbP-1) {
87 aT=aT2;
88 }
89 //
90 aC->D0(aT, aP);
91 aPPS.Init(aP, aS, aTol);
92 bRet=aPPS.IsDone();
93 if (!bRet) {
94 cout<<" GeomAPI_ProjectPointOnSurf failed"<<endl;
95 return 0;
96 }
97 //
98 aD=aPPS.LowerDistance();
99 printf(" T=%lg\tD=%lg\n", aT, aD);
100 //
101 aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize);
102 dout << aMr;
103 }
104 //
105 return 0;
106}
107
108//=======================================================================
109//function : TestProjCommands
110//purpose :
111//=======================================================================
112
113void GeometryTest::TestProjCommands(Draw_Interpretor& theCommands)
114{
115
116 static Standard_Boolean loaded = Standard_False;
117 if (loaded) return;
118 loaded = Standard_True;
119
120 DrawTrSurf::BasicCommands(theCommands);
121
122 const char* g;
123
124 g = "Testing of projection (geometric objects)";
125
126 theCommands.Add("xdistcs", "xdistcs c s t1 t2 nbp", __FILE__, xdistcs, g);
127}