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) 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 BuildContext.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "BuildContext.h"
30 #include "Context.h"
31 #include "ItemFactory.h"
32 #include "OutsideFactory.h"
33 #include "TemplateFactory.h"
34 #include "Utils.h"
35 #include "PaperConfig.h"
36 #include "Scene.h"
37 #include "BuildGraphicsItem.h"
38 
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 {
49 
50 }
51 
53 {
54  if(m_itemFactory)
55  {
56  delete m_itemFactory;
57  m_itemFactory = 0;
58  }
59 
60  if(m_outsideFactory)
61  {
62  delete m_outsideFactory;
63  m_outsideFactory = 0;
64  }
65 
66  if(m_templateFactory)
67  {
68  delete m_templateFactory;
69  m_templateFactory = 0;
70  }
71 
72  if(m_utils)
73  {
74  delete m_utils;
75  m_utils = 0;
76  }
77 
78  if(m_paperConfig)
79  {
80  delete m_paperConfig;
81  m_paperConfig = 0;
82  }
83 
84  if(m_buildGraphicsItem)
85  {
86  delete m_buildGraphicsItem;
87  m_buildGraphicsItem = 0;
88  }
89 
90  if(m_canvas)
91  {
92  delete m_canvas;
93  m_canvas = 0;
94  }
95 }
96 
97 void te::layout::BuildContext::createLayoutContext( int width, int height, View* view )
98 {
99  if(!Context::getInstance()->getItemFactory())
100  {
101  m_itemFactory = new ItemFactory;
102  Context::getInstance()->setItemFactory(m_itemFactory);
103  }
104 
105  if(!Context::getInstance()->getOutsideFactory())
106  {
107  m_outsideFactory = new OutsideFactory;
108  Context::getInstance()->setOutsideFactory(m_outsideFactory);
109  }
110 
111  if(!Context::getInstance()->getTemplateFactory())
112  {
113  m_templateFactory = new TemplateFactory;
114  Context::getInstance()->setTemplateFactory(m_templateFactory);
115  }
116 
117  if(!Context::getInstance()->getUtils())
118  {
119  m_utils = new Utils;
120  Context::getInstance()->setUtils(m_utils);
121  }
122 
123  if(!Context::getInstance()->getPaperConfig())
124  {
125  m_paperConfig = new PaperConfig;
126  Context::getInstance()->setPaperConfig(m_paperConfig);
127  }
128 
129  if(!Context::getInstance()->getCanvas())
130  {
131  Scene* lScene = dynamic_cast<Scene*>(view->scene());
132 
133  if(lScene)
134  {
135  te::gm::Envelope* worldbox = lScene->getWorldBox();
136 
137  if(!worldbox)
138  worldbox = new te::gm::Envelope;
139 
140  //Create Canvas
141  m_canvas = new te::qt::widgets::Canvas(width, height);
142  m_canvas->setWindow(worldbox->getLowerLeftX(), worldbox->getLowerLeftY(),
143  worldbox->getUpperRightX(), worldbox->getUpperRightY());
144  m_canvas->clear();
145  Context::getInstance()->setCanvas(m_canvas);
146  }
147  }
148 
149  if(!Context::getInstance()->getScene())
150  {
151  Scene* lScene = dynamic_cast<Scene*>(view->scene());
152  if(lScene)
153  Context::getInstance()->setScene(lScene);
154  }
155  if(!Context::getInstance()->getBuildGraphicsItem())
156  {
157  m_buildGraphicsItem = new BuildGraphicsItem;
158  Context::getInstance()->setBuildGraphicsItem(m_buildGraphicsItem);
159  }
160 }
161 
void setPaperConfig(PaperConfig *config)
Definition: Context.cpp:176
void setScene(AbstractScene *scene)
Definition: Context.cpp:71
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
Definition: Envelope.h:410
virtual te::gm::Envelope * getWorldBox() const
Definition: Scene.cpp:334
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)
Definition: Context.cpp:91
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)
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void setOutsideFactory(AbstractOutsideFactory *factory)
Definition: Context.cpp:101
A canvas built on top of Qt.
Definition: Canvas.h:54
void setCanvas(te::map::Canvas *canvas)
Definition: Context.cpp:121
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
Definition: Envelope.h:390
void setUtils(Utils *utils)
Definition: Context.cpp:131
static Context * getInstance()
This function is called to create an instance of the class.
Definition: Context.cpp:46
void setBuildGraphicsItem(BuildGraphicsItem *build)
Definition: Context.cpp:186
void setTemplateFactory(AbstractTemplateFactory *factory)
Definition: Context.cpp:111