Browse Source

Work of today

Johannes Kreutz 2 years ago
parent
commit
21e0cf9966

BIN
testdata/testbutton.3mf


+ 2 - 1
trackpoint-app/CMakeLists.txt

@@ -67,6 +67,7 @@ QT_ADD_EXECUTABLE(TrackpointApp
   src/TrackPoint.cpp
   src/ThreeMFWriter.cpp
   src/OpenScadRenderer.cpp
+  src/StringBasics.cpp
 )
 
 if(NOT BUILD_STATIC_RELEASE)
@@ -108,4 +109,4 @@ TARGET_LINK_LIBRARIES(TrackpointApp PRIVATE
 )
 
 # Header to have version number available in the code
-CONFIGURE_FILE(src/trackpointapp.hpp.in src/trackpointapp.hpp)
+CONFIGURE_FILE(include/trackpointapp.hpp.in include/trackpointapp.hpp)

+ 4 - 0
trackpoint-app/include/MainWindow.hpp

@@ -3,6 +3,7 @@
 #include "OSGWidget.hpp"
 #include "NoMeshWidget.hpp"
 #include "EditWidget.hpp"
+#include "ProjectStore.hpp"
 
 #include <QMainWindow>
 
@@ -22,10 +23,13 @@ public:
   MainWindow(QWidget* parent = nullptr);
   ~MainWindow();
   void renderView(GuiView view);
+  ProjectStore* getProjectStorePointer();
+  OSGWidget* getOsgWidget();
 
 private:
   void openFile();
   Ui::MainWindow* ui;
+  ProjectStore* projectStore;
   OSGWidget* osgWidget;
   NoMeshWidget* noMeshWidget;
   EditWidget* editWidget;

+ 3 - 0
trackpoint-app/include/NoMeshWidget.hpp

@@ -13,6 +13,9 @@ public:
   NoMeshWidget(QWidget* parent = nullptr);
   ~NoMeshWidget();
 
+private slots:
+  void loadMeshFile();
+
 private:
   Ui::NoMeshWidget* ui;
 };

+ 5 - 1
trackpoint-app/include/ProjectStore.hpp

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <QString>
+#include "lib3mf_implicit.hpp"
 
 class ProjectStore {
 public:
@@ -9,8 +10,11 @@ public:
   // Load an existing project
   ProjectStore(QString projectFile);
   // Load a mesh
-  void loadMesh(QString meshFile);
+  void loadMesh(QString meshFileString);
 
 private:
   bool projectLoaded;
+  Lib3MF::PWrapper _wrapper;
+  Lib3MF::PModel _project;
+  void load3mfLib();
 };

+ 8 - 0
trackpoint-app/include/StringBasics.hpp

@@ -0,0 +1,8 @@
+#pragma once
+
+#include <string>
+
+class StringBasics {
+public:
+  static bool endsWithCaseInsensitive(std::string const &fullStringInput, std::string const &endingInput);
+};

+ 0 - 0
trackpoint-app/src/trackpointapp.hpp.in → trackpoint-app/include/trackpointapp.hpp.in


+ 1 - 0
trackpoint-app/src/EditWidget.cpp

@@ -1,3 +1,4 @@
+// Include own headers
 #include "EditWidget.hpp"
 #include "../gui/ui_EditWidget.h"
 

+ 13 - 1
trackpoint-app/src/MainWindow.cpp

@@ -1,6 +1,8 @@
+// Include own headers
 #include "MainWindow.hpp"
 #include "../gui/ui_MainWindow.h"
 
+// Include dependencies
 #include <QFileDialog>
 
 MainWindow::MainWindow(QWidget* parent): QMainWindow(parent), ui(new Ui::MainWindow) {
@@ -9,7 +11,9 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent), ui(new Ui::MainWin
   osgWidget = new OSGWidget(this);
   ui->sceneWidget->layout()->addWidget(osgWidget);
 
-  renderView(Edit);
+  // TODO: Add option for opening a project via double click
+  projectStore = new ProjectStore();
+  renderView(NoMesh);
 }
 
 MainWindow::~MainWindow() {
@@ -17,6 +21,14 @@ MainWindow::~MainWindow() {
   delete osgWidget;
 }
 
+ProjectStore* MainWindow::getProjectStorePointer() {
+  return projectStore;
+}
+
+OSGWidget* MainWindow::getOsgWidget() {
+  return osgWidget;
+}
+
 void MainWindow::renderView(GuiView view) {
   switch(view) {
     case NoMesh: {

+ 14 - 0
trackpoint-app/src/NoMeshWidget.cpp

@@ -1,10 +1,24 @@
+// Include own headers
 #include "NoMeshWidget.hpp"
 #include "../gui/ui_NoMeshWidget.h"
 
+// Include modules
+#include "MainWindow.hpp"
+
+// Include dependencies
+#include <QFileDialog>
+
 NoMeshWidget::NoMeshWidget(QWidget* parent): QWidget(parent), ui(new Ui::NoMeshWidget) {
   ui->setupUi(this);
+  QObject::connect(ui->noMeshButton, &QPushButton::clicked, this, &NoMeshWidget::loadMeshFile);
 }
 
 NoMeshWidget::~NoMeshWidget() {
   delete ui;
 }
+
+void NoMeshWidget::loadMeshFile() {
+  QString fileName = QFileDialog::getOpenFileName(this, tr("Open a 3D-Object"), "", tr("3D Objects (*.3mf *.stl)"));
+  MainWindow* parent = ((MainWindow*)this->parentWidget());
+  parent->getProjectStorePointer()->loadMesh(fileName);
+}

+ 27 - 106
trackpoint-app/src/OSGWidget.cpp

@@ -1,6 +1,8 @@
+// Include own headers
 #include "OSGWidget.hpp"
 #include "PickHandler.hpp"
 
+// Include dependencies
 #include <osgViewer/Viewer>
 #include <osg/ShapeDrawable>
 #include <osg/Geode>
@@ -144,84 +146,34 @@ void OSGWidget::resizeGL(int width, int height) {
   this->onResize(width, height);
 }
 
-void OSGWidget::keyPressEvent( QKeyEvent* event )
-{
-  QString keyString   = event->text();
+void OSGWidget::keyPressEvent(QKeyEvent* event) {
+  QString keyString = event->text();
   const char* keyData = keyString.toLocal8Bit().data();
 
-  if( event->key() == Qt::Key_S )
-  {
-
-    // Further processing is required for the statistics handler here, so we do
-    // not return right away.
-  }
-  else if( event->key() == Qt::Key_D )
-  {
-    osgDB::writeNodeFile( *_viewer->getView(0)->getSceneData(),
-                          "/tmp/sceneGraph.osg" );
-
-    return;
-  }
-  else if( event->key() == Qt::Key_H )
-  {
+  if (event->key() == Qt::Key_H) {
     this->onHome();
     return;
   }
 
-  this->getEventQueue()->keyPress( osgGA::GUIEventAdapter::KeySymbol( *keyData ) );
+  this->getEventQueue()->keyPress(osgGA::GUIEventAdapter::KeySymbol(*keyData));
 }
 
-void OSGWidget::keyReleaseEvent( QKeyEvent* event )
-{
-  QString keyString   = event->text();
+void OSGWidget::keyReleaseEvent(QKeyEvent* event) {
+  QString keyString = event->text();
   const char* keyData = keyString.toLocal8Bit().data();
 
-  this->getEventQueue()->keyRelease( osgGA::GUIEventAdapter::KeySymbol( *keyData ) );
+  this->getEventQueue()->keyRelease(osgGA::GUIEventAdapter::KeySymbol(*keyData));
 }
 
-void OSGWidget::mouseMoveEvent( QMouseEvent* event )
-{
-  // Note that we have to check the buttons mask in order to see whether the
-  // left button has been pressed. A call to `button()` will only result in
-  // `Qt::NoButton` for mouse move events.
-  /*if( selectionActive_ && event->buttons() & Qt::LeftButton )
-  {
-    selectionEnd_ = event->pos();
-
-    // Ensures that new paint events are created while the user moves the
-    // mouse.
-    this->update();
-  }
-  else
-  {*/
-    auto pixelRatio = this->devicePixelRatio();
-
-    this->getEventQueue()->mouseMotion( static_cast<float>( event->x() * pixelRatio ),
-                                        static_cast<float>( event->y() * pixelRatio ) );
-  //}
+void OSGWidget::mouseMoveEvent(QMouseEvent* event) {
+  auto pixelRatio = this->devicePixelRatio();
+  this->getEventQueue()->mouseMotion(static_cast<float>(event->position().x() * pixelRatio), static_cast<float>(event->position().y() * pixelRatio));
 }
 
-void OSGWidget::mousePressEvent( QMouseEvent* event )
-{
-  // Selection processing
-  /*if( selectionActive_ && event->button() == Qt::LeftButton )
-  {
-    selectionStart_    = event->pos();
-    selectionEnd_      = selectionStart_; // Deletes the old selection
-    selectionFinished_ = false;           // As long as this is set, the rectangle will be drawn
-  }
-
-  // Normal processing
-  else
-  {*/
-    // 1 = left mouse button
-    // 2 = middle mouse button
-    // 3 = right mouse button
-
-    unsigned int button = 0;
+void OSGWidget::mousePressEvent(QMouseEvent* event) {
+  unsigned int button = 0;
 
-    switch( event->button() )
-    {
+  switch(event->button()) {
     case Qt::LeftButton:
       button = 1;
       break;
@@ -236,38 +188,17 @@ void OSGWidget::mousePressEvent( QMouseEvent* event )
 
     default:
       break;
-    }
+  }
 
-    auto pixelRatio = this->devicePixelRatio();
+  auto pixelRatio = this->devicePixelRatio();
 
-    this->getEventQueue()->mouseButtonPress( static_cast<float>( event->x() * pixelRatio ),
-                                             static_cast<float>( event->y() * pixelRatio ),
-                                             button );
-    //}
+  this->getEventQueue()->mouseButtonPress(static_cast<float>(event->position().x() * pixelRatio), static_cast<float>(event->position().y() * pixelRatio), button);
 }
 
-void OSGWidget::mouseReleaseEvent(QMouseEvent* event)
-{
-  // Selection processing: Store end position and obtain selected objects
-  // through polytope intersection.
-  /*if( selectionActive_ && event->button() == Qt::LeftButton )
-  {
-    selectionEnd_      = event->pos();
-    selectionFinished_ = true; // Will force the painter to stop drawing the
-                               // selection rectangle
-  }
-
-  // Normal processing
-  else
-  {*/
-    // 1 = left mouse button
-    // 2 = middle mouse button
-    // 3 = right mouse button
-
-    unsigned int button = 0;
+void OSGWidget::mouseReleaseEvent(QMouseEvent* event) {
+  unsigned int button = 0;
 
-    switch( event->button() )
-    {
+  switch(event->button()) {
     case Qt::LeftButton:
       button = 1;
       break;
@@ -282,29 +213,20 @@ void OSGWidget::mouseReleaseEvent(QMouseEvent* event)
 
     default:
       break;
-    }
+  }
 
-    auto pixelRatio = this->devicePixelRatio();
+  auto pixelRatio = this->devicePixelRatio();
 
-    this->getEventQueue()->mouseButtonRelease( static_cast<float>( pixelRatio * event->x() ),
-                                               static_cast<float>( pixelRatio * event->y() ),
-                                               button );
-  //}
+  this->getEventQueue()->mouseButtonRelease(static_cast<float>(pixelRatio * event->position().x()), static_cast<float>(pixelRatio * event->position().y()), button);
 }
 
-void OSGWidget::wheelEvent( QWheelEvent* event )
-{
-  // Ignore wheel events as long as the selection is active.
-  if( selectionActive_ )
-    return;
-
+void OSGWidget::wheelEvent(QWheelEvent* event) {
   event->accept();
   int delta = event->angleDelta().y();
 
-  osgGA::GUIEventAdapter::ScrollingMotion motion = delta > 0 ?   osgGA::GUIEventAdapter::SCROLL_UP
-                                                               : osgGA::GUIEventAdapter::SCROLL_DOWN;
+  osgGA::GUIEventAdapter::ScrollingMotion motion = delta > 0 ? osgGA::GUIEventAdapter::SCROLL_UP : osgGA::GUIEventAdapter::SCROLL_DOWN;
 
-  this->getEventQueue()->mouseScroll( motion );
+  this->getEventQueue()->mouseScroll(motion);
 }
 
 bool OSGWidget::event(QEvent* event) {
@@ -358,7 +280,6 @@ void OSGWidget::onResize(int width, int height) {
 
 osgGA::EventQueue* OSGWidget::getEventQueue() const {
   osgGA::EventQueue* eventQueue = graphicsWindow_->getEventQueue();
-
   if (eventQueue) {
     return eventQueue;
   } else {

+ 2 - 0
trackpoint-app/src/OpenScadRenderer.cpp

@@ -1,5 +1,7 @@
+// Include own headers
 #include "OpenScadRenderer.hpp"
 
+// Include dependencies
 #include <iostream>
 #include <fstream>
 

+ 2 - 0
trackpoint-app/src/PickHandler.cpp

@@ -1,5 +1,7 @@
+// Include own headers
 #include "PickHandler.hpp"
 
+// Include dependencies
 #include <osg/io_utils>
 
 #include <osgUtil/IntersectionVisitor>

+ 20 - 2
trackpoint-app/src/ProjectStore.cpp

@@ -1,13 +1,31 @@
+// Include own headers
 #include "ProjectStore.hpp"
 
+// Include modules
+#include "StringBasics.hpp"
+
 ProjectStore::ProjectStore() {
   projectLoaded = false;
+  load3mfLib();
 }
 
 ProjectStore::ProjectStore(QString projectFile) {
 
 }
 
-void ProjectStore::loadMesh(QString meshFile) {
-  
+void ProjectStore::load3mfLib() {
+  _wrapper = Lib3MF::CWrapper::loadLibrary();
+}
+
+void ProjectStore::loadMesh(QString meshFileString) {
+  std::string meshFile = meshFileString.toUtf8().constData();
+  if (StringBasics::endsWithCaseInsensitive(meshFile, ".STL")) {
+    printf("Currently unsupported.\n");
+  } else if (StringBasics::endsWithCaseInsensitive(meshFile, ".3MF")) {
+    Lib3MF::PModel meshModel = _wrapper->CreateModel();
+    Lib3MF::PReader reader = meshModel->QueryReader("3mf");
+    reader->ReadFromFile(meshFile);
+  } else {
+    printf("Unsupported file type.\n"); // TODO: Show popup
+  }
 }

+ 20 - 0
trackpoint-app/src/StringBasics.cpp

@@ -0,0 +1,20 @@
+// Include own headers
+#include "StringBasics.hpp"
+
+// Include dependencies
+#include <algorithm>
+#include <cctype>
+
+// From https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c
+// Lowercase from https://stackoverflow.com/questions/313970/how-to-convert-an-instance-of-stdstring-to-lower-case
+bool StringBasics::endsWithCaseInsensitive(std::string const &fullStringInput, std::string const &endingInput) {
+  std::string fullString = fullStringInput;
+  std::transform(fullString.begin(), fullString.end(), fullString.begin(), ::tolower);
+  std::string ending = endingInput;
+  std::transform(ending.begin(), ending.end(), ending.begin(), ::tolower);
+  if (fullString.length() >= ending.length()) {
+    return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
+  } else {
+    return false;
+  }
+}

+ 1 - 0
trackpoint-app/src/ThreeMFWriter.cpp

@@ -1,3 +1,4 @@
+// Include own headers
 #include "ThreeMFWriter.hpp"
 
 ThreeMFWriter::ThreeMFWriter() {

+ 2 - 0
trackpoint-app/src/TrackPoint.cpp

@@ -1,5 +1,7 @@
+// Include own headers
 #include "TrackPoint.hpp"
 
+// Include dependencies
 #include <osg/Geode>
 #include <osg/ShapeDrawable>
 #include <osg/Material>

+ 1 - 0
trackpoint-app/src/main.cpp

@@ -1,3 +1,4 @@
+// Include dependencies
 #include <QApplication>
 #include <QSurfaceFormat>