All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BuildContext.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 BuildContext.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "BuildContext.h"
30 #include "../../../layout/core/pattern/singleton/Context.h"
31 #include "../../../layout/qt/core/pattern/factory/ItemFactory.h"
32 #include "../../../layout/qt/core/pattern/factory/OutsideFactory.h"
33 #include "../../../layout/core/template/TemplateFactory.h"
34 #include "../../../layout/core/Utils.h"
35 #include "../../../layout/qt/core/Scene.h"
36 #include "../../../layout/qt/core/BuildGraphicsItem.h"
37 #include "../../../layout/qt/core/ItemUtils.h"
38 #include "../../../layout/qt/core/BuildGraphicsOutside.h"
39 
41  m_itemFactory(0),
42  m_outsideFactory(0),
43  m_templateFactory(0),
44  m_utils(0),
45  m_paperConfig(0),
46  m_canvas(0),
47  m_buildGraphicsItem(0),
48  m_itemUtils(0),
49  m_buildGraphicsOutside(0)
50 {
51 
52 }
53 
55 {
56  if(m_itemFactory)
57  {
58  delete m_itemFactory;
59  m_itemFactory = 0;
60  }
61 
62  if(m_outsideFactory)
63  {
64  delete m_outsideFactory;
65  m_outsideFactory = 0;
66  }
67 
68  if(m_templateFactory)
69  {
70  delete m_templateFactory;
71  m_templateFactory = 0;
72  }
73 
74  if(m_utils)
75  {
76  delete m_utils;
77  m_utils = 0;
78  }
79 
80  if(m_paperConfig)
81  {
82  delete m_paperConfig;
83  m_paperConfig = 0;
84  }
85 
86  if(m_buildGraphicsItem)
87  {
88  delete m_buildGraphicsItem;
89  m_buildGraphicsItem = 0;
90  }
91 
92  if(m_canvas)
93  {
94  delete m_canvas;
95  m_canvas = 0;
96  }
97 
98  if(m_itemUtils)
99  {
100  delete m_itemUtils;
101  m_itemUtils = 0;
102  }
103 
104  if(m_buildGraphicsOutside)
105  {
106  delete m_buildGraphicsOutside;
107  m_buildGraphicsOutside = 0;
108  }
109 }
110 
111 void te::layout::BuildContext::createLayoutContext( int width, int height, View* view )
112 {
113  if(!Context::getInstance().getItemFactory())
114  {
115  m_itemFactory = new ItemFactory;
116  Context::getInstance().setItemFactory(m_itemFactory);
117  }
118 
119  if(!Context::getInstance().getOutsideFactory())
120  {
121  m_outsideFactory = new OutsideFactory;
122  Context::getInstance().setOutsideFactory(m_outsideFactory);
123  }
124 
125  if(!Context::getInstance().getTemplateFactory())
126  {
127  m_templateFactory = new TemplateFactory;
128  Context::getInstance().setTemplateFactory(m_templateFactory);
129  }
130 
131  if(!Context::getInstance().getUtils())
132  {
133  m_utils = new Utils;
134  Context::getInstance().setUtils(m_utils);
135  }
136 
137  if(!Context::getInstance().getPaperConfig())
138  {
139  m_paperConfig = new PaperConfig;
140  Context::getInstance().setPaperConfig(m_paperConfig);
141  }
142 
143  if(!Context::getInstance().getCanvas())
144  {
145  Scene* lScene = dynamic_cast<Scene*>(view->scene());
146 
147  if(lScene)
148  {
149  te::gm::Envelope worldbox = lScene->getSceneBox();
150 
151  //Create Canvas
152  m_canvas = new te::qt::widgets::Canvas(width, height);
153  m_canvas->setWindow(worldbox.getLowerLeftX(), worldbox.getLowerLeftY(),
154  worldbox.getUpperRightX(), worldbox.getUpperRightY());
155  m_canvas->clear();
156  Context::getInstance().setCanvas(m_canvas);
157  }
158  }
159 
160  if(!Context::getInstance().getScene())
161  {
162  Scene* lScene = dynamic_cast<Scene*>(view->scene());
163  if(lScene)
164  Context::getInstance().setScene(lScene);
165  }
166  if(!Context::getInstance().getAbstractBuildGraphicsItem())
167  {
168  m_buildGraphicsItem = new BuildGraphicsItem;
169  Context::getInstance().setAbstractBuildGraphicsItem(m_buildGraphicsItem);
170  }
171  if(!Context::getInstance().getSystematicScaleConfig())
172  {
173  m_systematicConfig = new SystematicScaleConfig;
174  Context::getInstance().setSystematicScaleConfig(m_systematicConfig);
175  }
176  if(!Context::getInstance().getItemUtils())
177  {
178  Scene* lScene = dynamic_cast<Scene*>(view->scene());
179  if(lScene)
180  {
181  m_itemUtils = new ItemUtils(view->scene());
182  Context::getInstance().setItemUtils(m_itemUtils);
183  }
184  }
185  if(!Context::getInstance().getAbstractBuildGraphicsOutside())
186  {
187  m_buildGraphicsOutside = new BuildGraphicsOutside;
188  Context::getInstance().setAbstractBuildGraphicsOutside(m_buildGraphicsOutside);
189  }
190 }
191 
192 
193 
194 
void setPaperConfig(PaperConfig *config)
Change paper setting.
Definition: Context.cpp:203
Class responsible for paper setting. Size, orientation, custom size, etc.
Definition: PaperConfig.h:45
void setItemUtils(ItemUtils *utils)
Change pointer for manipulating items in the scene and vectorization of text and legend.
Definition: Context.cpp:268
void setScene(AbstractScene *scene)
Change scene, QGraphicsScene class, part of Graphics View Framework.
Definition: Context.cpp:98
void setAbstractBuildGraphicsItem(AbstractBuildGraphicsItem *build)
Change a pointer for build graphics MVC components.
Definition: Context.cpp:213
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
void setSystematicScaleConfig(SystematicScaleConfig *scale)
Definition: Context.cpp:253
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Definition: Envelope.h:400
void setItemFactory(AbstractItemFactory *factory)
Change factory for creating families of related or dependent graphic objects (MVC components)...
Definition: Context.cpp:118
Factory for creating families of related or dependent graphic objects (MVC components).
Definition: ItemFactory.h:46
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:420
void createLayoutContext(int width, int height, View *view)
void setAbstractBuildGraphicsOutside(AbstractBuildGraphicsOutside *build)
Change a pointer for build graphics MVC components.
Definition: Context.cpp:303
Class responsible for creating or building graphics objects. All objects are children of QGraphicsIte...
static Context & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
Class responsible for creating or building widgets. All objects are children of Qwidget and OutsideOb...
Class representing the view. This view is child of QGraphicsView, part of Graphics View Framework...
Definition: View.h:89
Utility class for manipulating items in the scene and vectorization of text and legend.
Definition: ItemUtils.h:62
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
void setOutsideFactory(AbstractOutsideFactory *factory)
Change factory provide an interface for creating families of related or dependent graphic widgets (MV...
Definition: Context.cpp:128
A canvas built on top of Qt.
Definition: Canvas.h:54
void setCanvas(te::map::Canvas *canvas)
Change abstraction of a drawing area.
Definition: Context.cpp:148
Factory for creating families of related or dependent templates.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
virtual te::gm::Envelope getSceneBox()
Method that return the scene box.
void setUtils(Utils *utils)
Change pointer with functions to manipulate the canvas and conversion between projections.
Definition: Context.cpp:158
Factory for creating families of related or dependent widgets (MVC widgets).
Utility class with functions to manipulate the canvas and conversion between projections.
Definition: Utils.h:61
void setTemplateFactory(AbstractTemplateFactory *factory)
Change factory provide an interface for creating families of related or dependent templates...
Definition: Context.cpp:138