b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | /*********************************************************************** |
19 | |
20 | FONCTION : |
21 | ---------- |
22 | Classe V3d_CircularGrid : |
23 | |
24 | HISTORIQUE DES MODIFICATIONS : |
25 | -------------------------------- |
26 | 16-08-98 : CAL ; S3892. Ajout grilles 3d. |
27 | 13-10-98 : CAL ; S3892. Ajout de la gestion de la taille des grilles 3d. |
28 | 23-10-98 : CAL ; PRO 15885. Patch K4403 et K4404 |
29 | 03-11-98 : CAL ; PRO 16161. Patch K4418 et K4419 |
30 | IMP230300: GG The color fields and methods have moved in Aspect_Grid |
31 | |
32 | |
33 | ************************************************************************/ |
34 | |
35 | #define IMP200100 //GG |
36 | // -> Compute the case Aspect_GDM_None |
37 | // -> Initialize the grid size according to the |
38 | // viewer default size. |
39 | |
40 | #define IMP200300 //GG |
41 | // -> Recompute the grid when any graphic parameter is |
42 | // modified. |
43 | |
44 | /*----------------------------------------------------------------------*/ |
45 | /* |
46 | * Includes |
47 | */ |
48 | |
49 | #include <V3d_RectangularGrid.ixx> |
50 | |
51 | #include <TColStd_Array2OfReal.hxx> |
52 | #include <Graphic3d_AspectLine3d.hxx> |
53 | #include <Graphic3d_AspectMarker3d.hxx> |
54 | #include <Graphic3d_AspectText3d.hxx> |
a577aaab |
55 | #include <Graphic3d_ArrayOfPoints.hxx> |
7fd59977 |
56 | #include <Visual3d_ViewManager.hxx> |
57 | #include <V3d_Viewer.hxx> |
b8ddfc2f |
58 | #include <TColgp_SequenceOfPnt.hxx> |
59 | #include <Graphic3d_ArrayOfSegments.hxx> |
7fd59977 |
60 | |
61 | /*----------------------------------------------------------------------*/ |
62 | /* |
63 | * Constant |
64 | */ |
65 | |
7fd59977 |
66 | #define MYMINMAX 25. |
67 | #define MYFACTOR 50. |
68 | |
69 | /*----------------------------------------------------------------------*/ |
70 | |
b8ddfc2f |
71 | V3d_RectangularGrid::V3d_RectangularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor) |
72 | : Aspect_RectangularGrid (1.,1.), |
73 | myStructure (new Graphic3d_Structure (aViewer->Viewer ())), |
74 | myGroup (new Graphic3d_Group (myStructure)), |
75 | myViewer (aViewer), |
76 | myCurAreDefined (Standard_False) |
7fd59977 |
77 | { |
b8ddfc2f |
78 | myColor = aColor; |
79 | myTenthColor = aTenthColor; |
7fd59977 |
80 | |
b8ddfc2f |
81 | myStructure->SetInfiniteState (Standard_True); |
7fd59977 |
82 | |
b8ddfc2f |
83 | const Standard_Real step = 10.; |
84 | const Standard_Real gstep = step/MYFACTOR; |
85 | const Standard_Real size = 0.5*myViewer->DefaultViewSize(); |
86 | SetGraphicValues (size, size, gstep); |
87 | SetXStep (step); |
88 | SetYStep (step); |
7fd59977 |
89 | } |
90 | |
b8ddfc2f |
91 | void V3d_RectangularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor) |
92 | { |
93 | if( myColor != aColor || myTenthColor != aTenthColor ) { |
94 | myColor = aColor; |
95 | myTenthColor = aTenthColor; |
96 | myCurAreDefined = Standard_False; |
97 | UpdateDisplay(); |
98 | } |
7fd59977 |
99 | } |
100 | |
b8ddfc2f |
101 | void V3d_RectangularGrid::Display () |
102 | { |
103 | myStructure->Display (1); |
7fd59977 |
104 | } |
105 | |
b8ddfc2f |
106 | void V3d_RectangularGrid::Erase () const |
107 | { |
108 | myStructure->Erase (); |
7fd59977 |
109 | } |
110 | |
b8ddfc2f |
111 | Standard_Boolean V3d_RectangularGrid::IsDisplayed () const |
112 | { |
113 | return myStructure->IsDisplayed (); |
7fd59977 |
114 | } |
115 | |
b8ddfc2f |
116 | void V3d_RectangularGrid::UpdateDisplay () |
117 | { |
118 | gp_Ax3 ThePlane = myViewer->PrivilegedPlane (); |
119 | |
120 | Standard_Boolean MakeTransform = Standard_False; |
121 | Standard_Real xl, yl, zl; |
122 | Standard_Real xdx, xdy, xdz; |
123 | Standard_Real ydx, ydy, ydz; |
124 | Standard_Real dx, dy, dz; |
125 | ThePlane.Location ().Coord (xl, yl, zl); |
126 | ThePlane.XDirection ().Coord (xdx, xdy, xdz); |
127 | ThePlane.YDirection ().Coord (ydx, ydy, ydz); |
128 | ThePlane.Direction ().Coord (dx, dy, dz); |
129 | if (! myCurAreDefined) |
130 | MakeTransform = Standard_True; |
131 | else { |
132 | if (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo) |
133 | MakeTransform = Standard_True; |
134 | if (! MakeTransform) { |
135 | Standard_Real curxl, curyl, curzl; |
136 | Standard_Real curxdx, curxdy, curxdz; |
137 | Standard_Real curydx, curydy, curydz; |
138 | Standard_Real curdx, curdy, curdz; |
139 | myCurViewPlane.Location ().Coord (curxl, curyl, curzl); |
140 | myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz); |
141 | myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz); |
142 | myCurViewPlane.Direction ().Coord (curdx, curdy, curdz); |
143 | if (xl != curxl || yl != curyl || zl != curzl || |
144 | xdx != curxdx || xdy != curxdy || xdz != curxdz || |
145 | ydx != curydx || ydy != curydy || ydz != curydz || |
146 | dx != curdx || dy != curdy || dz != curdz) |
147 | MakeTransform = Standard_True; |
148 | } |
149 | } |
150 | |
151 | if (MakeTransform) { |
152 | const Standard_Real CosAlpha = Cos (RotationAngle ()); |
153 | const Standard_Real SinAlpha = Sin (RotationAngle ()); |
154 | TColStd_Array2OfReal Trsf (1, 4, 1, 4); |
155 | Trsf (4, 4) = 1.0; |
156 | Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0; |
157 | // Translation |
158 | Trsf (1, 4) = xl, |
159 | Trsf (2, 4) = yl, |
160 | Trsf (3, 4) = zl; |
161 | // Transformation of change of marker |
162 | Trsf (1, 1) = xdx, |
163 | Trsf (2, 1) = xdy, |
164 | Trsf (3, 1) = xdz, |
165 | Trsf (1, 2) = ydx, |
166 | Trsf (2, 2) = ydy, |
167 | Trsf (3, 2) = ydz, |
168 | Trsf (1, 3) = dx, |
169 | Trsf (2, 3) = dy, |
170 | Trsf (3, 3) = dz; |
171 | myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE); |
172 | |
173 | // Translation of the origin |
174 | Trsf (1, 4) = -XOrigin (), |
175 | Trsf (2, 4) = -YOrigin (), |
176 | Trsf (3, 4) = 0.0; |
177 | // Rotation Alpha around axis -Z |
178 | Trsf (1, 1) = CosAlpha, |
179 | Trsf (2, 1) = -SinAlpha, |
180 | Trsf (3, 1) = 0.0, |
181 | Trsf (1, 2) = SinAlpha, |
182 | Trsf (2, 2) = CosAlpha, |
183 | Trsf (3, 2) = 0.0, |
184 | Trsf (1, 3) = 0.0, |
185 | Trsf (2, 3) = 0.0, |
186 | Trsf (3, 3) = 1.0; |
187 | myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE); |
188 | |
189 | myCurAngle = RotationAngle (); |
190 | myCurXo = XOrigin (), myCurYo = YOrigin (); |
191 | myCurViewPlane = ThePlane; |
192 | } |
193 | |
194 | switch (DrawMode ()) |
195 | { |
196 | default: |
197 | //case Aspect_GDM_Points: |
198 | DefinePoints (); |
199 | myCurDrawMode = Aspect_GDM_Points; |
200 | break; |
201 | case Aspect_GDM_Lines: |
202 | DefineLines (); |
203 | myCurDrawMode = Aspect_GDM_Lines; |
204 | break; |
7fd59977 |
205 | #ifdef IMP210100 |
b8ddfc2f |
206 | case Aspect_GDM_None: |
207 | myCurDrawMode = Aspect_GDM_None; |
208 | break; |
7fd59977 |
209 | #endif |
210 | } |
211 | myCurAreDefined = Standard_True; |
7fd59977 |
212 | } |
213 | |
b8ddfc2f |
214 | void V3d_RectangularGrid::DefineLines () |
215 | { |
216 | const Standard_Real aXStep = XStep(); |
217 | const Standard_Real aYStep = YStep(); |
218 | const Standard_Boolean toUpdate = !myCurAreDefined |
219 | || myCurDrawMode != Aspect_GDM_Lines |
220 | || aXStep != myCurXStep |
221 | || aYStep != myCurYStep; |
222 | if (!toUpdate) |
223 | { |
224 | return; |
225 | } |
226 | |
227 | myGroup->Clear(); |
228 | |
229 | Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d (); |
230 | LineAttrib->SetColor (myColor); |
231 | LineAttrib->SetType (Aspect_TOL_SOLID); |
232 | LineAttrib->SetWidth (1.0); |
233 | |
234 | Standard_Integer nblines; |
235 | Standard_Real xl, yl, zl = myOffSet; |
236 | |
237 | TColgp_SequenceOfPnt aSeqLines, aSeqTenth; |
238 | |
239 | // verticals |
240 | aSeqTenth.Append(gp_Pnt(0., -myYSize, -zl)); |
241 | aSeqTenth.Append(gp_Pnt(0., myYSize, -zl)); |
242 | for (nblines = 1, xl = aXStep; xl < myXSize; xl += aXStep, nblines++) |
243 | { |
244 | TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth; |
245 | aSeq.Append(gp_Pnt( xl, -myYSize, -zl)); |
246 | aSeq.Append(gp_Pnt( xl, myYSize, -zl)); |
247 | aSeq.Append(gp_Pnt(-xl, -myYSize, -zl)); |
248 | aSeq.Append(gp_Pnt(-xl, myYSize, -zl)); |
249 | } |
250 | |
251 | // horizontals |
252 | aSeqTenth.Append(gp_Pnt(-myXSize, 0., -zl)); |
253 | aSeqTenth.Append(gp_Pnt( myXSize, 0., -zl)); |
254 | for (nblines = 1, yl = aYStep; yl < myYSize; yl += aYStep, nblines++) |
255 | { |
256 | TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth; |
257 | aSeq.Append(gp_Pnt(-myXSize, yl, -zl)); |
258 | aSeq.Append(gp_Pnt( myXSize, yl, -zl)); |
259 | aSeq.Append(gp_Pnt(-myXSize, -yl, -zl)); |
260 | aSeq.Append(gp_Pnt( myXSize, -yl, -zl)); |
261 | } |
262 | |
263 | if (aSeqLines.Length()) |
264 | { |
265 | LineAttrib->SetColor (myColor); |
266 | myGroup->SetPrimitivesAspect (LineAttrib); |
267 | const Standard_Integer nbv = aSeqLines.Length(); |
268 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv); |
269 | Standard_Integer n = 1; |
270 | while (n<=nbv) |
271 | aPrims->AddVertex(aSeqLines(n++)); |
272 | myGroup->AddPrimitiveArray(aPrims, Standard_False); |
273 | } |
274 | if (aSeqTenth.Length()) |
275 | { |
276 | LineAttrib->SetColor (myTenthColor); |
277 | myGroup->SetPrimitivesAspect (LineAttrib); |
278 | const Standard_Integer nbv = aSeqTenth.Length(); |
279 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv); |
280 | Standard_Integer n = 1; |
281 | while (n<=nbv) |
282 | aPrims->AddVertex(aSeqTenth(n++)); |
283 | myGroup->AddPrimitiveArray(aPrims, Standard_False); |
284 | } |
285 | |
286 | myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0); |
287 | myCurXStep = aXStep, myCurYStep = aYStep; |
7fd59977 |
288 | } |
289 | |
b8ddfc2f |
290 | void V3d_RectangularGrid::DefinePoints () |
291 | { |
292 | const Standard_Real aXStep = XStep(); |
293 | const Standard_Real aYStep = YStep(); |
294 | const Standard_Boolean toUpdate = !myCurAreDefined |
295 | || myCurDrawMode != Aspect_GDM_Points |
296 | || aXStep != myCurXStep |
297 | || aYStep != myCurYStep; |
298 | if (!toUpdate) |
299 | { |
300 | return; |
301 | } |
302 | |
303 | myGroup->Clear (); |
304 | |
305 | Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d (); |
306 | MarkerAttrib->SetColor (myColor); |
307 | MarkerAttrib->SetType (Aspect_TOM_POINT); |
308 | MarkerAttrib->SetScale (3.); |
309 | |
310 | // horizontals |
311 | Standard_Real xl, yl; |
312 | TColgp_SequenceOfPnt aSeqPnts; |
313 | for (xl = 0.0; xl <= myXSize; xl += aXStep) { |
314 | aSeqPnts.Append(gp_Pnt( xl, 0.0, -myOffSet)); |
315 | aSeqPnts.Append(gp_Pnt(-xl, 0.0, -myOffSet)); |
316 | for (yl = aYStep; yl <= myYSize; yl += aYStep) { |
317 | aSeqPnts.Append(gp_Pnt( xl, yl, -myOffSet)); |
318 | aSeqPnts.Append(gp_Pnt( xl, -yl, -myOffSet)); |
319 | aSeqPnts.Append(gp_Pnt(-xl, yl, -myOffSet)); |
320 | aSeqPnts.Append(gp_Pnt(-xl, -yl, -myOffSet)); |
321 | } |
322 | } |
323 | if (aSeqPnts.Length()) |
324 | { |
325 | Standard_Integer i; |
326 | Standard_Real X,Y,Z; |
327 | const Standard_Integer nbv = aSeqPnts.Length(); |
a577aaab |
328 | Handle(Graphic3d_ArrayOfPoints) Vertical = new Graphic3d_ArrayOfPoints (nbv); |
b8ddfc2f |
329 | for (i=1; i<=nbv; i++) |
330 | { |
331 | aSeqPnts(i).Coord(X,Y,Z); |
a577aaab |
332 | Vertical->AddVertex (X,Y,Z); |
b8ddfc2f |
333 | } |
334 | myGroup->SetGroupPrimitivesAspect (MarkerAttrib); |
a577aaab |
335 | myGroup->AddPrimitiveArray (Vertical, Standard_False); |
b8ddfc2f |
336 | } |
337 | |
338 | myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0); |
339 | myCurXStep = aXStep, myCurYStep = aYStep; |
7fd59977 |
340 | } |
341 | |
b8ddfc2f |
342 | void V3d_RectangularGrid::GraphicValues (Standard_Real& theXSize, Standard_Real& theYSize, Standard_Real& theOffSet) const |
343 | { |
344 | theXSize = myXSize; |
345 | theYSize = myYSize; |
346 | theOffSet = myOffSet; |
7fd59977 |
347 | } |
348 | |
b8ddfc2f |
349 | void V3d_RectangularGrid::SetGraphicValues (const Standard_Real theXSize, const Standard_Real theYSize, const Standard_Real theOffSet) |
350 | { |
351 | if (! myCurAreDefined) { |
352 | myXSize = theXSize; |
353 | myYSize = theYSize; |
354 | myOffSet = theOffSet; |
355 | } |
356 | if (myXSize != theXSize) { |
357 | myXSize = theXSize; |
358 | myCurAreDefined = Standard_False; |
359 | } |
360 | if (myYSize != theYSize) { |
361 | myYSize = theYSize; |
362 | myCurAreDefined = Standard_False; |
363 | } |
364 | if (myOffSet != theOffSet) { |
365 | myOffSet = theOffSet; |
366 | myCurAreDefined = Standard_False; |
367 | } |
368 | if( !myCurAreDefined ) UpdateDisplay(); |
7fd59977 |
369 | } |