All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LineModel.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 LineModel.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "LineModel.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 #include "../../geometry/Point.h"
36 #include "../core/pattern/singleton/Context.h"
37 #include "../core/Utils.h"
38 #include "../core/pattern/mvc/ItemObserver.h"
39 #include "../core/property/Property.h"
40 #include "../core/property/Properties.h"
41 
43 {
44  m_type = Enums::getInstance().getEnumObjectType()->getLineItem();
45 
46  m_borderColor = te::color::RGBAColor(255, 255, 255, 0);
47  m_box = te::gm::Envelope(0., 0., 20., 20.);
48 
49  m_lineColor = te::color::RGBAColor(0, 0, 0, 255);
50 
51  m_border = false;
52 }
53 
55 {
56  if(!m_coords.empty())
57  {
58  std::vector<te::gm::Point*>::iterator ito;
59 
60  for(ito = m_coords.begin() ; ito != m_coords.end() ; ++ito)
61  {
62  if(*ito)
63  {
64  te::gm::Point* pt = *ito;
65  if(pt)
66  {
67  delete pt;
68  pt = 0;
69  }
70  }
71  }
72 
73  m_coords.clear();
74  }
75 }
76 
77 void te::layout::LineModel::setCoords( std::vector<te::gm::Point*> coords )
78 {
79  m_coords = coords;
80 
81  int sizeMCoords = m_coords.size();
82 
83  te::gm::LinearRing *lineOfPoints = new te::gm::LinearRing(sizeMCoords, te::gm::LineStringType);
84 
85  for(int i = 0; i < sizeMCoords ; ++i)
86  {
87  lineOfPoints->setPointN( i, te::gm::Point(m_coords[i]->getX(), m_coords[i]->getY()));
88  }
89 
90  const te::gm::Envelope *returnBox = lineOfPoints->getMBR();
91  double x1 = 0;
92  double y1 = 0;
93  double x2 = 0;
94  double y2 = 0;
95  x1 = returnBox->getLowerLeftX();
96  y1 = returnBox->getLowerLeftY();
97  x2 = returnBox->getUpperRightX();
98  y2 = returnBox->getUpperRightY();
99 
100  m_box = te::gm::Envelope(x1, y1, x2, y2);
101 
102  if (lineOfPoints)
103  {
104  delete lineOfPoints;
105  lineOfPoints = 0;
106  }
107 
108  double x = m_box.getLowerLeftX();
109  double y = m_box.getLowerLeftY();
110 
111  te::gm::Coord2D coord (x, y);
112 
113  ContextItem context;
114  context.setPos(coord);
115  context.setChangePos(true);
116 
117  notifyAll(context);
118 }
119 
120 std::vector<te::gm::Point*> te::layout::LineModel::getCoords()
121 {
122  return m_coords;
123 }
124 
126 {
127  return m_lineColor;
128 }
129 
131 {
133 
135 
136  Property pro_linecolor(m_hashCode);
137  pro_linecolor.setName("line_color");
138  pro_linecolor.setLabel("line color");
139  pro_linecolor.setValue(pro_linecolor, dataType->getDataTypeColor());
140  pro_linecolor.setMenu(true);
141  m_properties->addProperty(pro_linecolor);
142 
143  return m_properties;
144 }
145 
147 {
149 
150  Properties* vectorProps = const_cast<Properties*>(properties);
151 
152  Property pro_linecolor = vectorProps->contains("line_color");
153  if(!pro_linecolor.isNull())
154  {
155  m_lineColor = pro_linecolor.getValue().toColor();
156  }
157 }
158 
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
Variant getValue()
Returns stored value.
Definition: Property.cpp:72
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
Definition: Enums.cpp:52
virtual void setCoords(std::vector< te::gm::Point * > coords)
Definition: LineModel.cpp:77
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
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Definition: Envelope.h:400
The Properties class represents a persistent set of properties. The Properties can be saved to a file...
Definition: Properties.h:52
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
EnumType * m_type
type of the MVC component
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
void setPos(te::gm::Coord2D pos)
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
static Enums & getInstance()
It returns a reference to the singleton instance.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual te::color::RGBAColor getLineColor()
Definition: LineModel.cpp:125
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
void setChangePos(bool change)
virtual EnumType * getDataTypeColor() const
Returns value that represents type te::color::RGBAColor** (color) belonging to enumeration.
virtual void updateProperties(te::layout::Properties *properties)
Reimplemented from Observable.
Definition: LineModel.cpp:146
virtual Properties * getProperties() const
Reimplemented from Observable.
void setValue(ValueType value, EnumType *type)
Stores a copy of value.
Definition: Property.h:298
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void setName(std::string name)
Sets the name of this property.
Definition: Property.cpp:62
void setPointN(std::size_t i, const Point &p)
It sets the value of the specified point to this new one.
Definition: LineString.cpp:339
virtual void setMenu(bool menu)
Sets true if property will be used in a menu, false otherwise.
Definition: Property.cpp:228
te::color::RGBAColor toColor()
Returns the value of te::color::RGBAColor type. (The setValue method received a te::color::RGBAColor)...
Definition: Variant.cpp:341
te::color::RGBAColor m_borderColor
border color
virtual std::vector< te::gm::Point * > getCoords()
Definition: LineModel.cpp:120
virtual te::layout::Properties * getProperties() const
Reimplemented from Observable.
Definition: LineModel.cpp:130
virtual void setLabel(std::string label)
Sets the label of this property.
Definition: Property.cpp:218
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:104
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
te::color::RGBAColor m_lineColor
line color
Definition: LineModel.h:63