📄 cvg.cpp
字号:
/* GHelm - Nautical Navigation Software * Copyright (C) 2004 Jon Michaelchuck * * This application is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */#include "cvg.h"#include "cvgutil.h"#include <math.h>#include <iostream>#include <sstream>/* * Load fillable attributes * @param doc xml doc * @param cur xml cursor * @return 0 on success, -1 on failure */int CVGFillable::Load(xmlDocPtr doc, xmlNodePtr cur){ xmlChar *prop; prop = xmlGetProp(cur, (const xmlChar *)"fill"); if (prop) { if (xmlStrcmp(prop, (const xmlChar *) "none")) { std::string fill = (const char *)prop; if (fill.size() != 7) { std::cout << "CVGFillable::Load: bad fill parameter" << std::endl; return -1; } fill_rgb[0] = _hex_to_dec(fill.substr(1,2))/255.0; fill_rgb[1] = _hex_to_dec(fill.substr(3,2))/255.0; fill_rgb[2] = _hex_to_dec(fill.substr(5,2))/255.0; filled = true; } } return 0;}/** * Constructor */CVG::CVG(){}/** * Destructor */CVG::~CVG(){ // FIXME this deletes some statically allocated arrays! // (rect) std::vector<CVGShape *>::iterator it; for (it = cvg_shapes.begin(); it != cvg_shapes.end(); ++it) delete *it;}/** * Load an cvg file * @param fname Filename * @return 0 on success, -1 on failure */int CVG::Load(const char *fname){ xmlDocPtr doc; xmlNodePtr cur; doc = xmlReadFile(fname, NULL, 0); if (doc == NULL) { std::cerr << "CVG::Load(): Error loading cvg xml" << std::endl; return -1; } cur = xmlDocGetRootElement(doc); if (cur == NULL) { std::cerr << "CVG::Load(): Error getting root element" << std::endl; xmlFreeDoc(doc); return -1; } if (xmlStrcmp(cur->name, (const xmlChar *) "cvg")) { std::cerr << "CVG::Load(): Root element != cvg" << std::endl; xmlFreeDoc(doc); return -1; } cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"line"))) { CVGShape *cvg_line = new CVGLine; if (cvg_line->Load(doc, cur) < 0) { std::cerr << "CVG::Load(): Error loading line" << std::endl; delete cvg_line; } else cvg_shapes.push_back(cvg_line); } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"circle"))) { CVGShape *cvg_circle = new CVGCircle; if (cvg_circle->Load(doc, cur) < 0) { std::cerr << "CVG::Load(): Error loading circle" << std::endl; delete cvg_circle; } else cvg_shapes.push_back(cvg_circle); } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"ellipse"))) { CVGShape *cvg_ellipse = new CVGEllipse; if (cvg_ellipse->Load(doc, cur) < 0) { std::cerr << "CVG::Load(): Error loading ellipse" << std::endl; delete cvg_ellipse; } else cvg_shapes.push_back(cvg_ellipse); } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"rect"))) { CVGShape *cvg_rect = new CVGRect; if (cvg_rect->Load(doc, cur) < 0) { std::cerr << "CVG::Load(): Error loading rect" << std::endl; delete cvg_rect; } else cvg_shapes.push_back(cvg_rect); } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"polygon"))) { CVGShape *cvg_polygon = new CVGPolygon; if (cvg_polygon->Load(doc, cur) < 0) { std::cerr << "CVG::Load(): Error loading polygon" << std::endl; delete cvg_polygon; } else cvg_shapes.push_back(cvg_polygon); } else if ((!xmlStrcmp(cur->name, (const xmlChar *)"polyline"))) { CVGShape *cvg_polyline = new CVGPolyline; if (cvg_polyline->Load(doc, cur) < 0) { std::cerr << "CVG::Load(): Error loading polyline" << std::endl; delete cvg_polyline; } else cvg_shapes.push_back(cvg_polyline); } cur = cur->next; } xmlFreeDoc(doc); filename = fname; return 0;}/** * Render the model */void CVG::Render(){ std::vector<CVGShape *>::iterator it; std::vector<CVGShape *>::iterator end = cvg_shapes.end(); for (it = cvg_shapes.begin(); it != end; ++it) (*it)->Render();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -