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.
15 #include <Prs3d_ShadingAspect.hxx>
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>
23 IMPLEMENT_STANDARD_RTTIEXT(Prs3d_ShadingAspect, Prs3d_BasicAspect)
25 //=======================================================================
26 //function : Prs3d_ShadingAspect
28 //=======================================================================
29 Prs3d_ShadingAspect::Prs3d_ShadingAspect()
31 const Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
32 const Quantity_Color aColor = aMat.AmbientColor();
33 myAspect = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
42 //=======================================================================
45 //=======================================================================
46 void Prs3d_ShadingAspect::SetColor (const Quantity_Color& theColor,
47 const Aspect_TypeOfFacingModel theModel)
49 if (theModel != Aspect_TOFM_BOTH_SIDE)
51 myAspect->SetDistinguishOn();
54 if (theModel == Aspect_TOFM_FRONT_SIDE
55 || theModel == Aspect_TOFM_BOTH_SIDE)
57 myAspect->ChangeFrontMaterial().SetColor (theColor);
58 myAspect->SetInteriorColor (theColor);
61 if (theModel == Aspect_TOFM_BACK_SIDE
62 || theModel == Aspect_TOFM_BOTH_SIDE)
64 myAspect->ChangeBackMaterial().SetColor (theColor);
65 myAspect->SetBackInteriorColor (theColor);
69 //=======================================================================
72 //=======================================================================
73 const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel theModel) const
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();
90 //=======================================================================
91 //function : SetMaterial
93 //=======================================================================
94 void Prs3d_ShadingAspect::SetMaterial (const Graphic3d_MaterialAspect& theMaterial,
95 const Aspect_TypeOfFacingModel theModel)
97 if (theModel != Aspect_TOFM_BOTH_SIDE)
99 myAspect->SetDistinguishOn();
101 if (theModel == Aspect_TOFM_FRONT_SIDE
102 || theModel == Aspect_TOFM_BOTH_SIDE)
104 myAspect->SetFrontMaterial(theMaterial);
107 if (theModel == Aspect_TOFM_BACK_SIDE
108 || theModel == Aspect_TOFM_BOTH_SIDE)
110 myAspect->SetBackMaterial (theMaterial);
114 //=======================================================================
115 //function : Material
117 //=======================================================================
118 const Graphic3d_MaterialAspect& Prs3d_ShadingAspect::Material (const Aspect_TypeOfFacingModel theModel) const
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();
131 //=======================================================================
132 //function : SetTransparency
134 //=======================================================================
135 void Prs3d_ShadingAspect::SetTransparency (const Standard_Real theValue,
136 const Aspect_TypeOfFacingModel theModel)
138 if (theModel != Aspect_TOFM_BOTH_SIDE)
140 myAspect->SetDistinguishOn();
143 if (theModel == Aspect_TOFM_FRONT_SIDE
144 || theModel == Aspect_TOFM_BOTH_SIDE)
146 myAspect->ChangeFrontMaterial().SetTransparency (Standard_ShortReal(theValue));
149 if (theModel == Aspect_TOFM_BACK_SIDE
150 || theModel == Aspect_TOFM_BOTH_SIDE)
152 myAspect->ChangeBackMaterial().SetTransparency (Standard_ShortReal(theValue));
156 //=======================================================================
157 //function : Transparency
159 //=======================================================================
160 Standard_Real Prs3d_ShadingAspect::Transparency (const Aspect_TypeOfFacingModel theModel) const
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();
173 // =======================================================================
174 // function : DumpJson
176 // =======================================================================
177 void Prs3d_ShadingAspect::DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth) const
179 DUMP_CLASS_BEGIN (theOStream, Prs3d_ShadingAspect);
180 DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspect.get());