Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Resetview Option Feature #1668

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions avogadro/io/pdbformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 22 additions & 10 deletions avogadro/qtgui/multiviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -238,6 +250,6 @@ void MultiViewWidget::splitView(Qt::Orientation orient,
}
}

} // End Avogadro namespace
} // namespace Avogadro::QtGui

#include "multiviewwidget.moc"
6 changes: 4 additions & 2 deletions avogadro/qtgui/multiviewwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContainerWidget*> m_children;
Expand All @@ -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
8 changes: 8 additions & 0 deletions avogadro/qtopengl/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QtGui::ToolPlugin*>& toolList)
{
Expand Down
10 changes: 7 additions & 3 deletions avogadro/qtopengl/glwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <avogadro/qtgui/toolplugin.h>
#include <avogadro/rendering/glrenderer.h>

#include <QPointer>
#include <QOpenGLWidget>
#include <QPointer>

class QTimer;

Expand Down Expand Up @@ -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<QtGui::ToolPlugin*>& toolList);

/**
Expand Down Expand Up @@ -196,7 +200,7 @@ protected slots:
QTimer* m_renderTimer;
};

} // End QtOpenGL namespace
} // End Avogadro namespace
} // namespace QtOpenGL
} // namespace Avogadro

#endif // AVOGADRO_QTOPENGL_GLWIDGET_H