Commit 0b82a51e authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Finish Avogadro porting of molecule view.

Still missing:
- update of view after loading
- editor tools
- labels
parent 1a67cb21
......@@ -19,6 +19,7 @@
#include <avogadro/rendering/primitive.h>
#include <avogadro/qtplugins/pluginmanager.h>
#include <avogadro/qtgui/molecule.h>
#include <avogadro/qtgui/sceneplugin.h>
// #include <avogadro/toolgroup.h>//FIXME:Avogadro2 port away from toolgroup
#include <QWidget>
#include "iowrapper.h"
......@@ -49,15 +50,21 @@ KalziumGLWidget::KalziumGLWidget(QWidget *parent)
}
Avogadro::QtPlugins::PluginManager *manager = Avogadro::QtPlugins::PluginManager::instance();
manager->load();
QList<Avogadro::QtGui::ScenePluginFactory*> scenePluginFactories =
manager->pluginFactories<Avogadro::QtGui::ScenePluginFactory>();
foreach (auto *factory, scenePluginFactories) {
auto *scenePlugin = factory->createInstance();
// enable Ball-and-Sticks
if (scenePlugin->objectName() == "BallStick") {
scenePlugin->setEnabled(true);
}
sceneModel().addItem(scenePlugin);
}
// Avogadro::ToolGroup* tools = new Avogadro::ToolGroup(this);//FIXME:Avogadro2 port away from ToolGroup
// tools->append(manager->tools(this));
// tools->setActiveTool("Navigate");
// setToolGroup(tools);
// Set the default engine to be active
// loadDefaultEngines();//FIXME:Avogadro2 port away from engine.h
// Set the default quality level to high
setQuality(2);
setMolecule(new Avogadro::QtGui::Molecule(this));
update();
......@@ -86,46 +93,6 @@ bool KalziumGLWidget::openFile(const QString &file)
return true;
}
void KalziumGLWidget::setStyle(int style)
{
//FIXME:Avogadro2
// foreach (Avogadro::Engine *engine, engines()) {
// if ((m_lastEngine1 == 0 && engine->identifier() == "Ball and Stick")
// || (m_lastEngine1 == 1 && engine->identifier() == "Stick")
// || (m_lastEngine1 == 2 && engine->identifier() == "Van der Waals Spheres")
// || (m_lastEngine1 == 3 && engine->identifier() == "Wireframe")) {
// engine->setEnabled(false);
// }
// if ((style == 0 && engine->identifier() == "Ball and Stick")
// || (style == 1 && engine->identifier() == "Stick")
// || (style == 2 && engine->identifier() == "Van der Waals Spheres")
// || (style == 3 && engine->identifier() == "Wireframe")) {
// engine->setEnabled(true);
// }
// }
m_lastEngine1 = style;
update();
}
void KalziumGLWidget::setStyle2(int style)
{
//FIXME:Avogadro2
// foreach (Avogadro::Engine *engine, engines()) {
// if ((m_lastEngine2 == 1 && engine->identifier() == "Ribbon")
// || (m_lastEngine2 == 2 && engine->identifier() == "Ring")
// || (m_lastEngine2 == 3 && engine->identifier() == "Orbitals")) {
// engine->setEnabled(false);
// }
// if ((style == 1 && engine->identifier() == "Ribbon")
// || (style == 2 && engine->identifier() == "Ring")
// || (style == 3 && engine->identifier() == "Orbitals")) {
// engine->setEnabled(true);
// }
// }
m_lastEngine2 = style;
update();
}
void KalziumGLWidget::setLabels(int style)
{
//FIXME:Avogadro2
......@@ -159,17 +126,3 @@ void KalziumGLWidget::setLabels(int style)
// }
// }
}
void KalziumGLWidget::setQuality(int quality)
{
// Set the global quality of the GLWidget, 0=min, 2=mid, 4=max
int q = 0;
if (quality == 1) {
q = 2;
} else if (quality == 2) {
q = 4;
}
// GLWidget::setQuality(q);//FIXME:Avogadro2
// invalidateDLs();//FIXME:Avogadro2
GLWidget::update();
}
......@@ -14,23 +14,18 @@
#ifndef KALZIUMGLWIDGET_H
#define KALZIUMGLWIDGET_H
#include <QtWidgets>
#include <QtOpenGL>
#include <QOpenGLWidget>
#include <avogadro/qtopengl/glwidget.h>
class Q_DECL_EXPORT KalziumGLWidget : public Avogadro::QtOpenGL::GLWidget
{
Q_OBJECT
public:
KalziumGLWidget(QWidget *parent = 0);
KalziumGLWidget(QWidget *parent = nullptr);
virtual ~KalziumGLWidget();
public slots:
void setStyle(int style);
void setStyle2(int style);
void setLabels(int style);
void setQuality(int quality);
bool openFile(const QString &file);
protected:
......
/***************************************************************************
* Copyright (C) 2006 by Carsten Niehaus <cniehaus@kde.org>
* Copyright (C) 2007-2008 by Marcus D. Hanwell <marcus@cryos.org>
* Copyright (C) 2016 by Andreas Cord-Landwehr <cordlandwehr@kde.org>
***************************************************************************/
/***************************************************************************
......@@ -18,6 +19,7 @@
#include <avogadro/qtgui/elementtranslator.h>
#include <avogadro/qtgui/periodictableview.h>
#include <avogadro/qtgui/molecule.h>
#include <avogadro/qtgui/scenepluginmodel.h>
// #include <avogadro/qtplugins/openbabel/openbabel.h>FIXME:Avogadro2
#include <QFileInfo>
......@@ -47,9 +49,11 @@ using namespace OpenBabel;
using namespace Avogadro::QtGui;
MoleculeDialog::MoleculeDialog(QWidget * parent)
: KDialog(parent), m_periodicTable(0), m_addHydrogens(false)
: KDialog(parent)
, m_path(QString())
, m_periodicTable(nullptr)
, m_addHydrogens(false)
{
// use multi-sample (anti-aliased) OpenGL if available
QGLFormat defFormat = QGLFormat::defaultFormat();
defFormat.setSampleBuffers(true);
......@@ -68,18 +72,10 @@ MoleculeDialog::MoleculeDialog(QWidget * parent)
ui.setupUi(mainWidget());
ui.qualityCombo->setCurrentIndex(2); //default to high quality
//default to atom symbols
ui.labelsCombo->setCurrentIndex(1);
ui.glWidget->setLabels(1);
//default to balls-and-sticks
ui.styleCombo->setCurrentIndex(0);
ui.glWidget->setStyle(0);
m_path = QString("");
// Attempt to set up the UFF forcefield
m_forceField = OBForceField::FindForceField("UFF");
if (!m_forceField) {
......@@ -97,16 +93,12 @@ MoleculeDialog::MoleculeDialog(QWidget * parent)
m_drawSettings->setValue("bondOrder", 1);
m_drawSettings->setValue("addHydrogens", 0);
ui.styleCombo->setModel(
qobject_cast<QAbstractItemModel*>(&ui.glWidget->sceneModel()));
connect(ui.tabWidget, SIGNAL(currentChanged(int)),
this, SLOT(setViewEdit(int)));
// Visualization parameters
connect(ui.qualityCombo, SIGNAL(activated(int)),
ui.glWidget, SLOT(setQuality(int)));
connect(ui.styleCombo, SIGNAL(activated(int)),
ui.glWidget, SLOT(setStyle(int)));
connect(ui.style2Combo, SIGNAL(activated(int)),
ui.glWidget, SLOT(setStyle2(int)));
connect(ui.labelsCombo, SIGNAL(activated(int)),
ui.glWidget, SLOT(setLabels(int)));
......@@ -124,8 +116,8 @@ MoleculeDialog::MoleculeDialog(QWidget * parent)
connect(ui.clearDrawingButton, SIGNAL(clicked()),
this, SLOT(clearAllElementsInEditor()));
connect(ui.glWidget->molecule(), SIGNAL(updated()),
this, SLOT(slotUpdateStatistics()));
connect(ui.glWidget->molecule(), &Avogadro::QtGui::Molecule::changed,
this, &MoleculeDialog::slotUpdateStatistics);
connect(this, SIGNAL(user1Clicked()),
this, SLOT(slotLoadMolecule()));
......@@ -135,17 +127,10 @@ MoleculeDialog::MoleculeDialog(QWidget * parent)
this, SLOT(slotSaveMolecule()));
// Check that we have managed to load up some tools and engines
// int nEngines = ui.glWidget->engines().size() - 1;//FIXME:Avogadro2
// int nTools = ui.glWidget->toolGroup()->tools().size();//FIXME:Avogadro2
QString error;
// if (!nEngines && !nTools) {//FIXME:Avogadro2
// error = i18n("No tools or engines loaded - it is likely that the Avogadro plugins could not be located.");
// } else if (!nEngines) {
// error = i18n("No engines loaded - it is likely that the Avogadro plugins could not be located.");
// } else if (!nTools) {
// if (!nTools) {
// error = i18n("No tools loaded - it is likely that the Avogadro plugins could not be located.");
// }
// if (!nEngines || !nTools) {
// KMessageBox::error(this, error, i18n("Kalzium"));
// }
}
......@@ -153,17 +138,11 @@ MoleculeDialog::MoleculeDialog(QWidget * parent)
void MoleculeDialog::slotLoadMolecule()
{
// Check that we have managed to load up some tools and engines
// int nEngines = ui.glWidget->engines().size() - 1;//FIXME:Avogadro2
// int nTools = ui.glWidget->toolGroup()->tools().size();//FIXME:Avogadro2
// QString error;
// if (!nEngines && !nTools) {//FIXME:Avogadro2
// error = i18n("No tools or engines loaded - it is likely that the Avogadro plugins could not be located. No molecules can be viewed until this issue is resolved.");
// } else if (!nEngines) {
// error = i18n("No engines loaded - it is likely that the Avogadro plugins could not be located. No molecules can be viewed until this issue is resolved.");
// } else if (!nTools) {
// if (!nTools) {
// error = i18n("No tools loaded - it is likely that the Avogadro plugins could not be located. No molecules can be viewed until this issue is resolved.");
// }
// if (!nEngines || !nTools) {
// KMessageBox::information(this, error);
// }
......@@ -196,32 +175,31 @@ void MoleculeDialog::loadMolecule(const QString &filename)
auto tmpMol = IoWrapper::readMolecule(filename);
auto molecule = new Avogadro::QtGui::Molecule(*tmpMol);
if (tmpMol) {
delete tmpMol;
}
delete tmpMol;
// Check that a valid molecule object was returned
if (!molecule) {
qCritical() << "Could not load molecule, aborting.";
return;
}
//FIXME:Avogadro2
// if (molecule->numAtoms() != 0) {
// disconnect(ui.glWidget->molecule(), 0, this, 0);
// molecule->center();
// ui.glWidget->setMolecule(molecule);
// ui.glWidget->update();
// slotUpdateStatistics();
// connect(molecule, SIGNAL(updated()), this, SLOT(slotUpdateStatistics()));
// }
// ui.glWidget->invalidateDLs();
if (molecule->atomCount() != 0) {
disconnect(ui.glWidget->molecule(), 0, this, 0);
ui.glWidget->setMolecule(molecule);
ui.glWidget->update();
slotUpdateStatistics();
connect(molecule, &Avogadro::QtGui::Molecule::changed,
this, &MoleculeDialog::slotUpdateStatistics);
}
ui.glWidget->resetCamera();
ui.glWidget->update();
}
void MoleculeDialog::clearAllElementsInEditor()
{
//FIXME:Avogadro2
// ui.glWidget->molecule()->clear();
// ui.glWidget->update();
ui.glWidget->molecule()->clearBonds();
ui.glWidget->molecule()->clearAtoms();
ui.glWidget->update();
}
void MoleculeDialog::slotSaveMolecule()
......@@ -271,11 +249,11 @@ void MoleculeDialog::slotUpdateStatistics()
if (!mol) {
return;
}
//FIXME:Avogadro2
// ui.nameLabel->setText(mol->OBMol().GetTitle());
// ui.weightLabel->setText(i18nc("This 'u' stands for the chemical unit (u for 'units'). Most likely this does not need to be translated at all!", "%1 u", mol->OBMol().GetMolWt()));
// ui.formulaLabel->setText(openBabel.getPrettyFormula(mol));
// ui.glWidget->update();
const std::string name = mol->data(QString("name").toStdString()).toString();
ui.nameLabel->setText(QString::fromStdString(name));
ui.weightLabel->setText(i18nc("This 'u' stands for the chemical unit (u for 'units'). Most likely this does not need to be translated at all!", "%1 u", mol->mass()));
ui.formulaLabel->setText(IoWrapper::getPrettyFormula(mol));
ui.glWidget->update();
}
void MoleculeDialog::slotDownloadNewStuff()
......
......@@ -30,55 +30,6 @@
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Quality:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>qualityCombo</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="KComboBox" name="qualityCombo">
<item>
<property name="text">
<string>Low</string>
</property>
</item>
<item>
<property name="text">
<string>Medium</string>
</property>
</item>
<item>
<property name="text">
<string>High</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Style:</string>
......@@ -91,85 +42,10 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="KComboBox" name="styleCombo">
<item>
<property name="text">
<string>Balls and sticks</string>
</property>
</item>
<item>
<property name="text">
<string>Sticks</string>
</property>
</item>
<item>
<property name="text">
<string>Van der Waals</string>
</property>
</item>
<item>
<property name="text">
<string>Wireframe</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>2nd Style:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>styleCombo</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="KComboBox" name="style2Combo">
<item>
<property name="text">
<string comment="No 2nd Style">None</string>
</property>
</item>
<item>
<property name="text">
<string>Ribbon</string>
</property>
</item>
<item>
<property name="text">
<string>Ring</string>
</property>
</item>
<item>
<property name="text">
<string>Molecular Orbital</string>
</property>
</item>
</widget>
<widget class="KComboBox" name="styleCombo"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
......@@ -186,7 +62,7 @@
</item>
</layout>
</item>
<item row="3" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Labels:</string>
......@@ -199,7 +75,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="KComboBox" name="labelsCombo">
......@@ -267,9 +143,6 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>qualityCombo</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
......@@ -300,9 +173,6 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>qualityCombo</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
......@@ -535,7 +405,6 @@
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>qualityCombo</tabstop>
<tabstop>styleCombo</tabstop>
<tabstop>labelsCombo</tabstop>
<tabstop>elementCombo</tabstop>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment