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