d2b47c233218db49a0b4ca096a9dea5588883277
[occt.git] / src / V3d / V3d_Viewer_4.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 /***********************************************************************
19  
20      FONCTION :
21      ----------
22         Classe V3d_Viewer :
23  
24      HISTORIQUE DES MODIFICATIONS   :
25      --------------------------------
26       16-07-98 : CAL ; S3892. Ajout grilles 3d.
27       22-09-98 : CAL ; Erreur de compilation sur WNT dans V3d_Viewer_4.cxx.
28
29 ************************************************************************/
30
31 #define IMP200100       //GG 
32 //                      -> Add GridDrawMode() method.
33 //                      -> Compute the case Aspect_TDM_None
34 //                         in ActivateGrid(..)
35
36 #define IMP240100       //GG
37 //                      -> Add SetGridEcho() & GridEcho() methods
38 //                      -> Add ShowGridEcho() private method.
39
40 #define OCC281          //SAV added new field to store grid echo aspect
41
42 /*----------------------------------------------------------------------*/
43 /*
44  * Includes
45  */
46 #include <V3d_Viewer.jxx>
47
48 /*----------------------------------------------------------------------*/
49
50 Handle(Aspect_Grid) V3d_Viewer::Grid () const {
51
52         if (myGridType == Aspect_GT_Circular)
53                 return myCGrid; 
54         else if (myGridType == Aspect_GT_Rectangular)
55                      return myRGrid;
56              else
57                      return myRGrid;
58 }
59
60 Aspect_GridType V3d_Viewer::GridType () const {
61
62         return myGridType;
63 }
64
65 #ifdef IMP200100
66 Aspect_GridDrawMode V3d_Viewer::GridDrawMode () const {
67
68         return Grid()->DrawMode();
69 }
70 #endif
71
72 void V3d_Viewer::ActivateGrid (const Aspect_GridType aType, const Aspect_GridDrawMode aMode) {
73
74         Grid ()->Erase ();
75         myGridType = aType;
76         Grid ()->SetDrawMode (aMode);
77 #ifdef IMP200100
78         if( aMode != Aspect_GDM_None ) Grid ()->Display ();
79 #else
80         Grid ()->Display ();
81 #endif
82         Grid ()->Activate ();
83         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ()) {
84                 ActiveView ()->SetGrid (myPrivilegedPlane, Grid ());
85 #ifndef IMP200100       //Do nothing more than the previous Grid()->Activate()
86                 ActiveView ()->SetGridActivity (Standard_True);
87 #endif
88         }
89         Update ();
90 }
91
92 void V3d_Viewer::DeactivateGrid () {
93
94         Grid ()->Erase ();
95         myGridType = Aspect_GT_Rectangular;
96         Grid ()->Deactivate ();
97         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ()) {
98                 ActiveView ()->SetGridActivity (Standard_False);
99         }
100         Update ();
101 }
102
103 Standard_Boolean V3d_Viewer::IsActive () const {
104
105         return Grid ()->IsActive ();
106 }
107
108 void V3d_Viewer::RectangularGridValues (Quantity_Length& theXOrigin, Quantity_Length& theYOrigin, Quantity_Length& theXStep, Quantity_Length& theYStep, Quantity_PlaneAngle& theRotationAngle) const {
109
110         theXOrigin = myRGrid->XOrigin ();
111         theYOrigin = myRGrid->YOrigin ();
112         theXStep = myRGrid->XStep ();
113         theYStep = myRGrid->YStep ();
114         theRotationAngle = myRGrid->RotationAngle ();
115 }
116
117 void V3d_Viewer::SetRectangularGridValues (const Quantity_Length theXOrigin, const Quantity_Length theYOrigin, const Quantity_Length theXStep, const Quantity_Length theYStep, const Quantity_PlaneAngle theRotationAngle) {
118
119         myRGrid->SetGridValues
120                 (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
121         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
122                 ActiveView ()->SetGrid (myPrivilegedPlane, myRGrid);
123         Update ();
124 }
125
126 void V3d_Viewer::CircularGridValues (Quantity_Length& theXOrigin, Quantity_Length& theYOrigin, Quantity_Length& theRadiusStep, Standard_Integer& theDivisionNumber, Quantity_PlaneAngle& theRotationAngle) const {
127
128         theXOrigin = myCGrid->XOrigin ();
129         theYOrigin = myCGrid->YOrigin ();
130         theRadiusStep = myCGrid->RadiusStep ();
131         theDivisionNumber = myCGrid->DivisionNumber ();
132         theRotationAngle = myCGrid->RotationAngle ();
133 }
134
135 void V3d_Viewer::SetCircularGridValues (const Quantity_Length theXOrigin, const Quantity_Length theYOrigin, const Quantity_Length theRadiusStep, const Standard_Integer theDivisionNumber, const Quantity_PlaneAngle theRotationAngle) {
136
137         myCGrid->SetGridValues
138                 (theXOrigin, theYOrigin, theRadiusStep,
139                  theDivisionNumber, theRotationAngle);
140         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
141                 ActiveView ()->SetGrid (myPrivilegedPlane, myCGrid);
142         Update ();
143 }
144
145 void V3d_Viewer::RectangularGridGraphicValues (Quantity_Length& theXSize, Quantity_Length& theYSize, Quantity_Length& theOffSet) const {
146
147         myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
148 }
149
150 void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize, const Quantity_Length theYSize, const Quantity_Length theOffSet) {
151
152         myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
153         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
154                 ActiveView ()->SetGridGraphicValues (myRGrid);
155         Update ();
156 }
157
158 void V3d_Viewer::CircularGridGraphicValues (Quantity_Length& theRadius, Quantity_Length& theOffSet) const {
159
160         myCGrid->GraphicValues (theRadius, theOffSet);
161 }
162
163 void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius, const Quantity_Length theOffSet) {
164
165         myCGrid->SetGraphicValues (theRadius, theOffSet);
166         for (InitActiveViews (); MoreActiveViews (); NextActiveViews ())
167                 ActiveView ()->SetGridGraphicValues (myCGrid);
168         Update ();
169 }
170
171 #ifdef IMP240100
172 void V3d_Viewer::SetGridEcho( const Standard_Boolean showGrid ) {
173
174   myGridEcho = showGrid; 
175 }
176
177 void V3d_Viewer::SetGridEcho( const Handle(Graphic3d_AspectMarker3d)& aMarker ) {
178     if( myGridEchoStructure.IsNull() ) {
179       myGridEchoStructure = new Graphic3d_Structure(Viewer());
180       myGridEchoGroup = new Graphic3d_Group (myGridEchoStructure);
181     }
182 #ifdef OCC281
183     myGridEchoAspect = aMarker;
184 #endif
185     myGridEchoGroup->SetPrimitivesAspect (aMarker);
186 }
187
188 Standard_Boolean V3d_Viewer::GridEcho() const {
189
190   return myGridEcho;
191 }
192
193 #include <Visual3d_TransientManager.hxx>
194 void V3d_Viewer::ShowGridEcho( const Handle(V3d_View)& aView, 
195                                         const Graphic3d_Vertex& aVertex ) {
196   if( myGridEcho ) {
197     if( myGridEchoStructure.IsNull() ) {
198       myGridEchoStructure = new Graphic3d_Structure(Viewer());
199       myGridEchoGroup = new Graphic3d_Group (myGridEchoStructure);
200 #ifdef OCC281
201       myGridEchoAspect = new Graphic3d_AspectMarker3d( Aspect_TOM_STAR, 
202                                                        Quantity_Color( Quantity_NOC_GRAY90 ),
203                                                        3.0 );
204       myGridEchoGroup->SetPrimitivesAspect( myGridEchoAspect );
205 #else
206       Handle(Graphic3d_AspectMarker3d) markerAttrib =
207         new Graphic3d_AspectMarker3d(Aspect_TOM_STAR,
208                 Quantity_Color(Quantity_NOC_GRAY90),3.0);
209       myGridEchoGroup->SetPrimitivesAspect (markerAttrib);
210 #endif
211     }
212
213     static Graphic3d_Vertex lastVertex;
214     if( aVertex.Distance(lastVertex) != 0.0 ) {
215       lastVertex = aVertex;
216       myGridEchoGroup->Clear();
217 #ifdef OCC281
218       myGridEchoGroup->SetPrimitivesAspect( myGridEchoAspect );
219 #endif
220       myGridEchoGroup->Marker(aVertex);
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