diff --git a/GDE_3_2008/GDE_3.vcxproj b/GDE_3_2008/GDE_3.vcxproj index c563179..2436ffa 100644 --- a/GDE_3_2008/GDE_3.vcxproj +++ b/GDE_3_2008/GDE_3.vcxproj @@ -28,7 +28,7 @@ Application Static MultiByte - v100 + v120 diff --git a/GDE_3_2008/stdafx.h b/GDE_3_2008/stdafx.h index d1b88dd..e5bb195 100644 --- a/GDE_3_2008/stdafx.h +++ b/GDE_3_2008/stdafx.h @@ -13,12 +13,12 @@ // Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind. // Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen. #ifndef WINVER // Lassen Sie die Verwendung von Features spezifisch für Windows 95 und Windows NT 4 oder später zu. -#define WINVER 0x0400 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen. +#define WINVER 0x0501 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen. #endif #ifndef _WIN32_WINNT // Lassen Sie die Verwendung von Features spezifisch für Windows NT 4 oder später zu. //#define _WIN32_WINNT 0x0400 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen. -#define _WIN32_WINNT 0x0500 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen. +#define _WIN32_WINNT 0x0501 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen. #endif #ifndef _WIN32_WINDOWS // Lassen Sie die Verwendung von Features spezifisch für Windows 98 oder später zu. diff --git a/Hazard/Hazard/Hazard.cpp b/Hazard/Hazard/Hazard.cpp index c717bbc..6b7a6a5 100644 --- a/Hazard/Hazard/Hazard.cpp +++ b/Hazard/Hazard/Hazard.cpp @@ -83,7 +83,7 @@ void user_main(void) Wertetabelle* wt = new Wertetabelle(allCells, variables); wt->Print(); - KV* kv = new KV(globalPIC, allCells, 30); + KV* kv = new KV(globalPIC, allCells, 30,variables); kv->Print(30); //system("pause"); @@ -92,7 +92,7 @@ void user_main(void) allCells->findHazards(); //system("pause"); - + // print Wertetabelle and KV of corrected data wt->Print(); delete wt; @@ -104,6 +104,7 @@ void user_main(void) allCells->Dispose(); delete globalPIC; delete allCells; + //delete [] variables; @ Johnny: Warum soll ich diese Auskommentierung nicht aktieren?? pause(); return; diff --git a/Hazard/Hazard/KV.cpp b/Hazard/Hazard/KV.cpp index bc2ee8e..d898bcc 100644 --- a/Hazard/Hazard/KV.cpp +++ b/Hazard/Hazard/KV.cpp @@ -28,6 +28,7 @@ void KV::Print(uint offsetX, uint offsetY) this->offsetY = offsetY; this->PrintRaster(); + this->PrintString_Var(); this->PrintVariables(); this->PrintCellValues(); this->PrintPrimImplikanten(); @@ -45,7 +46,7 @@ uint KV::height() } - +/* void KV::PrintRaster() // Erstellt die Felder: ▯▯▯ { // ▯▯▯ // ▯▯▯ @@ -65,10 +66,87 @@ void KV::PrintRaster() // Erstellt die Felder: ▯▯▯ } } +*/ + +//------------------------------------------------------------ + +void KV::Setstring_Var(){ + + this->string_VarY = ""; + this->string_VarX = ""; + + for (uint i = 0; i < this->variables->size(); i++) { + + if (i > this->numVarY-1) { + this->string_VarX += this->variables->at(i) + " "; + } + else { + this->string_VarY += this->variables->at(i) + " "; + + + } + } + + // Weitere Initialisierung der restlichen privaten Klassenelemente. + + this->VarY_Length = max(this->edgeLength+1, this->string_VarY.size() * 10); + this->VarX_Length = max(this->edgeLength+1, this->string_VarX.size() * 10); + +} + +void KV::PrintRaster() // Erstellt die Felder: ▯▯▯ +{ // ▯▯▯ + // ▯▯▯ + + + this->Line(0, this->VarX_Length, 0, this->heightPx, BLACK); // first vertical line, one edge shorter + this->Line(this->VarY_Length, 0, this->VarY_Length, this->heightPx, BLACK); // second vertical line + for (uint w = 1; w <= this->numFieldX ; w++) // vertical lines. Periodic with (edgeLength + 1) + { + uint X = w * (this->edgeLength + 1) + VarY_Length; // X position of the line + this->Line(X, 0, X, this->heightPx, BLACK); + } + + + this->Line(this->VarY_Length, 0, this->widthPx, 0, BLACK); // first horizontal line, one edge shorter + this->Line(0, this->VarX_Length, this->widthPx, this->VarX_Length, BLACK); // +10 to avoid the strings coliision + // second horizontal line + for (uint h = 1; h <= this->numFieldY ; h++) // horizontal lines. Periodic with (edgeLength + 1) + { + uint Y = h * (this->edgeLength + 1) + this->VarX_Length; // Y position of the line + this->Line(0, Y, this->widthPx, Y, BLACK); + } +} + +void KV::PrintString_Var(){ + + char* valueY = (char*)this->string_VarY.c_str(); + char* valueX= (char*)this->string_VarX.c_str(); + uint x1_valueY = 0; // coordinante of ValueY + uint y1_valueY = this->VarX_Length-12; + uint x2_valueY = this->VarY_Length; + uint y2_valueY = VarX_Length; + + + uint x1_valueX = 0; // coordinante of ValueX + uint y1_valueX = 0; + uint x2_valueX = VarY_Length; + uint y2_valueX = VarX_Length/3; + + this->TextBoxBold(x1_valueY, y1_valueY, x2_valueY, y2_valueY, 10, BLACK, TRANS, TRANS, CENTER, valueY); + this->TextBoxBold(x1_valueX, y1_valueX, x2_valueX, y2_valueX, 10, BLACK, BLACK, TRANS,CENTER, valueX); + + //this->Text(x1_valueX, y1_valueX, 10, BLACK,TRANS, 90, CENTER, valueX); + + // this->Text(x1_valueY, y1_valueY, 10, BLACK, TRANS, 0, int align, char* theText) + + +} +/* void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- und Y-Spalte: â–¯ 0 1 { // 0 ▯▯ // 1 ▯▯ - for (uint w = 0; w < this->numFieldX; w++) // vertical variable text + for (uint w = 0; w < this->numFieldX; w++) // horizontal variable text { uint XL = (w + 1) * (this->edgeLength + 1); uint XR = XL + this->edgeLength; @@ -78,7 +156,7 @@ void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- u } - for (uint h = 0; h < this->numFieldY; h++) // horizontal variable text + for (uint h = 0; h < this->numFieldY; h++) // vertical variable text { uint YT = (h + 1) * (this->edgeLength + 1); uint YB = YT + this->edgeLength; @@ -87,7 +165,35 @@ void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- u delete value; } } +*/ +//---------------------------------------------- +void KV::PrintVariables() // Erstellt die Werte der Variablen in der ersten X- und Y-Spalte: â–¯ 0 1 +{ // 0 ▯▯ + // 1 ▯▯ + for (uint w = 0; w < this->numFieldX; w++) // horizontal variable text + { + 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 + this->TextBoxBold(XL, 0, XR, this->edgeLength, 10, BLACK, TRANS, TRANS, CENTER, value); + delete value; + } + + + for (uint h = 0; h < this->numFieldY; h++) // vertical variable text + { + uint YT = h * (this->edgeLength + 1) + this->VarX_Length; + uint YB = YT + this->edgeLength; + char* value = this->Binary(h ^ (h / 2), this->numVarY); // in Gray und String umwandeln + this->TextBoxBold(0, YT, this->edgeLength, YB, 10, BLACK, TRANS, TRANS, CENTER, value); + delete value; + } +} + +//------------------------------------------------------------ + +/* void KV::PrintCellValues() // Erstellt die Werte der jeweiligen Zellen: ▯▯▯ { // â–¯ x x // â–¯ x x @@ -104,6 +210,40 @@ void KV::PrintCellValues() // Erstellt die Werte der jeweiligen Zellen: ▯▯ uint i = ((h^h/2) * this->numFieldX) | (w^w/2); // w und h müssen getrennt in Gray umgewandelt werden (weil sie so aufgetragen wurden, siehe ) // zusammengesetzt ergeben sie dann unsere aktuelle Position + // Dies sind die Zellnummern: + /* + 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); + // später muss ich die Auskommentierung schließen. + + // 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::PrintCellValues() // Erstellt die Werte der jeweiligen Zellen: ▯▯▯ +{ // â–¯ 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 + uint YB = YT + this->edgeLength; + + for (uint w = 0; w < this->numFieldX; w++) // jede Zeile durchgehen + { + uint XL = w * (this->edgeLength + 1) + this->VarY_Length; // X Positionen berechnen + uint XR = XL + this->edgeLength; + + uint i = ((h^h / 2) * this->numFieldX) | (w^w / 2); // w und h müssen getrennt in Gray umgewandelt werden (weil sie so aufgetragen wurden, siehe ) + // zusammengesetzt ergeben sie dann unsere aktuelle Position + // Dies sind die Zellnummern: /* char* I = new char[(int)(ceil(log10((float)numElements)))+1]; @@ -120,6 +260,7 @@ void KV::PrintCellValues() // Erstellt die Werte der jeweiligen Zellen: ▯▯ } } +/* void KV::PrintPrimImplikanten() { srand(time(NULL)); @@ -138,12 +279,17 @@ void KV::PrintPrimImplikanten() if (w == 0) overflow |= 0x1; // left side - else if (w == this->numVarX) + else if (w == this->numFieldX-1) overflow |= 0x2; // right side + else + overflow |= 0x4; + if (h == 0) overflow |= 0x10; // upper side - else if (h == this->numVarY) + else if (h == this->numFieldY-1) overflow |= 0x20; // lower side + else + overflow |= 0x40; } switch (overflow) @@ -196,7 +342,88 @@ void KV::PrintPrimImplikanten() } +*/ +//-------------------------------------------------------------- +void KV::PrintPrimImplikanten() +{ + srand(time(NULL)); + for (uint i = 0; i < this->globalPic->size(); i++) + { + PrimImplikant* currentPI = this->globalPic->at(i); + + uint overflow = 0; // at which sides the PrimImplikant overlaps + for (uint j = 0; j < currentPI->implikanten.size(); j++) + { + uint currentI = currentPI->implikanten[j]; + uint w = (currentI & ((0x1 << (this->numVarX)) - 1)); // get all bits that make X (=w) + w ^= w / 2; + uint h = (currentI >> this->numVarX); // get all bits that make Y (=h) + h ^= h / 2; + + if (w == 0) + overflow |= 0x1; // left side + else if (w == this->numFieldX - 1) + overflow |= 0x2; // right side + else + overflow |= 0x4; + + if (h == 0) + overflow |= 0x10; // upper side + else if (h == this->numFieldY - 1) + overflow |= 0x20; // lower side + else + overflow |= 0x40; + } + + switch (overflow) + { + case 0x33: // all 4 edges + break; + case 0x30: // overflows from top to bottom + break; + case 0x03: // overflows from left to right + break; + default: + uint X1 = -1, X2 = 0, Y1 = -1, Y2 = 0; // find coordinates for Rechteck + for (uint j = 0; j < currentPI->implikanten.size(); j++) + { + uint currentI = currentPI->implikanten[j]; + uint w = (currentI & ((0x1 << (this->numVarX)) - 1)); // get all bits that make X (=w) + w ^= w / 2; + uint h = (currentI >> this->numVarX); // get all bits that make Y (=h) + h ^= h / 2; + + uint x1 = w * (this->edgeLength + 1) + this->VarY_Length; // Upper coord + uint x2 = x1 + this->edgeLength; // Lower coord + uint y1 = h * (this->edgeLength + 1) + this->VarX_Length; // Left coord + uint y2 = y1 + this->edgeLength; // Right coord + + X1 = min(X1, x1); + X2 = max(X2, x2); + Y1 = min(Y1, y1); + Y2 = max(Y2, y2); + } + + if (currentPI->name.find("|") != string::npos) + { + this->Rechteck(X1 + 12, Y1 + 9, X2 - 12, Y2 - 9, RED, TRANS); + } + else + { + uint random = rand() % 10; + X1 += random; + X2 -= random; + Y1 += random; + Y2 -= random; + if (currentPI->implikanten.size() == 1) + this->Rechteck(X1, Y1, X2, Y2, GREEN, TRANS); + else + this->Rechteck(X1, Y1, X2, Y2, BLUE, TRANS); + } + } + } +} void KV::Line(uint x1, uint y1, uint x2, uint y2, int color) @@ -233,10 +460,10 @@ char* KV::Binary(uint x, char length) char* buffer = new char[length+1]; char* p = buffer + length; - *p-- = 0; + *p = 0; do { - *p-- = '0' + (x & 1); + *--p = '0' + (x & 1); x >>= 1; } while (--length); diff --git a/Hazard/Hazard/KV.h b/Hazard/Hazard/KV.h index e3cdf13..40daf10 100644 --- a/Hazard/Hazard/KV.h +++ b/Hazard/Hazard/KV.h @@ -22,36 +22,50 @@ public: uint height(); // Gibt die Höhe eines KV-Diagramms zurück (heightPx) // Konstruktor - KV(PrimImplikantCollection* globalPic, CellCollection* allCells, uint size) - : edgeLength(size), - numVarX(((uint)floor(dimension/2.0f))), numVarY(((uint)ceil(dimension/2.0f))), - numFieldX((uint)pow(2,(float)numVarX)), numFieldY((uint)pow(2,(float)numVarY)), - widthPx((numFieldX + 1) * (this->edgeLength + 1)), heightPx((numFieldY + 1) * (this->edgeLength + 1)) + KV(PrimImplikantCollection* globalPic, CellCollection* allCells, uint size, vector* &variables) + : edgeLength(size), numVarX(((uint)floor(dimension / 2.0f))), numVarY(((uint)ceil(dimension / 2.0f))), + numFieldX((uint)pow(2, (float)numVarX)), numFieldY((uint)pow(2, (float)numVarY)) { + + + this->globalPic = globalPic; this->allCells = allCells; + this->variables = variables; + Setstring_Var(); + this->widthPx = numFieldX * (this->edgeLength + 1) + this->VarY_Length; + this->heightPx = numFieldY * (this->edgeLength + 1) + this->VarX_Length; + this->Clear(); } private: PrimImplikantCollection* globalPic; CellCollection* allCells; + vector* variables; uint offsetX; // Der freie Platz nach links in Pixeln uint offsetY; // Der freie Platz nach rechts in Pixeln + const uint edgeLength; // Die Kantenlänge der einzelnen Felder const uint numVarX; // Wieviele Variablen in X-Richtung gezeichnet werden const uint numVarY; // Wieviele Variablen in Y-Richtung gezeichnet werden - const uint numFieldX; // Wieviele Felder in X-Richtung gezeichnet werden = pow(2, numVarX) + const uint numFieldX; // Wieviele Felder in X-Richtung gezeichnet werden = pow(2, numVarX) const uint numFieldY; // Wieviele Felder in Y-Richtung gezeichnet werden = pow(2, numVarY) - const uint widthPx; // Breite des KV-Diagramms in Pixeln - const uint heightPx; // Höhe des KV-Diagramms in Pixeln + uint widthPx; // Breite des KV-Diagramms in Pixeln + uint heightPx; // Höhe des KV-Diagramms in Pixeln + uint VarX_Length; // Höhe der Variablen in X-Richtung in Pixeln + uint VarY_Length; // Breite der Variablen in Y-Richtung in Pixeln + string string_VarX; // Variables_String in X-Richtung + string string_VarY; // Variables_String in Y_Richtung + void Setstring_Var(); // Einfuegen von String_Varx & String_VarY mit Variables. void PrintRaster(); // Erstellt die Felder void PrintVariables(); // Erstellt die Werte der Variablen in der ersten X- und Y-Spalte void PrintCellValues(); // Erstellt die Werte der jeweiligen Zellen void PrintPrimImplikanten(); // Erstellt die einzelnen Primimplikanten + void PrintString_Var(); // Erstellt den horizontalen TextVariable & vertikalen Textvariable void Clear(); void Line(uint x1, uint y1, uint x2, uint y2, int color); // Zeichnet eine Linie mit Offset