0025180: Visualization - Homogeneous transformation API in TKV3d
[occt.git] / src / Prs3d / Prs3d_ShadingAspect.cxx
CommitLineData
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
42cf5bc1 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>
7fd59977 21
92efcf78 22IMPLEMENT_STANDARD_RTTIEXT(Prs3d_ShadingAspect,Prs3d_BasicAspect)
23
7fd59977 24//=======================================================================
25//function : Prs3d_ShadingAspect
26//purpose :
27//=======================================================================
7fd59977 28Prs3d_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
1a75746e 47Prs3d_ShadingAspect::Prs3d_ShadingAspect( const Handle( Graphic3d_AspectFillArea3d )& theAspect )
48{
49 myAspect = theAspect;
50}
7fd59977 51
52//=======================================================================
53//function : SetColor
54//purpose :
55//=======================================================================
56
7fd59977 57void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor,
58 const Aspect_TypeOfFacingModel aModel) {
59
60 SetColor(Quantity_Color(aColor),aModel);
61}
62
63void Prs3d_ShadingAspect::SetColor(const Quantity_Color &aColor,
64 const Aspect_TypeOfFacingModel aModel) {
7fd59977 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);
7fd59977 72 myAspect->SetInteriorColor( aColor );
7fd59977 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);
7fd59977 79 myAspect->SetBackInteriorColor( aColor );
7fd59977 80 }
81}
82
e0608a8d 83const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel theModel) const
84{
85 switch (theModel)
86 {
7fd59977 87 default:
88 case Aspect_TOFM_BOTH_SIDE:
89 case Aspect_TOFM_FRONT_SIDE:
e0608a8d 90 return myAspect->FrontMaterial().Color();
7fd59977 91 case Aspect_TOFM_BACK_SIDE:
e0608a8d 92 return myAspect->BackMaterial().Color();
7fd59977 93 }
7fd59977 94}
7fd59977 95
96//=======================================================================
97//function : SetMaterial
98//purpose :
99//=======================================================================
100
7fd59977 101void Prs3d_ShadingAspect::SetMaterial(
102 const Graphic3d_NameOfMaterial aMaterial,
103 const Aspect_TypeOfFacingModel aModel ) {
7fd59977 104 SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel);
105}
7fd59977 106
107//=======================================================================
108//function : SetMaterial
109//purpose :
110//=======================================================================
111
7fd59977 112void 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
e0608a8d 128const Graphic3d_MaterialAspect& Prs3d_ShadingAspect::Material (const Aspect_TypeOfFacingModel theModel) const
129{
130 switch (theModel)
131 {
7fd59977 132 default:
133 case Aspect_TOFM_BOTH_SIDE:
134 case Aspect_TOFM_FRONT_SIDE:
e0608a8d 135 return myAspect->FrontMaterial();
7fd59977 136 case Aspect_TOFM_BACK_SIDE:
e0608a8d 137 return myAspect->BackMaterial();
7fd59977 138 }
7fd59977 139}
7fd59977 140
141//=======================================================================
142//function : SetTransparency
143//purpose :
144//=======================================================================
145
7fd59977 146void 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
165Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const {
166Standard_Real aValue(0.);
167 switch (aModel) {
168 case Aspect_TOFM_BOTH_SIDE:
169 case Aspect_TOFM_FRONT_SIDE:
170 aValue = myAspect->FrontMaterial().Transparency();
e2570917 171 break;
7fd59977 172 case Aspect_TOFM_BACK_SIDE:
173 aValue = myAspect->BackMaterial().Transparency();
e2570917 174 break;
7fd59977 175 }
176 return aValue;
177}
7fd59977 178
179//=======================================================================
180//function : SetAspect
181//purpose :
182//=======================================================================
183
1a75746e 184void Prs3d_ShadingAspect::SetAspect( const Handle( Graphic3d_AspectFillArea3d )& theAspect )
7fd59977 185{
1a75746e 186 myAspect = theAspect;
7fd59977 187}
188
189Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const {
190 return myAspect;
191}