0025459: Visualization - AIS_ColoredShape::SetMaterial() should not reset custom...
[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
7fd59977 15#include <Prs3d_ShadingAspect.ixx>
16
17//=======================================================================
18//function : Prs3d_ShadingAspect
19//purpose :
20//=======================================================================
21
22Prs3d_ShadingAspect::Prs3d_ShadingAspect () {
23
24
25 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
26 Quantity_Color Col;
27 // Ceci permet de recuperer la couleur associee
28 // au materiau defini par defaut.
29//POP K4L
30 Col = aMat.AmbientColor ();
31// Col = aMat.Color ();
32 myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
33 Col,
34 Col,
35 Aspect_TOL_SOLID,
36 1.0,
37 aMat,
38 aMat);
39}
40
41
42//=======================================================================
43//function : SetColor
44//purpose :
45//=======================================================================
46
7fd59977 47void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor,
48 const Aspect_TypeOfFacingModel aModel) {
49
50 SetColor(Quantity_Color(aColor),aModel);
51}
52
53void Prs3d_ShadingAspect::SetColor(const Quantity_Color &aColor,
54 const Aspect_TypeOfFacingModel aModel) {
7fd59977 55 if( aModel != Aspect_TOFM_BOTH_SIDE ) {
56 myAspect->SetDistinguishOn();
57 }
58 if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
59 Graphic3d_MaterialAspect front = myAspect->FrontMaterial();
60 front.SetColor(aColor);
61 myAspect->SetFrontMaterial(front);
7fd59977 62 myAspect->SetInteriorColor( aColor );
7fd59977 63 }
64
65 if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
66 Graphic3d_MaterialAspect back = myAspect->BackMaterial();
67 back.SetColor(aColor);
68 myAspect->SetBackMaterial(back);
7fd59977 69 myAspect->SetBackInteriorColor( aColor );
7fd59977 70 }
71}
72
e0608a8d 73const 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:
e0608a8d 80 return myAspect->FrontMaterial().Color();
7fd59977 81 case Aspect_TOFM_BACK_SIDE:
e0608a8d 82 return myAspect->BackMaterial().Color();
7fd59977 83 }
7fd59977 84}
7fd59977 85
86//=======================================================================
87//function : SetMaterial
88//purpose :
89//=======================================================================
90
7fd59977 91void Prs3d_ShadingAspect::SetMaterial(
92 const Graphic3d_NameOfMaterial aMaterial,
93 const Aspect_TypeOfFacingModel aModel ) {
7fd59977 94 SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel);
95}
7fd59977 96
97//=======================================================================
98//function : SetMaterial
99//purpose :
100//=======================================================================
101
7fd59977 102void Prs3d_ShadingAspect::SetMaterial(
103 const Graphic3d_MaterialAspect& aMaterial,
104 const Aspect_TypeOfFacingModel aModel ) {
105
106 if( aModel != Aspect_TOFM_BOTH_SIDE ) {
107 myAspect->SetDistinguishOn();
108 }
109 if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
110 myAspect->SetFrontMaterial(aMaterial);
111 }
112
113 if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
114 myAspect->SetBackMaterial(aMaterial);
115 }
116}
117
e0608a8d 118const 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
133//purpose :
134//=======================================================================
135
7fd59977 136void Prs3d_ShadingAspect::SetTransparency(const Standard_Real aValue,
137 const Aspect_TypeOfFacingModel aModel ) {
138
139 if( aModel != Aspect_TOFM_BOTH_SIDE ) {
140 myAspect->SetDistinguishOn();
141 }
142 if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
143 Graphic3d_MaterialAspect front = myAspect->FrontMaterial();
144 front.SetTransparency(aValue);
145 myAspect->SetFrontMaterial(front);
146 }
147
148 if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
149 Graphic3d_MaterialAspect back = myAspect->BackMaterial();
150 back.SetTransparency(aValue);
151 myAspect->SetBackMaterial(back);
152 }
153}
154
155Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const {
156Standard_Real aValue(0.);
157 switch (aModel) {
158 case Aspect_TOFM_BOTH_SIDE:
159 case Aspect_TOFM_FRONT_SIDE:
160 aValue = myAspect->FrontMaterial().Transparency();
e2570917 161 break;
7fd59977 162 case Aspect_TOFM_BACK_SIDE:
163 aValue = myAspect->BackMaterial().Transparency();
e2570917 164 break;
7fd59977 165 }
166 return aValue;
167}
7fd59977 168
169//=======================================================================
170//function : SetAspect
171//purpose :
172//=======================================================================
173
174void Prs3d_ShadingAspect::SetAspect(const Handle(Graphic3d_AspectFillArea3d)& Asp)
175{
176 myAspect=Asp;
177}
178
179Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const {
180 return myAspect;
181}
182