Skip to content

Commit a58b2ed

Browse files
committed
Fixes for unicode handling in Python
1 parent e5c20a0 commit a58b2ed

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

cmake/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ FIND_LIBRARY(icu "icuuc" /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 ${I
5656
IF(icu)
5757
MESSAGE(STATUS "ICU libraries found")
5858
ADD_DEFINITIONS(-DHAVE_ICU)
59+
SET(ICU_LIBRARIES icuuc icudata)
5960
ELSE()
6061
MESSAGE(STATUS "Unable to find ICU library files, continuing")
6162
ENDIF()
@@ -170,13 +171,13 @@ ADD_EXECUTABLE(IfcConvert
170171
../src/ifcconvert/util.cpp
171172
)
172173

173-
TARGET_LINK_LIBRARIES (IfcConvert IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKSTEP TKSTEPBase TKSTEPAttr TKXSBase TKSTEP209 TKIGES TKOffset ${Boost_LIBRARIES} ${OPENCOLLADA_LIBRARIES})
174+
TARGET_LINK_LIBRARIES (IfcConvert IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKSTEP TKSTEPBase TKSTEPAttr TKXSBase TKSTEP209 TKIGES TKOffset ${Boost_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${ICU_LIBRARIES})
174175

175176
ADD_EXECUTABLE(IfcGeomServer
176177
../src/ifcgeomserver/IfcGeomServer.cpp
177178
)
178179

179-
TARGET_LINK_LIBRARIES (IfcGeomServer IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKSTEP TKSTEPBase TKSTEPAttr TKXSBase TKSTEP209 TKIGES TKOffset)
180+
TARGET_LINK_LIBRARIES (IfcGeomServer IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKSTEP TKSTEPBase TKSTEPAttr TKXSBase TKSTEP209 TKIGES TKOffset ${ICU_LIBRARIES})
180181

181182
# Build python wrapper using separate CMakeLists.txt
182183
ADD_SUBDIRECTORY(../src/ifcwrap ifcwrap)

src/ifcopenshell-python/ifcopenshell/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def __setitem__(self, idx, value):
8282
attr_type = self.attribute_type(idx).title().replace(' ', '')
8383
attr_type = attr_type.replace('Binary', 'String')
8484
attr_type = attr_type.replace('Enumeration', 'String')
85+
try:
86+
if isinstance(value, unicode): value = value.encode("utf-8")
87+
except: pass
8588
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
8689
return value
8790
def __len__(self): return len(self.wrapped_data)

src/ifcparse/IfcCharacterDecoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ UErrorCode IfcCharacterDecoder::status = U_ZERO_ERROR;
288288
#endif
289289

290290
#ifdef HAVE_ICU
291-
IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::JSON;
291+
IfcCharacterDecoder::ConversionMode IfcCharacterDecoder::mode = IfcCharacterDecoder::UTF8;
292292

293293
// Many BIM software (eg. Revit, ArchiCAD, ...) has wrong behavior
294294
bool IfcCharacterDecoder::compatibility_mode = false;

src/ifcwrap/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SET(CMAKE_SWIG_FLAGS "")
1616

1717
SET_SOURCE_FILES_PROPERTIES(IfcPython.i PROPERTIES CPLUSPLUS ON)
1818
SWIG_ADD_MODULE(ifcopenshell_wrapper python IfcPython.i)
19-
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${PYTHON_LIBRARIES} IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKOffset)
19+
SWIG_LINK_LIBRARIES(ifcopenshell_wrapper ${PYTHON_LIBRARIES} IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKOffset ${ICU_LIBRARIES})
2020

2121
# To install IfcPython let's get the site-packages dir from python
2222
EXECUTE_PROCESS(COMMAND python -c "import sys; from distutils.sysconfig import get_python_lib; sys.stdout.write(get_python_lib())"

src/ifcwrap/utils/type_conversion.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
PyObject* pythonize(const unsigned int& t) { return PyInt_FromLong(t); }
111111
PyObject* pythonize(const bool& t) { return PyBool_FromLong(t); }
112112
PyObject* pythonize(const double& t) { return PyFloat_FromDouble(t); }
113-
PyObject* pythonize(const std::string& t) { return PyString_FromString(t.c_str()); }
113+
PyObject* pythonize(const std::string& t) { return PyUnicode_FromString(t.c_str()); }
114114
PyObject* pythonize(const IfcUtil::IfcBaseClass* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcParse__IfcLateBoundEntity, 0); }
115115
// NB: This cannot be temporary as a Python object is constructed from a pointer to the address of this object
116116
PyObject* pythonize(const IfcGeom::Material& t) { return SWIG_NewPointerObj(SWIG_as_voidptr(&t), SWIGTYPE_p_IfcGeom__Material, 0); }

0 commit comments

Comments
 (0)