D:/WorkDir/SugoiProjects/SugoiTracer/src/svg.cpp

Go to the documentation of this file.
00001 #include "SugoiTracer\svg.h"
00002 
00003 #if _SG_TRC_SVG
00004 TiXmlElement* SVGCreateLine(TiXmlElement*  _Root, CL_Vector2Df &_Origine, CL_Vector2Df &_Dest, std::string _Style ="stroke-width:3 ; fill:none; stroke:black")
00005 {
00006         TiXmlElement* LineElem = new TiXmlElement("line");
00007         
00008         //line position
00009         LineElem->SetAttribute("x1", _Origine.x);
00010         LineElem->SetAttribute("x2", _Dest.x);
00011         LineElem->SetAttribute("y1", _Origine.y);
00012         LineElem->SetAttribute("y2", _Dest.y);
00013         
00014         //line style
00015         //if (_Style!="")
00016                 LineElem->SetAttribute("style", "stroke-width:3 ; fill:none; stroke:black");//_Style.data());
00017 
00018         _Root->InsertEndChild(*LineElem);
00019 
00020         return LineElem;
00021 }
00022 
00023 TiXmlElement* SVGCreateText(TiXmlElement*  _Root, CL_Vector2Df &_Pos, std::string _Text)
00024 {
00025         TiXmlElement* TextElem = new TiXmlElement("text");
00026         
00027         //position
00028         TextElem->SetAttribute("x", _Pos.x);
00029         TextElem->SetAttribute("y", _Pos.y);
00030 
00031         // value
00032         //<text x='20'  y='25'>Time(ms)</text>
00033         //TextElem->SetAttribute("style", _Style);
00034 
00035         _Root->InsertEndChild(*TextElem);
00036         return TextElem;
00037 }
00038 
00039 TiXmlElement* SVGCreateCircle(TiXmlElement*  _Root, CL_Vector2Df &_Pos, int _size)
00040 {
00041         TiXmlElement* CircleElem = new TiXmlElement("circle ");
00042         
00043         //position
00044         CircleElem->SetAttribute("cx", _Pos.x);
00045         CircleElem->SetAttribute("cy", _Pos.y);
00046 
00047         // value
00048         CircleElem->SetAttribute("r", _size);
00049 
00050         _Root->InsertEndChild(*CircleElem);
00051         return CircleElem;
00052 }
00053 
00054 TiXmlElement* SVGCreateStyleContainer(TiXmlElement*  _Root, std::string _Style, std::string _Transform)
00055 {
00056         TiXmlElement* StyleElem = new TiXmlElement("g");
00057 
00058         if (_Style!="")
00059                 StyleElem->SetAttribute("style", _Style.data());
00060 
00061         if (_Transform!="")
00062                 StyleElem->SetAttribute("transform", _Transform.data());
00063 
00064         _Root->InsertEndChild(*StyleElem);
00065 
00066         return StyleElem;
00067 }
00068 
00069 
00070 TiXmlDocument  * SVGCreateGraph(std::string FileName, CL_Vector2Df &_graphOrigine, CL_Vector2Df &_graphSize, CL_Vector2Df &_Size)
00071 {
00072         TiXmlDocument  * XML_File = XMLSaveFile(FileName, "svg");
00073         SG_Assert(XML_File, "Could not save SVG to file!");
00074         
00075         TiXmlElement * RootSVG = XML_File->FirstChild("svg")->ToElement();
00076         SG_Assert(RootSVG, "No XML Root Tag Found!");
00077         //SG_Assert(this->XMLSave(XML_ROOT),  "XMLSave Failed!");
00078 
00079         //TiXmlElement* RootSVG  = XML_SAVEToFile(FileName, "svg");
00080 
00081         //      = new TiXmlElement("svg");
00082         RootSVG->SetAttribute("width", _Size.x);
00083         RootSVG->SetAttribute("height", _Size.y);
00084 
00085         //draw main lines...
00086         float scaleFactor = 0.8;
00087 
00088         CL_Vector2Df Min(_graphOrigine.x, _Size.y - _graphOrigine.y);
00089         CL_Vector2Df Max (Min.x + _graphSize.x, Min.y - _graphSize.y);
00090 
00091 
00092         //x axe
00093         //SVGCreateLine(RootSVG, CL_Vector2Df(_Origine - CL_Vector2Df(_Size.x*0.1,0)), 
00094         //              CL_Vector2Df(_Origine + CL_Vector2Df(_Size.x*1.1,0)), "");
00095         SVGCreateLine(RootSVG, CL_Vector2Df(Min), CL_Vector2Df(Max.x, Min.y) , "");
00096         //y axe
00097         SVGCreateLine(RootSVG, CL_Vector2Df(Min), CL_Vector2Df(Min.x, Max.y) , "");
00098 
00099         SVGCreateCircle(RootSVG, CL_Vector2Df(Min + _Size/2), 2);
00100         SVGCreateCircle(RootSVG, CL_Vector2Df(Min + _Size*3/4), 3);
00101         SVGCreateCircle(RootSVG, CL_Vector2Df(Min + _Size*1/4), 4);
00102 
00103         SG_Assert(XML_File->SaveFile(), "XML_File->SaveFile() Failed!");
00104         return XML_File;
00105 }
00106 
00107 
00108 void SVGGeneratePNGFiles()
00109 {
00110         printf("\nGenerating PNG files...");
00111     //"/k java.exe -jar D:\\batik-1.6\\batik-rasterizer.jar -m image/png SVG\\*.svg "
00112     string Command = "/k java.exe -jar ";
00113     Command += _CVG_SVG_BATIK_RASTERIZER_PATH;
00114     Command += " -m image/png ";
00115     Command += _CVG_SVG_EXPORT_PATH;
00116     Command += "\\*.svg";
00117     ShellExecute(0,0,"cmd.exe",Command.data(),0,SW_HIDE);  
00118     printf("Done!");
00119 }
00120 #endif

Generated on Mon Mar 19 23:16:20 2007 for SugoiTracer by  doxygen 1.4.6-NO