Subversion Repositories gelsvn

Rev

Rev 649 | Rev 656 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
647 janba 1
//
2
//  MeshEditor.h
3
//  GEL
4
//
5
//  Created by J. Andreas Bærentzen on 09/10/13.
6
//
7
//
8
 
9
#ifndef __GEL__MeshEditor__
10
#define __GEL__MeshEditor__
11
 
12
#include <string>
649 janba 13
#include "../GLGraphics/Console.h"
14
#include "../GLGraphics/VisObj.h"
15
#include "../GLGraphics/GLViewController.h"
647 janba 16
 
17
namespace GLGraphics {
18
 
19
    class MeshEditor
20
    {
21
        Console theConsole;
22
        bool console_visible = false;
23
        static const int NO_MESHES = 9;
24
        std::array<VisObj,NO_MESHES> vo;
25
        Console::variable<int> active;
26
        Console::variable<std::string> display_render_mode;
27
        Console::variable<int> display_smooth_shading;
28
        Console::variable<float> display_gamma;
29
 
650 janba 30
        VisObj& active_visobj() { return vo[active]; }
31
        const VisObj& active_visobj() const { return vo[active]; }
32
 
33
        GLViewController& active_view_control() {
34
            return active_visobj().view_control();
35
        }
647 janba 36
 
37
 
38
    public:
39
        MeshEditor():active(0), display_render_mode("normal"), display_smooth_shading(true),
40
        display_gamma(2.2) {}
41
 
42
        /// Initialize the mesh editor. Do this only when OpenGL state is available.
43
        void init();
44
 
45
        // GLViewController stuff
46
        void reshape(int w, int h);
47
        void grab_ball(TrackBallAction action, const CGLA::Vec2i& pos);
48
        void roll_ball(const CGLA::Vec2i& pos);
49
        void release_ball();
50
        bool try_spinning_ball();
51
 
52
        /// Align means that we sync view controllers.
53
        void align(int src, int dst)
54
        {
55
            vo[dst].view_control() =
56
            vo[src].view_control();
57
        }
58
 
59
        /// Make sure the object fits in the window.
60
        void refit() {
61
            active_visobj().refit();
62
        }
650 janba 63
 
64
        /// Returns the name of the file whence the active mesh was loaded.
65
        const std::string& file_name() const {return active_visobj().file_name();}
647 janba 66
 
67
        // Get mesh and mesh state.
68
        void save_active_mesh() {active_visobj().save_old();}
69
        void restore_active_mesh() {active_visobj().restore_old();}
70
 
71
        // Display functions ------------
72
 
73
        /// Notify the visualization object that we need to regenerate the display list.
74
        void post_create_display_list() {active_visobj().post_create_display_list();}
75
 
76
        /// Render the active mesh.
77
        void display(int scale = 1);
78
 
79
 
80
        // Console functions --------------
81
 
82
        void register_console_function(const std::string& name,
83
                                       const std::function<void(MeshEditor*, const std::vector<std::string>&)>& con_fun,
84
                                       const std::string& help_txt);
85
 
86
        void printf(const char* format, ...);
87
        void keyparse(unsigned short c);
88
        void key_up();
89
        void key_down();
90
        void key_left();
91
        void key_right();
92
        void key_home();
93
        void key_end();
650 janba 94
 
95
        /// Returns a reference to active mesh.
96
        HMesh::Manifold& active_mesh() { return active_visobj().mesh(); }
647 janba 97
 
650 janba 98
       /// Add a file to the next empty slot.
647 janba 99
        bool add_file(const std::string& str);
100
 
101
        /// Load the mesh given as argument to the current slot.
102
        bool reload_active_from_file(const std::string& str);
103
 
104
        /// Load the mesh but without clearing, effectively combining it with existing mesh.
105
        bool add_to_active_from_file(const std::string& str);
106
 
107
        void harmonics_analyze_mesh() {active_visobj().harmonics_analyze();}
108
 
109
    };
110
}
111
 
112
#endif /* defined(__GEL__MeshEditor__) */