Skip to content

Commit

Permalink
allow shape names to be edited (and saved to ascii stl)
Browse files Browse the repository at this point in the history
  • Loading branch information
hurzl committed Sep 1, 2012
1 parent e388dd1 commit 5f361af
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
44 changes: 35 additions & 9 deletions src/objtree.cpp
Expand Up @@ -28,12 +28,12 @@
TreeObject::~TreeObject()
{
for (uint i = 0; i<shapes.size(); i++)
delete shapes[i];
delete shapes[i];
shapes.clear();
}


bool TreeObject::deleteShape(uint i)
bool TreeObject::deleteShape(uint i)
{
delete shapes[i];
shapes.erase (shapes.begin() + i);
Expand All @@ -49,13 +49,13 @@ Gtk::TreePath TreeObject::addShape(Shape *shape, std::string location)
shape->filename = location;
if (shapes.size() > 0)
if (dimensions != shape->dimensions()) {
Gtk::MessageDialog dialog (_("Cannot add a 3-dimensional Shape to a 2-dimensional Model and vice versa"),
Gtk::MessageDialog dialog (_("Cannot add a 3-dimensional Shape to a 2-dimensional Model and vice versa"),
false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
dialog.run();
path.push_back (shapes.size() - 1);
return path;
}

dimensions = shape->dimensions();
shapes.push_back(shape);
path.push_back (shapes.size() - 1);
Expand Down Expand Up @@ -96,6 +96,7 @@ ObjectsTree::ObjectsTree()
m_cols = new ModelColumns();
m_model = Gtk::TreeStore::create (*m_cols);
update_model();
m_model->signal_row_changed().connect(sigc::mem_fun(*this, &ObjectsTree::on_row_changed));
}

ObjectsTree::~ObjectsTree()
Expand All @@ -106,8 +107,15 @@ ObjectsTree::~ObjectsTree()
delete m_cols;
}

void ObjectsTree::on_row_changed(const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter){
if (!inhibit_row_changed)
update_shapenames(m_model->children());
}

void ObjectsTree::update_model()
{
inhibit_row_changed = true;
// re-build the model each time for ease ...
m_model->clear();

Expand Down Expand Up @@ -148,6 +156,24 @@ void ObjectsTree::update_model()
row[m_cols->m_pickindex] = index++;
}
}
inhibit_row_changed = false;
}

void ObjectsTree::update_shapenames(Gtk::TreeModel::Children children)
{
Gtk::TreeModel::iterator iter = children.begin();
for (;iter; iter++) {
int nobj = (*iter)[m_cols->m_object];
int nshape = (*iter)[m_cols->m_shape];
if (nobj >= 0 && nshape >= 0) {
ustring name = (*iter)[m_cols->m_name];
if ((int)Objects.size() > nobj &&
(int)Objects[nobj]->shapes.size() > nshape)
Objects[nobj]->shapes[nshape]->filename = name;
}
else
update_shapenames((*iter).children());
}
}


Expand Down Expand Up @@ -206,13 +232,13 @@ void ObjectsTree::get_selected_shapes(const vector<Gtk::TreeModel::Path> &path,
}
if (!parent_obj_selected){
allshapes.push_back(sel_shapes[s]);
transforms.push_back(transform3D.transform
transforms.push_back(transform3D.transform
* getParent(sel_shapes[s])->transform3D.transform);
}
}
// add all shapes of selected objects
for (uint o = 0; o < sel_objects.size(); o++) {
Matrix4d otrans =
Matrix4d otrans =
transform3D.transform * sel_objects[o]->transform3D.transform;
allshapes.insert(allshapes.begin(),
sel_objects[o]->shapes.begin(), sel_objects[o]->shapes.end());
Expand All @@ -222,13 +248,13 @@ void ObjectsTree::get_selected_shapes(const vector<Gtk::TreeModel::Path> &path,
}
}

void ObjectsTree::get_all_shapes(vector<Shape*> &allshapes,
void ObjectsTree::get_all_shapes(vector<Shape*> &allshapes,
vector<Matrix4d> &transforms) const
{
allshapes.clear();
transforms.clear();
for (uint o = 0; o < Objects.size(); o++) {
Matrix4d otrans =
Matrix4d otrans =
transform3D.transform * Objects[o]->transform3D.transform;
allshapes.insert(allshapes.begin(),
Objects[o]->shapes.begin(), Objects[o]->shapes.end());
Expand All @@ -245,7 +271,7 @@ void ObjectsTree::DeleteSelected(vector<Gtk::TreeModel::Path> &path)
int num = path[p].size();
if (num == 1)
Objects.clear();
else if (num == 2)
else if (num == 2)
Objects.erase (Objects.begin() + path[p][1]);
else if (num == 3) { // have shapes
Objects[path[p][1]]->deleteShape(path[p][2]);
Expand Down
13 changes: 9 additions & 4 deletions src/objtree.h
Expand Up @@ -55,6 +55,11 @@ class TreeObject
class ObjectsTree
{
void update_model();
bool inhibit_row_changed;
void update_shapenames(Gtk::TreeModel::Children children);
void on_row_changed(const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter);

public:
class ModelColumns : public Gtk::TreeModelColumnRecord
{
Expand All @@ -74,16 +79,16 @@ class ObjectsTree
//void draw(Settings &settings, Gtk::TreeModel::iterator &iter);
void newObject();
Gtk::TreePath addShape(TreeObject *parent, Shape *shape, std::string location);
void get_selected_objects(const vector<Gtk::TreeModel::Path> &iter,
void get_selected_objects(const vector<Gtk::TreeModel::Path> &iter,
vector<TreeObject*> &object, vector<Shape*> &shape) const;

void get_selected_shapes(const vector<Gtk::TreeModel::Path> &iter,
void get_selected_shapes(const vector<Gtk::TreeModel::Path> &iter,
vector<Shape*> &shape, vector<Matrix4d> &transforms) const;

void get_all_shapes(vector<Shape*> &shapes, vector<Matrix4d> &transforms) const;

Gtk::TreeModel::iterator find_stl_by_index(guint pickindex);

Matrix4d getTransformationMatrix(int object, int shape=-1) const;

TreeObject * getParent(const Shape *shape) const;
Expand All @@ -94,6 +99,6 @@ class ObjectsTree
Glib::RefPtr<Gtk::TreeStore> m_model;
ModelColumns *m_cols;
private:
Gtk::TreeModel::iterator find_stl_in_children(Gtk::TreeModel::Children children,
Gtk::TreeModel::iterator find_stl_in_children(Gtk::TreeModel::Children children,
guint pickindex);
};
2 changes: 1 addition & 1 deletion src/shape.cpp
Expand Up @@ -59,7 +59,7 @@ void Shape::setTriangles(const vector<Triangle> &triangles_)
}


int Shape::saveBinarySTL(string filename) const
int Shape::saveBinarySTL(Glib::ustring filename) const
{

if (!File::saveBinarySTL(filename, triangles, transform3D.transform))
Expand Down
8 changes: 2 additions & 6 deletions src/shape.h
Expand Up @@ -66,7 +66,7 @@ class Shape
Shape();
/* Shape(string filename, istream &text); */
virtual ~Shape(){};
string filename;
Glib::ustring filename;
int idx;

int parseASCIISTL(istream &text, uint max_triangles=0, bool readnormals=false);
Expand Down Expand Up @@ -131,11 +131,7 @@ class Shape
int divideAtZ(double z, Shape *upper, Shape *lower, const Matrix4d &T) const;


/* int load(std::string filename, uint max_triangles=0); */
/* int loadASCIISTL(std::string filename, uint max_triangles=0, bool readnormals=false); */
/* int loadBinarySTL(std::string filename, uint max_triangles=0, bool readnormals=false); */
/* int loadASCIIVRML(std::string filename, uint max_triangles=0); */
int saveBinarySTL(std::string filename) const;
int saveBinarySTL(Glib::ustring filename) const;


bool slow_drawing;
Expand Down
2 changes: 1 addition & 1 deletion src/view.cpp
Expand Up @@ -1610,7 +1610,7 @@ void View::setModel(Model *model)
(sigc::mem_fun(*this, &View::update_settings_gui));

m_treeview->set_model (m_model->objtree.m_model);
m_treeview->append_column("Name", m_model->objtree.m_cols->m_name);
m_treeview->append_column_editable("Name", m_model->objtree.m_cols->m_name);

m_gcodetextview = NULL;
m_builder->get_widget ("txt_gcode_result", m_gcodetextview);
Expand Down

0 comments on commit 5f361af

Please sign in to comment.