| 1 | // Copyright (c) 1995-1999 Matra Datavision |
| 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 3 | // |
| 4 | // This file is part of Open CASCADE Technology software library. |
| 5 | // |
| 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. |
| 11 | // |
| 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 13 | // commercial license or contractual agreement. |
| 14 | |
| 15 | #include <Prs3d_ShadingAspect.ixx> |
| 16 | |
| 17 | //======================================================================= |
| 18 | //function : Prs3d_ShadingAspect |
| 19 | //purpose : |
| 20 | //======================================================================= |
| 21 | |
| 22 | Prs3d_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 | |
| 47 | void Prs3d_ShadingAspect::SetColor(const Quantity_NameOfColor aColor, |
| 48 | const Aspect_TypeOfFacingModel aModel) { |
| 49 | |
| 50 | SetColor(Quantity_Color(aColor),aModel); |
| 51 | } |
| 52 | |
| 53 | void Prs3d_ShadingAspect::SetColor(const Quantity_Color &aColor, |
| 54 | const Aspect_TypeOfFacingModel aModel) { |
| 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); |
| 62 | myAspect->SetInteriorColor( aColor ); |
| 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); |
| 69 | myAspect->SetBackInteriorColor( aColor ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | const Quantity_Color& Prs3d_ShadingAspect::Color (const Aspect_TypeOfFacingModel theModel) const |
| 74 | { |
| 75 | switch (theModel) |
| 76 | { |
| 77 | default: |
| 78 | case Aspect_TOFM_BOTH_SIDE: |
| 79 | case Aspect_TOFM_FRONT_SIDE: |
| 80 | return myAspect->FrontMaterial().Color(); |
| 81 | case Aspect_TOFM_BACK_SIDE: |
| 82 | return myAspect->BackMaterial().Color(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | //======================================================================= |
| 87 | //function : SetMaterial |
| 88 | //purpose : |
| 89 | //======================================================================= |
| 90 | |
| 91 | void Prs3d_ShadingAspect::SetMaterial( |
| 92 | const Graphic3d_NameOfMaterial aMaterial, |
| 93 | const Aspect_TypeOfFacingModel aModel ) { |
| 94 | SetMaterial(Graphic3d_MaterialAspect(aMaterial),aModel); |
| 95 | } |
| 96 | |
| 97 | //======================================================================= |
| 98 | //function : SetMaterial |
| 99 | //purpose : |
| 100 | //======================================================================= |
| 101 | |
| 102 | void 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 | |
| 118 | const Graphic3d_MaterialAspect& Prs3d_ShadingAspect::Material (const Aspect_TypeOfFacingModel theModel) const |
| 119 | { |
| 120 | switch (theModel) |
| 121 | { |
| 122 | default: |
| 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(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | //======================================================================= |
| 132 | //function : SetTransparency |
| 133 | //purpose : |
| 134 | //======================================================================= |
| 135 | |
| 136 | void 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 | |
| 155 | Standard_Real Prs3d_ShadingAspect::Transparency(const Aspect_TypeOfFacingModel aModel ) const { |
| 156 | Standard_Real aValue(0.); |
| 157 | switch (aModel) { |
| 158 | case Aspect_TOFM_BOTH_SIDE: |
| 159 | case Aspect_TOFM_FRONT_SIDE: |
| 160 | aValue = myAspect->FrontMaterial().Transparency(); |
| 161 | break; |
| 162 | case Aspect_TOFM_BACK_SIDE: |
| 163 | aValue = myAspect->BackMaterial().Transparency(); |
| 164 | break; |
| 165 | } |
| 166 | return aValue; |
| 167 | } |
| 168 | |
| 169 | //======================================================================= |
| 170 | //function : SetAspect |
| 171 | //purpose : |
| 172 | //======================================================================= |
| 173 | |
| 174 | void Prs3d_ShadingAspect::SetAspect(const Handle(Graphic3d_AspectFillArea3d)& Asp) |
| 175 | { |
| 176 | myAspect=Asp; |
| 177 | } |
| 178 | |
| 179 | Handle (Graphic3d_AspectFillArea3d) Prs3d_ShadingAspect::Aspect () const { |
| 180 | return myAspect; |
| 181 | } |
| 182 | |