|
26 | 26 | #include "../ifcparse/IfcCharacterDecoder.h" |
27 | 27 | #include "../ifcparse/IfcFile.h" |
28 | 28 |
|
| 29 | +#ifdef USE_IFC4 |
| 30 | +#include "../ifcparse/Ifc4-latebound.h" |
| 31 | +#else |
| 32 | +#include "../ifcparse/Ifc2x3-latebound.h" |
| 33 | +#endif |
| 34 | + |
29 | 35 | using namespace IfcWrite; |
30 | 36 |
|
31 | 37 | IfcWritableEntity::IfcWritableEntity(IfcSchema::Type::Enum t) { |
@@ -56,8 +62,7 @@ IfcWritableEntity::IfcWritableEntity(IfcAbstractEntity* e) |
56 | 62 |
|
57 | 63 | const unsigned int count = e->getArgumentCount(); |
58 | 64 | for ( unsigned int i = 0; i < count; ++ i ) { |
59 | | - args[i] = e->getArgument(i); |
60 | | - writemask[i] = false; |
| 65 | + this->setArgument(i, e->getArgument(i)); |
61 | 66 | } |
62 | 67 | } |
63 | 68 |
|
@@ -131,6 +136,76 @@ template <typename T> void IfcWritableEntity::_setArgument(int i, const T& t) { |
131 | 136 | void IfcWritableEntity::setArgument(int i) { |
132 | 137 | _setArgument(i, boost::none); |
133 | 138 | } |
| 139 | + |
| 140 | +void IfcWritableEntity::setArgument(int i, Argument* a) { |
| 141 | + IfcWrite::IfcWriteArgument* wa = new IfcWrite::IfcWriteArgument(this); |
| 142 | + IfcUtil::ArgumentType attr_type = a->type(); |
| 143 | + switch(attr_type) { |
| 144 | + case IfcUtil::Argument_NULL: |
| 145 | + this->setArgument(i); |
| 146 | + break; |
| 147 | + case IfcUtil::Argument_DERIVED: |
| 148 | + this->setArgumentDerived(i); |
| 149 | + break; |
| 150 | + case IfcUtil::Argument_INT: |
| 151 | + this->setArgument(i, static_cast<int>(*a)); |
| 152 | + break; |
| 153 | + case IfcUtil::Argument_BOOL: |
| 154 | + this->setArgument(i, static_cast<bool>(*a)); |
| 155 | + break; |
| 156 | + case IfcUtil::Argument_DOUBLE: |
| 157 | + this->setArgument(i, static_cast<double>(*a)); |
| 158 | + break; |
| 159 | + case IfcUtil::Argument_STRING: |
| 160 | + this->setArgument(i, static_cast<std::string>(*a)); |
| 161 | + break; |
| 162 | + case IfcUtil::Argument_VECTOR_INT: |
| 163 | + this->setArgument(i, static_cast< std::vector<int> >(*a)); |
| 164 | + break; |
| 165 | + case IfcUtil::Argument_VECTOR_DOUBLE: |
| 166 | + this->setArgument(i, static_cast< std::vector<double> >(*a)); |
| 167 | + break; |
| 168 | + case IfcUtil::Argument_VECTOR_STRING: |
| 169 | + this->setArgument(i, static_cast< std::vector< std::string > >(*a)); |
| 170 | + break; |
| 171 | + case IfcUtil::Argument_ENUMERATION: { |
| 172 | + IfcSchema::Type::Enum ty = IfcSchema::Type::GetAttributeEntity(_type, i); |
| 173 | + std::string enum_literal = a->toString(); |
| 174 | + // Remove leading and trailing '.' |
| 175 | + enum_literal = enum_literal.substr(1, enum_literal.size() - 2); |
| 176 | + std::pair<const char*, int> enum_ref = IfcSchema::Type::GetEnumerationIndex(ty, enum_literal); |
| 177 | + this->setArgument(i, enum_ref.second, enum_ref.first); } |
| 178 | + break; |
| 179 | + case IfcUtil::Argument_ENTITY: { |
| 180 | + this->setArgument(i, static_cast<IfcUtil::IfcBaseClass*>(*a)); } |
| 181 | + break; |
| 182 | + case IfcUtil::Argument_ENTITY_LIST: { |
| 183 | + IfcEntityList::ptr instances = *a; |
| 184 | + IfcEntityList::ptr mapped_instances(new IfcEntityList); |
| 185 | + for (IfcEntityList::it it = instances->begin(); it != instances->end(); ++it) { |
| 186 | + mapped_instances->push(*it); |
| 187 | + } |
| 188 | + this->setArgument(i, mapped_instances); } |
| 189 | + break; |
| 190 | + case IfcUtil::Argument_ENTITY_LIST_LIST: { |
| 191 | + IfcEntityListList::ptr instances = *a; |
| 192 | + IfcEntityListList::ptr mapped_instances(new IfcEntityListList); |
| 193 | + for (IfcEntityListList::outer_it it = instances->begin(); it != instances->end(); ++it) { |
| 194 | + std::vector<IfcUtil::IfcBaseClass*> inner; |
| 195 | + for (IfcEntityListList::inner_it jt = it->begin(); jt != it->end(); ++jt) { |
| 196 | + inner.push_back(*jt); |
| 197 | + } |
| 198 | + mapped_instances->push(inner); |
| 199 | + } |
| 200 | + this->setArgument(i, mapped_instances); } |
| 201 | + break; |
| 202 | + case IfcUtil::Argument_UNKNOWN: |
| 203 | + throw IfcParse::IfcException("Unknown argument encountered"); |
| 204 | + break; |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | + |
134 | 209 | void IfcWritableEntity::setArgumentDerived(int i) { |
135 | 210 | _setArgument(i, IfcWriteArgument::Derived()); |
136 | 211 | } |
|
0 commit comments