On Fri, Jul 8, 2011 at 11:07 AM, Rodolf Meyer rodolf.meyer@gmail.com wrote:
Hi all,
I’m currently working on an Avogadro extension. It should be able to control
most of the Avogadro functionnalities (camera, open file, copy/paste, select
a tool, add hydrogen, …) with an external controller.
I found the Navigate class to use the camera, and it is ok. But for some
other points, I need help:
I think I can call every other functionnalities by using the MainWindow
instance, am I correct?
I tried to get the MainWindow instance by QObject_casting the parent() of
the extension in a loop in the constructor. The QObject_cast
works, but the casting in MainWindow fails.
if (!m_mainwindow) {
QObject mainwindow = this;
while (mainwindow && !qobject_cast<MainWindow>(mainwindow)) {
mainwindow = qobject_cast<QWidget*>(mainwindow->parent());
}
m_mainwindow = qobject_cast<MainWindow*>(mainwindow);
}
I’ve used this method to get the QMainWindow object in the
crystallography extension, but only to get access to the dockwidget
methods, which are implemented in QMainWindow (not
Avogadro::MainWindow). I do not think what you are trying to do is
possible (at least not in a reliable way) since the
Avogadro::MainWindow class is not available to extensions, as it is
not in libavogadro and its headers are not installed.
However, some of the functionality you want is possible in other ways:
Files can be opened by using Avogadro::MoleculeFile to create a
Molecule instance, which can be loaded in the main window by emitting
the moleculeChanged(Molecule*) signal from your extensions.
Copy/paste can be implemented in an extension by modifying/reading the
molecule that is passed to the extension in the
Avogadro::Extension::setMolecule slot and using QClipboard and
associated classes.
AFAIK, tool selection is not possible from within an extension, though
it certainly would be useful!
“Add hydrogen” and most other molecule modification can be performed
by handling the setMolecule virtual function to store the pointer to
the current molecule, and then modifying it. Calling
Molecule::update() when you’re done modifying the molecule will force
the GL widgets that are drawing the molecule to refresh.
Hope this helps,
Dave
The error is :
In function Avogadro::MainWindow* qobject_cast<Avogadro::MainWindow*>(QObject*)': /usr/include/qt4/QtCore/qobject.h:366: undefined reference to
Avogadro::MainWindow::staticMetaObject’
MainWindow is a QObject, I don’t understand why the QObject_cast doesn’t
work.
Do you know why? (or maybe you know a better idea to resolve my problem)
Regards,
RM
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options