Faster way to plot objects on Document Interface

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
ezm
Registered Member
Posts: 2
Joined: Wed Nov 14, 2018 6:30 pm

Faster way to plot objects on Document Interface

Post by ezm » Wed Nov 14, 2018 7:30 pm

Hello Andrew,

I am working on a QCAD application that gets (x,y) values from laser and plots them on the Document Interface. I get values from laser every 100ms.
Each time a get a value, I delete and redraw 1 polyline + 3 circles and draw 1 point to the document. This works fine for a couple of minutes but after that, the plotting gets slow and eventually the document becomes unresponsive and hangs. So is there a way to handle such fast data ? I was even looking to move this to C++ so that I can use threads but as Document Interface is a GUI object I cannot move it. Also is there a way to select points from the document and export them as csv?

//--Point--

view = EAction.getGraphicsView();

PlotXY = function(X,Y){
var op = new RAddObjectsOperation();
var point = new RPointEntity(document,new RPointData(new RVector(X, Y)));
op.addObject(point);
documentInterface.applyOperation(op);
view.repaintNow();
};

//--Line--
PlotLine = function(V1, V2) {
deleteSegment();
var List = [V1, V2];
var poly = new RPolyline(List,false);
var polyData = new RPolylineData(poly);
lineSegment = new RPolylineEntity(document, polyData);

var op = new RAddObjectsOperation();
op.addObject(lineSegment ,false);
documentInterface.applyOperation(op);
};

function deleteSegment()
{
var op = new RDeleteObjectsOperation(true);
if(lineSegment != null){
op.deleteObject(lineSegment );
lineSegment = null;
op.apply(document,false);
}
}; //Similarly I add and delete 3 circles.


I am using QCAD version : 3.20.1.5

Appreciate your help.
Thanks!
EZM

RR88
Junior Member
Posts: 19
Joined: Sun Apr 29, 2018 7:04 am
Location: Leinefelde

Re: Faster way to plot objects on Document Interface

Post by RR88 » Thu Nov 15, 2018 3:49 pm

Code: Select all

applyOperation
takes time! It's better to use

Code: Select all

RAddObjectsOperation
for more than one object.
Gentoo/Linux, QCad 3.20 Prof.

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

Re: Faster way to plot objects on Document Interface

Post by andrew » Fri Nov 16, 2018 2:43 pm

The problem is that by adding and removing entities, an huge stack of undo / redo history is created.

If your intention is to display short-lived data as a kind of a preview, you might want to consider using a preview instead. Previews are not added to a document but only shown on top of a drawing. This is fast and what QCAD does to display previews while drawing and editing.

If you really need to add that data to your drawing, you might want to add it as not undoable:

Code: Select all

var op = new RAddObjectsOperation(false);
This can of course break undo / redo and can have other side effects (e.g. widgets not being updated).

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

Re: Faster way to plot objects on Document Interface

Post by andrew » Mon Nov 19, 2018 10:42 am

A new option has been added in the current snapshot release 3.21.3.7 to flush the transaction history (and all objects that were undone) at any point:

Code: Select all

documentInterface.flushTransactions();
Call this after every operation or e.g. every 10 operations to clear the undo / redo stack and reduce the size of indices, etc.

ezm
Registered Member
Posts: 2
Joined: Wed Nov 14, 2018 6:30 pm

Re: Faster way to plot objects on Document Interface

Post by ezm » Mon Nov 19, 2018 5:23 pm

Thank you Andrew! I changed the undoable to "false" and it already improved the plotting. Can you guide me into creating a preview ? I tried to follow this example but nothing shows up on the screen. Only difference is I am doing this from C++.

https://github.com/qcad/qcad/blob/maste ... hDialog.js

Thanks

Post Reply

Return to “QCAD Developers and Contributors”