b311480e |
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 |
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 | |
7fd59977 |
21 | |
22 | |
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> |
34 | |
35 | #include <Poly_Polygon3D.hxx> |
36 | #include <Poly_Polygon2D.hxx> |
37 | |
38 | #ifdef WNT |
39 | Standard_IMPORT Draw_Viewer dout; |
40 | #endif |
41 | //======================================================================= |
42 | //function : polytr |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | static Standard_Integer polytr(Draw_Interpretor& di, Standard_Integer n, const char** a) |
47 | { |
48 | if (n < 4) |
49 | return 1; |
50 | |
91322f44 |
51 | Standard_Integer nbNodes = Draw::Atoi(a[2]); |
52 | Standard_Integer nbTri = Draw::Atoi(a[3]); |
7fd59977 |
53 | |
54 | // read the nodes |
55 | Standard_Integer i, j = 4; |
56 | TColgp_Array1OfPnt Nodes(1, nbNodes); |
57 | |
58 | for (i = 1; i <= nbNodes; i++) { |
59 | if (j + 2 >= n) { |
60 | di << "Not enough nodes"; |
61 | return 1; |
62 | } |
91322f44 |
63 | Nodes(i).SetCoord(Draw::Atof(a[j]),Draw::Atof(a[j+1]),Draw::Atof(a[j+2])); |
7fd59977 |
64 | j += 3; |
65 | } |
66 | |
67 | // read the triangles |
68 | |
69 | Poly_Array1OfTriangle Triangles(1, nbTri); |
70 | for (i = 1; i <= nbTri; i++) { |
71 | if (j + 2 >= n) { |
72 | di << "Not enough triangles"; |
73 | return 1; |
74 | } |
91322f44 |
75 | Triangles(i).Set(Draw::Atoi(a[j]),Draw::Atoi(a[j+1]),Draw::Atoi(a[j+2])); |
7fd59977 |
76 | j += 3; |
77 | } |
78 | |
79 | Handle(Poly_Triangulation) T = new Poly_Triangulation(Nodes,Triangles); |
80 | |
81 | DrawTrSurf::Set(a[1],T); |
82 | |
83 | return 0;//wnt |
84 | } |
85 | |
86 | |
87 | //======================================================================= |
88 | //function : polygon3d |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | static Standard_Integer polygon3d(Draw_Interpretor& di, Standard_Integer n, const char** a) |
93 | { |
94 | if (n < 4) |
95 | return 1; |
96 | |
91322f44 |
97 | Standard_Integer nbNodes = Draw::Atoi(a[2]); |
7fd59977 |
98 | |
99 | // read the nodes |
100 | Standard_Integer i, j = 3; |
101 | TColgp_Array1OfPnt Nodes(1, nbNodes); |
102 | |
103 | for (i = 1; i <= nbNodes; i++) { |
104 | if (j + 2 >= n) { |
105 | di << "Not enough nodes"; |
106 | return 1; |
107 | } |
91322f44 |
108 | Nodes(i).SetCoord(Draw::Atof(a[j]),Draw::Atof(a[j+1]),Draw::Atof(a[j+2])); |
7fd59977 |
109 | j += 3; |
110 | } |
111 | |
112 | Handle(Poly_Polygon3D) P3d = new Poly_Polygon3D(Nodes); |
113 | |
114 | DrawTrSurf::Set(a[1], P3d); |
115 | |
116 | return 0; |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : polygon2d |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | static Standard_Integer polygon2d(Draw_Interpretor& di, Standard_Integer n, const char** a) |
125 | { |
126 | if (n < 4) |
127 | return 1; |
128 | |
91322f44 |
129 | Standard_Integer nbNodes = Draw::Atoi(a[2]); |
7fd59977 |
130 | |
131 | // read the nodes |
132 | Standard_Integer i, j = 3; |
133 | TColgp_Array1OfPnt2d Nodes(1, nbNodes); |
134 | |
135 | for (i = 1; i <= nbNodes; i++) { |
136 | if (j + 1 >= n) { |
137 | di << "Not enough nodes"; |
138 | return 1; |
139 | } |
91322f44 |
140 | Nodes(i).SetCoord(Draw::Atof(a[j]),Draw::Atof(a[j+1])); |
7fd59977 |
141 | j += 2; |
142 | } |
143 | |
144 | Handle(Poly_Polygon2D) P2d = new Poly_Polygon2D(Nodes); |
145 | |
146 | DrawTrSurf::Set(a[1], P2d); |
147 | |
148 | return 0; |
149 | } |
150 | |
151 | |
152 | //======================================================================= |
153 | //function : shnodes |
154 | //purpose : |
155 | //======================================================================= |
156 | |
157 | static Standard_Integer shnodes(Draw_Interpretor& , Standard_Integer n, const char** a) |
158 | { |
159 | if (n != 2) return 1; |
160 | Handle(DrawTrSurf_Triangulation) T |
161 | = Handle(DrawTrSurf_Triangulation)::DownCast(Draw::Get(a[1])); |
162 | |
163 | if (!T.IsNull()) { |
164 | Standard_Boolean SHOWNODES = T->ShowNodes(); |
165 | T->ShowNodes(!SHOWNODES); |
166 | } |
167 | |
168 | |
169 | |
170 | dout.RepaintAll(); |
171 | |
172 | return 0;//wnt |
173 | } |
174 | |
175 | //======================================================================= |
176 | //function : shtriangles |
177 | //purpose : |
178 | //======================================================================= |
179 | |
180 | static Standard_Integer shtriangles(Draw_Interpretor& , Standard_Integer n, const char** a) |
181 | { |
182 | if (n != 2) return 1; |
183 | |
184 | Handle(DrawTrSurf_Triangulation) T |
185 | = Handle(DrawTrSurf_Triangulation)::DownCast(Draw::Get(a[1])); |
186 | Standard_Boolean SHOWTRIANGLES = T->ShowTriangles(); |
187 | T->ShowTriangles(!SHOWTRIANGLES); |
188 | dout.RepaintAll(); |
189 | return 0;//wnt |
190 | } |
191 | |
192 | //======================================================================= |
193 | //function : PolyCommands |
194 | //purpose : |
195 | //======================================================================= |
196 | |
197 | void GeometryTest::PolyCommands(Draw_Interpretor& theCommands) |
198 | { |
199 | |
200 | const char* g = "Poly Commands"; |
201 | |
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); |
207 | } |