38591f2cacb06a4512960a0d2f06554d9c2d37d5
[occt.git] / src / V3d / V3d_Viewer_4.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 /***********************************************************************
15  
16      FONCTION :
17      ----------
18         Classe V3d_Viewer :
19  
20      HISTORIQUE DES MODIFICATIONS   :
21      --------------------------------
22       16-07-98 : CAL ; S3892. Ajout grilles 3d.
23       22-09-98 : CAL ; Erreur de compilation sur WNT dans V3d_Viewer_4.cxx.
24
25 ************************************************************************/
26
27 #define IMP200100       //GG 
28 //                      -> Add GridDrawMode() method.
29 //                      -> Compute the case Aspect_TDM_None
30 //                         in ActivateGrid(..)
31
32 #define IMP240100       //GG
33 //                      -> Add SetGridEcho() & GridEcho() methods
34 //                      -> Add ShowGridEcho() private method.
35
36 #define OCC281          //SAV added new field to store grid echo aspect
37
38 /*----------------------------------------------------------------------*/
39 /*
40  * Includes
41  */
42 #include <V3d_Viewer.jxx>
43
44 /*----------------------------------------------------------------------*/
45
46 Handle(Aspect_Grid) V3d_Viewer::Grid () const {
47
48         if (myGridType == Aspect_GT_Circular)
49                 return myCGrid; 
50         else if (myGridType == Aspect_GT_Rectangular)
51                      return myRGrid;
52              else
53                      return myRGrid;
54 }
55
56 Aspect_GridType V3d_Viewer::GridType () const {
57
58         return myGridType;
59 }
60
61 #ifdef IMP200100
62 Aspect_GridDrawMode V3d_Viewer::GridDrawMode () const {
63
64         return Grid()->DrawMode();
65 }
66 #endif
67
68 void V3d_Viewer::ActivateGrid (const Aspect_GridType aType, const Aspect_GridDrawMode aMode) {
69
70         Grid ()->Erase ();
71         myGridType = aType;
72         Grid ()->SetDrawMode (aMode);
73 #ifdef IMP200100
74         if( aMode != Aspect_GDM_None ) Grid ()->Display ();
75 #else
76         Grid ()->Display ();
77 #endif
78         Grid ()->Activate ();
79         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ()) {
80                 ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
81 #ifndef IMP200100       //Do nothing more than the previous Grid()->Activate()
82                 ActiveView ()->SetGridActivity (Standard_True);
83 #endif
84         }
85         Update ();
86 }
87
88 void V3d_Viewer::DeactivateGrid () {
89
90         Grid ()->Erase ();
91         myGridType = Aspect_GT_Rectangular;
92         Grid ()->Deactivate ();
93         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ()) {
94                 ActiveView ()->SetGridActivity (Standard_False);
95         }
96         Update ();
97 }
98
99 Standard_Boolean V3d_Viewer::IsActive () const {
100
101         return Grid ()->IsActive ();
102 }
103
104 void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin, Quantity_Length& theYOrigin, Quantity_Length& theXStep, Quantity_Length& theYStep, Quantity_PlaneAngle& theRotationAngle) const {
105
106         theXOrigin = myRGrid->XOrigin ();
107         theYOrigin = myRGrid->YOrigin ();
108         theXStep = myRGrid->XStep ();
109         theYStep = myRGrid->YStep ();
110         theRotationAngle = myRGrid->RotationAngle ();
111 }
112
113 void V3d_Viewer::SetRectangularGridValues (const Quantity_Length theXOrigin, const Quantity_Length theYOrigin, const Quantity_Length theXStep, const Quantity_Length theYStep, const Quantity_PlaneAngle theRotationAngle) {
114
115         myRGrid->SetGridValues
116                 (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
117         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
118                 ActiveView ()->SetGrid (myPrivilegedPlane, myRGrid);
119         Update ();
120 }
121
122 void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin, Quantity_Length& theYOrigin, Quantity_Length& theRadiusStep, Standard_Integer& theDivisionNumber, Quantity_PlaneAngle& theRotationAngle) const {
123
124         theXOrigin = myCGrid->XOrigin ();
125         theYOrigin = myCGrid->YOrigin ();
126         theRadiusStep = myCGrid->RadiusStep ();
127         theDivisionNumber = myCGrid->DivisionNumber ();
128         theRotationAngle = myCGrid->RotationAngle ();
129 }
130
131 void V3d_Viewer::SetCircularGridValues (const Quantity_Length theXOrigin, const Quantity_Length theYOrigin, const Quantity_Length theRadiusStep, const Standard_Integer theDivisionNumber, const Quantity_PlaneAngle theRotationAngle) {
132
133         myCGrid->SetGridValues
134                 (theXOrigin, theYOrigin, theRadiusStep,
135                  theDivisionNumber, theRotationAngle);
136         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
137                 ActiveView ()->SetGrid (myPrivilegedPlane, myCGrid);
138         Update ();
139 }
140
141 void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize, Quantity_Length& theYSize, Quantity_Length& theOffSet) const {
142
143         myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
144 }
145
146 void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize, const Quantity_Length theYSize, const Quantity_Length theOffSet) {
147
148         myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
149         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
150                 ActiveView ()->SetGridGraphicValues (myRGrid);
151         Update ();
152 }
153
154 void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius, Quantity_Length& theOffSet) const {
155
156         myCGrid->GraphicValues (theRadius, theOffSet);
157 }
158
159 void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius, const Quantity_Length theOffSet) {
160
161         myCGrid->SetGraphicValues (theRadius, theOffSet);
162         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
163                 ActiveView ()->SetGridGraphicValues (myCGrid);
164         Update ();
165 }
166
167 #ifdef IMP240100
168 void V3d_Viewer::SetGridEcho( const Standard_Boolean showGrid ) {
169
170   myGridEcho = showGrid; 
171 }
172
173 void V3d_Viewer::SetGridEcho( const Handle(Graphic3d_AspectMarker3d)& aMarker ) {
174     if( myGridEchoStructure.IsNull() ) {
175       myGridEchoStructure = new Graphic3d_Structure(Viewer());
176       myGridEchoGroup = new Graphic3d_Group (myGridEchoStructure);
177     }
178 #ifdef OCC281
179     myGridEchoAspect = aMarker;
180 #endif
181     myGridEchoGroup->SetPrimitivesAspect (aMarker);
182 }
183
184 Standard_Boolean V3d_Viewer::GridEcho() const {
185
186   return myGridEcho;
187 }
188
189 #include <Graphic3d_ArrayOfPoints.hxx>
190 #include <Visual3d_TransientManager.hxx>
191 void V3d_Viewer::ShowGridEcho( const Handle(V3d_View)& aView, 
192                                         const Graphic3d_Vertex& aVertex ) {
193   if( myGridEcho ) {
194     if( myGridEchoStructure.IsNull() ) {
195       myGridEchoStructure = new Graphic3d_Structure(Viewer());
196       myGridEchoGroup = new Graphic3d_Group (myGridEchoStructure);
197 #ifdef OCC281
198       myGridEchoAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_STAR, 
199                                                        Quantity_Color( Quantity_NOC_GRAY90 ),
200                                                        3.0 );
201       myGridEchoGroup->SetPrimitivesAspect( myGridEchoAspect );
202 #else
203       Handle(Graphic3d_AspectMarker3d) markerAttrib =
204         new Graphic3d_AspectMarker3d(Aspect_TOM_STAR,
205                 Quantity_Color(Quantity_NOC_GRAY90),3.0);
206       myGridEchoGroup->SetPrimitivesAspect (markerAttrib);
207 #endif
208     }
209
210     static Graphic3d_Vertex lastVertex;
211     if( aVertex.Distance(lastVertex) != 0.0 ) {
212       lastVertex = aVertex;
213       myGridEchoGroup->Clear();
214 #ifdef OCC281
215       myGridEchoGroup->SetPrimitivesAspect( myGridEchoAspect );
216 #endif
217       Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
218       anArrayOfPoints->AddVertex (aVertex.X(), aVertex.Y(), aVertex.Z());
219       myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
220
221       Visual3d_TransientManager::BeginDraw(
222                 aView->View(), Standard_False, Standard_False);
223       Visual3d_TransientManager::DrawStructure (myGridEchoStructure);
224       Visual3d_TransientManager::EndDraw (Standard_True);
225     }
226   }
227 }
228 #endif