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

Allow more render plugins to be "layer enabled" #1008

Merged
merged 3 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion avogadro/qtgui/layermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "molecule.h"
#include "rwmolecule.h"

#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtGui/QColor>
#include <QtGui/QIcon>
Expand Down Expand Up @@ -121,26 +122,37 @@ const QString LayerModel::getTranslatedName(const std::string& name) const
{
// This is a bad hack, but whatever..
// Put all the strings that show up as layer options

if (name == "Ball and Stick")
return tr("Ball and Stick");
else if (name == "Cartoons")
return tr("Cartoons", "protein ribbon / cartoon rendering");
else if (name == "Close Contacts")
return tr("Close Contacts", "rendering of non-covalent close contacts");
else if (name == "Crystal Lattice")
return tr("Crystal Lattice");
else if (name == "Force")
return tr("Force");
else if (name == "Labels")
return tr("Labels");
else if (name == "Licorice")
return tr("Licorice", "stick / licorice rendering");
else if (name == "Meshes")
return tr("Meshes");
else if (name == "Non-Covalent")
return tr("Non-Covalent");
else if (name == "Symmetry Elements")
return tr("Symmetry Elements");
else if (name == "Van der Waals")
return tr("Van der Waals");
else if (name == "Van der Waals (AO)")
return tr("Van der Waals (AO)", "ambient occlusion");
else if (name == "Wireframe")
return tr("Wireframe");

return QString();
qDebug() << "LayerModel: name didn't match: " << name.c_str();

return QString(name.c_str());
}

QModelIndex LayerModel::index(int row, int column, const QModelIndex& p) const
Expand Down
19 changes: 3 additions & 16 deletions avogadro/qtplugins/crystal/crystalscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ using Rendering::GroupNode;
using Rendering::LineStripGeometry;

CrystalScene::CrystalScene(QObject* p)
: ScenePlugin(p), m_enabled(true), m_setupWidget(nullptr)
: ScenePlugin(p), m_setupWidget(nullptr)
{
m_layerManager = QtGui::PluginLayerManager(m_name);

QSettings settings;
m_lineWidth = settings.value("crystal/lineWidth", 2.0).toDouble();

Expand Down Expand Up @@ -93,21 +95,6 @@ void CrystalScene::process(const QtGui::Molecule& molecule, GroupNode& node)
}
}

bool CrystalScene::isEnabled() const
{
return m_enabled;
}

bool CrystalScene::isActiveLayerEnabled() const
{
return m_enabled;
}

void CrystalScene::setEnabled(bool enable)
{
m_enabled = enable;
}

void CrystalScene::setLineWidth(double width)
{
m_lineWidth = width;
Expand Down
8 changes: 1 addition & 7 deletions avogadro/qtplugins/crystal/crystalscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,14 @@ class CrystalScene : public QtGui::ScenePlugin
return tr("Render the unit cell boundaries.");
}

bool isEnabled() const override;

bool isActiveLayerEnabled() const override;

void setEnabled(bool enable) override;

QWidget* setupWidget() override;

private slots:
void setColor(const QColor &color);
void setLineWidth(double width);

private:
bool m_enabled;
std::string m_name = "Crystal Lattice";

QWidget* m_setupWidget;
float m_lineWidth;
Expand Down
24 changes: 8 additions & 16 deletions avogadro/qtplugins/force/force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ using Rendering::ArrowGeometry;
using Rendering::GeometryNode;
using Rendering::GroupNode;

Force::Force(QObject* p) : ScenePlugin(p), m_enabled(false) {}
Force::Force(QObject* p) : ScenePlugin(p)
{
m_layerManager = QtGui::PluginLayerManager(m_name);
}

Force::~Force() {}

Expand All @@ -38,25 +41,14 @@ void Force::process(const QtGui::Molecule& molecule, Rendering::GroupNode& node)
arrows->identifier().molecule = &molecule;
geometry->addDrawable(arrows);
for (Index i = 0; i < molecule.atomCount(); ++i) {
if (!m_layerManager.atomEnabled(i))
continue; // ignore hidden atoms

Core::Atom atom1 = molecule.atom(i);
Vector3f pos1 = atom1.position3d().cast<float>();
Vector3f forceVector = atom1.forceVector().cast<float>();
arrows->addSingleArrow(pos1, pos1 + forceVector);
}
}

bool Force::isEnabled() const
{
return m_enabled;
}

bool Force::isActiveLayerEnabled() const
{
return m_enabled;
}

void Force::setEnabled(bool enable)
{
m_enabled = enable;
}
} // namespace Avogadro
} // namespace Avogadro::QtPlugins
11 changes: 5 additions & 6 deletions avogadro/qtplugins/force/force.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ class Force : public QtGui::ScenePlugin
"Render the force field visualizations for the atoms of the molecule.");
}

bool isEnabled() const override;

bool isActiveLayerEnabled() const override;

void setEnabled(bool enable) override;
DefaultBehavior defaultBehavior() const override
{
return DefaultBehavior::False;
}

private:
bool m_enabled;
std::string m_name = "Force";
};

} // end namespace QtPlugins
Expand Down
19 changes: 3 additions & 16 deletions avogadro/qtplugins/meshes/meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ using Rendering::GeometryNode;
using Rendering::GroupNode;
using Rendering::MeshGeometry;

Meshes::Meshes(QObject* p) : ScenePlugin(p), m_enabled(true), m_setupWidget(nullptr)
Meshes::Meshes(QObject* p) : ScenePlugin(p), m_setupWidget(nullptr)
{
m_layerManager = QtGui::PluginLayerManager(m_name);

QSettings settings;
// out of 255
m_opacity = settings.value("meshes/opacity", 150).toUInt();
Expand Down Expand Up @@ -104,21 +106,6 @@ void Meshes::process(const QtGui::Molecule& mol, GroupNode& node)
}
}

bool Meshes::isEnabled() const
{
return m_enabled;
}

bool Meshes::isActiveLayerEnabled() const
{
return m_enabled;
}

void Meshes::setEnabled(bool enable)
{
m_enabled = enable;
}

void Meshes::setOpacity(int opacity)
{
m_opacity = opacity;
Expand Down
20 changes: 9 additions & 11 deletions avogadro/qtplugins/meshes/meshes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,26 @@ class Meshes : public QtGui::ScenePlugin
explicit Meshes(QObject* parent = nullptr);
~Meshes() override;

void process(const QtGui::Molecule& mol,
Rendering::GroupNode& node) override;
void process(const QtGui::Molecule& mol, Rendering::GroupNode& node) override;

QString name() const override { return tr("Meshes"); }

QString description() const override { return tr("Render polygon meshes."); }

bool isEnabled() const override;

bool isActiveLayerEnabled() const override;

void setEnabled(bool enable) override;

QWidget* setupWidget() override;

DefaultBehavior defaultBehavior() const override
{
return DefaultBehavior::False;
}

private slots:
void setColor1(const QColor &color);
void setColor2(const QColor &color);
void setColor1(const QColor& color);
void setColor2(const QColor& color);
void setOpacity(int opacity);

private:
bool m_enabled;
std::string m_name = "Meshes";

QWidget* m_setupWidget;
unsigned char m_opacity;
Expand Down