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 : GridDrawMode
49 // =======================================================================
50 Aspect_GridDrawMode V3d_Viewer::GridDrawMode() const
52 return Grid()->DrawMode();
55 // =======================================================================
56 // function : ActivateGrid
58 // =======================================================================
59 void V3d_Viewer::ActivateGrid (const Aspect_GridType theType,
60 const Aspect_GridDrawMode theMode)
64 Grid()->SetDrawMode (theMode);
65 if (theMode != Aspect_GDM_None)
70 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
72 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, Grid());
76 // =======================================================================
77 // function : DeactivateGrid
79 // =======================================================================
80 void V3d_Viewer::DeactivateGrid()
83 myGridType = Aspect_GT_Rectangular;
85 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
87 anActiveViewIter.Value()->SetGridActivity (Standard_False);
89 && !myGridEchoStructure.IsNull())
91 myGridEchoStructure->Erase();
96 // =======================================================================
97 // function : IsActive
99 // =======================================================================
100 Standard_Boolean V3d_Viewer::IsActive() const
102 return Grid()->IsActive();
105 // =======================================================================
106 // function : RectangularGridValues
108 // =======================================================================
109 void V3d_Viewer::RectangularGridValues (Standard_Real& theXOrigin,
110 Standard_Real& theYOrigin,
111 Standard_Real& theXStep,
112 Standard_Real& theYStep,
113 Standard_Real& theRotationAngle) const
115 theXOrigin = myRGrid->XOrigin();
116 theYOrigin = myRGrid->YOrigin();
117 theXStep = myRGrid->XStep();
118 theYStep = myRGrid->YStep();
119 theRotationAngle = myRGrid->RotationAngle();
122 // =======================================================================
123 // function : SetRectangularGridValues
125 // =======================================================================
126 void V3d_Viewer::SetRectangularGridValues (const Standard_Real theXOrigin,
127 const Standard_Real theYOrigin,
128 const Standard_Real theXStep,
129 const Standard_Real theYStep,
130 const Standard_Real theRotationAngle)
132 myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
133 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
135 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myRGrid);
139 // =======================================================================
140 // function : CircularGridValues
142 // =======================================================================
143 void V3d_Viewer::CircularGridValues (Standard_Real& theXOrigin,
144 Standard_Real& theYOrigin,
145 Standard_Real& theRadiusStep,
146 Standard_Integer& theDivisionNumber,
147 Standard_Real& theRotationAngle) const
149 theXOrigin = myCGrid->XOrigin();
150 theYOrigin = myCGrid->YOrigin();
151 theRadiusStep = myCGrid->RadiusStep();
152 theDivisionNumber = myCGrid->DivisionNumber();
153 theRotationAngle = myCGrid->RotationAngle();
156 // =======================================================================
157 // function : SetCircularGridValues
159 // =======================================================================
160 void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin,
161 const Standard_Real theYOrigin,
162 const Standard_Real theRadiusStep,
163 const Standard_Integer theDivisionNumber,
164 const Standard_Real theRotationAngle)
166 myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
167 theDivisionNumber, theRotationAngle);
168 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
170 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myCGrid);
174 // =======================================================================
175 // function : RectangularGridGraphicValues
177 // =======================================================================
178 void V3d_Viewer::RectangularGridGraphicValues (Standard_Real& theXSize,
179 Standard_Real& theYSize,
180 Standard_Real& theOffSet) const
182 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
185 // =======================================================================
186 // function : SetRectangularGridGraphicValues
188 // =======================================================================
189 void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize,
190 const Standard_Real theYSize,
191 const Standard_Real theOffSet)
193 myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
196 // =======================================================================
197 // function : CircularGridGraphicValues
199 // =======================================================================
200 void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius,
201 Standard_Real& theOffSet) const
203 myCGrid->GraphicValues (theRadius, theOffSet);
206 // =======================================================================
207 // function : SetCircularGridGraphicValues
209 // =======================================================================
210 void V3d_Viewer::SetCircularGridGraphicValues (const Standard_Real theRadius,
211 const Standard_Real theOffSet)
213 myCGrid->SetGraphicValues (theRadius, theOffSet);
216 // =======================================================================
217 // function : SetGridEcho
219 // =======================================================================
220 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
222 if (myGridEcho == theToShowGrid)
227 myGridEcho = theToShowGrid;
229 || myGridEchoStructure.IsNull())
234 myGridEchoStructure->Erase();
237 // =======================================================================
238 // function : SetGridEcho
240 // =======================================================================
241 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
243 if (myGridEchoStructure.IsNull())
245 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
246 myGridEchoGroup = myGridEchoStructure->NewGroup();
249 myGridEchoAspect = theMarker;
250 myGridEchoGroup->SetPrimitivesAspect (theMarker);
253 // =======================================================================
254 // function : ShowGridEcho
256 // =======================================================================
257 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
258 const Graphic3d_Vertex& theVertex)
265 if (myGridEchoStructure.IsNull())
267 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
268 myGridEchoGroup = myGridEchoStructure->NewGroup();
270 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
271 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
274 if (theVertex.X() == myGridEchoLastVert.X()
275 && theVertex.Y() == myGridEchoLastVert.Y()
276 && theVertex.Z() == myGridEchoLastVert.Z())
281 myGridEchoLastVert = theVertex;
282 myGridEchoGroup->Clear();
283 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
285 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
286 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
287 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
289 myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost);
290 myGridEchoStructure->SetInfiniteState (Standard_True);
291 myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
292 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
293 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true);
294 myGridEchoStructure->Display();
297 // =======================================================================
298 // function : HideGridEcho
300 // =======================================================================
301 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
303 if (myGridEchoStructure.IsNull())
308 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
309 const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
310 if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
311 myGridEchoStructure->Erase();