From f80d91193e9c8dbb842d7550dd269bfe3f7f61f5 Mon Sep 17 00:00:00 2001 From: zhouhang95 <765229842@qq.com> Date: Mon, 22 Apr 2024 17:20:24 +0800 Subject: [PATCH] step 3 --- ui/zenoedit/viewport/cameracontrol.cpp | 16 +++++++++++++--- ui/zenoedit/viewport/cameracontrol.h | 4 ++-- ui/zenoedit/viewport/viewportwidget.cpp | 3 +++ zeno/src/utils/log.cpp | 5 ++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ui/zenoedit/viewport/cameracontrol.cpp b/ui/zenoedit/viewport/cameracontrol.cpp index b1fd4683f2..2978c63ba2 100644 --- a/ui/zenoedit/viewport/cameracontrol.cpp +++ b/ui/zenoedit/viewport/cameracontrol.cpp @@ -116,10 +116,12 @@ void CameraControl::fakeMousePressEvent(QMouseEvent *event) if (event->button() == Qt::MiddleButton) { middle_button_pressed = true; } + auto m_picker = this->m_picker.lock(); + auto m_transformer = this->m_transformer.lock(); if (scene->camera->m_need_sync) { scene->camera->m_need_sync = false; if (bool(m_picker) && scene->camera->m_auto_radius) { - this->m_picker->set_picked_depth_callback([&] (float depth, int x, int y) { + m_picker->set_picked_depth_callback([&] (float depth, int x, int y) { if (depth < 0.001f) { return; } @@ -133,7 +135,7 @@ void CameraControl::fakeMousePressEvent(QMouseEvent *event) }); int mid_x = int(this->res().x() * 0.5); int mid_y = int(this->res().y() * 0.5); - this->m_picker->pick_depth(mid_x, mid_y); + m_picker->pick_depth(mid_x, mid_y); } } int button = Qt::NoButton; @@ -227,6 +229,7 @@ void CameraControl::lookTo(int dir) { } void CameraControl::clearTransformer() { + auto m_transformer = this->m_transformer.lock(); if (!m_transformer) return; m_transformer->clear(); @@ -234,6 +237,7 @@ void CameraControl::clearTransformer() { void CameraControl::changeTransformOperation(const QString &node) { + auto m_transformer = this->m_transformer.lock(); if (!m_transformer) return; @@ -256,6 +260,7 @@ void CameraControl::changeTransformOperation(const QString &node) void CameraControl::changeTransformOperation(int mode) { + auto m_transformer = this->m_transformer.lock(); if (!m_transformer) return; @@ -270,6 +275,7 @@ void CameraControl::changeTransformOperation(int mode) void CameraControl::changeTransformCoordSys() { + auto m_transformer = this->m_transformer.lock(); if (!m_transformer) return; m_transformer->changeCoordSys(); @@ -278,6 +284,7 @@ void CameraControl::changeTransformCoordSys() void CameraControl::resizeTransformHandler(int dir) { + auto m_transformer = this->m_transformer.lock(); if (!m_transformer) return; m_transformer->resizeHandler(dir); @@ -286,6 +293,7 @@ void CameraControl::resizeTransformHandler(int dir) void CameraControl::fakeMouseMoveEvent(QMouseEvent *event) { + auto m_transformer = this->m_transformer.lock(); bool ctrl_pressed = event->modifiers() & Qt::ControlModifier; bool alt_pressed = event->modifiers() & Qt::AltModifier; @@ -467,6 +475,7 @@ void CameraControl::fakeWheelEvent(QWheelEvent *event) { void CameraControl::fakeMouseDoubleClickEvent(QMouseEvent *event) { auto pos = event->pos(); + auto m_picker = this->m_picker.lock(); if (!m_picker) return; auto scene = m_zenovis->getSession()->get_scene(); @@ -580,7 +589,8 @@ void CameraControl::fakeMouseReleaseEvent(QMouseEvent *event) { middle_button_pressed = false; } if (event->button() == Qt::LeftButton) { - + auto m_transformer = this->m_transformer.lock(); + auto m_picker = this->m_picker.lock(); //if (Zenovis::GetInstance().m_bAddPoint == true) { //float x = (float)event->x() / m_res.x(); //float y = (float)event->y() / m_res.y(); diff --git a/ui/zenoedit/viewport/cameracontrol.h b/ui/zenoedit/viewport/cameracontrol.h index a82c073aff..61cfc6c75b 100644 --- a/ui/zenoedit/viewport/cameracontrol.h +++ b/ui/zenoedit/viewport/cameracontrol.h @@ -64,8 +64,8 @@ class CameraControl : public QObject QVector2D m_res; QSet m_pressedKeys; - std::shared_ptr m_picker; - std::shared_ptr m_transformer; + std::weak_ptr m_picker; + std::weak_ptr m_transformer; Zenovis* m_zenovis; bool middle_button_pressed = false; diff --git a/ui/zenoedit/viewport/viewportwidget.cpp b/ui/zenoedit/viewport/viewportwidget.cpp index d43bcc9375..07b5e47f2e 100644 --- a/ui/zenoedit/viewport/viewportwidget.cpp +++ b/ui/zenoedit/viewport/viewportwidget.cpp @@ -137,6 +137,9 @@ void ViewportWidget::cleanUpView() { if (m_zenovis) m_zenovis->cleanupView(); + + m_picker = nullptr; + m_fakeTrans = nullptr; } namespace { diff --git a/zeno/src/utils/log.cpp b/zeno/src/utils/log.cpp index 705efd62b7..12bf11179e 100644 --- a/zeno/src/utils/log.cpp +++ b/zeno/src/utils/log.cpp @@ -34,14 +34,17 @@ ZENO_API void __impl_log_print(log_level_t level, source_location const &loc, st //*os << ansiclr::fg[make_array(ansiclr::white, ansiclr::cyan, ansiclr::green, //ansiclr::cyan | ansiclr::light, ansiclr::yellow | ansiclr::light, //ansiclr::red | ansiclr::light)[linlev]]; - *os << format("[{} {02d}:{02d}:{02d}.{03d}] ({}:{}) {}\n", + auto content = format("[{} {02d}:{02d}:{02d}.{03d}] ({}:{}) {}\n", "TDICWE"[linlev], mss / 1000 / 60 / 60 % 24, mss / 1000 / 60 % 60, mss / 1000 % 60, mss % 1000, loc.file_name(), loc.line(), msg); //*os << ansiclr::reset; + *os << content; os->flush(); + if (level == log_level_t::error) + std::cerr << content; } namespace {