Added GDE-Loop

Das Programm wird jetzt in einer while-Schleife ausgeführt, zwei Buttons
sind zu Steuerung in der GDE vorhanden
This commit is contained in:
Jonny007-MKD 2014-01-06 20:32:59 +01:00
parent ac7e6ff233
commit d17de2a6a1
9 changed files with 195 additions and 130 deletions

View file

@ -122,6 +122,7 @@
<ClCompile Include="..\Hazard\Hazard\KV_PiGroup.cpp" />
<ClCompile Include="..\Hazard\Hazard\PrimImplikant.cpp" />
<ClCompile Include="..\Hazard\Hazard\PrimImplikantCollection.cpp" />
<ClCompile Include="..\Hazard\Hazard\Tools.cpp" />
<ClCompile Include="..\Hazard\Hazard\Wertetabelle.cpp" />
<ClCompile Include="GDE_3.cpp" />
<ClCompile Include="GDE_3Doc.cpp" />
@ -146,6 +147,7 @@
<ClInclude Include="..\Hazard\Hazard\KV_PiGroup.h" />
<ClInclude Include="..\Hazard\Hazard\PrimImplikant.h" />
<ClInclude Include="..\Hazard\Hazard\PrimImplikantCollection.h" />
<ClInclude Include="..\Hazard\Hazard\Tools.h" />
<ClInclude Include="..\Hazard\Hazard\Wertetabelle.h" />
<ClInclude Include="GDE_3.h" />
<ClInclude Include="GDE_3Doc.h" />
@ -153,7 +155,6 @@
<ClInclude Include="MainFrm.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="User.h" />
<ClInclude Include="Graphics\BaseException.h" />
<ClInclude Include="Graphics\Dib.h" />
<ClInclude Include="Graphics\Graphicfunctions.h" />

View file

@ -78,6 +78,9 @@
<ClCompile Include="..\Hazard\Hazard\KV_PiGroup.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="..\Hazard\Hazard\Tools.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="GDE_3.h">
@ -98,9 +101,6 @@
<ClInclude Include="stdafx.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="User.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="Graphics\BaseException.h">
<Filter>Graphics</Filter>
</ClInclude>
@ -149,6 +149,9 @@
<ClInclude Include="..\Hazard\Hazard\KV_PiEleLoc.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="..\Hazard\Hazard\Tools.h">
<Filter>Quelldateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\GDE_3.ico">

View file

@ -220,9 +220,9 @@ void CGDE_3View::OnButtonzoomfit()
void CGDE_3View::OnStartButton()
{
theApp.m_stopflag=FALSE;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////if(theApp.vw->uthread==NULL)
if(theApp.vw->uthread==NULL)
theApp.vw->uthread = AfxBeginThread(StartGDE, &theApp, THREAD_PRIORITY_NORMAL);
//else AfxMessageBox("User_main is already running\n",MB_OK);
else AfxMessageBox("User_main is already running\n",MB_OK);
}
void CGDE_3View::OnStopButton()

View file

@ -208,7 +208,7 @@ int mouseclick(int *x, int *y) // Wartet auf einen Mausklick und gibt dann butto
while (theApp.vw->MouseClick == 0) // Warten bis eine Maustaste gedrueckt wird.
{
DoEvents();
if(StopProcess())break;
if(stopProcess())break;
Sleep(20); // 20ms warten
}
*x = theApp.vw->MousePoint.x; // Zurueckgeben der x-Koordinate des Mauszeigers.
@ -247,7 +247,7 @@ void updatescr() // Neuzeichnen des gesamten Zeichenbereiches.
{
theApp.vw->Invalidate(FALSE); // Zeichenbereich aktualisieren (GDEView::OnPaint() wird aufgerufen)
}
BOOL StopProcess()
bool stopProcess()
{
return theApp.m_stopflag ;
return (bool)theApp.m_stopflag ;
}

View file

@ -1,3 +1,5 @@
#include "../stdafx.h"
// Graphicfunctions.h : interface of the GDE functions
//
// In diesem Header-File sind alle Grafikfunktionen, die der Benutzer
@ -98,4 +100,4 @@ void wait(unsigned int msecs); // Wartet die vorgegebende Zeit in Millisekunden.
void clrscr(); // Loescht den gesamten Zeichenbereich.
void updatescr(); // Neuzeichnen des gesamten Zeichenbereiches.
BOOL StopProcess(); // Gibt an ob ein Stopflagg gesetzt wurde
bool stopProcess(); // Gibt an ob ein Stopflagg gesetzt wurde

View file

@ -44,7 +44,7 @@ void Zeichne_Ast(int x, int y, float n, float Tiefe, float Laenge)
{
int x_rel;
int y_rel;
if(StopProcess())return;
if(stopProcess())return;
if (Tiefe > 1) { // Stopbedingung fuer die Rekursion.
// Zeichnen des linken Astes.
x_rel = (int)(Laenge * _sinus(n + baum.Neigung_links)); // Berechnen der x-Koordinate.
@ -109,7 +109,7 @@ void Restart()
((y > h-40) && (y < h-5))
)) {
printf(".");
if(StopProcess())break;
if(stopProcess())break;
};
printf("######################################\n\n");
@ -147,7 +147,7 @@ void user_main2()
Zeichne_Baum(); // Den Baum zeichnen.
cout << "Baum gezeichnet\n";
Restart(); // Den "Restart"-Button malen und auf eine Aktivierung warten.
if(StopProcess())break;
if(stopProcess())break;
}
}

View file

@ -18,58 +18,68 @@ uint numElements = 0; // = 2 ^ dimension
bool KNF = false;
bool fileChosen = false;
char fnInput[256];
char fnError[256];
char fnLists[256];
int open_files(FILE * &input, FILE * &error, FILE * &list)
{
if (fileChosen == false)
if (fileChosen == true) // don't reopen files
return 9;
GetCurrentDirectory(sizeof(fnInput), fnInput);
if (error == NULL)
{
GetCurrentDirectory(sizeof(fnInput), fnInput);
char fnError[256];
strcpy_s(fnError, (string(fnInput) + "\\res\\errorParser.txt").c_str());
strcpy_s(fnLists, (string(fnInput) + "\\res\\listParser.txt").c_str());
strcpy_s(fnInput, (string(fnInput) + "\\res\\input.txt").c_str());
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = fnInput;
ofn.nMaxFile = sizeof(fnInput);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) != TRUE)
fopen_s(&error, fnError, "a");
if (error == NULL)
{
cout << "Auswahl der Inputdatei abgebrochen!";
perror("Fehler beim Öffnen der Fehlerdatei");
return 1;
}
}
if (list == NULL)
{
char fnLists[256];
strcpy_s(fnLists, (string(fnInput) + "\\res\\listParser.txt").c_str());
fopen_s(&list, fnLists, "w");
if (list == NULL)
{
perror("Fehler beim Öffnen der Listdatei");
return 1;
}
fileChosen = true;
}
strcpy_s(fnInput, (string(fnInput) + "\\res\\input.txt").c_str());
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = fnInput;
ofn.nMaxFile = sizeof(fnInput);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) != TRUE)
{
cout << "Auswahl der Inputdatei abgebrochen!";
return 2;
}
fileChosen = true;
if (input != NULL)
fclose(input);
fopen_s(&input, fnInput, "r");
if (input == NULL)
{
perror("Fehler beim Lesen der Inputdatei");
return 1;
}
fopen_s(&error, fnError, "a");
if (error == NULL)
{
perror("Fehler beim Öffnen der Fehlerdatei");
return 1;
}
fopen_s(&list, fnLists, "w");
if (list == NULL)
{
perror("Fehler beim Öffnen der Listdatei");
return 1;
}
return 0;
}
@ -82,58 +92,91 @@ void pause()
void user_main(void)
{
FILE * input, * error, * list;
if (open_files(input, error, list) != 0)
FILE * input = NULL, * error = NULL, * list = NULL;
KV* kv;
while(1)
{
pause();
return;
switch(open_files(input, error, list))
{
case 1: // some error
fileChosen = false;
perror("Error while opening a file (1)");
continue;
case 2: // user aborted
ExitProcess(2);
break;
case 9: // same input as before
// We could skip recalculation, but then the GDE is not redrawn (updatescr doesn't help) :/
case 0: // new file opened
{
cout << endl << endl << endl << endl;
PrimImplikantCollection* globalPIC = new PrimImplikantCollection();
vector<string>* variables = new vector<string>();
rewind(input);
CParser* parser = new CParser(input, error, list);
int parseFailure = parser->yyparse(globalPIC, variables);
delete parser;
if (parseFailure != 0)
{
fileChosen = false;
string error = "Error while parsing the input (";
char buf[5];
_itoa_s(parseFailure, buf, 10);
error += buf;
error += ")";
perror(error.c_str());
continue;
}
// initialize Cells
CellCollection* allCells = new CellCollection(globalPIC);
// print Wertetabelle and KV of imported data
Wertetabelle* wt = new Wertetabelle(allCells, variables);
wt->Print();
kv = new KV(globalPIC, allCells, 30,variables);
kv->Print(30);
// find and solve Hazards
allCells->findHazards();
// print Wertetabelle and KV of corrected data
wt->Print();
kv->Print(30 + kv->width() + 30, 30); // Diagramm neben dem vorherigen
kv->Buttons();
delete wt;
wt = NULL;
globalPIC->Dispose();
delete globalPIC;
globalPIC = NULL;
allCells->Dispose();
delete allCells;
allCells = NULL;
delete variables;
variables = NULL;
break;}
}
if (kv->StopProcess())
{
if (kv != NULL)
delete kv;
kv = NULL;
_fcloseall();
fileChosen = false;
break;
}
}
PrimImplikantCollection* globalPIC = new PrimImplikantCollection();
vector<string>* variables = new vector<string>();
CParser* parser = new CParser(input, error, list);
bool parseFailure = parser->yyparse(globalPIC, variables) != 0;
fclose(input);
fclose(error);
fclose(list);
delete parser;
if (parseFailure)
{
pause();
return;
}
// initialize Cells
CellCollection* allCells = new CellCollection(globalPIC);
// print Wertetabelle and KV of imported data
Wertetabelle* wt = new Wertetabelle(allCells, variables);
wt->Print();
KV* kv = new KV(globalPIC, allCells, 30,variables);
kv->Print(30);
// find and solve Hazards
allCells->findHazards();
// print Wertetabelle and KV of corrected data
wt->Print();
delete wt;
kv->Print(30 + kv->width() + 30, 30); // Diagramm neben dem vorherigen
delete kv;
globalPIC->Dispose();
allCells->Dispose();
delete globalPIC;
delete allCells;
delete variables;
cout << endl << endl << endl << endl;
return;
}

View file

@ -3,11 +3,13 @@
#include "Cell.h"
#include "PrimImplikantCollection.h"
#include "..\..\GDE_3_2008\graphics\graphicfunctions.h"
#include "Tools.h"
#include "KV.h"
extern uint dimension;
extern uint numElements;
extern bool KNF;
extern bool fileChosen;
using namespace std;
@ -26,6 +28,9 @@ void KV::Print(uint offset)
}
void KV::Print(uint offsetX, uint offsetY)
{
if (this->numVarX == 0 || this->numVarY == 0)
return;
this->offsetX = offsetX;
this->offsetY = offsetY;
@ -112,7 +117,7 @@ void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- u
{
uint XL = w * (this->edgeLength + 1) + this->VarY_Length;
uint XR = XL + this->edgeLength;
char* value = this->Binary(w ^ (w / 2), this->numVarX); // in Gray und String umwandeln
char* value = Tools::BinaryToChars(w ^ (w / 2), this->numVarX); // in Gray und String umwandeln
this->TextBoxBold(XL, 0, XR, this->VarX_Length, 10, BLACK, TRANS, TRANS, SINGLE_LINE|CENTER_ALIGN|BOTTOM_ALIGN, value);
delete value;
}
@ -122,7 +127,7 @@ void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- u
{
uint YT = h * (this->edgeLength + 1) + this->VarX_Length + 1;
uint YB = YT + this->edgeLength;
char* value = this->Binary(h ^ (h / 2), this->numVarY); // in Gray und String umwandeln
char* value = Tools::BinaryToChars(h ^ (h / 2), this->numVarY); // in Gray und String umwandeln
this->TextBoxBold(0, YT, this->VarY_Length-5, YB, 10, BLACK, TRANS, TRANS, SINGLE_LINE|RIGHT_ALIGN|VCENTER_ALIGN, value);
delete value;
}
@ -130,7 +135,7 @@ void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- u
void KV::PrintCellValues() // Erstellt die Werte der jeweiligen Zellen: ▯▯▯
{ // ▯ x x
// ▯ x x
// ▯ x x
for (uint h = 0; h < this->numFieldY; h++) // jede Spalte durchgehen
{
uint YT = h * (this->edgeLength + 1)+ this->VarX_Length; // Y Positionen berechnen
@ -148,21 +153,23 @@ void KV::PrintCellValues() // Erstellt die Werte der jeweiligen Zellen: ▯▯
/*
char* I = new char[(int)(ceil(log10((float)numElements)))+1];
itoa(i, I, 10);
this->TextBox(XL, YT, XR, YB, 10, BLACK, TRANSPARENT, TRANSPARENT, CENTER, I);
this->TextBox(XL, YT, XR, YB, 10, BLACK, TRANS, TRANS, CENTER, I);
*/
// Dies sind die Zellwerte:
///*
char* I = new char[2];
_itoa_s(this->allCells->at(i)->value, I, 2, 10);
this->TextBox(XL, YT, XR, YB, 10, BLACK, TRANS, TRANS, CENTER, I);
delete I;
//*/
}
}
}
void KV::PrintPrimImplikanten()
{
srand(time(NULL) ^ rand());
srand((uint)time(NULL) ^ rand());
vector<KV_PiGroup*> piGroups;
for (uint i = 0; i < this->globalPic->size(); i++) // for each PrimImplikant
@ -268,7 +275,34 @@ void KV::PrintPrimImplikantenGroup(KV_PiGroup* &group, char random, uint &color)
void KV::Buttons()
{
int b, h, x, y;
get_drawarea(&b, &h);
textbox(b-120, h-40, b-5, h-5, 12, BLACK, GREY, RGB(50,50,50), SINGLE_LINE|VCENTER_ALIGN|CENTER_ALIGN, "Restart");
textbox(b-240, h-40, b-125, h-5, 12, BLACK, GREY, RGB(50,50,50), SINGLE_LINE|VCENTER_ALIGN|CENTER_ALIGN, "Other file");
updatescr();
while (
!(mouseclick(&x,&y) == 1 && (y > h-40 && y < h-5) && (
(x > b-120 && x < b-5) ||
(x > b-240 && x < b-125)
)))
{
printf(".");
if(stopProcess())break;
};
if ((x > b-240 && x < b-125) && (y > h-40 && y < h-5))
fileChosen = false;
}
bool KV::StopProcess()
{
return (bool)stopProcess();
}
@ -296,23 +330,4 @@ void KV::TextBoxBold(uint x1, uint y1, uint x2, uint y2, uint size, int ctext, i
void KV::Rechteck(uint x1, uint y1, uint x2, uint y2, int cframe, int cfill)
{
rectangle(x1 + this->offsetX + 1, y1 + this->offsetY + 1, x2 + this->offsetX + 1, y2 + this->offsetY + 1, cframe, cfill);
}
// convert the binary representation of x to a string with the specified length
char* KV::Binary(uint x, char length)
{
// warning: this breaks for numbers with more than 64 bits (= variables)
char* c = new char[length+1];
c += length; // last char
*c = 0;
do
{
*--c = '0' + (x & 1); // 0 or 1 at the specified position
x >>= 1;
} while (--length);
return c;
}

View file

@ -1,3 +1,5 @@
#pragma once
#include "stdafx.h"
#include <vector>
#include <string>
@ -10,10 +12,6 @@ extern uint dimension;
extern uint numElements;
extern bool KNF;
#ifndef _KV_H
#define _KV_H
class KV
{
public:
@ -22,6 +20,9 @@ public:
uint width(); // Gibt die Breite eines KV-Diagramms zurück (widthPx)
uint height(); // Gibt die Höhe eines KV-Diagramms zurück (heightPx)
void Buttons();
bool StopProcess();
// Konstruktor
KV(PrimImplikantCollection* globalPic, CellCollection* allCells, uint size, vector<string>* &variables)
: edgeLength(size),
@ -71,6 +72,7 @@ private:
void Clear();
void Line(uint x1, uint y1, uint x2, uint y2, int color); // Zeichnet eine Linie mit Offset
void Text(uint x, uint y, uint size, int color, int bkcolor, int angle, int align, char* theText); // Zeichnet einen Text mit Offset
void KV::TextBox(uint x1, uint y1, uint x2, uint y2, uint size, int ctext, int cframe, int cfill, int flags, char* theText); // Zeichnet eine TextBox mit Offset
@ -81,5 +83,4 @@ private:
};
#define CENTER SINGLE_LINE|CENTER_ALIGN|VCENTER_ALIGN
#endif
#define CENTER SINGLE_LINE|CENTER_ALIGN|VCENTER_ALIGN