QStringList Doc_plugin_interface::getAllBlocks(){
    QStringList listName;
    RS_BlockList* listBlk = doc->getBlockList();
    for (unsigned int i = 0; i < listBlk->count(); ++i) {
         listName << listBlk->at(i)->getName();
     }
    return listName;
}
void RS_ActionBlocksRemove::trigger() {
    RS_DEBUG->print("RS_ActionBlocksRemove::trigger");

    if (graphic!=NULL) {
        RS_Block* block =
            RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList());

        // list of containers that might refer to the block via inserts:
        RS_PtrList<RS_EntityContainer> containerList;
        containerList.append(graphic);
        RS_BlockList* blkLst = graphic->getBlockList();
        for (uint bi=0; bi<blkLst->count(); bi++) {
            containerList.append(blkLst->at(bi));
        }

        if (block!=NULL) {

            for (RS_EntityContainer* cont = containerList.first();
                    cont!=NULL;
                    cont=containerList.next()) {

                // remove all inserts from the graphic:
                bool done;
                do {
                    done = true;
                    for (RS_Entity* e=cont->firstEntity(RS2::ResolveNone);
                            e!=NULL;
                            e=cont->nextEntity(RS2::ResolveNone)) {

                        if (e->rtti()==RS2::EntityInsert) {
                            RS_Insert* ins = (RS_Insert*)e;
                            if (ins->getName()==block->getName()) {
                                cont->removeEntity(ins);
                                done = false;
                                break;
                            }
                        }
                    }
                } while (!done);
            }

            // close all windows that are editing this block:
            if (RS_DIALOGFACTORY!=NULL) {
                RS_DIALOGFACTORY->closeEditBlockWindow(block);
            }

            // Now remove the block from the block list:
            graphic->removeBlock(block);
            graphic->updateInserts();
            graphicView->redraw();
        }
    }

    finish();
    RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
}
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;
    }
}
void LC_MakerCamSVG::writeBlocks(RS_Document* document) {

    if (!writeBlocksInline) {

        RS_DEBUG->print("RS_MakerCamSVG::writeBlocks: Writing blocks ...");

        RS_BlockList* blocklist = document->getBlockList();

        if (blocklist->count() > 0) {

            xmlWriter->addElement("defs", NAMESPACE_URI_SVG);

            for (int i = 0; i < blocklist->count(); i++) {

                writeBlock(blocklist->at(i));
            }

            xmlWriter->closeElement();
        }

    }
}
Beispiel #5
0
void QC_MDIWindow::drawChars() {

    RS_BlockList* bl = document->getBlockList();
    double sep = document->getGraphic()->getVariableDouble("LetterSpacing", 3.0);
    double h = sep/3;
    sep = sep*3;
    for (int i=0; i<bl->count(); ++i) {
        RS_Block* ch = bl->at(i);
        RS_InsertData data(ch->getName(), RS_Vector(i*sep,0), RS_Vector(1,1), 0, 1, 1, RS_Vector(0,0));
        RS_Insert* in = new RS_Insert(document, data);
        document->addEntity(in);
        QFileInfo info(document->getFilename() );
        QString uCode = (ch->getName()).mid(1,4);
        RS_MTextData datatx(RS_Vector(i*sep,-h), h, 4*h, RS_MTextData::VATop,
                           RS_MTextData::HALeft, RS_MTextData::ByStyle, RS_MTextData::AtLeast,
                           1, uCode, "standard", 0);
/*        RS_MTextData datatx(RS_Vector(i*sep,-h), h, 4*h, RS2::VAlignTop,
                           RS2::HAlignLeft, RS2::ByStyle, RS2::AtLeast,
                           1, uCode, info.baseName(), 0);*/
        RS_MText *tx = new RS_MText(document, datatx);
        document->addEntity(tx);
    }

}