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

« back to all changes in this revision

Viewing changes to xs/src/Model.hpp

  • 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
#ifndef slic3r_Model_hpp_
 
2
#define slic3r_Model_hpp_
 
3
 
 
4
#include <myinit.h>
 
5
#include "PrintConfig.hpp"
 
6
#include "Layer.hpp"
 
7
#include "Point.hpp"
 
8
#include "TriangleMesh.hpp"
 
9
#include <map>
 
10
#include <string>
 
11
#include <utility>
 
12
#include <vector>
 
13
 
 
14
namespace Slic3r {
 
15
 
 
16
class ModelInstance;
 
17
class ModelMaterial;
 
18
class ModelObject;
 
19
class ModelVolume;
 
20
 
 
21
typedef std::string t_model_material_id;
 
22
typedef std::string t_model_material_attribute;
 
23
typedef std::map<t_model_material_attribute,std::string> t_model_material_attributes;
 
24
 
 
25
typedef std::map<t_model_material_id,ModelMaterial*> ModelMaterialMap;
 
26
typedef std::vector<ModelObject*> ModelObjectPtrs;
 
27
typedef std::vector<ModelVolume*> ModelVolumePtrs;
 
28
typedef std::vector<ModelInstance*> ModelInstancePtrs;
 
29
 
 
30
class Model
 
31
{
 
32
    public:
 
33
    ModelMaterialMap materials;
 
34
    ModelObjectPtrs objects;
 
35
    
 
36
    Model();
 
37
    Model(const Model &other);
 
38
    Model& operator= (Model other);
 
39
    void swap(Model &other);
 
40
    ~Model();
 
41
    ModelObject* add_object();
 
42
    ModelObject* add_object(const ModelObject &other);
 
43
    void delete_object(size_t idx);
 
44
    void clear_objects();
 
45
    
 
46
    ModelMaterial* add_material(t_model_material_id material_id);
 
47
    ModelMaterial* add_material(t_model_material_id material_id, const ModelMaterial &other);
 
48
    ModelMaterial* get_material(t_model_material_id material_id);
 
49
    void delete_material(t_model_material_id material_id);
 
50
    void clear_materials();
 
51
    // void duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance);
 
52
    // void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
 
53
    // void arrange_objects(coordf_t distance, const BoundingBox &bb);
 
54
    // void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb);
 
55
    bool has_objects_with_no_instances() const;
 
56
    // void bounding_box(BoundingBox* bb) const;
 
57
    // void align_to_origin();
 
58
    // void center_instances_around_point(const Pointf &point);
 
59
    // void translate(coordf_t x, coordf_t y, coordf_t z);
 
60
    // void mesh(TriangleMesh* mesh) const;
 
61
    // void split_meshes();
 
62
    // std::string get_material_name(t_model_material_id material_id);
 
63
 
 
64
    
 
65
    private:
 
66
    void _arrange(const std::vector<Size> &sizes, coordf_t distance, const BoundingBox &bb) const;
 
67
};
 
68
 
 
69
class ModelMaterial
 
70
{
 
71
    friend class Model;
 
72
    public:
 
73
    t_model_material_attributes attributes;
 
74
    DynamicPrintConfig config;
 
75
 
 
76
    Model* get_model() const { return this->model; };
 
77
    void apply(const t_model_material_attributes &attributes);
 
78
    
 
79
    private:
 
80
    Model* model;
 
81
    
 
82
    ModelMaterial(Model *model);
 
83
    ModelMaterial(Model *model, const ModelMaterial &other);
 
84
};
 
85
 
 
86
class ModelObject
 
87
{
 
88
    friend class Model;
 
89
    public:
 
90
    std::string input_file;
 
91
    ModelInstancePtrs instances;
 
92
    ModelVolumePtrs volumes;
 
93
    DynamicPrintConfig config;
 
94
    t_layer_height_ranges layer_height_ranges;
 
95
    Pointf origin_translation;
 
96
    
 
97
    // these should be private but we need to expose them via XS until all methods are ported
 
98
    BoundingBoxf3 _bounding_box;
 
99
    bool _bounding_box_valid;
 
100
    
 
101
    Model* get_model() const { return this->model; };
 
102
    
 
103
    ModelVolume* add_volume(const TriangleMesh &mesh);
 
104
    ModelVolume* add_volume(const ModelVolume &volume);
 
105
    void delete_volume(size_t idx);
 
106
    void clear_volumes();
 
107
 
 
108
    ModelInstance* add_instance();
 
109
    ModelInstance* add_instance(const ModelInstance &instance);
 
110
    void delete_instance(size_t idx);
 
111
    void delete_last_instance();
 
112
    void clear_instances();
 
113
 
 
114
    void invalidate_bounding_box();
 
115
 
 
116
    //void raw_mesh(TriangleMesh* mesh) const;
 
117
    //void mesh(TriangleMesh* mesh) const;
 
118
    //void instance_bounding_box(size_t instance_idx, BoundingBox* bb) const;
 
119
    //void center_around_origin();
 
120
    //void translate(coordf_t x, coordf_t y, coordf_t z);
 
121
    //size_t materials_count() const;
 
122
    //void unique_materials(std::vector<t_model_material_id>* materials) const;
 
123
    //size_t facets_count() const;
 
124
    //bool needed_repair() const;
 
125
    
 
126
    private:
 
127
    Model* model;
 
128
    
 
129
    ModelObject(Model *model);
 
130
    ModelObject(Model *model, const ModelObject &other);
 
131
    ModelObject& operator= (ModelObject other);
 
132
    void swap(ModelObject &other);
 
133
    ~ModelObject();
 
134
    void update_bounding_box();
 
135
};
 
136
 
 
137
class ModelVolume
 
138
{
 
139
    friend class ModelObject;
 
140
    public:
 
141
    TriangleMesh mesh;
 
142
    bool modifier;
 
143
    
 
144
    ModelObject* get_object() const { return this->object; };
 
145
    t_model_material_id material_id() const;
 
146
    void material_id(t_model_material_id material_id);
 
147
    ModelMaterial* material() const;
 
148
    
 
149
    private:
 
150
    ModelObject* object;
 
151
    t_model_material_id _material_id;
 
152
    
 
153
    ModelVolume(ModelObject *object, const TriangleMesh &mesh);
 
154
    ModelVolume(ModelObject *object, const ModelVolume &other);
 
155
};
 
156
 
 
157
class ModelInstance
 
158
{
 
159
    friend class ModelObject;
 
160
    public:
 
161
    double rotation;            // around mesh center point
 
162
    double scaling_factor;
 
163
    Pointf offset;              // in unscaled coordinates
 
164
    
 
165
    ModelObject* get_object() const { return this->object; };
 
166
    void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
 
167
    void transform_polygon(Polygon* polygon) const;
 
168
    
 
169
    private:
 
170
    ModelObject* object;
 
171
    
 
172
    ModelInstance(ModelObject *object);
 
173
    ModelInstance(ModelObject *object, const ModelInstance &other);
 
174
};
 
175
 
 
176
}
 
177
 
 
178
#endif