summaryrefslogtreecommitdiff
path: root/src/Prs3d/Prs3d_ShadingAspect.cxx
blob: 7cef5edc143c1de056ffffb7b4024e54066d5781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

#define BUC60488	//GG_23/09/99 Updates correctly the Material after
//			any change.

#define GER61351		//GG_171199     Enable to set an object RGB color
//						  instead a restricted object NameOfColor.
//				Enable to change separatly the front and back color.

#define OCC1174 //SAV_080103 Added back face interior color management

#include <Prs3d_ShadingAspect.ixx>

//=======================================================================
//function : Prs3d_ShadingAspect
//purpose  : 
//=======================================================================

Prs3d_ShadingAspect::Prs3d_ShadingAspect () {


  Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
  Quantity_Color Col;
  // Ceci permet de recuperer la couleur associee
  // au materiau defini par defaut.
//POP K4L
  Col = aMat.AmbientColor ();
//  Col = aMat.Color ();
  myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
					     Col,
					     Col,
					     Aspect_TOL_SOLID,
					     1.0,
					     aMat,
					     aMat);
}


//=======================================================================
//function : SetColor
//purpose  : 
//=======================================================================

#ifdef GER61351
void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor,
					     const Aspect_TypeOfFacingModel aModel) {

  SetColor(Quantity_Color(aColor),aModel);
}

void Prs3d_ShadingAspect::SetColor(const Quantity_Color &aColor,
					     const Aspect_TypeOfFacingModel aModel) {
#ifndef OCC1174  
  myAspect->SetInteriorColor(aColor);
#endif

  if( aModel != Aspect_TOFM_BOTH_SIDE ) {
    myAspect->SetDistinguishOn();
  }
  if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
    Graphic3d_MaterialAspect front = myAspect->FrontMaterial();
    front.SetColor(aColor);
    myAspect->SetFrontMaterial(front);
#ifdef OCC1174
    myAspect->SetInteriorColor( aColor );
#endif
  }

  if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
    Graphic3d_MaterialAspect back = myAspect->BackMaterial();
    back.SetColor(aColor);
    myAspect->SetBackMaterial(back);
#ifdef OCC1174
    myAspect->SetBackInteriorColor( aColor );
#endif
  }
}

Quantity_Color Prs3d_ShadingAspect::Color( const Aspect_TypeOfFacingModel aModel ) const {
  Quantity_Color myReturn ;
  switch (aModel) {
    default:
    case Aspect_TOFM_BOTH_SIDE:
    case Aspect_TOFM_FRONT_SIDE:
	myReturn = myAspect->FrontMaterial().Color();
	break;
    case Aspect_TOFM_BACK_SIDE:
	myReturn = myAspect->BackMaterial().Color();
	break;
  }
  return myReturn ;
}
#else
void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor) {
  myAspect->SetInteriorColor(aColor);
#ifdef OCC1174
  myAspect->SetBackInteriorColor( aColor );
#endif
  myAspect->FrontMaterial().SetAmbientColor(Quantity_Color(aColor));
  myAspect->BackMaterial().SetAmbientColor(Quantity_Color(aColor));
//  myAspect->FrontMaterial().SetColor(Quantity_Color(aColor));
//  myAspect->BackMaterial().SetColor(Quantity_Color(aColor));
}
#endif	

//=======================================================================
//function : SetMaterial
//purpose  : 
//=======================================================================

#ifdef GER61351
void Prs3d_ShadingAspect::SetMaterial(
                   const Graphic3d_NameOfMaterial aMaterial,
			 const Aspect_TypeOfFacingModel aModel ) {

  SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel);
}
#else
void Prs3d_ShadingAspect::SetMaterial(
//                 const Graphic3d_NameOfPhysicalMaterial aMaterial) {
                 const Graphic3d_NameOfMaterial aMaterial) {

  Graphic3d_MaterialAspect TheMaterial(aMaterial);
  myAspect->SetFrontMaterial (TheMaterial);
  myAspect->SetBackMaterial (TheMaterial);
}
#endif

//=======================================================================
//function : SetMaterial
//purpose  : 
//=======================================================================

#ifdef GER61351
void Prs3d_ShadingAspect::SetMaterial(
                   const Graphic3d_MaterialAspect& aMaterial,
			 const Aspect_TypeOfFacingModel aModel ) {

  if( aModel != Aspect_TOFM_BOTH_SIDE ) {
    myAspect->SetDistinguishOn();
  }
  if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
    myAspect->SetFrontMaterial(aMaterial);
  }

  if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
    myAspect->SetBackMaterial(aMaterial);
  }
}

Graphic3d_MaterialAspect  Prs3d_ShadingAspect::Material(
			 const Aspect_TypeOfFacingModel aModel ) const {
  Graphic3d_MaterialAspect myReturn ;		   
  switch (aModel) {
    default:
    case Aspect_TOFM_BOTH_SIDE:
    case Aspect_TOFM_FRONT_SIDE:
	myReturn = myAspect->FrontMaterial();
	break;
    case Aspect_TOFM_BACK_SIDE:
	myReturn = myAspect->BackMaterial();
	break;
  }
 return myReturn ;  
} 
#else
void Prs3d_ShadingAspect::SetMaterial(
                 const Graphic3d_MaterialAspect&  aMaterial) 
{
  myAspect->SetFrontMaterial (aMaterial);
  myAspect->SetBackMaterial (aMaterial);
}
#endif

//=======================================================================
//function : SetTransparency
//purpose  : 
//=======================================================================

#ifdef GER61351
void Prs3d_ShadingAspect::SetTransparency(const Standard_Real aValue,
						      const Aspect_TypeOfFacingModel aModel ) {

  if( aModel != Aspect_TOFM_BOTH_SIDE ) {
    myAspect->SetDistinguishOn();
  }
  if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
    Graphic3d_MaterialAspect front = myAspect->FrontMaterial();
    front.SetTransparency(aValue);
    myAspect->SetFrontMaterial(front);
  }

  if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
    Graphic3d_MaterialAspect back = myAspect->BackMaterial();
    back.SetTransparency(aValue);
    myAspect->SetBackMaterial(back);
  }
}

Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const {
Standard_Real aValue(0.);
  switch (aModel) {
    case Aspect_TOFM_BOTH_SIDE:
    case Aspect_TOFM_FRONT_SIDE:
	aValue = myAspect->FrontMaterial().Transparency();
    case Aspect_TOFM_BACK_SIDE:
	aValue = myAspect->BackMaterial().Transparency();
  }
  return aValue;
}
#endif

//=======================================================================
//function : SetAspect
//purpose  : 
//=======================================================================

void Prs3d_ShadingAspect::SetAspect(const Handle(Graphic3d_AspectFillArea3d)& Asp)
{
  myAspect=Asp;
}

Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const {
  return myAspect;
}