| 336 | }; |
| 337 | |
| 338 | void importFromStream(std::istream& stream) |
| 339 | { |
| 340 | GlobalSelectionSystem().setSelectedAll(false); |
| 341 | |
| 342 | // Instantiate the default import filter |
| 343 | SimpleMapImportFilter importFilter; |
| 344 | |
| 345 | try |
| 346 | { |
| 347 | auto format = determineMapFormat(stream); |
| 348 | |
| 349 | if (!format) |
| 350 | { |
| 351 | throw IMapReader::FailureException(_("Unknown map format")); |
| 352 | } |
| 353 | |
| 354 | auto reader = format->getMapReader(importFilter); |
| 355 | |
| 356 | // Start parsing |
| 357 | reader->readFromStream(stream); |
| 358 | |
| 359 | // Prepare child primitives |
| 360 | scene::addOriginToChildPrimitives(importFilter.getRootNode()); |
| 361 | |
| 362 | // Adjust all new names to fit into the existing map namespace |
| 363 | prepareNamesForImport(GlobalMap().getRoot(), importFilter.getRootNode()); |
| 364 | |
| 365 | importMap(importFilter.getRootNode()); |
| 366 | } |
| 367 | catch (IMapReader::FailureException& ex) |
| 368 | { |
| 369 | // Clear out the root node, otherwise we end up with half a map |
| 370 | scene::NodeRemover remover; |
| 371 | importFilter.getRootNode()->traverseChildren(remover); |
| 372 | |
| 373 | throw cmd::ExecutionFailure(fmt::format(_("Failure reading map from clipboard:\n{0}"), ex.what())); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | } |
| 378 |
no test coverage detected