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 | |
32 | // ======================================================================= |
33 | // function : Grid |
34 | // purpose : |
35 | // ======================================================================= |
36 | Handle(Aspect_Grid) V3d_Viewer::Grid() const |
37 | { |
38 | switch (myGridType) |
39 | { |
5b111128 |
40 | case Aspect_GT_Circular: return Handle(Aspect_Grid) (myCGrid); |
41 | case Aspect_GT_Rectangular: return Handle(Aspect_Grid) (myRGrid); |
679ecdee |
42 | } |
5b111128 |
43 | return Handle(Aspect_Grid) (myRGrid); |
7fd59977 |
44 | } |
45 | |
679ecdee |
46 | // ======================================================================= |
47 | // function : GridDrawMode |
48 | // purpose : |
49 | // ======================================================================= |
50 | Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const |
51 | { |
52 | return Grid()->DrawMode(); |
7fd59977 |
53 | } |
7fd59977 |
54 | |
679ecdee |
55 | // ======================================================================= |
56 | // function : ActivateGrid |
57 | // purpose : |
58 | // ======================================================================= |
59 | void V3d_Viewer::ActivateGrid (const Aspect_GridType theType, |
60 | const Aspect_GridDrawMode theMode) |
61 | { |
62 | Grid()->Erase(); |
63 | myGridType = theType; |
64 | Grid()->SetDrawMode (theMode); |
65 | if (theMode != Aspect_GDM_None) |
66 | { |
67 | Grid()->Display(); |
68 | } |
69 | Grid()->Activate(); |
6a24c6de |
70 | for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next()) |
679ecdee |
71 | { |
6a24c6de |
72 | anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, Grid()); |
679ecdee |
73 | } |
7fd59977 |
74 | } |
75 | |
679ecdee |
76 | // ======================================================================= |
77 | // function : DeactivateGrid |
78 | // purpose : |
79 | // ======================================================================= |
80 | void V3d_Viewer::DeactivateGrid() |
81 | { |
82 | Grid()->Erase(); |
83 | myGridType = Aspect_GT_Rectangular; |
84 | Grid()->Deactivate(); |
6a24c6de |
85 | for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next()) |
679ecdee |
86 | { |
6a24c6de |
87 | anActiveViewIter.Value()->SetGridActivity (Standard_False); |
679ecdee |
88 | if (myGridEcho |
89 | && !myGridEchoStructure.IsNull()) |
90 | { |
c3282ec1 |
91 | myGridEchoStructure->Erase(); |
679ecdee |
92 | } |
93 | } |
7fd59977 |
94 | } |
95 | |
679ecdee |
96 | // ======================================================================= |
97 | // function : IsActive |
98 | // purpose : |
99 | // ======================================================================= |
100 | Standard_Boolean V3d_Viewer::IsActive() const |
101 | { |
102 | return Grid()->IsActive(); |
7fd59977 |
103 | } |
104 | |
679ecdee |
105 | // ======================================================================= |
106 | // function : RectangularGridValues |
107 | // purpose : |
108 | // ======================================================================= |
ee2be2a8 |
109 | void V3d_Viewer::RectangularGridValues (Standard_Real& theXOrigin, |
110 | Standard_Real& theYOrigin, |
111 | Standard_Real& theXStep, |
112 | Standard_Real& theYStep, |
113 | Standard_Real& theRotationAngle) const |
679ecdee |
114 | { |
115 | theXOrigin = myRGrid->XOrigin(); |
116 | theYOrigin = myRGrid->YOrigin(); |
117 | theXStep = myRGrid->XStep(); |
118 | theYStep = myRGrid->YStep(); |
119 | theRotationAngle = myRGrid->RotationAngle(); |
120 | } |
7fd59977 |
121 | |
679ecdee |
122 | // ======================================================================= |
123 | // function : SetRectangularGridValues |
124 | // purpose : |
125 | // ======================================================================= |
ee2be2a8 |
126 | void V3d_Viewer::SetRectangularGridValues (const Standard_Real theXOrigin, |
127 | const Standard_Real theYOrigin, |
128 | const Standard_Real theXStep, |
129 | const Standard_Real theYStep, |
130 | const Standard_Real theRotationAngle) |
679ecdee |
131 | { |
132 | myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle); |
6a24c6de |
133 | for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next()) |
679ecdee |
134 | { |
6a24c6de |
135 | anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myRGrid); |
679ecdee |
136 | } |
7fd59977 |
137 | } |
138 | |
679ecdee |
139 | // ======================================================================= |
140 | // function : CircularGridValues |
141 | // purpose : |
142 | // ======================================================================= |
ee2be2a8 |
143 | void V3d_Viewer::CircularGridValues (Standard_Real& theXOrigin, |
144 | Standard_Real& theYOrigin, |
145 | Standard_Real& theRadiusStep, |
146 | Standard_Integer& theDivisionNumber, |
147 | Standard_Real& theRotationAngle) const |
679ecdee |
148 | { |
149 | theXOrigin = myCGrid->XOrigin(); |
150 | theYOrigin = myCGrid->YOrigin(); |
151 | theRadiusStep = myCGrid->RadiusStep(); |
152 | theDivisionNumber = myCGrid->DivisionNumber(); |
153 | theRotationAngle = myCGrid->RotationAngle(); |
154 | } |
7fd59977 |
155 | |
679ecdee |
156 | // ======================================================================= |
157 | // function : SetCircularGridValues |
158 | // purpose : |
159 | // ======================================================================= |
ee2be2a8 |
160 | void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin, |
161 | const Standard_Real theYOrigin, |
162 | const Standard_Real theRadiusStep, |
163 | const Standard_Integer theDivisionNumber, |
164 | const Standard_Real theRotationAngle) |
679ecdee |
165 | { |
166 | myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep, |
167 | theDivisionNumber, theRotationAngle); |
6a24c6de |
168 | for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next()) |
679ecdee |
169 | { |
6a24c6de |
170 | anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myCGrid); |
679ecdee |
171 | } |
7fd59977 |
172 | } |
173 | |
679ecdee |
174 | // ======================================================================= |
175 | // function : RectangularGridGraphicValues |
176 | // purpose : |
177 | // ======================================================================= |
ee2be2a8 |
178 | void V3d_Viewer::RectangularGridGraphicValues (Standard_Real& theXSize, |
179 | Standard_Real& theYSize, |
180 | Standard_Real& theOffSet) const |
679ecdee |
181 | { |
182 | myRGrid->GraphicValues (theXSize, theYSize, theOffSet); |
183 | } |
7fd59977 |
184 | |
679ecdee |
185 | // ======================================================================= |
186 | // function : SetRectangularGridGraphicValues |
187 | // purpose : |
188 | // ======================================================================= |
ee2be2a8 |
189 | void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize, |
190 | const Standard_Real theYSize, |
191 | const Standard_Real theOffSet) |
679ecdee |
192 | { |
193 | myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet); |
7fd59977 |
194 | } |
195 | |
679ecdee |
196 | // ======================================================================= |
197 | // function : CircularGridGraphicValues |
198 | // purpose : |
199 | // ======================================================================= |
ee2be2a8 |
200 | void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius, |
201 | Standard_Real& theOffSet) const |
679ecdee |
202 | { |
203 | myCGrid->GraphicValues (theRadius, theOffSet); |
204 | } |
7fd59977 |
205 | |
679ecdee |
206 | // ======================================================================= |
207 | // function : SetCircularGridGraphicValues |
208 | // purpose : |
209 | // ======================================================================= |
ee2be2a8 |
210 | void V3d_Viewer::SetCircularGridGraphicValues (const Standard_Real theRadius, |
211 | const Standard_Real theOffSet) |
679ecdee |
212 | { |
213 | myCGrid->SetGraphicValues (theRadius, theOffSet); |
7fd59977 |
214 | } |
215 | |
679ecdee |
216 | // ======================================================================= |
217 | // function : SetGridEcho |
218 | // purpose : |
219 | // ======================================================================= |
220 | void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid) |
221 | { |
222 | if (myGridEcho == theToShowGrid) |
223 | { |
224 | return; |
225 | } |
226 | |
227 | myGridEcho = theToShowGrid; |
228 | if (theToShowGrid |
229 | || myGridEchoStructure.IsNull()) |
230 | { |
231 | return; |
232 | } |
7fd59977 |
233 | |
c3282ec1 |
234 | myGridEchoStructure->Erase(); |
7fd59977 |
235 | } |
236 | |
679ecdee |
237 | // ======================================================================= |
238 | // function : SetGridEcho |
239 | // purpose : |
240 | // ======================================================================= |
241 | void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker) |
242 | { |
243 | if (myGridEchoStructure.IsNull()) |
244 | { |
c357e426 |
245 | myGridEchoStructure = new Graphic3d_Structure (StructureManager()); |
b64d84be |
246 | myGridEchoGroup = myGridEchoStructure->NewGroup(); |
679ecdee |
247 | } |
7fd59977 |
248 | |
679ecdee |
249 | myGridEchoAspect = theMarker; |
250 | myGridEchoGroup->SetPrimitivesAspect (theMarker); |
7fd59977 |
251 | } |
252 | |
679ecdee |
253 | // ======================================================================= |
254 | // function : ShowGridEcho |
255 | // purpose : |
256 | // ======================================================================= |
257 | void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView, |
258 | const Graphic3d_Vertex& theVertex) |
259 | { |
260 | if (!myGridEcho) |
261 | { |
262 | return; |
263 | } |
7fd59977 |
264 | |
679ecdee |
265 | if (myGridEchoStructure.IsNull()) |
266 | { |
c357e426 |
267 | myGridEchoStructure = new Graphic3d_Structure (StructureManager()); |
b64d84be |
268 | myGridEchoGroup = myGridEchoStructure->NewGroup(); |
7fd59977 |
269 | |
679ecdee |
270 | myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0); |
271 | myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect); |
272 | } |
7fd59977 |
273 | |
679ecdee |
274 | if (theVertex.X() == myGridEchoLastVert.X() |
275 | && theVertex.Y() == myGridEchoLastVert.Y() |
276 | && theVertex.Z() == myGridEchoLastVert.Z()) |
277 | { |
278 | return; |
279 | } |
7fd59977 |
280 | |
679ecdee |
281 | myGridEchoLastVert = theVertex; |
282 | myGridEchoGroup->Clear(); |
283 | myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect); |
7fd59977 |
284 | |
679ecdee |
285 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
286 | anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z()); |
287 | myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints); |
7fd59977 |
288 | |
c3282ec1 |
289 | myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost); |
290 | myGridEchoStructure->SetInfiniteState (Standard_True); |
291 | myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity(); |
292 | myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False); |
293 | myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true); |
294 | myGridEchoStructure->Display(); |
7fd59977 |
295 | } |
296 | |
679ecdee |
297 | // ======================================================================= |
298 | // function : HideGridEcho |
299 | // purpose : |
300 | // ======================================================================= |
301 | void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView) |
302 | { |
303 | if (myGridEchoStructure.IsNull()) |
304 | { |
305 | return; |
7fd59977 |
306 | } |
679ecdee |
307 | |
308 | myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast()); |
c3282ec1 |
309 | const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity; |
310 | if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification())) |
311 | myGridEchoStructure->Erase(); |
7fd59977 |
312 | } |