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 | // |
d5f74e42 |
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 |
973c2be1 |
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 | |
4e1bc39a |
15 | #include <Prs3d_ShadingAspect.hxx> |
42cf5bc1 |
16 | |
17 | #include <Graphic3d_AspectFillArea3d.hxx> |
18 | #include <Graphic3d_MaterialAspect.hxx> |
42cf5bc1 |
19 | #include <Quantity_Color.hxx> |
20 | #include <Standard_Type.hxx> |
0904aa63 |
21 | #include <Standard_Dump.hxx> |
7fd59977 |
22 | |
4e1bc39a |
23 | IMPLEMENT_STANDARD_RTTIEXT(Prs3d_ShadingAspect, Prs3d_BasicAspect) |
92efcf78 |
24 | |
7fd59977 |
25 | //======================================================================= |
26 | //function : Prs3d_ShadingAspect |
4e1bc39a |
27 | //purpose : |
7fd59977 |
28 | //======================================================================= |
4e1bc39a |
29 | Prs3d_ShadingAspect::Prs3d_ShadingAspect() |
30 | { |
31 | const Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS); |
32 | const Quantity_Color aColor = aMat.AmbientColor(); |
7fd59977 |
33 | myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, |
4e1bc39a |
34 | aColor, |
35 | aColor, |
7fd59977 |
36 | Aspect_TOL_SOLID, |
37 | 1.0, |
38 | aMat, |
39 | aMat); |
40 | } |
41 | |
7fd59977 |
42 | //======================================================================= |
43 | //function : SetColor |
4e1bc39a |
44 | //purpose : |
7fd59977 |
45 | //======================================================================= |
4e1bc39a |
46 | void Prs3d_ShadingAspect::SetColor (const Quantity_Color& theColor, |
47 | const Aspect_TypeOfFacingModel theModel) |
48 | { |
49 | if (theModel != Aspect_TOFM_BOTH_SIDE) |
50 | { |
7fd59977 |
51 | myAspect->SetDistinguishOn(); |
52 | } |
4e1bc39a |
53 | |
54 | if (theModel == Aspect_TOFM_FRONT_SIDE |
55 | || theModel == Aspect_TOFM_BOTH_SIDE) |
56 | { |
57 | myAspect->ChangeFrontMaterial().SetColor (theColor); |
58 | myAspect->SetInteriorColor (theColor); |
7fd59977 |
59 | } |
60 | |
4e1bc39a |
61 | if (theModel == Aspect_TOFM_BACK_SIDE |
62 | || theModel == Aspect_TOFM_BOTH_SIDE) |
63 | { |
64 | myAspect->ChangeBackMaterial().SetColor (theColor); |
65 | myAspect->SetBackInteriorColor (theColor); |
7fd59977 |
66 | } |
67 | } |
68 | |
4e1bc39a |
69 | //======================================================================= |
70 | //function : Color |
71 | //purpose : |
72 | //======================================================================= |
e0608a8d |
73 | const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel theModel) const |
74 | { |
75 | switch (theModel) |
76 | { |
7fd59977 |
77 | default: |
78 | case Aspect_TOFM_BOTH_SIDE: |
79 | case Aspect_TOFM_FRONT_SIDE: |
61168418 |
80 | return myAspect->FrontMaterial().MaterialType() == Graphic3d_MATERIAL_ASPECT |
81 | ? myAspect->InteriorColor() |
82 | : myAspect->FrontMaterial().Color(); |
7fd59977 |
83 | case Aspect_TOFM_BACK_SIDE: |
61168418 |
84 | return myAspect->BackMaterial().MaterialType() == Graphic3d_MATERIAL_ASPECT |
85 | ? myAspect->BackInteriorColor() |
86 | : myAspect->BackMaterial().Color(); |
7fd59977 |
87 | } |
7fd59977 |
88 | } |
7fd59977 |
89 | |
90 | //======================================================================= |
91 | //function : SetMaterial |
4e1bc39a |
92 | //purpose : |
7fd59977 |
93 | //======================================================================= |
4e1bc39a |
94 | void Prs3d_ShadingAspect::SetMaterial (const Graphic3d_MaterialAspect& theMaterial, |
95 | const Aspect_TypeOfFacingModel theModel) |
96 | { |
97 | if (theModel != Aspect_TOFM_BOTH_SIDE) |
98 | { |
7fd59977 |
99 | myAspect->SetDistinguishOn(); |
100 | } |
4e1bc39a |
101 | if (theModel == Aspect_TOFM_FRONT_SIDE |
102 | || theModel == Aspect_TOFM_BOTH_SIDE) |
103 | { |
104 | myAspect->SetFrontMaterial(theMaterial); |
7fd59977 |
105 | } |
106 | |
4e1bc39a |
107 | if (theModel == Aspect_TOFM_BACK_SIDE |
108 | || theModel == Aspect_TOFM_BOTH_SIDE) |
109 | { |
110 | myAspect->SetBackMaterial (theMaterial); |
7fd59977 |
111 | } |
112 | } |
113 | |
4e1bc39a |
114 | //======================================================================= |
115 | //function : Material |
116 | //purpose : |
117 | //======================================================================= |
e0608a8d |
118 | const Graphic3d_MaterialAspect& Prs3d_ShadingAspect::Material (const Aspect_TypeOfFacingModel theModel) const |
119 | { |
120 | switch (theModel) |
121 | { |
7fd59977 |
122 | default: |
123 | case Aspect_TOFM_BOTH_SIDE: |
124 | case Aspect_TOFM_FRONT_SIDE: |
e0608a8d |
125 | return myAspect->FrontMaterial(); |
7fd59977 |
126 | case Aspect_TOFM_BACK_SIDE: |
e0608a8d |
127 | return myAspect->BackMaterial(); |
7fd59977 |
128 | } |
7fd59977 |
129 | } |
7fd59977 |
130 | |
131 | //======================================================================= |
132 | //function : SetTransparency |
4e1bc39a |
133 | //purpose : |
7fd59977 |
134 | //======================================================================= |
4e1bc39a |
135 | void Prs3d_ShadingAspect::SetTransparency (const Standard_Real theValue, |
136 | const Aspect_TypeOfFacingModel theModel) |
137 | { |
138 | if (theModel != Aspect_TOFM_BOTH_SIDE) |
139 | { |
7fd59977 |
140 | myAspect->SetDistinguishOn(); |
141 | } |
7fd59977 |
142 | |
4e1bc39a |
143 | if (theModel == Aspect_TOFM_FRONT_SIDE |
144 | || theModel == Aspect_TOFM_BOTH_SIDE) |
145 | { |
146 | myAspect->ChangeFrontMaterial().SetTransparency (Standard_ShortReal(theValue)); |
7fd59977 |
147 | } |
7fd59977 |
148 | |
4e1bc39a |
149 | if (theModel == Aspect_TOFM_BACK_SIDE |
150 | || theModel == Aspect_TOFM_BOTH_SIDE) |
151 | { |
152 | myAspect->ChangeBackMaterial().SetTransparency (Standard_ShortReal(theValue)); |
7fd59977 |
153 | } |
7fd59977 |
154 | } |
7fd59977 |
155 | |
156 | //======================================================================= |
4e1bc39a |
157 | //function : Transparency |
158 | //purpose : |
7fd59977 |
159 | //======================================================================= |
4e1bc39a |
160 | Standard_Real Prs3d_ShadingAspect::Transparency (const Aspect_TypeOfFacingModel theModel) const |
7fd59977 |
161 | { |
4e1bc39a |
162 | switch (theModel) |
163 | { |
164 | case Aspect_TOFM_BOTH_SIDE: |
165 | case Aspect_TOFM_FRONT_SIDE: |
166 | return myAspect->FrontMaterial().Transparency(); |
167 | case Aspect_TOFM_BACK_SIDE: |
168 | return myAspect->BackMaterial().Transparency(); |
169 | } |
170 | return 0.0; |
7fd59977 |
171 | } |
0904aa63 |
172 | |
173 | // ======================================================================= |
174 | // function : DumpJson |
175 | // purpose : |
176 | // ======================================================================= |
177 | void Prs3d_ShadingAspect::DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth) const |
178 | { |
3de0f784 |
179 | OCCT_DUMP_CLASS_BEGIN (theOStream, Prs3d_ShadingAspect); |
180 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspect.get()); |
0904aa63 |
181 | } |
182 | |