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
|
// K-3D
// Copyright (c) 1995-2004, Timothy M. Shead
//
// Contact: tshead@k-3d.com
//
// 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; either
// version 2 of the License, or (at your option) any later version.
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** \file
\brief Implements object, a default implementation of the iobject interface for use as a base class for document objects
\author Tim Shead (tshead@k-3d.com)
*/
#include "application.h"
#include "icommand_tree.h"
#include "imouse_event_observer.h"
#include "iplugin_factory.h"
#include "iplugin_factory.h"
#include "iselection.h"
#include "object.h"
#include <algorithm>
#include <iostream>
namespace k3d
{
namespace detail
{
/// Concrete implementation of istate_container that adds a command node to the command tree
class add_command_node :
public istate_container
{
public:
add_command_node(icommand_node& Node, icommand_node& Parent) :
m_node(Node),
m_parent(Parent)
{
}
~add_command_node()
{
}
void restore_state()
{
application().command_tree().add_node(m_node, m_parent);
}
private:
icommand_node& m_node;
icommand_node& m_parent;
};
/// Concrete implementation of istate_container that removes a command node from the command tree
class remove_command_node :
public istate_container
{
public:
remove_command_node(icommand_node& Node) :
m_node(Node)
{
}
~remove_command_node()
{
}
void restore_state()
{
application().command_tree().remove_node(m_node);
}
private:
icommand_node& m_node;
};
} // namespace detail
/////////////////////////////////////////////////////////////////////////////
// object
object::object(idocument& Document) :
command_node(""),
property_collection(Document.dag()),
m_document(Document),
m_id(0),
m_name(init_name("name") + init_description("Object name [string]") + init_value<std::string>("") +init_document(Document))
{
register_property(m_name);
// Add ourselves to the command tree ...
application().command_tree().add_node(*this, dynamic_cast<icommand_node&>(m_document));
// If we're recording undos ...
istate_change_set* const changeset = m_document.state_recorder().current_change_set();
if(changeset)
{
// changeset->undo_signal().connect(m_deleted_signal.slot());
changeset->record_old_state(new detail::remove_command_node(*this));
changeset->record_new_state(new detail::add_command_node(*this, dynamic_cast<icommand_node&>(m_document)));
}
// We want to know when we're deleted
m_deleted_signal.connect(SigC::slot(*this, &object::on_deleted));
// We want to know whenever our name changes
m_name.changed_signal().connect(SigC::slot(*this, &object::on_name_changed));
// We want to know whenever a request comes in to deselect everything
m_document.selection().deselect_all_signal().connect(SigC::slot(*this, &object::on_deselect_all));
}
object::~object()
{
}
const iobject::id_type object::id()
{
return m_id;
}
void object::set_id(const id_type ID)
{
m_id = ID;
}
void object::set_name(const std::string Name)
{
m_name.set_value(Name);
}
const std::string object::name()
{
return m_name.value();
}
void object::on_deleted()
{
// Remove ourselves from the command tree ...
application().command_tree().remove_node(*this);
// Signal that our properties are going away ...
properties_t props(properties());
for(properties_t::iterator property = props.begin(); property != props.end(); ++property)
(*property)->deleted_signal().emit();
// If we're recording undos ...
istate_change_set* const changeset = m_document.state_recorder().current_change_set();
if(changeset)
{
changeset->record_old_state(new detail::add_command_node(*this, dynamic_cast<icommand_node&>(m_document)));
changeset->record_new_state(new detail::remove_command_node(*this));
}
}
void object::on_name_changed()
{
set_command_node_name(m_name.value());
}
void object::on_deselect_all()
{
deselect();
}
idocument& object::document()
{
return m_document;
}
iobject::deleted_signal_t& object::deleted_signal()
{
return m_deleted_signal;
}
iobject::name_changed_signal_t& object::name_changed_signal()
{
return m_name.changed_signal();
}
iobject::visibility_changed_signal_t& object::visibility_changed_signal()
{
return m_visibility_changed_signal;
}
} // namespace k3d
|