0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Prs3d / Prs3d_ShadingAspect.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License 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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <Graphic3d_AspectFillArea3d.hxx>
17 #include <Graphic3d_MaterialAspect.hxx>
18 #include <Prs3d_ShadingAspect.hxx>
19 #include <Quantity_Color.hxx>
20 #include <Standard_Type.hxx>
21
22 IMPLEMENT_STANDARD_RTTIEXT(Prs3d_ShadingAspect,Prs3d_BasicAspect)
23
24 //=======================================================================
25 //function : Prs3d_ShadingAspect
26 //purpose  : 
27 //=======================================================================
28 Prs3d_ShadingAspect::Prs3d_ShadingAspect () {
29
30
31   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
32   Quantity_Color Col;
33   // Ceci permet de recuperer la couleur associee
34   // au materiau defini par defaut.
35 //POP K4L
36   Col = aMat.AmbientColor ();
37 //  Col = aMat.Color ();
38   myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
39                                              Col,
40                                              Col,
41                                              Aspect_TOL_SOLID,
42                                              1.0,
43                                              aMat,
44                                              aMat);
45 }
46
47 Prs3d_ShadingAspect::Prs3d_ShadingAspect( const Handle( Graphic3d_AspectFillArea3d )& theAspect )
48 {
49   myAspect = theAspect;
50 }
51
52 //=======================================================================
53 //function : SetColor
54 //purpose  : 
55 //=======================================================================
56
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   if( aModel != Aspect_TOFM_BOTH_SIDE ) {
66     myAspect->SetDistinguishOn();
67   }
68   if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
69     Graphic3d_MaterialAspect front = myAspect->FrontMaterial();
70     front.SetColor(aColor);
71     myAspect->SetFrontMaterial(front);
72     myAspect->SetInteriorColor( aColor );
73   }
74
75   if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
76     Graphic3d_MaterialAspect back = myAspect->BackMaterial();
77     back.SetColor(aColor);
78     myAspect->SetBackMaterial(back);
79     myAspect->SetBackInteriorColor( aColor );
80   }
81 }
82
83 const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel theModel) const
84 {
85   switch (theModel)
86   {
87     default:
88     case Aspect_TOFM_BOTH_SIDE:
89     case Aspect_TOFM_FRONT_SIDE:
90       return myAspect->FrontMaterial().Color();
91     case Aspect_TOFM_BACK_SIDE:
92       return myAspect->BackMaterial().Color();
93   }
94 }
95
96 //=======================================================================
97 //function : SetMaterial
98 //purpose  : 
99 //=======================================================================
100
101 void Prs3d_ShadingAspect::SetMaterial(
102                    const Graphic3d_NameOfMaterial aMaterial,
103                          const Aspect_TypeOfFacingModel aModel ) {
104   SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel);
105 }
106
107 //=======================================================================
108 //function : SetMaterial
109 //purpose  : 
110 //=======================================================================
111
112 void Prs3d_ShadingAspect::SetMaterial(
113                    const Graphic3d_MaterialAspect& aMaterial,
114                          const Aspect_TypeOfFacingModel aModel ) {
115
116   if( aModel != Aspect_TOFM_BOTH_SIDE ) {
117     myAspect->SetDistinguishOn();
118   }
119   if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
120     myAspect->SetFrontMaterial(aMaterial);
121   }
122
123   if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
124     myAspect->SetBackMaterial(aMaterial);
125   }
126 }
127
128 const Graphic3d_MaterialAspect& Prs3d_ShadingAspect::Material (const Aspect_TypeOfFacingModel theModel) const
129 {
130   switch (theModel)
131   {
132     default:
133     case Aspect_TOFM_BOTH_SIDE:
134     case Aspect_TOFM_FRONT_SIDE:
135       return myAspect->FrontMaterial();
136     case Aspect_TOFM_BACK_SIDE:
137       return myAspect->BackMaterial();
138   }
139 }
140
141 //=======================================================================
142 //function : SetTransparency
143 //purpose  : 
144 //=======================================================================
145
146 void Prs3d_ShadingAspect::SetTransparency(const Standard_Real aValue,
147                                                       const Aspect_TypeOfFacingModel aModel ) {
148
149   if( aModel != Aspect_TOFM_BOTH_SIDE ) {
150     myAspect->SetDistinguishOn();
151   }
152   if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
153     Graphic3d_MaterialAspect front = myAspect->FrontMaterial();
154     front.SetTransparency(aValue);
155     myAspect->SetFrontMaterial(front);
156   }
157
158   if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
159     Graphic3d_MaterialAspect back = myAspect->BackMaterial();
160     back.SetTransparency(aValue);
161     myAspect->SetBackMaterial(back);
162   }
163 }
164
165 Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const {
166 Standard_Real aValue(0.);
167   switch (aModel) {
168     case Aspect_TOFM_BOTH_SIDE:
169     case Aspect_TOFM_FRONT_SIDE:
170         aValue = myAspect->FrontMaterial().Transparency();
171         break;
172     case Aspect_TOFM_BACK_SIDE:
173         aValue = myAspect->BackMaterial().Transparency();
174         break;
175   }
176   return aValue;
177 }
178
179 //=======================================================================
180 //function : SetAspect
181 //purpose  : 
182 //=======================================================================
183
184 void Prs3d_ShadingAspect::SetAspect( const Handle( Graphic3d_AspectFillArea3d )& theAspect )
185 {
186   myAspect = theAspect;
187 }
188
189 Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const {
190   return myAspect;
191 }