mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
IfcBlender: provide a temporary workaround for interfacing from a UCS2 Blender Python
A real solution could be to compile IfcGeom into a dynamic library and compile multiple versions of _IfcImport.so for different configurations which are selected based on sys.maxunicode Another alternative would be not to rely on strings when exchanging textual data but vectors of int that contain the string character codes
This commit is contained in:
@@ -44,11 +44,15 @@ if "bpy" in locals():
|
||||
if "IfcImport" in locals():
|
||||
imp.reload(IfcImport)
|
||||
|
||||
import sys
|
||||
import bpy
|
||||
import mathutils
|
||||
from bpy.props import StringProperty, IntProperty, BoolProperty
|
||||
from bpy_extras.io_utils import ImportHelper
|
||||
|
||||
wrong_unicode = sys.platform[0:5] == 'linux' and sys.maxunicode==(2**16-1)
|
||||
warned_about_wrong_unicode = False
|
||||
|
||||
bpy.types.Object.ifc_id = IntProperty(name="IFC Entity ID",
|
||||
description="The STEP entity instance name")
|
||||
bpy.types.Object.ifc_guid = StringProperty(name="IFC Entity GUID",
|
||||
@@ -62,7 +66,7 @@ bpy.types.Object.ifc_type = StringProperty(name="IFC Entity Type",
|
||||
def import_ifc(filename, use_names, process_relations):
|
||||
from . import IfcImport
|
||||
print("Reading %s..."%bpy.path.basename(filename))
|
||||
if not IfcImport.Init(filename):
|
||||
if (wrong_unicode and not IfcImport.InitUCS2(''.join(['\0']+['\0%s'%s for s in filename]+['\0\0']))) or (not wrong_unicode and not IfcImport.Init(filename)):
|
||||
return False
|
||||
print("Done reading file")
|
||||
id_to_object = {}
|
||||
@@ -205,6 +209,16 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
|
||||
default=False)
|
||||
|
||||
def execute(self, context):
|
||||
global wrong_unicode,warned_about_wrong_unicode
|
||||
if wrong_unicode and not warned_about_wrong_unicode:
|
||||
warned_about_wrong_unicode = True
|
||||
self.report({'WARNING'},
|
||||
"""This addon has been built with a different unicode configuration
|
||||
This will result in incorrectly imported text and may result in undefined behaviour
|
||||
Additionally it will result in IfcSpaces and IfcOpeningElements being visible by default
|
||||
You can use the offical builds from the blender.org website instead
|
||||
Sorry for the inconvenience"""
|
||||
)
|
||||
if not import_ifc(self.filepath, self.use_names, self.process_relations):
|
||||
self.report({'ERROR'},
|
||||
'Unable to parse .ifc file or no geometrical entities found'
|
||||
|
||||
@@ -435,6 +435,9 @@ const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() {
|
||||
bool IfcGeomObjects::Init(const std::string fn) {
|
||||
return IfcGeomObjects::Init(fn, 0, 0);
|
||||
}
|
||||
bool IfcGeomObjects::InitUCS2(char* fn) {
|
||||
return IfcGeomObjects::Init(fn+1, 0, 0);
|
||||
}
|
||||
bool _Init() {
|
||||
shapereps = Ifc::EntitiesByType<Ifc2x3::IfcShapeRepresentation>();
|
||||
if ( ! shapereps ) return false;
|
||||
|
||||
@@ -116,6 +116,7 @@ namespace IfcGeomObjects {
|
||||
};
|
||||
|
||||
bool Init(const std::string fn);
|
||||
bool InitUCS2(char* fn);
|
||||
bool Init(void* data, int len);
|
||||
bool Init(const std::string fn, std::ostream* log1= 0, std::ostream* log2= 0);
|
||||
bool Init(std::istream& f, int len, std::ostream* log1= 0, std::ostream* log2= 0);
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace IfcGeomObjects {
|
||||
bool Next();
|
||||
const IfcGeomObject* Get();
|
||||
bool Init(const std::string fn);
|
||||
bool InitUCS2(char* fn);
|
||||
void Settings(int setting, bool value);
|
||||
int Progress();
|
||||
const IfcObject* GetObject(int id);
|
||||
|
||||
Reference in New Issue
Block a user