1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*
VOTable parser
Copyright © 2010 - 2013, 2017-8 F.Hroch (hroch@physics.muni.cz)
This file is part of Munipack.
Munipack is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Munipack 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 Munipack. If not, see <http://www.gnu.org/licenses/>.
Reference:
http://www.ivoa.net/Documents/VOTable/20091130/REC-VOTable-1.2.html
*/
#include <wx/wx.h>
#include <wx/xml/xml.h>
#include <wx/url.h>
#include <vector>
class VOField
{
const wxXmlNode *node;
public:
VOField(): node(0) {}
VOField(const wxXmlNode *nod): node(nod) {}
wxString GetLabel() const;
wxString GetType() const;
wxString GetUnit() const;
wxString GetArraySize() const;
};
class VOTableTable {
public:
VOTableTable(): nrows(0), tablenode(0) {}
VOTableTable(const wxXmlNode *node);
int RecordCount() const;
std::vector<wxString> GetRecord(int) const;
std::vector<wxString> GetColumn(int) const;
std::vector<wxString> GetFields() const;
std::vector<wxString> GetUnits() const;
std::vector<wxString> GetTypes() const;
//private:
wxString description;
std::vector<VOField> fields;
std::vector<wxString> links;
int nrows;
wxXmlNode *tablenode;
std::vector<wxString> elements;
std::vector<wxXmlNode *> rows;
void VOData(const wxXmlNode *);
void VOTableData(const wxXmlNode *);
};
class VOResource
{
const wxXmlNode *resource;
public:
VOResource(): resource(0), coosys(0) {}
VOResource(const wxXmlNode *);
wxString GetEquinox() const;
wxString GetCooSys() const;
double GetEpoch() const;
//private:
wxString description;
std::vector<wxString> links;
wxXmlNode *coosys;
VOTableTable table;
};
class VOTable: public wxXmlDocument
{
public:
/*
VOTable(const wxInputStream&);
*/
VOTable();
VOTable(const wxString&);
VOTable(const wxXmlDocument&);
VOTable(const wxURL&);
bool Load(const wxString&);
wxString GetDescription() const;
std::vector<VOResource> GetResources() const { return resources; }
int RecordCount() const;
bool IsEmpty() const;
bool HasError() const { return ! infomsg.IsEmpty(); }
wxString GetErrorMsg() const { return infomsg; }
std::vector<wxString> GetQueryPar() const;
bool Sort(const wxString&, const size_t index=0);
bool Save(const wxString&);
bool Save(wxOutputStream&);
void ShowStructure() const;
protected:
wxString infomsg;
std::vector<VOResource> resources;
private:
void ParseTable();
void ParseErrorInfo();
void ShowNode(const wxXmlNode *node) const;
};
class SVGcanvas: public VOTable
{
wxString proj_type, mag_key, alpha_key, delta_key;
double proj_alpha, proj_delta, proj_scale, mag_limit;
long canvas_width, canvas_height;
double ToDouble(const wxString& a) const;
public:
SVGcanvas(const wxString&);
bool Save(wxOutputStream&);
void SetProjection(const wxString&);
void SetProjectionCenter(double,double);
void SetCanvasSize(long,long);
void SetScale(double);
void SetMaglim(double);
void SetMagkey(const wxString&);
void SetAlphakey(const wxString&);
void SetDeltakey(const wxString&);
};
class FITStable: public VOTable
{
std::vector<wxString> FitsTypes(const std::vector<VOField>& fields);
char **GetArray(const std::vector<wxString>&);
public:
FITStable(const wxString&);
FITStable(const VOTable&);
bool Save(const wxString&, bool);
};
class TXTable: public VOTable
{
public:
TXTable(const wxString&);
bool Save(wxOutputStream& output);
};
class CSVtable: public VOTable
{
public:
CSVtable(const wxString&);
bool Save(wxOutputStream& output);
};
wxString GetString(const wxString&);
double GetDouble(const wxString&);
long GetLong(const wxString&);
bool GetBool(const wxString&);
wxString GetFileType(const wxString&);
|