973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | |
42cf5bc1 |
15 | #include <Aspect_Background.hxx> |
16 | #include <Aspect_GradientBackground.hxx> |
17 | #include <Aspect_Grid.hxx> |
18 | #include <gp_Ax3.hxx> |
679ecdee |
19 | #include <Graphic3d_ArrayOfPoints.hxx> |
42cf5bc1 |
20 | #include <Graphic3d_AspectMarker3d.hxx> |
21 | #include <Graphic3d_GraphicDriver.hxx> |
22 | #include <Graphic3d_Group.hxx> |
23 | #include <Graphic3d_Structure.hxx> |
24 | #include <Quantity_Color.hxx> |
25 | #include <V3d_BadValue.hxx> |
26 | #include <V3d_CircularGrid.hxx> |
27 | #include <V3d_Light.hxx> |
28 | #include <V3d_RectangularGrid.hxx> |
29 | #include <V3d_View.hxx> |
30 | #include <V3d_Viewer.hxx> |
679ecdee |
31 | #include <Visual3d_View.hxx> |
42cf5bc1 |
32 | #include <Visual3d_ViewManager.hxx> |
679ecdee |
33 | |
34 | // ======================================================================= |
35 | // function : Grid |
36 | // purpose : |
37 | // ======================================================================= |
38 | Handle(Aspect_Grid) V3d_Viewer::Grid() const |
39 | { |
40 | switch (myGridType) |
41 | { |
5b111128 |
42 | case Aspect_GT_Circular: return Handle(Aspect_Grid) (myCGrid); |
43 | case Aspect_GT_Rectangular: return Handle(Aspect_Grid) (myRGrid); |
679ecdee |
44 | } |
5b111128 |
45 | return Handle(Aspect_Grid) (myRGrid); |
7fd59977 |
46 | } |
47 | |
679ecdee |
48 | // ======================================================================= |
49 | // function : GridType |
50 | // purpose : |
51 | // ======================================================================= |
52 | Aspect_GridType V3d_Viewer::GridType() const |
53 | { |
54 | return myGridType; |
7fd59977 |
55 | } |
56 | |
679ecdee |
57 | // ======================================================================= |
58 | // function : GridDrawMode |
59 | // purpose : |
60 | // ======================================================================= |
61 | Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const |
62 | { |
63 | return Grid()->DrawMode(); |
7fd59977 |
64 | } |
7fd59977 |
65 | |
679ecdee |
66 | // ======================================================================= |
67 | // function : ActivateGrid |
68 | // purpose : |
69 | // ======================================================================= |
70 | void V3d_Viewer::ActivateGrid (const Aspect_GridType theType, |
71 | const Aspect_GridDrawMode theMode) |
72 | { |
73 | Grid()->Erase(); |
74 | myGridType = theType; |
75 | Grid()->SetDrawMode (theMode); |
76 | if (theMode != Aspect_GDM_None) |
77 | { |
78 | Grid()->Display(); |
79 | } |
80 | Grid()->Activate(); |
81 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
82 | { |
83 | ActiveView()->SetGrid (myPrivilegedPlane, Grid()); |
84 | } |
85 | Update(); |
7fd59977 |
86 | } |
87 | |
679ecdee |
88 | // ======================================================================= |
89 | // function : DeactivateGrid |
90 | // purpose : |
91 | // ======================================================================= |
92 | void V3d_Viewer::DeactivateGrid() |
93 | { |
94 | Grid()->Erase(); |
95 | myGridType = Aspect_GT_Rectangular; |
96 | Grid()->Deactivate(); |
97 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
98 | { |
99 | ActiveView()->SetGridActivity (Standard_False); |
100 | if (myGridEcho |
101 | && !myGridEchoStructure.IsNull()) |
102 | { |
103 | ActiveView()->View()->EraseImmediate (myGridEchoStructure); |
104 | } |
105 | } |
106 | Update(); |
7fd59977 |
107 | } |
108 | |
679ecdee |
109 | // ======================================================================= |
110 | // function : IsActive |
111 | // purpose : |
112 | // ======================================================================= |
113 | Standard_Boolean V3d_Viewer::IsActive() const |
114 | { |
115 | return Grid()->IsActive(); |
7fd59977 |
116 | } |
117 | |
679ecdee |
118 | // ======================================================================= |
119 | // function : RectangularGridValues |
120 | // purpose : |
121 | // ======================================================================= |
122 | void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin, |
123 | Quantity_Length& theYOrigin, |
124 | Quantity_Length& theXStep, |
125 | Quantity_Length& theYStep, |
126 | Quantity_PlaneAngle& theRotationAngle) const |
127 | { |
128 | theXOrigin = myRGrid->XOrigin(); |
129 | theYOrigin = myRGrid->YOrigin(); |
130 | theXStep = myRGrid->XStep(); |
131 | theYStep = myRGrid->YStep(); |
132 | theRotationAngle = myRGrid->RotationAngle(); |
133 | } |
7fd59977 |
134 | |
679ecdee |
135 | // ======================================================================= |
136 | // function : SetRectangularGridValues |
137 | // purpose : |
138 | // ======================================================================= |
139 | void V3d_Viewer::SetRectangularGridValues (const Quantity_Length theXOrigin, |
140 | const Quantity_Length theYOrigin, |
141 | const Quantity_Length theXStep, |
142 | const Quantity_Length theYStep, |
143 | const Quantity_PlaneAngle theRotationAngle) |
144 | { |
145 | myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle); |
146 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
147 | { |
148 | ActiveView()->SetGrid (myPrivilegedPlane, myRGrid); |
149 | } |
150 | Update(); |
7fd59977 |
151 | } |
152 | |
679ecdee |
153 | // ======================================================================= |
154 | // function : CircularGridValues |
155 | // purpose : |
156 | // ======================================================================= |
157 | void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin, |
158 | Quantity_Length& theYOrigin, |
159 | Quantity_Length& theRadiusStep, |
160 | Standard_Integer& theDivisionNumber, |
161 | Quantity_PlaneAngle& theRotationAngle) const |
162 | { |
163 | theXOrigin = myCGrid->XOrigin(); |
164 | theYOrigin = myCGrid->YOrigin(); |
165 | theRadiusStep = myCGrid->RadiusStep(); |
166 | theDivisionNumber = myCGrid->DivisionNumber(); |
167 | theRotationAngle = myCGrid->RotationAngle(); |
168 | } |
7fd59977 |
169 | |
679ecdee |
170 | // ======================================================================= |
171 | // function : SetCircularGridValues |
172 | // purpose : |
173 | // ======================================================================= |
174 | void V3d_Viewer::SetCircularGridValues (const Quantity_Length theXOrigin, |
175 | const Quantity_Length theYOrigin, |
176 | const Quantity_Length theRadiusStep, |
177 | const Standard_Integer theDivisionNumber, |
178 | const Quantity_PlaneAngle theRotationAngle) |
179 | { |
180 | myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep, |
181 | theDivisionNumber, theRotationAngle); |
182 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
183 | { |
184 | ActiveView()->SetGrid (myPrivilegedPlane, myCGrid); |
185 | } |
186 | Update(); |
7fd59977 |
187 | } |
188 | |
679ecdee |
189 | // ======================================================================= |
190 | // function : RectangularGridGraphicValues |
191 | // purpose : |
192 | // ======================================================================= |
193 | void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize, |
194 | Quantity_Length& theYSize, |
195 | Quantity_Length& theOffSet) const |
196 | { |
197 | myRGrid->GraphicValues (theXSize, theYSize, theOffSet); |
198 | } |
7fd59977 |
199 | |
679ecdee |
200 | // ======================================================================= |
201 | // function : SetRectangularGridGraphicValues |
202 | // purpose : |
203 | // ======================================================================= |
204 | void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize, |
205 | const Quantity_Length theYSize, |
206 | const Quantity_Length theOffSet) |
207 | { |
208 | myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet); |
209 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
210 | { |
211 | ActiveView()->SetGridGraphicValues (myRGrid); |
212 | } |
213 | Update(); |
7fd59977 |
214 | } |
215 | |
679ecdee |
216 | // ======================================================================= |
217 | // function : CircularGridGraphicValues |
218 | // purpose : |
219 | // ======================================================================= |
220 | void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius, |
221 | Quantity_Length& theOffSet) const |
222 | { |
223 | myCGrid->GraphicValues (theRadius, theOffSet); |
224 | } |
7fd59977 |
225 | |
679ecdee |
226 | // ======================================================================= |
227 | // function : SetCircularGridGraphicValues |
228 | // purpose : |
229 | // ======================================================================= |
230 | void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius, |
231 | const Quantity_Length theOffSet) |
232 | { |
233 | myCGrid->SetGraphicValues (theRadius, theOffSet); |
234 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
235 | { |
236 | ActiveView()->SetGridGraphicValues (myCGrid); |
237 | } |
238 | Update(); |
7fd59977 |
239 | } |
240 | |
679ecdee |
241 | // ======================================================================= |
242 | // function : SetGridEcho |
243 | // purpose : |
244 | // ======================================================================= |
245 | void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid) |
246 | { |
247 | if (myGridEcho == theToShowGrid) |
248 | { |
249 | return; |
250 | } |
251 | |
252 | myGridEcho = theToShowGrid; |
253 | if (theToShowGrid |
254 | || myGridEchoStructure.IsNull()) |
255 | { |
256 | return; |
257 | } |
7fd59977 |
258 | |
679ecdee |
259 | for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) |
260 | { |
261 | ActiveView()->View()->EraseImmediate (myGridEchoStructure); |
262 | } |
7fd59977 |
263 | } |
264 | |
679ecdee |
265 | // ======================================================================= |
266 | // function : SetGridEcho |
267 | // purpose : |
268 | // ======================================================================= |
269 | void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker) |
270 | { |
271 | if (myGridEchoStructure.IsNull()) |
272 | { |
273 | myGridEchoStructure = new Graphic3d_Structure (Viewer()); |
b64d84be |
274 | myGridEchoGroup = myGridEchoStructure->NewGroup(); |
679ecdee |
275 | } |
7fd59977 |
276 | |
679ecdee |
277 | myGridEchoAspect = theMarker; |
278 | myGridEchoGroup->SetPrimitivesAspect (theMarker); |
7fd59977 |
279 | } |
280 | |
679ecdee |
281 | // ======================================================================= |
282 | // function : GridEcho |
283 | // purpose : |
284 | // ======================================================================= |
285 | Standard_Boolean V3d_Viewer::GridEcho() const |
286 | { |
287 | return myGridEcho; |
7fd59977 |
288 | } |
289 | |
679ecdee |
290 | // ======================================================================= |
291 | // function : ShowGridEcho |
292 | // purpose : |
293 | // ======================================================================= |
294 | void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView, |
295 | const Graphic3d_Vertex& theVertex) |
296 | { |
297 | if (!myGridEcho) |
298 | { |
299 | return; |
300 | } |
7fd59977 |
301 | |
679ecdee |
302 | if (myGridEchoStructure.IsNull()) |
303 | { |
304 | myGridEchoStructure = new Graphic3d_Structure (Viewer()); |
b64d84be |
305 | myGridEchoGroup = myGridEchoStructure->NewGroup(); |
7fd59977 |
306 | |
679ecdee |
307 | myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0); |
308 | myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect); |
309 | } |
7fd59977 |
310 | |
679ecdee |
311 | if (theVertex.X() == myGridEchoLastVert.X() |
312 | && theVertex.Y() == myGridEchoLastVert.Y() |
313 | && theVertex.Z() == myGridEchoLastVert.Z()) |
314 | { |
315 | return; |
316 | } |
7fd59977 |
317 | |
679ecdee |
318 | myGridEchoLastVert = theVertex; |
319 | myGridEchoGroup->Clear(); |
320 | myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect); |
7fd59977 |
321 | |
679ecdee |
322 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
323 | anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z()); |
324 | myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints); |
7fd59977 |
325 | |
679ecdee |
326 | theView->View()->DisplayImmediate (myGridEchoStructure, Standard_True); |
7fd59977 |
327 | } |
328 | |
679ecdee |
329 | // ======================================================================= |
330 | // function : HideGridEcho |
331 | // purpose : |
332 | // ======================================================================= |
333 | void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView) |
334 | { |
335 | if (myGridEchoStructure.IsNull()) |
336 | { |
337 | return; |
7fd59977 |
338 | } |
679ecdee |
339 | |
340 | myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast()); |
341 | theView->View()->EraseImmediate (myGridEchoStructure); |
7fd59977 |
342 | } |