1 /*
2     This file is a part of the RepSnapper project.
3     Copyright (C) 2010  Kulitorum
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #pragma once
20 
21 #include "shape.h"
22 
23 
24 /* class RFO_File */
25 /* { */
26 /* public: */
27 /* 	RFO_File(){} */
28 /* 	void Draw(); */
29 /* 	RFO_Transform3D transform3D; */
30 /* 	string location; */
31 /* 	string filetype; */
32 /* 	string material; */
33 /* 	Shape stl; */
34 /* 	Shape getSTL() const {return stl;}; */
35 /* 	int idx; */
36 /* }; */
37 
38 class TreeObject
39 {
40 public:
TreeObject()41   TreeObject(){name = _("Unnamed object");};
42   ~TreeObject();
43 	string name;
44 	Transform3D transform3D;
45 	vector<Shape*> shapes;
46 	bool deleteShape(uint i);
47   short dimensions;
size()48 	uint size(){return shapes.size();};
49 	int idx;
50   Gtk::TreePath addShape(Shape *shape, std::string location);
move(const Vector3d & delta)51   void move(const Vector3d &delta){ transform3D.move(delta); };
52   Vector3d center() const;
53 };
54 
55 
56 class ObjectsTree
57 {
58 	void update_model();
59 	bool inhibit_row_changed;
60 	void update_shapenames(Gtk::TreeModel::Children children);
61 	void on_row_changed(const Gtk::TreeModel::Path& path,
62 			    const Gtk::TreeModel::iterator& iter);
63 
64 public:
65 	class ModelColumns : public Gtk::TreeModelColumnRecord
66 	{
67 	public:
ModelColumns()68 	  ModelColumns() {
69 	    add (m_name); add (m_object);
70 	    add (m_shape); add(m_pickindex);
71 	    add (m_material);
72 	    //add (m_extruder);
73 	  }
74 	  Gtk::TreeModelColumn<Glib::ustring> m_name;
75 	  Gtk::TreeModelColumn<int>           m_object;
76 	  Gtk::TreeModelColumn<int>           m_shape;
77 	  Gtk::TreeModelColumn<int>           m_pickindex;
78 	  Gtk::TreeModelColumn<int>           m_material;
79 	  //Gtk::TreeModelColumn<Gtk::ComboBox*> m_extruder;
80 	};
81 
82 	ObjectsTree();
83 	~ObjectsTree();
84 
85 	void clear();
empty()86 	bool empty() const {return Objects.size()==0; }
87 
88 	void DeleteSelected(vector<Gtk::TreeModel::Path> &iter);
89 	//void draw(Settings &settings, Gtk::TreeModel::iterator &iter);
90 	void newObject();
91 	Gtk::TreePath addShape(TreeObject *parent, Shape *shape, std::string location);
92 	void get_selected_objects(const vector<Gtk::TreeModel::Path> &iter,
93 				  vector<TreeObject*> &object, vector<Shape*> &shape) const;
94 
95 	void get_selected_shapes(const vector<Gtk::TreeModel::Path> &iter,
96 				 vector<Shape*> &shape, vector<Matrix4d> &transforms) const;
97 
98 	void get_all_shapes(vector<Shape*> &shapes, vector<Matrix4d> &transforms) const;
99 
100         Gtk::TreeModel::iterator find_stl_by_index(guint pickindex);
101 
102 	Matrix4d getTransformationMatrix(int object, int shape=-1) const;
103 
104 	TreeObject * getParent(const Shape *shape) const;
105 	vector<TreeObject*> Objects;
106 	Transform3D transform3D;
107 	float version;
108 	string m_filename;
109 	Glib::RefPtr<Gtk::TreeStore> m_model;
110 	ModelColumns   *m_cols;
111 private:
112         Gtk::TreeModel::iterator find_stl_in_children(Gtk::TreeModel::Children children,
113 						      guint pickindex);
114 };
115