Page 1 of 1

Faster way to plot objects on Document Interface

Posted: Wed Nov 14, 2018 7:30 pm
by ezm
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

Re: Faster way to plot objects on Document Interface

Posted: Thu Nov 15, 2018 3:49 pm
by RR88

Code: Select all

applyOperation
takes time! It's better to use

Code: Select all

RAddObjectsOperation
for more than one object.

Re: Faster way to plot objects on Document Interface

Posted: Fri Nov 16, 2018 2:43 pm
by andrew
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).

Re: Faster way to plot objects on Document Interface

Posted: Mon Nov 19, 2018 10:42 am
by andrew
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.

Re: Faster way to plot objects on Document Interface

Posted: Mon Nov 19, 2018 5:23 pm
by ezm
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