QString Doc_plugin_interface::addBlockfromFromdisk(QString fullName){ if (fullName.isEmpty() || doc==NULL) return NULL; RS_BlockList* blockList = doc->getBlockList(); if (blockList==NULL) return NULL; QFileInfo fi(fullName); QString s = fi.completeBaseName(); QString name = s; if(blockList->find(name)){ for (int i=0; i<1e5; ++i) { name = QString("%1-%2").arg(s).arg(i); if (blockList->find(name)==NULL) { break; } } } if (fi.isReadable()) { RS_BlockData d(name, RS_Vector(0,0), false); RS_Block *b = new RS_Block(doc, d); RS_Graphic g; if (!g.open(fi.absoluteFilePath(), RS2::FormatUnknown)) { RS_DEBUG->print(RS_Debug::D_WARNING, "Doc_plugin_interface::addBlockfromFromdisk: Cannot open file: %s"); delete b; return NULL; } RS_LayerList* ll = g.getLayerList(); for (int i = 0; i<ll->count(); i++){ RS_Layer* nl = ll->at(i)->clone(); doc->addLayer(nl); } RS_BlockList* bl = g.getBlockList(); for (int i = 0; i<bl->count(); i++){ RS_Block* nb = (RS_Block*)bl->at(i)->clone(); doc->addBlock(nb); } for (int i = 0; i<g.count(); i++){ RS_Entity* e = g.entityAt(i)->clone(); e->reparent(b); b->addEntity(e); } doc->addBlock(b); return name; } else { return NULL; } }
/** * @return Pointer to the block associated with this Insert or * nullptr if the block couldn't be found. Blocks are requested * from the blockSource if one was supplied and otherwise from * the closest parent graphic. */ RS_Block* RS_Insert::getBlockForInsert() const{ RS_Block* blk = nullptr; if (block) { blk=block; return blk; } RS_BlockList* blkList; if (data.blockSource==nullptr) { if (getGraphic()) { blkList = getGraphic()->getBlockList(); } else { blkList = nullptr; } } else { blkList = data.blockSource; } if (blkList) { blk = blkList->find(data.name); } if (blk) { } block = blk; return blk; }
/** * @return Pointer to the block associated with this Insert or * NULL if the block couldn't be found. Blocks are requested * from the blockSource if one was supplied and otherwise from * the closest parent graphic. */ RS_Block* RS_Insert::getBlockForInsert() { if (block!=NULL) { return block; } RS_BlockList* blkList; if (data.blockSource==NULL) { if (getGraphic()!=NULL) { blkList = getGraphic()->getBlockList(); } else { blkList = NULL; } } else { blkList = data.blockSource; } RS_Block* blk = NULL; if (blkList!=NULL) { blk = blkList->find(data.name); } if (blk!=NULL) { } block = blk; return blk; }