1 // Created on: 1995-03-06
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
23 #include <GeometryTest.ixx>
24 #include <Poly_Triangulation.hxx>
25 #include <Poly_Array1OfTriangle.hxx>
26 #include <Poly_Triangle.hxx>
27 #include <TColgp_Array1OfPnt.hxx>
28 #include <TColgp_Array1OfPnt2d.hxx>
29 #include <DrawTrSurf.hxx>
30 #include <Draw_Appli.hxx>
31 #include <DrawTrSurf_Triangulation.hxx>
32 #include <DrawTrSurf_Polygon3D.hxx>
33 #include <DrawTrSurf_Polygon2D.hxx>
35 #include <Poly_Polygon3D.hxx>
36 #include <Poly_Polygon2D.hxx>
39 Standard_IMPORT Draw_Viewer dout;
41 //=======================================================================
44 //=======================================================================
46 static Standard_Integer polytr(Draw_Interpretor& di, Standard_Integer n, const char** a)
51 Standard_Integer nbNodes = Draw::Atoi(a[2]);
52 Standard_Integer nbTri = Draw::Atoi(a[3]);
55 Standard_Integer i, j = 4;
56 TColgp_Array1OfPnt Nodes(1, nbNodes);
58 for (i = 1; i <= nbNodes; i++) {
60 di << "Not enough nodes";
63 Nodes(i).SetCoord(Draw::Atof(a[j]),Draw::Atof(a[j+1]),Draw::Atof(a[j+2]));
69 Poly_Array1OfTriangle Triangles(1, nbTri);
70 for (i = 1; i <= nbTri; i++) {
72 di << "Not enough triangles";
75 Triangles(i).Set(Draw::Atoi(a[j]),Draw::Atoi(a[j+1]),Draw::Atoi(a[j+2]));
79 Handle(Poly_Triangulation) T = new Poly_Triangulation(Nodes,Triangles);
81 DrawTrSurf::Set(a[1],T);
87 //=======================================================================
88 //function : polygon3d
90 //=======================================================================
92 static Standard_Integer polygon3d(Draw_Interpretor& di, Standard_Integer n, const char** a)
97 Standard_Integer nbNodes = Draw::Atoi(a[2]);
100 Standard_Integer i, j = 3;
101 TColgp_Array1OfPnt Nodes(1, nbNodes);
103 for (i = 1; i <= nbNodes; i++) {
105 di << "Not enough nodes";
108 Nodes(i).SetCoord(Draw::Atof(a[j]),Draw::Atof(a[j+1]),Draw::Atof(a[j+2]));
112 Handle(Poly_Polygon3D) P3d = new Poly_Polygon3D(Nodes);
114 DrawTrSurf::Set(a[1], P3d);
119 //=======================================================================
120 //function : polygon2d
122 //=======================================================================
124 static Standard_Integer polygon2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
129 Standard_Integer nbNodes = Draw::Atoi(a[2]);
132 Standard_Integer i, j = 3;
133 TColgp_Array1OfPnt2d Nodes(1, nbNodes);
135 for (i = 1; i <= nbNodes; i++) {
137 di << "Not enough nodes";
140 Nodes(i).SetCoord(Draw::Atof(a[j]),Draw::Atof(a[j+1]));
144 Handle(Poly_Polygon2D) P2d = new Poly_Polygon2D(Nodes);
146 DrawTrSurf::Set(a[1], P2d);
152 //=======================================================================
155 //=======================================================================
157 static Standard_Integer shnodes(Draw_Interpretor& , Standard_Integer n, const char** a)
159 if (n != 2) return 1;
160 Handle(DrawTrSurf_Triangulation) T
161 = Handle(DrawTrSurf_Triangulation)::DownCast(Draw::Get(a[1]));
164 Standard_Boolean SHOWNODES = T->ShowNodes();
165 T->ShowNodes(!SHOWNODES);
175 //=======================================================================
176 //function : shtriangles
178 //=======================================================================
180 static Standard_Integer shtriangles(Draw_Interpretor& , Standard_Integer n, const char** a)
182 if (n != 2) return 1;
184 Handle(DrawTrSurf_Triangulation) T
185 = Handle(DrawTrSurf_Triangulation)::DownCast(Draw::Get(a[1]));
186 Standard_Boolean SHOWTRIANGLES = T->ShowTriangles();
187 T->ShowTriangles(!SHOWTRIANGLES);
192 //=======================================================================
193 //function : PolyCommands
195 //=======================================================================
197 void GeometryTest::PolyCommands(Draw_Interpretor& theCommands)
200 const char* g = "Poly Commands";
202 theCommands.Add("polytr","polytr name nbnodes nbtri x1 y1 z1 ... n1 n2 n3 ...",__FILE__,polytr,g);
203 theCommands.Add("polygon3d","polygon3d name nbnodes x1 y1 z1 ...",__FILE__,polygon3d,g);
204 theCommands.Add("polygon2d","polygon2d name nbnodes x1 y1 ...",__FILE__,polygon2d,g);
205 theCommands.Add("shnodes","shnodes name", __FILE__,shnodes, g);
206 theCommands.Add("shtriangles","shtriangles name", __FILE__,shtriangles, g);