From f0e68d9f7ae6d320759669ef66fde09b91958601 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 11 Apr 2018 20:49:00 +0800 Subject: [PATCH] Change rendered model move button from left to middle --- src/meshgenerator.cpp | 5 ++++- src/meshutil.cpp | 26 +++++++++++++++++--------- src/meshutil.h | 2 +- src/modelwidget.cpp | 4 ++-- src/skeletongraphicswidget.cpp | 4 ++-- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/meshgenerator.cpp b/src/meshgenerator.cpp index 43e3d1a8..a1f76c5b 100644 --- a/src/meshgenerator.cpp +++ b/src/meshgenerator.cpp @@ -274,7 +274,10 @@ void MeshGenerator::process() if (mergedMeshId > 0) mergedMeshId = meshlite_combine_coplanar_faces(meshliteContext, mergedMeshId); if (mergedMeshId > 0) { - int subdivedMeshId = subdivMesh(meshliteContext, mergedMeshId); + int errorCount = 0; + int subdivedMeshId = subdivMesh(meshliteContext, mergedMeshId, &errorCount); + if (errorCount > 0) + broken = true; if (subdivedMeshId > 0) mergedMeshId = subdivedMeshId; else diff --git a/src/meshutil.cpp b/src/meshutil.cpp index 7cfd4458..69a807d2 100644 --- a/src/meshutil.cpp +++ b/src/meshutil.cpp @@ -188,18 +188,26 @@ int mergeMeshs(void *meshliteContext, const std::vector &meshIds) return mergedMeshId; } -int subdivMesh(void *meshliteContext, int meshId) +int subdivMesh(void *meshliteContext, int meshId, int *errorCount) { int triangulatedMeshId = meshlite_triangulate(meshliteContext, meshId); -//#if USE_CGAL == 1 -// CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); -// SimpleMesh *simpleMesh = makeCgalMeshFromMeshlite(meshliteContext, triangulatedMeshId); -// CGAL::Subdivision_method_3::CatmullClark_subdivision(*simpleMesh, CGAL::Polygon_mesh_processing::parameters::number_of_iterations(1)); -// return makeMeshliteMeshFromCgal(meshliteContext, simpleMesh); -//#else if (0 == meshlite_is_triangulated_manifold(meshliteContext, triangulatedMeshId)) { - return 0; +#if USE_CGAL == 1 + CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); + int subdiviedMeshId = 0; + SimpleMesh *simpleMesh = nullptr; + try { + simpleMesh = makeCgalMeshFromMeshlite(meshliteContext, triangulatedMeshId); + CGAL::Subdivision_method_3::CatmullClark_subdivision(*simpleMesh, CGAL::Polygon_mesh_processing::parameters::number_of_iterations(1)); + subdiviedMeshId = makeMeshliteMeshFromCgal(meshliteContext, simpleMesh); + } catch (...) { + if (errorCount) + (*errorCount)++; + } + if (simpleMesh) + delete simpleMesh; + return subdiviedMeshId; +#endif } return meshlite_subdivide(meshliteContext, meshId); -//#endif } diff --git a/src/meshutil.h b/src/meshutil.h index a2cfcd46..b8b207c7 100644 --- a/src/meshutil.h +++ b/src/meshutil.h @@ -4,6 +4,6 @@ int mergeMeshs(void *meshliteContext, const std::vector &meshIds); int unionMeshs(void *meshliteContext, const std::vector &meshIds, int *errorCount=0); -int subdivMesh(void *meshliteContext, int meshId); +int subdivMesh(void *meshliteContext, int meshId, int *errorCount=0); #endif diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index a189b576..8c087f9d 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -183,7 +183,7 @@ void ModelWidget::mousePressEvent(QMouseEvent *event) if (!m_moveStarted && m_graphicsFunctions && m_graphicsFunctions->mousePress(event)) return; m_lastPos = event->pos(); - if (event->button() == Qt::LeftButton) { + if (event->button() == Qt::MidButton) { if (!m_moveStarted) { m_moveStartPos = mapToParent(event->pos()); m_moveStartGeometry = geometry(); @@ -209,7 +209,7 @@ void ModelWidget::mouseMoveEvent(QMouseEvent *event) int dx = event->x() - m_lastPos.x(); int dy = event->y() - m_lastPos.y(); - if (event->buttons() & Qt::LeftButton) { + if (event->buttons() & Qt::MidButton) { if (m_moveStarted) { QRect rect = m_moveStartGeometry; QPoint pos = mapToParent(event->pos()); diff --git a/src/skeletongraphicswidget.cpp b/src/skeletongraphicswidget.cpp index 98e6f269..109b94a4 100644 --- a/src/skeletongraphicswidget.cpp +++ b/src/skeletongraphicswidget.cpp @@ -631,7 +631,7 @@ bool SkeletonGraphicsWidget::mousePress(QMouseEvent *event) return true; } } else if (SkeletonDocumentEditMode::Select == m_document->editMode) { - if (m_mouseEventFromSelf) { + //if (m_mouseEventFromSelf) { bool processed = false; if ((nullptr == m_hoveredNodeItem || m_rangeSelectionSet.find(m_hoveredNodeItem) == m_rangeSelectionSet.end()) && (nullptr == m_hoveredEdgeItem || m_rangeSelectionSet.find(m_hoveredEdgeItem) == m_rangeSelectionSet.end())) { @@ -657,7 +657,7 @@ bool SkeletonGraphicsWidget::mousePress(QMouseEvent *event) if (processed) { return true; } - } + //} } } return false;