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
|
// K-3D
// Copyright (c) 1995-2008, 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
#include <k3d-i18n-config.h>
#include <k3dsdk/application_plugin_factory.h>
#include <k3dsdk/metadata_keys.h>
#include <k3dsdk/module.h>
#include <k3dsdk/ngui/custom_property_control.h>
#include <k3dsdk/ngui/document_state.h>
#include <k3dsdk/ngui/entry.h>
#include <k3dsdk/mesh.h>
#include <k3dsdk/property.h>
#include <k3dsdk/type_registry.h>
#include <gtkmm/box.h>
#include <gtkmm/spinbutton.h>
#include <boost/assign/list_of.hpp>
using namespace k3d::ngui;
namespace module
{
namespace ngui
{
namespace knot_vector
{
/////////////////////////////////////////////////////////////////////////////
// control
/// Provides a custom property-control for NURBS knot-vectors
class control :
public k3d::ngui::custom_property::control,
public k3d::iunknown,
public Gtk::VBox
{
public:
control() :
Gtk::VBox()
{
}
~control()
{
}
/// Implementation of entry::imodel for use with knot vectors
class knot_vector_model :
public entry::imodel
{
public:
knot_vector_model(k3d::iproperty& Data) :
m_readable_data(Data),
m_writable_data(dynamic_cast<k3d::iwritable_property*>(&Data))
{
}
const Glib::ustring label()
{
Glib::ustring result = m_readable_data.property_label();
if(m_readable_data.property_node())
result = m_readable_data.property_node()->name() + " " + result;
return result;
}
const k3d::string_t value()
{
const std::type_info& type = m_readable_data.property_type();
if(type == typeid(k3d::mesh::knots_t))
{
const k3d::mesh::knots_t knots = boost::any_cast<k3d::mesh::knots_t>(m_readable_data.property_internal_value());
std::ostringstream buffer;
std::copy(knots.begin(), knots.end(), std::ostream_iterator<double>(buffer, " "));
return buffer.str();
}
k3d::log() << error << k3d_file_reference << ": unsupported property type: " << k3d::demangle(type) << std::endl;
return k3d::string_t();
}
void set_value(const k3d::string_t& Value)
{
return_if_fail(m_writable_data);
const std::type_info& type = m_readable_data.property_type();
if(type == typeid(k3d::mesh::knots_t))
{
double knot;
k3d::mesh::knots_t knots;
std::istringstream buffer(Value);
for(buffer >> knot; buffer; buffer >> knot)
knots.push_back(knot);
m_writable_data->property_set_value(knots);
return;
}
k3d::log() << error << k3d_file_reference << ": unsupported property type: " << k3d::demangle(type) << std::endl;
}
sigc::connection connect_changed_signal(const sigc::slot<void>& Slot)
{
return m_readable_data.property_changed_signal().connect(sigc::hide(Slot));
}
private:
k3d::iproperty& m_readable_data;
k3d::iwritable_property* const m_writable_data;
};
void initialize(document_state& DocumentState, k3d::iproperty& Property)
{
entry::control* const control = new entry::control(new knot_vector_model(Property), &DocumentState.document().state_recorder());
pack_start(*Gtk::manage(control), Gtk::PACK_EXPAND_WIDGET);
}
static k3d::iplugin_factory& get_factory()
{
static k3d::application_plugin_factory<control> factory(
k3d::uuid(0xade18285, 0x9a4333fc, 0x7449f382, 0x39628d15),
"NGUIKnotVectorControl",
_("Provides a custom property control for NURBS knot vectors."),
"NGUI Control",
k3d::iplugin_factory::EXPERIMENTAL,
boost::assign::map_list_of("ngui:component-type", "property-control")("ngui:property-role", k3d::metadata::value::nurbs_knot_vector_role().c_str()));
return factory;
}
};
} // namespace knot_vector
} // namespace ngui
} // namespace module
K3D_MODULE_START(Registry)
Registry.register_factory(module::ngui::knot_vector::control::get_factory());
K3D_MODULE_END
|