mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 03:14:23 +00:00
Allow optional arguments to be set from Python with None, e.g: ifc_person.set_argument(0, None)
This commit is contained in:
@@ -61,6 +61,12 @@ void Ifc::IfcUntypedEntity::invalid_argument(unsigned int i, const std::string&
|
||||
const std::string arg_name = Ifc2x3::Type::GetAttributeName(_type,i);
|
||||
throw IfcException(t + " is not a valid type for '" + arg_name + "'");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i) {
|
||||
bool is_optional = Ifc2x3::Type::GetAttributeOptional(_type, i);
|
||||
if (is_optional) {
|
||||
writable_entity()->setArgument(i);
|
||||
} else invalid_argument(i,"NONE");
|
||||
}
|
||||
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, int v) {
|
||||
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
|
||||
if (arg_type == Argument_INT) {
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Ifc {
|
||||
const char* getArgumentName(unsigned int i) const;
|
||||
unsigned getArgumentIndex(const std::string& a) const;
|
||||
|
||||
void setArgument(unsigned int iz);
|
||||
void setArgument(unsigned int i, int v);
|
||||
void setArgument(unsigned int i, bool v);
|
||||
void setArgument(unsigned int i, double v);
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
%rename("get_argument_type") getArgumentType;
|
||||
%rename("get_argument_name") getArgumentName;
|
||||
%rename("get_argument_index") getArgumentIndex;
|
||||
%rename("set_argument") setArgument;
|
||||
%rename("_set_argument") setArgument;
|
||||
%rename("__repr__") toString;
|
||||
%rename("Entity") IfcUntypedEntity;
|
||||
|
||||
@@ -144,11 +144,16 @@
|
||||
$self->AddEntity(e);
|
||||
}
|
||||
void write(const std::string& fn) {
|
||||
std::ofstream f(fn.c_str());
|
||||
std::ofstream f(fn);
|
||||
f << (*$self);
|
||||
}
|
||||
}
|
||||
|
||||
%extend Ifc::IfcUntypedEntity {
|
||||
%pythoncode %{
|
||||
set_argument = lambda self,x,y: self._set_argument(x) if y is None else self._set_argument(x,y)
|
||||
%}
|
||||
}
|
||||
|
||||
namespace std {
|
||||
%template(Ints) vector<int>;
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Ifc {
|
||||
const char* getArgumentName(unsigned int i) const;
|
||||
unsigned getArgumentIndex(const std::string& a) const;
|
||||
|
||||
void setArgument(unsigned int i);
|
||||
void setArgument(unsigned int i, int v);
|
||||
void setArgument(unsigned int i, bool v);
|
||||
void setArgument(unsigned int i, double v);
|
||||
|
||||
Reference in New Issue
Block a user