1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Aspect_Background.hxx>
16 #include <Aspect_GradientBackground.hxx>
17 #include <Aspect_Grid.hxx>
19 #include <Graphic3d_ArrayOfPoints.hxx>
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>
32 // =======================================================================
35 // =======================================================================
36 Handle(Aspect_Grid) V3d_Viewer::Grid() const
40 case Aspect_GT_Circular: return Handle(Aspect_Grid) (myCGrid);
41 case Aspect_GT_Rectangular: return Handle(Aspect_Grid) (myRGrid);
43 return Handle(Aspect_Grid) (myRGrid);
46 // =======================================================================
47 // function : GridType
49 // =======================================================================
50 Aspect_GridType V3d_Viewer::GridType() const
55 // =======================================================================
56 // function : GridDrawMode
58 // =======================================================================
59 Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
61 return Grid()->DrawMode();
64 // =======================================================================
65 // function : ActivateGrid
67 // =======================================================================
68 void V3d_Viewer::ActivateGrid (const Aspect_GridType theType,
69 const Aspect_GridDrawMode theMode)
73 Grid()->SetDrawMode (theMode);
74 if (theMode != Aspect_GDM_None)
79 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
81 ActiveView()->SetGrid (myPrivilegedPlane, Grid());
86 // =======================================================================
87 // function : DeactivateGrid
89 // =======================================================================
90 void V3d_Viewer::DeactivateGrid()
93 myGridType = Aspect_GT_Rectangular;
95 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
97 ActiveView()->SetGridActivity (Standard_False);
99 && !myGridEchoStructure.IsNull())
101 myGridEchoStructure->Erase();
107 // =======================================================================
108 // function : IsActive
110 // =======================================================================
111 Standard_Boolean V3d_Viewer::IsActive() const
113 return Grid()->IsActive();
116 // =======================================================================
117 // function : RectangularGridValues
119 // =======================================================================
120 void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin,
121 Quantity_Length& theYOrigin,
122 Quantity_Length& theXStep,
123 Quantity_Length& theYStep,
124 Quantity_PlaneAngle& theRotationAngle) const
126 theXOrigin = myRGrid->XOrigin();
127 theYOrigin = myRGrid->YOrigin();
128 theXStep = myRGrid->XStep();
129 theYStep = myRGrid->YStep();
130 theRotationAngle = myRGrid->RotationAngle();
133 // =======================================================================
134 // function : SetRectangularGridValues
136 // =======================================================================
137 void V3d_Viewer::SetRectangularGridValues (const Quantity_Length theXOrigin,
138 const Quantity_Length theYOrigin,
139 const Quantity_Length theXStep,
140 const Quantity_Length theYStep,
141 const Quantity_PlaneAngle theRotationAngle)
143 myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
144 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
146 ActiveView()->SetGrid (myPrivilegedPlane, myRGrid);
151 // =======================================================================
152 // function : CircularGridValues
154 // =======================================================================
155 void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin,
156 Quantity_Length& theYOrigin,
157 Quantity_Length& theRadiusStep,
158 Standard_Integer& theDivisionNumber,
159 Quantity_PlaneAngle& theRotationAngle) const
161 theXOrigin = myCGrid->XOrigin();
162 theYOrigin = myCGrid->YOrigin();
163 theRadiusStep = myCGrid->RadiusStep();
164 theDivisionNumber = myCGrid->DivisionNumber();
165 theRotationAngle = myCGrid->RotationAngle();
168 // =======================================================================
169 // function : SetCircularGridValues
171 // =======================================================================
172 void V3d_Viewer::SetCircularGridValues (const Quantity_Length theXOrigin,
173 const Quantity_Length theYOrigin,
174 const Quantity_Length theRadiusStep,
175 const Standard_Integer theDivisionNumber,
176 const Quantity_PlaneAngle theRotationAngle)
178 myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
179 theDivisionNumber, theRotationAngle);
180 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
182 ActiveView()->SetGrid (myPrivilegedPlane, myCGrid);
187 // =======================================================================
188 // function : RectangularGridGraphicValues
190 // =======================================================================
191 void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize,
192 Quantity_Length& theYSize,
193 Quantity_Length& theOffSet) const
195 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
198 // =======================================================================
199 // function : SetRectangularGridGraphicValues
201 // =======================================================================
202 void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize,
203 const Quantity_Length theYSize,
204 const Quantity_Length theOffSet)
206 myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
210 // =======================================================================
211 // function : CircularGridGraphicValues
213 // =======================================================================
214 void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius,
215 Quantity_Length& theOffSet) const
217 myCGrid->GraphicValues (theRadius, theOffSet);
220 // =======================================================================
221 // function : SetCircularGridGraphicValues
223 // =======================================================================
224 void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius,
225 const Quantity_Length theOffSet)
227 myCGrid->SetGraphicValues (theRadius, theOffSet);
231 // =======================================================================
232 // function : SetGridEcho
234 // =======================================================================
235 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
237 if (myGridEcho == theToShowGrid)
242 myGridEcho = theToShowGrid;
244 || myGridEchoStructure.IsNull())
249 myGridEchoStructure->Erase();
252 // =======================================================================
253 // function : SetGridEcho
255 // =======================================================================
256 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
258 if (myGridEchoStructure.IsNull())
260 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
261 myGridEchoGroup = myGridEchoStructure->NewGroup();
264 myGridEchoAspect = theMarker;
265 myGridEchoGroup->SetPrimitivesAspect (theMarker);
268 // =======================================================================
269 // function : GridEcho
271 // =======================================================================
272 Standard_Boolean V3d_Viewer::GridEcho() const
277 // =======================================================================
278 // function : ShowGridEcho
280 // =======================================================================
281 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
282 const Graphic3d_Vertex& theVertex)
289 if (myGridEchoStructure.IsNull())
291 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
292 myGridEchoGroup = myGridEchoStructure->NewGroup();
294 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
295 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
298 if (theVertex.X() == myGridEchoLastVert.X()
299 && theVertex.Y() == myGridEchoLastVert.Y()
300 && theVertex.Z() == myGridEchoLastVert.Z())
305 myGridEchoLastVert = theVertex;
306 myGridEchoGroup->Clear();
307 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
309 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
310 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
311 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
313 myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost);
314 myGridEchoStructure->SetInfiniteState (Standard_True);
315 myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
316 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
317 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true);
318 myGridEchoStructure->Display();
321 // =======================================================================
322 // function : HideGridEcho
324 // =======================================================================
325 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
327 if (myGridEchoStructure.IsNull())
332 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
333 const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
334 if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
335 myGridEchoStructure->Erase();