From 7d9b464016d3a102e023be917b398144d26d8352 Mon Sep 17 00:00:00 2001 From: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> Date: Sat, 30 Mar 2024 10:01:33 +0530 Subject: [PATCH 1/2] transfer Signed-off-by: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> --- avogadro/io/pdbformat.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/avogadro/io/pdbformat.cpp b/avogadro/io/pdbformat.cpp index db6ec85bc..c3a2c8ff0 100644 --- a/avogadro/io/pdbformat.cpp +++ b/avogadro/io/pdbformat.cpp @@ -58,14 +58,12 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol) while (getline(in, buffer)) { // Read Each line one by one - if (startsWith(buffer, "ENDMDL")) { - if (coordSet == 0) { - mol.setCoordinate3d(mol.atomPositions3d(), coordSet++); - positions.reserve(mol.atomCount()); - } else { - mol.setCoordinate3d(positions, coordSet++); - positions.clear(); - } + if (startsWith(buffer, "ENDMDL")) { + // Ensure positions array is not empty before creating a new frame + if (!positions.empty()) { + mol.setCoordinate3d(positions, coordSet++); + positions.clear(); // Clear positions after adding them as a frame + } } // e.g. CRYST1 4.912 4.912 6.696 90.00 90.00 120.00 P1 1 @@ -245,7 +243,10 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol) } } } // End while loop - +if (!positions.empty()) { + // This handles the last set of positions if the file doesn't end with ENDMDL + mol.setCoordinate3d(positions, coordSet); +} int count = mol.coordinate3dCount() ? mol.coordinate3dCount() : 1; for (int c = 0; c < count; ++c) { for (char l : altLocs) { From 92d3aa2ba020a8267965f003ab044101d7ba2156 Mon Sep 17 00:00:00 2001 From: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:19:22 +0530 Subject: [PATCH 2/2] resetview Signed-off-by: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> --- avogadro/qtgui/multiviewwidget.cpp | 32 ++++++++++++++++++++---------- avogadro/qtgui/multiviewwidget.h | 6 ++++-- avogadro/qtopengl/glwidget.cpp | 8 ++++++++ avogadro/qtopengl/glwidget.h | 10 +++++++--- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/avogadro/qtgui/multiviewwidget.cpp b/avogadro/qtgui/multiviewwidget.cpp index 25f283951..bbc588d32 100644 --- a/avogadro/qtgui/multiviewwidget.cpp +++ b/avogadro/qtgui/multiviewwidget.cpp @@ -21,10 +21,7 @@ class ActiveWidgetFilter : public QObject Q_OBJECT public: - ActiveWidgetFilter(MultiViewWidget* p = nullptr) - : QObject(p) - , m_widget(p) - {} + ActiveWidgetFilter(MultiViewWidget* p = nullptr) : QObject(p), m_widget(p) {} signals: void activeWidget(QWidget* widget); @@ -46,11 +43,10 @@ class ActiveWidgetFilter : public QObject }; MultiViewWidget::MultiViewWidget(QWidget* p, Qt::WindowFlags f) - : QWidget(p, f) - , m_factory(nullptr) - , m_activeWidget(nullptr) - , m_activeFilter(new ActiveWidgetFilter(this)) -{} + : QWidget(p, f), m_factory(nullptr), m_activeWidget(nullptr), + m_activeFilter(new ActiveWidgetFilter(this)) +{ +} MultiViewWidget::~MultiViewWidget() {} @@ -168,6 +164,22 @@ void MultiViewWidget::removeView() } } } +void MultiViewWidget::removeView() +{ + // Existing code for removeView... +} + +void MultiViewWidget::resetAllViews() +{ + + foreach (ContainerWidget* container, m_children) { + QWidget* viewWidget = container->viewWidget(); + if (viewWidget) { + + QMetaObject::invokeMethod(viewWidget, "resetView", Qt::DirectConnection); + } + } +} ContainerWidget* MultiViewWidget::createContainer(QWidget* widget) { @@ -238,6 +250,6 @@ void MultiViewWidget::splitView(Qt::Orientation orient, } } -} // End Avogadro namespace +} // namespace Avogadro::QtGui #include "multiviewwidget.moc" diff --git a/avogadro/qtgui/multiviewwidget.h b/avogadro/qtgui/multiviewwidget.h index f0714c221..737582371 100644 --- a/avogadro/qtgui/multiviewwidget.h +++ b/avogadro/qtgui/multiviewwidget.h @@ -54,6 +54,8 @@ public slots: void splitVertical(); void createView(); void removeView(); + /** New method to reset all views to their default settings. */ + void resetAllViews(); // New slot added for resetting all views private: QList m_children; @@ -67,7 +69,7 @@ public slots: void splitView(Qt::Orientation orient, ContainerWidget* container); }; -} // End QtGui namespace -} // End Avogadro namespace +} // namespace QtGui +} // namespace Avogadro #endif // AVOGADRO_QTGUI_MULTIVIEWWIDGET_H diff --git a/avogadro/qtopengl/glwidget.cpp b/avogadro/qtopengl/glwidget.cpp index 3dcee7a3c..f1b368337 100644 --- a/avogadro/qtopengl/glwidget.cpp +++ b/avogadro/qtopengl/glwidget.cpp @@ -112,6 +112,14 @@ void GLWidget::resetGeometry() { m_renderer.resetGeometry(); } +void GLWidget::resetViewSettings() +{ + // Reset the camera to a default view + m_renderer.resetCamera(); + + // Additional default resets can be added here if needed + update(); // +} void GLWidget::setTools(const QList& toolList) { diff --git a/avogadro/qtopengl/glwidget.h b/avogadro/qtopengl/glwidget.h index be600aaba..e28c5f1fe 100644 --- a/avogadro/qtopengl/glwidget.h +++ b/avogadro/qtopengl/glwidget.h @@ -12,8 +12,8 @@ #include #include -#include #include +#include class QTimer; @@ -126,6 +126,10 @@ public slots: * Make the tools in toolList available to the GLWidget. The GLWidget takes * ownership of the tools. */ + + /** New method to reset the camera and other view settings to default. */ + void resetViewSettings(); // New slot added for resetting view settings + void setTools(const QList& toolList); /** @@ -196,7 +200,7 @@ protected slots: QTimer* m_renderTimer; }; -} // End QtOpenGL namespace -} // End Avogadro namespace +} // namespace QtOpenGL +} // namespace Avogadro #endif // AVOGADRO_QTOPENGL_GLWIDGET_H