Skip to content

Commit 1065741

Browse files
committed
Allow optional arguments to be set from Python with None, e.g: ifc_person.set_argument(0, None)
1 parent e5abdb7 commit 1065741

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/ifcparse/IfcUntypedEntity.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ void Ifc::IfcUntypedEntity::invalid_argument(unsigned int i, const std::string&
6161
const std::string arg_name = Ifc2x3::Type::GetAttributeName(_type,i);
6262
throw IfcException(t + " is not a valid type for '" + arg_name + "'");
6363
}
64+
void Ifc::IfcUntypedEntity::setArgument(unsigned int i) {
65+
bool is_optional = Ifc2x3::Type::GetAttributeOptional(_type, i);
66+
if (is_optional) {
67+
writable_entity()->setArgument(i);
68+
} else invalid_argument(i,"NONE");
69+
}
6470
void Ifc::IfcUntypedEntity::setArgument(unsigned int i, int v) {
6571
IfcUtil::ArgumentType arg_type = Ifc2x3::Type::GetAttributeType(_type,i);
6672
if (arg_type == Argument_INT) {

src/ifcparse/IfcUntypedEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace Ifc {
2727
const char* getArgumentName(unsigned int i) const;
2828
unsigned getArgumentIndex(const std::string& a) const;
2929

30+
void setArgument(unsigned int iz);
3031
void setArgument(unsigned int i, int v);
3132
void setArgument(unsigned int i, bool v);
3233
void setArgument(unsigned int i, double v);

src/ifcwrap/IfcPython.i

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
%rename("get_argument_type") getArgumentType;
3838
%rename("get_argument_name") getArgumentName;
3939
%rename("get_argument_index") getArgumentIndex;
40-
%rename("set_argument") setArgument;
40+
%rename("_set_argument") setArgument;
4141
%rename("__repr__") toString;
4242
%rename("Entity") IfcUntypedEntity;
4343

@@ -144,11 +144,16 @@
144144
$self->AddEntity(e);
145145
}
146146
void write(const std::string& fn) {
147-
std::ofstream f(fn.c_str());
147+
std::ofstream f(fn);
148148
f << (*$self);
149149
}
150150
}
151151

152+
%extend Ifc::IfcUntypedEntity {
153+
%pythoncode %{
154+
set_argument = lambda self,x,y: self._set_argument(x) if y is None else self._set_argument(x,y)
155+
%}
156+
}
152157

153158
namespace std {
154159
%template(Ints) vector<int>;

src/ifcwrap/Interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Ifc {
2828
const char* getArgumentName(unsigned int i) const;
2929
unsigned getArgumentIndex(const std::string& a) const;
3030

31+
void setArgument(unsigned int i);
3132
void setArgument(unsigned int i, int v);
3233
void setArgument(unsigned int i, bool v);
3334
void setArgument(unsigned int i, double v);

0 commit comments

Comments
 (0)