1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "workbench_physical_viewfigure_impl.h"
#include "model_layer_impl.h"
#include "workbench_physical_model_impl.h"
#include "workbench_physical_diagram_impl.h"
using namespace base;
workbench_physical_ViewFigure::ImplData::ImplData(workbench_physical_ViewFigure *owner)
: super(owner), _figure(0)
{
_resizable= false;
}
void workbench_physical_ViewFigure::ImplData::view_member_changed(const std::string &name,
const grt::ValueRef &ovalue)
{
if (name == "name")
{
self()->_name= self()->view()->name();
if (_figure)
_figure->set_title(*self()->_name);
}
}
void workbench_physical_ViewFigure::ImplData::set_in_view(bool flag)
{
if (!self()->owner().is_valid())
throw std::logic_error("adding figure to diagram before setting owner");
if (flag)
{
if (self()->_view.is_valid())
workbench_physical_DiagramRef::cast_from(self()->_owner)->get_data()->add_mapping(self()->_view, self());
}
else
{
if (self()->_view.is_valid())
workbench_physical_DiagramRef::cast_from(self()->_owner)->get_data()->remove_mapping(self()->_view);
}
model_Figure::ImplData::set_in_view(flag);
}
void workbench_physical_ViewFigure::ImplData::set_view(const db_ViewRef &view)
{
// Check if we had a valid view before and revert the previous setup if so.
if (self()->_view.is_valid())
{
if (self()->_owner.is_valid())
workbench_physical_DiagramRef::cast_from(self()->_owner)->get_data()->remove_mapping(self()->_view);
}
self()->_view= view;
if (_figure_conn.connected())
_figure_conn.disconnect();
if (self()->view().is_valid())
{
if (self()->_owner.is_valid())
workbench_physical_DiagramRef::cast_from(self()->_owner)->get_data()->add_mapping(view, self());
_figure_conn= self()->view()->signal_changed()->connect(boost::bind(&ImplData::view_member_changed, this, _1, _2));
self()->_name= self()->view()->name();
}
if (!_figure)
try_realize();
else if (_figure)
{
if (self()->view().is_valid())
_figure->set_title(*self()->view()->name());
else
unrealize();
}
}
void workbench_physical_ViewFigure::ImplData::member_changed(const std::string &name, const grt::ValueRef &ovalue)
{
/* dont rename view from figure
else if (name == "name")
{
if (grt::StringRef::cast_from(value) == self()->_view->name())
{
//if (__view.is_valid())
// __view.name(__name);
}
}*/
if (name == "color" && self()->owner().is_valid() && self()->owner()->owner().is_valid() &&
self()->owner()->owner()->get_data()->get_int_option("SynchronizeObjectColors", 0))
{
if (*grt::StringRef::cast_from(ovalue) != "")
self()->owner()->owner()->get_data()->update_object_color_in_all_diagrams(self()->_color,
"view", self()->_view.id());
super::member_changed(name, ovalue);
}
}
bool workbench_physical_ViewFigure::ImplData::is_realizable()
{
if (!super::is_realizable())
return false;
if (self()->_view.is_valid())
return true;
return false;
}
void workbench_physical_ViewFigure::ImplData::unrealize()
{
workbench_physical_ModelRef model(workbench_physical_ModelRef::cast_from(self()->owner()->owner()));
notify_will_unrealize();
// remove tag badges
std::list<meta_TagRef> tags(model->get_data()->get_tags_for_dbobject(self()->_view));
for (std::list<meta_TagRef>::const_iterator end= tags.end(), tag= tags.begin();
tag != end; ++tag)
{
self()->owner()->get_data()->remove_tag_badge_from_figure(self(), *tag);
}
super::unrealize();
delete _figure;
_figure= 0;
}
bool workbench_physical_ViewFigure::ImplData::realize()
{
if (_figure) return true;
if (!is_realizable()) return false;
if (!is_main_thread())
{
run_later(boost::bind(&ImplData::realize, this));
return true;
}
if (!_figure)
{
mdc::CanvasView *view= self()->owner()->get_data()->get_canvas_view();
workbench_physical_ModelRef model(workbench_physical_ModelRef::cast_from(self()->owner()->owner()));
mdc::AreaGroup *agroup;
if (!self()->_view.is_valid())
throw std::logic_error("Realizing table figure without table object");
view->lock();
_figure= new wbfig::View(view->get_current_layer(), self()->owner()->get_data(), self());
agroup= self()->layer()->get_data()->get_area_group();
view->get_current_layer()->add_item(_figure, agroup);
_figure->set_color(Color::parse(*self()->_color));
_figure->set_title(*self()->_view->name());
finish_realize();
view->unlock();
notify_realized();
// add badges for each tag
std::list<meta_TagRef> tags(model->get_data()->get_tags_for_dbobject(self()->_view));
for (std::list<meta_TagRef>::const_iterator end= tags.end(), tag= tags.begin();
tag != end; ++tag)
{
self()->owner()->get_data()->add_tag_badge_to_figure(self(), *tag);
}
}
return true;
}
|