From d17de2a6a1061a716c69e564ed0757623954d767 Mon Sep 17 00:00:00 2001
From: Jonny007-MKD <1-23-4-5@web.de>
Date: Mon, 6 Jan 2014 20:32:59 +0100
Subject: [PATCH] Added GDE-Loop
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Das Programm wird jetzt in einer while-Schleife ausgeführt, zwei Buttons
sind zu Steuerung in der GDE vorhanden
---
GDE_3_2008/GDE_3.vcxproj | 3 +-
GDE_3_2008/GDE_3.vcxproj.filters | 9 +-
GDE_3_2008/GDE_3View.cpp | 4 +-
GDE_3_2008/Graphics/Graphicfunctions.cpp | 6 +-
GDE_3_2008/Graphics/Graphicfunctions.h | 4 +-
GDE_3_2008/user.cpp | 6 +-
Hazard/Hazard/Hazard.cpp | 217 ++++++++++++++---------
Hazard/Hazard/KV.cpp | 63 ++++---
Hazard/Hazard/KV.h | 13 +-
9 files changed, 195 insertions(+), 130 deletions(-)
diff --git a/GDE_3_2008/GDE_3.vcxproj b/GDE_3_2008/GDE_3.vcxproj
index 0d87dd4..d2bb8be 100644
--- a/GDE_3_2008/GDE_3.vcxproj
+++ b/GDE_3_2008/GDE_3.vcxproj
@@ -122,6 +122,7 @@
+
@@ -146,6 +147,7 @@
+
@@ -153,7 +155,6 @@
-
diff --git a/GDE_3_2008/GDE_3.vcxproj.filters b/GDE_3_2008/GDE_3.vcxproj.filters
index cbc3105..929fe0b 100644
--- a/GDE_3_2008/GDE_3.vcxproj.filters
+++ b/GDE_3_2008/GDE_3.vcxproj.filters
@@ -78,6 +78,9 @@
Quelldateien
+
+ Quelldateien
+
@@ -98,9 +101,6 @@
Headerdateien
-
- Headerdateien
-
Graphics
@@ -149,6 +149,9 @@
Headerdateien
+
+ Quelldateien
+
diff --git a/GDE_3_2008/GDE_3View.cpp b/GDE_3_2008/GDE_3View.cpp
index 082ba6c..f1e6ff2 100644
--- a/GDE_3_2008/GDE_3View.cpp
+++ b/GDE_3_2008/GDE_3View.cpp
@@ -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()
diff --git a/GDE_3_2008/Graphics/Graphicfunctions.cpp b/GDE_3_2008/Graphics/Graphicfunctions.cpp
index bcd52d6..ff66f87 100644
--- a/GDE_3_2008/Graphics/Graphicfunctions.cpp
+++ b/GDE_3_2008/Graphics/Graphicfunctions.cpp
@@ -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 ;
}
diff --git a/GDE_3_2008/Graphics/Graphicfunctions.h b/GDE_3_2008/Graphics/Graphicfunctions.h
index 7445ac0..dd8bff5 100644
--- a/GDE_3_2008/Graphics/Graphicfunctions.h
+++ b/GDE_3_2008/Graphics/Graphicfunctions.h
@@ -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
\ No newline at end of file
+bool stopProcess(); // Gibt an ob ein Stopflagg gesetzt wurde
\ No newline at end of file
diff --git a/GDE_3_2008/user.cpp b/GDE_3_2008/user.cpp
index cd0750a..dc8d884 100644
--- a/GDE_3_2008/user.cpp
+++ b/GDE_3_2008/user.cpp
@@ -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;
}
}
\ No newline at end of file
diff --git a/Hazard/Hazard/Hazard.cpp b/Hazard/Hazard/Hazard.cpp
index cedbcee..4e1ddcc 100644
--- a/Hazard/Hazard/Hazard.cpp
+++ b/Hazard/Hazard/Hazard.cpp
@@ -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* variables = new vector();
+
+ 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* variables = new vector();
-
- 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;
}
\ No newline at end of file
diff --git a/Hazard/Hazard/KV.cpp b/Hazard/Hazard/KV.cpp
index e50ea09..6916aae 100644
--- a/Hazard/Hazard/KV.cpp
+++ b/Hazard/Hazard/KV.cpp
@@ -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 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;
}
\ No newline at end of file
diff --git a/Hazard/Hazard/KV.h b/Hazard/Hazard/KV.h
index 9742aa6..bfc3908 100644
--- a/Hazard/Hazard/KV.h
+++ b/Hazard/Hazard/KV.h
@@ -1,3 +1,5 @@
+#pragma once
+
#include "stdafx.h"
#include
#include
@@ -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* &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
\ No newline at end of file
+#define CENTER SINGLE_LINE|CENTER_ALIGN|VCENTER_ALIGN
\ No newline at end of file