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.
14 #include <V3d_Viewer.jxx>
16 #include <Graphic3d_ArrayOfPoints.hxx>
17 #include <Visual3d_View.hxx>
19 // =======================================================================
22 // =======================================================================
23 Handle(Aspect_Grid) V3d_Viewer::Grid() const
27 case Aspect_GT_Circular: return myCGrid;
28 case Aspect_GT_Rectangular: return myRGrid;
33 // =======================================================================
34 // function : GridType
36 // =======================================================================
37 Aspect_GridType V3d_Viewer::GridType() const
42 // =======================================================================
43 // function : GridDrawMode
45 // =======================================================================
46 Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
48 return Grid()->DrawMode();
51 // =======================================================================
52 // function : ActivateGrid
54 // =======================================================================
55 void V3d_Viewer::ActivateGrid (const Aspect_GridType theType,
56 const Aspect_GridDrawMode theMode)
60 Grid()->SetDrawMode (theMode);
61 if (theMode != Aspect_GDM_None)
66 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
68 ActiveView()->SetGrid (myPrivilegedPlane, Grid());
73 // =======================================================================
74 // function : DeactivateGrid
76 // =======================================================================
77 void V3d_Viewer::DeactivateGrid()
80 myGridType = Aspect_GT_Rectangular;
82 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
84 ActiveView()->SetGridActivity (Standard_False);
86 && !myGridEchoStructure.IsNull())
88 ActiveView()->View()->EraseImmediate (myGridEchoStructure);
94 // =======================================================================
95 // function : IsActive
97 // =======================================================================
98 Standard_Boolean V3d_Viewer::IsActive() const
100 return Grid()->IsActive();
103 // =======================================================================
104 // function : RectangularGridValues
106 // =======================================================================
107 void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin,
108 Quantity_Length& theYOrigin,
109 Quantity_Length& theXStep,
110 Quantity_Length& theYStep,
111 Quantity_PlaneAngle& theRotationAngle) const
113 theXOrigin = myRGrid->XOrigin();
114 theYOrigin = myRGrid->YOrigin();
115 theXStep = myRGrid->XStep();
116 theYStep = myRGrid->YStep();
117 theRotationAngle = myRGrid->RotationAngle();
120 // =======================================================================
121 // function : SetRectangularGridValues
123 // =======================================================================
124 void 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)
130 myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
131 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
133 ActiveView()->SetGrid (myPrivilegedPlane, myRGrid);
138 // =======================================================================
139 // function : CircularGridValues
141 // =======================================================================
142 void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin,
143 Quantity_Length& theYOrigin,
144 Quantity_Length& theRadiusStep,
145 Standard_Integer& theDivisionNumber,
146 Quantity_PlaneAngle& theRotationAngle) const
148 theXOrigin = myCGrid->XOrigin();
149 theYOrigin = myCGrid->YOrigin();
150 theRadiusStep = myCGrid->RadiusStep();
151 theDivisionNumber = myCGrid->DivisionNumber();
152 theRotationAngle = myCGrid->RotationAngle();
155 // =======================================================================
156 // function : SetCircularGridValues
158 // =======================================================================
159 void 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)
165 myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
166 theDivisionNumber, theRotationAngle);
167 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
169 ActiveView()->SetGrid (myPrivilegedPlane, myCGrid);
174 // =======================================================================
175 // function : RectangularGridGraphicValues
177 // =======================================================================
178 void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize,
179 Quantity_Length& theYSize,
180 Quantity_Length& theOffSet) const
182 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
185 // =======================================================================
186 // function : SetRectangularGridGraphicValues
188 // =======================================================================
189 void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize,
190 const Quantity_Length theYSize,
191 const Quantity_Length theOffSet)
193 myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
194 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
196 ActiveView()->SetGridGraphicValues (myRGrid);
201 // =======================================================================
202 // function : CircularGridGraphicValues
204 // =======================================================================
205 void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius,
206 Quantity_Length& theOffSet) const
208 myCGrid->GraphicValues (theRadius, theOffSet);
211 // =======================================================================
212 // function : SetCircularGridGraphicValues
214 // =======================================================================
215 void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius,
216 const Quantity_Length theOffSet)
218 myCGrid->SetGraphicValues (theRadius, theOffSet);
219 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
221 ActiveView()->SetGridGraphicValues (myCGrid);
226 // =======================================================================
227 // function : SetGridEcho
229 // =======================================================================
230 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
232 if (myGridEcho == theToShowGrid)
237 myGridEcho = theToShowGrid;
239 || myGridEchoStructure.IsNull())
244 for (InitActiveViews(); MoreActiveViews(); NextActiveViews())
246 ActiveView()->View()->EraseImmediate (myGridEchoStructure);
250 // =======================================================================
251 // function : SetGridEcho
253 // =======================================================================
254 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
256 if (myGridEchoStructure.IsNull())
258 myGridEchoStructure = new Graphic3d_Structure (Viewer());
259 myGridEchoGroup = myGridEchoStructure->NewGroup();
262 myGridEchoAspect = theMarker;
263 myGridEchoGroup->SetPrimitivesAspect (theMarker);
266 // =======================================================================
267 // function : GridEcho
269 // =======================================================================
270 Standard_Boolean V3d_Viewer::GridEcho() const
275 // =======================================================================
276 // function : ShowGridEcho
278 // =======================================================================
279 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
280 const Graphic3d_Vertex& theVertex)
287 if (myGridEchoStructure.IsNull())
289 myGridEchoStructure = new Graphic3d_Structure (Viewer());
290 myGridEchoGroup = myGridEchoStructure->NewGroup();
292 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
293 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
296 if (theVertex.X() == myGridEchoLastVert.X()
297 && theVertex.Y() == myGridEchoLastVert.Y()
298 && theVertex.Z() == myGridEchoLastVert.Z())
303 myGridEchoLastVert = theVertex;
304 myGridEchoGroup->Clear();
305 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
307 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
308 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
309 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
311 theView->View()->DisplayImmediate (myGridEchoStructure, Standard_True);
314 // =======================================================================
315 // function : HideGridEcho
317 // =======================================================================
318 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
320 if (myGridEchoStructure.IsNull())
325 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
326 theView->View()->EraseImmediate (myGridEchoStructure);