/// /// show(): Generates the SVG drawing output file for each pedigree. /// void DrawingCanvas::show(const char* filename){ // If label and/or icon legends are present // readjust the x and y extents: if(_labelSet->getNumberOfLabels() != 0 || _iconLegendFlag){ _xMinimum -= _labelLegend.getWidth(); double height = _labelLegend.getHeight(); if(_iconLegendFlag) height += _iconLegend.getHeight(); if(height > getYRange()) { _yMaximum += (height - getYRange()); } } // // Only set the header now because at this point the // true x and y extents (width and height) are known: _setHeader(); // // Add the legends: // _drawLegends(); std::ofstream svgfile(filename); if(svgfile.is_open()){ svgfile << _header.str() << std::endl; ///////////////////////////////////////////////////// // // 2009.05.21.ET: // Dump the bottommost layer (for curved connectors) // ///////////////////////////////////////////////////// svgfile << " <g id=\"bottomLayer" << "\" class=\"layer\" >\n"; svgfile << _bottomLayer.str() << std::endl; svgfile << " </g>\n"; for(unsigned i=0;i<_layers.size();i++){ svgfile << _layers[i] << std::endl; } svgfile << _body.str() << std::endl; svgfile << _footer.str() << std::endl; svgfile.close(); }else{ std::cout << "Unable to open file " << filename << std::endl; } }
/// /// show(): Generates the SVG drawing output file for each pedigree. /// void DrawingCanvas::show(const char* filename){ // DEBUG: //std::cout << _header << std::endl; // Show the layers before the body //for(unsigned i=0;i<_layers.size();i++) // std::cout << _layers[i] << std::endl; //std::cout << _body << std::endl; //std::cout << _footer << std::endl; // Write to file with name : pedigree_id+".xml" // If label and/or icon legends are present // readjust the x and y extents: if(_labelSet->getNumberOfLabels() != 0 || _iconLegendFlag){ _xMinimum -= _labelLegend.getWidth(); double height = _labelLegend.getHeight(); if(_iconLegendFlag) height += _iconLegend.getHeight(); if(height > getYRange()) { _yMaximum += (height - getYRange()); } } // // Only set the header now because at this point the // true x and y extents (width and height) are known: _setHeader(); // // Add the legends: // _drawLegends(); std::ofstream svgfile(filename); if(svgfile.is_open()){ svgfile << _header.str() << std::endl; for(unsigned i=0;i<_layers.size();i++){ svgfile << _layers[i] << std::endl; } svgfile << _body.str() << std::endl; svgfile << _footer.str() << std::endl; svgfile.close(); }else{ std::cout << "Unable to open file " << filename << std::endl; } }
SvgItem::SvgItem(View *parent, const QString &file) : ViewItem(parent) { if (!file.isNull()) { _svg = new QSvgRenderer(file); QFile svgfile(file); if (svgfile.open(QIODevice::ReadOnly | QIODevice::Text)) { while (!svgfile.atEnd()) { _svgData.append(svgfile.readLine()); } } } else { _svg = new QSvgRenderer(); } setTypeName("Svg"); setLockAspectRatio(true); setLockAspectRatioFixed(true); }
SvgItem::SvgItem(View *parent, const QString &file) : ViewItem(parent) { if (!file.isNull()) { _svg = new QSvgRenderer(file); QFile svgfile(file); if (svgfile.open(QIODevice::ReadOnly | QIODevice::Text)) { while (!svgfile.atEnd()) { _svgData.append(svgfile.readLine()); } } } else { _svg = new QSvgRenderer(); } //FIXME need to set the element id?? setName("Svg"); setZValue(SVG_ZVALUE); setLockAspectRatio(true); }
void Enumerator::svg_output() { std::ofstream svgfile("result.svg"); double xmin = 99999, ymin = 99999; double xmax = 0, ymax = 0; for (auto part : best_partition) { for (auto p : part) { xmin = std::min(xmin, p.X); xmax = std::max(xmax, p.X); ymin = std::min(ymin, p.Y); ymax = std::max(ymax, p.Y); } } xmin -= 2; ymin -= 2; xmax += 2; ymax += 2; double scale = 20; int pointsize = (int) ceil(std::max((xmax-xmin)/10.,(ymax-ymin)/10.)); svgfile << "<?xml version=\"1.0\"?><!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << std::endl; svgfile << "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"960\" height=\"700\" viewBox = \"" << scale*xmin << " " << scale*ymin << " " << scale*(xmax - xmin) << " " << scale*(ymax - ymin) << "\" preserveAspectRatio = \"xMidYMid meet\">" << std::endl; //svgfile << "<rect x = \"0\" y = \"0\" width = \"500\" height = \"500\" style = \"stroke:black;stroke-width:3;fill:white\"/>" << std::endl; for (unsigned int part = 0; part < best_partition.size(); ++part) { auto cen = best_sites[part]; svgfile << "<circle cx = \"" << scale * cen.X << "\" cy = \"" << scale * cen.Y << "\" r = \"" << pointsize << "\" style = \"fill:green\" />" << std::endl; for (auto p : best_partition[part]) { svgfile << "<line x1=\"" << scale * p.X << "\" y1=\"" << scale*p.Y << "\" x2=\"" << scale * cen.X << "\" y2=\"" << scale * cen.Y << "\" style=\"stroke:#aaa; stroke-width:"<< pointsize <<"; \" stroke-dasharray=\"1, 1\"/>"; svgfile << "<circle cx = \"" << scale * p.X << "\" cy = \"" << scale*p.Y << "\" r = \"" << pointsize << "\" style = \"fill:red\" />" << std::endl; } } svgfile << "</svg>"; }