diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.h b/hw04/mainwindow.h index b3aab25..ba0c87d 100644 --- a/hw04/mainwindow.h +++ b/hw04/mainwindow.h @@ -18,6 +18,9 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void loadButtonClick(); + private: Ui::MainWindow *ui; }; diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.h b/hw04/mainwindow.h index b3aab25..ba0c87d 100644 --- a/hw04/mainwindow.h +++ b/hw04/mainwindow.h @@ -18,6 +18,9 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void loadButtonClick(); + private: Ui::MainWindow *ui; }; diff --git a/hw04/mainwindow.ui b/hw04/mainwindow.ui index 9f9248a..d3b8369 100644 --- a/hw04/mainwindow.ui +++ b/hw04/mainwindow.ui @@ -126,6 +126,31 @@ + + + + Qt::Horizontal + + + + + + + + + C:\CLionProjects\cg\hw04\mesh1.obj + + + + + + + Load + + + + + diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.h b/hw04/mainwindow.h index b3aab25..ba0c87d 100644 --- a/hw04/mainwindow.h +++ b/hw04/mainwindow.h @@ -18,6 +18,9 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void loadButtonClick(); + private: Ui::MainWindow *ui; }; diff --git a/hw04/mainwindow.ui b/hw04/mainwindow.ui index 9f9248a..d3b8369 100644 --- a/hw04/mainwindow.ui +++ b/hw04/mainwindow.ui @@ -126,6 +126,31 @@ + + + + Qt::Horizontal + + + + + + + + + C:\CLionProjects\cg\hw04\mesh1.obj + + + + + + + Load + + + + + diff --git a/hw04/oglwidget.cpp b/hw04/oglwidget.cpp index 3c2f9bb..df2af28 100644 --- a/hw04/oglwidget.cpp +++ b/hw04/oglwidget.cpp @@ -15,6 +15,7 @@ Mesh *parentMesh; Mesh *childMesh; +bool init = false; bool childWireframe = false; bool drawParent = false; int parentSubdivCount = 0; @@ -61,6 +62,7 @@ } void DrawTriag() { + if (!init) return; drawMesh(*childMesh); if (drawParent) drawMesh(*parentMesh); @@ -157,14 +159,6 @@ InitLightingAndProjection(); // define light sources and projection - originalMesh = new Mesh(); - originalMesh->loadData(R"(C:\CLionProjects\cg\hw04\mesh1.obj)"); - - OGLWidget::childSubdiv(1); - -// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); - - OGLWidget::parentSubdiv(0); } @@ -235,3 +229,21 @@ scale = float(i) / 10.0f; } +bool OGLWidget::loadFile(string filename) { + + originalMesh = new Mesh(); + bool success = originalMesh->loadData(filename); + + init = success; + if (!success) return false; + + + OGLWidget::childSubdiv(childSubdivCount); + +// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); + + OGLWidget::parentSubdiv(parentSubdivCount); + + return true; +} + diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.h b/hw04/mainwindow.h index b3aab25..ba0c87d 100644 --- a/hw04/mainwindow.h +++ b/hw04/mainwindow.h @@ -18,6 +18,9 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void loadButtonClick(); + private: Ui::MainWindow *ui; }; diff --git a/hw04/mainwindow.ui b/hw04/mainwindow.ui index 9f9248a..d3b8369 100644 --- a/hw04/mainwindow.ui +++ b/hw04/mainwindow.ui @@ -126,6 +126,31 @@ + + + + Qt::Horizontal + + + + + + + + + C:\CLionProjects\cg\hw04\mesh1.obj + + + + + + + Load + + + + + diff --git a/hw04/oglwidget.cpp b/hw04/oglwidget.cpp index 3c2f9bb..df2af28 100644 --- a/hw04/oglwidget.cpp +++ b/hw04/oglwidget.cpp @@ -15,6 +15,7 @@ Mesh *parentMesh; Mesh *childMesh; +bool init = false; bool childWireframe = false; bool drawParent = false; int parentSubdivCount = 0; @@ -61,6 +62,7 @@ } void DrawTriag() { + if (!init) return; drawMesh(*childMesh); if (drawParent) drawMesh(*parentMesh); @@ -157,14 +159,6 @@ InitLightingAndProjection(); // define light sources and projection - originalMesh = new Mesh(); - originalMesh->loadData(R"(C:\CLionProjects\cg\hw04\mesh1.obj)"); - - OGLWidget::childSubdiv(1); - -// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); - - OGLWidget::parentSubdiv(0); } @@ -235,3 +229,21 @@ scale = float(i) / 10.0f; } +bool OGLWidget::loadFile(string filename) { + + originalMesh = new Mesh(); + bool success = originalMesh->loadData(filename); + + init = success; + if (!success) return false; + + + OGLWidget::childSubdiv(childSubdivCount); + +// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); + + OGLWidget::parentSubdiv(parentSubdivCount); + + return true; +} + diff --git a/hw04/oglwidget.h b/hw04/oglwidget.h index 91200f7..cb5c424 100644 --- a/hw04/oglwidget.h +++ b/hw04/oglwidget.h @@ -24,6 +24,7 @@ void drawOutline(int i); void drawWireframe(int i); void setScale(int i); + bool loadFile(std::string filename); protected: void initializeGL(); diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.h b/hw04/mainwindow.h index b3aab25..ba0c87d 100644 --- a/hw04/mainwindow.h +++ b/hw04/mainwindow.h @@ -18,6 +18,9 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void loadButtonClick(); + private: Ui::MainWindow *ui; }; diff --git a/hw04/mainwindow.ui b/hw04/mainwindow.ui index 9f9248a..d3b8369 100644 --- a/hw04/mainwindow.ui +++ b/hw04/mainwindow.ui @@ -126,6 +126,31 @@ + + + + Qt::Horizontal + + + + + + + + + C:\CLionProjects\cg\hw04\mesh1.obj + + + + + + + Load + + + + + diff --git a/hw04/oglwidget.cpp b/hw04/oglwidget.cpp index 3c2f9bb..df2af28 100644 --- a/hw04/oglwidget.cpp +++ b/hw04/oglwidget.cpp @@ -15,6 +15,7 @@ Mesh *parentMesh; Mesh *childMesh; +bool init = false; bool childWireframe = false; bool drawParent = false; int parentSubdivCount = 0; @@ -61,6 +62,7 @@ } void DrawTriag() { + if (!init) return; drawMesh(*childMesh); if (drawParent) drawMesh(*parentMesh); @@ -157,14 +159,6 @@ InitLightingAndProjection(); // define light sources and projection - originalMesh = new Mesh(); - originalMesh->loadData(R"(C:\CLionProjects\cg\hw04\mesh1.obj)"); - - OGLWidget::childSubdiv(1); - -// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); - - OGLWidget::parentSubdiv(0); } @@ -235,3 +229,21 @@ scale = float(i) / 10.0f; } +bool OGLWidget::loadFile(string filename) { + + originalMesh = new Mesh(); + bool success = originalMesh->loadData(filename); + + init = success; + if (!success) return false; + + + OGLWidget::childSubdiv(childSubdivCount); + +// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); + + OGLWidget::parentSubdiv(parentSubdivCount); + + return true; +} + diff --git a/hw04/oglwidget.h b/hw04/oglwidget.h index 91200f7..cb5c424 100644 --- a/hw04/oglwidget.h +++ b/hw04/oglwidget.h @@ -24,6 +24,7 @@ void drawOutline(int i); void drawWireframe(int i); void setScale(int i); + bool loadFile(std::string filename); protected: void initializeGL(); diff --git a/hw04/src/Mesh.cpp b/hw04/src/Mesh.cpp index c3f444f..b925b20 100644 --- a/hw04/src/Mesh.cpp +++ b/hw04/src/Mesh.cpp @@ -38,11 +38,11 @@ file.close(); } -void Mesh::loadData(const string& fileName) { +bool Mesh::loadData(const string& fileName) { ifstream file( fileName); if (!file){ cout << "error opening file" << endl; - return; + return false; } string key; while( file){ @@ -63,6 +63,8 @@ file.close(); tris.pop_back(); + + return true; } void Mesh::connectivityAlgo() { diff --git a/hw04/mainwindow.cpp b/hw04/mainwindow.cpp index 43656fd..804fd8d 100644 --- a/hw04/mainwindow.cpp +++ b/hw04/mainwindow.cpp @@ -10,15 +10,33 @@ { ui->setupUi(this); + ui->parentSpinBox->setEnabled(false); + ui->childSpinBox->setEnabled(false); + ui->drawWireframe->setEnabled(false); + ui->drawOutline->setEnabled(false); + connect(ui->parentSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(parentSubdiv(int))); connect(ui->childSpinBox, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(childSubdiv(int))); connect(ui->drawWireframe, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawWireframe(int))); connect(ui->drawOutline, SIGNAL(stateChanged(int)), ui->glwidget, SLOT(drawOutline(int))); connect(ui->scale, SIGNAL(valueChanged(int)), ui->glwidget, SLOT(setScale(int))); + + connect(ui->fileLoad, SIGNAL(pressed()), this, SLOT(loadButtonClick())); + } MainWindow::~MainWindow() { delete ui; } + +void MainWindow::loadButtonClick() { + + bool success = ui->glwidget->loadFile(ui->fileEdit->text().toStdString()); + + ui->parentSpinBox->setEnabled(success); + ui->childSpinBox->setEnabled(success); + ui->drawWireframe->setEnabled(success); + ui->drawOutline->setEnabled(success); +} diff --git a/hw04/mainwindow.h b/hw04/mainwindow.h index b3aab25..ba0c87d 100644 --- a/hw04/mainwindow.h +++ b/hw04/mainwindow.h @@ -18,6 +18,9 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +public slots: + void loadButtonClick(); + private: Ui::MainWindow *ui; }; diff --git a/hw04/mainwindow.ui b/hw04/mainwindow.ui index 9f9248a..d3b8369 100644 --- a/hw04/mainwindow.ui +++ b/hw04/mainwindow.ui @@ -126,6 +126,31 @@ + + + + Qt::Horizontal + + + + + + + + + C:\CLionProjects\cg\hw04\mesh1.obj + + + + + + + Load + + + + + diff --git a/hw04/oglwidget.cpp b/hw04/oglwidget.cpp index 3c2f9bb..df2af28 100644 --- a/hw04/oglwidget.cpp +++ b/hw04/oglwidget.cpp @@ -15,6 +15,7 @@ Mesh *parentMesh; Mesh *childMesh; +bool init = false; bool childWireframe = false; bool drawParent = false; int parentSubdivCount = 0; @@ -61,6 +62,7 @@ } void DrawTriag() { + if (!init) return; drawMesh(*childMesh); if (drawParent) drawMesh(*parentMesh); @@ -157,14 +159,6 @@ InitLightingAndProjection(); // define light sources and projection - originalMesh = new Mesh(); - originalMesh->loadData(R"(C:\CLionProjects\cg\hw04\mesh1.obj)"); - - OGLWidget::childSubdiv(1); - -// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); - - OGLWidget::parentSubdiv(0); } @@ -235,3 +229,21 @@ scale = float(i) / 10.0f; } +bool OGLWidget::loadFile(string filename) { + + originalMesh = new Mesh(); + bool success = originalMesh->loadData(filename); + + init = success; + if (!success) return false; + + + OGLWidget::childSubdiv(childSubdivCount); + +// childMesh->saveData( R"(C:\CLionProjects\cg\hw04\test2.obj)"); + + OGLWidget::parentSubdiv(parentSubdivCount); + + return true; +} + diff --git a/hw04/oglwidget.h b/hw04/oglwidget.h index 91200f7..cb5c424 100644 --- a/hw04/oglwidget.h +++ b/hw04/oglwidget.h @@ -24,6 +24,7 @@ void drawOutline(int i); void drawWireframe(int i); void setScale(int i); + bool loadFile(std::string filename); protected: void initializeGL(); diff --git a/hw04/src/Mesh.cpp b/hw04/src/Mesh.cpp index c3f444f..b925b20 100644 --- a/hw04/src/Mesh.cpp +++ b/hw04/src/Mesh.cpp @@ -38,11 +38,11 @@ file.close(); } -void Mesh::loadData(const string& fileName) { +bool Mesh::loadData(const string& fileName) { ifstream file( fileName); if (!file){ cout << "error opening file" << endl; - return; + return false; } string key; while( file){ @@ -63,6 +63,8 @@ file.close(); tris.pop_back(); + + return true; } void Mesh::connectivityAlgo() { diff --git a/hw04/src/Mesh.h b/hw04/src/Mesh.h index eb672dd..8599579 100644 --- a/hw04/src/Mesh.h +++ b/hw04/src/Mesh.h @@ -23,7 +23,7 @@ bool drawOutline = false; Mesh(); - void loadData(const string& fileName); + bool loadData(const string& fileName); void saveData(const string& fileName); void connectivityAlgo();