All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ScaleModel.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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 Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file ScaleModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "ScaleModel.h"
30 #include "MapModel.h"
31 #include "../core/property/Property.h"
32 #include "../core/property/Properties.h"
33 #include "../core/property/SharedProperties.h"
34 #include "../../geometry/Polygon.h"
35 #include "../core/enum/Enums.h"
36 
37 // STL
38 #include <string>
39 #include <sstream> // std::stringstream
40 
41 
43  m_mapName(""),
44  m_mapScale(0),
45  m_scaleGapX(20),
46  m_scaleGapY(5),
47  m_enumScaleType(0),
48  m_currentScaleType(0)
49 {
50 
51  m_type = Enums::getInstance().getEnumObjectType()->getScaleItem();
52 
53  m_box = te::gm::Envelope(0., 0., 70., 30.);
54 
55  m_border = false;
56 
59 }
60 
62 {
63  if(m_enumScaleType)
64  {
65  delete m_enumScaleType;
66  m_enumScaleType = 0;
67  }
68 }
69 
71 {
73 
75 
76  Property pro_widthGap(m_hashCode);
77  pro_widthGap.setName("scale_width_rect_gap");
78  pro_widthGap.setValue(m_scaleGapX, dataType->getDataTypeDouble());
79  m_properties->addProperty(pro_widthGap);
80 
81  Property pro_heightGap(m_hashCode);
82  pro_heightGap.setName("scale_height_rect_gap");
83  pro_heightGap.setValue(m_scaleGapY, dataType->getDataTypeDouble());
84  m_properties->addProperty(pro_heightGap);
85 
86  Property pro_mapName(m_hashCode);
87  pro_mapName.setName(m_sharedProps->getMapName());
88  pro_mapName.setValue(m_mapName, dataType->getDataTypeStringList());
89  Variant v;
90  v.setValue(m_mapName, dataType->getDataTypeString());
91  pro_mapName.addOption(v);
92  m_properties->addProperty(pro_mapName);
93 
94  Property pro_scaleName = scaleProperty();
95  if(!pro_scaleName.isNull())
96  {
97  m_properties->addProperty(pro_scaleName);
98  }
99 
100  return m_properties;
101 }
102 
104 {
106 
107  Properties* vectorProps = const_cast<Properties*>(properties);
108 
109  Property pro_mapName = vectorProps->contains(m_sharedProps->getMapName());
110 
111  if(!pro_mapName.isNull())
112  {
113  m_mapName = pro_mapName.getOptionByCurrentChoice().toString();
114  }
115 
116  Property pro_widthGap = vectorProps->contains("scale_width_rect_gap");
117 
118  if(!pro_widthGap.isNull())
119  {
120  m_scaleGapX = pro_widthGap.getValue().toDouble();
121  }
122 
123  Property pro_heightGap = vectorProps->contains("scale_height_rect_gap");
124 
125  if(!pro_heightGap.isNull())
126  {
127  m_scaleGapY = pro_heightGap.getValue().toDouble();
128  }
129 
130  Property pro_scaleName = vectorProps->contains("scale_type");
131 
132  if(!pro_scaleName.isNull())
133  {
134  std::string label = pro_scaleName.getOptionByCurrentChoice().toString();
135  EnumType* enumType = m_enumScaleType->searchLabel(label);
136  if(enumType)
137  {
138  m_currentScaleType = enumType;
139  }
140  }
141 }
142 
144 {
145  MapModel* map = dynamic_cast<MapModel*>(m_visitable);
146 
147  if(map)
148  {
149  m_mapScale = map->getScale();
150 
151  notifyAll(context);
152  }
153 }
154 
156 {
157  m_scaleGapX = x;
158 }
159 
161 {
162  return m_scaleGapX;
163 }
164 
166 {
167  m_scaleGapY = y;
168 }
169 
171 {
172  return m_scaleGapY;
173 }
174 
176 {
177  return m_mapScale;
178 }
179 
181 {
182  return m_enumScaleType;
183 }
184 
186 {
187  Property pro_scaleName(m_hashCode);
188 
189  if(!m_currentScaleType)
190  return pro_scaleName;
191 
193 
194  if(!dataType)
195  return pro_scaleName;
196 
197  pro_scaleName.setName("scale_type");
198  pro_scaleName.setLabel("graphic type");
199  pro_scaleName.setValue(m_currentScaleType->getLabel(), dataType->getDataTypeStringList());
200 
201  Variant v;
202  v.setValue(m_currentScaleType->getLabel(), dataType->getDataTypeString());
203  pro_scaleName.addOption(v);
204  pro_scaleName.setOptionChoice(v);
205 
206  for(int i = 0 ; i < m_enumScaleType->size() ; ++i)
207  {
208  EnumType* enumType = m_enumScaleType->getEnum(i);
209 
210  if(enumType == m_enumScaleType->getNoneType() || enumType == m_currentScaleType)
211  continue;
212 
213  Variant v;
214  v.setValue(enumType->getLabel(), dataType->getDataTypeString());
215  pro_scaleName.addOption(v);
216  }
217 
218  return pro_scaleName;
219 }
220 
222 {
223  return m_currentScaleType;
224 }
225 
virtual double getScaleGapX()
Definition: ScaleModel.cpp:160
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
virtual double getScale()
Definition: MapModel.cpp:231
virtual void setScaleGapY(double y)
Definition: ScaleModel.cpp:165
ScaleModel()
Constructor.
Definition: ScaleModel.cpp:42
Variant getValue()
Returns stored value.
Definition: Property.cpp:72
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
void addOption(Variant variant)
Definition: Property.cpp:77
std::string getLabel()
Returns label.
Definition: EnumType.cpp:64
virtual ~ScaleModel()
Destructor.
Definition: ScaleModel.cpp:61
virtual EnumType * getDataTypeDouble() const
Returns value that represents type double belonging to enumeration.
bool isNull()
Returns true if no value has been set, false otherwise.
Definition: Property.cpp:146
bool m_border
true if should be drawn border, false otherwise
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
Definition: ScaleModel.cpp:103
Variant getOptionByCurrentChoice()
Definition: Property.cpp:104
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Definition: Properties.h:52
EnumType * m_type
type of the MVC component
virtual void setScaleGapX(double x)
Definition: ScaleModel.cpp:155
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
static Enums & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual EnumType * getDoubleAlternatingScaleBarType() const
Returns value that represents double alternating scale bar type belonging to enumeration.
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
Definition: EnumDataType.h:48
te::gm::Envelope m_box
bounding rectangle
Class that represents a "Model" part of Map MVC component. Its coordinate system is the same of scene...
Class acts like a union for some C++/TerraLib5 data types. Responsible for storing the value...
Definition: Variant.h:80
virtual void visitDependent(ContextItem context)
visit and if necessary redraw
Definition: ScaleModel.cpp:143
virtual double getMapScale()
Definition: ScaleModel.cpp:175
virtual EnumScaleType * getEnumScaleType()
Definition: ScaleModel.cpp:180
double toDouble()
Returns the value of double type. (The setValue method received a double)
Definition: Variant.cpp:316
Class that represents a "Model" part of Map MVC component. Its coordinate system is the same of scene...
Definition: MapModel.h:61
Class to represent a scale type enumeration. Ex.: hollow scale bar, etc.
Definition: EnumScaleType.h:48
Class that represents a "Model" part of Scale MVC component. Its coordinate system is the same of sce...
virtual Properties * getProperties() const
Reimplemented from Observable.
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Property.h:298
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
Definition: EnumType.h:48
virtual EnumType * getDataTypeStringList() const
Returns value that represents type StringList (string) belonging to enumeration.
std::string toString()
Returns the value of string type. (The setValue method received a string)
Definition: Variant.cpp:311
virtual double getScaleGapY()
Definition: ScaleModel.cpp:170
virtual Properties * getProperties() const
Reimplemented from Observable.
Definition: ScaleModel.cpp:70
void setName(std::string name)
Sets the name of this property.
Definition: Property.cpp:62
virtual Property scaleProperty() const
Definition: ScaleModel.cpp:185
virtual EnumType * getDataTypeString() const
Returns value that represents type string belonging to enumeration.
virtual EnumType * getCurrentScaleType()
Definition: ScaleModel.cpp:221
virtual void setLabel(std::string label)
Sets the label of this property.
Definition: Property.cpp:218
EnumScaleType * m_enumScaleType
Definition: ScaleModel.h:105
void setOptionChoice(Variant variant)
Definition: Property.cpp:99
virtual bool contains(Property property)
Checks if the property is contained within the set of properties.
Definition: Properties.h:251
A property acts like a attribute member of a object and stores the state of this attribute. A set of properties stores the state of an object. Any data type, not included in the convertValue method in the class te::layout::Variant, it will be by default "std::string" value.
Definition: Property.h:47
EnumType * m_currentScaleType
Definition: ScaleModel.h:106
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Variant.h:288