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 (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
81 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, Grid());
85 // =======================================================================
86 // function : DeactivateGrid
88 // =======================================================================
89 void V3d_Viewer::DeactivateGrid()
92 myGridType = Aspect_GT_Rectangular;
94 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
96 anActiveViewIter.Value()->SetGridActivity (Standard_False);
98 && !myGridEchoStructure.IsNull())
100 myGridEchoStructure->Erase();
105 // =======================================================================
106 // function : IsActive
108 // =======================================================================
109 Standard_Boolean V3d_Viewer::IsActive() const
111 return Grid()->IsActive();
114 // =======================================================================
115 // function : RectangularGridValues
117 // =======================================================================
118 void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin,
119 Quantity_Length& theYOrigin,
120 Quantity_Length& theXStep,
121 Quantity_Length& theYStep,
122 Quantity_PlaneAngle& theRotationAngle) const
124 theXOrigin = myRGrid->XOrigin();
125 theYOrigin = myRGrid->YOrigin();
126 theXStep = myRGrid->XStep();
127 theYStep = myRGrid->YStep();
128 theRotationAngle = myRGrid->RotationAngle();
131 // =======================================================================
132 // function : SetRectangularGridValues
134 // =======================================================================
135 void V3d_Viewer::SetRectangularGridValues (const Quantity_Length theXOrigin,
136 const Quantity_Length theYOrigin,
137 const Quantity_Length theXStep,
138 const Quantity_Length theYStep,
139 const Quantity_PlaneAngle theRotationAngle)
141 myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
142 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
144 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myRGrid);
148 // =======================================================================
149 // function : CircularGridValues
151 // =======================================================================
152 void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin,
153 Quantity_Length& theYOrigin,
154 Quantity_Length& theRadiusStep,
155 Standard_Integer& theDivisionNumber,
156 Quantity_PlaneAngle& theRotationAngle) const
158 theXOrigin = myCGrid->XOrigin();
159 theYOrigin = myCGrid->YOrigin();
160 theRadiusStep = myCGrid->RadiusStep();
161 theDivisionNumber = myCGrid->DivisionNumber();
162 theRotationAngle = myCGrid->RotationAngle();
165 // =======================================================================
166 // function : SetCircularGridValues
168 // =======================================================================
169 void V3d_Viewer::SetCircularGridValues (const Quantity_Length theXOrigin,
170 const Quantity_Length theYOrigin,
171 const Quantity_Length theRadiusStep,
172 const Standard_Integer theDivisionNumber,
173 const Quantity_PlaneAngle theRotationAngle)
175 myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
176 theDivisionNumber, theRotationAngle);
177 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
179 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myCGrid);
183 // =======================================================================
184 // function : RectangularGridGraphicValues
186 // =======================================================================
187 void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize,
188 Quantity_Length& theYSize,
189 Quantity_Length& theOffSet) const
191 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
194 // =======================================================================
195 // function : SetRectangularGridGraphicValues
197 // =======================================================================
198 void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize,
199 const Quantity_Length theYSize,
200 const Quantity_Length theOffSet)
202 myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
205 // =======================================================================
206 // function : CircularGridGraphicValues
208 // =======================================================================
209 void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius,
210 Quantity_Length& theOffSet) const
212 myCGrid->GraphicValues (theRadius, theOffSet);
215 // =======================================================================
216 // function : SetCircularGridGraphicValues
218 // =======================================================================
219 void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius,
220 const Quantity_Length theOffSet)
222 myCGrid->SetGraphicValues (theRadius, theOffSet);
225 // =======================================================================
226 // function : SetGridEcho
228 // =======================================================================
229 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
231 if (myGridEcho == theToShowGrid)
236 myGridEcho = theToShowGrid;
238 || myGridEchoStructure.IsNull())
243 myGridEchoStructure->Erase();
246 // =======================================================================
247 // function : SetGridEcho
249 // =======================================================================
250 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
252 if (myGridEchoStructure.IsNull())
254 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
255 myGridEchoGroup = myGridEchoStructure->NewGroup();
258 myGridEchoAspect = theMarker;
259 myGridEchoGroup->SetPrimitivesAspect (theMarker);
262 // =======================================================================
263 // function : GridEcho
265 // =======================================================================
266 Standard_Boolean V3d_Viewer::GridEcho() const
271 // =======================================================================
272 // function : ShowGridEcho
274 // =======================================================================
275 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
276 const Graphic3d_Vertex& theVertex)
283 if (myGridEchoStructure.IsNull())
285 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
286 myGridEchoGroup = myGridEchoStructure->NewGroup();
288 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
289 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
292 if (theVertex.X() == myGridEchoLastVert.X()
293 && theVertex.Y() == myGridEchoLastVert.Y()
294 && theVertex.Z() == myGridEchoLastVert.Z())
299 myGridEchoLastVert = theVertex;
300 myGridEchoGroup->Clear();
301 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
303 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
304 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
305 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
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();
315 // =======================================================================
316 // function : HideGridEcho
318 // =======================================================================
319 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
321 if (myGridEchoStructure.IsNull())
326 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
327 const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
328 if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
329 myGridEchoStructure->Erase();