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