1 /*
2 # PostgreSQL Database Modeler (pgModeler)
3 #
4 # Copyright 2006-2020 - Raphael Araújo e Silva <raphael@pgmodeler.io>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation version 3.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # The complete text of GPLv3 is at LICENSE file on source code root directory.
16 # Also, you can get the complete GNU General Public License at <http://www.gnu.org/licenses/>
17 */
18
19 #include "spatialtype.h"
20
21 template<>
22 QStringList SpatialType::TemplateType<SpatialType>::type_names =
23 {
24 "", // Reserved for BaseType::null
25
26 "POINT", "LINESTRING",
27 "POLYGON", "MULTIPOINT",
28 "MULTILINESTRING", "MULTIPOLYGON",
29 "GEOMETRY", "GEOMETRYCOLLECTION",
30 "POLYHEDRALSURFACE", "TRIANGLE",
31 "TIN", "CIRCULARSTRING",
32 "COMPOUNDCURVE", "CURVEPOLYGON",
33 "MULTICURVE", "MULTISURFACE",
34 };
35
SpatialType(const QString & type_name,int srid,unsigned variation_id)36 SpatialType::SpatialType(const QString &type_name, int srid, unsigned variation_id)
37 {
38 QString name=type_name;
39
40 if(name.endsWith(QString("ZM")))
41 {
42 variation_id=VarZm;
43 name.remove(QString("ZM"));
44 }
45 else if(name.endsWith(QString("M")))
46 {
47 variation_id=VarM;
48 name.remove(QString("M"));
49 }
50 else if(name.endsWith(QString("Z")))
51 {
52 variation_id=VarZ;
53 name.remove(QString("Z"));
54 }
55
56 setType(type_name);
57 setVariation(variation_id);
58 setSRID(srid);
59 }
60
SpatialType(unsigned type_id,int srid,unsigned var_id)61 SpatialType::SpatialType(unsigned type_id, int srid, unsigned var_id)
62 {
63 setType(type_id);
64 setVariation(var_id);
65 setSRID(srid);
66 }
67
SpatialType()68 SpatialType::SpatialType()
69 {
70 type_idx=BaseType::Null;
71 variation=NoVar;
72 srid=0;
73 }
74
setVariation(unsigned var)75 void SpatialType::setVariation(unsigned var)
76 {
77 if(var > VarZm)
78 variation=VarZm;
79 else
80 variation=var;
81 }
82
getVariation()83 unsigned SpatialType::getVariation()
84 {
85 return variation;
86 }
87
setSRID(int srid)88 void SpatialType::setSRID(int srid)
89 {
90 if(srid < -1) srid=-1;
91 this->srid=srid;
92 }
93
getSRID()94 int SpatialType::getSRID()
95 {
96 return srid;
97 }
98
operator *()99 QString SpatialType::operator * ()
100 {
101 if(type_idx != Null)
102 {
103 QString var_str;
104
105 switch(variation)
106 {
107 case VarZ: var_str+=QString("Z"); break;
108 case VarM: var_str+=QString("M"); break;
109 case VarZm: var_str+=QString("ZM"); break;
110 default: var_str=""; break;
111 }
112
113 if(srid > 0)
114 return (QString("(%1%2, %3)").arg(type_names[type_idx]).arg(var_str)).arg(srid);
115 else
116 return (QString("(%1%2)").arg(type_names[type_idx]).arg(var_str));
117 }
118 else
119 return "";
120 }
121