~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/xsp/Config.xsp

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%module{Slic3r::XS};
 
2
 
 
3
%{
 
4
#include <myinit.h>
 
5
#include "PrintConfig.hpp"
 
6
%}
 
7
 
 
8
%name{Slic3r::Config} class DynamicPrintConfig {
 
9
    DynamicPrintConfig();
 
10
    ~DynamicPrintConfig();
 
11
    bool has(t_config_option_key opt_key);
 
12
    SV* as_hash();
 
13
    SV* get(t_config_option_key opt_key);
 
14
    SV* get_at(t_config_option_key opt_key, int i);
 
15
    bool set(t_config_option_key opt_key, SV* value);
 
16
    bool set_deserialize(t_config_option_key opt_key, SV* str);
 
17
    std::string serialize(t_config_option_key opt_key);
 
18
    double get_abs_value(t_config_option_key opt_key);
 
19
    %name{get_abs_value_over}
 
20
        double get_abs_value(t_config_option_key opt_key, double ratio_over);
 
21
    void apply(DynamicPrintConfig* other)
 
22
        %code{% THIS->apply(*other, true); %};
 
23
    void apply_static(FullPrintConfig* other)
 
24
        %code{% THIS->apply(*other, true); %};
 
25
    std::vector<std::string> get_keys()
 
26
        %code{% THIS->keys(&RETVAL); %};
 
27
    void erase(t_config_option_key opt_key);
 
28
    void normalize();
 
29
};
 
30
 
 
31
%name{Slic3r::Config::Print} class PrintConfig {
 
32
    PrintConfig();
 
33
    ~PrintConfig();
 
34
    bool has(t_config_option_key opt_key);
 
35
    SV* as_hash();
 
36
    SV* get(t_config_option_key opt_key);
 
37
    SV* get_at(t_config_option_key opt_key, int i);
 
38
    bool set(t_config_option_key opt_key, SV* value);
 
39
    bool set_deserialize(t_config_option_key opt_key, SV* str);
 
40
    std::string serialize(t_config_option_key opt_key);
 
41
    double get_abs_value(t_config_option_key opt_key);
 
42
    %name{get_abs_value_over}
 
43
        double get_abs_value(t_config_option_key opt_key, double ratio_over);
 
44
    void apply_dynamic(DynamicPrintConfig* other)
 
45
        %code{% THIS->apply(*other, true); %};
 
46
    std::vector<std::string> get_keys()
 
47
        %code{% THIS->keys(&RETVAL); %};
 
48
};
 
49
 
 
50
%name{Slic3r::Config::PrintRegion} class PrintRegionConfig {
 
51
    PrintRegionConfig();
 
52
    ~PrintRegionConfig();
 
53
    bool has(t_config_option_key opt_key);
 
54
    SV* as_hash();
 
55
    SV* get(t_config_option_key opt_key);
 
56
    SV* get_at(t_config_option_key opt_key, int i);
 
57
    bool set(t_config_option_key opt_key, SV* value);
 
58
    bool set_deserialize(t_config_option_key opt_key, SV* str);
 
59
    std::string serialize(t_config_option_key opt_key);
 
60
    double get_abs_value(t_config_option_key opt_key);
 
61
    %name{get_abs_value_over}
 
62
        double get_abs_value(t_config_option_key opt_key, double ratio_over);
 
63
    void apply(PrintRegionConfig* other)
 
64
        %code{% THIS->apply(*other, true); %};
 
65
    void apply_dynamic(DynamicPrintConfig* other)
 
66
        %code{% THIS->apply(*other, true); %};
 
67
    std::vector<std::string> get_keys()
 
68
        %code{% THIS->keys(&RETVAL); %};
 
69
};
 
70
 
 
71
%name{Slic3r::Config::PrintObject} class PrintObjectConfig {
 
72
    PrintObjectConfig();
 
73
    ~PrintObjectConfig();
 
74
    bool has(t_config_option_key opt_key);
 
75
    SV* as_hash();
 
76
    SV* get(t_config_option_key opt_key);
 
77
    SV* get_at(t_config_option_key opt_key, int i);
 
78
    bool set(t_config_option_key opt_key, SV* value);
 
79
    bool set_deserialize(t_config_option_key opt_key, SV* str);
 
80
    std::string serialize(t_config_option_key opt_key);
 
81
    double get_abs_value(t_config_option_key opt_key);
 
82
    %name{get_abs_value_over}
 
83
        double get_abs_value(t_config_option_key opt_key, double ratio_over);
 
84
    void apply(PrintObjectConfig* other)
 
85
        %code{% THIS->apply(*other, true); %};
 
86
    void apply_dynamic(DynamicPrintConfig* other)
 
87
        %code{% THIS->apply(*other, true); %};
 
88
    std::vector<std::string> get_keys()
 
89
        %code{% THIS->keys(&RETVAL); %};
 
90
};
 
91
 
 
92
%name{Slic3r::Config::Full} class FullPrintConfig {
 
93
    FullPrintConfig();
 
94
    ~FullPrintConfig();
 
95
    bool has(t_config_option_key opt_key);
 
96
    SV* as_hash();
 
97
    SV* get(t_config_option_key opt_key);
 
98
    SV* get_at(t_config_option_key opt_key, int i);
 
99
    bool set(t_config_option_key opt_key, SV* value);
 
100
    bool set_deserialize(t_config_option_key opt_key, SV* str);
 
101
    std::string serialize(t_config_option_key opt_key);
 
102
    double get_abs_value(t_config_option_key opt_key);
 
103
    %name{get_abs_value_over}
 
104
        double get_abs_value(t_config_option_key opt_key, double ratio_over);
 
105
    void apply_print_config(PrintConfig* other)
 
106
        %code{% THIS->apply(*other, true); %};
 
107
    void apply_object_config(PrintObjectConfig* other)
 
108
        %code{% THIS->apply(*other, true); %};
 
109
    void apply_region_config(PrintRegionConfig* other)
 
110
        %code{% THIS->apply(*other, true); %};
 
111
    void apply_dynamic(DynamicPrintConfig* other)
 
112
        %code{% THIS->apply(*other, true); %};
 
113
    std::vector<std::string> get_keys()
 
114
        %code{% THIS->keys(&RETVAL); %};
 
115
    std::string get_extrusion_axis();
 
116
};
 
117
 
 
118
%package{Slic3r::Config};
 
119
 
 
120
%{
 
121
PROTOTYPES: DISABLE
 
122
 
 
123
SV*
 
124
print_config_def()
 
125
    CODE:
 
126
        FullPrintConfig config;
 
127
        t_optiondef_map* def = config.def;
 
128
        
 
129
        HV* options_hv = newHV();
 
130
        for (t_optiondef_map::iterator oit = def->begin(); oit != def->end(); ++oit) {
 
131
            HV* hv = newHV();
 
132
            
 
133
            t_config_option_key opt_key = oit->first;
 
134
            ConfigOptionDef* optdef     = &oit->second;
 
135
            
 
136
            const char* opt_type;
 
137
            if (optdef->type == coFloat || optdef->type == coFloats || optdef->type == coFloatOrPercent) {
 
138
                opt_type = "f";
 
139
            } else if (optdef->type == coPercent) {
 
140
                opt_type = "percent";
 
141
            } else if (optdef->type == coInt || optdef->type == coInts) {
 
142
                opt_type = "i";
 
143
            } else if (optdef->type == coString) {
 
144
                opt_type = "s";
 
145
            } else if (optdef->type == coStrings) {
 
146
                opt_type = "s@";
 
147
            } else if (optdef->type == coPoint || optdef->type == coPoints) {
 
148
                opt_type = "point";
 
149
            } else if (optdef->type == coBool || optdef->type == coBools) {
 
150
                opt_type = "bool";
 
151
            } else if (optdef->type == coEnum) {
 
152
                opt_type = "select";
 
153
            } else {
 
154
                throw "Unknown option type";
 
155
            }
 
156
            (void)hv_stores( hv, "type",        newSVpv(opt_type, 0) );
 
157
            (void)hv_stores( hv, "label",       newSVpvn_utf8(optdef->label.c_str(), optdef->label.length(), true) );
 
158
            if (!optdef->full_label.empty())
 
159
                (void)hv_stores( hv, "full_label",  newSVpvn_utf8(optdef->full_label.c_str(), optdef->full_label.length(), true) );
 
160
            (void)hv_stores( hv, "category",    newSVpvn(optdef->category.c_str(), optdef->category.length()) );
 
161
            (void)hv_stores( hv, "tooltip",     newSVpvn_utf8(optdef->tooltip.c_str(), optdef->tooltip.length(), true) );
 
162
            (void)hv_stores( hv, "sidetext",    newSVpvn_utf8(optdef->sidetext.c_str(), optdef->sidetext.length(), true) );
 
163
            (void)hv_stores( hv, "cli",         newSVpvn(optdef->cli.c_str(), optdef->cli.length()) );
 
164
            (void)hv_stores( hv, "ratio_over",  newSVpvn(optdef->ratio_over.c_str(), optdef->ratio_over.length()) );
 
165
            (void)hv_stores( hv, "multiline",   newSViv(optdef->multiline ? 1 : 0) );
 
166
            (void)hv_stores( hv, "full_width",  newSViv(optdef->full_width ? 1 : 0) );
 
167
            (void)hv_stores( hv, "readonly",    newSViv(optdef->readonly ? 1 : 0) );
 
168
            (void)hv_stores( hv, "height",      newSViv(optdef->height) );
 
169
            (void)hv_stores( hv, "width",       newSViv(optdef->width) );
 
170
            (void)hv_stores( hv, "min",         newSViv(optdef->min) );
 
171
            (void)hv_stores( hv, "max",         newSViv(optdef->max) );
 
172
            
 
173
            // aliases
 
174
            if (!optdef->aliases.empty()) {
 
175
                AV* av = newAV();
 
176
                av_fill(av, optdef->aliases.size()-1);
 
177
                for (std::vector<t_config_option_key>::iterator it = optdef->aliases.begin(); it != optdef->aliases.end(); ++it)
 
178
                    av_store(av, it - optdef->aliases.begin(), newSVpvn(it->c_str(), it->length()));
 
179
                (void)hv_stores( hv, "aliases", newRV_noinc((SV*)av) );
 
180
            }
 
181
            
 
182
            // shortcut
 
183
            if (!optdef->shortcut.empty()) {
 
184
                AV* av = newAV();
 
185
                av_fill(av, optdef->shortcut.size()-1);
 
186
                for (std::vector<t_config_option_key>::iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it)
 
187
                    av_store(av, it - optdef->shortcut.begin(), newSVpvn(it->c_str(), it->length()));
 
188
                (void)hv_stores( hv, "shortcut", newRV_noinc((SV*)av) );
 
189
            }
 
190
            
 
191
            // enum_values
 
192
            if (!optdef->enum_values.empty()) {
 
193
                AV* av = newAV();
 
194
                av_fill(av, optdef->enum_values.size()-1);
 
195
                for (std::vector<std::string>::iterator it = optdef->enum_values.begin(); it != optdef->enum_values.end(); ++it)
 
196
                    av_store(av, it - optdef->enum_values.begin(), newSVpvn(it->c_str(), it->length()));
 
197
                (void)hv_stores( hv, "values", newRV_noinc((SV*)av) );
 
198
            }
 
199
            
 
200
            // enum_labels
 
201
            if (!optdef->enum_labels.empty()) {
 
202
                AV* av = newAV();
 
203
                av_fill(av, optdef->enum_labels.size()-1);
 
204
                for (std::vector<std::string>::iterator it = optdef->enum_labels.begin(); it != optdef->enum_labels.end(); ++it)
 
205
                    av_store(av, it - optdef->enum_labels.begin(), newSVpvn_utf8(it->c_str(), it->length(), true));
 
206
                (void)hv_stores( hv, "labels", newRV_noinc((SV*)av) );
 
207
            }
 
208
            
 
209
            (void)hv_stores( hv, "default", config.get(opt_key) );
 
210
            (void)hv_store( options_hv, opt_key.c_str(), opt_key.length(), newRV_noinc((SV*)hv), 0 );
 
211
        }
 
212
        
 
213
        RETVAL = newRV_noinc((SV*)options_hv);
 
214
    OUTPUT:
 
215
        RETVAL
 
216
%}