1 |
|
5 |
//------------------------------------------------------------
|
2 |
|
|
//------------------------------------------------------------
|
3 |
|
|
// MAGiC
|
4 |
|
|
// Jean Christophe Cuillière et Vincent FRANCOIS
|
5 |
|
|
// Département de Génie Mécanique - UQTR
|
6 |
|
|
//------------------------------------------------------------
|
7 |
|
|
// 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 |
|
|
// des auteurs (contact : francois@uqtr.ca)
|
12 |
|
|
//------------------------------------------------------------
|
13 |
|
|
//------------------------------------------------------------
|
14 |
|
|
//
|
15 |
|
|
// expwin.cpp
|
16 |
|
|
//
|
17 |
|
|
//------------------------------------------------------------
|
18 |
|
|
//------------------------------------------------------------
|
19 |
|
|
// COPYRIGHT 2000
|
20 |
|
|
// Version du 02/03/2006 à 11H26
|
21 |
|
|
//------------------------------------------------------------
|
22 |
|
|
//------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "gestionversion.h"
|
26 |
|
|
|
27 |
|
|
#include <vcl.h>
|
28 |
|
|
#include <io.h>
|
29 |
|
|
#include "parse.h"
|
30 |
|
|
#include "pars_argument.h"
|
31 |
|
|
#pragma hdrstop
|
32 |
|
|
|
33 |
|
|
#include "expwin.h"
|
34 |
|
|
#include "mg_file_ref.h"
|
35 |
|
|
//---------------------------------------------------------------------------
|
36 |
|
|
#pragma package(smart_init)
|
37 |
|
|
#pragma resource "*.dfm"
|
38 |
|
|
Texpwinf *expwinf;
|
39 |
|
|
//---------------------------------------------------------------------------
|
40 |
|
|
__fastcall Texpwinf::Texpwinf(TComponent* Owner)
|
41 |
|
|
: TForm(Owner)
|
42 |
|
|
{
|
43 |
|
|
}
|
44 |
|
|
//---------------------------------------------------------------------------
|
45 |
|
|
void __fastcall Texpwinf::Button1Click(TObject *Sender)
|
46 |
|
|
{
|
47 |
|
|
Close();
|
48 |
|
|
}
|
49 |
|
|
//---------------------------------------------------------------------------
|
50 |
|
|
void __fastcall Texpwinf::FormClose(TObject *Sender, TCloseAction &Action)
|
51 |
|
|
{
|
52 |
|
|
Action=caFree;
|
53 |
|
|
}
|
54 |
|
|
//---------------------------------------------------------------------------
|
55 |
|
|
void __fastcall Texpwinf::FileListBox1Change(TObject *Sender)
|
56 |
|
|
{
|
57 |
|
|
if (FilterComboBox1->Text!="MAGIC") return;
|
58 |
|
|
Label2->Caption=FileListBox1->FileName;
|
59 |
|
|
Cursor=crHourGlass;
|
60 |
|
|
FileListBox1->Cursor=crHourGlass;
|
61 |
|
|
DriveComboBox1->Cursor=crHourGlass;
|
62 |
|
|
DirectoryListBox1->Cursor=crHourGlass;
|
63 |
|
|
FilterComboBox1->Cursor=crHourGlass;
|
64 |
|
|
ListBox1->Clear();
|
65 |
|
|
Application->ProcessMessages();
|
66 |
|
|
MG_FILE_REF fich(FileListBox1->FileName.c_str());
|
67 |
|
|
int nb_ref=fich.get_liste_reference()->get_nb();
|
68 |
|
|
for (int i=0;i<nb_ref;i++)
|
69 |
|
|
ListBox1->Items->Add(fich.get_liste_reference()->get(i).c_str());
|
70 |
|
|
Cursor=crDefault;
|
71 |
|
|
FileListBox1->Cursor=crDefault;
|
72 |
|
|
DriveComboBox1->Cursor=crDefault;
|
73 |
|
|
DirectoryListBox1->Cursor=crDefault;
|
74 |
|
|
FilterComboBox1->Cursor=crDefault;
|
75 |
|
|
Application->ProcessMessages();
|
76 |
|
|
if (Label2->Caption!="") Button2->Visible=true;
|
77 |
|
|
}
|
78 |
|
|
//---------------------------------------------------------------------------
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
void __fastcall Texpwinf::Button2Click(TObject *Sender)
|
82 |
|
|
{
|
83 |
|
|
long nb_reference=ListBox1->Items->Count;
|
84 |
|
|
char mess[1500];
|
85 |
|
|
strcpy(mess,Label2->Caption.c_str());
|
86 |
|
|
strcat(mess,".cmp");
|
87 |
|
|
FILE *out=fopen(mess,"wb");
|
88 |
|
|
fwrite(&nb_reference,sizeof(long),1,out);
|
89 |
|
|
strcpy(mess,Label2->Caption.c_str());
|
90 |
|
|
long taille=strlen(mess)*sizeof(char);
|
91 |
|
|
fwrite(&taille,sizeof(long),1,out);
|
92 |
|
|
fwrite(mess,taille,1,out);
|
93 |
|
|
for (int i=0;i<nb_reference;i++)
|
94 |
|
|
{
|
95 |
|
|
strcpy(mess,ListBox1->Items->Strings[i].c_str());
|
96 |
|
|
taille=strlen(mess)*sizeof(char);
|
97 |
|
|
fwrite(&taille,sizeof(long),1,out);
|
98 |
|
|
fwrite(mess,taille,1,out);
|
99 |
|
|
}
|
100 |
|
|
strcpy(mess,Label2->Caption.c_str());
|
101 |
|
|
FILE *in=fopen(mess,"rb");
|
102 |
|
|
taille=filelength(fileno(in));
|
103 |
|
|
fwrite(&taille,sizeof(long),1,out);
|
104 |
|
|
void *ptr=malloc(taille);
|
105 |
|
|
fread(ptr,taille,1,in);
|
106 |
|
|
fwrite(ptr,taille,1,out);
|
107 |
|
|
free(ptr);
|
108 |
|
|
fclose(in);
|
109 |
|
|
for (int i=0;i<nb_reference;i++)
|
110 |
|
|
{
|
111 |
|
|
strcpy(mess,ListBox1->Items->Strings[i].c_str());
|
112 |
|
|
FILE *in=fopen(mess,"rb");
|
113 |
|
|
taille=filelength(fileno(in));
|
114 |
|
|
fwrite(&taille,sizeof(long),1,out);
|
115 |
|
|
void *ptr=malloc(taille);
|
116 |
|
|
fread(ptr,taille,1,in);
|
117 |
|
|
fwrite(ptr,taille,1,out);
|
118 |
|
|
free(ptr);
|
119 |
|
|
fclose(in);
|
120 |
|
|
}
|
121 |
|
|
fclose(out);
|
122 |
|
|
}
|
123 |
|
|
//---------------------------------------------------------------------------
|
124 |
|
|
|
125 |
|
|
void __fastcall Texpwinf::Button3Click(TObject *Sender)
|
126 |
|
|
{
|
127 |
|
|
if (OpenDialog1->Execute())
|
128 |
|
|
{
|
129 |
|
|
char mess[1500];
|
130 |
|
|
strcpy(mess,OpenDialog1->FileName.c_str());
|
131 |
|
|
FILE *in=fopen(mess,"rb");
|
132 |
|
|
long nb_reference;
|
133 |
|
|
fread(&nb_reference,sizeof(long),1,in);
|
134 |
|
|
ListBox2->Clear();
|
135 |
|
|
for (int i=0;i<nb_reference+1;i++)
|
136 |
|
|
{
|
137 |
|
|
long taille;
|
138 |
|
|
fread(&taille,sizeof(long),1,in);
|
139 |
|
|
char mess[1500];
|
140 |
|
|
fread(mess,taille,1,in);
|
141 |
|
|
mess[taille]=0;
|
142 |
|
|
ListBox2->Items->Add(mess);
|
143 |
|
|
}
|
144 |
|
|
for (int i=0;i<nb_reference+1;i++)
|
145 |
|
|
{
|
146 |
|
|
long taille;
|
147 |
|
|
fread(&taille,sizeof(long),1,in);
|
148 |
|
|
char mess[255];
|
149 |
|
|
strcpy(mess,ListBox2->Items->Strings[i].c_str());
|
150 |
|
|
FILE* out=fopen(mess,"wb");
|
151 |
|
|
void *ptr=malloc(taille);
|
152 |
|
|
fread(ptr,taille,1,in);
|
153 |
|
|
fwrite(ptr,taille,1,out);
|
154 |
|
|
free(ptr);
|
155 |
|
|
fclose(out);
|
156 |
|
|
}
|
157 |
|
|
fclose(in);
|
158 |
|
|
FileListBox1->Update();
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
//---------------------------------------------------------------------------
|
162 |
|
|
|
163 |
|
|
void __fastcall Texpwinf::Button4Click(TObject *Sender)
|
164 |
|
|
{
|
165 |
|
|
if (OpenDialog1->Execute())
|
166 |
|
|
{
|
167 |
|
|
char mess[1500];
|
168 |
|
|
strcpy(mess,OpenDialog1->FileName.c_str());
|
169 |
|
|
FILE *in=fopen(mess,"rb");
|
170 |
|
|
long nb_reference;
|
171 |
|
|
fread(&nb_reference,sizeof(long),1,in);
|
172 |
|
|
ListBox2->Clear();
|
173 |
|
|
for (int i=0;i<nb_reference+1;i++)
|
174 |
|
|
{
|
175 |
|
|
long taille;
|
176 |
|
|
fread(&taille,sizeof(long),1,in);
|
177 |
|
|
char mess[1500];
|
178 |
|
|
fread(mess,taille,1,in);
|
179 |
|
|
mess[taille]=0;
|
180 |
|
|
char mess2[1500];
|
181 |
|
|
strcpy(mess2,DirectoryListBox1->Directory.c_str());
|
182 |
|
|
strcat(mess2,strrchr(mess,'\\'));
|
183 |
|
|
ListBox2->Items->Add(mess2);
|
184 |
|
|
}
|
185 |
|
|
for (int i=0;i<nb_reference+1;i++)
|
186 |
|
|
{
|
187 |
|
|
long taille;
|
188 |
|
|
fread(&taille,sizeof(long),1,in);
|
189 |
|
|
char mess[1500];
|
190 |
|
|
strcpy(mess,ListBox2->Items->Strings[i].c_str());
|
191 |
|
|
if (i==0) strcat(mess,".tmp");
|
192 |
|
|
FILE* out=fopen(mess,"wb");
|
193 |
|
|
void *ptr=malloc(taille);
|
194 |
|
|
fread(ptr,taille,1,in);
|
195 |
|
|
fwrite(ptr,taille,1,out);
|
196 |
|
|
free(ptr);
|
197 |
|
|
fclose(out);
|
198 |
|
|
}
|
199 |
|
|
fclose(in);
|
200 |
|
|
strcpy(mess,ListBox2->Items->Strings[0].c_str());
|
201 |
|
|
strcat(mess,".tmp");
|
202 |
|
|
in=fopen(mess,"rt");
|
203 |
|
|
strcpy(mess,ListBox2->Items->Strings[0].c_str());
|
204 |
|
|
FILE *out=fopen(mess,"wt");
|
205 |
|
|
while (!feof(in))
|
206 |
|
|
{
|
207 |
|
|
char chaine[10000];
|
208 |
|
|
fgets(chaine,10000,in);
|
209 |
|
|
long arg1;
|
210 |
|
|
char arg2[1000];
|
211 |
|
|
char c;
|
212 |
|
|
int num=sscanf(chaine,"%c%ld=GEOMETRIE%s",&c,&arg1,arg2);
|
213 |
|
|
if (num==3)
|
214 |
|
|
{
|
215 |
|
|
strcpy(arg2,strchr(chaine,'('));
|
216 |
|
|
PARS_ARGUMENT param[10];
|
217 |
|
|
PARSE parse;
|
218 |
|
|
parse.decode(arg2,"(&);",param);
|
219 |
|
|
int nb=param[0].get_nombre();
|
220 |
|
|
fprintf(out,"%c%ld=GEOMETRIE(",c,arg1);
|
221 |
|
|
if (nb>1)
|
222 |
|
|
{
|
223 |
|
|
char arg[500];
|
224 |
|
|
char mess[500];
|
225 |
|
|
strcpy(arg,param[0].argument[1].c_str());
|
226 |
|
|
strcpy(mess,DirectoryListBox1->Directory.c_str());
|
227 |
|
|
strcat(mess,strrchr(arg,'\\'));
|
228 |
|
|
fprintf(out,"%s,%s",param[0].argument[0].c_str(),mess);
|
229 |
|
|
}
|
230 |
|
|
if (nb>2)
|
231 |
|
|
{
|
232 |
|
|
char arg[500];
|
233 |
|
|
char mess[500];
|
234 |
|
|
strcpy(arg,param[0].argument[2].c_str());
|
235 |
|
|
strcpy(mess,DirectoryListBox1->Directory.c_str());
|
236 |
|
|
strcat(mess,strrchr(arg,'\\'));
|
237 |
|
|
fprintf(out,",%s",mess);
|
238 |
|
|
}
|
239 |
|
|
fprintf(out,");\n");
|
240 |
|
|
}
|
241 |
|
|
else
|
242 |
|
|
{
|
243 |
|
|
int num=sscanf(chaine,"%c%ld=SOLUTION%s",&c,&arg1,arg2);
|
244 |
|
|
if (num==3)
|
245 |
|
|
{
|
246 |
|
|
strcpy(arg2,strchr(chaine,'('));
|
247 |
|
|
PARS_ARGUMENT param[10];
|
248 |
|
|
PARSE parse;
|
249 |
|
|
parse.decode(arg2,"(&);",param);
|
250 |
|
|
int nb=param[0].get_nombre();
|
251 |
|
|
char arg[500];
|
252 |
|
|
char mess[500];
|
253 |
|
|
strcpy(arg,param[0].argument[3].c_str());
|
254 |
|
|
strcpy(mess,DirectoryListBox1->Directory.c_str());
|
255 |
|
|
strcat(mess,strrchr(arg,'\\'));
|
256 |
|
|
fprintf(out,"%c%ld=SOLUTION(",c,arg1);
|
257 |
|
|
for (int i=0;i<nb;i++)
|
258 |
|
|
{
|
259 |
|
|
if (i!=3) fprintf(out,"%s",param[0].argument[i].c_str());
|
260 |
|
|
else fprintf(out,"%s",mess);
|
261 |
|
|
if (i!=nb-1) fprintf(out,",");
|
262 |
|
|
}
|
263 |
|
|
fprintf(out,");\n");
|
264 |
|
|
}
|
265 |
|
|
else fprintf(out,"%s",chaine);
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
|
|
fclose(out);
|
269 |
|
|
fclose(in);
|
270 |
|
|
strcpy(mess,ListBox2->Items->Strings[0].c_str());
|
271 |
|
|
strcat(mess,".tmp");
|
272 |
|
|
remove(mess);
|
273 |
|
|
FileListBox1->Update();
|
274 |
|
|
}
|
275 |
|
|
}
|
276 |
|
|
//---------------------------------------------------------------------------
|
277 |
|
|
|
278 |
|
|
void __fastcall Texpwinf::FilterComboBox1Change(TObject *Sender)
|
279 |
|
|
{
|
280 |
|
|
if (FilterComboBox1->Text=="MAGIC")
|
281 |
|
|
{
|
282 |
|
|
ListBox1->Visible=true;
|
283 |
|
|
Button3->Visible=true;
|
284 |
|
|
Button4->Visible=true;
|
285 |
|
|
Label1->Visible=true;
|
286 |
|
|
Label2->Visible=true;
|
287 |
|
|
Label2->Caption="";
|
288 |
|
|
}
|
289 |
|
|
else
|
290 |
|
|
{
|
291 |
|
|
ListBox1->Visible=false;
|
292 |
|
|
Button2->Visible=false;
|
293 |
|
|
Button3->Visible=false;
|
294 |
|
|
Button4->Visible=false;
|
295 |
|
|
Label1->Visible=false;
|
296 |
|
|
Label2->Visible=false;
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
|
|
//---------------------------------------------------------------------------
|
300 |
|
|
|