0023115: Polygon offset doesn't applied in Viewer3D sample
[occt.git] / src / Graphic3d / Graphic3d_AspectFillArea3d.cxx
1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 // Modified     1/08/97 ; PCT : Ajout texture mapping
21 //              26/01/00 ; EUG/GG degeneration management (G003)
22 //                      Add SetDegenerateModel() and DegenerateModel() methods
23 // JR 02.01.100 : Initialization order of fields in contructors
24 //              29/09/00 ; GG Add SetDefaultDegerateModel() and
25 //                      DefaultDegenerateModel() class methods
26 //              22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets 
27
28
29 //-Version      
30
31 //-Design       Declaration of variables specific to the context
32 //              of tracing of facets 3D
33
34 //-Warning      Ccontext of tracing of facets 3d inherits the context
35 //              defined by :
36 //              - the style of the interior of the facet
37 //              - the style of the facet border
38 //              - the color
39 //              Additionally, it has more than one definition of material
40 //              for internal and external faces.
41
42 //-References   
43
44 //-Language     C++ 2.0
45
46 //-Declarations
47
48 // for the class
49 #include <Graphic3d_AspectFillArea3d.ixx>
50
51 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets 
52 #include <Aspect_PolygonOffsetMode.hxx>
53 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets 
54
55 #include <Standard_Boolean.hxx>
56
57 //-Aliases
58
59 //-Global data definitions
60 static Aspect_TypeOfDegenerateModel theDefaultDegenerateModel = Aspect_TDM_WIREFRAME;
61 static Quantity_Ratio theDefaultDegenerateRatio = 0.0;
62
63 //      -- la matiere
64 //      MyFrontMaterial         :       MaterialAspect;
65 //      MyBackMaterial          :       MaterialAspect;
66
67 //      -- flag de distinction entre faces internes et externes
68 //      DistinguishModeActive   :       Standard_Boolean;
69
70 //      -- flag de trace des aretes
71 //      EdgeModeActive          :       Standard_Boolean;
72
73 //      -- flag d'affichage des polygones tournant le dos
74 //      BackFaceRemovalActive   :       Standard_Boolean;
75
76 //-Constructors
77
78 //-Destructors
79
80 //-Methods, in order
81
82 Graphic3d_AspectFillArea3d::Graphic3d_AspectFillArea3d ():
83 DistinguishModeActive (Standard_False), EdgeModeActive (Standard_False), BackFaceRemovalActive (Standard_False),  MyTextureMapState(Standard_False), MyFrontMaterial (), MyBackMaterial () {
84   MyDegenerateModel = theDefaultDegenerateModel;
85   MyDegenerateRatio = theDefaultDegenerateRatio;
86
87   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets
88   // By default, aspect do not change current polygon offset parameters
89   MyPolygonOffsetMode   = Aspect_POM_Fill;
90   MyPolygonOffsetFactor = 1.;
91   MyPolygonOffsetUnits  = 0.;
92   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets 
93 }
94
95 // (InteriorStyle, InteriorColor, EdgeColor, EdgeLineType, EdgeLineWidth)
96 // because AspectFillArea3d inherits AspectFillArea and it is necessary to call
97 // initialisation of AspectFillArea with InteriorStyle, InteriorColor,
98 // EdgeColor, EdgeLineType and EdgeLineWidth.
99
100 Graphic3d_AspectFillArea3d::Graphic3d_AspectFillArea3d (const Aspect_InteriorStyle InteriorStyle, const Quantity_Color& InteriorColor, const Quantity_Color& EdgeColor, const Aspect_TypeOfLine EdgeLineType, const Standard_Real EdgeLineWidth, const Graphic3d_MaterialAspect& FrontMaterial, const Graphic3d_MaterialAspect& BackMaterial):
101 Aspect_AspectFillArea (InteriorStyle, InteriorColor, EdgeColor, EdgeLineType, EdgeLineWidth), DistinguishModeActive (Standard_False), EdgeModeActive (Standard_False), BackFaceRemovalActive (Standard_False), MyTextureMap(), MyTextureMapState(Standard_False), MyFrontMaterial (FrontMaterial), MyBackMaterial (BackMaterial) {
102   MyDegenerateModel = theDefaultDegenerateModel;
103   MyDegenerateRatio = theDefaultDegenerateRatio;
104
105   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets 
106   // By default, aspect do not change current polygon offset parameters
107   MyPolygonOffsetMode   = Aspect_POM_Fill;
108   MyPolygonOffsetFactor = 1.;
109   MyPolygonOffsetUnits  = 0.;
110   // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets 
111 }
112
113 void Graphic3d_AspectFillArea3d::SetBackMaterial (const Graphic3d_MaterialAspect& AMaterial) {
114
115         MyBackMaterial  = AMaterial;
116
117 }
118
119 void Graphic3d_AspectFillArea3d::SetFrontMaterial (const Graphic3d_MaterialAspect& AMaterial) {
120
121         MyFrontMaterial = AMaterial;
122
123 }
124
125 Graphic3d_MaterialAspect Graphic3d_AspectFillArea3d::BackMaterial () const {
126
127         return (MyBackMaterial);
128
129 }
130
131 Graphic3d_MaterialAspect Graphic3d_AspectFillArea3d::FrontMaterial () const {
132
133         return (MyFrontMaterial);
134
135 }
136
137 void Graphic3d_AspectFillArea3d::AllowBackFace () {
138
139         BackFaceRemovalActive   = Standard_False;
140
141 }
142
143 void Graphic3d_AspectFillArea3d::SuppressBackFace () {
144
145         BackFaceRemovalActive   = Standard_True;
146
147 }
148
149 Standard_Boolean Graphic3d_AspectFillArea3d::BackFace () const {
150
151         return (BackFaceRemovalActive);
152
153 }
154
155 void Graphic3d_AspectFillArea3d::SetDistinguishOn () {
156
157         DistinguishModeActive   = Standard_True;
158
159 }
160
161 void Graphic3d_AspectFillArea3d::SetDistinguishOff () {
162
163         DistinguishModeActive   = Standard_False;
164
165 }
166
167 Standard_Boolean Graphic3d_AspectFillArea3d::Distinguish () const {
168
169         return (DistinguishModeActive);
170
171 }
172
173 void Graphic3d_AspectFillArea3d::SetEdgeOn () {
174
175         EdgeModeActive  = Standard_True;
176
177 }
178
179 void Graphic3d_AspectFillArea3d::SetEdgeOff () {
180
181         EdgeModeActive  = Standard_False;
182
183 }
184
185
186 void Graphic3d_AspectFillArea3d::SetTextureMap(const Handle(Graphic3d_TextureMap)& ATexture)
187 {
188   MyTextureMap = ATexture;
189 }
190
191
192 void Graphic3d_AspectFillArea3d::SetTextureMapOn()
193 {
194   MyTextureMapState = Standard_True;
195 }
196
197
198 void Graphic3d_AspectFillArea3d::SetTextureMapOff()
199 {
200   MyTextureMapState = Standard_False;
201 }
202
203
204 Standard_Boolean Graphic3d_AspectFillArea3d::Edge () const {
205
206         return (EdgeModeActive);
207
208 }
209
210
211 Handle(Graphic3d_TextureMap) Graphic3d_AspectFillArea3d::TextureMap() const
212 {
213   return MyTextureMap;
214 }
215
216
217 Standard_Boolean Graphic3d_AspectFillArea3d::TextureMapState() const
218 {
219   return MyTextureMapState;
220 }
221
222 void Graphic3d_AspectFillArea3d::SetDefaultDegenerateModel(
223         const Aspect_TypeOfDegenerateModel aModel,
224         const Quantity_Ratio aRatio) {
225   theDefaultDegenerateModel = aModel;
226   theDefaultDegenerateRatio = aRatio;
227 }
228
229 void Graphic3d_AspectFillArea3d::SetDegenerateModel(
230         const Aspect_TypeOfDegenerateModel aModel,
231         const Quantity_Ratio aRatio) {
232
233   MyDegenerateModel = aModel;
234   MyDegenerateRatio = aRatio;
235 }
236
237 Aspect_TypeOfDegenerateModel Graphic3d_AspectFillArea3d::DefaultDegenerateModel(
238                         Quantity_Ratio& aRatio) {
239   aRatio = theDefaultDegenerateRatio;
240   return theDefaultDegenerateModel;
241 }
242
243 Aspect_TypeOfDegenerateModel Graphic3d_AspectFillArea3d::DegenerateModel(
244                         Quantity_Ratio& aRatio) const {
245   aRatio = MyDegenerateRatio;
246   return MyDegenerateModel;
247 }
248
249 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets 
250 void Graphic3d_AspectFillArea3d::SetPolygonOffsets(const Standard_Integer aMode,
251                                                    const Standard_Real    aFactor,
252                                                    const Standard_Real    aUnits) {
253   MyPolygonOffsetMode   = ( aMode & Aspect_POM_Mask );
254   MyPolygonOffsetFactor = aFactor;
255   MyPolygonOffsetUnits  = aUnits;
256 }
257
258 void Graphic3d_AspectFillArea3d::PolygonOffsets(Standard_Integer& aMode,
259                                                 Standard_Real&    aFactor,
260                                                 Standard_Real&    aUnits) const {
261   aMode   = MyPolygonOffsetMode;
262   aFactor = MyPolygonOffsetFactor;
263   aUnits  = MyPolygonOffsetUnits;
264 }
265 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets