1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
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>
22 IMPLEMENT_STANDARD_RTTIEXT(Prs3d_ShadingAspect,Prs3d_BasicAspect)
24 //=======================================================================
25 //function : Prs3d_ShadingAspect
27 //=======================================================================
28 Prs3d_ShadingAspect::Prs3d_ShadingAspect () {
31 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
33 // Ceci permet de recuperer la couleur associee
34 // au materiau defini par defaut.
36 Col = aMat.AmbientColor ();
37 // Col = aMat.Color ();
38 myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
47 Prs3d_ShadingAspect::Prs3d_ShadingAspect( const Handle( Graphic3d_AspectFillArea3d )& theAspect )
52 //=======================================================================
55 //=======================================================================
57 void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor,
58 const Aspect_TypeOfFacingModel aModel) {
60 SetColor(Quantity_Color(aColor),aModel);
63 void Prs3d_ShadingAspect::SetColor(const Quantity_Color &aColor,
64 const Aspect_TypeOfFacingModel aModel) {
65 if( aModel != Aspect_TOFM_BOTH_SIDE ) {
66 myAspect->SetDistinguishOn();
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);
72 myAspect->SetInteriorColor( aColor );
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);
79 myAspect->SetBackInteriorColor( aColor );
83 const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel theModel) const
88 case Aspect_TOFM_BOTH_SIDE:
89 case Aspect_TOFM_FRONT_SIDE:
90 return myAspect->FrontMaterial().Color();
91 case Aspect_TOFM_BACK_SIDE:
92 return myAspect->BackMaterial().Color();
96 //=======================================================================
97 //function : SetMaterial
99 //=======================================================================
101 void Prs3d_ShadingAspect::SetMaterial(
102 const Graphic3d_NameOfMaterial aMaterial,
103 const Aspect_TypeOfFacingModel aModel ) {
104 SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel);
107 //=======================================================================
108 //function : SetMaterial
110 //=======================================================================
112 void Prs3d_ShadingAspect::SetMaterial(
113 const Graphic3d_MaterialAspect& aMaterial,
114 const Aspect_TypeOfFacingModel aModel ) {
116 if( aModel != Aspect_TOFM_BOTH_SIDE ) {
117 myAspect->SetDistinguishOn();
119 if( aModel == Aspect_TOFM_FRONT_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
120 myAspect->SetFrontMaterial(aMaterial);
123 if( aModel == Aspect_TOFM_BACK_SIDE || aModel == Aspect_TOFM_BOTH_SIDE ) {
124 myAspect->SetBackMaterial(aMaterial);
128 const Graphic3d_MaterialAspect& Prs3d_ShadingAspect::Material (const Aspect_TypeOfFacingModel theModel) const
133 case Aspect_TOFM_BOTH_SIDE:
134 case Aspect_TOFM_FRONT_SIDE:
135 return myAspect->FrontMaterial();
136 case Aspect_TOFM_BACK_SIDE:
137 return myAspect->BackMaterial();
141 //=======================================================================
142 //function : SetTransparency
144 //=======================================================================
146 void Prs3d_ShadingAspect::SetTransparency(const Standard_Real aValue,
147 const Aspect_TypeOfFacingModel aModel ) {
149 if( aModel != Aspect_TOFM_BOTH_SIDE ) {
150 myAspect->SetDistinguishOn();
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);
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);
165 Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const {
166 Standard_Real aValue(0.);
168 case Aspect_TOFM_BOTH_SIDE:
169 case Aspect_TOFM_FRONT_SIDE:
170 aValue = myAspect->FrontMaterial().Transparency();
172 case Aspect_TOFM_BACK_SIDE:
173 aValue = myAspect->BackMaterial().Transparency();
179 //=======================================================================
180 //function : SetAspect
182 //=======================================================================
184 void Prs3d_ShadingAspect::SetAspect( const Handle( Graphic3d_AspectFillArea3d )& theAspect )
186 myAspect = theAspect;
189 Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const {