#include #include #include #include #include "graph.h" extern FILE *fpov; extern int fy; static void pov_drawtext ( int x, int y, int z, const char *line) { if (fpov != NULL){ char newline[strlen(line)+1]; char *dst = newline; while (*line != '\0'){ if (*line == 'é'){ *dst = 'e'; }else if (*line == 'è'){ *dst = 'e'; }else if (*line == 'à'){ *dst = 'a'; }else{ *dst = *line; } dst++; line++; } *dst = '\0'; fprintf (fpov,"text {\n"); fprintf (fpov,"\tttf \"timrom.ttf\" \"%s\" 0.5, 0\n",newline); fprintf (fpov,"\tpigment { Blue }\n"); fprintf (fpov,"\tscale <18,18,-5>\n"); fprintf (fpov,"\ttranslate <%d,%d,%d>\n",x,fy-y-12,z); fprintf (fpov,"}\n"); } } void drawcylinder ( GRAPH_MODE mode, GR_NODE &node, int w, int h, const char *title, const char *desc) { drawrect (mode,node,w,h,title,desc); if (mode == GR_DRAW && fpov != NULL){ int radius = w/2; int xc = node.x + radius; fprintf (fpov,"cylinder {\n"); fprintf (fpov,"\t<%d, %d, %d>,\n",xc,fy-node.y,node.z); // Center of one end fprintf (fpov,"\t<%d, %d, %d>,\n",xc,fy-(node.y + h),node.z); // Center of other end fprintf (fpov,"\t%d\n",radius); // Radius // fprintf (fpov,"\topen\n"); // Remove end caps fprintf (fpov,"\ttexture { pigment {color Grey }}\n"); fprintf (fpov,"}\n"); } } void drawthickline(GRAPH_MODE mode, GR_NODE &node) { drawrect (mode,node,node.depth,node.width,"",""); if (mode == GR_DRAW && fpov != NULL){ fprintf (fpov,"cylinder {\n"); fprintf (fpov,"\t<%d, %d, 0>,\n",node.x,fy-node.y); // Center of one end fprintf (fpov,"\t<%d, %d, 0>,\n",node.x+node.depth,fy-node.y); // Center of other end fprintf (fpov,"\t%d\n",node.width/2); // Radius // fprintf (fpov,"\topen\n"); // Remove end caps fprintf (fpov,"\ttexture { pigment {color Black }}\n"); fprintf (fpov,"}\n"); } } void drawarrow (GRAPH_MODE mode, GR_NODE &node, int len, bool hori) { int x0,y0,x1,y1,x2,y2; if (hori){ node.depth = len; node.width = 10; x0 = node.x; y0 = y1 = y2 = node.y; x1 = x0 + len-5; x2 = x0 + len; }else{ node.depth = 10; node.width = len; x0 = x1 = x2 = node.x + 5; y0 = node.y; y1 = y0 + len - 5; y2 = y0 + len; } if (mode == GR_DRAW){ diagui_sendcmd (P_Drawline,"%d %d %d %d\n",x0,y0,x2,y2); if (fpov != NULL){ fprintf (fpov,"union {\n"); fprintf (fpov,"\tcylinder {\n"); fprintf (fpov,"\t\t<%d, %d, 0>,\n",x0,fy-y0); // Center of one end fprintf (fpov,"\t\t<%d, %d, 0>,\n",x1,fy-y1); // Center of other end fprintf (fpov,"\t\t5\n"); // Radius fprintf (fpov,"\t\ttexture { pigment {color Blue }}\n"); fprintf (fpov,"\t}\n"); fprintf (fpov,"}\n"); } } } void drawcycle_arrow(GRAPH_MODE mode, GR_NODE &node) { } void drawparagraph (GRAPH_MODE mode, GR_NODE &node, const char *para) { int x = node.x; int y = node.y; int maxw = 0; int height = 0; while (*para != '\0'){ char line[200]; char *dst = line; while (*para != '\0' && *para != '\n') *dst++ = *para++; *dst = '\0'; if (*para == '\n') para++; char linetab[1000]; str_exptab (line,4,linetab); int len = strlen(linetab) * 8; if (len > maxw) maxw = len; if (mode == GR_DRAW){ char tmp[1000]; diagui_sendcmd (P_Drawtext,"%d %d %s\n",node.x,node.y+height ,diagui_quote (linetab,tmp)); pov_drawtext (x,y,node.z,linetab); } height += 14; y += 14; } node.width = height; node.depth = maxw; node.top.x = node.x + node.depth/2; node.top.y = node.y; node.bottom.x = node.top.x; node.bottom.y = node.y + node.width; node.left.x = node.x; node.left.y = node.y + node.width/2; } // Drawing functions void drawrect ( GRAPH_MODE mode, GR_NODE &node, int w, int h, const char *title, // Message on top of the circle const char *desc) // Message inside { int node_x = node.x; int node_y = node.y; if (title != NULL && title[0] != '\0'){ node_y += 14; node.margin.top = 14; } int lendesc = 0; if (desc != NULL && desc[0] != '\0'){ lendesc = strlen(desc)*8; if (lendesc > w - 16) w = lendesc + 16; } node.depth = w; node.height = 1; node.width = h; node.right.x = node_x + w; node.right.y = node_y + h/2; node.left.x = node_x; node.left.y = node.right.y; node.bottom.x = node.top.x = node_x + w/2; node.top.y = node.y; node.bottom.y = node.y + h + node.margin.top + node.margin.bottom; if (mode == GR_DRAW){ diagui_sendcmd (P_Drawline,"%d %d %d %d\n",node_x,node_y,node_x+w,node_y); diagui_sendcmd (P_Drawline,"%d %d %d %d\n",node_x+w,node_y,node_x+w,node_y+h); diagui_sendcmd (P_Drawline,"%d %d %d %d\n",node_x+w,node_y+h,node_x,node_y+h); diagui_sendcmd (P_Drawline,"%d %d %d %d\n",node_x,node_y+h,node_x,node_y); if (title != NULL && title[0] != '\0'){ char tmp[1000]; diagui_sendcmd (P_Drawtext,"%d %d %s\n",node_x+5,node_y-14 ,diagui_quote(title,tmp)); } if (desc != NULL && desc[0] != '\0'){ char tmp[1000]; int x = node_x + w/2 - lendesc/2; int y = node_y + h/2 - 7; diagui_sendcmd (P_Drawtext,"%d %d %s\n",x,y ,diagui_quote(desc,tmp)); pov_drawtext (x,y,node.z,desc); } if (fpov != NULL){ fprintf (fpov,"box {\n"); fprintf (fpov,"<%d, %d, %d+5>,\n",node.x,fy-(node.y+node.width),node.z); // Near lower left corner fprintf (fpov,"<%d, %d, %d+10>\n",node.x+node.depth,fy-node.y,node.z); // Near lower left corner fprintf (fpov,"\ttexture {\n"); fprintf (fpov,"\t\tpigment { color rgbf<1.0, 1.0, 1.0, 0.7> }\n"); //fprintf (fpov,"\t\tfinish { F_Glass1 }\n"); //fprintf (fpov,"\t\tpigment { color Green }\n"); fprintf (fpov,"\t}\n"); fprintf (fpov,"}\n"); } } } void drawellipse ( GRAPH_MODE mode, GR_NODE &node, int w, int h, const char *title, // Message on top of the circle const char *desc) // Message inside { node.width = h; if (title != NULL && title[0] != '\0'){ node.margin.top = 14; } int lendesc = 0; if (desc != NULL && desc[0] != '\0'){ lendesc = strlen(desc)*6; if (lendesc > w - 14) w = lendesc + 14; } node.depth = w; node.height = 1; node.right.x = node.x + w; node.right.y = node.y + h/2; node.left.x = node.x; node.left.y = node.right.y; node.bottom.x = node.top.x = node.x + w/2; node.top.y = node.y; node.bottom.y = node.y + h + node.margin.top + node.margin.bottom; if (mode == GR_DRAW){ diagui_sendcmd (P_Fillarc,"%d %d %d %d %d %d\n" ,node.x,node.y,w,h,0,64*360); if (title != NULL && title[0] != '\0'){ char tmp[1000]; diagui_sendcmd (P_Drawtext,"%d %d %s\n",node.x,node.y-14 ,diagui_quote(title,tmp)); } if (desc != NULL && desc[0] != '\0'){ char tmp[1000]; int x = node.x + w/2 - lendesc/2; int y = node.y + h/2 - 5; diagui_sendcmd (P_Drawtext,"%d %d %s\n",x,y ,diagui_quote(desc,tmp)); pov_drawtext (x,y,node.z,desc); } if (fpov != NULL){ fprintf (fpov,"box {\n"); fprintf (fpov,"<%d, %d, %d>,\n",node.x,fy-(node.y+node.width),node.z); // Near lower left corner fprintf (fpov,"<%d, %d, %d+10>\n",node.x+node.depth,fy-node.y,node.z); // Near lower left corner fprintf (fpov,"\ttexture {\n"); fprintf (fpov,"\t\tpigment { color Yellow }\n"); fprintf (fpov,"\t}\n"); fprintf (fpov,"}\n"); } } } void drawline (int x1, int y1, int x2, int y2, int thick) { diagui_sendcmd (P_Drawline,"%d %d %d %d\n",x1,y1,x2,y2); if (fpov != NULL){ fprintf (fpov,"cylinder {\n"); fprintf (fpov,"\t<%d, %d, 7>,\n",x1,fy-y1); // Center of one end fprintf (fpov,"\t<%d, %d, 7>,\n",x2,fy-y2); // Center of other end fprintf (fpov,"\t%d\n",thick); // Radius fprintf (fpov,"\topen\n"); // Remove end caps fprintf (fpov,"\ttexture { pigment {color Yellow }}\n"); fprintf (fpov,"}\n"); } }