1 // -*- C++ -*-
2 
3 /*
4  * Gnome Crystal
5  * line.cc
6  *
7  * Copyright (C) 2000-2010 Jean Bréfort <jean.brefort@normalesup.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24 
25 #include "config.h"
26 #include "gcrystal.h"
27 #include "line.h"
28 #include <glib.h>
29 #include <GL/gl.h>
30 #include <GL/glu.h>
31 #include <cmath>
32 #include <cstring>
33 
gcLine()34 gcLine::gcLine (): gcr::Line ()
35 {
36 }
37 
~gcLine()38 gcLine::~gcLine ()
39 {
40 }
41 
42 
LoadOld(xmlNodePtr node,unsigned version)43 bool gcLine::LoadOld (xmlNodePtr node, unsigned version)
44 {
45 	char *txt;
46 	txt = (char*) xmlGetProp (node, (xmlChar*) "type");
47 	if (txt) {
48 		int i = 0;
49 		while (strcmp (txt, gcr::LineTypeName[i]) && (i < 5))
50 			i++;
51 		xmlFree (txt);
52 		if (i < 5)
53 		    m_nType = (gcr::LineType) i;
54 		else
55 		    return false;
56 	} else
57 		return false;
58 	xmlNodePtr child = node->children;
59 	while (child) {
60 		if (!strcmp ((gchar*) child->name, "position")) {
61 			txt = (char*) xmlNodeGetContent (child);
62 			if (txt) {
63 				sscanf (txt, "%lg %lg %lg %lg %lg %lg", &m_dx, &m_dy, &m_dz, &m_dx2, &m_dy2, &m_dz2);
64 				xmlFree (txt);
65 			}
66 		} else if (!strcmp ((gchar*) child->name, "color")) {
67 			txt = (char*) xmlNodeGetContent (child);
68 			if (txt) {
69 				if (version < 0x200)
70 					sscanf (txt, "%g %g %g %g", &m_fBlue, &m_fRed, &m_fGreen, &m_fAlpha);
71 				else
72 					sscanf (txt, "%g %g %g %g", &m_fRed, &m_fGreen, &m_fBlue, &m_fAlpha);
73 				xmlFree (txt);
74 			}
75 		} else if (!strcmp ((gchar*) child->name, "radius")) {
76 			txt = (char*) xmlNodeGetContent (child);
77 			if (txt) {
78 				sscanf (txt, "%lg", &m_dr);
79 				xmlFree (txt);
80 			}
81 		}
82 		child = child->next;
83 	}
84 	if (m_dr == 0)
85 		return false;
86 	return true;
87 }
88