logical handling in python and small fixes

This commit is contained in:
Thomas Krijnen
2021-07-29 16:32:45 +02:00
parent 7c3fcc26f4
commit 0d49c89943
8 changed files with 48 additions and 0 deletions
@@ -152,6 +152,8 @@ class entity_instance(object):
idx, entity_instance.unwrap_value(value)
)
except BaseException as e:
import traceback
traceback.print_exc()
valid = False
if not valid:
+5
View File
@@ -1212,6 +1212,11 @@ void IfcEntityInstanceData::setArgument(size_t i, Argument* a, IfcUtil::Argument
case IfcUtil::Argument_BOOL:
copy->set(static_cast<bool>(*a));
break;
case IfcUtil::Argument_LOGICAL: {
boost::logic::tribool tb = *a;
copy->set(tb);
break;
}
case IfcUtil::Argument_DOUBLE:
copy->set(static_cast<double>(*a));
break;
+1
View File
@@ -229,6 +229,7 @@ void StringBuilderVisitor::operator()(const std::vector< std::vector<double> >&
IfcWriteArgument::operator int() const { return as<int>(); }
IfcWriteArgument::operator bool() const { return as<bool>(); }
IfcWriteArgument::operator boost::logic::tribool() const { return as<boost::logic::tribool>(); }
IfcWriteArgument::operator double() const { return as<double>(); }
IfcWriteArgument::operator std::string() const {
if (type() == IfcUtil::Argument_ENUMERATION) {
+2
View File
@@ -145,6 +145,8 @@ namespace IfcWrite {
operator int() const;
operator bool() const;
operator boost::logic::tribool() const;
operator double() const;
operator std::string() const;
operator boost::dynamic_bitset<>() const;
+11
View File
@@ -326,6 +326,17 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
}
}
void setArgumentAsLogical(unsigned int i, boost::logic::tribool v) {
IfcUtil::ArgumentType arg_type = helper_fn_attribute_type($self, i);
if (arg_type == IfcUtil::Argument_LOGICAL) {
IfcWrite::IfcWriteArgument* arg = new IfcWrite::IfcWriteArgument();
arg->set(v);
self->data().setArgument(i, arg);
} else {
throw IfcParse::IfcException("Attribute not set");
}
}
void setArgumentAsDouble(unsigned int i, double v) {
IfcUtil::ArgumentType arg_type = helper_fn_attribute_type($self, i);
if (arg_type == IfcUtil::Argument_DOUBLE) {
+1
View File
@@ -123,6 +123,7 @@
PyObject* pythonize(const int& t) { return PyInt_FromLong(t); }
PyObject* pythonize(const unsigned int& t) { return PyInt_FromLong(t); }
PyObject* pythonize(const bool& t) { return PyBool_FromLong(t); }
PyObject* pythonize(const boost::logic::tribool& t) { return boost::logic::indeterminate(t) ? PyUnicode_FromString("UNKNOWN") : PyBool_FromLong((bool)t) ;}
PyObject* pythonize(const double& t) { return PyFloat_FromDouble(t); }
PyObject* pythonize(const std::string& t) { return PyUnicode_FromString(t.c_str()); }
PyObject* pythonize(const IfcUtil::IfcBaseClass* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcUtil__IfcBaseClass, 0); }
+22
View File
@@ -241,6 +241,28 @@ CREATE_VECTOR_TYPEMAP_IN(std::string, STRING, str)
$1 = check_aggregate_of_aggregate_of_type($input, get_python_type<double>());
}
%typemap(in) boost::logic::tribool {
if (PyBool_Check($input)) {
$1 = $input == Py_True;
} else if (PyUnicode_Check($input)) {
// we already checked the value of the string in the typecheck typemap
$1 = boost::logic::indeterminate;
} else {
SWIG_exception(SWIG_TypeError, "Logical needs boolean or \"UNKOWN\"");
}
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_INTEGER) boost::logic::tribool {
$1 = PyBool_Check($input);
if (!$1 && PyUnicode_Check($input)) {
PyObject * ascii = PyUnicode_AsEncodedString(result, "UTF-8", "strict");
if (ascii) {
$1 = strcmp(PyBytes_AS_STRING(ascii), "UNKNOWN") == 0;
Py_DECREF(ascii);
}
}
}
%define CREATE_OPTIONAL_TYPEMAP_IN(template_type, express_name, python_name)
%typemap(in) const boost::optional<template_type>& {
+4
View File
@@ -51,6 +51,10 @@
bool v = arg;
$result = pythonize(v);
break; }
case IfcUtil::Argument_LOGICAL: {
boost::logic::tribool v = arg;
$result = pythonize(v);
break; }
case IfcUtil::Argument_DOUBLE: {
double v = arg;
$result = pythonize(v);