]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Added Mini viewer yan/standaloneapp
authorYoann Audouin <yoann.audouin@edf.fr>
Tue, 27 Jul 2021 13:00:32 +0000 (15:00 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Tue, 27 Jul 2021 13:00:32 +0000 (15:00 +0200)
src/DummyApplication/CMakeLists.txt
src/DummyApplication/DummyDesktop.cxx
src/DummyApplication/DummyDesktop.h
src/DummyApplication/MiniViewer.cxx [new file with mode: 0644]
src/DummyApplication/MiniViewer.h [new file with mode: 0644]

index 7161cb67fe32b5956a71a8354e4c83970e0a1088..5f2ae890c4ea72b363cb175f23c7436134b8f2aa 100644 (file)
@@ -24,6 +24,9 @@ INCLUDE(UseQtExt)
 # additional include directories
 INCLUDE_DIRECTORIES(
   ${QT_INCLUDES}
+  ${PROJECT_SOURCE_DIR}/src/SUIT
+  ${PROJECT_SOURCE_DIR}/src/VTKViewer
+  ${OpenCASCADE_INCLUDE_DIR}
   ${PROJECT_SOURCE_DIR}/src/Qtx
   ${PROJECT_SOURCE_DIR}/src/ObjBrowser
 )
@@ -32,7 +35,12 @@ INCLUDE_DIRECTORIES(
 ADD_DEFINITIONS(${QT_DEFINITIONS})
 
 # libraries to link to
-SET(_link_LIBRARIES ${PLATFORM_LIBS} ${QT_LIBRARIES} qtx ObjBrowser)
+SET(_link_LIBRARIES
+  ${PLATFORM_LIBS}
+  ${QT_LIBRARIES}
+  qtx
+  ObjBrowser
+  VTK::GUISupportQt)
 
 # --- headers ---
 
@@ -40,6 +48,7 @@ SET(_link_LIBRARIES ${PLATFORM_LIBS} ${QT_LIBRARIES} qtx ObjBrowser)
 SET(_moc_HEADERS
   DummyApplication.h
   DummyDesktop.h
+  MiniViewer.h
 )
 
 # header files / no moc processing
@@ -75,6 +84,7 @@ QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS})
 SET(_other_SOURCES
   DummyApplication.cxx
   DummyDesktop.cxx
+  MiniViewer.cxx
 )
 
 # sources / to compile
index 0b5a394a852ca0b6cdcc2d54a57d5b742b9e9f7e..42c97596b236035fb8142a5b6945609a18a957e8 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "utilities.h"
 
+#include <vtkDataSetReader.h>
+
 
 #include <QtxLogoMgr.h>
 #include <QtxActionMenuMgr.h>
@@ -60,8 +62,10 @@ DummyDesktop::DummyDesktop()
   myMenuMgr = new QtxActionMenuMgr( this );
   myToolMgr = new QtxActionToolMgr( this );
   myLogoMgr = new QtxLogoMgr( menuBar() );
+  myViewer = new MiniViewer(this);
 
   createMenus();
+
 }
 
 /*!
@@ -77,17 +81,10 @@ void DummyDesktop::createMenus()
   //QPushButton *mybutton = new QPushButton("Test", this);
   //connect(mybutton, &QPushButton::released, this, &DummyDesktop::RunScript);
 
-  //this->setCentralWidget(mybutton);
+  this->setCentralWidget(myViewer);
   QMenu *fileMenu = menuBar()->addMenu("File");
   fileMenu->addAction("Open File", this, &DummyDesktop::RunScript, QKeySequence::Open);
-  fileMenu->addAction("Dummy", this, SLOT( Dummy()), QKeySequence::New);
-}
-
-void DummyDesktop::Dummy()
-{
-  QMessageBox msgBox;
-  msgBox.setText("Dummy text");
-  msgBox.exec();
+  fileMenu->addAction("Open Mesh File", this, &DummyDesktop::OpenMeshFile );
 }
 
 void DummyDesktop::RunScript()
@@ -125,3 +122,31 @@ void DummyDesktop::RunScript()
   // Release GIL
   PyGILState_Release(gstate);
 }
+
+void DummyDesktop::OpenMeshFile()
+{
+  // Getting file to display
+  QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), "",
+      "VTK Files (*.vtk)");
+
+  // Open file
+  QFile file(fileName);
+  file.open(QIODevice::ReadOnly);
+
+  // Return on Cancel
+  if (!file.exists())
+      return;
+
+  // Create reader
+  vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New();
+  reader->SetFileName(fileName.toStdString().c_str());
+
+  // Read the file
+  reader->Update();
+
+  // Add data set to 3D view
+  vtkSmartPointer<vtkDataSet> dataSet = reader->GetOutput();
+  if (dataSet != nullptr) {
+      myViewer->addDataSet(reader->GetOutput());
+  }
+}
\ No newline at end of file
index 3225b4b65872a200d4b9e70dcd35f54cc879de40..92dcbffaaeafda2019a52e7e91a4358485011e53 100644 (file)
@@ -23,6 +23,7 @@
 #define DUMMYDESKTOP_H
 
 #include <QtxMainWindow.h>
+#include "MiniViewer.h"
 
 class QtxLogoMgr;
 class QtxActionMenuMgr;
@@ -38,12 +39,14 @@ public:
 
   void RunScript();
   void Dummy();
+  void OpenMeshFile();
   void createMenus();
 
 private:
   QtxActionMenuMgr*        myMenuMgr;
   QtxActionToolMgr*        myToolMgr;
   QtxLogoMgr*              myLogoMgr;
+  MiniViewer*              myViewer;
 };
 
 #endif
diff --git a/src/DummyApplication/MiniViewer.cxx b/src/DummyApplication/MiniViewer.cxx
new file mode 100644 (file)
index 0000000..ac75e36
--- /dev/null
@@ -0,0 +1,85 @@
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "MiniViewer.h"
+
+#include <vtkCamera.h>
+#include <vtkDataSetMapper.h>
+#include <vtkGenericOpenGLRenderWindow.h>
+#include <vtkProperty.h>
+#include <vtkRenderWindowInteractor.h>
+
+MiniViewer::MiniViewer(QWidget* parent)
+    : QVTKOpenGLNativeWidget(parent)
+{
+    vtkNew<vtkGenericOpenGLRenderWindow> window;
+    setRenderWindow(window.Get());
+
+    // Camera
+    vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
+    camera->SetViewUp(0, 1, 0);
+    camera->SetPosition(0, 0, 10);
+    camera->SetFocalPoint(0, 0, 0);
+
+    // Renderer
+    m_renderer = vtkSmartPointer<vtkRenderer>::New();
+    m_renderer->SetActiveCamera(camera);
+    m_renderer->SetBackground(0.5, 0.5, 0.5);
+    renderWindow()->AddRenderer(m_renderer);
+}
+
+void MiniViewer::addDataSet(vtkSmartPointer<vtkDataSet> dataSet)
+{
+    // Actor
+    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
+
+    // Mapper
+    vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
+    mapper->SetInputData(dataSet);
+    actor->SetMapper(mapper);
+
+    m_renderer->AddActor(actor);
+    m_renderer->ResetCamera(dataSet->GetBounds());
+
+    renderWindow()->Render();
+}
+
+void MiniViewer::removeDataSet()
+{
+    vtkActor* actor = m_renderer->GetActors()->GetLastActor();
+    if (actor != nullptr) {
+        m_renderer->RemoveActor(actor);
+    }
+
+    renderWindow()->Render();
+}
+
+void MiniViewer::zoomToExtent()
+{
+    // Zoom to extent of last added actor
+    vtkSmartPointer<vtkActor> actor = m_renderer->GetActors()->GetLastActor();
+    if (actor != nullptr) {
+        m_renderer->ResetCamera(actor->GetBounds());
+    }
+
+    renderWindow()->Render();
+}
\ No newline at end of file
diff --git a/src/DummyApplication/MiniViewer.h b/src/DummyApplication/MiniViewer.h
new file mode 100644 (file)
index 0000000..7f556d4
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef MINIVIEWER_H
+#define MINIVIEWER_H
+
+#include <QVTKOpenGLNativeWidget.h>
+#include <vtkDataSet.h>
+#include <vtkRenderer.h>
+#include <vtkSmartPointer.h>
+
+class MiniViewer : public QVTKOpenGLNativeWidget {
+    Q_OBJECT
+public:
+    explicit MiniViewer(QWidget* parent = nullptr);
+
+    //! Add a data set to the scene
+    /*!
+    \param[in] dataSet The data set to add
+  */
+    void addDataSet(vtkSmartPointer<vtkDataSet> dataSet);
+
+    //! Remove the data set from the scene
+    void removeDataSet();
+
+public slots:
+    //! Zoom to the extent of the data set in the scene
+    void zoomToExtent();
+
+private:
+    vtkSmartPointer<vtkRenderer> m_renderer;
+};
+
+#endif // MINIVIEWER_H
\ No newline at end of file