| 1278 | } |
| 1279 | |
| 1280 | IfcUtil::IfcBaseEntity* mapping::representation_of(const IfcUtil::IfcBaseEntity* product) { |
| 1281 | // @todo correct, but very inefficient |
| 1282 | IfcSchema::IfcRepresentation::list::ptr representations(new IfcSchema::IfcRepresentation::list); |
| 1283 | IfcSchema::IfcRepresentation::list::ptr of_product(new IfcSchema::IfcRepresentation::list); |
| 1284 | IfcSchema::IfcRepresentation::list::ptr intersection(new IfcSchema::IfcRepresentation::list); |
| 1285 | IfcSchema::IfcRepresentation::list::ptr intersection_no_box(new IfcSchema::IfcRepresentation::list); |
| 1286 | |
| 1287 | if (!settings_.get<settings::ContextIds>().has()) { |
| 1288 | addRepresentationsFromDefaultContexts(representations); |
| 1289 | } else { |
| 1290 | addRepresentationsFromContextIds(representations); |
| 1291 | } |
| 1292 | |
| 1293 | if (product->as<IfcSchema::IfcProduct>()->Representation()) { |
| 1294 | of_product->push(product->as<IfcSchema::IfcProduct>()->Representation()->Representations()); |
| 1295 | } |
| 1296 | |
| 1297 | for (auto& r : *of_product) { |
| 1298 | if (representations->contains(r)) { |
| 1299 | intersection->push(r); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | if (intersection->size() == 0 && settings_.get<settings::ContextIds>().has() && this->settings_.get<settings::OutputDimensionality>().get() == settings::CURVES) { |
| 1304 | for (auto& r : *of_product) { |
| 1305 | if (r->RepresentationIdentifier() && *r->RepresentationIdentifier() == "Axis") { |
| 1306 | intersection->push(r); |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | if (intersection->size() == 0) { |
| 1312 | return nullptr; |
| 1313 | } else { |
| 1314 | for (auto& r : *intersection) { |
| 1315 | if (IfcParse::traverse((r))->as<IfcSchema::IfcBoundingBox>()->size()) { |
| 1316 | continue; |
| 1317 | } |
| 1318 | intersection_no_box->push(r); |
| 1319 | } |
| 1320 | if (intersection_no_box->size() > 1) { |
| 1321 | Logger::Warning("Multiple applicable representations found for element, selecting arbitrary"); |
| 1322 | } |
| 1323 | if (intersection_no_box->size()) { |
| 1324 | return (*intersection_no_box->begin())->as<IfcUtil::IfcBaseEntity>(); |
| 1325 | } else { |
| 1326 | return (*intersection->begin())->as<IfcUtil::IfcBaseEntity>(); |
| 1327 | } |
| 1328 | } |
| 1329 | } |