| 259 | } |
| 260 | |
| 261 | void Document::importLibrary(const ConstDocumentPtr& library) |
| 262 | { |
| 263 | if (!library) |
| 264 | { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | for (auto child : library->getChildren()) |
| 269 | { |
| 270 | if (child->getCategory().empty()) |
| 271 | { |
| 272 | throw Exception("Trying to import child without a category: " + child->getName()); |
| 273 | } |
| 274 | |
| 275 | const string childName = child->getQualifiedName(child->getName()); |
| 276 | |
| 277 | // Check for duplicate elements. |
| 278 | ConstElementPtr previous = getChild(childName); |
| 279 | if (previous) |
| 280 | { |
| 281 | continue; |
| 282 | } |
| 283 | |
| 284 | // Create the imported element. |
| 285 | ElementPtr childCopy = addChildOfCategory(child->getCategory(), childName); |
| 286 | childCopy->copyContentFrom(child); |
| 287 | if (!childCopy->hasFilePrefix() && library->hasFilePrefix()) |
| 288 | { |
| 289 | childCopy->setFilePrefix(library->getFilePrefix()); |
| 290 | } |
| 291 | if (!childCopy->hasGeomPrefix() && library->hasGeomPrefix()) |
| 292 | { |
| 293 | childCopy->setGeomPrefix(library->getGeomPrefix()); |
| 294 | } |
| 295 | if (!childCopy->hasColorSpace() && library->hasColorSpace()) |
| 296 | { |
| 297 | childCopy->setColorSpace(library->getColorSpace()); |
| 298 | } |
| 299 | if (!childCopy->hasNamespace() && library->hasNamespace()) |
| 300 | { |
| 301 | childCopy->setNamespace(library->getNamespace()); |
| 302 | } |
| 303 | if (!childCopy->hasSourceUri() && library->hasSourceUri()) |
| 304 | { |
| 305 | childCopy->setSourceUri(library->getSourceUri()); |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | StringSet Document::getReferencedSourceUris() const |
| 311 | { |