All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ItemController.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2014 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 ItemController.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "ItemController.h"
30 #include "ItemModelObservable.h"
31 #include "ItemObserver.h"
32 #include "ContextItem.h"
33 #include "Context.h"
34 #include "../../../../../maptools/Canvas.h"
35 
37  m_model(o)
38 {
39 
40 }
41 
43  m_model(o)
44 {
45  if(m_model)
46  {
47  m_model->setType(type);
48  }
49 }
50 
52 {
53  if(m_model)
54  {
55  ItemModelObservable* model = dynamic_cast<ItemModelObservable*>(m_model);
56  if(model)
57  delete model;
58  m_model = 0;
59  }
60 }
61 
62 void te::layout::ItemController::redraw( const double& zoomFactor )
63 {
64  ParamsCreate params;
65  ContextItem context(params, zoomFactor);
66 
68  canvas->clear();
69  if(m_model)
70  {
71  ItemModelObservable* model = dynamic_cast<ItemModelObservable*>(m_model);
72  if(model)
73  model->draw(context);
74  }
75  canvas->clear();
76 }
77 
79 {
80  return m_model;
81 }
82 
84 {
85  return m_view;
86 }
87 
89 {
90  if(m_model)
91  {
92  ItemModelObservable* model = dynamic_cast<ItemModelObservable*>(m_model);
93  if(model)
94  model->setBox(box);
95  }
96 }
97 
99 {
100  if(m_model)
101  {
102  ItemModelObservable* model = dynamic_cast<ItemModelObservable*>(m_model);
103  if(model)
104  model->updateProperties(properties);
105  }
106 }
107 
109 {
110  if(m_model)
111  {
112  ItemModelObservable* model = dynamic_cast<ItemModelObservable*>(m_model);
113  if(model)
114  return model->contains(coord);
115  }
116  return false;
117 }
virtual bool contains(const te::gm::Coord2D &coord) const
const Observer * getView()
virtual void updateProperties(te::layout::Properties *properties)
virtual void redraw(const double &zoomFactor)
virtual void clear()=0
It clears the canvas content and fills with the background color.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
const Observable * getModel()
virtual void updateProperties(te::layout::Properties *properties)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
LayoutAbstractObjectType
Enum TdkAbstractComponentType. This is the enumeration of the components types.
Definition: AbstractType.h:38
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
virtual void draw(ContextItem context)=0
virtual void setType(LayoutAbstractObjectType type)=0
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
virtual bool contains(const te::gm::Coord2D &coord) const
virtual void setBox(te::gm::Envelope box)
te::map::Canvas * getCanvas()
Definition: Context.cpp:116
virtual void setBox(te::gm::Envelope box)