00001 #ifndef K3DSDK_MESH_SOURCE_H
00002 #define K3DSDK_MESH_SOURCE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #include <k3d-i18n-config.h>
00028 #include <k3dsdk/data.h>
00029 #include <k3dsdk/hints.h>
00030 #include <k3dsdk/ipipeline_profiler.h>
00031 #include <k3dsdk/imesh_source.h>
00032 #include <k3dsdk/mesh.h>
00033 #include <k3dsdk/pointer_demand_storage.h>
00034
00035 namespace k3d
00036 {
00037
00038 template<typename base_t>
00039 class mesh_source :
00040 public base_t,
00041 public imesh_source
00042 {
00043 public:
00044 iproperty& mesh_source_output()
00045 {
00046 return m_output_mesh;
00047 }
00048
00050 sigc::slot<void, ihint*> make_update_mesh_slot()
00051 {
00052 return m_output_mesh.make_slot();
00053 }
00054
00055 protected:
00056 mesh_source(iplugin_factory& Factory, idocument& Document) :
00057 base_t(Factory, Document),
00058 m_output_mesh(init_owner(*this) + init_name("output_mesh") + init_label(_("Output Mesh")) + init_description("Output mesh"))
00059 {
00060 m_output_mesh.set_update_slot(sigc::mem_fun(*this, &mesh_source<base_t>::execute));
00061 }
00062
00064 k3d_data(mesh*, immutable_name, change_signal, no_undo, pointer_demand_storage, no_constraint, read_only_property, no_serialization) m_output_mesh;
00065
00066 private:
00068 void execute(const std::vector<ihint*>& Hints, mesh& Mesh)
00069 {
00070 bool_t update_topology = false;
00071 bool_t update_geometry = false;
00072
00073 for(uint_t i = 0; i != Hints.size(); ++i)
00074 {
00075
00076 if(dynamic_cast<hint::mesh_geometry_changed*>(Hints[i]))
00077 {
00078 update_geometry = true;
00079 }
00080
00081
00082 else
00083 {
00084 update_topology = true;
00085 update_geometry = true;
00086 break;
00087 }
00088 }
00089
00090 if(update_topology)
00091 {
00092 base_t::document().pipeline_profiler().start_execution(*this, "Update Topology");
00093 on_update_mesh_topology(Mesh);
00094 base_t::document().pipeline_profiler().finish_execution(*this, "Update Topology");
00095 }
00096
00097 if(update_geometry)
00098 {
00099 base_t::document().pipeline_profiler().start_execution(*this, "Update Geometry");
00100 on_update_mesh_geometry(Mesh);
00101 base_t::document().pipeline_profiler().finish_execution(*this, "Update Geometry");
00102 }
00103 }
00104
00108 virtual void on_update_mesh_topology(mesh& Output) = 0;
00109
00111 virtual void on_update_mesh_geometry(mesh& Output) = 0;
00112 };
00113
00114 }
00115
00116 #endif // !K3DSDK_MESH_SOURCE_H
00117