Cleaned up campvis-scripting package:

Removed obsolete Lua pipeline registration. Create campvis-scripting as shared library. Added CAMPVIS_SCRIPTING_API definitions where needed. Disabled warnings in SWIG lua bindings.
parent dfec0e89
# = CAMPVis - Yet another medical visualization framework =====================
PROJECT(CAMPVis)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)
SET(CAMPVIS_VERSION 1.0.0)
......
......@@ -53,10 +53,6 @@
#include <QApplication>
#ifdef CAMPVIS_HAS_SCRIPTING
#include "scripting/gen_pipelineregistration.h"
#endif
namespace campvis {
const std::string CampVisApplication::loggerCat_ = "CAMPVis.application.CampVisApplication";
......
......@@ -125,7 +125,7 @@ namespace campvis {
return;
QString textUnderCursor = text().left(cursorPosition());
size_t pos = textUnderCursor.toStdString().find_last_of(" ()[]{}");
int pos = int(textUnderCursor.toStdString().find_last_of(" ()[]{}"));
QString completionPrefix = textUnderCursor.right(textUnderCursor.length() - pos - 1);
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
......@@ -150,7 +150,7 @@ namespace campvis {
return;
QString textUnderCursor = text().left(cursorPosition());
size_t pos = textUnderCursor.toStdString().find_last_of(" .:()[]{}");
int pos = int(textUnderCursor.toStdString().find_last_of(" .:()[]{}"));
if (pos == std::string::npos)
pos = 0;
else
......
......@@ -229,6 +229,8 @@ namespace campvis {
return QVariant("[Metatable]");
case COMPLETER_MODEL:
return QVariant("[Methods]");
default:
return QVariant("");
}
}
else {
......
......@@ -24,7 +24,7 @@ FILE(GLOB CampvisScriptingHeaders
)
IF(WIN32)
LIST(APPEND CampvisScriptingDefinitions /wd4267)
#LIST(APPEND CampvisScriptingDefinitions "/wd4267")
ENDIF(WIN32)
......@@ -46,26 +46,19 @@ FOREACH(ModName ${CampvisModules})
IF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
LIST(APPEND CampvisBindingDirs "modules/${ModName}")
FILE(GLOB ModLuaPipelines "${CampvisHome}/modules/${ModName}/pipelines/*.lua")
LIST(APPEND CampvisLuaPipelines ${ModLuaPipelines})
ENDIF(CAMPVIS_BUILD_MODULE_${ModNameUpper})
ENDFOREACH(ModName ${CampvisModules})
# Hack-fix for a bug in SWIG_ADD_MODULE that breaks out-of-tree builds by not creating wrapper
# output directories.
# TODO: remove once http://www.cmake.org/Bug/view.php?id=14459 lands
FOREACH(BindingDir ${CampvisBindingDirs})
FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${BindingDir}/bindings")
ENDFOREACH(BindingDir ${CampvisBindingDirs})
# Declare a Lua module to be generated by SWIG from the specified interface file
MACRO(DECLARE_LUA_MODULE InterfaceFile)
STRING(REGEX REPLACE ".*/([A-Za-z0-9_]+)\\.i" "\\1" LuaModShortName ${InterfaceFile})
SET(LuaModName "${LuaModShortName}-lua-mod")
MESSAGE(STATUS "* ${LuaModShortName}")
IF(WIN32)
ADD_DEFINITIONS("/wd4244 /wd4267")
ENDIF()
SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(${InterfaceFile} PROPERTIES SWIG_FLAGS "-I${CampvisHome}")
LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
......@@ -101,14 +94,6 @@ FOREACH(BindingDir ${CampvisBindingDirs})
ENDFOREACH(BindingDir ${CampvisBindingDirs})
# Generate a registration header for Lua pipelines
FOREACH(LuaPipeline ${CampvisLuaPipelines})
PARSE_SCRIPT_FOR_PIPELINE(${LuaPipeline})
ENDFOREACH(LuaPipeline ${CampvisBindingDirs})
WRITE_SCRIPTED_PIPELINE_REGISTRATION("gen_pipelineregistration.h")
# Generate header with SWIG run-time functions
ADD_CUSTOM_COMMAND(
OUTPUT "swigluarun.h"
......@@ -121,14 +106,13 @@ ADD_DEFINITIONS(${CampvisGlobalDefinitions} ${CampvisScriptingDefinitions})
INCLUDE_DIRECTORIES(${CampvisGlobalIncludeDirs} ${CMAKE_CURRENT_BINARY_DIR})
LINK_DIRECTORIES(${CampvisGlobalLinkDirectories} ${CampvisModulesLinkDirectories})
ADD_LIBRARY(campvis-scripting ${CampvisSharedStaticModulesFix}
${CampvisScriptingSources} ${CampvisScriptingHeaders}
)
#ADD_DEPENDENCIES(campvis-scripting ${CampvisLuaModules})
ADD_LIBRARY(campvis-scripting ${CampvisScriptingSources} ${CampvisScriptingHeaders})
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules cgt ${CampvisGlobalExternalLibs})
# if campvis-core is built as a shared library, CMake will define the following flag to instruct
# the code to export DLL symbols
SET_TARGET_PROPERTIES(campvis-scripting PROPERTIES DEFINE_SYMBOL "CAMPVIS_SCRIPTING_BUILD_DLL")
IF(CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisScriptingSources ${CampvisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisScriptingHeaders ${CampvisHome} "")
......
......@@ -26,6 +26,7 @@
#define GLOBALLUATABLE_H__
#include "luatable.h"
#include "scripting/scriptingapi.h"
namespace campvis {
......@@ -36,7 +37,7 @@ namespace campvis {
* a result, they must be used in order to interact with Lua states and access user-defined
* values.
*/
class GlobalLuaTable : public LuaTable {
class CAMPVIS_SCRIPTING_API GlobalLuaTable : public LuaTable {
public:
/**
* Creates a new GlobalLuaTable.
......
......@@ -25,6 +25,8 @@
#ifndef LUATABLE_H__
#define LUATABLE_H__
#include "scripting/scriptingapi.h"
#include <map>
#include <memory>
#include <set>
......@@ -55,7 +57,7 @@ namespace campvis {
* such calls to be propagated through their enclosing tables all the way up to the global
* table.
*/
class LuaTable : public std::enable_shared_from_this<LuaTable>
class CAMPVIS_SCRIPTING_API LuaTable : public std::enable_shared_from_this<LuaTable>
{
friend GlobalLuaTable;
friend MetatableLuaTable;
......
......@@ -28,7 +28,14 @@
#include <iostream>
#include <memory>
#include <string>
#pragma warning(push)
#pragma warning (disable: 4244 4267)
#include "scripting/swigluarun.h"
#pragma warning(pop)
#include "scripting/scriptingapi.h"
#include "scripting/glue/globalluatable.h"
#include "tbb/recursive_mutex.h"
......@@ -60,7 +67,7 @@ namespace campvis {
* common operations (e.g. script execution) while still giving access to the underlying raw
* Lua state.
*/
class LuaVmState
class CAMPVIS_SCRIPTING_API LuaVmState
{
public:
/**
......
......@@ -2,6 +2,7 @@
#define METATABLELUATABLE_H__
#include "luatable.h"
#include "scripting/scriptingapi.h"
namespace campvis {
......@@ -11,7 +12,7 @@ namespace campvis {
* Any Lua field may contain a metatable. They serve multiple purposes, including emulation
* of classes and objects.
*/
class MetatableLuaTable : public LuaTable {
class CAMPVIS_SCRIPTING_API MetatableLuaTable : public LuaTable {
public:
/**
* Creates a new MetatableLuaTable.
......
......@@ -26,6 +26,7 @@
#define REGULARLUATABLE_H__
#include "luatable.h"
#include "scripting/scriptingapi.h"
namespace campvis {
......@@ -35,7 +36,7 @@ namespace campvis {
* Regular tables can be defined by exclusion: any Lua table that is not a global table or a
* metatable is a regular one.
*/
class RegularLuaTable : public LuaTable {
class CAMPVIS_SCRIPTING_API RegularLuaTable : public LuaTable {
public:
/**
* Creates a new RegularLuaTable.
......
......@@ -25,10 +25,8 @@
#ifndef ABSTRACTPROPERTYLUA_H__
#define ABSTRACTPROPERTYLUA_H__
#include "sigslot/sigslot.h"
#include "tbb/atomic.h"
#include <QBoxLayout>
#include <QLabel>
#include "scripting/scriptingapi.h"
#include <string>
namespace campvis {
class AbstractProperty;
......@@ -37,7 +35,7 @@ namespace campvis {
/**
* Abstract base class for property luas.
*/
class AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API AbstractPropertyLua {
public:
/**
* Creates a new Lua Property for the property \a property.
......
......@@ -25,6 +25,7 @@
#ifndef BOOLPROPERTYLUA_H__
#define BOOLPROPERTYLUA_H__
#include "scripting/scriptingapi.h"
#include "scripting/luagen/properties/abstractpropertylua.h"
#include "scripting/luagen/properties/propertyluafactory.h"
#include "core/properties/genericproperty.h"
......@@ -33,7 +34,7 @@ namespace campvis {
/**
* Lua generator for a BoolProperty
*/
class BoolPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API BoolPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new BoolPropertyLua for the property \a property.
......
......@@ -29,13 +29,14 @@
#include "propertyluafactory.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/colorproperty.h"
#include "scripting/scriptingapi.h"
namespace campvis {
/**
* Lua generator for a ColorProperty
*/
class ColorPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API ColorPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new FloatPropertyLua for the property \a property.
......
......@@ -26,21 +26,15 @@
#define DATANAMEPROPERTYLUA_H__
#include "core/properties/datanameproperty.h"
#include "scripting/scriptingapi.h"
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
class QComboBox;
class QLineEdit;
namespace campvis {
class DataNameProperty;
class DataContainer;
class DataHandle;
/**
* Lua generator for a DataNameProperty
*/
class DataNamePropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API DataNamePropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new PropertyLua for the property \a property.
......
......@@ -34,7 +34,7 @@ namespace campvis {
/**
* Lua generator for a FloatProperty
*/
class FloatPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API FloatPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new FloatPropertyLua for the property \a property.
......
......@@ -27,6 +27,8 @@
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
#include "scripting/scriptingapi.h"
#include "core/properties/numericproperty.h"
#include "core/tools/stringutils.h"
......@@ -34,7 +36,7 @@ namespace campvis {
/**
* Lua generator for a IntProperty
*/
class IntPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API IntPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new IntPropertyLua for the property \a property.
......
......@@ -26,19 +26,19 @@
#define METAPROPERTYLUA_H__
#include "scripting/scriptingapi.h"
#include "core/properties/metaproperty.h"
#include "abstractpropertylua.h"
#include "propertycollectionluascriptgenerator.h"
#include "propertyluafactory.h"
namespace campvis {
class DataContainer;
/**
* Lua for a MetaProperty.
* Forwards the call to the PropertyCollectionLua
*/
class MetaPropertyLua : public PropertyCollectionLuaScriptGenerator {
class CAMPVIS_SCRIPTING_API MetaPropertyLua : public PropertyCollectionLuaScriptGenerator {
public:
/**
* Creates a new MetaPropertyLua for the property \a property.
......
......@@ -27,7 +27,9 @@
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
#include "core/properties/optionproperty.h"
#include "scripting/scriptingapi.h"
namespace campvis {
class AbstractOptionProperty;
......@@ -35,7 +37,7 @@ namespace campvis {
/**
* Lua generator for a OptionProperty
*/
class OptionPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API OptionPropertyLua : public AbstractPropertyLua {
public:
/**
......
......@@ -39,7 +39,7 @@ namespace campvis {
* Main lua generator for the CAMPVis application.
* Calls individual properties for their own scripts and assembles all responses.
*/
class PropertyCollectionLuaScriptGenerator : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API PropertyCollectionLuaScriptGenerator : public AbstractPropertyLua {
public:
/**
* Creates a new PropertyCollectionLua.
......
......@@ -31,6 +31,8 @@
#include <tbb/atomic.h>
#include <tbb/spin_mutex.h>
#include "scripting/scriptingapi.h"
#include <map>
#include <string>
#include <typeindex>
......@@ -40,7 +42,6 @@
namespace campvis {
class AbstractProperty;
class AbstractPropertyLua;
class DataContainer;
/**
* Factory for creating Lua Property depending on the Property type.
......@@ -49,7 +50,7 @@ namespace campvis {
*
* \note PropertyLuaFactory is a thread-safe lazy-instantiated singleton.
*/
class PropertyLuaFactory {
class CAMPVIS_SCRIPTING_API PropertyLuaFactory {
public:
/// Typedef for a function pointer to create a PropertyLua if you know exactly its type.
typedef AbstractPropertyLua* (*PropertyLuaCreateFunctionPointer) (AbstractProperty*);
......@@ -83,7 +84,6 @@ namespace campvis {
* Create a PropertyLua for the given property.
* Checkes all registered luas, wether they match the type of \a property.
* \param property The property the lua shall handle.
* \param dataContainer DataContainer to use (optional), defaults to nullptr. However, some derived classed might need a valid pointer here!
* \return The created property lua for the property - nullptr, if there was no matching lua found.
*/
AbstractPropertyLua* createPropertyLua(AbstractProperty* property);
......@@ -117,7 +117,6 @@ namespace campvis {
/**
* Static factory method for creating the lua if we know the property type exactly.
* \param property The property the lua shall handle.
* \param dataContainer DataContainer to use (optional), defaults to nullptr. However, some derived classed might need a valid pointer here!
* \return The newly created property lua.
*/
static AbstractPropertyLua* create(AbstractProperty* property) {
......@@ -129,7 +128,6 @@ namespace campvis {
* Static factory method for creating the lua if we don't know the property type.
* Performs a dynamic type check to see whether the property type matches.
* \param property The property the lua shall handle.
* \param dataContainer DataContainer to use (optional), defaults to nullptr. However, some derived classed might need a valid pointer here!
* \return The newly created property lua, may be nullptr in case the types do not match.
*/
static AbstractPropertyLua* tryCreate(AbstractProperty* property) {
......
......@@ -27,13 +27,15 @@
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
#include "core/properties/stringproperty.h"
#include "scripting/scriptingapi.h"
namespace campvis {
/**
* Lua generator for a StringProperty
*/
class StringPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API StringPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new PropertyLua for the property \a property.
......
......@@ -27,8 +27,9 @@
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
//#include "abstracttransferfunctionlua.h"
#include "core/properties/transferfunctionproperty.h"
#include "scripting/scriptingapi.h"
namespace campvis {
class AbstractTransferFunctionEditor;
......@@ -36,7 +37,7 @@ namespace campvis {
/**
* Widget for a TransferFunctionProperty
*/
class TransferFunctionPropertyLua : public AbstractPropertyLua {
class CAMPVIS_SCRIPTING_API TransferFunctionPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new Lua Property for the property \a property.
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "luapipeline.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include "scripting/glue/luatable.h"
#include "scripting/glue/globalluatable.h"
#include "scripting/glue/metatableluatable.h"
#include "scripting/glue/regularluatable.h"
#include "scripting/glue/luavmstate.h"
namespace campvis {
LuaPipeline::LuaPipeline(const std::string name, std::string scriptPath, DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _name(name)
, _scriptPath(scriptPath)
, _luaVmState(new LuaVmState())
, _pipelineTable(_luaVmState->getGlobalTable()->getTable("pipeline"))
{
// Let Lua know where CAMPVis modules are located
if (!_luaVmState->execString("package.cpath = '" CAMPVIS_LUA_MODS_PATH "'"))
return;
// Load CAMPVis' core Lua module to have SWIG glue for AutoEvaluationPipeline available
if (!_luaVmState->execString("require(\"campvis\")"))
return;
// Make this pipeline object available to the script so that it can configure it
if (!_luaVmState->injectGlobalObjectPointer(this, "campvis::AutoEvaluationPipeline *", "instance"))
return;
// Try executing the pipeline's Lua script
if (!_luaVmState->execFile(scriptPath))
return;
if (!_pipelineTable->isValid())
std::cerr << "No valid Lua pipeline found (global variable `pipeline` is not a table)" << std::endl;
else
_pipelineTable->callInstanceMethod("ctor");
}
LuaPipeline::~LuaPipeline() {
}
void LuaPipeline::init() {
AutoEvaluationPipeline::init();
_pipelineTable->callInstanceMethod("init");
}
void LuaPipeline::deinit() {
AutoEvaluationPipeline::deinit();
_pipelineTable->callInstanceMethod("deinit");
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef SCRIPTEDPIPELINEREGISTRAR_H__
#define SCRIPTEDPIPELINEREGISTRAR_H__
#include "luapipeline.h"
#include "core/pipeline/pipelinefactory.h"
namespace campvis {
/**
* PipelineFactory requires each pipeline to be represented by a separate class whose static
* getId method returns a unique identifier. As all Lua pipelines are instance of one class,
* LuaPipeline, and only differ with respect to the script they execute (which is not known at
* compile time), the following adapter class is needed.
*
* IdentifiableLuaPipeline gets its identifier as a template argument, and is able to return it
* from a static method as a result.
*/
template <const char* id>
class IdentifiableLuaPipeline : public LuaPipeline {
public:
IdentifiableLuaPipeline(const std::string scriptPath, DataContainer* dc) : LuaPipeline(id, scriptPath, dc) {}
static const std::string getId() { return id; }
};
// ================================================================================================
template<typename T, const char* scriptPath>
class ScriptedPipelineRegistrar {
public:
/**
* Static factory method for creating the pipeline of type T.
* \param dc DataContainer for the created pipeline to work on.
* \return A newly created Lua pipeline of type T. Caller has to take ownership of the pointer.
*/
static AbstractPipeline* create(DataContainer* dc) {
return new T(scriptPath, dc);
}
private:
/// static helper field to ensure registration at static initialization time.
static const size_t _factoryId;
};
template<typename T, const char* scriptPath>
const size_t ScriptedPipelineRegistrar<T, scriptPath>::_factoryId =
PipelineFactory::getRef().registerPipeline<T>(&ScriptedPipelineRegistrar<T, scriptPath>::create);
}
#endif // SCRIPTEDPIPELINEREGISTRAR_H__
......@@ -2,7 +2,7 @@
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
......@@ -22,51 +22,28 @@
//
// ================================================================================================
#ifndef LUAPIPELINE_H__
#define LUAPIPELINE_H__
#include <memory>
#include "core/pipeline/autoevaluationpipeline.h"
namespace campvis {
class LuaTable;
class LuaVmState;
/**
* Class representing CAMPVis pipelines defined in Lua.
*/
class LuaPipeline : public AutoEvaluationPipeline {
public:
/**