Extension plugin (C++)

Hi,

I have difficulties to get a extension plugin (C++) that Avogadro
"displays". I try a simply code which compile with no error, but plugin
manager don’t display it :

================
myextention.h :

#include <avogadro/extension.h>
#include <avogadro/primitivelist.h>
#include

namespace Avogadro {
class MyExtension : public Extension
{
Q_OBJECT
AVOGADRO_EXTENSION(“MyExtension”, tr(“MyExtension”),
tr(“Transform nothing to nothing”))
public:
MyExtension(QObject *parent=0);
virtual ~MyExtension();

  virtual QList<QAction *> actions() const;
  virtual QUndoCommand* performAction(QAction *action, GLWidget

*widget);
virtual QString menuPath(QAction *action) const;

private:
  QList<QAction *> m_actions;

};

class MyExtensionFactory : public QObject, public PluginFactory
{
Q_OBJECT
Q_INTERFACES(Avogadro::PluginFactory)
AVOGADRO_EXTENSION_FACTORY(MyExtension)
};
}

==============
myextension.cpp :

#include “myextension.h”
#include <avogadro/glwidget.h>
#include <avogadro/molecule.h>
#include <avogadro/atom.h>
#include <avogadro/primitivelist.h>

#include <openbabel/mol.h>
#include <openbabel/obiter.h>

#include

using namespace std;
using namespace OpenBabel;

namespace Avogadro {
MyExtension::MyExtension(QObject *parent) : Extension(parent)
{
QAction *action = new QAction(this);
action->setText(tr(“Nothing to nothing”));
m_actions.append(action);

action = new QAction( this );
action->setSeparator(true);
m_actions.append( action );

}

MyExtension::~MyExtension(){}
QList<QAction *> MyExtension::actions() const{return m_actions;}
QString MyExtension::menuPath(QAction *) const{return tr("&Build");}

QUndoCommand* MyExtension::performAction( QAction *, GLWidget *widget )
{
QUndoCommand *undo = 0;
return undo;
}
} // end namespace Avogadro

Q_EXPORT_PLUGIN2(MyExtension, Avogadro::MyExtensionFactory)

===============
CMakeLists.txt :

project(MyExtension)
cmake_minimum_required(VERSION 2.6)
find_package(Avogadro 0.9.4 REQUIRED)

Set up the build environment

set( OpenBabel_DIR “/usr/include/openbabel-2.0/” )
include({Avogadro_USE_FILE}) include_directories({OpenBabel_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

avogadro_plugin(myextension myextension.cpp)

==========
Execute by :

cmake .
make
sudo cp myextension.so /usr/local/lib/avogadro/1_1/extensions

I don’t see where is the problem …

Regards,
Mickaël Gadroy

sudo cp myextension.so /usr/local/lib/avogadro/1_1/extensions

I’ve not found how to solve your problem yet, but you don’t need root actions to install plugin - you can copy it to ~/.avogadro/1_1/plugins/extensions

17.03.10, 23:10, “Mickaël Gadroy” mickael.gadroy@gmail.com:

Hi,

I have difficulties to get a extension plugin (C++) that Avogadro “displays”. I try a simply code which compile with no error, but plugin manager don’t display it :

================
myextention.h :

#include
#include
#include

namespace Avogadro {
class MyExtension : public Extension
{
Q_OBJECT
AVOGADRO_EXTENSION(“MyExtension”, tr(“MyExtension”),
tr(“Transform nothing to nothing”))
public:
MyExtension(QObject *parent=0);
virtual ~MyExtension();

   virtual QList actions() const;
  virtual QUndoCommand* performAction(QAction *action, GLWidget *widget);
   virtual QString menuPath(QAction *action) const;

private:
   QList m_actions;

};

class MyExtensionFactory : public QObject, public PluginFactory
{
Q_OBJECT
Q_INTERFACES(Avogadro::PluginFactory)
AVOGADRO_EXTENSION_FACTORY(MyExtension)
};
}

==============
myextension.cpp :

#include “myextension.h”
#include
#include
#include
#include

#include
#include

#include

using namespace std;
using namespace OpenBabel;

namespace Avogadro {
MyExtension::MyExtension(QObject *parent) : Extension(parent)
{
QAction *action = new QAction(this);
action->setText(tr(“Nothing to nothing”));
m_actions.append(action);

action = new QAction( this );
action->setSeparator(true);
 m_actions.append( action );

}

MyExtension::~MyExtension(){}
QList MyExtension::actions() const{return m_actions;}
QString MyExtension::menuPath(QAction *) const{return tr("&Build");}

QUndoCommand* MyExtension::performAction( QAction *, GLWidget *widget )
{
QUndoCommand *undo = 0;
return undo;
}
} // end namespace Avogadro

Q_EXPORT_PLUGIN2(MyExtension, Avogadro::MyExtensionFactory)

===============
CMakeLists.txt :

project(MyExtension)
cmake_minimum_required(VERSION 2.6)
find_package(Avogadro 0.9.4 REQUIRED)

Set up the build environment

set( OpenBabel_DIR “/usr/include/openbabel-2.0/” )
include({Avogadro_USE_FILE}) include_directories({OpenBabel_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

avogadro_plugin(myextension myextension.cpp)

==========
Execute by :

cmake .
make
sudo cp myextension.so /usr/local/lib/avogadro/1_1/extensions

I don’t see where is the problem …

Regards,
Mickaël Gadroy


Regards,
Konstantin

Яндекс.Почта. Письма есть. Спама - нет. http://mail.yandex.ru/nospam/sign

Is moc-file generated on build? With CMake you probably need to #include it explicitly in myextension.cpp file

17.03.10, 23:10, “Mickaël Gadroy” mickael.gadroy@gmail.com:

Hi,

I have difficulties to get a extension plugin (C++) that Avogadro “displays”. I try a simply code which compile with no error, but plugin manager don’t display it :

================
myextention.h :

#include
#include
#include

namespace Avogadro {
class MyExtension : public Extension
{
Q_OBJECT
AVOGADRO_EXTENSION(“MyExtension”, tr(“MyExtension”),
tr(“Transform nothing to nothing”))
public:
MyExtension(QObject *parent=0);
virtual ~MyExtension();

   virtual QList actions() const;
  virtual QUndoCommand* performAction(QAction *action, GLWidget *widget);
   virtual QString menuPath(QAction *action) const;

private:
   QList m_actions;

};

class MyExtensionFactory : public QObject, public PluginFactory
{
Q_OBJECT
Q_INTERFACES(Avogadro::PluginFactory)
AVOGADRO_EXTENSION_FACTORY(MyExtension)
};
}

==============
myextension.cpp :

#include “myextension.h”
#include
#include
#include
#include

#include
#include

#include

using namespace std;
using namespace OpenBabel;

namespace Avogadro {
MyExtension::MyExtension(QObject *parent) : Extension(parent)
{
QAction *action = new QAction(this);
action->setText(tr(“Nothing to nothing”));
m_actions.append(action);

action = new QAction( this );
action->setSeparator(true);
 m_actions.append( action );

}

MyExtension::~MyExtension(){}
QList MyExtension::actions() const{return m_actions;}
QString MyExtension::menuPath(QAction *) const{return tr("&Build");}

QUndoCommand* MyExtension::performAction( QAction *, GLWidget *widget )
{
QUndoCommand *undo = 0;
return undo;
}
} // end namespace Avogadro

Q_EXPORT_PLUGIN2(MyExtension, Avogadro::MyExtensionFactory)

===============
CMakeLists.txt :

project(MyExtension)
cmake_minimum_required(VERSION 2.6)
find_package(Avogadro 0.9.4 REQUIRED)

Set up the build environment

set( OpenBabel_DIR “/usr/include/openbabel-2.0/” )
include({Avogadro_USE_FILE}) include_directories({OpenBabel_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

avogadro_plugin(myextension myextension.cpp)

==========
Execute by :

cmake .
make
sudo cp myextension.so /usr/local/lib/avogadro/1_1/extensions

I don’t see where is the problem …

Regards,
Mickaël Gadroy


Regards,
Konstantin

Яндекс.Почта. Письма есть. Спама - нет. http://mail.yandex.ru/nospam/sign

Actually, I just added : #include"myextension.moc", in myextension.cpp,
before Q_EXPORT_PLUGIN2(MyExtension, Avogadro::MyExtensionFactory) .

Thanks.