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

« back to all changes in this revision

Viewing changes to xs/xsp/Model.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 "Model.hpp"
 
6
#include "PrintConfig.hpp"
 
7
%}
 
8
 
 
9
%name{Slic3r::Model} class Model {
 
10
    Model();
 
11
    ~Model();
 
12
 
 
13
    Clone<Model> clone()
 
14
        %code%{ RETVAL = THIS; %};
 
15
    
 
16
    %name{_add_object} Ref<ModelObject> add_object();
 
17
    Ref<ModelObject> _add_object_clone(ModelObject* other)
 
18
        %code%{ RETVAL = THIS->add_object(*other); %};
 
19
    void delete_object(size_t idx);
 
20
    void clear_objects();
 
21
 
 
22
    Ref<ModelMaterial> get_material(t_model_material_id material_id)
 
23
        %code%{
 
24
            RETVAL = THIS->get_material(material_id);
 
25
            if (RETVAL == NULL) {
 
26
                XSRETURN_UNDEF;
 
27
            }
 
28
        %};
 
29
 
 
30
    %name{add_material} Ref<ModelMaterial> add_material(t_model_material_id material_id);
 
31
    Ref<ModelMaterial> add_material_clone(t_model_material_id material_id, ModelMaterial* other)
 
32
        %code%{ RETVAL = THIS->add_material(material_id, *other); %};
 
33
    bool has_material(t_model_material_id material_id) const
 
34
        %code%{
 
35
            RETVAL = (THIS->get_material(material_id) != NULL);
 
36
        %};
 
37
    void delete_material(t_model_material_id material_id);
 
38
    void clear_materials();
 
39
 
 
40
    std::vector<std::string> material_names() const
 
41
        %code%{
 
42
            for (ModelMaterialMap::iterator i = THIS->materials.begin();
 
43
                i != THIS->materials.end(); ++i)
 
44
            {
 
45
                RETVAL.push_back(i->first);
 
46
            }
 
47
        %};
 
48
 
 
49
    size_t material_count() const
 
50
        %code%{ RETVAL = THIS->materials.size(); %};
 
51
 
 
52
    // void duplicate_objects_grid(coordf_t x, coordf_t y, coordf_t distance);
 
53
    // void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
 
54
    // void arrange_objects(coordf_t distance, const BoundingBox &bb);
 
55
    // void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
 
56
    bool has_objects_with_no_instances() const;
 
57
    // void bounding_box(BoundingBox* bb) const;
 
58
    // void center_instances_around_point(const Pointf &point);
 
59
    // void align_instances_to_origin();
 
60
    // void translate(coordf_t x, coordf_t y, coordf_t z);
 
61
    // void mesh(TriangleMesh* mesh) const;
 
62
    // void split_meshes();
 
63
    // std::string get_material_name(t_model_material_id material_id);
 
64
 
 
65
    ModelObjectPtrs* objects()
 
66
        %code%{ RETVAL = &THIS->objects; %};
 
67
};
 
68
 
 
69
 
 
70
%name{Slic3r::Model::Material} class ModelMaterial {
 
71
    Ref<Model> model()
 
72
        %code%{ RETVAL = THIS->get_model(); %};
 
73
 
 
74
    Ref<DynamicPrintConfig> config()
 
75
        %code%{ RETVAL = &THIS->config; %};
 
76
    
 
77
    std::string get_attribute(std::string name)
 
78
        %code%{ if (THIS->attributes.find(name) != THIS->attributes.end()) RETVAL = THIS->attributes[name]; %};
 
79
    
 
80
    void set_attribute(std::string name, std::string value)
 
81
        %code%{ THIS->attributes[name] = value; %};
 
82
 
 
83
%{
 
84
 
 
85
SV*
 
86
ModelMaterial::attributes()
 
87
    CODE:
 
88
        HV* hv = newHV();
 
89
        for (t_model_material_attributes::const_iterator attr = THIS->attributes.begin(); attr != THIS->attributes.end(); ++attr) {
 
90
            (void)hv_store( hv, attr->first.c_str(), attr->first.length(), newSVpv(attr->second.c_str(), attr->second.length()), 0 );
 
91
        }
 
92
        RETVAL = (SV*)newRV_noinc((SV*)hv);
 
93
    OUTPUT:
 
94
        RETVAL
 
95
%}
 
96
 
 
97
};
 
98
 
 
99
 
 
100
%name{Slic3r::Model::Object} class ModelObject {
 
101
    ModelVolumePtrs* volumes()
 
102
        %code%{ RETVAL = &THIS->volumes; %};
 
103
 
 
104
    ModelInstancePtrs* instances()
 
105
        %code%{ RETVAL = &THIS->instances; %};
 
106
    
 
107
    void invalidate_bounding_box();
 
108
 
 
109
    Ref<BoundingBoxf3> _bounding_box(BoundingBoxf3* new_bbox = NULL)
 
110
        %code{%
 
111
            if (NULL != new_bbox) {
 
112
                THIS->_bounding_box = *new_bbox;
 
113
                THIS->_bounding_box_valid = true;
 
114
            }
 
115
            
 
116
            if (!THIS->_bounding_box_valid) {
 
117
                XSRETURN_UNDEF;
 
118
            }
 
119
 
 
120
            RETVAL = &THIS->_bounding_box;
 
121
        %};
 
122
 
 
123
    %name{_add_volume} Ref<ModelVolume> add_volume(TriangleMesh* mesh)
 
124
        %code%{ RETVAL = THIS->add_volume(*mesh); %};
 
125
    Ref<ModelVolume> _add_volume_clone(ModelVolume* other)
 
126
        %code%{ RETVAL = THIS->add_volume(*other); %};
 
127
 
 
128
    void delete_volume(size_t idx);
 
129
    void clear_volumes();
 
130
 
 
131
    %name{_add_instance} Ref<ModelInstance> add_instance();
 
132
    Ref<ModelInstance> _add_instance_clone(ModelInstance* other)
 
133
        %code%{ RETVAL = THIS->add_instance(*other); %};
 
134
    void delete_last_instance();
 
135
    void clear_instances();
 
136
    int instances_count()
 
137
        %code%{ RETVAL = THIS->instances.size(); %};
 
138
 
 
139
    std::string input_file()
 
140
        %code%{ RETVAL = THIS->input_file; %};
 
141
    void set_input_file(std::string value)
 
142
        %code%{ THIS->input_file = value; %};
 
143
    Ref<DynamicPrintConfig> config()
 
144
        %code%{ RETVAL = &THIS->config; %};
 
145
 
 
146
    Ref<Model> model()
 
147
        %code%{ RETVAL = THIS->get_model(); %};
 
148
 
 
149
    t_layer_height_ranges layer_height_ranges()
 
150
        %code%{ RETVAL = THIS->layer_height_ranges; %};
 
151
    void set_layer_height_ranges(t_layer_height_ranges ranges)
 
152
        %code%{ THIS->layer_height_ranges = ranges; %};
 
153
 
 
154
    Ref<Pointf> origin_translation()
 
155
        %code%{ RETVAL = &THIS->origin_translation; %};
 
156
    void set_origin_translation(Pointf* point)
 
157
        %code%{ THIS->origin_translation = *point; %};
 
158
};
 
159
 
 
160
 
 
161
%name{Slic3r::Model::Volume} class ModelVolume {
 
162
    Ref<ModelObject> object()
 
163
        %code%{ RETVAL = THIS->get_object(); %};
 
164
    
 
165
    t_model_material_id material_id();
 
166
    void set_material_id(t_model_material_id material_id)
 
167
        %code%{ THIS->material_id(material_id); %};
 
168
    Ref<ModelMaterial> material();
 
169
    
 
170
    Ref<TriangleMesh> mesh()
 
171
        %code%{ RETVAL = &THIS->mesh; %};
 
172
    
 
173
    bool modifier()
 
174
        %code%{ RETVAL = THIS->modifier; %};
 
175
    void set_modifier(bool modifier)
 
176
        %code%{ THIS->modifier = modifier; %};
 
177
};
 
178
 
 
179
 
 
180
%name{Slic3r::Model::Instance} class ModelInstance {
 
181
    Ref<ModelObject> object()
 
182
        %code%{ RETVAL = THIS->get_object(); %};
 
183
 
 
184
    double rotation()
 
185
        %code%{ RETVAL = THIS->rotation; %};
 
186
    double scaling_factor()
 
187
        %code%{ RETVAL = THIS->scaling_factor; %};
 
188
    Ref<Pointf> offset()
 
189
        %code%{ RETVAL = &THIS->offset; %};
 
190
 
 
191
    void set_rotation(double val)
 
192
        %code%{ THIS->rotation = val; %};
 
193
    void set_scaling_factor(double val)
 
194
        %code%{ THIS->scaling_factor = val; %};
 
195
    void set_offset(Pointf *offset)
 
196
        %code%{ THIS->offset = *offset; %};
 
197
};