Skip to content

Commit

Permalink
Merge pull request #158 from yungyuc/feature/develop-mdi
Browse files Browse the repository at this point in the history
Add MDI support to viewer
  • Loading branch information
yungyuc committed Nov 26, 2022
2 parents 8e4aea0 + 6887af2 commit 2774f90
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 115 deletions.
32 changes: 32 additions & 0 deletions cpp/modmesh/view/R3DWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/

#include <modmesh/view/R3DWidget.hpp> // Must be the first include.
#include <modmesh/view/RAxisMark.hpp>
#include <modmesh/view/RStaticMesh.hpp>

namespace modmesh
{
Expand All @@ -50,6 +52,36 @@ R3DWidget::R3DWidget(Qt3DExtras::Qt3DWindow * window, RScene * scene, QWidget *
control->setCamera(camera);
control->setLinearSpeed(50.0f);
control->setLookSpeed(180.0f);

if (Toggle::instance().get_show_axis())
{
showMark();
}
}

void R3DWidget::showMark()
{
for (Qt3DCore::QNode * child : m_scene->childNodes())
{
if (typeid(*child) == typeid(RAxisMark))
{
child->deleteLater();
}
}
new RAxisMark(m_scene);
}

void R3DWidget::updateMesh(std::shared_ptr<StaticMesh> const & mesh)
{
for (Qt3DCore::QNode * child : m_scene->childNodes())
{
if (typeid(*child) == typeid(RStaticMesh))
{
child->deleteLater();
}
}
new RStaticMesh(mesh, m_scene);
m_mesh = mesh;
}

void R3DWidget::resizeEvent(QResizeEvent * event)
Expand Down
6 changes: 6 additions & 0 deletions cpp/modmesh/view/R3DWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ class R3DWidget

QPixmap grabPixmap() const { return m_view->screen()->grabWindow(m_view->winId()); }

void showMark();
void updateMesh(std::shared_ptr<StaticMesh> const & mesh);

std::shared_ptr<StaticMesh> mesh() const { return m_mesh; }

private:

Qt3DExtras::Qt3DWindow * m_view = nullptr;
RScene * m_scene = nullptr;
QWidget * m_container = nullptr;
std::shared_ptr<StaticMesh> m_mesh;

}; /* end class R3DWidget */

Expand Down
14 changes: 14 additions & 0 deletions cpp/modmesh/view/RApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ RApplication::~RApplication()
{
}

R3DWidget * RApplication::add3DWidget()
{
R3DWidget * viewer = nullptr;
if (m_mainWindow)
{
viewer = new R3DWidget();
viewer->setWindowTitle("3D viewer");
viewer->show();
auto * subwin = m_mainWindow->addSubWindow(viewer);
subwin->resize(300, 200);
}
return viewer;
}

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
4 changes: 3 additions & 1 deletion cpp/modmesh/view/RApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RApplication

public:

~RApplication();
~RApplication() override;

RApplication & setUp();

Expand All @@ -54,6 +54,8 @@ class RApplication
static RApplication * initialize(int argc, char ** argv);
static RApplication * instance();

R3DWidget * add3DWidget();

private:

RApplication(int & argc, char ** argv);
Expand Down
22 changes: 9 additions & 13 deletions cpp/modmesh/view/RMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void RMainWindow::setUp()
}

this->setUpConsole();
this->setUpViewer();
this->setUpCentral();
this->setUpMenu();

m_already_setup = true;
Expand All @@ -70,10 +70,12 @@ void RMainWindow::setUpConsole()
addDockWidget(Qt::BottomDockWidgetArea, m_pycon);
}

void RMainWindow::setUpViewer()
void RMainWindow::setUpCentral()
{
m_viewer = new R3DWidget();
setCentralWidget(m_viewer);
m_mdiArea = new QMdiArea(this);
m_mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setCentralWidget(m_mdiArea);
}

void RMainWindow::setUpMenu()
Expand Down Expand Up @@ -117,25 +119,19 @@ void RMainWindow::setUpMenu()
m_cameraMenu = this->menuBar()->addMenu(QString("Camera"));

auto * use_orbit_camera = new RAction(
QString("Use Oribt Camera Controller"),
QString("Use Orbit Camera Controller"),
QString("Use Oribt Camera Controller"),
[this]()
{
qDebug() << "Use Orbit Camera Controller";
auto * viewer = this->viewer();
viewer->scene()->setOrbitCameraController();
viewer->scene()->controller()->setCamera(viewer->camera());
qDebug() << "Use Orbit Camera Controller (menu demo)";
});

auto * use_fps_camera = new RAction(
QString("Use First Person Camera Controller"),
QString("Use First Person Camera Controller"),
[this]()
{
qDebug() << "Use First Person Camera Controller";
auto * viewer = this->viewer();
viewer->scene()->setFirstPersonCameraController();
viewer->scene()->controller()->setCamera(viewer->camera());
qDebug() << "Use First Person Camera Controller (menu demo)";
});

auto * cameraGroup = new QActionGroup(this);
Expand Down
23 changes: 20 additions & 3 deletions cpp/modmesh/view/RMainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

#include <Qt>
#include <QMainWindow>
#include <QMdiArea>
#include <QMdiSubWindow>

namespace modmesh
{
Expand All @@ -51,7 +53,9 @@ class RMainWindow
void setUp();

RPythonConsoleDockWidget * pycon() { return m_pycon; }
R3DWidget * viewer() { return m_viewer; }

template <typename... Args>
QMdiSubWindow * addSubWindow(Args &&... args);

public slots:

Expand All @@ -61,7 +65,7 @@ public slots:
private:

void setUpConsole();
void setUpViewer();
void setUpCentral();
void setUpMenu();

bool m_already_setup = false;
Expand All @@ -71,10 +75,23 @@ public slots:
QMenu * m_cameraMenu = nullptr;

RPythonConsoleDockWidget * m_pycon = nullptr;
R3DWidget * m_viewer = nullptr;
QMdiArea * m_mdiArea = nullptr;

}; /* end class RPythonText */

template <typename... Args>
QMdiSubWindow * RMainWindow::addSubWindow(Args &&... args)
{
QMdiSubWindow * subwin = nullptr;
if (m_mdiArea)
{
subwin = m_mdiArea->addSubWindow(std::forward<Args>(args)...);
subwin->show();
m_mdiArea->setActiveSubWindow(subwin);
}
return subwin;
}

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
10 changes: 10 additions & 0 deletions cpp/modmesh/view/RPythonConsoleDockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ void RPythonConsoleDockWidget::navigateCommand(int offset)
}
}

void RPythonConsoleDockWidget::writeToHistory(const std::string & data)
{
QTextCursor cursor = m_history_edit->textCursor();
cursor.movePosition(QTextCursor::End);
m_history_edit->setTextCursor(cursor);
m_history_edit->insertPlainText(QString::fromStdString(data));
cursor.movePosition(QTextCursor::End);
m_history_edit->setTextCursor(cursor);
}

} /* end namespace modmesh */

// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
2 changes: 2 additions & 0 deletions cpp/modmesh/view/RPythonConsoleDockWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class RPythonConsoleDockWidget
return *this;
}

void writeToHistory(std::string const & data);

public slots:

void setCommand(QString const & value);
Expand Down
Loading

0 comments on commit 2774f90

Please sign in to comment.