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

  1. #ifndef K3DSDK_MESH_SELECTION_MODIFIER_H
  2. #define K3DSDK_MESH_SELECTION_MODIFIER_H
  3.  
  4. // K-3D
  5. // Copyright (c) 1995-2008, 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 "imesh_sink.h"
  30. #include "imesh_source.h"
  31. #include "ipipeline_profiler.h"
  32. #include "mesh.h"
  33. #include "pointer_demand_storage.h"
  34.  
  35. namespace k3d
  36. {
  37.  
  38. /// Mesh modifier implementation for use in plugins that alter the selection state of a mesh without altering its topology or geometry.  To create a plugin, derive from mesh_selection_modifier and implement the on_select_mesh() method.
  39. template<typename base_t>
  40. class mesh_selection_modifier :
  41.     public base_t,
  42.     public imesh_sink,
  43.     public imesh_source
  44. {
  45. public:
  46.     iproperty& mesh_source_output()
  47.     {
  48.         return m_output_mesh;
  49.     }
  50.  
  51.     iproperty& mesh_sink_input()
  52.     {
  53.         return m_input_mesh;
  54.     }
  55.  
  56.     /// Returns a slot that should be connected to input properties to signal that the output mesh has changed
  57.     sigc::slot<void, ihint*> make_update_mesh_slot()
  58.     {
  59.         return m_output_mesh.make_slot();
  60.     }
  61.  
  62. protected:
  63.     mesh_selection_modifier(iplugin_factory& Factory, idocument& Document) :
  64.         base_t(Factory, Document),
  65.         m_input_mesh(init_owner(*this) + init_name("input_mesh") + init_label(_("Input Mesh")) + init_description(_("Input mesh")) + init_value<mesh*>(0)),
  66.         m_output_mesh(init_owner(*this) + init_name("output_mesh") + init_label(_("Output Mesh")) + init_description(_("Output mesh")))
  67.     {
  68.         m_input_mesh.changed_signal().connect(hint::converter<
  69.             hint::convert<hint::any, hint::none> >(make_update_mesh_slot()));
  70.  
  71.         m_output_mesh.set_update_slot(sigc::mem_fun(*this, &mesh_selection_modifier<base_t>::execute));
  72.     }
  73.  
  74.     /// Called whenever the output mesh has been modified and needs to be updated.
  75.     void execute(const std::vector<ihint*>& Hints, mesh& Mesh)
  76.     {
  77.         // In our case, we don't have to worry about any hints, we just execute.
  78.         if(const mesh* const input = m_input_mesh.pipeline_value())
  79.         {
  80.             Mesh = *input;
  81.             
  82.             base_t::document().pipeline_profiler().start_execution(*this, "Update Selection");
  83.             on_update_selection(*input, Mesh);
  84.             base_t::document().pipeline_profiler().finish_execution(*this, "Update Selection");
  85.         }
  86.     }
  87.  
  88.     k3d_data(mesh*, immutable_name, change_signal, no_undo, local_storage, no_constraint, read_only_property, no_serialization) m_input_mesh;
  89.     k3d_data(mesh*, immutable_name, change_signal, no_undo, pointer_demand_storage, no_constraint, read_only_property, no_serialization) m_output_mesh;
  90.  
  91. private:
  92.     /// Implement this method in derived classes and alter the output selection(s) as-desired.
  93.     virtual void on_update_selection(const mesh& Input, mesh& Output) = 0;
  94. };
  95.  
  96. } // namespace k3d
  97.  
  98. #endif // !K3DSDK_MESH_SELECTION_MODIFIER_H
  99.  
  100.