fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Material / Base / OSGSwitchMaterial.cpp
blob85bedd5f1cee418ba30475536662a992d8be683d
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGSwitchMaterial.h"
50 OSG_USING_NAMESPACE
52 // Documentation for this class is emited in the
53 // OSGSwitchMaterialBase.cpp file.
54 // To modify it, please change the .fcd file (OSGSwitchMaterial.fcd) and
55 // regenerate the base file.
57 /***************************************************************************\
58 * Class variables *
59 \***************************************************************************/
61 /***************************************************************************\
62 * Class methods *
63 \***************************************************************************/
65 void SwitchMaterial::initMethod(InitPhase ePhase)
67 Inherited::initMethod(ePhase);
71 /***************************************************************************\
72 * Instance methods *
73 \***************************************************************************/
75 /*-------------------------------------------------------------------------*\
76 - private -
77 \*-------------------------------------------------------------------------*/
79 /*----------------------- constructors & destructors ----------------------*/
81 SwitchMaterial::SwitchMaterial(void) :
82 Inherited()
86 SwitchMaterial::SwitchMaterial(const SwitchMaterial &source) :
87 Inherited(source)
91 SwitchMaterial::~SwitchMaterial(void)
95 /*----------------------------- class specific ----------------------------*/
97 void SwitchMaterial::changed(ConstFieldMaskArg whichField,
98 UInt32 origin,
99 BitVector details)
101 Inherited::changed(whichField, origin, details);
104 void SwitchMaterial::addMaterial(Material *mat)
106 if(mat == NULL)
107 return;
109 pushToMaterials(mat);
112 void SwitchMaterial::subMaterial(Material *mat)
114 if(mat == NULL)
115 return;
117 removeObjFromMaterials(mat);
120 bool SwitchMaterial::hasMaterial(Material *mat) const
122 UInt32 i;
124 for(i = 0; i < _mfMaterials.size(); ++i)
126 if(_mfMaterials[i] == mat)
127 return true;
130 return false;
133 Material *SwitchMaterial::getMaterial(UInt32 index) const
135 if(index >= _mfMaterials.size())
137 FWARNING(("SwitchMaterial::getMaterial : index %u out of range\n",
138 index));
140 return NULL;
143 return _mfMaterials[index];
146 Material *SwitchMaterial::getCurrentMaterial(void) const
148 UInt32 choice = getChoice();
150 if(choice >= _mfMaterials.size())
152 FWARNING(("SwitchMaterial::getCurrentMaterial : current choice %u "
153 "out of range\n", choice));
155 return NULL;
157 return _mfMaterials[choice];
161 /*! Check if the Material (i.e. any of its materials) is transparent..
164 bool SwitchMaterial::isTransparent(void) const
166 UInt32 choice = getChoice();
168 if(choice >= _mfMaterials.size())
170 if(!_mfMaterials.empty())
172 SWARNING << "SwitchMaterial::isTransparent: choice index out "
173 << "of range!"
174 << std::endl;
177 return false;
180 if(_mfMaterials[choice] != NULL)
181 return _mfMaterials[choice]->isTransparent();
183 return false;
186 /*! Check if the Material (i.e. any of its materials) is transparent..
188 PrimeMaterial *SwitchMaterial::finalize( MaterialMapKey oKey,
189 const StateOverride *pOverrides,
190 Window *pWin )
192 UInt32 choice = getChoice();
194 if(choice >= _mfMaterials.size())
196 if(!_mfMaterials.empty())
198 SWARNING << "SwitchMaterial::finalize choice index out "
199 << "of range!"
200 << std::endl;
203 return NULL;
206 if(_mfMaterials[choice] != NULL)
207 return _mfMaterials[choice]->finalize(oKey, pOverrides, pWin);
209 return NULL;
212 void SwitchMaterial::dump( UInt32 ,
213 const BitVector ) const
215 SLOG << "Dump SwitchMaterial NI" << std::endl;