Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Fix Windows & Python 3.x building
Browse files Browse the repository at this point in the history
  • Loading branch information
Runar Tenfjord committed Nov 23, 2012
1 parent d17b74c commit 7d7197d
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 164 deletions.
11 changes: 11 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include Makefile
include setup_build.py
include setup_docs.py
include version.py
include MANIFEST.in
include README.rst
include TODO.rst
include LICENSE.txt
recursive-include occmodel *.py *.pyx *.pxi *.pxd *.rst *.cpp *.h
exclude occmodel/test.py occmodel/test2.py occmodel/Note.rst
prune occmodel/@arch
65 changes: 65 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# File: Makefile (for library)
#
# The variables 'PYTHON' and 'PYVER' can be modified by
# passing parameters to make: make PYTHON=python PYVER=2.6
#
PYTHON=python2
PYVER=2.7

CC=g++
CFLAGS=-Wall -fPIC -O2 -frtti -fexceptions -Isrc -I/usr/include/oce
LIB=occmodel/liboccmodel.a

LIBSRC = $(wildcard occmodel/@src/*.cpp)

LIBOBJ=$(LIBSRC:.cpp=.o)

.PHONY: pylib docs test tests install clean

$(LIB): $(LIBOBJ)
@echo lib Makefile - archiving $(LIB)
@$(AR) r $(LIB) $(LIBOBJ)

.cpp.o:
@echo lib Makefile - compiling $<
@$(CC) $(CFLAGS) -c $< -o $@

pylib: $(LIB)
@echo lib Makefile - building python extension
$(PYTHON) setup_build.py build_ext --inplace

docs: pylib
@echo lib Makefile - building documentation
@cd occmodel/@docs ; $(PYTHON) ../../setup_docs.py build_sphinx
@cp -rf occmodel/@docs/build/sphinx/html/* occmodel/@docs/html/

test: pylib
@echo lib Makefile - running test file
$(PYTHON) occmodel/test.py

tests: pylib
@echo lib Makefile - running test suite
@cd occmodel/@tests ; $(PYTHON) runAll.py

install: pylib
@cp occmodel.so ~/.local/lib/python$(PYVER)/site-packages/
@cp occmodelviewer.so ~/.local/lib/python$(PYVER)/site-packages/

sdist: clean
@echo lib Makefile - creating source distribution
$(PYTHON) setup_build.py sdist --formats=gztar,zip

clean:
-rm $(LIBOBJ)
-rm $(LIB)
-rm -rf build dist
-rm -rf occmodel/@docs/build
-rm -rf occmodel/@docs/html
-rm MANIFEST occmodel/@src/Config.pxi
-rm occmodel.so occmodel/occmodel.cpp
-rm occmodelviewer.so occmodel/occmodelviewer.c
-find occmodel -iname '*.so' -exec rm {} \;
-find occmodel -iname '*.pyc' -exec rm {} \;
-find occmodel -iname '*.pyo' -exec rm {} \;
-find occmodel -iname '*.pyd' -exec rm {} \;
23 changes: 20 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ The license is GPL v2.
Building
========

* Python 2.7 and Cython 0.17.
* Python 2.7/3.x and Cython 0.17 or later.
* A working installation of OpenCASCADE (OCE prefered)
* The geotools_ library.
* The optional viewer and demo needs the gltools_ library.

The extension have only been build on the Linux platform.
Note that currently I can not find a way to install the required
Cython 'pxd' files with distutils and this file has to be copied
manually.

On the Windows platform installers are available on the
pypi_ web site. It is possible to build the module from source
with the help of the express edition of Visual Studio, but the
process is rather involved compared to Linux.

To complete the windows installation the OpenCASCADE dll's must be
installed and placed in the system path. Prebuilt binaries are available
on the OCE_ project site. The python 2.7 module is linked against
'OCE-0.10.0-Win-MSVC2008.zip' and the python 3.3 module is
linked against 'OCE-0.10.0-Win-MSVC2010.zip'.

Documentation
=============
Expand All @@ -36,4 +49,8 @@ See online Sphinx docs_

.. _geotools: http://github.com/tenko/geotools

.. _gltools: https://github.com/tenko/gltools
.. _gltools: https://github.com/tenko/gltools

.. _pypi: http://pypi.python.org/pypi/occmodel

.. _OCE: https://github.com/tpaviot/oce/downloads
2 changes: 1 addition & 1 deletion TODO.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ToDo
----

* Migrate building to CMake or similiar
* Optimize viewer
2 changes: 1 addition & 1 deletion occmodel/@src/OCCModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int OCCMesh::extractFaceMesh(const TopoDS_Face& face, bool qualityNormals = fals
pt.Get(n1,n2,n3);

// make sure that we don't process invalid triangle
if (n1 == n2 or n2 == n3 or n3 == n1)
if (n1 == n2 || n2 == n3 || n3 == n1)
continue;

// Calculate face normal
Expand Down
48 changes: 0 additions & 48 deletions occmodel/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions occmodel/occmodel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2012 by Runar Tenfjord, Tenko as.
# See LICENSE.txt for details on conditions.
include "OCCIncludes.pxi"
include "Config.pxi"

class OCCError(Exception):
pass
Expand Down
8 changes: 7 additions & 1 deletion occmodel/occmodeldemo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import sys
import math

import geotools as geo
Expand All @@ -18,7 +20,11 @@ def eval(self):
'Solid':occ.Solid,
'SWEEP_RIGHT_CORNER': occ.SWEEP_RIGHT_CORNER,
}
exec(self.TEXT) in loc
if sys.hexversion > 0x03000000:
exec(self.TEXT, loc)
else:
exec(self.TEXT) in loc

return self.results(loc)

class Edge_1(Demo):
Expand Down
18 changes: 13 additions & 5 deletions occmodel/occmodelviewer.py → occmodel/occmodelviewer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
import ctypes
import atexit

cimport geotools as geo
import geotools as geo

cimport gltools as gl
import gltools as gl

import occmodel as occ

from occmodel import OCCError

if sys.hexversion > 0x03000000:
basestring = str

class InputHookManager(object):
"""
Manage PyOS_InputHook.
Expand Down Expand Up @@ -89,7 +97,7 @@ def removeInputHook(self):
'blue' :gl.ColorRGBA(0,0,255,255),
'yellow':gl.ColorRGBA(255,255,0,255),
'white' :gl.ColorRGBA(0,0,0,0),
'grey' :gl.ColorRGBA(128,128,128,255),
'grey' :gl.ColorRGBA(128,128,128,255),
'black' :gl.ColorRGBA(255,255,255,255),
}

Expand Down Expand Up @@ -216,7 +224,7 @@ def add(self, obj, color = None):
if color.lower() in COLORS:
color = COLORS[color.lower()]
else:
raise GLError("Unknown color: '%s'" % color)
raise OCCError("Unknown color: '%s'" % color)

if isinstance(obj, (occ.Edge, occ.Wire)):
res = PolylineObj(obj.hashCode())
Expand Down Expand Up @@ -335,7 +343,7 @@ def add(self, obj, color = None):
self.objects.add(obj)

else:
raise GLError('unknown object type')
raise OCCError('unknown object type')

return True

Expand Down Expand Up @@ -619,7 +627,7 @@ def onPick(self):
# set color from counter
color.fromInt(cnt)
if color.alpha != 0:
raise GLError('to many object to pick')
raise OCCError('to many object to pick')
color.alpha = 255
gl.Color(color)

Expand Down
96 changes: 0 additions & 96 deletions occmodel/setup_build.py

This file was deleted.

Loading

0 comments on commit 7d7197d

Please sign in to comment.