Commit f70eb5ee by Alisa Jung

added deleting selected primitive.

parent 503545c5
...@@ -233,7 +233,7 @@ void Controller::addBox(){ ...@@ -233,7 +233,7 @@ void Controller::addBox(){
} }
void Controller::addCylinder(){ void Controller::addCylinder(){
currentTransform = scene->addCylinder(tesselation); currentTransform = scene->addCylinder(tesselation);
} }
void Controller::addCone(){ void Controller::addCone(){
...@@ -243,3 +243,9 @@ void Controller::addCone(){ ...@@ -243,3 +243,9 @@ void Controller::addCone(){
void Controller::addTorus(){ void Controller::addTorus(){
currentTransform = scene->addTorus(tesselation); currentTransform = scene->addTorus(tesselation);
} }
void Controller::deletePrimitive(){
qDebug("try deleting");
if (currentTransform) currentTransform = scene->deleteNode(currentTransform);
else qDebug("nothing selected. Did not call delete on scenegraph");
}
...@@ -86,6 +86,7 @@ public slots: ...@@ -86,6 +86,7 @@ public slots:
void addCylinder(); void addCylinder();
void addCone(); void addCone();
void addTorus(); void addTorus();
void deletePrimitive();
}; };
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-21T20:37:36. --> <!-- Written by QtCreator 3.5.1, 2015-11-21T20:51:27. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<file>grapa-a2-iconset/camera.png</file> <file>grapa-a2-iconset/camera.png</file>
<file>grapa-a2-iconset/cone.png</file> <file>grapa-a2-iconset/cone.png</file>
<file>grapa-a2-iconset/cylinder.png</file> <file>grapa-a2-iconset/cylinder.png</file>
<file>grapa-a2-iconset/delete.png</file>
<file>grapa-a2-iconset/select.png</file> <file>grapa-a2-iconset/select.png</file>
<file>grapa-a2-iconset/sphere.png</file> <file>grapa-a2-iconset/sphere.png</file>
<file>grapa-a2-iconset/torus.png</file> <file>grapa-a2-iconset/torus.png</file>
......
...@@ -210,18 +210,21 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -210,18 +210,21 @@ MainWindow::MainWindow(QWidget *parent)
addCylinder = new QAction("Add Cylinder", toolBar); addCylinder = new QAction("Add Cylinder", toolBar);
addCone = new QAction("Add Cone", toolBar); addCone = new QAction("Add Cone", toolBar);
addTorus = new QAction("Add Torus", toolBar); addTorus = new QAction("Add Torus", toolBar);
deletePrimitive = new QAction("Delete", toolBar);
addSphere->setIcon(QIcon(":/grapa-a2-iconset/sphere.png")); addSphere->setIcon(QIcon(":/grapa-a2-iconset/sphere.png"));
addBox->setIcon(QIcon(":/grapa-a2-iconset/box.png")); addBox->setIcon(QIcon(":/grapa-a2-iconset/box.png"));
addCylinder->setIcon(QIcon(":/grapa-a2-iconset/cylinder.png")); addCylinder->setIcon(QIcon(":/grapa-a2-iconset/cylinder.png"));
addCone->setIcon(QIcon(":/grapa-a2-iconset/cone.png")); addCone->setIcon(QIcon(":/grapa-a2-iconset/cone.png"));
addTorus->setIcon(QIcon(":/grapa-a2-iconset/torus.png")); addTorus->setIcon(QIcon(":/grapa-a2-iconset/torus.png"));
deletePrimitive->setIcon(QIcon(":/grapa-a2-iconset/delete.png"));
addSphere->setCheckable(false); addSphere->setCheckable(false);
addBox->setCheckable(false); addBox->setCheckable(false);
addCylinder->setCheckable(false); addCylinder->setCheckable(false);
addCone->setCheckable(false); addCone->setCheckable(false);
addTorus->setCheckable(false); addTorus->setCheckable(false);
deletePrimitive->setCheckable(false);
toolBar->addAction(addSphere); toolBar->addAction(addSphere);
toolBar->insertSeparator(addSphere); toolBar->insertSeparator(addSphere);
...@@ -229,12 +232,14 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -229,12 +232,14 @@ MainWindow::MainWindow(QWidget *parent)
toolBar->addAction(addCylinder); toolBar->addAction(addCylinder);
toolBar->addAction(addCone); toolBar->addAction(addCone);
toolBar->addAction(addTorus); toolBar->addAction(addTorus);
toolBar->addAction(deletePrimitive);
connect(addSphere, SIGNAL(triggered(bool)),controller, SLOT(addSphere())); connect(addSphere, SIGNAL(triggered(bool)),controller, SLOT(addSphere()));
connect(addBox, SIGNAL(triggered(bool)),controller, SLOT(addBox())); connect(addBox, SIGNAL(triggered(bool)),controller, SLOT(addBox()));
connect(addCylinder, SIGNAL(triggered(bool)),controller, SLOT(addCylinder())); connect(addCylinder, SIGNAL(triggered(bool)),controller, SLOT(addCylinder()));
connect(addCone, SIGNAL(triggered(bool)),controller, SLOT(addCone())); connect(addCone, SIGNAL(triggered(bool)),controller, SLOT(addCone()));
connect(addTorus, SIGNAL(triggered(bool)),controller, SLOT(addTorus())); connect(addTorus, SIGNAL(triggered(bool)),controller, SLOT(addTorus()));
connect(deletePrimitive, SIGNAL(triggered(bool)),controller, SLOT(deletePrimitive()));
} }
......
...@@ -85,6 +85,8 @@ private: ...@@ -85,6 +85,8 @@ private:
QAction* addCone; QAction* addCone;
QAction* addTorus; QAction* addTorus;
QAction* deletePrimitive;
public slots : public slots :
void showAboutBox ( ) ; void showAboutBox ( ) ;
}; };
......
...@@ -8,6 +8,10 @@ RigidBodyTransformation::RigidBodyTransformation(Primitive* child) ...@@ -8,6 +8,10 @@ RigidBodyTransformation::RigidBodyTransformation(Primitive* child)
// qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation; // qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation;
} }
RigidBodyTransformation::~RigidBodyTransformation(){
child->~Primitive();
}
void RigidBodyTransformation::addTranslation(QVector3D diff){ void RigidBodyTransformation::addTranslation(QVector3D diff){
translation += diff; translation += diff;
......
...@@ -8,6 +8,7 @@ class RigidBodyTransformation ...@@ -8,6 +8,7 @@ class RigidBodyTransformation
{ {
public: public:
RigidBodyTransformation(Primitive* child); RigidBodyTransformation(Primitive* child);
~RigidBodyTransformation();
void addTranslation(QVector3D diff); void addTranslation(QVector3D diff);
void setRotation(QQuaternion newRotation); void setRotation(QQuaternion newRotation);
......
...@@ -78,6 +78,19 @@ RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){ ...@@ -78,6 +78,19 @@ RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){
return r; return r;
} }
RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){
if (r == 0){
qDebug("transform already 0");
return 0;
}
bool s = nodes.removeOne(r);
if (!s) qDebug("could not remove this. Delete r anyways.");
r->~RigidBodyTransformation();
notifyViews();
if (nodes.length() > 0) return nodes.back();
else return 0;
}
//transform something //transform something
void SceneGraph::addRotation(RigidBodyTransformation *r, QQuaternion diff){ void SceneGraph::addRotation(RigidBodyTransformation *r, QQuaternion diff){
r->addRotation(diff); r->addRotation(diff);
......
...@@ -26,6 +26,9 @@ public: ...@@ -26,6 +26,9 @@ public:
const QList<RigidBodyTransformation*> getGraph(); const QList<RigidBodyTransformation*> getGraph();
//automatically selects last added primitive. if none left, selects 0.
RigidBodyTransformation* deleteNode(RigidBodyTransformation* r);
//Hallo. Todos: //Hallo. Todos:
//Log selected name in status bar //Log selected name in status bar
//add remaining primitive types //add remaining primitive types
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment