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>
31 #include <Visual3d_View.hxx>
32 #include <Visual3d_ViewManager.hxx>
34 // =======================================================================
37 // =======================================================================
38 Handle(Aspect_Grid) V3d_Viewer::Grid() const
42 case Aspect_GT_Circular: return Handle(Aspect_Grid) (myCGrid);
43 case Aspect_GT_Rectangular: return Handle(Aspect_Grid) (myRGrid);
45 return Handle(Aspect_Grid) (myRGrid);
48 // =======================================================================
49 // function : GridType
51 // =======================================================================
52 Aspect_GridType V3d_Viewer::GridType() const
57 // =======================================================================
58 // function : GridDrawMode
60 // =======================================================================
61 Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
63 return Grid()->DrawMode();
66 // =======================================================================
67 // function : ActivateGrid
69 // =======================================================================
70 void V3d_Viewer::ActivateGrid (const Aspect_GridType theType,
71 const Aspect_GridDrawMode theMode)
75 Grid()->SetDrawMode (theMode);
76 if (theMode != Aspect_GDM_None)
81 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
83 ActiveView()->SetGrid (myPrivilegedPlane, Grid());
88 // =======================================================================
89 // function : DeactivateGrid
91 // =======================================================================
92 void V3d_Viewer::DeactivateGrid()
95 myGridType = Aspect_GT_Rectangular;
97 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
99 ActiveView()->SetGridActivity (Standard_False);
101 && !myGridEchoStructure.IsNull())
103 myGridEchoStructure->Erase();
109 // =======================================================================
110 // function : IsActive
112 // =======================================================================
113 Standard_Boolean V3d_Viewer::IsActive() const
115 return Grid()->IsActive();
118 // =======================================================================
119 // function : RectangularGridValues
121 // =======================================================================
122 void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin,
123 Quantity_Length& theYOrigin,
124 Quantity_Length& theXStep,
125 Quantity_Length& theYStep,
126 Quantity_PlaneAngle& theRotationAngle) const
128 theXOrigin = myRGrid->XOrigin();
129 theYOrigin = myRGrid->YOrigin();
130 theXStep = myRGrid->XStep();
131 theYStep = myRGrid->YStep();
132 theRotationAngle = myRGrid->RotationAngle();
135 // =======================================================================
136 // function : SetRectangularGridValues
138 // =======================================================================
139 void V3d_Viewer::SetRectangularGridValues (const Quantity_Length theXOrigin,
140 const Quantity_Length theYOrigin,
141 const Quantity_Length theXStep,
142 const Quantity_Length theYStep,
143 const Quantity_PlaneAngle theRotationAngle)
145 myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
146 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
148 ActiveView()->SetGrid (myPrivilegedPlane, myRGrid);
153 // =======================================================================
154 // function : CircularGridValues
156 // =======================================================================
157 void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin,
158 Quantity_Length& theYOrigin,
159 Quantity_Length& theRadiusStep,
160 Standard_Integer& theDivisionNumber,
161 Quantity_PlaneAngle& theRotationAngle) const
163 theXOrigin = myCGrid->XOrigin();
164 theYOrigin = myCGrid->YOrigin();
165 theRadiusStep = myCGrid->RadiusStep();
166 theDivisionNumber = myCGrid->DivisionNumber();
167 theRotationAngle = myCGrid->RotationAngle();
170 // =======================================================================
171 // function : SetCircularGridValues
173 // =======================================================================
174 void V3d_Viewer::SetCircularGridValues (const Quantity_Length theXOrigin,
175 const Quantity_Length theYOrigin,
176 const Quantity_Length theRadiusStep,
177 const Standard_Integer theDivisionNumber,
178 const Quantity_PlaneAngle theRotationAngle)
180 myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
181 theDivisionNumber, theRotationAngle);
182 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
184 ActiveView()->SetGrid (myPrivilegedPlane, myCGrid);
189 // =======================================================================
190 // function : RectangularGridGraphicValues
192 // =======================================================================
193 void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize,
194 Quantity_Length& theYSize,
195 Quantity_Length& theOffSet) const
197 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
200 // =======================================================================
201 // function : SetRectangularGridGraphicValues
203 // =======================================================================
204 void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize,
205 const Quantity_Length theYSize,
206 const Quantity_Length theOffSet)
208 myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
209 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
211 ActiveView()->SetGridGraphicValues (myRGrid);
216 // =======================================================================
217 // function : CircularGridGraphicValues
219 // =======================================================================
220 void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius,
221 Quantity_Length& theOffSet) const
223 myCGrid->GraphicValues (theRadius, theOffSet);
226 // =======================================================================
227 // function : SetCircularGridGraphicValues
229 // =======================================================================
230 void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius,
231 const Quantity_Length theOffSet)
233 myCGrid->SetGraphicValues (theRadius, theOffSet);
234 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
236 ActiveView()->SetGridGraphicValues (myCGrid);
241 // =======================================================================
242 // function : SetGridEcho
244 // =======================================================================
245 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
247 if (myGridEcho == theToShowGrid)
252 myGridEcho = theToShowGrid;
254 || myGridEchoStructure.IsNull())
259 myGridEchoStructure->Erase();
262 // =======================================================================
263 // function : SetGridEcho
265 // =======================================================================
266 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
268 if (myGridEchoStructure.IsNull())
270 myGridEchoStructure = new Graphic3d_Structure (Viewer());
271 myGridEchoGroup = myGridEchoStructure->NewGroup();
274 myGridEchoAspect = theMarker;
275 myGridEchoGroup->SetPrimitivesAspect (theMarker);
278 // =======================================================================
279 // function : GridEcho
281 // =======================================================================
282 Standard_Boolean V3d_Viewer::GridEcho() const
287 // =======================================================================
288 // function : ShowGridEcho
290 // =======================================================================
291 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
292 const Graphic3d_Vertex& theVertex)
299 if (myGridEchoStructure.IsNull())
301 myGridEchoStructure = new Graphic3d_Structure (Viewer());
302 myGridEchoGroup = myGridEchoStructure->NewGroup();
304 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
305 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
308 if (theVertex.X() == myGridEchoLastVert.X()
309 && theVertex.Y() == myGridEchoLastVert.Y()
310 && theVertex.Z() == myGridEchoLastVert.Z())
315 myGridEchoLastVert = theVertex;
316 myGridEchoGroup->Clear();
317 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
319 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
320 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
321 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
323 myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost);
324 myGridEchoStructure->SetInfiniteState (Standard_True);
325 myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
326 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
327 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true);
328 myGridEchoStructure->Display();
331 // =======================================================================
332 // function : HideGridEcho
334 // =======================================================================
335 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
337 if (myGridEchoStructure.IsNull())
342 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
343 const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
344 if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
345 myGridEchoStructure->Erase();