diff --git a/src/ifcgeom/IfcGeomObjects.h b/src/ifcgeom/IfcGeomObjects.h index f24af91d49..15efe0d4a9 100644 --- a/src/ifcgeom/IfcGeomObjects.h +++ b/src/ifcgeom/IfcGeomObjects.h @@ -64,6 +64,7 @@ #include #include +#include "../ifcparse/IfcParse.h" #include "../ifcgeom/IfcShapeList.h" namespace IfcGeomObjects { diff --git a/src/ifcjni/IfcJni.cpp b/src/ifcjni/IfcJni.cpp index 99579f0ed2..2eee1b4343 100644 --- a/src/ifcjni/IfcJni.cpp +++ b/src/ifcjni/IfcJni.cpp @@ -1,28 +1,28 @@ /******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ +* * +* This file is part of IfcOpenShell. * +* * +* IfcOpenShell is free software: you can redistribute it and/or modify * +* it under the terms of the Lesser GNU General Public License as published by * +* the Free Software Foundation, either version 3.0 of the License, or * +* (at your option) any later version. * +* * +* IfcOpenShell is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* Lesser GNU General Public License for more details. * +* * +* You should have received a copy of the Lesser GNU General Public License * +* along with this program. If not, see . * +* * +********************************************************************************/ /******************************************************************************** - * * - * This is a JNI interface to IfcOpenShell for use with the open source * - * http://BIMserver.org * - * * - ********************************************************************************/ +* * +* This is a JNI interface to IfcOpenShell for use with the open source * +* http://BIMserver.org * +* * +********************************************************************************/ #include "org_ifcopenshell_IfcOpenShellModel.h" #include "../ifcgeom/IfcGeomObjects.h" @@ -30,47 +30,56 @@ bool has_more = false; JNIEXPORT jobject JNICALL Java_org_ifcopenshell_IfcOpenShellModel_getGeometry (JNIEnv * env, jobject) { - if ( ! has_more ) return 0; - jclass class_def = env->FindClass ("org/ifcopenshell/IfcGeomObject"); - if ( ! class_def ) return 0; - jmethodID jconstructor = env->GetMethodID(class_def, "", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[I[F[F)V"); - if ( ! jconstructor ) return 0; - const IfcGeomObjects::IfcGeomObject* o = IfcGeomObjects::Get(); - - jstring name = env->NewStringUTF(o->name.c_str()); - jstring type = env->NewStringUTF(o->type.c_str()); - jstring guid = env->NewStringUTF(o->guid.c_str()); - - jintArray indices = env->NewIntArray(o->mesh->faces.size()); - jfloatArray positions = env->NewFloatArray(o->mesh->verts.size()); - jfloatArray normals = env->NewFloatArray(o->mesh->normals.size()); - - env->SetIntArrayRegion(indices,0,o->mesh->faces.size(),(jint*) &o->mesh->faces[0]); - env->SetFloatArrayRegion(positions,0,o->mesh->verts.size(),(jfloat*) &o->mesh->verts[0]); - env->SetFloatArrayRegion(normals,0,o->mesh->normals.size(),(jfloat*) &o->mesh->normals[0]); - - jobject return_obj = env->NewObject(class_def, jconstructor, o->id, name, type, guid, indices, positions, normals); - - env->DeleteLocalRef(name); - env->DeleteLocalRef(type); - env->DeleteLocalRef(guid); - env->DeleteLocalRef(indices); - env->DeleteLocalRef(positions); - env->DeleteLocalRef(normals); - env->DeleteLocalRef(class_def); + if ( ! has_more ) return 0; + jclass class_def = env->FindClass ("org/ifcopenshell/IfcGeomObject"); + if ( ! class_def ) return 0; + jmethodID jconstructor = env->GetMethodID(class_def, "", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[I[F[F)V"); + if ( ! jconstructor ) return 0; + const IfcGeomObjects::IfcGeomObject* o = IfcGeomObjects::Get(); - has_more = IfcGeomObjects::Next(); - if ( ! has_more ) IfcGeomObjects::CleanUp(); + jstring name = env->NewStringUTF(o->name.c_str()); + jstring type = env->NewStringUTF(o->type.c_str()); + jstring guid = env->NewStringUTF(o->guid.c_str()); - return return_obj; + jintArray indices = env->NewIntArray(o->mesh->faces.size()); + jfloatArray positions = env->NewFloatArray(o->mesh->verts.size()); + jfloatArray normals = env->NewFloatArray(o->mesh->normals.size()); + + env->SetIntArrayRegion(indices,0,o->mesh->faces.size(),(jint*) &o->mesh->faces[0]); + env->SetFloatArrayRegion(positions,0,o->mesh->verts.size(),(jfloat*) &o->mesh->verts[0]); + env->SetFloatArrayRegion(normals,0,o->mesh->normals.size(),(jfloat*) &o->mesh->normals[0]); + + jobject return_obj = env->NewObject(class_def, jconstructor, o->id, name, type, guid, indices, positions, normals); + + env->DeleteLocalRef(name); + env->DeleteLocalRef(type); + env->DeleteLocalRef(guid); + env->DeleteLocalRef(indices); + env->DeleteLocalRef(positions); + env->DeleteLocalRef(normals); + env->DeleteLocalRef(class_def); + + has_more = IfcGeomObjects::Next(); + if ( ! has_more ) IfcGeomObjects::CleanUp(); + + return return_obj; } JNIEXPORT jboolean JNICALL Java_org_ifcopenshell_IfcOpenShellModel_setIfcData (JNIEnv * env, jobject, jbyteArray jdata) { - void* data = env->GetByteArrayElements(jdata, NULL); - const int length = env->GetArrayLength(jdata); - if ( ! data || ! length ) return false; - IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,true); - IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,false); - IfcGeomObjects::Settings(IfcGeomObjects::CONVERT_BACK_UNITS,true); - return has_more = IfcGeomObjects::Init(data,length); + if ( ! jdata ) return false; + const int length = env->GetArrayLength(jdata); + jboolean is_copy = false; + jbyte* jbytes = env->GetByteArrayElements(jdata, &is_copy); + if ( ! jbytes || ! length ) return false; + void* data = new char[length]; + memcpy(data,jbytes,length); + env->ReleaseByteArrayElements(jdata, jbytes, JNI_ABORT); + IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS, true); + IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES, false); + IfcGeomObjects::Settings(IfcGeomObjects::CONVERT_BACK_UNITS, true); + return has_more = IfcGeomObjects::Init(data, length); +} + +JNIEXPORT jstring JNICALL Java_org_ifcopenshell_IfcOpenShellModel_getPluginVersion (JNIEnv * env, jobject) { + return env->NewStringUTF(IFCOPENSHELL_VERSION); } \ No newline at end of file diff --git a/src/ifcjni/org_ifcopenshell_IfcOpenShellModel.h b/src/ifcjni/org_ifcopenshell_IfcOpenShellModel.h index 6260f01618..ab4cdc1e0e 100644 --- a/src/ifcjni/org_ifcopenshell_IfcOpenShellModel.h +++ b/src/ifcjni/org_ifcopenshell_IfcOpenShellModel.h @@ -23,6 +23,14 @@ JNIEXPORT jobject JNICALL Java_org_ifcopenshell_IfcOpenShellModel_getGeometry JNIEXPORT jboolean JNICALL Java_org_ifcopenshell_IfcOpenShellModel_setIfcData (JNIEnv *, jobject, jbyteArray); +/* + * Class: org_ifcopenshell_IfcOpenShellModel + * Method: getPluginVersion + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ifcopenshell_IfcOpenShellModel_getPluginVersion + (JNIEnv *, jobject); + #ifdef __cplusplus } #endif diff --git a/src/ifcparse/IfcParse.h b/src/ifcparse/IfcParse.h index 37a1fde156..f13d1bff65 100644 --- a/src/ifcparse/IfcParse.h +++ b/src/ifcparse/IfcParse.h @@ -27,6 +27,8 @@ #ifndef IFCPARSE_H #define IFCPARSE_H +#define IFCOPENSHELL_VERSION "0.3.0-rc2" + #include #include #include