1 |
|
5 |
//------------------------------------------------------------
|
2 |
|
|
//------------------------------------------------------------
|
3 |
|
|
// MAGiC
|
4 |
francois |
177 |
// Jean Christophe Cuilli�re et Vincent FRANCOIS
|
5 |
|
|
// D�partement de G�nie M�canique - UQTR
|
6 |
|
5 |
//------------------------------------------------------------
|
7 |
francois |
177 |
// Le projet MAGIC est un projet de recherche du d�partement
|
8 |
|
|
// de g�nie m�canique de l'Universit� du Qu�bec �
|
9 |
|
|
// Trois Rivi�res
|
10 |
|
|
// Les librairies ne peuvent �tre utilis�es sans l'accord
|
11 |
|
5 |
// des auteurs (contact : francois@uqtr.ca)
|
12 |
|
|
//------------------------------------------------------------
|
13 |
|
|
//------------------------------------------------------------
|
14 |
|
|
//
|
15 |
|
|
// mt_gestionnaire.cpp
|
16 |
|
|
//
|
17 |
|
|
//------------------------------------------------------------
|
18 |
|
|
//------------------------------------------------------------
|
19 |
|
|
// COPYRIGHT 2000
|
20 |
francois |
177 |
// Version du 02/03/2006 � 11H23
|
21 |
|
5 |
//------------------------------------------------------------
|
22 |
|
|
//------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "gestionversion.h"
|
26 |
|
|
|
27 |
|
|
#pragma hdrstop
|
28 |
|
|
|
29 |
|
|
#include "mt_gestionnaire.h"
|
30 |
|
|
#include "mt_materiau.h"
|
31 |
|
|
#include "parse.h"
|
32 |
|
|
#include "pars_argument.h"
|
33 |
francois |
177 |
#include <string.h>
|
34 |
|
5 |
//---------------------------------------------------------------------------
|
35 |
|
|
MT_GESTIONNAIRE::MT_GESTIONNAIRE(char* path)
|
36 |
|
|
{
|
37 |
|
|
chemin=path;
|
38 |
|
|
lire();
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
MT_GESTIONNAIRE::~MT_GESTIONNAIRE()
|
42 |
|
|
{
|
43 |
|
|
int nb=lst_mat.get_nb();
|
44 |
|
|
while (nb!=0)
|
45 |
|
|
{
|
46 |
|
|
MT_MATERIAU* mat=lst_mat.get(0);
|
47 |
|
|
lst_mat.supprimer(mat);
|
48 |
|
|
delete mat;
|
49 |
|
|
nb=lst_mat.get_nb();
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
class MT_MATERIAU* MT_GESTIONNAIRE::ajouter_materiau(std::string nom,std::string descrip)
|
54 |
|
|
{
|
55 |
|
|
MT_MATERIAU* mat=new MT_MATERIAU((char*)nom.c_str(),(char*)descrip.c_str());
|
56 |
|
|
lst_mat.ajouter(mat);
|
57 |
|
|
return mat;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
int MT_GESTIONNAIRE::get_nb_materiau()
|
61 |
|
|
{
|
62 |
|
|
return lst_mat.get_nb();
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
class MT_MATERIAU* MT_GESTIONNAIRE::get_materiau(int num)
|
66 |
|
|
{
|
67 |
|
|
return lst_mat.get(num);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
char* MT_GESTIONNAIRE::get_chemin()
|
71 |
|
|
{
|
72 |
|
|
return (char*)chemin.c_str();
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
void MT_GESTIONNAIRE::lire(void)
|
77 |
|
|
{
|
78 |
|
|
FILE *in=fopen(chemin.c_str(),"rt");
|
79 |
|
|
if (in==NULL) return ;
|
80 |
|
|
PARS_ARGUMENT param[20];
|
81 |
|
|
PARSE parse;
|
82 |
francois |
177 |
char motcle[255];
|
83 |
|
5 |
do
|
84 |
|
|
{
|
85 |
|
|
char mess[255];
|
86 |
|
|
fgets(mess,255,in);
|
87 |
|
|
std::string ligne=mess;
|
88 |
|
|
parse.decode(ligne.c_str(),"@\n",param);
|
89 |
francois |
177 |
sscanf(param[0].argument[0].c_str(),"%s",motcle);
|
90 |
|
|
if (strcmp(motcle,"END")!=0)
|
91 |
|
5 |
{
|
92 |
|
|
parse.decode(ligne.c_str(),"@:@\n",param);
|
93 |
francois |
177 |
sscanf(param[0].argument[0].c_str(),"%s",motcle);
|
94 |
|
|
if (strcmp(motcle,"MATL")==0)
|
95 |
|
|
{
|
96 |
|
5 |
parse.decode(ligne.c_str(),"@:@:@:@\n",param);
|
97 |
|
|
MT_MATERIAU* mate=ajouter_materiau(param[1].argument[0],param[3].argument[0].c_str());
|
98 |
|
|
do
|
99 |
|
|
{
|
100 |
|
|
char mess[255];
|
101 |
|
|
fgets(mess,255,in);
|
102 |
|
|
std::string ligne=mess;
|
103 |
|
|
parse.decode(ligne.c_str(),"@\n",param);
|
104 |
francois |
177 |
sscanf(param[0].argument[0].c_str(),"%s",motcle);
|
105 |
|
|
if (strcmp(motcle,"ENDMATL")!=0)
|
106 |
|
|
{
|
107 |
|
5 |
char nom[20],uni1[50],uni2[50],uni3[50];
|
108 |
|
|
double val1,val2,val3;
|
109 |
|
|
int nb=sscanf(ligne.c_str(),"%s %lf %s %lf %s %lf %s",nom,&val1,uni1,&val2,uni2,&val3,uni3);
|
110 |
|
|
if (nb==7)
|
111 |
|
|
mate->ajouter_propriete(nom,val1,uni1,val2,uni2,val3,uni3);
|
112 |
|
|
else
|
113 |
|
|
{
|
114 |
|
|
sscanf(ligne.c_str(),"%s %lf %lf %lf",nom,&val1,&val2,&val3);
|
115 |
|
|
mate->ajouter_propriete(nom,val1,"",val2,"",val3,"");
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
}
|
119 |
francois |
177 |
sscanf(param[0].argument[0].c_str(),"%s",motcle);
|
120 |
|
|
}
|
121 |
|
|
while (strcmp(motcle,"ENDMATL")!=0);
|
122 |
|
5 |
}
|
123 |
|
|
}
|
124 |
francois |
177 |
sscanf(param[0].argument[0].c_str(),"%s",motcle);
|
125 |
|
|
}
|
126 |
|
|
while (strcmp(motcle,"END")!=0);
|
127 |
|
5 |
fclose(in);
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
|