0024752: Visualization - inherit OpenGl_Group from Graphic3d_Group
[occt.git] / src / V3d / V3d_Viewer_4.cxx
CommitLineData
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#include <V3d_Viewer.jxx>
15
679ecdee 16#include <Graphic3d_ArrayOfPoints.hxx>
17#include <Visual3d_View.hxx>
18
19// =======================================================================
20// function : Grid
21// purpose :
22// =======================================================================
23Handle(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;
7fd59977 31}
32
679ecdee 33// =======================================================================
34// function : GridType
35// purpose :
36// =======================================================================
37Aspect_GridType V3d_Viewer::GridType() const
38{
39 return myGridType;
7fd59977 40}
41
679ecdee 42// =======================================================================
43// function : GridDrawMode
44// purpose :
45// =======================================================================
46Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
47{
48 return Grid()->DrawMode();
7fd59977 49}
7fd59977 50
679ecdee 51// =======================================================================
52// function : ActivateGrid
53// purpose :
54// =======================================================================
55void 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();
7fd59977 71}
72
679ecdee 73// =======================================================================
74// function : DeactivateGrid
75// purpose :
76// =======================================================================
77void 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();
7fd59977 92}
93
679ecdee 94// =======================================================================
95// function : IsActive
96// purpose :
97// =======================================================================
98Standard_Boolean V3d_Viewer::IsActive() const
99{
100 return Grid()->IsActive();
7fd59977 101}
102
679ecdee 103// =======================================================================
104// function : RectangularGridValues
105// purpose :
106// =======================================================================
107void 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}
7fd59977 119
679ecdee 120// =======================================================================
121// function : SetRectangularGridValues
122// purpose :
123// =======================================================================
124void 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();
7fd59977 136}
137
679ecdee 138// =======================================================================
139// function : CircularGridValues
140// purpose :
141// =======================================================================
142void 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}
7fd59977 154
679ecdee 155// =======================================================================
156// function : SetCircularGridValues
157// purpose :
158// =======================================================================
159void 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();
7fd59977 172}
173
679ecdee 174// =======================================================================
175// function : RectangularGridGraphicValues
176// purpose :
177// =======================================================================
178void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize,
179 Quantity_Length& theYSize,
180 Quantity_Length& theOffSet) const
181{
182 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
183}
7fd59977 184
679ecdee 185// =======================================================================
186// function : SetRectangularGridGraphicValues
187// purpose :
188// =======================================================================
189void 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();
7fd59977 199}
200
679ecdee 201// =======================================================================
202// function : CircularGridGraphicValues
203// purpose :
204// =======================================================================
205void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius,
206 Quantity_Length& theOffSet) const
207{
208 myCGrid->GraphicValues (theRadius, theOffSet);
209}
7fd59977 210
679ecdee 211// =======================================================================
212// function : SetCircularGridGraphicValues
213// purpose :
214// =======================================================================
215void 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();
7fd59977 224}
225
679ecdee 226// =======================================================================
227// function : SetGridEcho
228// purpose :
229// =======================================================================
230void 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 }
7fd59977 243
679ecdee 244 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
245 {
246 ActiveView()->View()->EraseImmediate (myGridEchoStructure);
247 }
7fd59977 248}
249
679ecdee 250// =======================================================================
251// function : SetGridEcho
252// purpose :
253// =======================================================================
254void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
255{
256 if (myGridEchoStructure.IsNull())
257 {
258 myGridEchoStructure = new Graphic3d_Structure (Viewer());
b64d84be 259 myGridEchoGroup = myGridEchoStructure->NewGroup();
679ecdee 260 }
7fd59977 261
679ecdee 262 myGridEchoAspect = theMarker;
263 myGridEchoGroup->SetPrimitivesAspect (theMarker);
7fd59977 264}
265
679ecdee 266// =======================================================================
267// function : GridEcho
268// purpose :
269// =======================================================================
270Standard_Boolean V3d_Viewer::GridEcho() const
271{
272 return myGridEcho;
7fd59977 273}
274
679ecdee 275// =======================================================================
276// function : ShowGridEcho
277// purpose :
278// =======================================================================
279void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
280 const Graphic3d_Vertex& theVertex)
281{
282 if (!myGridEcho)
283 {
284 return;
285 }
7fd59977 286
679ecdee 287 if (myGridEchoStructure.IsNull())
288 {
289 myGridEchoStructure = new Graphic3d_Structure (Viewer());
b64d84be 290 myGridEchoGroup = myGridEchoStructure->NewGroup();
7fd59977 291
679ecdee 292 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
293 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
294 }
7fd59977 295
679ecdee 296 if (theVertex.X() == myGridEchoLastVert.X()
297 && theVertex.Y() == myGridEchoLastVert.Y()
298 && theVertex.Z() == myGridEchoLastVert.Z())
299 {
300 return;
301 }
7fd59977 302
679ecdee 303 myGridEchoLastVert = theVertex;
304 myGridEchoGroup->Clear();
305 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
7fd59977 306
679ecdee 307 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
308 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
309 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
7fd59977 310
679ecdee 311 theView->View()->DisplayImmediate (myGridEchoStructure, Standard_True);
7fd59977 312}
313
679ecdee 314// =======================================================================
315// function : HideGridEcho
316// purpose :
317// =======================================================================
318void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
319{
320 if (myGridEchoStructure.IsNull())
321 {
322 return;
7fd59977 323 }
679ecdee 324
325 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
326 theView->View()->EraseImmediate (myGridEchoStructure);
7fd59977 327}