Re: Movement animation - update problem [SOLVED]

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

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: Movement animation - update problem [SOLVED]

Post by mariosboarina » Thu Nov 29, 2012 5:15 pm

Hi,
I'm testing QCad/ECMAScript in order to do movement 2D animations.
I ran a little test script: apply a little step (1,1) movement on a preselected block, inside a for cycle, with a sleep between every step.
I get no errors, but I can't see intermediate positions: only the last one (when its time comes, at last of the animation); so I see no animation.
Also: at the end of actions I cannot select the moved block unless I do it with a selection window which includes also the original position of the block (so it looks).
If I run QCad with debugger enabled the problem doesn't appear.
There might be some update problems with document or rappresentation data of entities.
I tried all update/repaint/regenerate commands in the document interface with no effect.
I run QCad-trial 3.0 on a Windows 7 SP1 (64bit) machine.
This is the testing code:

Code: Select all

	var document = this.getDocument();
	var storage = document.getStorage();
    var di = this.getDocumentInterface();
    var ids = document.querySelectedEntities();
    blockRef = document.queryEntity(ids[0]);
	blockRef.setSelected(false);
	var newPosition = new RVector(1,1);
	for (i=0; i<30; i++) {
		var op = new RModifyObjectsOperation();
		blockRef.move(newPosition);
		op.addObject(blockRef);
		di.applyOperation(op);
		blockRef.update();
		sleep(50);
		di.updateAllEntities
		document.updateAllEntities();
		di.regenerateScenes(ids[0],true);
		di.regenerateViews(true);
		di.repaintViews();
	}
    this.terminate
Thanks for help
Ciao
Mario
Last edited by mariosboarina on Thu Dec 27, 2012 2:17 pm, edited 1 time in total.

mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: Movement animation - update problem

Post by mariosboarina » Tue Dec 04, 2012 11:47 am

some updating on the problem:
I added the line

Code: Select all

document.rebuildSpatialIndex();
so I don't have the selection problem anymore,

but still I can't solve the main problem: I can't see the animation running but only the last step.
Ciao
Mario

mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: Movement animation - update problem [SOLVED]

Post by mariosboarina » Wed Dec 12, 2012 7:22 pm

Solved, at last: just have to process events on every step.

before the cycle:
var el = new QEventLoop()

inside the cycle:
el.processEvents();

Ciao

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

Re: Movement animation - update problem

Post by andrew » Wed Dec 12, 2012 7:44 pm

Note that processing events inside a script is not recommended. It allows the user to 'do something' while your script is running (e.g. close the document, open a new file, etc.). This can have very undesirable effects (crashes).

You might be able to simply force an immediate repaint instead:

Code: Select all

var view = EAction.getGraphicsView();
...
// loop
    view.repaintNow();
// end of loop

mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: Movement animation - update problem

Post by mariosboarina » Thu Dec 20, 2012 3:21 pm

Ok, thank you for reply,
I'll try it soon with repaintNow()

mariosboarina
Junior Member
Posts: 19
Joined: Thu Nov 29, 2012 4:28 pm

Re: Movement animation - update problem

Post by mariosboarina » Thu Dec 27, 2012 2:16 pm

Ok. Tested. It works perfectly.
Thank you again.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”