2011-05-08 11:04:32 +00:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* 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 <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
%include "std_vector.i"
|
|
|
|
|
%include "std_string.i"
|
2012-10-21 17:54:09 +02:00
|
|
|
%include "exception.i"
|
2011-05-08 11:04:32 +00:00
|
|
|
|
2014-02-22 11:38:03 +01:00
|
|
|
%ignore IfcParse::IfcUntypedEntity::is;
|
|
|
|
|
%ignore IfcParse::IfcUntypedEntity::type;
|
|
|
|
|
%ignore IfcParse::IfcUntypedEntity::getArgument;
|
|
|
|
|
%ignore IfcParse::IfcUntypedEntity::IfcUntypedEntity(IfcAbstractEntity);
|
2012-10-21 17:54:09 +02:00
|
|
|
|
|
|
|
|
%ignore IfcParse::IfcFile::Init;
|
|
|
|
|
%ignore IfcParse::IfcFile::EntityById;
|
|
|
|
|
%ignore IfcParse::IfcFile::EntityByGuid;
|
|
|
|
|
%ignore IfcParse::IfcFile::AddEntity;
|
|
|
|
|
%ignore operator<<;
|
|
|
|
|
|
|
|
|
|
%rename("by_type") EntitiesByType;
|
2014-06-20 14:18:29 +02:00
|
|
|
%rename("__len__") getArgumentCount;
|
2012-10-21 17:54:09 +02:00
|
|
|
%rename("get_argument_type") getArgumentType;
|
|
|
|
|
%rename("get_argument_name") getArgumentName;
|
|
|
|
|
%rename("get_argument_index") getArgumentIndex;
|
2013-07-21 13:31:24 -03:00
|
|
|
%rename("_set_argument") setArgument;
|
2012-10-21 17:54:09 +02:00
|
|
|
%rename("__repr__") toString;
|
2014-06-20 14:18:29 +02:00
|
|
|
%rename("entity_instance") IfcUntypedEntity;
|
|
|
|
|
%rename("file") IfcFile;
|
2012-10-21 17:54:09 +02:00
|
|
|
|
2013-07-27 15:55:23 -07:00
|
|
|
%typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) IfcEntities {
|
|
|
|
|
$1 = (PySequence_Check($input) && !PyUnicode_Check($input) && !PyString_Check($input)) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%typemap(in) IfcEntities {
|
|
|
|
|
if (PySequence_Check($input)) {
|
2014-02-22 11:38:03 +01:00
|
|
|
// $1 = std::make_shared<IfcEntityList>();
|
2013-08-02 11:48:26 -03:00
|
|
|
$1 = SHARED_PTR<IfcEntityList>(new IfcEntityList());
|
2013-07-27 15:55:23 -07:00
|
|
|
for(Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
|
|
|
|
|
PyObject* obj = PySequence_GetItem($input, i);
|
|
|
|
|
if (obj) {
|
|
|
|
|
void *arg = 0;
|
2014-02-22 11:38:03 +01:00
|
|
|
int res = SWIG_ConvertPtr(obj, &arg, SWIGTYPE_p_IfcParse__IfcUntypedEntity, 0);
|
2013-07-27 15:55:23 -07:00
|
|
|
if (!SWIG_IsOK(res)) {
|
2014-02-22 11:38:03 +01:00
|
|
|
SWIG_exception_fail(SWIG_ArgError(res), "in method '" "Entity__set_argument" "', argument " "3"" of type '" "IfcParse::IfcUntypedEntity *""'");
|
2013-07-27 15:55:23 -07:00
|
|
|
} else {
|
2014-02-22 11:38:03 +01:00
|
|
|
$1->push(reinterpret_cast<IfcParse::IfcUntypedEntity*>(arg));
|
2013-07-27 15:55:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
SWIG_exception(SWIG_RuntimeError,"Unknown argument type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-21 17:54:09 +02:00
|
|
|
%typemap(out) IfcEntities {
|
2013-07-21 13:31:24 -03:00
|
|
|
const unsigned size = $1 ? $1->Size() : 0;
|
2012-10-21 17:54:09 +02:00
|
|
|
$result = PyList_New(size);
|
|
|
|
|
for (unsigned i = 0; i < size; ++i) {
|
2014-02-22 11:38:03 +01:00
|
|
|
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr((*$1)[i]), SWIGTYPE_p_IfcParse__IfcUntypedEntity, 0);
|
2012-10-21 17:54:09 +02:00
|
|
|
PyList_SetItem($result,i,o);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 16:37:21 +02:00
|
|
|
%typemap(out) IfcUtil::ArgumentType {
|
|
|
|
|
const char* strs[] = {"INT", "BOOL", "DOUBLE", "STRING", "VECTOR_INT", "VECTOR_DOUBLE", "VECTOR_STRING", "ENTITY", "ENTITY_LIST", "ENTITY_LIST_LIST", "ENUMERATION", "DERIVED", "UNKNOWN"};
|
|
|
|
|
$result = SWIG_Python_str_FromChar(strs[$1]);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-21 17:54:09 +02:00
|
|
|
%typemap(out) std::pair<IfcUtil::ArgumentType,ArgumentPtr> {
|
|
|
|
|
const Argument& arg = *($1.second);
|
2014-02-22 11:38:03 +01:00
|
|
|
const IfcUtil::ArgumentType type = $1.first;
|
2014-07-04 16:37:21 +02:00
|
|
|
if (arg.isNull() || type == IfcUtil::Argument_DERIVED) {
|
2013-07-22 20:09:38 -07:00
|
|
|
Py_INCREF(Py_None);
|
2012-10-21 17:54:09 +02:00
|
|
|
$result = Py_None;
|
|
|
|
|
} else {
|
|
|
|
|
switch(type) {
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_INT:
|
2012-10-21 17:54:09 +02:00
|
|
|
$result = PyInt_FromLong((int)arg);
|
|
|
|
|
break;
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_BOOL:
|
2012-10-21 17:54:09 +02:00
|
|
|
$result = PyBool_FromLong((bool)arg);
|
|
|
|
|
break;
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_DOUBLE:
|
2012-10-21 17:54:09 +02:00
|
|
|
$result = PyFloat_FromDouble(arg);
|
|
|
|
|
break;
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_ENUMERATION:
|
|
|
|
|
case IfcUtil::Argument_STRING: {
|
2012-10-21 17:54:09 +02:00
|
|
|
const std::string s = arg;
|
|
|
|
|
$result = PyString_FromString(s.c_str());
|
|
|
|
|
break; }
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_VECTOR_INT: {
|
2012-10-21 17:54:09 +02:00
|
|
|
const std::vector<int> v = arg;
|
|
|
|
|
const unsigned size = v.size();
|
|
|
|
|
$result = PyList_New(size);
|
|
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
|
PyList_SetItem($result,i,PyInt_FromLong(v[i]));
|
|
|
|
|
}
|
|
|
|
|
break; }
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_VECTOR_DOUBLE: {
|
2012-10-21 17:54:09 +02:00
|
|
|
const std::vector<double> v = arg;
|
|
|
|
|
const unsigned size = v.size();
|
|
|
|
|
$result = PyList_New(size);
|
|
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
|
PyList_SetItem($result,i,PyFloat_FromDouble(v[i]));
|
|
|
|
|
}
|
|
|
|
|
break; }
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_VECTOR_STRING: {
|
2012-10-21 17:54:09 +02:00
|
|
|
const std::vector<std::string> v = arg;
|
|
|
|
|
const unsigned size = v.size();
|
|
|
|
|
$result = PyList_New(size);
|
|
|
|
|
for (unsigned int i = 0; i < size; ++i) {
|
|
|
|
|
PyList_SetItem($result,i,PyString_FromString(v[i].c_str()));
|
|
|
|
|
}
|
|
|
|
|
break; }
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_ENTITY: {
|
2012-10-21 17:54:09 +02:00
|
|
|
IfcUtil::IfcSchemaEntity e = arg;
|
2014-02-22 11:38:03 +01:00
|
|
|
$result = SWIG_NewPointerObj(SWIG_as_voidptr(e), SWIGTYPE_p_IfcParse__IfcUntypedEntity, 0);
|
2012-10-21 17:54:09 +02:00
|
|
|
break; }
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_ENTITY_LIST: {
|
2012-10-21 17:54:09 +02:00
|
|
|
IfcEntities es = arg;
|
|
|
|
|
const unsigned size = es->Size();
|
|
|
|
|
$result = PyList_New(size);
|
|
|
|
|
for (unsigned i = 0; i < size; ++i) {
|
2014-02-22 11:38:03 +01:00
|
|
|
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr((*es)[i]), SWIGTYPE_p_IfcParse__IfcUntypedEntity, 0);
|
2012-10-21 17:54:09 +02:00
|
|
|
PyList_SetItem($result,i,o);
|
|
|
|
|
}
|
|
|
|
|
break; }
|
2014-02-22 11:38:03 +01:00
|
|
|
case IfcUtil::Argument_UNKNOWN:
|
2012-10-21 17:54:09 +02:00
|
|
|
default:
|
|
|
|
|
SWIG_exception(SWIG_RuntimeError,"Unknown argument type");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%exception {
|
|
|
|
|
try {
|
|
|
|
|
$action
|
|
|
|
|
} catch(::IfcParse::IfcException& e) {
|
|
|
|
|
SWIG_exception(SWIG_RuntimeError,e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-08 11:04:32 +00:00
|
|
|
|
2014-06-20 14:18:29 +02:00
|
|
|
%module ifc_wrapper %{
|
2012-10-21 17:54:09 +02:00
|
|
|
#include "../ifcparse/IfcException.h"
|
|
|
|
|
#include "Interface.h"
|
|
|
|
|
using namespace IfcParse;
|
2011-05-08 11:04:32 +00:00
|
|
|
%}
|
|
|
|
|
|
2012-10-21 17:54:09 +02:00
|
|
|
%include "Interface.h"
|
|
|
|
|
|
|
|
|
|
%extend IfcParse::IfcFile {
|
2014-02-22 11:38:03 +01:00
|
|
|
IfcParse::IfcUntypedEntity* by_id(unsigned id) {
|
2012-10-21 17:54:09 +02:00
|
|
|
return (IfcUntypedEntity*) $self->EntityById(id);
|
|
|
|
|
}
|
2014-02-22 11:38:03 +01:00
|
|
|
IfcParse::IfcUntypedEntity* by_guid(const std::string& guid) {
|
2012-10-21 17:54:09 +02:00
|
|
|
return (IfcUntypedEntity*) $self->EntityByGuid(guid);
|
|
|
|
|
}
|
2014-02-22 11:38:03 +01:00
|
|
|
void add(IfcParse::IfcUntypedEntity* e) {
|
2012-10-21 17:54:09 +02:00
|
|
|
$self->AddEntity(e);
|
|
|
|
|
}
|
|
|
|
|
void write(const std::string& fn) {
|
2013-07-21 13:41:27 -03:00
|
|
|
std::ofstream f(fn.c_str());
|
2012-10-21 17:54:09 +02:00
|
|
|
f << (*$self);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 11:38:03 +01:00
|
|
|
%extend IfcParse::IfcUntypedEntity {
|
2013-07-21 13:31:24 -03:00
|
|
|
%pythoncode %{
|
|
|
|
|
set_argument = lambda self,x,y: self._set_argument(x) if y is None else self._set_argument(x,y)
|
|
|
|
|
%}
|
|
|
|
|
}
|
2012-10-21 17:54:09 +02:00
|
|
|
|
2011-05-08 11:04:32 +00:00
|
|
|
namespace std {
|
2014-06-20 14:18:29 +02:00
|
|
|
%template(ints) vector<int>;
|
|
|
|
|
%template(doubles) vector<double>;
|
|
|
|
|
%template(strings) vector<string>;
|
2013-07-21 13:41:27 -03:00
|
|
|
};
|