Commit 85ea81f9 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez
Browse files

first copypasta for python binding support

parent 9769a235
Loading
Loading
Loading
Loading
+162 −0
Original line number Diff line number Diff line
@@ -43,3 +43,165 @@ print.prt
*/tsts/*/output/*
*/build/
*/install/

# Created by https://www.gitignore.io/api/c++

### C++ ###
# Prerequisites
*.d
*.cpp
*.c
*.hpp
*.sbf

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app


# Created by https://www.gitignore.io/api/osx

### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


# Created by https://www.gitignore.io/api/python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
+0 −0

File moved.

configure.py

0 → 100644
+88 −0
Original line number Diff line number Diff line
import os
import sys
import sipconfig
import sipdistutils
import PyQt5
import subprocess
import argparse

from os.path import splitext
from os.path import dirname
from glob import glob
from distutils.spawn import find_executable

from PyQt5.QtCore import PYQT_CONFIGURATION
from plio.utils.utils import find_in_dict
from PyQt5.QtCore import PYQT_CONFIGURATION as qtconfigdict
from sipconfig import ModuleMakefile

def main (module):
    # The name of the SIP build file generated by SIP and used by the build
    # system.
    sipy_sip_dir = "sipfiles/"
    module = sipy_sip_dir+module + '.sip'
    build_file = "bundle"+".sbf"
    target = module+".so"

    # Get the extra SIP flags needed by the imported qt module.  Note that
    # this normally only includes those flags (-x and -t) that relate to SIP's
    # versioning system.
    qt_sip_flags = qtconfigdict["sip_flags"]

    # sip_bin = current_env_path + "/bin/sip"
    sip_bin = find_executable('sip')
    pyqt_sip_dir = dirname(dirname(sip_bin)) + "/share/sip/PyQt5"

    # Get the PyQt configuration information.
    config = sipconfig.Configuration()

    # Run SIP to generate the code.  Note that we tell SIP where to find the qt
    # module's specification files using the -I flag.

    errcode = os.system(" ".join([sip_bin, "-e","-c", ".", "-b", build_file, "-I",
        pyqt_sip_dir, qt_sip_flags, module]))

    if errcode != 0:
        print('sip exited with non zero error code: {}'.format(errcode))

    # We are going to install the SIP specification file for this module and
    # its configuration module.
    installs = []
    installs.append([module, os.path.join(pyqt_sip_dir, "isis3")])

    isis_root = os.getenv("ISISROOT")
    if not isis_root:
        raise("Please set ISIS")

    extra_libs = ["$(ALLLIBS)", "-Wl,-rpath,"+isis_root+"/lib", "-Wl,-rpath,"+isis_root+"/3rdParty/lib"]

    makefile = ModuleMakefile(configuration=config, build_file=build_file, installs=installs)
    makefile.extra_cxxflags = ["$(ALLINCDIRS)", "-Wstrict-aliasing=0", "-Wno-unused-variable"]
    makefile.extra_lflags =  ["$(ALLLIBDIRS)"]
    makefile.extra_include_dirs = [x[0] for x in os.walk('incs/')]
    makefile.extra_lib_dirs = [isis_root + '/3rdParty/lib', isis_root + 'lib']
    makefile.generate()

    # add import line for isismake.os
    isis_makefile = "include " + isis_root + "/make/isismake.os"

    with open("Makefile", 'r+') as f:
        content = f.read()
        content = content.replace("LIBS =", "LIBS = " + ' '.join(extra_libs))
        f.seek(0, 0)
        f.write(isis_makefile + '\n\n' + content)

if __name__ == "__main__":
    clean = ['cpp', 'c', 'h', 'hpp', 'o', 'sbf']

    # If clean is passed in, clear up all the files genreated by the scripts
    if len(sys.argv) > 1 and sys.argv[1] == 'clean':
        files = []
        for filetype in clean:
            files.extend(glob('*.{}'.format(filetype)))

        for f in files:
            os.remove(f)
        exit()

    main('master')
+31 −0
Original line number Diff line number Diff line
// SIP Wrapper to the ISIS3 bundle class
%Include type_conversions.sip


namespace Isis {
  class BundleAdjust : public QObject {
    %TypeHeaderCode
    #include "BundleAdjust.h"
    #include "IException.h"
    %End

  public:
    BundleAdjust(PyObject* settings, const QString &cnetFile, const QString &cubeList, bool printSummary = true) throw(Isis::IException) [(QSharedPointer<Isis::BundleSettings>, QString, QString, bool)];
    %MethodCode
      int sipErr = 0;
      QSharedPointer<Isis::BundleSettings> *wrappedSettings = new QSharedPointer<Isis::BundleSettings>();

      Isis::BundleSettings *settings = (Isis::BundleSettings*) sipConvertToType(a0, sipType_Isis_BundleSettings, NULL, SIP_NOT_NONE, NULL, &sipErr);
      wrappedSettings->reset(settings);
      try {
        sipCpp = new sipIsis_BundleAdjust(*wrappedSettings, *a1, *a2, a3);
      }
      catch (Isis::IException &error) {
          PyErr_SetString(sipException_Isis_IException, error.what());
          return NULL;
      }
    %End

    Isis::BundleSolutionInfo solveCholeskyBR() throw(Isis::IException) ;
   };
};
+68 −0
Original line number Diff line number Diff line
namespace Isis {
  class BundleControlPoint {

    %TypeHeaderCode
    #include "BundleControlPoint.h"
    #include <QSharedPointer>
    %End

    public:

      SIP_PYTYPE measures() throw(Isis::IException);
      %MethodCode
        size_t size = sipCpp->size();

        PyObject *l = PyList_New(size);
        for (size_t i = 0; i < size; ++i) {
          Isis::BundleMeasure* cppMeasure = sipCpp->at(i).data();

          PyObject *pyMeasure = sipConvertFromType((void*)(cppMeasure), sipType_Isis_BundleMeasure, NULL);
          PyList_SetItem(l, i, pyMeasure);
        }

        return l;

      %End

      // BundleControlPoint(ControlPoint *point); // default constructor
      BundleControlPoint(const Isis::BundleControlPoint &src) throw(Isis::IException);
      ~BundleControlPoint();

      // copy
      void copy(const Isis::BundleControlPoint &src) throw(Isis::IException);

      // mutators
      // QSharedPointer<Isis::BundleMeasure> addMeasure(ControlMeasure *controlMeasure);
      void computeResiduals() throw(Isis::IException);
      void setNumberOfRejectedMeasures(int numRejected) throw(Isis::IException);
      void setRejected(bool reject) throw(Isis::IException);
      void setWeights(const QSharedPointer<Isis::BundleSettings> settings, double metersToRadians) throw(Isis::IException);
      void zeroNumberOfRejectedMeasures() throw(Isis::IException);

      // accessors
      bool isRejected() const throw(Isis::IException);
      int numberOfMeasures() const throw(Isis::IException);
      int numberOfRejectedMeasures() const throw(Isis::IException);
      double residualRms() const throw(Isis::IException);
      QString id() const throw(Isis::IException);
      Isis::ControlPoint::PointType type() const throw(Isis::IException);

      // string format methods
      QString formatBundleOutputSummaryString(bool errorPropagation) const throw(Isis::IException);
      QString formatBundleOutputDetailString(bool errorPropagation, double RTM, bool solveRadius=false) throw(Isis::IException) /KeywordArgs="Optional"/;
      QString formatValue(double value, int fieldWidth, int precision) throw(Isis::IException);
      QString formatAprioriSigmaString(int type, int fieldWidth, int precision, bool solveRadius=false) throw(Isis::IException) /KeywordArgs="Optional"/;
      QString formatLatitudeAprioriSigmaString(int fieldWidth, int precision) const throw(Isis::IException);
      QString formatLongitudeAprioriSigmaString(int fieldWidth, int precision) const throw(Isis::IException);
      QString formatRadiusAprioriSigmaString(int fieldWidth, int precision, bool solveRadius=false) throw(Isis::IException) /KeywordArgs="Optional"/;
      QString formatAdjustedSigmaString(int type, int fieldWidth, int precision,
                                        bool errorPropagation) const throw(Isis::IException);
      QString formatLatitudeAdjustedSigmaString(int fieldWidth, int precision,
                                                bool errorPropagation) const throw(Isis::IException);
      QString formatLongitudeAdjustedSigmaString(int fieldWidth, int precision,
                                                 bool errorPropagation) const throw(Isis::IException);
      QString formatRadiusAdjustedSigmaString(int fieldWidth, int precision,
                                              bool errorPropagation) const throw(Isis::IException);

  };
};
Loading