home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / include / k3d / k3dsdk / selection.h < prev    next >
C/C++ Source or Header  |  2009-01-23  |  5KB  |  207 lines

  1. #ifndef K3DSDK_SELECTION_H
  2. #define K3DSDK_SELECTION_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. #include "gl.h"
  24. #include "inode_collection.h"
  25. #include "inode_selection.h"
  26. #include "iselectable.h"
  27. #include "nodes.h"
  28. #include <vector>
  29.  
  30. namespace k3d
  31. {
  32.  
  33. class inode;
  34.  
  35. class mesh;
  36. namespace legacy { class mesh; }
  37.  
  38. /// Functor object for deciding whether an object is selected (i.e. has a non-zero selection weight)
  39. struct is_selected
  40. {
  41.     template<typename T>
  42.     bool operator()(T* Object)
  43.     {
  44.         return Object->selection_weight != 0 ? true : false;
  45.     }
  46.  
  47.     template<typename T>
  48.     bool operator()(T& Object)
  49.     {
  50.         return Object.selection_weight != 0 ? true : false;
  51.     }
  52. };
  53.  
  54. namespace selection
  55. {
  56.  
  57. enum type
  58. {
  59.  
  60. /** \note Never alter the values of these enumerations, they may be used for efficient serialization */
  61.  
  62. /// Used to mark "NULL" tokens
  63. NONE = 0,
  64. /// Storage for a zero-based node index (relative to the document node collection)
  65. NODE = 1,
  66. /// Storage for a zero-based mesh index (relative to a node)
  67. MESH = 2,
  68. //POINT_GROUP = 3,
  69. //POINT = 4,
  70. /** \deprecated Storage for a zero-based point index (relative to a mesh) */
  71. ABSOLUTE_POINT = 5,
  72. //POLYHEDRON = 6,
  73. //FACE = 7,
  74. /** \deprecated Storage for a zero-based face index (relative to a mesh) */
  75. ABSOLUTE_FACE = 8,
  76. //FACE_HOLE = 9,
  77. //SPLIT_EDGE = 10,
  78. /** \deprecated Storage for a zero-based split-edge index (relative to a mesh) */
  79. ABSOLUTE_SPLIT_EDGE = 11,
  80. //LINEAR_CURVE_GROUP = 12,
  81. //LINEAR_CURVE = 13,
  82. //ABSOLUTE_LINEAR_CURVE = 14,
  83. //CUBIC_CURVE_GROUP = 15,
  84. //CUBIC_CURVE = 16,
  85. //ABSOLUTE_CUBIC_CURVE = 17,
  86. //NUCURVE_GROUP = 18,
  87. //NUCURVE = 19,
  88. /** \deprecated Storage for a zero-based NURBS curve index (relative to a mesh) */
  89. ABSOLUTE_NURBS_CURVE = 20,
  90. //ABSOLUTE_BILINEAR_PATCH = 21,
  91. //ABSOLUTE_BICUBIC_PATCH = 22,
  92. /** \deprecated Storage for a zero-based NURBS patch index (relative to a mesh) */
  93. ABSOLUTE_NURBS_PATCH = 23,
  94. /// Storage for a user-defined index
  95. USER1 = 24,
  96. /// Storage for a zero-based primitive index (relative to a mesh)
  97. PRIMITIVE = 25,
  98. /// Storage for a zero-based constant index (relative to a primitive)
  99. CONSTANT = 26,
  100. /// Storage for a zero-based uniform index (relative to a primitive)
  101. UNIFORM = 27,
  102. /// Storage for a zero-based varying index (relative to a primitive)
  103. VARYING = 28,
  104. /// Storage for a zero-based face-varying index (relative to a primitive)
  105. FACE_VARYING = 29,
  106. /// Storage for a zero-based split-edge index (relative to a primitive)
  107. SPLIT_EDGE = 30,
  108. /// Storage for a zero-based point index (relative to a mesh)
  109. POINT = 31,
  110.  
  111. };
  112.  
  113. std::ostream& operator<<(std::ostream& Stream, const type& RHS);
  114. std::istream& operator>>(std::istream& Stream, type& RHS);
  115.  
  116. typedef GLuint id;
  117. const id null_id();
  118.  
  119. struct token
  120. {
  121.     token();
  122.     token(const selection::type Type, const selection::id ID);
  123.  
  124.     selection::type type;
  125.     selection::id id;
  126. };
  127.  
  128. bool operator==(const token& LHS, const token& RHS);
  129. bool operator!=(const token& LHS, const token& RHS);
  130. std::ostream& operator<<(std::ostream& Stream, const token& RHS);
  131. std::istream& operator>>(std::istream& Stream, token& RHS);
  132.  
  133. struct record
  134. {
  135.     record();
  136.     static const record empty_record();
  137.  
  138.     const bool empty() const;
  139.     const id get_id(const selection::type Type) const;
  140.     const token get_token(const selection::type Type) const;
  141.  
  142.     GLuint zmin;
  143.     GLuint zmax;
  144.  
  145.     typedef std::vector<token> tokens_t;
  146.     tokens_t tokens;
  147. };
  148. std::ostream& operator<<(std::ostream& Stream, const record& RHS);
  149. std::istream& operator>>(std::istream& Stream, record& RHS);
  150.  
  151. typedef std::vector<record> records;
  152.  
  153. const id node_id(inode*);
  154. const record make_record(inode*);
  155. const records make_records(inode*);
  156.  
  157. inode* get_node(const record& Record);
  158. mesh* get_mesh(const record& Record);
  159.  
  160. template<typename T>
  161. const bool is_selected(T* Object)
  162. {
  163.     iselectable* const selectable = dynamic_cast<iselectable*>(Object);
  164.     return selectable && selectable->get_selection_weight();
  165. }
  166.  
  167. /// Functor object for setting selection weight on a collection of objects - good with k3d::for_each_component
  168. struct set_weight
  169. {
  170.     set_weight(const double SelectionWeight) :
  171.         selection_weight(SelectionWeight)
  172.     {
  173.     }
  174.  
  175.     template<typename T>
  176.     void operator()(T& Object) const
  177.     {
  178.         Object.selection_weight = selection_weight;
  179.     }
  180.  
  181.     template<typename T>
  182.     void operator()(T* Object) const
  183.     {
  184.         Object->selection_weight = selection_weight;
  185.     }
  186.  
  187.     double selection_weight;
  188. };
  189.  
  190. } // namespace selection
  191.  
  192. namespace gl
  193. {
  194.  
  195. void push_selection_token(inode*);
  196. void push_selection_token(const selection::token&);
  197. void push_selection_token(const selection::type, const selection::id);
  198.  
  199. void pop_selection_token();
  200.  
  201. } // namespace gl
  202.  
  203. } // namespace k3d
  204.  
  205. #endif // !K3DSDK_SELECTION_H
  206.  
  207.