-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added io_test plugin example (simple xyz).
- Loading branch information
1 parent
76b5e52
commit db15146
Showing
7 changed files
with
370 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Meta-Objects | ||
set(xyztest_MOC_HDRS | ||
xyztest.h | ||
) | ||
QT5_WRAP_CPP(xyztest_MOC_SRCS ${xyztest_MOC_HDRS} OPTIONS -I${PROJECT_SOURCE_DIR}/src) | ||
|
||
add_library(xyztest MODULE | ||
xyztest_funcs.cpp | ||
${xyztest_MOC_SRCS} | ||
) | ||
set_target_properties(xyztest PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${Aten_BINARY_DIR}/data/plugins | ||
COMPILE_DEFINITIONS "QT_PLUGIN" | ||
PREFIX "" | ||
) | ||
|
||
if(UNIX AND NOT APPLE) | ||
install(TARGETS xyztest | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/aten/plugins COMPONENT RuntimePlugins | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/aten/plugins COMPONENT RuntimePlugins | ||
) | ||
endif(UNIX AND NOT APPLE) | ||
|
||
target_include_directories(xyztest PRIVATE | ||
${PROJECT_SOURCE_DIR}/src | ||
${PROJECT_BINARY_DIR}/src | ||
${Qt5Core_INCLUDE_DIRS} | ||
${Qt5Gui_INCLUDE_DIRS} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
pluginexecdir = ${pkglibdir}/plugins | ||
pluginexec_LTLIBRARIES = xyztest.la | ||
|
||
# Rules | ||
.hui.lo: | ||
${QTMOC} -o $*.cpp -I../../ @ATEN_INCLUDES@ $< | ||
${LIBTOOL} --tag=CXX --mode=compile $(CXX) -I$(top_srcdir)/src -I../ -I./ ${AM_CPPFLAGS} -c $*.cpp -o $@ | ||
rm $*.cpp | ||
|
||
clean-local: | ||
-rm -f xyztest.cpp | ||
|
||
xyztest_la_SOURCES = xyztest.hui xyztest_funcs.cpp | ||
xyztest_la_LDFLAGS = -module -shared -avoid-version | ||
|
||
AM_CPPFLAGS = -I${top_srcdir}/src @ATEN_INCLUDES@ @ATEN_CFLAGS@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
*** Simple XYZ Plugin | ||
*** src/plugins/io_test/xyztest.hui | ||
Copyright T. Youngs 2016-2016 | ||
|
||
This file is part of Aten. | ||
|
||
Aten is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
Aten is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with Aten. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef ATEN_TESTXYZPLUGIN_H | ||
#define ATEN_TESTXYZPLUGIN_H | ||
|
||
#include "plugins/interfaces/fileplugin.h" | ||
|
||
ATEN_BEGIN_NAMESPACE | ||
|
||
// Forward Declarations | ||
/* none */ | ||
|
||
// XYZ Model Import / Export Plugin | ||
class TestModelPlugin : public QObject, public FilePluginInterface | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "com.projectaten.Aten.FilePluginInterface.v1") | ||
Q_INTERFACES(AtenSpace::FilePluginInterface) | ||
|
||
|
||
/* | ||
* Core | ||
*/ | ||
public: | ||
// Constructor | ||
TestModelPlugin(); | ||
// Destructor | ||
~TestModelPlugin(); | ||
|
||
|
||
/* | ||
* Instance Handling | ||
*/ | ||
private: | ||
// Return a copy of the plugin object | ||
BasePluginInterface* makeCopy() const; | ||
|
||
|
||
/* | ||
* Definition | ||
*/ | ||
public: | ||
// Return type of plugin | ||
PluginTypes::PluginType type() const; | ||
// Return category of plugin | ||
int category() const; | ||
// Return name of plugin | ||
QString name() const; | ||
// Return nickname of plugin | ||
QString nickname() const; | ||
// Return whether the plugin is enabled | ||
bool enabled() const; | ||
// Return description (long name) of plugin | ||
QString description() const; | ||
// Return related file extensions | ||
QStringList extensions() const; | ||
// Return exact names | ||
QStringList exactNames() const; | ||
|
||
|
||
/* | ||
* Input / Output | ||
*/ | ||
public: | ||
// Return whether this plugin can import data | ||
bool canImport() const; | ||
// Import data via the supplied parser | ||
bool importData(); | ||
// Return whether this plugin can export data | ||
bool canExport() const; | ||
// Export data via the supplied parser | ||
bool exportData(); | ||
// Import next partial data chunk | ||
bool importNextPart(); | ||
// Skip next partial data chunk | ||
bool skipNextPart(); | ||
|
||
|
||
/* | ||
* Options | ||
*/ | ||
public: | ||
// Return whether the plugin has import options | ||
bool hasImportOptions() const; | ||
// Show import options dialog | ||
bool showImportOptionsDialog(KVMap& targetOptions) const; | ||
// Return whether the plugin has export options | ||
bool hasExportOptions() const; | ||
// Show export options dialog | ||
bool showExportOptionsDialog(KVMap& targetOptions) const; | ||
}; | ||
|
||
ATEN_END_NAMESPACE | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/* | ||
*** Simple XYZ Plugin Functions | ||
*** src/plugins/io_test/xyztest_funcs.cpp | ||
Copyright T. Youngs 2016-2016 | ||
This file is part of Aten. | ||
Aten is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Aten is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Aten. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "plugins/io_test/xyztest.hui" | ||
#include "model/model.h" | ||
|
||
// Constructor | ||
TestModelPlugin::TestModelPlugin() | ||
{ | ||
} | ||
|
||
// Destructor | ||
TestModelPlugin::~TestModelPlugin() | ||
{ | ||
} | ||
|
||
/* | ||
* Instance Handling | ||
*/ | ||
|
||
// Return a copy of the plugin object | ||
BasePluginInterface* TestModelPlugin::makeCopy() const | ||
{ | ||
return new TestModelPlugin; | ||
} | ||
|
||
/* | ||
* Definition | ||
*/ | ||
|
||
// Return type of plugin | ||
PluginTypes::PluginType TestModelPlugin::type() const | ||
{ | ||
return PluginTypes::FilePlugin; | ||
} | ||
|
||
// Return category of plugin | ||
int TestModelPlugin::category() const | ||
{ | ||
return PluginTypes::ModelFilePlugin; | ||
} | ||
|
||
// Name of plugin | ||
QString TestModelPlugin::name() const | ||
{ | ||
return QString("XYZ Files (XMol Style) (Test)"); | ||
} | ||
|
||
// Nickname of plugin | ||
QString TestModelPlugin::nickname() const | ||
{ | ||
return QString("xyz"); | ||
} | ||
|
||
// Return whether the plugin is enabled | ||
bool TestModelPlugin::enabled() const | ||
{ | ||
return false; | ||
} | ||
|
||
// Description (long name) of plugin | ||
QString TestModelPlugin::description() const | ||
{ | ||
return QString("Import/export for XMol-style XYZ coordinate files (Test)"); | ||
} | ||
|
||
// Related file extensions | ||
QStringList TestModelPlugin::extensions() const | ||
{ | ||
return QStringList() << "xyz"; | ||
} | ||
|
||
// Exact names | ||
QStringList TestModelPlugin::exactNames() const | ||
{ | ||
return QStringList(); | ||
} | ||
|
||
/* | ||
* Input / Output | ||
*/ | ||
|
||
// Return whether this plugin can import data | ||
bool TestModelPlugin::canImport() const | ||
{ | ||
return true; | ||
} | ||
|
||
// Import data from the specified file | ||
bool TestModelPlugin::importData() | ||
{ | ||
int nAtoms, n; | ||
QString e, name; | ||
Vec3<double> r; | ||
|
||
// Read data | ||
while (!fileParser_.eofOrBlank()) | ||
{ | ||
// Read number of atoms from file | ||
if (!fileParser_.readLineAsInteger(nAtoms)) return false; | ||
|
||
// Next line is name of model | ||
if (!fileParser_.readLine(name)) return false; | ||
|
||
// Create a new model now.... | ||
createModel(); | ||
targetModel()->setName(name); | ||
|
||
// Load atoms for model | ||
for (n=0; n<nAtoms; ++n) | ||
{ | ||
if (!fileParser_.parseLine()) break; | ||
|
||
// Create the new atom | ||
r.set(fileParser_.argd(1), fileParser_.argd(2), fileParser_.argd(3)); | ||
targetModel()->addAtom(ElementMap().find(fileParser_.argc(0)), r); | ||
} | ||
|
||
// Rebond the model | ||
targetModel()->calculateBonding(true); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// Return whether this plugin can export data | ||
bool TestModelPlugin::canExport() const | ||
{ | ||
return true; | ||
} | ||
|
||
// Export data to the specified file | ||
bool TestModelPlugin::exportData() | ||
{ | ||
// Write number atoms line | ||
fileParser_.writeLineF("%i", targetModel()->nAtoms()); | ||
|
||
// Write title line | ||
fileParser_.writeLine(targetModel()->name()); | ||
|
||
// Write atom information | ||
for (Atom* i = targetModel()->atoms(); i != NULL; i = i->next) | ||
{ | ||
fileParser_.writeLineF("%-8s %12.6f %12.6f %12.6f %12.6f", ElementMap().symbol(i->element()), i->r().x, i->r().y, i->r().z, i->charge()); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// Import next partial data chunk | ||
bool TestModelPlugin::importNextPart() | ||
{ | ||
return false; | ||
} | ||
|
||
// Skip next partial data chunk | ||
bool TestModelPlugin::skipNextPart() | ||
{ | ||
return false; | ||
} | ||
|
||
|
||
/* | ||
* Options | ||
*/ | ||
|
||
// Return whether the plugin has import options | ||
bool TestModelPlugin::hasImportOptions() const | ||
{ | ||
return false; | ||
} | ||
|
||
// Show import options dialog | ||
bool TestModelPlugin::showImportOptionsDialog(KVMap& targetOptions) const | ||
{ | ||
return false; | ||
} | ||
|
||
// Return whether the plugin has export options | ||
bool TestModelPlugin::hasExportOptions() const | ||
{ | ||
return false; | ||
} | ||
|
||
// Show export options dialog | ||
bool TestModelPlugin::showExportOptionsDialog(KVMap& targetOptions) const | ||
{ | ||
return false; | ||
} |