00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "SVGDev.h"
00027 #include "stdio.h"
00028 #include <iostream>
00029 using namespace std;
00030
00031 static char* xmlcode(const char* name, char* name2)
00032 {
00033 int i,j;
00034
00035
00036
00037 for (i=0, j=0; (name[i] != 0) && (j < 250); i++) {
00038 switch (name[i]) {
00039 case '<' : name2[j++] = '&'; name2[j++] = 'l'; name2[j++] = 't'; name2[j++] = ';'; break;
00040 case '>' : name2[j++] = '&'; name2[j++] = 'g'; name2[j++] = 't'; name2[j++] = ';'; break;
00041 case '\'' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'p'; name2[j++] = 'o'; name2[j++] = 's'; name2[j++] = ';'; break;
00042 case '"' : name2[j++] = '&'; name2[j++] = 'q'; name2[j++] = 'u'; name2[j++] = 'o'; name2[j++] = 't'; name2[j++] = ';'; break;
00043 case '&' : name2[j++] = '&'; name2[j++] = 'a'; name2[j++] = 'm'; name2[j++] = 'p'; name2[j++] = ';'; break;
00044 default : name2[j++] = name[i];
00045 }
00046 }
00047 name2[j] = 0;
00048
00049 return name2;
00050 }
00051
00052 SVGDev::SVGDev(const char* ficName,double largeur, double hauteur)
00053 {
00054 double gScale = 0.5;
00055
00056 if ((fic_repr = fopen(ficName,"w+")) == NULL) {
00057
00058 cout<<"Impossible de creer ou d'ouvrir "<<ficName<<endl;
00059 }
00060
00061
00062 fprintf(fic_repr,"<?xml version=\"1.0\"?>\n");
00063
00064
00065
00066 fprintf(fic_repr,"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 %f %f\" width=\"%fmm\" height=\"%fmm\" version=\"1.1\">\n", largeur, hauteur, largeur*gScale, hauteur*gScale);
00067 }
00068
00069 SVGDev::~SVGDev()
00070 {
00071 fprintf(fic_repr,"</svg>\n");
00072 fclose(fic_repr);
00073 }
00074
00075 void SVGDev::rect(double x,double y,double l,double h, const char* color, const char* link)
00076 {
00077 char buf[512];
00078 if (link != 0 && link[0]!=0) {
00079
00080 fprintf(fic_repr,"<a xlink:href=\"%s\">\n", xmlcode(link, buf));
00081 }
00082
00083 fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"0\" ry=\"0\" style=\"stroke:none;fill:#cccccc;\"/>\n",x+1,y+1,l,h);
00084
00085
00086
00087
00088 fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" rx=\"0\" ry=\"0\" style=\"stroke:none;fill:%s;\"/>\n", x, y, l, h, color);
00089 if (link != 0 && link[0]!=0) {
00090
00091 fprintf(fic_repr,"</a>\n");
00092 }
00093
00094 }
00095
00096 void SVGDev::rond(double x,double y,double rayon)
00097 {
00098 fprintf(fic_repr,"<circle cx=\"%f\" cy=\"%f\" r=\"%f\"/>\n",x,y,rayon);
00099 }
00100
00101 void SVGDev::fleche(double x,double y,double rotation,int sens)
00102 {
00103 double dx = 3;
00104 double dy = 1;
00105
00106 if(sens == 1)
00107 {
00108 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x-dx,y-dy,x,y,rotation,x,y);
00109 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x-dx,y+dy,x,y,rotation,x,y);
00110 }
00111 else
00112 {
00113 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x+dx,y-dy,x,y,rotation,x,y);
00114 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" transform=\"rotate(%f,%f,%f)\" style=\"stroke: black; stroke-width:0.25;\"/>\n",x+dx,y+dy,x,y,rotation,x,y);
00115 }
00116 }
00117
00118 void SVGDev::carre(double x,double y,double cote)
00119 {
00120 fprintf(fic_repr,"<rect x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\" style=\"stroke: black;stroke-width:0.5;fill:none;\"/>\n",x-0.5*cote,y-cote,cote,cote);
00121 }
00122
00123 void SVGDev::trait(double x1,double y1,double x2,double y2)
00124 {
00125
00126 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:black; stroke-linecap:round; stroke-width:0.25;\"/>\n",x1,y1,x2,y2);
00127 }
00128
00129 void SVGDev::dasharray(double x1,double y1,double x2,double y2)
00130 {
00131 fprintf(fic_repr,"<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-linecap:round; stroke-width:0.25; stroke-dasharray:3,3;\"/>\n",x1,y1,x2,y2);
00132 }
00133
00134 void SVGDev::text(double x,double y,const char* name)
00135 {
00136 char name2[256];
00137
00138 fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" font-family=\"Arial\" font-size=\"7\" text-anchor=\"middle\" fill=\"#FFFFFF\">%s</text>\n",x,y+2,xmlcode(name,name2));
00139 }
00140
00141 void SVGDev::label(double x,double y,const char* name)
00142 {
00143 char name2[256];
00144
00145 fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" font-family=\"Arial\" font-size=\"7\">%s</text>\n",x,y+2,xmlcode(name,name2));
00146
00147 }
00148
00149 void SVGDev::markSens(double x,double y,int sens)
00150 {
00151 int offset = (sens == 1) ? 2 : -2;
00152 fprintf(fic_repr,"<circle cx=\"%f\" cy=\"%f\" r=\"1\"/>\n", x+offset, y+offset);
00153 }
00154
00155 void SVGDev::Error(const char* message, const char* reason,int nb_error,double x,double y,double largeur)
00156 {
00157 fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" textLength=\"%f\" lengthAdjust=\"spacingAndGlyphs\" style=\"stroke: red; stroke-width:0.3; fill:red; text-anchor:middle;\">%d : %s</text>\n",x,y-7,largeur,nb_error,message);
00158 fprintf(fic_repr,"<text x=\"%f\" y=\"%f\" textLength=\"%f\" lengthAdjust=\"spacingAndGlyphs\" style=\"stroke: red; stroke-width:0.3; fill:none; text-anchor:middle;\">%s</text>\n",x,y+7,largeur,reason);
00159 }
00160
00161
00162