b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #define BUC60488 //GG_23/09/99 Updates correctly the Material after |
16 | // any change. |
17 | |
18 | #define GER61351 //GG_171199 Enable to set an object RGB color |
19 | // instead a restricted object NameOfColor. |
20 | // Enable to change separatly the front and back color. |
21 | |
22 | #define OCC1174 //SAV_080103 Added back face interior color management |
23 | |
24 | #include <Prs3d_ShadingAspect.ixx> |
25 | |
26 | //======================================================================= |
27 | //function : Prs3d_ShadingAspect |
28 | //purpose : |
29 | //======================================================================= |
30 | |
31 | Prs3d_ShadingAspect::Prs3d_ShadingAspect () { |
32 | |
33 | |
34 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS); |
35 | Quantity_Color Col; |
36 | // Ceci permet de recuperer la couleur associee |
37 | // au materiau defini par defaut. |
38 | //POP K4L |
39 | Col = aMat.AmbientColor (); |
40 | // Col = aMat.Color (); |
41 | myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, |
42 | Col, |
43 | Col, |
44 | Aspect_TOL_SOLID, |
45 | 1.0, |
46 | aMat, |
47 | aMat); |
48 | } |
49 | |
50 | |
51 | //======================================================================= |
52 | //function : SetColor |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | #ifdef GER61351 |
57 | void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor, |
58 | const Aspect_TypeOfFacingModel aModel) { |
59 | |
60 | SetColor(Quantity_Color(aColor),aModel); |
61 | } |
62 | |
63 | void Prs3d_ShadingAspect::SetColor(const Quantity_Color &aColor, |
64 | const Aspect_TypeOfFacingModel aModel) { |
65 | #ifndef OCC1174 |
66 | myAspect->SetInteriorColor(aColor); |
67 | #endif |
68 | |
69 | if( aModel != Aspect_TOFM_BOTH_SIDE ) { |
70 | myAspect->SetDistinguishOn(); |
71 | } |
72 | if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) { |
73 | Graphic3d_MaterialAspect front = myAspect->FrontMaterial(); |
74 | front.SetColor(aColor); |
75 | myAspect->SetFrontMaterial(front); |
76 | #ifdef OCC1174 |
77 | myAspect->SetInteriorColor( aColor ); |
78 | #endif |
79 | } |
80 | |
81 | if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) { |
82 | Graphic3d_MaterialAspect back = myAspect->BackMaterial(); |
83 | back.SetColor(aColor); |
84 | myAspect->SetBackMaterial(back); |
85 | #ifdef OCC1174 |
86 | myAspect->SetBackInteriorColor( aColor ); |
87 | #endif |
88 | } |
89 | } |
90 | |
91 | Quantity_Color Prs3d_ShadingAspect::Color( const Aspect_TypeOfFacingModel aModel ) const { |
92 | Quantity_Color myReturn ; |
93 | switch (aModel) { |
94 | default: |
95 | case Aspect_TOFM_BOTH_SIDE: |
96 | case Aspect_TOFM_FRONT_SIDE: |
97 | myReturn = myAspect->FrontMaterial().Color(); |
98 | break; |
99 | case Aspect_TOFM_BACK_SIDE: |
100 | myReturn = myAspect->BackMaterial().Color(); |
101 | break; |
102 | } |
103 | return myReturn ; |
104 | } |
105 | #else |
106 | void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor) { |
107 | myAspect->SetInteriorColor(aColor); |
108 | #ifdef OCC1174 |
109 | myAspect->SetBackInteriorColor( aColor ); |
110 | #endif |
111 | myAspect->FrontMaterial().SetAmbientColor(Quantity_Color(aColor)); |
112 | myAspect->BackMaterial().SetAmbientColor(Quantity_Color(aColor)); |
113 | // myAspect->FrontMaterial().SetColor(Quantity_Color(aColor)); |
114 | // myAspect->BackMaterial().SetColor(Quantity_Color(aColor)); |
115 | } |
116 | #endif |
117 | |
118 | //======================================================================= |
119 | //function : SetMaterial |
120 | //purpose : |
121 | //======================================================================= |
122 | |
123 | #ifdef GER61351 |
124 | void Prs3d_ShadingAspect::SetMaterial( |
125 | const Graphic3d_NameOfMaterial aMaterial, |
126 | const Aspect_TypeOfFacingModel aModel ) { |
127 | |
128 | SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel); |
129 | } |
130 | #else |
131 | void Prs3d_ShadingAspect::SetMaterial( |
132 | // const Graphic3d_NameOfPhysicalMaterial aMaterial) { |
133 | const Graphic3d_NameOfMaterial aMaterial) { |
134 | |
135 | Graphic3d_MaterialAspect TheMaterial(aMaterial); |
136 | myAspect->SetFrontMaterial (TheMaterial); |
137 | myAspect->SetBackMaterial (TheMaterial); |
138 | } |
139 | #endif |
140 | |
141 | //======================================================================= |
142 | //function : SetMaterial |
143 | //purpose : |
144 | //======================================================================= |
145 | |
146 | #ifdef GER61351 |
147 | void Prs3d_ShadingAspect::SetMaterial( |
148 | const Graphic3d_MaterialAspect& aMaterial, |
149 | const Aspect_TypeOfFacingModel aModel ) { |
150 | |
151 | if( aModel != Aspect_TOFM_BOTH_SIDE ) { |
152 | myAspect->SetDistinguishOn(); |
153 | } |
154 | if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) { |
155 | myAspect->SetFrontMaterial(aMaterial); |
156 | } |
157 | |
158 | if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) { |
159 | myAspect->SetBackMaterial(aMaterial); |
160 | } |
161 | } |
162 | |
163 | Graphic3d_MaterialAspect Prs3d_ShadingAspect::Material( |
164 | const Aspect_TypeOfFacingModel aModel ) const { |
165 | Graphic3d_MaterialAspect myReturn ; |
166 | switch (aModel) { |
167 | default: |
168 | case Aspect_TOFM_BOTH_SIDE: |
169 | case Aspect_TOFM_FRONT_SIDE: |
170 | myReturn = myAspect->FrontMaterial(); |
171 | break; |
172 | case Aspect_TOFM_BACK_SIDE: |
173 | myReturn = myAspect->BackMaterial(); |
174 | break; |
175 | } |
176 | return myReturn ; |
177 | } |
178 | #else |
179 | void Prs3d_ShadingAspect::SetMaterial( |
180 | const Graphic3d_MaterialAspect& aMaterial) |
181 | { |
182 | myAspect->SetFrontMaterial (aMaterial); |
183 | myAspect->SetBackMaterial (aMaterial); |
184 | } |
185 | #endif |
186 | |
187 | //======================================================================= |
188 | //function : SetTransparency |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | #ifdef GER61351 |
193 | void Prs3d_ShadingAspect::SetTransparency(const Standard_Real aValue, |
194 | const Aspect_TypeOfFacingModel aModel ) { |
195 | |
196 | if( aModel != Aspect_TOFM_BOTH_SIDE ) { |
197 | myAspect->SetDistinguishOn(); |
198 | } |
199 | if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) { |
200 | Graphic3d_MaterialAspect front = myAspect->FrontMaterial(); |
201 | front.SetTransparency(aValue); |
202 | myAspect->SetFrontMaterial(front); |
203 | } |
204 | |
205 | if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) { |
206 | Graphic3d_MaterialAspect back = myAspect->BackMaterial(); |
207 | back.SetTransparency(aValue); |
208 | myAspect->SetBackMaterial(back); |
209 | } |
210 | } |
211 | |
212 | Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const { |
213 | Standard_Real aValue(0.); |
214 | switch (aModel) { |
215 | case Aspect_TOFM_BOTH_SIDE: |
216 | case Aspect_TOFM_FRONT_SIDE: |
217 | aValue = myAspect->FrontMaterial().Transparency(); |
e2570917 |
218 | break; |
7fd59977 |
219 | case Aspect_TOFM_BACK_SIDE: |
220 | aValue = myAspect->BackMaterial().Transparency(); |
e2570917 |
221 | break; |
7fd59977 |
222 | } |
223 | return aValue; |
224 | } |
225 | #endif |
226 | |
227 | //======================================================================= |
228 | //function : SetAspect |
229 | //purpose : |
230 | //======================================================================= |
231 | |
232 | void Prs3d_ShadingAspect::SetAspect(const Handle(Graphic3d_AspectFillArea3d)& Asp) |
233 | { |
234 | myAspect=Asp; |
235 | } |
236 | |
237 | Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const { |
238 | return myAspect; |
239 | } |
240 | |