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