| 1240 | } |
| 1241 | |
| 1242 | boost::optional<model::ModelObject> ReverseTranslator::translateSurface(const pugi::xml_node& element, openstudio::model::Space& space) { |
| 1243 | boost::optional<model::ModelObject> result; |
| 1244 | |
| 1245 | UnitSystem siSys(UnitSystem::SI); |
| 1246 | |
| 1247 | std::vector<openstudio::Point3d> vertices; |
| 1248 | |
| 1249 | pugi::xml_node polyLoopElement = element.child("PolyLp"); |
| 1250 | if (!polyLoopElement) { |
| 1251 | LOG(Error, "Surface element 'PolyLp' is empty, cannot create Surface."); |
| 1252 | return boost::none; |
| 1253 | } |
| 1254 | |
| 1255 | std::vector<pugi::xml_node> cartesianPointElements = makeVectorOfChildren(polyLoopElement, "CartesianPt"); |
| 1256 | for (std::vector<pugi::xml_node>::size_type i = 0; i < cartesianPointElements.size(); i++) { |
| 1257 | std::vector<pugi::xml_node> coordinateElements = makeVectorOfChildren(cartesianPointElements[i], "Coord"); |
| 1258 | if (coordinateElements.size() != 3) { |
| 1259 | LOG(Error, "PolyLp element 'CartesianPt' does not have exactly 3 'Coord' elements, cannot create Surface."); |
| 1260 | return boost::none; |
| 1261 | } |
| 1262 | |
| 1263 | /* DLM: these unit conversions are taking about 75% of the total time to translate a large model |
| 1264 | |
| 1265 | // sdd units = ft, os units = m |
| 1266 | Quantity xIP(coordinateElements.at(0).toElement().text().as_double(), IPUnit(IPExpnt(0,1,0))); |
| 1267 | Quantity yIP(coordinateElements.at(1).toElement().text().as_double(), IPUnit(IPExpnt(0,1,0))); |
| 1268 | Quantity zIP(coordinateElements.at(2).toElement().text().as_double(), IPUnit(IPExpnt(0,1,0))); |
| 1269 | |
| 1270 | OptionalQuantity xSI = QuantityConverter::instance().convert(xIP, siSys); |
| 1271 | OS_ASSERT(xSI); |
| 1272 | OS_ASSERT(xSI->units() == SIUnit(SIExpnt(0,1,0))); |
| 1273 | |
| 1274 | OptionalQuantity ySI = QuantityConverter::instance().convert(yIP, siSys); |
| 1275 | OS_ASSERT(ySI); |
| 1276 | OS_ASSERT(ySI->units() == SIUnit(SIExpnt(0,1,0))); |
| 1277 | |
| 1278 | OptionalQuantity zSI = QuantityConverter::instance().convert(zIP, siSys); |
| 1279 | OS_ASSERT(zSI); |
| 1280 | OS_ASSERT(zSI->units() == SIUnit(SIExpnt(0,1,0))); |
| 1281 | |
| 1282 | vertices.push_back(openstudio::Point3d(xSI->value(), ySI->value(), zSI->value())); |
| 1283 | */ |
| 1284 | |
| 1285 | double x = footToMeter * coordinateElements[0].text().as_double(); |
| 1286 | double y = footToMeter * coordinateElements[1].text().as_double(); |
| 1287 | double z = footToMeter * coordinateElements[2].text().as_double(); |
| 1288 | vertices.push_back(openstudio::Point3d(x, y, z)); |
| 1289 | } |
| 1290 | |
| 1291 | openstudio::model::Surface surface(vertices, space.model()); |
| 1292 | surface.setSpace(space); |
| 1293 | |
| 1294 | pugi::xml_node nameElement = element.child("Name"); |
| 1295 | std::string name; |
| 1296 | if (!nameElement) { |
| 1297 | LOG(Error, "Surface element 'Name' is empty.") |
| 1298 | } else { |
| 1299 | name = escapeName(nameElement.text().as_string()); |
nothing calls this directly
no test coverage detected