Skip to content

Commit

Permalink
Merge pull request #622 from patmarion/new-dev-py2
Browse files Browse the repository at this point in the history
New dev py2
  • Loading branch information
patmarion authored Apr 5, 2019
2 parents 70c4925 + 85e98c6 commit 43d540f
Show file tree
Hide file tree
Showing 30 changed files with 1,124 additions and 161 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")

# set project variables
include(cmake/dd-version.cmake)
set(DD_INSTALL_BIN_DIR bin)
set(DD_INSTALL_DOC_DIR share/doc/director)
set(DD_INSTALL_LIB_DIR lib)
set(DD_INSTALL_INCLUDE_DIR include/director)
set(DD_INSTALL_CONFIG_DIR ${DD_INSTALL_LIB_DIR}/cmake/director-${DD_VERSION})
set(DD_TARGETS_NAME director-targets)

set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/${DD_INSTALL_BIN_DIR}")
Expand All @@ -34,7 +36,6 @@ option(BUILD_TESTING "Build director with tests enabled." ON)
# include cmake scripts
include(cmake/dd-macros.cmake)
include(cmake/dd-testing.cmake)
include(cmake/dd-version.cmake)

# dependency options
option(USE_PORTMIDI "Build director with portmidi dependency." OFF)
Expand Down
4 changes: 4 additions & 0 deletions cmake/dd-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@ endmacro()
macro(setup_pkg_config_path)
set(ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
endmacro()

macro(install_headers)
install(FILES ${ARGN} DESTINATION ${DD_INSTALL_INCLUDE_DIR})
endmacro()
2 changes: 0 additions & 2 deletions cmake/dd-post-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#get_property(DD_RELATIVE_BUILD_INCLUDE_DIRS GLOBAL PROPERTY DD_RELATIVE_BUILD_INCLUDE_DIRS)
#get_property(DD_LIBRARIES GLOBAL PROPERTY DD_LIBRARIES)

set(DD_INSTALL_CONFIG_DIR ${DD_INSTALL_LIB_DIR}/cmake/director-${DD_VERSION})

file(RELATIVE_PATH DD_INCLUDE_DIR_RELATIVE_TO_CONFIG_DIR
"${CMAKE_INSTALL_PREFIX}/${DD_INSTALL_CONFIG_DIR}"
"${CMAKE_INSTALL_PREFIX}/${DD_INSTALL_INCLUDE_DIR}")
Expand Down
12 changes: 8 additions & 4 deletions distro/package/fixup_elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def findElfFiles(searchPath, recursive=True):

def main():

baseDir = sys.argv[1]
patchElfCommand = sys.argv[2]
workDir = sys.argv[1]
baseDir = sys.argv[2]
patchElfCommand = sys.argv[3]

assert os.path.isfile(patchElfCommand)
assert os.path.isdir(workDir)
assert os.path.isdir(baseDir)
assert os.path.isfile(patchElfCommand)


files = findElfFiles(baseDir)
Expand Down Expand Up @@ -54,7 +56,9 @@ def main():
newRpath = ':'.join(newPaths)
print ' new rpath:', newRpath

subprocess.check_output('"%s" --set-rpath "%s" --force-rpath "%s"' % (patchElfCommand, newRpath.replace('$', '\\$'), elfFile), shell=True)
newElfFile = os.path.join(workDir, os.path.relpath(elfFile, baseDir))
assert os.path.isfile(newElfFile)
subprocess.check_output('"%s" --set-rpath "%s" --force-rpath "%s"' % (patchElfCommand, newRpath.replace('$', '\\$'), newElfFile), shell=True)


if __name__ == '__main__':
Expand Down
5 changes: 3 additions & 2 deletions distro/package/make_linux_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ if [ ! -f "$patchelfExe" ]; then
fi

cd $scriptDir
cp -r $superbuildInstallDir $packageName
echo 'running fixup_elf script'
python fixup_elf.py $superbuildInstallDir $patchelfExe

cp -r $superbuildInstallDir $packageName
python fixup_elf.py $packageName $superbuildInstallDir $patchelfExe
tar -czf $packageName.tar.gz $packageName
rm -r $packageName
51 changes: 51 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include_directories(${CTK_PYTHONCONSOLE_INCLUDE_DIRS})
include_directories(${PYTHONQT_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})

set(hdrs)
set(decorator_file ${CMAKE_CURRENT_BINARY_DIR}/ddPythonQtDecorators.h)

# Configure whether to use the QVTKWidget or the QVTKOpenGLWidget
Expand All @@ -41,6 +42,7 @@ if((${Qt5Core_VERSION} VERSION_GREATER "5.4.0") AND
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ddQVTKOpenGLWidgetConfigure.h.in
${CMAKE_CURRENT_BINARY_DIR}/ddQVTKOpenGLWidgetConfigure.h)
list(APPEND hdrs ${CMAKE_CURRENT_BINARY_DIR}/ddQVTKOpenGLWidgetConfigure.h)

if(USE_QVTKWIDGET)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/wrapped_methods_qvtk.txt
Expand Down Expand Up @@ -119,6 +121,36 @@ set(srcs
vtkTDxInteractorStyleCallback.cxx
)

list(APPEND hdrs
ddAppConfigure.h
ddEmptyView.h
ddFPSCounter.h
ddGLWidgetView.h
ddGroupBoxHider.h
ddMacrosManager.h
ddMainWindow.h
ddObjectTree.h
ddPropertiesPanel.h
ddPythonApp.h
ddPythonEventFilter.h
ddPythonManager.h
ddPythonQtWrapperFactory.h
ddPythonUndoCommand.h
ddQVTKWidgetView.h
ddSignalMap.h
ddSpreadsheetView.h
ddTaskSelection.h
ddViewBase.h
ddViewManager.h
ddViewMenu.h
ddVTKObjectMap.h
py3main.h
QtVariantProperty.h
QVTKOpenGLInit.h
vtkSimpleActorInteractor.h
vtkTDxInteractorStyleCallback.h
)

set(deps
${QT_LIBRARIES}
${CTK_PYTHONCONSOLE_LIBRARIES}
Expand Down Expand Up @@ -168,6 +200,12 @@ if (USE_DRAKE)

configure_file(ddDrakeVersion.h.in ddDrakeVersion.h)

list(APPEND hdrs
${CMAKE_CURRENT_BINARY_DIR}/ddDrakeVersion.h
ddDrakeModel.h
ddDrakeWrapper.h
)

list(APPEND wrap_files
wrapped_methods_drake.txt
)
Expand All @@ -194,6 +232,11 @@ if (USE_LCM)
ddLCMThread.cpp
)

list(APPEND hdrs
ddLCMSubscriber.h
ddLCMThread.h
)

if(NOT BUILD_SHARED_LIBS AND LCM_STATIC_LIBRARIES)
set(LCM_LIBRARIES ${LCM_STATIC_LIBRARIES})
endif()
Expand Down Expand Up @@ -236,6 +279,11 @@ if (USE_PERCEPTION)
ddPointCloudLCM.h
)

list(APPEND hdrs
ddBotImageQueue.h
ddPointCloudLCM.h
)

list(APPEND srcs
${moc_srcs}
ddBotImageQueue.cpp
Expand Down Expand Up @@ -302,3 +350,6 @@ add_custom_command(OUTPUT ${decorator_file}
--auto-class-includes --module-name dd
DEPENDS ${wrap_files} WrapPythonQt.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

install_headers(${hdrs})
install(FILES WrapPythonQt.py DESTINATION ${DD_INSTALL_CONFIG_DIR})
14 changes: 9 additions & 5 deletions src/app/WrapPythonQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ def wrap(args):
outFileName = args.output_file
exportSymbol = args.export_symbol
exportHeader = args.export_header
decoratorClassName = args.class_name
classNamePrefixes = args.class_prefixes
qtClassNamePrefixes = args.qt_class_prefixes
moduleName = args.module_name
autoClassIncludes = args.auto_class_includes

if not outFileName.endswith('.h'):
raise Exception('Error: output file extension must be .h')
if not decoratorClassName:
if not outFileName.endswith('.h'):
raise Exception('Error: when output class name is not provided then the'
' output file extension must be .h')
decoratorClassName = os.path.basename(outFileName).replace('.h', '')

lines = []
for inFileName in inFileNames:
Expand Down Expand Up @@ -131,15 +135,13 @@ def wrap(args):
classRegisters = "\n".join([' this->registerClassForPythonQt(&%s::staticMetaObject);' % className
for className in sortedClasses if className.startswith(qtClassNamePrefixes)])

decoratorClassName = os.path.basename(outFileName).replace('.h', '')

outFile = open(outFileName, 'w')
outFile.write('''
#ifndef __%s_h
#define __%s_h
#include <QObject>
#include "PythonQt.h"
#include <PythonQt.h>
%s
%s
Expand Down Expand Up @@ -187,6 +189,8 @@ def main():
parser.add_argument('--input-file', '-i', nargs='+', required=True, help='A text file with method signatures, one per line.')
parser.add_argument('--output-file', '-o', required=True, help='The output filename. The file extension should be .h')
parser.add_argument('--module-name', default='', help='The Python module name under which Qt classes will be registered.')
parser.add_argument('--class-name', default='', help='The C++ class name of the generated decorator.'
' If empty, it will be computed from the output filename.')
parser.add_argument('--export-symbol', default='', help='An export symbol that will be added to the class declaration.')
parser.add_argument('--export-header', default='', help='A header filename that defines an export symbol.')
parser.add_argument('--class-prefixes', nargs='*', help='A list of class name prefixes.')
Expand Down
3 changes: 3 additions & 0 deletions src/app/ddMeasurementPanel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="toleranceSpinBox">
<property name="decimals">
<number>3</number>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
Expand Down
54 changes: 43 additions & 11 deletions src/app/ddVTKObjectMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ddVTKObjectMap::ddInternal
{
public:
QMap<QString, vtkObjectBase*> Map;
QMap<QString, QList<vtkObjectBase*>> Map;
QMutex Mutex;
};

Expand All @@ -29,31 +29,63 @@ ddVTKObjectMap::~ddVTKObjectMap()
}

//-----------------------------------------------------------------------------
QVariant ddVTKObjectMap::take(const QString& key) const
QVariant ddVTKObjectMap::takeAll(const QString& key) const
{
QMutexLocker locker(&this->Internal->Mutex);
PythonQtObjectPtr pythonPtr;
vtkObjectBase* obj = this->Internal->Map.take(key);
if (obj)
QList<QVariant> pyList;
QList<vtkObjectBase*> objList = this->Internal->Map.take(key);
foreach(vtkObjectBase* obj, objList)
{
PythonQtObjectPtr pythonPtr;
pythonPtr.setNewRef(vtkPythonUtil::GetObjectFromPointer(obj));
pyList.append(QVariant::fromValue(pythonPtr));
obj->Delete();
return QVariant::fromValue(pythonPtr);
}
return QVariant();
return pyList;
}

//-----------------------------------------------------------------------------
QVariant ddVTKObjectMap::take(const QString& key) const
{
QList<QVariant> pyList = this->takeAll(key).value<QList<QVariant>>();
return pyList.count() ? QVariant::fromValue(pyList.last()) : QVariant();
}

//-----------------------------------------------------------------------------
void ddVTKObjectMap::put(const QString& key, vtkObjectBase* obj)
{
this->Internal->Mutex.lock();
vtkObjectBase* prev = this->Internal->Map.value(key);
if (prev)
foreach(vtkObjectBase* obj, this->Internal->Map.take(key))
{
prev->Delete();
obj->Delete();
}
this->Internal->Map[key] = obj;
QList<vtkObjectBase*> newList;
newList.append(obj);
this->Internal->Map[key] = newList;
this->Internal->Mutex.unlock();
emit this->objectAssigned(key);
}


//-----------------------------------------------------------------------------
void ddVTKObjectMap::putAppend(const QString& key, vtkObjectBase* obj, bool sendSignal)
{
this->Internal->Mutex.lock();
if (this->Internal->Map.contains(key))
{
this->Internal->Map[key].append(obj);
}
else
{
QList<vtkObjectBase*> newList;
newList.append(obj);
this->Internal->Map[key] = newList;
}

this->Internal->Mutex.unlock();

if (sendSignal)
{
emit this->objectAssigned(key);
}
}
31 changes: 24 additions & 7 deletions src/app/ddVTKObjectMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,50 @@ class DD_APP_EXPORT ddVTKObjectMap : public QObject
virtual ~ddVTKObjectMap();

// Description:
// Puts the given vtkObjectBase instance into the map and takes
// ownership. This steals a reference. The caller should not
// Puts the given vtkObjectBase instance into the map, and removes
// any objects already in the map with this key. The map takes ownership
// of the given object. This steals a reference. The caller should not
// call Delete() or otherwise decrement the reference count after
// the object is put into the map. The purpose of this function is
// to pass the object to another thread, so you should should touch
// to pass the object to another thread, so you should not touch
// the object after calling this function, or use anything like a
// smart pointer that might touch the object to decrement a reference
// count. This is threadsafe and may be called from any thread.
void put(const QString& key, vtkObjectBase* obj);

// Description:
// Same as put() except the object is appended to a list associated with
// the given key. See put() for ownership semantics and thread safety.
void putAppend(const QString& key, vtkObjectBase* obj, bool sendSignal=true);

// Description:
// This function is designed to be called from Python. This will
// remove the vtkObjectBase instance from the map and wrap it with
// a reference counted Python object pointer using PythonQt's smart
// take the most recent vtkObjectBase instance in the map associated
// with the given key (and erase other instances). An empty QVariant
// is returned if there are no instances in the map. The returned instance
// is wrapped with a reference counted Python object pointer using PythonQt's smart
// pointer type PythonObjectPtr. The PythonObjectPtr is returned
// wrapped in a QVariant so that this header does not have any
// dependency on the PythonQt API. When Python releases the reference
// the vtkObjectBase instance will be destroyed. This function
// should only be called from the main Python thread.
// This is equivalent to takeAll().last() when the list is not empty.
QVariant take(const QString& key) const;

// Description:
// This function is designed to be called from Python. See take() for
// more details. Returns a QList<QVariant>>, wrapped as a QVariant.
// This is a list that contains all vtkObjectBase instances in the map
// associated with the given key, in the order they were added to the
// map.
QVariant takeAll(const QString& key) const;

signals:

// Description:
// This signal is emitted each time put() is called, after the
// This signal is emitted each time put() or putAppend() is called, after the
// reference has been stored in the map. This signal is emitted
// from the thread that called put(). You can connect to this
// from the thread that called put() or putAppend(). You can connect to this
// signal in Python on the main thread to get a notification.
// Note that the signal connection will be queued so you may get
// multiple signals emitted before the signal handler is called.
Expand Down
1 change: 1 addition & 0 deletions src/app/wrapped_methods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ QVariant ddSignalMap::value(const QString&) const;

ddVTKObjectMap::ddVTKObjectMap();
QVariant ddVTKObjectMap::take(const QString&);
QVariant ddVTKObjectMap::takeAll(const QString&);
8 changes: 8 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
configure_file(ddVersion.h.in ddVersion.h)


install_headers(
${CMAKE_CURRENT_BINARY_DIR}/ddVersion.h
ddMacros.h
ddOpenGL.h
ddSharedPtr.h
)
Loading

0 comments on commit 43d540f

Please sign in to comment.