# 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
)
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 ---
SET(_moc_HEADERS
DummyApplication.h
DummyDesktop.h
+ MiniViewer.h
)
# header files / no moc processing
SET(_other_SOURCES
DummyApplication.cxx
DummyDesktop.cxx
+ MiniViewer.cxx
)
# sources / to compile
#include "utilities.h"
+#include <vtkDataSetReader.h>
+
#include <QtxLogoMgr.h>
#include <QtxActionMenuMgr.h>
myMenuMgr = new QtxActionMenuMgr( this );
myToolMgr = new QtxActionToolMgr( this );
myLogoMgr = new QtxLogoMgr( menuBar() );
+ myViewer = new MiniViewer(this);
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()
// 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
#define DUMMYDESKTOP_H
#include <QtxMainWindow.h>
+#include "MiniViewer.h"
class QtxLogoMgr;
class QtxActionMenuMgr;
void RunScript();
void Dummy();
+ void OpenMeshFile();
void createMenus();
private:
QtxActionMenuMgr* myMenuMgr;
QtxActionToolMgr* myToolMgr;
QtxLogoMgr* myLogoMgr;
+ MiniViewer* myViewer;
};
#endif
--- /dev/null
+// 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
--- /dev/null
+// 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