All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PointModel.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 PointModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "PointModel.h"
30 #include "../core/ContextItem.h"
31 #include "../../geometry/Envelope.h"
32 #include "../../color/RGBAColor.h"
33 #include "../../maptools/Canvas.h"
34 #include "../core/enum/Enums.h"
35 
37  m_enumPointType(0),
38  m_currentPointType(0),
39  m_shapeSize(4)
40 {
41  m_type = Enums::getInstance().getEnumObjectType()->getPointItem();
42 
43  m_pointColor = te::color::RGBAColor(0, 255, 0, 255);
44 
45  m_box = te::gm::Envelope(0., 0., 10., 10.);
46 
49 }
50 
52 {
53  if(m_enumPointType)
54  {
55  delete m_enumPointType;
56  m_enumPointType = 0;
57  }
58 }
59 
61 {
63 
64  Property pro_pointName = pointProperty();
65  if(!pro_pointName.isNull())
66  {
67  m_properties->addProperty(pro_pointName);
68  }
69 
70  return m_properties;
71 }
72 
74 {
76 
77  Properties* vectorProps = const_cast<Properties*>(properties);
78 
79  Property pro_pointName = vectorProps->contains("point_type");
80 
81  if(!pro_pointName.isNull())
82  {
83  std::string label = pro_pointName.getOptionByCurrentChoice().toString();
84  EnumType* enumType = m_enumPointType->searchLabel(label);
85  if(enumType)
86  {
87  m_currentPointType = enumType;
88  }
89  }
90 }
91 
93 {
94  return m_enumPointType;
95 }
96 
98 {
99  return m_currentPointType;
100 }
101 
103 {
104  Property pro_pointName(m_hashCode);
105 
106  if(!m_currentPointType)
107  return pro_pointName;
108 
110 
111  if(!dataType)
112  return pro_pointName;
113 
114  pro_pointName.setName("point_type");
115  pro_pointName.setLabel("graphic type");
116  pro_pointName.setValue(m_currentPointType->getLabel(), dataType->getDataTypeStringList());
117 
118  Variant v;
119  v.setValue(m_currentPointType->getLabel(), dataType->getDataTypeString());
120  pro_pointName.addOption(v);
121  pro_pointName.setOptionChoice(v);
122 
123  for(int i = 0 ; i < m_enumPointType->size() ; ++i)
124  {
125  EnumType* enumType = m_enumPointType->getEnum(i);
126 
127  if(enumType == m_enumPointType->getNoneType() || enumType == m_currentPointType)
128  continue;
129 
130  Variant v;
131  v.setValue(enumType->getLabel(), dataType->getDataTypeString());
132  pro_pointName.addOption(v);
133  }
134 
135  return pro_pointName;
136 }
137 
139 {
140  return m_shapeSize;
141 }
142 
144 {
145  return m_pointColor;
146 }
147 
149 {
150  m_pointColor = color;
151 }
152 
153 
virtual EnumType * getCircleType() const
Returns value that represents circle type belonging to enumeration.
Class that represents a "Model" part of Point MVC component. Its coordinate system is the same of sce...
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
te::color::RGBAColor m_pointColor
Definition: PointModel.h:89
void addOption(Variant variant)
Definition: Property.cpp:77
Class to represent a scale point enumeration. Ex.: X, square, circle, etc.
Definition: EnumPointType.h:48
std::string getLabel()
Returns label.
Definition: EnumType.cpp:64
virtual EnumType * getCurrentPointType()
Definition: PointModel.cpp:97
bool isNull()
Returns true if no value has been set, false otherwise.
Definition: Property.cpp:146
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
Definition: PointModel.cpp:73
virtual te::color::RGBAColor getPointColor()
Definition: PointModel.cpp:143
Variant getOptionByCurrentChoice()
Definition: Property.cpp:104
EnumPointType * m_enumPointType
Definition: PointModel.h:86
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Definition: Properties.h:52
PointModel()
Constructor.
Definition: PointModel.cpp:36
EnumType * m_type
type of the MVC component
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
virtual Property pointProperty() const
Definition: PointModel.cpp:102
virtual EnumPointType * getEnumPointType()
Definition: PointModel.cpp:92
static Enums & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
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 acts like a union for some C++/TerraLib5 data types. Responsible for storing the value...
Definition: Variant.h:80
virtual Properties * getProperties() const
Reimplemented from Observable.
virtual ~PointModel()
Destructor.
Definition: PointModel.cpp:51
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
EnumType * m_currentPointType
Definition: PointModel.h:87
virtual EnumType * getDataTypeStringList() const
Returns value that represents type StringList (string) belonging to enumeration.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
virtual Properties * getProperties() const
Reimplemented from Observable.
Definition: PointModel.cpp:60
virtual double getShapeSize()
Definition: PointModel.cpp:138
std::string toString()
Returns the value of string type. (The setValue method received a string)
Definition: Variant.cpp:311
void setName(std::string name)
Sets the name of this property.
Definition: Property.cpp:62
virtual EnumType * getDataTypeString() const
Returns value that represents type string belonging to enumeration.
virtual void setLabel(std::string label)
Sets the label of this property.
Definition: Property.cpp:218
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
virtual void setPointColor(te::color::RGBAColor color)
Definition: PointModel.cpp:148
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Variant.h:288