PDF export after applying Operations

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
pmbrull
Junior Member
Posts: 14
Joined: Thu Aug 23, 2018 4:07 pm

PDF export after applying Operations

Post by pmbrull » Fri Aug 31, 2018 12:41 pm

Hello and thank you for your time,

We're using the scripting tool for importing different DXF files and applying some changes to both layers and entities. The is idea getting some printings while we keep applying modifications.

My question arises as when exporting, the changes do not appear in the resulting PDF. However, saving the DXF and using dwg2pdf shows the final state correctly. My guess is that we are missing some kind of action before the printing. Code logic looks like this:

Code: Select all

var op = new RModifyObjectsOperation();
[....]
di.applyOperation(op);

var scene = new RGraphicsSceneQt(di);
var view = new RGraphicsViewImage();
view.setScene(scene);

var print = new Print(undefined, document, view);
print.print("...");
[....]
Is there something missing to actually register the changes for the RDocumentInterface? I noticed that if the changes are applied regarding just RDocument (for example, Offset or Scale), printing goes smoothly.

Thank you,
Pere

User avatar
andrew
Site Admin
Posts: 5702
Joined: Fri Mar 30, 2007 6:07 am

Re: PDF export after applying Operations

Post by andrew » Fri Aug 31, 2018 12:45 pm

Can you try creating the scene / view directly when creating the document / document interface, i.e. before applying the operation?

pmbrull
Junior Member
Posts: 14
Joined: Thu Aug 23, 2018 4:07 pm

Re: PDF export after applying Operations

Post by pmbrull » Fri Aug 31, 2018 12:52 pm

Appreciate your fast response. The new code logic involves the following steps:

* Initialization of document and document interface
* Generation of view and scene
* Applying Operations (There are also RPasteOperation, as we are merging different files, I am not sure if those affect differently than Mofigy operations)
* Print

Although, we reach the same output, perfect dxf saved file that can be printed but wrong on-the-way pdf generation. My thoughts on creating the scene right before each print was that it would have the applied changes.

Could you please give further advice?

Thanks,
Pere

User avatar
andrew
Site Admin
Posts: 5702
Joined: Fri Mar 30, 2007 6:07 am

Re: PDF export after applying Operations

Post by andrew » Fri Aug 31, 2018 10:04 pm

You can try to explicitly regenerate the scenes before printing:

Code: Select all

di.regenerateScenes();

pmbrull
Junior Member
Posts: 14
Joined: Thu Aug 23, 2018 4:07 pm

Re: PDF export after applying Operations

Post by pmbrull » Mon Sep 03, 2018 7:22 am

Hello Andrew,

Thank you for your response. However, it didn't solve the issue. Following the RDocumentInterface docs I also tried (without results) the following methods:

1- di.regenerateViews(true);
2- di.repaintViews();
3- di.registerScene(scene) + view.setScene(scene)

I would appreciate further guidance, as I still do not understand what piece is missing for the operations to actually apply.

EDIT: I don't know how important this is when working with "scenes" and "views", but I am working with scripts through the command line with the -no-gui option, as it is intended to run in a server and we are only interested in the pdf output.

Thanks,
Pere

User avatar
andrew
Site Admin
Posts: 5702
Joined: Fri Mar 30, 2007 6:07 am

Re: PDF export after applying Operations

Post by andrew » Mon Sep 03, 2018 8:45 am

Unfortunately, this would indicate that there's a snag somewhere else (not in the code posted).

Perhaps the problem is something completely different (printing white on white, thin lines, ...). Please provide more context and attach output DXF files, output PDF, etc.

pmbrull
Junior Member
Posts: 14
Joined: Thu Aug 23, 2018 4:07 pm

Re: PDF export after applying Operations

Post by pmbrull » Mon Sep 03, 2018 2:52 pm

Good afternoon,

Please find attached the resulting DXF file exported at the end of the process and the looks of the resulting PDF. Note that the PDF export is done just above.

What we are using on the process is a template with title/subtitle to directly frame what we want to print in the DXF. As the frame (layers: Marc_pdf_1 and Marc_pdf_2) is black and white, we disabled the option that alterates both colors when printing, so that we can actually get both of the actual colors as intended.

That is why during the process we also attack layers like EXTERNAL_DIM and NEIGHBOR_DIM to explicitly set its objects to black. Disabling the "Prevent white on white /black on black display" option, exporting to PDF directly from QCAD gets us the desired result, so I do not think it has anything to do with thin lines.

To further extend the code provided, we are following this schema:

Code: Select all

    //! [document]
    var storage = new RMemoryStorage();
    var spatialIndex = new RSpatialIndexNavel();
    var document = new RDocument(storage, spatialIndex);
    var di = new RDocumentInterface(document);

    //! [view]
    var scene = new RGraphicsSceneQt(di);
    var view = new RGraphicsViewImage();
    view.setScene(scene);
    //! [view]
    
    // Import various input DXF files
    for (...){
        var doc_insert = new RDocument(new RMemoryStorage(), new RSpatialIndexNavel());
        var di_insert = new RDocumentInterface(doc_insert);

        if (di_insert.importFile(insert) !== RDocumentInterface.IoErrorNoError) {
            qWarning("cannot import file: ", insert);
        }
        var op = new RPasteOperation(doc_insert);
        op.setOffset(new RVector(0, 0));
        di.applyOperation(op);

        di_insert.destroy();
    }
    
    // Modify operationg on both layers and entities, for example
    var op = new RModifyObjectsOperation();
    var layer = document.queryLayer("0");
    layer.setLineweight(18);
    layer.setColor(black);
    op.addObject(layer);
    di.applyOperation(op);
    
    // set Document variables and export
    [...]
    document.setVariable("PageSettings/OffsetX", OffsetX);
    document.setVariable("PageSettings/OffsetY", OffsetY);
    [...]
    //! [export]
    var print = new Print(undefined, document, view);
    print.print(outputFile + "_" + String(i) + ".pdf");
    //! [export]
    
    // Export for checking result in DXF
    di.exportFile("path/to/final.dxf");
Thank you for your time. We are really welcome for your comments and hope for your further advice.

EDIT: I also attached what we see when opening the generated "final.dxf" in QCAD with the specified application options.

Pere
Attachments
final_shot.png
final_shot.png (28.01 KiB) Viewed 731 times
final1.PNG
final1.PNG (32.04 KiB) Viewed 731 times
final1.dxf
(300.53 KiB) Downloaded 23 times

Post Reply

Return to “QCAD Developers and Contributors”