2013-11-29 01:54:13 +01:00
# include " stdafx.h "
# include <vector>
# include "Cell.h"
# include "PrimImplikantCollection.h"
# include "..\..\GDE_3_2008\graphics\graphicfunctions.h"
# include "KV.h"
extern uint dimension ;
extern uint numElements ;
extern bool KNF ;
2013-12-23 02:51:37 +01:00
using namespace std ;
2013-11-29 01:54:13 +01:00
void KV : : Clear ( )
{
int ww , hh ;
get_windowsize ( & ww , & hh ) ;
set_drawarea ( ww , hh ) ; // Setzen des Zeichenbereiches
clrscr ( ) ; // Clear screen
}
void KV : : Print ( uint offset )
{
this - > Print ( offset , offset ) ;
}
void KV : : Print ( uint offsetX , uint offsetY )
{
this - > offsetX = offsetX ;
this - > offsetY = offsetY ;
this - > PrintRaster ( ) ;
2013-12-17 19:06:36 +01:00
this - > PrintString_Var ( ) ;
2013-11-29 01:54:13 +01:00
this - > PrintVariables ( ) ;
this - > PrintCellValues ( ) ;
this - > PrintPrimImplikanten ( ) ;
updatescr ( ) ; // make this f****** GDE update, does not work everytime :/
}
uint KV : : width ( )
{
return this - > widthPx ;
}
uint KV : : height ( )
{
return this - > heightPx ;
}
2013-12-17 20:18:27 +01:00
void KV : : Setstring_Var ( )
{
2013-12-17 19:06:36 +01:00
this - > string_VarY = " " ;
this - > string_VarX = " " ;
2013-12-17 20:18:27 +01:00
for ( uint i = 0 ; i < this - > variables - > size ( ) ; i + + )
{
if ( i > = this - > numVarY )
2013-12-17 19:06:36 +01:00
this - > string_VarX + = this - > variables - > at ( i ) + " " ;
2013-12-17 20:18:27 +01:00
else
2013-12-17 19:06:36 +01:00
this - > string_VarY + = this - > variables - > at ( i ) + " " ;
}
2013-12-17 20:18:27 +01:00
this - > string_VarX = this - > string_VarX . substr ( 0 , this - > string_VarX . size ( ) - 1 ) ;
this - > string_VarY = this - > string_VarY . substr ( 0 , this - > string_VarY . size ( ) - 1 ) ;
2013-12-17 19:06:36 +01:00
// Weitere Initialisierung der restlichen privaten Klassenelemente.
2013-12-17 20:18:27 +01:00
this - > VarX_Length = max ( this - > edgeLength + 1 , this - > string_VarX . size ( ) * 9 ) ;
this - > VarY_Length = max ( this - > edgeLength + 1 , this - > string_VarY . size ( ) * 9 ) ;
2013-12-17 19:06:36 +01:00
}
void KV : : PrintRaster ( ) // Erstellt die Felder: ▯▯▯
{ // ▯▯▯
2013-12-17 20:18:27 +01:00
// ▯▯▯
2013-12-17 19:06:36 +01:00
2013-12-17 20:18:27 +01:00
this - > Line ( this - > VarY_Length , 0 , this - > VarY_Length , this - > heightPx , BLACK ) ; // first vertical line, one edge shorter
this - > Line ( 0 , this - > VarX_Length , 0 , this - > heightPx , BLACK ) ; // second vertical line
for ( uint w = 1 ; w < = this - > numFieldX ; w + + ) // vertical lines. Periodic with (edgeLength + 1)
2013-12-17 19:06:36 +01:00
{
uint X = w * ( this - > edgeLength + 1 ) + VarY_Length ; // X position of the line
this - > Line ( X , 0 , X , this - > heightPx , BLACK ) ;
}
2013-12-17 20:18:27 +01:00
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 collision
// second horizontal line
for ( uint h = 1 ; h < = this - > numFieldY ; h + + ) // horizontal lines. Periodic with (edgeLength + 1)
2013-12-17 19:06:36 +01:00
{
2013-12-17 20:18:27 +01:00
uint Y = h * ( this - > edgeLength + 1 ) + this - > VarX_Length ; // Y position of the line
2013-12-17 19:06:36 +01:00
this - > Line ( 0 , Y , this - > widthPx , Y , BLACK ) ;
}
}
2013-12-17 20:18:27 +01:00
void KV : : PrintString_Var ( )
{
2013-12-17 19:06:36 +01:00
char * valueY = ( char * ) this - > string_VarY . c_str ( ) ;
char * valueX = ( char * ) this - > string_VarX . c_str ( ) ;
2013-12-17 20:18:27 +01:00
uint x1_valueY = 2 ; // coordinante of ValueY
uint y1_valueY = this - > VarX_Length - 16 ;
2013-12-17 19:06:36 +01:00
2013-12-17 20:18:27 +01:00
uint x1_valueX = this - > VarY_Length - 16 ; // coordinante of ValueX
uint y1_valueX = this - > VarX_Length - 12 ;
2013-12-17 19:06:36 +01:00
2013-12-17 20:18:27 +01:00
this - > Text ( x1_valueX , y1_valueX , 10 , BLACK , WHITE , 90 , 0 , valueX ) ;
this - > Text ( x1_valueY , y1_valueY , 10 , BLACK , WHITE , 00 , 0 , valueY ) ;
2013-12-17 19:06:36 +01:00
}
void KV : : PrintVariables ( ) // Erstellt die Werte der Variablen in der ersten X- und Y-Spalte: ▯ 0 1
{ // 0 ▯▯
2013-12-17 20:18:27 +01:00
// 1 ▯▯
for ( uint w = 0 ; w < this - > numFieldX ; w + + ) // horizontal variable text
2013-12-17 19:06:36 +01:00
{
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
2013-12-17 20:18:27 +01:00
this - > TextBoxBold ( XL , 0 , XR , this - > VarX_Length , 10 , BLACK , TRANS , TRANS , SINGLE_LINE | CENTER_ALIGN | BOTTOM_ALIGN , value ) ;
2013-12-17 19:06:36 +01:00
delete value ;
}
2013-11-29 01:54:13 +01:00
2013-12-17 20:18:27 +01:00
for ( uint h = 0 ; h < this - > numFieldY ; h + + ) // vertical variable text
2013-12-17 19:06:36 +01:00
{
2013-12-17 20:18:27 +01:00
uint YT = h * ( this - > edgeLength + 1 ) + this - > VarX_Length + 1 ;
2013-12-17 19:06:36 +01:00
uint YB = YT + this - > edgeLength ;
char * value = this - > Binary ( h ^ ( h / 2 ) , this - > numVarY ) ; // in Gray und String umwandeln
2013-12-17 20:18:27 +01:00
this - > TextBoxBold ( 0 , YT , this - > VarY_Length - 5 , YB , 10 , BLACK , TRANS , TRANS , SINGLE_LINE | RIGHT_ALIGN | VCENTER_ALIGN , value ) ;
2013-12-17 19:06:36 +01:00
delete value ;
}
}
//---------------------------------------------------------------
void KV : : PrintCellValues ( ) // Erstellt die Werte der jeweiligen Zellen: ▯▯▯
{ // ▯ x x
2013-12-17 20:18:27 +01:00
// ▯ x x
for ( uint h = 0 ; h < this - > numFieldY ; h + + ) // jede Spalte durchgehen
2013-12-17 19:06:36 +01:00
{
2013-12-17 20:18:27 +01:00
uint YT = h * ( this - > edgeLength + 1 ) + this - > VarX_Length ; // Y Positionen berechnen
2013-12-17 19:06:36 +01:00
uint YB = YT + this - > edgeLength ;
2013-12-17 20:18:27 +01:00
for ( uint w = 0 ; w < this - > numFieldX ; w + + ) // jede Zeile durchgehen
2013-12-17 19:06:36 +01:00
{
2013-12-17 20:18:27 +01:00
uint XL = w * ( this - > edgeLength + 1 ) + this - > VarY_Length ; // X Positionen berechnen
2013-12-17 19:06:36 +01:00
uint XR = XL + this - > edgeLength ;
2013-12-17 20:18:27 +01:00
uint i = ( ( h ^ h / 2 ) < < this - > numVarX ) | ( w ^ w / 2 ) ; // w und h müssen getrennt in Gray umgewandelt werden (weil sie so aufgetragen wurden)
2013-12-17 19:06:36 +01:00
// zusammengesetzt ergeben sie dann unsere aktuelle Position
2013-11-29 01:54:13 +01:00
// 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 ) ;
*/
// Dies sind die Zellwerte:
char * I = new char [ 2 ] ;
2013-12-02 01:41:44 +01:00
_itoa_s ( this - > allCells - > at ( i ) - > value , I , 2 , 10 ) ;
this - > TextBox ( XL , YT , XR , YB , 10 , BLACK , TRANS , TRANS , CENTER , I ) ;
2013-11-29 01:54:13 +01:00
delete I ;
}
}
}
2013-12-17 19:06:36 +01:00
void KV : : PrintPrimImplikanten ( )
{
2013-12-23 02:51:37 +01:00
srand ( time ( NULL ) + rand ( ) ) ;
2013-12-17 19:06:36 +01:00
for ( uint i = 0 ; i < this - > globalPic - > size ( ) ; i + + )
{
PrimImplikant * currentPI = this - > globalPic - > at ( i ) ;
2013-12-20 21:35:45 +01:00
/*uint overflow = 0; // at which sides the PrimImplikant overlaps
2013-12-17 19:06:36 +01:00
for ( uint j = 0 ; j < currentPI - > implikanten . size ( ) ; j + + )
{
2013-12-23 02:51:37 +01:00
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 ;
2013-12-17 19:06:36 +01:00
2013-12-23 02:51:37 +01:00
if ( h = = 0 )
overflow | = 0x10 ; // upper side
else if ( h = = this - > numFieldY - 1 )
overflow | = 0x20 ; // lower side
else
overflow | = 0x40 ;
2013-12-17 19:06:36 +01:00
}
switch ( overflow )
{
case 0x33 : // all 4 edges
2013-12-23 02:51:37 +01:00
break ;
2013-12-17 19:06:36 +01:00
case 0x30 : // overflows from top to bottom
2013-12-23 02:51:37 +01:00
break ;
2013-12-17 19:06:36 +01:00
case 0x03 : // overflows from left to right
2013-12-23 02:51:37 +01:00
break ;
2013-12-17 19:06:36 +01:00
default :
2013-12-20 21:35:45 +01:00
*/
// ab hier mache ich später weiter. Ich habe wieder Kopfschmerzen!!!
2013-12-23 02:51:37 +01:00
// uint X1 = -1, X2 = 0, Y1 = -1, Y2 = 0; // find coordinates for Rechteck
for ( uint j = 0 ; j < currentPI - > PI_groupCollection . size ( ) ; j + + )
{
vector < Implikant_localisation * > * kullers = currentPI - > PI_groupCollection [ j ] ;
2013-12-23 11:40:27 +01:00
uint X1 = - 1 , X2 = 0 , Y1 = - 1 , Y2 = 0 ;
2013-12-23 02:51:37 +01:00
2013-12-23 14:03:44 +01:00
for ( vector < Implikant_localisation * > : : iterator it = kullers - > begin ( ) ; it < kullers - > end ( ) ; it + + )
{
2013-12-23 11:40:27 +01:00
2013-12-23 02:51:37 +01:00
2013-12-23 14:03:44 +01:00
uint x1 = ( * it ) - > w * ( this - > edgeLength + 1 ) + this - > VarY_Length ; // Upper coord
uint x2 = x1 + this - > edgeLength ; // Lower coord
uint y1 = ( * it ) - > h * ( this - > edgeLength + 1 ) + this - > VarX_Length ; // Left coord
uint y2 = y1 + this - > edgeLength ; // Right coo
2013-12-20 21:35:45 +01:00
2013-12-23 14:03:44 +01:00
X1 = min ( X1 , x1 ) ;
X2 = max ( X2 , x2 ) ;
Y1 = min ( Y1 , y1 ) ;
Y2 = max ( Y2 , y2 ) ;
2013-12-23 02:51:37 +01:00
}
2013-12-23 19:33:41 +01:00
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 ) ;
}
2013-12-23 14:03:44 +01:00
2013-12-23 02:51:37 +01:00
}
}
}
2013-12-20 21:35:45 +01:00
2013-12-23 02:51:37 +01:00
/*
2013-12-20 21:35:45 +01:00
uint w = currentPI - > PI_groupCollection // get all bits that make X (=w)
2013-12-17 19:06:36 +01:00
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
2013-12-20 21:35:45 +01:00
uint y2 = y1 + this - > edgeLength ; // Right coo
2013-12-17 19:06:36 +01:00
X1 = min ( X1 , x1 ) ;
X2 = max ( X2 , x2 ) ;
Y1 = min ( Y1 , y1 ) ;
Y2 = max ( Y2 , y2 ) ;
}
2013-11-29 01:54:13 +01:00
2013-12-17 19:06:36 +01:00
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 ) ;
}
}
}
}
2013-11-29 01:54:13 +01:00
2013-12-20 00:56:48 +01:00
//------------------------------------------------------------------
2013-11-29 01:54:13 +01:00
2013-12-20 00:56:48 +01:00
2013-12-23 02:51:37 +01:00
*/
2013-12-20 00:56:48 +01:00
2013-11-29 01:54:13 +01:00
void KV : : Line ( uint x1 , uint y1 , uint x2 , uint y2 , int color )
{
line ( x1 + this - > offsetX , y1 + this - > offsetY , x2 + this - > offsetX , y2 + this - > offsetY , color ) ;
}
void KV : : Text ( uint x , uint y , uint size , int color , int bkcolor , int angle , int align , char * theText )
{
text ( x + this - > offsetX , y + this - > offsetY , size , color , bkcolor , angle , align , theText ) ;
}
void KV : : TextBox ( uint x1 , uint y1 , uint x2 , uint y2 , uint size , int ctext , int cframe , int cfill , int flags , char * theText )
{
textbox ( x1 + this - > offsetX + 1 , y1 + this - > offsetY , x2 + this - > offsetX + 1 , y2 + this - > offsetY , size , ctext , cframe , cfill , flags , theText ) ;
}
void KV : : TextBoxBold ( uint x1 , uint y1 , uint x2 , uint y2 , uint size , int ctext , int cframe , int cfill , int flags , char * theText )
{
textbox ( x1 + this - > offsetX + 1 , y1 + this - > offsetY , x2 + this - > offsetX + 1 , y2 + this - > offsetY , size , ctext , cframe , cfill , flags , theText ) ;
2013-12-02 01:41:44 +01:00
textbox ( x1 + this - > offsetX + 2 , y1 + this - > offsetY , x2 + this - > offsetX + 2 , y2 + this - > offsetY , size , ctext , TRANS , TRANSPARENT , flags , theText ) ; // write twice to simulate bold font
2013-11-29 01:54:13 +01:00
}
2013-12-02 00:10:15 +01:00
void KV : : Rechteck ( uint x1 , uint y1 , uint x2 , uint y2 , int cframe , int cfill )
{
2013-12-02 01:41:44 +01:00
rectangle ( x1 + this - > offsetX + 1 , y1 + this - > offsetY + 1 , x2 + this - > offsetX + 1 , y2 + this - > offsetY + 1 , cframe , cfill ) ;
2013-12-02 00:10:15 +01:00
}
2013-11-29 01:54:13 +01:00
char * KV : : Binary ( uint x , char length )
{
2013-12-17 20:18:27 +01:00
// warning: this breaks for numbers with more than 64 bits
char * buffer = new char [ length + 1 ] ;
char * p = buffer + length ;
2013-11-29 01:54:13 +01:00
2013-12-17 19:06:36 +01:00
* p = 0 ;
2013-12-17 20:18:27 +01:00
do
{
* - - p = ' 0 ' + ( x & 1 ) ;
2013-11-29 01:54:13 +01:00
x > > = 1 ;
2013-12-17 20:18:27 +01:00
} while ( - - length ) ;
2013-11-29 01:54:13 +01:00
2013-12-17 20:18:27 +01:00
return buffer ;
2013-11-29 01:54:13 +01:00
}