1 /* Copyright 2004, 2005 Nicholas Bishop 2 * 3 * This file is part of SharpConstruct. 4 * 5 * SharpConstruct is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * SharpConstruct is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with SharpConstruct; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 18 19 #ifndef MESHHISTORY_H 20 #define MESHHISTORY_H 21 22 #include "Mesh.h" 23 #include "Utilities.h" 24 #include <deque> 25 #include <sigc++/sigc++.h> 26 27 namespace SharpConstruct 28 { 29 class MeshHistory 30 { 31 public: 32 class PartialMesh 33 { 34 public: 35 class PartialVertexData : public Resource 36 { 37 public: VertexLocations()38 Optimized::Point3DVector& VertexLocations() 39 { 40 return _vertex_locations; 41 } VertexNormals()42 Optimized::Point3DVector& VertexNormals() 43 { 44 return _vertex_normals; 45 } 46 private: 47 Optimized::Point3DVector _vertex_locations; 48 Optimized::Point3DVector _vertex_normals; 49 }; 50 class PartialColorData : public Resource 51 { 52 public: VertexColors()53 std::vector< Color >& VertexColors() 54 { 55 return _vertex_colors; 56 } 57 private: 58 std::vector< Color > _vertex_colors; 59 }; 60 class PartialPolygonData : public Resource 61 { 62 public: TriangleNormals()63 Optimized::Point3DVector& TriangleNormals() 64 { 65 return _triangle_normals; 66 } QuadNormals()67 Optimized::Point3DVector& QuadNormals() 68 { 69 return _quad_normals; 70 } Triangles()71 std::vector< Triangle >& Triangles() 72 { 73 return _triangles; 74 } Quads()75 std::vector< Quad >& Quads() 76 { 77 return _quads; 78 } VertexUsers()79 std::vector< PolygonUsers >& VertexUsers() 80 { 81 return _vertex_users; 82 } 83 private: 84 Optimized::Point3DVector _triangle_normals; 85 Optimized::Point3DVector _quad_normals; 86 std::vector< Triangle > _triangles; 87 std::vector< Quad > _quads; 88 std::vector< PolygonUsers > _vertex_users; 89 }; 90 PartialMesh()91 PartialMesh() 92 : _saved( true ), _vertices( NULL ), 93 _colors( NULL ), _polygons( NULL ) 94 {} 95 ~PartialMesh()96 ~PartialMesh() 97 { 98 if( _vertices && !_vertices->Used() ) 99 delete _vertices; 100 101 if( _colors && !_colors->Used() ) 102 delete _colors; 103 104 if( _polygons && !_polygons->Used() ) 105 delete _polygons; 106 } 107 Saved()108 bool& Saved() 109 { 110 return _saved; 111 } Saved()112 bool Saved() const 113 { 114 return _saved; 115 } Filename()116 std::string& Filename() 117 { 118 return _filename; 119 } 120 Vertices()121 PartialVertexData* Vertices() 122 { 123 return _vertices; 124 } Colors()125 PartialColorData* Colors() 126 { 127 return _colors; 128 } Polygons()129 PartialPolygonData* Polygons() 130 { 131 return _polygons; 132 } SetVertices(PartialVertexData * pd)133 void SetVertices( PartialVertexData* pd ) 134 { 135 if( _vertices ) 136 _vertices->Release(); 137 _vertices = pd; 138 _vertices->Grab(); 139 } SetColors(PartialColorData * pd)140 void SetColors( PartialColorData* pd ) 141 { 142 if( _colors ) 143 _colors->Release(); 144 _colors = pd; 145 _colors->Grab(); 146 } SetPolygons(PartialPolygonData * pd)147 void SetPolygons( PartialPolygonData* pd ) 148 { 149 if( _polygons ) 150 _polygons->Release(); 151 _polygons = pd; 152 _polygons->Grab(); 153 } 154 VisibleElements()155 VisibleElementData& VisibleElements() 156 { 157 return _visible_elements; 158 } 159 private: 160 bool _saved; 161 std::string _filename; 162 PartialVertexData* _vertices; 163 PartialColorData* _colors; 164 PartialPolygonData* _polygons; 165 VisibleElementData _visible_elements; 166 }; 167 168 ~MeshHistory(); 169 170 static MeshHistory& Instance(); 171 172 void AddMesh( bool v, bool c, bool p, bool copy = true ); 173 void Undo(); 174 void Redo(); 175 void Clear(); 176 PartialMesh& GetPreviousComposite(); 177 PartialMesh& CurrentComposite(); 178 Mesh& GetCurrentMesh(); 179 int Maximum() const; 180 void SetMaximum( unsigned ); 181 bool UndoPossible() const; 182 bool RedoPossible() const; 183 bool Saved() const; 184 185 typedef sigc::signal< void, const bool, const bool, const bool > UpdateSignal; 186 sigc::signal< void, bool, bool >& Changed(); 187 UpdateSignal& SignalEntireSectionChanged(); 188 private: 189 MeshHistory( unsigned ); 190 191 void _print_debug_info(); 192 193 bool _update_composite(); 194 void _update_proxy(); 195 196 sigc::signal< void, bool, bool > _changed; 197 UpdateSignal signal_entire_section_changed_; 198 int _maximum, _current_index, _current_maximum_index; 199 std::deque< PartialMesh > _meshes; 200 Mesh* _current_mesh; 201 PartialMesh _current_composite; 202 PartialMesh _previous_composite; 203 }; 204 } 205 206 #endif // MESHHISTORY_H 207