/* Copyright 2004, 2005 Nicholas Bishop * * This file is part of SharpConstruct. * * SharpConstruct is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * SharpConstruct is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SharpConstruct; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef MESHHISTORY_H #define MESHHISTORY_H #include "Mesh.h" #include "Utilities.h" #include #include namespace SharpConstruct { class MeshHistory { public: class PartialMesh { public: class PartialVertexData : public Resource { public: Optimized::Point3DVector& VertexLocations() { return _vertex_locations; } Optimized::Point3DVector& VertexNormals() { return _vertex_normals; } private: Optimized::Point3DVector _vertex_locations; Optimized::Point3DVector _vertex_normals; }; class PartialColorData : public Resource { public: std::vector< Color >& VertexColors() { return _vertex_colors; } private: std::vector< Color > _vertex_colors; }; class PartialPolygonData : public Resource { public: Optimized::Point3DVector& TriangleNormals() { return _triangle_normals; } Optimized::Point3DVector& QuadNormals() { return _quad_normals; } std::vector< Triangle >& Triangles() { return _triangles; } std::vector< Quad >& Quads() { return _quads; } std::vector< PolygonUsers >& VertexUsers() { return _vertex_users; } private: Optimized::Point3DVector _triangle_normals; Optimized::Point3DVector _quad_normals; std::vector< Triangle > _triangles; std::vector< Quad > _quads; std::vector< PolygonUsers > _vertex_users; }; PartialMesh() : _saved( true ), _vertices( NULL ), _colors( NULL ), _polygons( NULL ) {} ~PartialMesh() { if( _vertices && !_vertices->Used() ) delete _vertices; if( _colors && !_colors->Used() ) delete _colors; if( _polygons && !_polygons->Used() ) delete _polygons; } bool& Saved() { return _saved; } bool Saved() const { return _saved; } std::string& Filename() { return _filename; } PartialVertexData* Vertices() { return _vertices; } PartialColorData* Colors() { return _colors; } PartialPolygonData* Polygons() { return _polygons; } void SetVertices( PartialVertexData* pd ) { if( _vertices ) _vertices->Release(); _vertices = pd; _vertices->Grab(); } void SetColors( PartialColorData* pd ) { if( _colors ) _colors->Release(); _colors = pd; _colors->Grab(); } void SetPolygons( PartialPolygonData* pd ) { if( _polygons ) _polygons->Release(); _polygons = pd; _polygons->Grab(); } VisibleElementData& VisibleElements() { return _visible_elements; } private: bool _saved; std::string _filename; PartialVertexData* _vertices; PartialColorData* _colors; PartialPolygonData* _polygons; VisibleElementData _visible_elements; }; ~MeshHistory(); static MeshHistory& Instance(); void AddMesh( bool v, bool c, bool p, bool copy = true ); void Undo(); void Redo(); void Clear(); PartialMesh& GetPreviousComposite(); PartialMesh& CurrentComposite(); Mesh& GetCurrentMesh(); int Maximum() const; void SetMaximum( unsigned ); bool UndoPossible() const; bool RedoPossible() const; bool Saved() const; typedef sigc::signal< void, const bool, const bool, const bool > UpdateSignal; sigc::signal< void, bool, bool >& Changed(); UpdateSignal& SignalEntireSectionChanged(); private: MeshHistory( unsigned ); void _print_debug_info(); bool _update_composite(); void _update_proxy(); sigc::signal< void, bool, bool > _changed; UpdateSignal signal_entire_section_changed_; int _maximum, _current_index, _current_maximum_index; std::deque< PartialMesh > _meshes; Mesh* _current_mesh; PartialMesh _current_composite; PartialMesh _previous_composite; }; } #endif // MESHHISTORY_H