Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Material.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #include "Material.h"
17 
19 {
20  for (std::map<unsigned int, Material*>::iterator it = materials.begin(); it != materials.end(); it++)
21  {
22  delete it->second;
23  }
24 }
25 
27 {
28 
29  // Donne un nouveau nom si celui ci n'est pas renseigne
30  if (m->getName().empty())
31  {
32  std::ostringstream num;
33  num << counterKey;
34  m->setName("Material " + num.str());
35  }
36 
37  m->id = counterKey;
38 
39  materials.insert(std::pair<unsigned int, Material*>(counterKey, m));
40 
41  unsigned int result = counterKey;
42  counterKey++;
43 
44  return result;
45 }
46 
48 {
49  // std::cout << "Description de la table des materiaux." << std::endl;
50  unsigned int compteur = 0;
51  for (std::map<unsigned int, Material*>::iterator it = materials.begin(); it != materials.end(); it++)
52  {
53  // std::cout << "Materiau " << compteur << " : " << it->second->getName() << std::endl;
54  // #ifdef USE_QT
55  // std::cout<<"Couleur :
56  // ("<<it->second->r<<","<<it->second->g<<","<<it->second->b<<")"<<std::endl;
57  // #endif
58  compteur++;
59  }
60 }
61 
63 {
64  std::map<unsigned int, Material*>::iterator it = materials.find(key);
65  if (it != materials.end())
66  {
67  return it->second;
68  }
69  else
70  {
71  return NULL;
72  }
73 }
void setName(const std::string &_name)
Set the name of the object.
Definition: Base.h:46
std::string getName()
Get the name of the object.
Definition: Base.h:41
unsigned int counterKey
Counter of materials into the list.
Definition: Material.h:85
~MaterialManager()
Destructor.
Definition: Material.cpp:18
Material * requestMaterial(unsigned int key)
Return a material from the list by its index.
Definition: Material.cpp:62
void print()
Print the materials list.
Definition: Material.cpp:47
std::map< unsigned int, Material * > materials
Pointer list to materials.
Definition: Material.h:84
unsigned int registerNewMaterial(Material *m)
Register a new material into the list.
Definition: Material.cpp:26
unsigned int id
Identification set by the MaterialManager.
Definition: Material.h:55