1 |
foucault |
30 |
//------------------------------------------------------------
|
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 |
|
|
// fenetre.cpp
|
16 |
|
|
//
|
17 |
|
|
//------------------------------------------------------------
|
18 |
|
|
//------------------------------------------------------------
|
19 |
|
|
// COPYRIGHT 2000
|
20 |
|
|
// Version du 02/03/2006 à 11H25
|
21 |
|
|
//------------------------------------------------------------
|
22 |
|
|
//------------------------------------------------------------
|
23 |
|
|
#include "gestionversion.h"
|
24 |
|
|
#ifdef WINDOWS_VERSION
|
25 |
|
|
#include <vcl.h>
|
26 |
|
|
#pragma hdrstop
|
27 |
|
|
|
28 |
|
|
#include <fstream>
|
29 |
|
|
#include <sstream>
|
30 |
|
|
#include "fenetre.h"
|
31 |
|
|
#include "mainprocess.h"
|
32 |
|
|
#include <stdio.h>
|
33 |
|
|
#include <time.h>
|
34 |
|
|
#include <io.h>
|
35 |
|
|
#include <dos.h>
|
36 |
|
|
//---------------------------------------------------------------------------
|
37 |
|
|
#pragma package(smart_init)
|
38 |
|
|
#pragma link "CGAUGES"
|
39 |
|
|
#pragma resource "*.dfm"
|
40 |
|
|
TForm1 *Form1;
|
41 |
|
|
//---------------------------------------------------------------------------
|
42 |
|
|
__fastcall TForm1::TForm1(TComponent* Owner)
|
43 |
|
|
: TForm(Owner)
|
44 |
|
|
{
|
45 |
|
|
}
|
46 |
|
|
//---------------------------------------------------------------------------
|
47 |
|
|
void __fastcall TForm1::Timer1Timer(TObject *Sender)
|
48 |
|
|
{
|
49 |
|
|
Timer1->Interval=32000;
|
50 |
|
|
ClientSocket1->Open();
|
51 |
|
|
Timer2->Interval=100;
|
52 |
|
|
Timer2->Enabled=true;
|
53 |
|
|
}
|
54 |
|
|
//---------------------------------------------------------------------------
|
55 |
|
|
void __fastcall TForm1::Timer2Timer(TObject *Sender)
|
56 |
|
|
{
|
57 |
|
|
struct time t;
|
58 |
|
|
gettime(&t);
|
59 |
|
|
sprintf(heure,"2 %2d:%02d:%02d.%02d",t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
|
60 |
|
|
ClientSocket1->Socket->SendText(heure);
|
61 |
|
|
Timer2->Enabled=false;
|
62 |
|
|
|
63 |
|
|
}
|
64 |
|
|
//---------------------------------------------------------------------------
|
65 |
|
|
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
|
66 |
|
|
TCustomWinSocket *Socket)
|
67 |
|
|
{
|
68 |
|
|
static int nbpb=0;
|
69 |
|
|
AnsiString rep=Socket->ReceiveText();
|
70 |
|
|
ClientSocket1->Close();
|
71 |
|
|
char *mess=rep.c_str();
|
72 |
|
|
char messtmp[20];
|
73 |
|
|
long num;
|
74 |
|
|
sprintf(messtmp,"%s1",heure);
|
75 |
|
|
StringHasher(messtmp,&num);
|
76 |
|
|
char decode[20];
|
77 |
|
|
sprintf(decode,"%08X",num);
|
78 |
|
|
if (strcmp(mess,decode)!=0)
|
79 |
|
|
{
|
80 |
|
|
nbpb++;
|
81 |
|
|
char mess[255];
|
82 |
|
|
// sprintf(mess,"Licence indisponible essai %d",nbpb);
|
83 |
|
|
// affichemessage(mess);
|
84 |
|
|
Timer2->Interval=100;
|
85 |
|
|
Timer2->Enabled=true;
|
86 |
|
|
// if (nbpb>2)
|
87 |
|
|
// TerminateProcess(GetCurrentProcess(),0);
|
88 |
|
|
}
|
89 |
|
|
else desaffichemessage();
|
90 |
|
|
}
|
91 |
|
|
//---------------------------------------------------------------------------
|
92 |
|
|
void __fastcall TForm1::ClientSocket1Error(TObject *Sender,
|
93 |
|
|
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
|
94 |
|
|
{
|
95 |
|
|
static int nbpb=0;
|
96 |
|
|
nbpb++;
|
97 |
|
|
char mess[255];
|
98 |
|
|
sprintf(mess,"Serveur de licence indisponible essai %d",nbpb);
|
99 |
|
|
affichemessage(mess);
|
100 |
|
|
Timer2->Interval=100;
|
101 |
|
|
Timer2->Enabled=true;
|
102 |
|
|
//if (nbpb>2)
|
103 |
|
|
// TerminateProcess(GetCurrentProcess(),0);
|
104 |
|
|
ErrorCode=0;
|
105 |
|
|
ClientSocket1->Close();
|
106 |
|
|
}
|
107 |
|
|
//---------------------------------------------------------------------------
|
108 |
|
|
void __fastcall TForm1::affichemessage(char *chaine)
|
109 |
|
|
{
|
110 |
|
|
Label4->Caption=chaine;
|
111 |
|
|
Label4->Visible=true;
|
112 |
|
|
Application->BringToFront();
|
113 |
|
|
}
|
114 |
|
|
//---------------------------------------------------------------------------
|
115 |
|
|
void __fastcall TForm1::desaffichemessage(void)
|
116 |
|
|
{
|
117 |
|
|
Label4->Caption="";
|
118 |
|
|
Label4->Visible=false;
|
119 |
|
|
}
|
120 |
|
|
//---------------------------------------------------------------------------
|
121 |
|
|
void __fastcall TForm1::FormCreate(TObject *Sender)
|
122 |
|
|
{
|
123 |
|
|
HKEY clef;
|
124 |
|
|
DWORD type,taille;
|
125 |
|
|
RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\UQTR\\VMM\\",0,KEY_EXECUTE,&clef);
|
126 |
|
|
int res=RegQueryValueEx(clef,"Serveur",0,&type,0,&taille);
|
127 |
|
|
/*if (res!=ERROR_SUCCESS)
|
128 |
|
|
{
|
129 |
|
|
MessageBox(Handle,"Problème d'installation","Erreur", MB_OK);
|
130 |
|
|
TerminateProcess(GetCurrentProcess(),0);
|
131 |
|
|
} */
|
132 |
|
|
char name[100];
|
133 |
|
|
RegQueryValueEx(clef,"Serveur",0,&type,name,&taille);
|
134 |
|
|
ClientSocket1->Host=name;
|
135 |
|
|
Timer1->Interval=10;
|
136 |
|
|
Timer1->Enabled=true;
|
137 |
|
|
debut=time(NULL);
|
138 |
|
|
Label5->Caption=__DATE__;
|
139 |
|
|
Label6->Caption="A";
|
140 |
|
|
Label7->Caption=__TIME__;
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
strcat (filenameNbTriangles, getenv("TEMP"));
|
144 |
|
|
strcat (filenameNbTriangles, "\\CAD4FE_NbTriangles.txt");
|
145 |
|
|
std::ofstream fileNbTriangles(filenameNbTriangles);
|
146 |
|
|
fileNbTriangles.clear();
|
147 |
|
|
fileNbTriangles.flush();
|
148 |
|
|
fileNbTriangles.close();
|
149 |
|
|
|
150 |
|
|
}
|
151 |
|
|
//---------------------------------------------------------------------------
|
152 |
|
|
int __fastcall TForm1::StringHasher(const char *string,long *hash)
|
153 |
|
|
{
|
154 |
|
|
unsigned short kbuffer[513];/* Block 1Kb at a time */
|
155 |
|
|
unsigned short *kindex;/* Index into 1Kb */
|
156 |
|
|
unsigned short *kend; /* Pointer to end of buffer */
|
157 |
|
|
unsigned long d0;
|
158 |
|
|
unsigned long d3 = 0;
|
159 |
|
|
unsigned long d4 = 0;
|
160 |
|
|
unsigned long size; /* File size */
|
161 |
|
|
int pass; /* pass through file */
|
162 |
|
|
unsigned int u1,u2,u3,u4,h1,h2,h3;
|
163 |
|
|
|
164 |
|
|
size = (unsigned long)strlen(string);
|
165 |
|
|
kend = (unsigned short *)string + (size>>1);
|
166 |
|
|
for (pass = 1; pass <= 2; pass++)
|
167 |
|
|
{
|
168 |
|
|
kindex = kend;
|
169 |
|
|
for (d0 = (size+1) >> 1; d0 > 0; d0--)
|
170 |
|
|
{
|
171 |
|
|
if (kindex == kend)
|
172 |
|
|
{
|
173 |
|
|
if(pass == 1)
|
174 |
|
|
{
|
175 |
|
|
strcpy((char *)kbuffer,string);
|
176 |
|
|
kbuffer[size+1] = 0;
|
177 |
|
|
}
|
178 |
|
|
else
|
179 |
|
|
{
|
180 |
|
|
strcpy((char *)kbuffer,string);
|
181 |
|
|
kbuffer[size+1] = 1;
|
182 |
|
|
}
|
183 |
|
|
kindex = kbuffer;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
d3 = d3+*(kindex++);
|
187 |
|
|
d4 = (unsigned short)(d4+(d3>>16));
|
188 |
|
|
d3 = (unsigned short)d3;
|
189 |
|
|
|
190 |
|
|
if (d4 < (unsigned short)d0)
|
191 |
|
|
{
|
192 |
|
|
d4 = d4+65536L-(unsigned short)d0;
|
193 |
|
|
d3 = (unsigned short)(d3+1);
|
194 |
|
|
}
|
195 |
|
|
else
|
196 |
|
|
d4 = d4-(unsigned short)d0;
|
197 |
|
|
|
198 |
|
|
d4 = d4+d3;
|
199 |
|
|
d3 = (unsigned short)(d3+(d4>>16));
|
200 |
|
|
d4 = (unsigned short)d4;
|
201 |
|
|
|
202 |
|
|
d3 <<= 1;
|
203 |
|
|
d4 = (d4<<1)+(d3>>16);
|
204 |
|
|
d3 = (unsigned short)d3+(d4>>16);
|
205 |
|
|
d4 = (unsigned short)d4;
|
206 |
|
|
}
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
u1 = (unsigned int)(d4 & 0777);
|
210 |
|
|
u2 = (unsigned int)((((d4 & 0177400)>>8)|((d4 & 0777)<<8)) & 0777);
|
211 |
|
|
u3 = (unsigned int)(d3 & 0777);
|
212 |
|
|
u4 = (unsigned int)((((d3 & 0177400)>>8)|((d3 & 0777)<<8)) & 0777);
|
213 |
|
|
|
214 |
|
|
h3 = u4 + ((u3 & 0x07) << 9);
|
215 |
|
|
h2 = ((u3 & 0x1F8) >> 3) + ((u2 & 0x3F) << 6);
|
216 |
|
|
h1 = ((u2 & 0x1C0) >> 6) + (u1 << 3);
|
217 |
|
|
|
218 |
|
|
*hash = ((h3<<24) | (h2<<12) | h1) & 0xFFFFFFFF;
|
219 |
|
|
|
220 |
|
|
return(1);
|
221 |
|
|
}
|
222 |
|
|
//---------------------------------------------------------------------------
|
223 |
|
|
void __fastcall TForm1::Timer3Timer(TObject *Sender)
|
224 |
|
|
{
|
225 |
|
|
Timer3->Enabled=false;
|
226 |
|
|
process=new mainprocess(false);
|
227 |
|
|
}
|
228 |
|
|
//---------------------------------------------------------------------------
|
229 |
|
|
void __fastcall TForm1::Timer4Timer(TObject *Sender)
|
230 |
|
|
{
|
231 |
|
|
_FILETIME lpct,lpet,lpkt,lput;
|
232 |
|
|
long res=GetProcessTimes(GetCurrentProcess(),&lpct,&lpet,&lpkt,&lput);
|
233 |
|
|
double temps;
|
234 |
|
|
static double tempsancien;
|
235 |
|
|
if (res)
|
236 |
|
|
{
|
237 |
|
|
temps=lput.dwHighDateTime*pow(2,32)*0.0000001;
|
238 |
|
|
temps=temps+lput.dwLowDateTime*0.0000001;
|
239 |
|
|
}
|
240 |
|
|
else temps=0;
|
241 |
|
|
time_t fin=time(NULL);
|
242 |
|
|
long valeur;
|
243 |
|
|
if (fin!=debut) valeur=(temps-tempsancien)/(fin-debut)*100.; else valeur=(temps-tempsancien)*100.;
|
244 |
|
|
debut=fin;
|
245 |
|
|
if (valeur>100) valeur=100;
|
246 |
|
|
if (valeur>75) CGauge1->ForeColor=clRed; else CGauge1->ForeColor=clGreen;
|
247 |
|
|
CGauge1->SetTextBuf("CPU");
|
248 |
|
|
CGauge1->Progress=valeur;
|
249 |
|
|
tempsancien=temps;
|
250 |
|
|
|
251 |
|
|
}
|
252 |
|
|
//---------------------------------------------------------------------------
|
253 |
|
|
void __fastcall TForm1::Button1Click(TObject *Sender)
|
254 |
|
|
{
|
255 |
|
|
int rep=MessageBox(Handle,"Voulez vous vraiment annuler ?","Annuler",MB_YESNO|MB_ICONEXCLAMATION);
|
256 |
|
|
if (rep==IDYES)
|
257 |
|
|
{
|
258 |
|
|
long code;
|
259 |
|
|
process->Suspend();
|
260 |
|
|
TerminateThread(process,code);
|
261 |
|
|
Button1->Visible=false;
|
262 |
|
|
Button2->Visible=true;
|
263 |
|
|
Timer5->Enabled=false;
|
264 |
|
|
}
|
265 |
|
|
}
|
266 |
|
|
//---------------------------------------------------------------------------
|
267 |
|
|
void __fastcall TForm1::Button2Click(TObject *Sender)
|
268 |
|
|
{
|
269 |
|
|
Close();
|
270 |
|
|
}
|
271 |
|
|
//---------------------------------------------------------------------------
|
272 |
|
|
void __fastcall TForm1::Timer5Timer(TObject *Sender)
|
273 |
|
|
{
|
274 |
|
|
static clock_t start=clock();
|
275 |
|
|
clock_t end=clock();
|
276 |
|
|
clock_t tempscpu=(end-start)/CLK_TCK;
|
277 |
|
|
int h=tempscpu/3600;
|
278 |
|
|
int m=(tempscpu-h*3600)/60;
|
279 |
|
|
int s=(tempscpu-h*3600-m*60);
|
280 |
|
|
char mess[255];
|
281 |
|
|
sprintf(mess,"%02dh%02dm%02ds",h,m,s);
|
282 |
|
|
Label2->Caption=mess;
|
283 |
|
|
}
|
284 |
|
|
//---------------------------------------------------------------------------
|
285 |
|
|
#endif
|
286 |
|
|
|
287 |
|
|
void __fastcall TForm1::Timer6Timer(TObject *Sender)
|
288 |
|
|
{
|
289 |
|
|
AfficheNbTriangles();
|
290 |
|
|
}
|
291 |
|
|
//---------------------------------------------------------------------------
|
292 |
|
|
|
293 |
|
|
void __fastcall TForm1::AfficheNbTriangles()
|
294 |
|
|
{
|
295 |
|
|
char nbTriangles[5000]="";
|
296 |
|
|
std::ifstream fileNbTriangles(filenameNbTriangles);
|
297 |
|
|
if ( fileNbTriangles.is_open())
|
298 |
|
|
{
|
299 |
|
|
fileNbTriangles.getline(nbTriangles,5000);
|
300 |
|
|
fileNbTriangles.close();
|
301 |
|
|
if (strlen(nbTriangles)==0)
|
302 |
|
|
return;
|
303 |
|
|
AnsiString curStrMemo1 = Memo1->Lines->Strings[Memo1->Lines->Count-1];
|
304 |
|
|
AnsiString newStrMemo1 (nbTriangles);
|
305 |
|
|
if (newStrMemo1 != curStrMemo1)
|
306 |
|
|
Memo1->Lines->Strings[Memo1->Lines->Count-1] = newStrMemo1;
|
307 |
|
|
}
|
308 |
|
|
}
|
309 |
|
|
|
310 |
|
|
|