#ifndef STARE_TABLE_H_INCLUDED #define STARE_TABLE_H_INCLUDED ///LIBRARIES #include #include #include #include #include #include #include #include #include #include #include "drawing_components.h" #include "functii_auxiliare.h" using namespace std; //Tudor Ilade - in afara de functiile facute de Andrei struct punctLegatura { int type; int x,y; int xConnection, yConnection; int ndxParent; int sd; }; typedef struct RECTANGLE { float left; float top; float right; float bottom; int xCenter; int yCenter; }; struct SWITCHSTATE{ int bulb=2; bool inOut; }; typedef struct RECTANGLE_FULL { struct { float x, y; } left_top, right_top, left_bottom, right_bottom; } RECTANGLE_FULL; struct BinaryCMP { int type; char name[512]; int x; int y; float R; int angle; float zoom; int value=0; bool conectat; RECTANGLE outsideRect; RECTANGLE rect; RECTANGLE nodes[3]; RECTANGLE_FULL coordinates[4]; int size_of_linkings; punctLegatura legatura[256]; }; struct COMPONENTE { int type; char name[512]; int x1; int y1; float R; int nr_puncte_legatura; bool connectat; int angle=0; float zoom=1.0; int value=0; RECTANGLE nodes[3]; RECTANGLE_FULL coordinates[4]; RECTANGLE rect; RECTANGLE outsideRect; vector>legatura; }; struct SITUATIA_TABLEI { int ans; char path_file[1024]; char path_to_dir[1024]; bool open=false; bool light = false; vector v; vector>p; }; struct HISTORY { stackUNDO; stackREDO; stackLOG; }; //Andrei Cerbu struct RECTANGLE_FULL generate_coordinates_full(struct componenta CMP) { struct RECTANGLE_FULL structt; structt.left_top.x=CMP.points[0]; structt.left_top.y=CMP.points[1]; structt.right_top.x=CMP.points[2]; structt.right_top.y=CMP.points[3]; structt.right_bottom.x=CMP.points[4]; structt.right_bottom.y=CMP.points[5]; structt.left_bottom.x=CMP.points[6]; structt.left_bottom.y=CMP.points[7]; return structt; } struct RECTANGLE generate_coordinates(struct componenta CMP) { struct RECTANGLE RECT; RECT.left=CMP.points[0]; RECT.top=CMP.points[1]; RECT.right=CMP.points[4]; RECT.bottom=CMP.points[5]; RECT.xCenter=(CMP.points[0]+CMP.points[4])/2; RECT.yCenter=(CMP.points[1]+CMP.points[5])/2; return RECT; } struct RECTANGLE initialize_RECT() { struct RECTANGLE RECT; RECT.left=1000000.0; RECT.top=1000000.0; RECT.bottom=0.0; RECT.right=0.0; return RECT; } RECTANGLE generate_maximum_rotation(int W, int H, float R, int X, int Y, float zoom, int type) { RECTANGLE RECT; componenta CMP; RECT = initialize_RECT(); if(type!=9) { for(int i=0; i>=-90; i--) { int width = W/8, height = H/4; float w1, w2, h1, h2, w, h; dreptunghi D; coordonate C; C.x=X, C.y=Y; w1=-(width*4-width/1.7)*R*zoom+X, w2=(width*4-width/1.7)*R*zoom+X, h1=-(height*2-height/2.7)*R*zoom+Y, h2=(height*2-height/2.7)*R*zoom+Y; D=create_struct_rectangle(w1,w2,h1,h2); D=translate_rectangle(D,C); CMP=RotateRectangle(C,D,i,1); RECT.left=min(RECT.left,CMP.points[6]); RECT.top=min(RECT.top,CMP.points[1]); RECT.right=max(RECT.right,CMP.points[2]); RECT.bottom=max(RECT.bottom,CMP.points[5]); } } else if(type==9) { for(int i=0; i>=-90; i--) { int width = W/8, height = H/4; float w1, w2, h1, h2, w, h; dreptunghi D; coordonate C; C.x=X, C.y=Y; w1=-2*width*R*zoom+X, w2=width*R*zoom+X, h1=-(height*2-height/2.7)*R*zoom+Y, h2=(height*2-height/2.7)*R*zoom+Y; D=create_struct_rectangle(w1,w2,h1,h2); D=translate_rectangle(D,C); CMP=RotateRectangle(C,D,i,1); RECT.left=min(RECT.left,CMP.points[6]); RECT.top=min(RECT.top,CMP.points[1]); RECT.right=max(RECT.right,CMP.points[2]); RECT.bottom=max(RECT.bottom,CMP.points[5]); } } return RECT; } void generate_rectangle_full_struct(struct RECTANGLE_FULL RECT_FULL[], componenta CMP[], int type) { if(type!=9) { RECT_FULL[1]=generate_coordinates_full(CMP[1]); RECT_FULL[2]=generate_coordinates_full(CMP[2]); RECT_FULL[3]=generate_coordinates_full(CMP[3]); } else if(type==9) { RECT_FULL[1]=generate_coordinates_full(CMP[1]); RECT_FULL[2]=generate_coordinates_full(CMP[2]); RECT_FULL[3]=generate_coordinates_full(CMP[3]); RECT_FULL[4]=generate_coordinates_full(CMP[4]); } } void generate_rectangle_struct(RECTANGLE RECT[], componenta CMP[], int type) { if(type!=9) { RECT[1]=generate_coordinates(CMP[1]); RECT[2]=generate_coordinates(CMP[2]); RECT[3]=generate_coordinates(CMP[3]); } else if(type==9) { RECT[1]=generate_coordinates(CMP[1]); RECT[2]=generate_coordinates(CMP[2]); RECT[3]=generate_coordinates(CMP[3]); RECT[4]=generate_coordinates(CMP[4]); } } int convert_y_to_angle(int y, int top_fader) { return (top_fader-y)*3; } int convert_angle_to_y(int angle, int top_fader) { //if(angle == 0) return top_fader-angle/3; } float convert_y_to_zoom(int y, int center_fader) { float conversion; y=-(y-center_fader); conversion=1.0*y/260; return conversion; } int convert_zoom_to_y(float zoom, int center_fader) { return center_fader-zoom*260; } //Tudor ILADE pana jos int getIndexOfComponent(SITUATIA_TABLEI project, int x, int y, float R) { for(int i=0; i=project.v[i].outsideRect.left && x <= project.v[i].outsideRect.right && (y>=project.v[i].outsideRect.top && y<=project.v[i].outsideRect.bottom)) { return i; } } return -1; } componenta CMP[30]; ///Verifica daca a fost dat click pe o legatura int isLinking(SITUATIA_TABLEI project, int w, int h, int x, int y, float R,componenta CMP[], int ndxCmp=-1) { int ndx = getIndexOfComponent(project, x,y,R); if(ndx == - 1) return 0; if(ndx == ndxCmp) return 0; COMPONENTE cmp = project.v[ndx]; if(cmp.type != 9) { if(x>=cmp.coordinates[1].left_top.x && x <= cmp.coordinates[1].right_bottom.x && (y>=cmp.coordinates[1].right_top.y&&y<=cmp.coordinates[1].left_bottom.y)) { return 1; } if(x>=cmp.coordinates[1].left_bottom.x && x <= cmp.coordinates[1].right_top.x && (y>=cmp.coordinates[1].left_top.y && y<=cmp.coordinates[1].right_bottom.y)) { return 1; } if(x>=cmp.coordinates[1].right_bottom.x && x <= cmp.coordinates[1].left_top.x && (y>=cmp.coordinates[1].left_bottom.y&&y<=cmp.coordinates[1].right_top.y)) { return 1; } if(x>=cmp.coordinates[1].right_top.x && x <= cmp.coordinates[1].left_bottom.x && (y>=cmp.coordinates[1].right_bottom.y&&y<=cmp.coordinates[1].left_top.y)) { return 1; } if(x>=cmp.coordinates[2].left_bottom.x && x <= cmp.coordinates[2].right_top.x && (y>=cmp.coordinates[2].left_top.y && y<=cmp.coordinates[2].right_bottom.y)) { return 2; } if(x>=cmp.coordinates[2].right_bottom.x && x <= cmp.coordinates[2].left_top.x && (y>=cmp.coordinates[2].left_bottom.y&&y<=cmp.coordinates[2].right_top.y)) { return 2; } if(x>=cmp.coordinates[2].left_top.x && x <= cmp.coordinates[2].right_bottom.x && (y>=cmp.coordinates[2].right_top.y&&y<=cmp.coordinates[2].left_bottom.y)) { return 2; } if(x>=cmp.coordinates[2].right_top.x && x <= cmp.coordinates[2].left_bottom.x && (y>=cmp.coordinates[2].right_bottom.y&&y<=cmp.coordinates[2].left_top.y)) { return 2; } return 0; } else { if(x>=cmp.coordinates[1].left_bottom.x && x <= cmp.coordinates[1].right_top.x && (y>=cmp.coordinates[1].left_top.y && y<=cmp.coordinates[1].right_bottom.y)) { return 1; } if(x>=cmp.coordinates[1].right_bottom.x && x <= cmp.coordinates[1].left_top.x && (y>=cmp.coordinates[1].left_bottom.y&&y<=cmp.coordinates[1].right_top.y)) { return 1; } if(x>=cmp.coordinates[1].left_top.x && x <= cmp.coordinates[1].right_bottom.x && (y>=cmp.coordinates[1].right_top.y&&y<=cmp.coordinates[1].left_bottom.y)) { return 1; } if(x>=cmp.coordinates[1].right_top.x && x <= cmp.coordinates[1].left_bottom.x && (y>=cmp.coordinates[1].right_bottom.y&&y<=cmp.coordinates[1].left_top.y)) { return 1; } if(x>=cmp.coordinates[2].left_bottom.x && x <= cmp.coordinates[2].right_top.x && (y>=cmp.coordinates[2].left_top.y && y<=cmp.coordinates[2].right_bottom.y)) { return 2; } if(x>=cmp.coordinates[2].right_bottom.x && x <= cmp.coordinates[2].left_top.x && (y>=cmp.coordinates[2].left_bottom.y&&y<=cmp.coordinates[2].right_top.y)) { return 2; } if(x>=cmp.coordinates[2].left_top.x && x <= cmp.coordinates[2].right_bottom.x && (y>=cmp.coordinates[2].right_top.y&&y<=cmp.coordinates[2].left_bottom.y)) { return 2; } if(x>=cmp.coordinates[2].right_top.x && x <= cmp.coordinates[2].left_bottom.x && (y>=cmp.coordinates[2].right_bottom.y&&y<=cmp.coordinates[2].left_top.y)) { return 2; } if(x>=cmp.coordinates[3].left_bottom.x && x <= cmp.coordinates[3].right_top.x && (y>=cmp.coordinates[3].left_top.y && y<=cmp.coordinates[3].right_bottom.y)) { return 3; } if(x>=cmp.coordinates[3].right_bottom.x && x <= cmp.coordinates[3].left_top.x && (y>=cmp.coordinates[3].left_bottom.y&&y<=cmp.coordinates[3].right_top.y)) { return 3; } if(x>=cmp.coordinates[3].left_top.x && x <= cmp.coordinates[3].right_bottom.x && (y>=cmp.coordinates[3].right_top.y&&y<=cmp.coordinates[3].left_bottom.y)) { return 3; } if(x>=cmp.coordinates[3].right_top.x && x <= cmp.coordinates[3].left_bottom.x && (y>=cmp.coordinates[3].right_bottom.y&&y<=cmp.coordinates[3].left_top.y)) { return 3; } return 0; } return 0; } ///Deseneaza linia de legatura void drawLine(int x1, int y1, int x2, int y2, int cul, int type) { if(type==1) { setcolor(cul); line(x1,y1,(x1+x2)/2,y1); line((x1+x2)/2,y1,(x1+x2)/2,y2); line((x1+x2)/2,y2,x2,y2); } else if(type==2) { setcolor(cul); line(x1,y1,x1,y2); line(x1,y2,x2,y2); } else if(type==3) { setcolor(cul); line(x1,y1,x2,y1); line(x2,y1,x2,y2); } else if(type==4) { setcolor(cul); line(x1,y1,x1,(y1+y2)/2); line(x1,(y1+y2)/2,x2,(y1+y2)/2); line(x2,(y1+y2)/2,x2,y2); } } ///Functie care creaza un obiect pe tabla SITUATIA_TABLEI creare_obiect(SITUATIA_TABLEI &tabla, int type, int x, int y, int w, int h, float R, RECTANGLE RECT[], RECTANGLE_FULL RECT_FULL[], RECTANGLE outSideRect) { COMPONENTE cmp; cmp.x1 = x; cmp.y1 = y; cmp.type = type; cmp.R = R; int W = w/10; int H = h/16; int width = W/8; int height = H/4; cmp.outsideRect = outSideRect; cmp.rect.bottom=RECT[1].bottom; cmp.rect.top=RECT[1].top; cmp.rect.left=RECT[1].left; cmp.rect.right=RECT[1].right; cmp.nodes[0] = RECT[2]; cmp.nodes[1] = RECT[3]; cmp.nodes[2] = RECT[4]; cmp.coordinates[0]=RECT_FULL[1]; cmp.coordinates[1]=RECT_FULL[2]; cmp.coordinates[2]=RECT_FULL[3]; cmp.coordinates[3]=RECT_FULL[4]; cmp.zoom = 1.0; tabla.v.push_back(cmp); return tabla; } ///Verifica coliziuni pe tabla bool isColision(RECTANGLE outSideRectangle,int h,int w,SITUATIA_TABLEI tabla, int R, int type, int ndxCmp = -1) { int H = h/16; int W = w/10; RECTANGLE t; int width_rectangle = w/8; int height_rectangle = h/12; t.left = width_rectangle*R; t.top = height_rectangle*R; t.right = (w-width_rectangle-width_rectangle/8)*R; t.bottom = (h-height_rectangle)*R; if(outSideRectangle.leftt.right || outSideRectangle.top < t.top || outSideRectangle.bottom > t.bottom) { return true; } if(!tabla.v.empty()) { for(int i=0; i=tabla.v[i].outsideRect.bottom&&outSideRectangle.right>=tabla.v[i].outsideRect.right) return true; if(outSideRectangle.top<=tabla.v[i].outsideRect.bottom && outSideRectangle.right>=tabla.v[i].outsideRect.left&& outSideRectangle.bottom>tabla.v[i].outsideRect.bottom&&outSideRectangle.left=tabla.v[i].outsideRect.left && outSideRectangle.left<=tabla.v[i].outsideRect.left&& outSideRectangle.top<=tabla.v[i].outsideRect.top && outSideRectangle.bottom>=tabla.v[i].outsideRect.top) return true; if(outSideRectangle.left<=tabla.v[i].outsideRect.right && outSideRectangle.right>=tabla.v[i].outsideRect.right&& outSideRectangle.bottom>=tabla.v[i].outsideRect.top && outSideRectangle.top<=tabla.v[i].outsideRect.top) return true; if(outSideRectangle.left>=tabla.v[i].outsideRect.left&&outSideRectangle.right<=tabla.v[i].outsideRect.right&& outSideRectangle.bottom>=tabla.v[i].outsideRect.top&&outSideRectangle.top<=tabla.v[i].outsideRect.top) return true; if(outSideRectangle.left>=tabla.v[i].outsideRect.left&&outSideRectangle.right<=tabla.v[i].outsideRect.right&& outSideRectangle.top<=tabla.v[i].outsideRect.bottom&&outSideRectangle.bottom>=tabla.v[i].outsideRect.bottom) return true; if(outSideRectangle.right>=tabla.v[i].outsideRect.left&&outSideRectangle.left<=tabla.v[i].outsideRect.left&& outSideRectangle.top>=tabla.v[i].outsideRect.top&&outSideRectangle.bottom<=tabla.v[i].outsideRect.bottom) return true; if(outSideRectangle.left<=tabla.v[i].outsideRect.right&&outSideRectangle.right>=tabla.v[i].outsideRect.right&& outSideRectangle.top>=tabla.v[i].outsideRect.top&&outSideRectangle.bottom<=tabla.v[i].outsideRect.bottom) return true; } } } return false; } ///Sterge tabla si tot ce a fost desenat SITUATIA_TABLEI stergere_tabla(SITUATIA_TABLEI tabla) { tabla.v.clear(); tabla.p.clear(); return tabla; } ///Deseneaza componentele ce au fost luate prin citirea fisierului binar void draw_components_from_file(SITUATIA_TABLEI tabla, int W, int H) { struct componenta CMP[30]; for(int i=0; i0) for(int i=0; i=project.v[i].outsideRect.left && x <= project.v[i].outsideRect.right&& (y>=project.v[i].outsideRect.top&&y<=project.v[i].outsideRect.bottom)) return project.v[i].type; } return 0; } void drawComponentsXSelected(SITUATIA_TABLEI project, int ndx, int W, int H, int R, int color) { componenta CMP[30]; for(int i=0; it.right || y < t.top || y > t.bottom) return 1; return 0; } RECTANGLE t; int H = h/16; int W = w/10; int width_r = W/8*R; int height_r = H/4*R; int width_rectangle = w/8; int height_rectangle = h/12; t.left = width_rectangle*R; t.top = height_rectangle*R; t.right = 7*width_rectangle*R; t.bottom = 11*height_rectangle*R; if(outSideRect.leftt.right+10|| outSideRect.top < t.top-34 || outSideRect.bottom > t.bottom + 34) return 1; return 0; } void draw_moving_line(SITUATIA_TABLEI project, int ndxCmp, int color, int W, int H, int R, RECTANGLE RECT[]) { for(int i = 0; i ndx) project.p[i].first.ndxParent-=1; if(project.p[i].second.ndxParent > ndx) project.p[i].second.ndxParent-=1; } for(int i = 0; i < project.v.size(); i++) for(int j=0; j ndx) { project.v[i].legatura[j].first.ndxParent--; } if(project.v[i].legatura[j].second.ndxParent > ndx) { project.v[i].legatura[j].second.ndxParent--; } } return project; } int checkLineTypeLink(int type, int x, int y, int x1, int y1, int x2, int y2) { if(type==1) { if(x>x1 && x <= (x1+x2)/2 && y y1-3) return 1; if(x (x1+x2)/2 && y y1-3) return 1; if(x>(x1+x2)/2-3 && x<(x1+x2)/2+3 && yy2) return 1; if(x>(x1+x2)/2-3 && x<(x1+x2)/2+3 && y>y1 && y(x1+x2)/2 && x < x2 && y y2-3) return 1; if(x < (x1+x2)/2 && x > x2 && y y2-3) return 1; return 0; } else if(type == 2) { if(x>x1-3 && x=y1 && y<=y2) return 2; if(x>x1-3 && x=y2) return 2; if(x>x1 && xy2-3 && y < y2 + 3) return 2; if(xx2 && y>y2-3 && y < y2 + 3) return 2; return 0; } else if(type == 3) { if(x>x1 && x < x2 && y>y1-3 && y x2 && y>y1-3 && yx2-3 && x < x2 + 3 && y>y1 && y < y2) return 3; if(x>x2-3 && x < x2 + 3 && y y2) return 3; return 0; } else if(type == 4) { if(x>x1-3 && xy1 && y<(y1+y2)/2) return 4; if(x>x1-3 && x(y1+y2)/2) return 4; if(x>x1 && x < x2 && y>(y1+y2)/2-3 && y < (y1+y2)/2+3) return 4; if(x x2 && y>(y1+y2)/2-3 && y < (y1+y2)/2+3) return 4; if(x>x2-3 && x < x2+3 && y > (y1+y2)/2 && y < y2) return 4; if(x>x2-3 && x < x2+3 && y < (y1+y2)/2 && y > y2) return 4; return 0; } } int isLinkSelected(SITUATIA_TABLEI project, int x, int y) { for(int i = 0; i < project.p.size(); i++) if(checkLineTypeLink(project.p[i].first.type, x, y, project.p[i].first.x, project.p[i].first.y, project.p[i].first.xConnection, project.p[i].first.yConnection)) return i; return -1; } SITUATIA_TABLEI stergeLegatura(SITUATIA_TABLEI project, int ndxLink) { pairP= project.p[ndxLink]; drawLine(P.first.x, P.first.y,P.first.xConnection, P.first.yConnection, BLACK, P.first.type); project.p.erase(project.p.begin()+ndxLink); for(int i = 0; i< project.v.size(); i++) for(int j = 0; j0) { if(stiva.UNDO.size()==1) { stiva.REDO.push(stiva.UNDO.top()); stiva.UNDO.pop(); return project; } stiva.REDO.push(stiva.UNDO.top()); stiva.UNDO.pop(); project = stiva.UNDO.top(); return project; } else return proj; } else if(UndoRedo==2) { if(stiva.REDO.size()>0) { project = stiva.REDO.top(); stiva.REDO.pop(); stiva.UNDO.push(project); return project; } else return proj; } } ///Functie care goleste stiva de memorie pt undo si redo HISTORY emptyStack(HISTORY stackk) { while(!stackk.UNDO.empty()) { stackk.UNDO.pop(); } while(!stackk.REDO.empty()) { stackk.REDO.pop(); } return stackk; } ///Functie responsabila de a verifica daca circuitul este conectat int checkIntegrity(SITUATIA_TABLEI project) { //cmp != 9 vectornodIntraStg(project.v.size()+project.p.size()); vectornodIeseStg(project.v.size()+project.p.size()); vectornodIntraDreapta(project.v.size()+project.p.size()); vectornodIeseDr(project.v.size()+project.p.size()); //cmp==9 vectornodIntraStg9(project.v.size()+project.p.size()); vectornodIeseStg9(project.v.size()+project.p.size()); vectornodIeseJos(project.v.size()+project.p.size()); vectornodIntraJos(project.v.size()+project.p.size()); vectornodIntraSus(project.v.size()+project.p.size()); vectornodIeseSus(project.v.size()+project.p.size()); for(int j = 0; j=0 && nodIeseDr[i]>=0)//Toate intra din dreapta, restul 0 return 0; if(nodIntraStg[i]>=0 && nodIeseStg[i]>=0 && nodIntraDreapta[i]==0 && nodIeseDr[i]==0)//Toate intra din dreapta, restul 0 return 0; } } for(int i=0; i=0 && nodIeseJos[i]>=0 && nodIntraSus[i]>=0 && nodIeseSus[i]>=0)//stanga este 0 return 0; if(nodIntraStg9[i]>=0 && nodIeseStg9[i]>=0 && nodIntraJos[i]==0 && nodIeseJos[i]==0 && nodIntraSus[i]>=0 && nodIeseSus[i]>=0)//jos este 0 return 0; if(nodIntraStg9[i]>=0 && nodIeseStg9[i]>=0 && nodIntraJos[i]>=0 && nodIeseJos[i]>=0 && nodIntraSus[i]==0 && nodIeseSus[i]==0)//sus este 0 return 0; } } return 1; } ///Functie responsabila de a deschide pagina html void openHtml(char *current_path) { LPCTSTR helpFile = path_for_images("prezentare.html",current_path); ShellExecute(NULL, "open", helpFile, NULL, NULL, SW_SHOWNORMAL); return; } ///Functie care verifica proprietatile "Circuitului Fericit" bool turnBulbOn(SITUATIA_TABLEI project) { // 2 electrical power // 2 resitors// 1 bulb // 1 transistor // 1 voltmeter // 1 ampermeter// 1 diode // 1 fuse // 1 capacitor if(project.light) return true; int circuit[12]; for(int i=0; i<12; i++) circuit[i]=0; if(project.v.empty()) return false; int connected = checkIntegrity(project); if(connected) { for(int i=0; i