home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / legacy_mesh_source.h < prev    next >
C/C++ Source or Header  |  2008-08-04  |  4KB  |  125 lines

  1. #ifndef K3DSDK_LEGACY_MESH_SOURCE_H
  2. #define K3DSDK_LEGACY_MESH_SOURCE_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2004, Timothy M. Shead
  6. //
  7. // Contact: tshead@k-3d.com
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. // General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public
  20. // License along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  
  23. /** \file
  24.         \author Timothy M. Shead (tshead@k-3d.com)
  25. */
  26.  
  27. #include "data.h"
  28. #include "hints.h"
  29. #include "k3d-i18n-config.h"
  30. #include "imesh_source.h"
  31. #include "ipipeline_profiler.h"
  32. #include "legacy_mesh.h"
  33. #include "mesh.h"
  34.  
  35. namespace k3d
  36. {
  37.  
  38. namespace legacy
  39. {
  40.  
  41. /// Boilerplate mesh source code for legacy mesh source plugins that handles conversion between array meshes and legacy meshes
  42. /** \todo Rewrite plugins that use this class to generate array meshes directly */
  43. template<typename base_t>
  44. class mesh_source :
  45.     public base_t,
  46.     public imesh_source
  47. {
  48. public:
  49.     mesh_source(iplugin_factory& Factory, idocument& Document) :
  50.         base_t(Factory, Document),
  51.         m_output_mesh(init_owner(*this) + init_name("output_mesh") + init_label(_("Output Mesh")) + init_description("Output mesh"))
  52.     {
  53.         m_output_mesh.set_initialize_slot(sigc::mem_fun(*this, &mesh_source<base_t>::initialize_mesh));
  54.         m_output_mesh.set_update_slot(sigc::mem_fun(*this, &mesh_source<base_t>::update_mesh));
  55.     }
  56.  
  57.     iproperty& mesh_source_output()
  58.     {
  59.         return m_output_mesh;
  60.     }
  61.  
  62.     sigc::slot<void, ihint*> make_reset_mesh_slot()
  63.     {
  64.         return sigc::mem_fun(*this, &mesh_source<base_t>::reset_mesh);
  65.     }
  66.  
  67.     sigc::slot<void, ihint*> make_update_mesh_slot()
  68.     {
  69.         return m_output_mesh.make_update_slot();
  70.     }
  71.  
  72. protected:
  73.     k3d_data(k3d::mesh*, data::immutable_name, data::change_signal, data::no_undo, data::pointer_storage, data::no_constraint, data::read_only_property, data::no_serialization) m_output_mesh;
  74.  
  75. private:
  76.     void reset_mesh(ihint* Hint)
  77.     {
  78.         m_legacy_output.reset();
  79.         m_output_mesh.changed_signal().emit(hint::mesh_deleted::instance());
  80.         m_output_mesh.reset(0, hint::mesh_topology_changed::instance());
  81.     }
  82.  
  83.     void initialize_mesh(k3d::mesh& Output)
  84.     {
  85.         m_legacy_output.reset(new legacy::mesh());
  86.  
  87.         base_t::document().pipeline_profiler().start_execution(*this, "Create Mesh");
  88.         on_initialize_mesh(*m_legacy_output);
  89.         base_t::document().pipeline_profiler().finish_execution(*this, "Create Mesh");
  90.  
  91.         base_t::document().pipeline_profiler().start_execution(*this, "Update Mesh");
  92.         on_update_mesh(*m_legacy_output);
  93.         base_t::document().pipeline_profiler().finish_execution(*this, "Update Mesh");
  94.  
  95.         base_t::document().pipeline_profiler().start_execution(*this, "Convert Output");
  96.         Output = *m_legacy_output;
  97.         base_t::document().pipeline_profiler().finish_execution(*this, "Convert Output");
  98.     }
  99.  
  100.     void update_mesh(k3d::mesh& Output)
  101.     {
  102.         return_if_fail(m_legacy_output.get());
  103.  
  104.         base_t::document().pipeline_profiler().start_execution(*this, "Update Mesh");
  105.         on_update_mesh(*m_legacy_output);
  106.         base_t::document().pipeline_profiler().finish_execution(*this, "Update Mesh");
  107.  
  108.         base_t::document().pipeline_profiler().start_execution(*this, "Convert Output");
  109.         Output = *m_legacy_output;
  110.         base_t::document().pipeline_profiler().finish_execution(*this, "Convert Output");
  111.     }
  112.  
  113.     virtual void on_initialize_mesh(legacy::mesh& Output) = 0;
  114.     virtual void on_update_mesh(legacy::mesh& Output) = 0;
  115.  
  116.     std::auto_ptr<legacy::mesh> m_legacy_output;
  117. };
  118.  
  119. } // namespace legacy
  120.  
  121. } // namespace k3d
  122.  
  123. #endif // !K3DSDK_LEGACY_MESH_SOURCE_H
  124.  
  125.