Subversion Repositories gelsvn

Rev

Rev 647 | Rev 650 | 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
 
30
        GLViewController& active_view_control();
31
        VisObj& active_visobj();
32
 
33
 
34
    public:
35
        MeshEditor():active(0), display_render_mode("normal"), display_smooth_shading(true),
36
        display_gamma(2.2) {}
37
 
38
        /// Initialize the mesh editor. Do this only when OpenGL state is available.
39
        void init();
40
 
41
        // GLViewController stuff
42
        void reshape(int w, int h);
43
        void grab_ball(TrackBallAction action, const CGLA::Vec2i& pos);
44
        void roll_ball(const CGLA::Vec2i& pos);
45
        void release_ball();
46
        bool try_spinning_ball();
47
 
48
        /// Align means that we sync view controllers.
49
        void align(int src, int dst)
50
        {
51
            vo[dst].view_control() =
52
            vo[src].view_control();
53
        }
54
 
55
        /// Make sure the object fits in the window.
56
        void refit() {
57
            active_visobj().refit();
58
        }
59
 
60
        // Get mesh and mesh state.
61
        HMesh::Manifold& active_mesh();
62
        void save_active_mesh() {active_visobj().save_old();}
63
        void restore_active_mesh() {active_visobj().restore_old();}
64
 
65
        // Display functions ------------
66
 
67
        /// Notify the visualization object that we need to regenerate the display list.
68
        void post_create_display_list() {active_visobj().post_create_display_list();}
69
 
70
        /// Render the active mesh.
71
        void display(int scale = 1);
72
 
73
 
74
        // Console functions --------------
75
 
76
        void register_console_function(const std::string& name,
77
                                       const std::function<void(MeshEditor*, const std::vector<std::string>&)>& con_fun,
78
                                       const std::string& help_txt);
79
 
80
        void printf(const char* format, ...);
81
        void keyparse(unsigned short c);
82
        void key_up();
83
        void key_down();
84
        void key_left();
85
        void key_right();
86
        void key_home();
87
        void key_end();
88
 
89
 
90
        /// Add a file to the next empty slot.
91
        bool add_file(const std::string& str);
92
 
93
        /// Load the mesh given as argument to the current slot.
94
        bool reload_active_from_file(const std::string& str);
95
 
96
        /// Load the mesh but without clearing, effectively combining it with existing mesh.
97
        bool add_to_active_from_file(const std::string& str);
98
 
99
        void harmonics_analyze_mesh() {active_visobj().harmonics_analyze();}
100
 
101
    };
102
}
103
 
104
#endif /* defined(__GEL__MeshEditor__) */