diff --git a/avogadro/io/pdbformat.cpp b/avogadro/io/pdbformat.cpp index db6ec85bcb..c3a2c8ff02 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) { diff --git a/avogadro/qtgui/multiviewwidget.cpp b/avogadro/qtgui/multiviewwidget.cpp index 25f283951e..bbc588d321 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 f0714c221d..7375823711 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 3dcee7a3cc..f1b3683372 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 be600aaba5..e28c5f1fe8 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