All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ItemObserver.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 ItemObserver.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "ItemObserver.h"
30 #include "../singleton/Context.h"
31 #include "../../AbstractScene.h"
32 #include "../../property/Properties.h"
33 #include "ItemController.h"
34 #include "Observable.h"
35 #include "../../../../geometry/Coord2D.h"
36 
38  m_controller(controller),
39  m_model(o),
40  m_printable(true),
41  m_canChangeGraphicOrder(true),
42  m_nameClass("Unknown"),
43  m_invertedMatrix(false)
44 {
45  m_model->addObserver(this);
46 }
47 
49 {
50  if(m_controller)
51  delete (ItemController*)m_controller;
52 }
53 
54 void te::layout::ItemObserver::redraw( bool bRefresh )
55 {
56  if (bRefresh)
57  {
58  refresh();
59  }
60  else
61  {
62  double x = 0;
63  double y = 0;
64  x = m_model->getBox().getLowerLeftX();
65  y = m_model->getBox().getLowerLeftY();
66 
67  te::gm::Coord2D coord (x, y);
68 
69  ContextItem context;
70  context.setPos(coord);
71  context.setChangePos(true);
72  updateObserver(context);
73  }
74 
75  m_controller->redraw();
76 }
77 
79 {
80  if(pos)
81  {
82  te::gm::Coord2D coord = getPosition();
83  m_controller->setPosition(coord.x, coord.y);
84  }
85  setZValueItem(getZValueItem());
86  applyRotation();
87 }
88 
90 {
91  m_printable = print;
92 }
93 
95 {
96  return m_printable;
97 }
98 
100 {
101  return m_controller;
102 }
103 
105 {
106  return m_model;
107 }
108 
110 {
111  m_model->setZValue(z);
112 }
113 
115 {
116  m_canChangeGraphicOrder = canChange;
117 }
118 
120 {
121  return m_canChangeGraphicOrder;
122 }
123 
125 {
126  return m_nameClass;
127 }
128 
130 {
131  return m_invertedMatrix;
132 }
133 
134 void te::layout::ItemObserver::changeZoomFactor( double currentZoomFactor )
135 {
136  //do nothing
137 }
138 
140 {
141  //do nothing
142 }
143 
144 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
Definition: ContextItem.h:49
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
double y
y-coordinate.
Definition: Coord2D.h:114
te::layout::Observable * m_model
"Model" part of MVC component.
Definition: ItemObserver.h:198
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
double x
x-coordinate.
Definition: Coord2D.h:113
Abstract class to represent an observable. "Model" part of MVC component.
virtual void setPrintable(bool print)
Modifies the state of the graphic component to be or not printable.
virtual ~ItemObserver()
Destructor.
virtual void setZValueItem(int z)
The Z value decides the stacking order of drawing.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
virtual void recalculateBoundingRect()
The default implementation does nothing.
virtual bool isInvertedMatrix()
Returns whether the graph component has the inverted matrix, otherwise the matrix scene...
virtual void redraw(bool bRefresh=true)
Redraws the graphic component.
virtual bool isPrintable()
Returns whether the graphic component is printable.
ItemObserver(ItemController *controller=0, Observable *o=0)
Constructor.
void setPos(te::gm::Coord2D pos)
virtual void changeZoomFactor(double currentZoomFactor)
It is called immediately by the Scene when the zoom factor is changed in the Context.
virtual bool isCanChangeGraphicOrder()
Returns whether the graphic component to be or not send to back or bring to front.
virtual std::string getNameClass()
Method that returns the class name.
void setChangePos(bool change)
virtual void refresh(bool pos=true)
Updated model state.
virtual bool addObserver(Observer *o)=0
Adds the specified observer to the set of observers for this object. Reimplement this function in a O...
virtual void setCanChangeGraphicOrder(bool canChange)
Change the state of the graphic component to be or not send to back or bring to front.
virtual ItemController * getController()
Returns the "Controller" part of the MVC.
virtual Observable * getModel()
Returns the "Model" part of the MVC.