document layers seem to be missing after passing to function

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
ScottP
Junior Member
Posts: 14
Joined: Wed Jul 08, 2020 5:08 pm

document layers seem to be missing after passing to function

Post by ScottP » Tue Mar 30, 2021 11:30 pm

I'm probably I'm missing something obvious here...

I'm making an RDocument from a DXF file,

Code: Select all

inputfile
, that has multiple entities on multiple layers.
I then duplicate the document, intending to selectively change some of the entities/layers, but when I pass the duplicated document's reference to a function, the number of layers changes. :?

Code: Select all

//SETUP DOCUMENT
var storage = new RMemoryStorage();
var spatialIndex = new RSpatialIndexSimple();
var doc = new RDocument(storage, spatialIndex);
var di = new RDocumentInterface(doc);
if (di.importFile(inputFile) != RDocumentInterface.IoErrorNoError) {
	qWarning("Cannot import file:", inputFile);
	di.destroy();
        return;
}


//DUPLICATE DOCUMENT
var storageTemp = new RMemoryStorage();
var spatialIndexTemp = new RSpatialIndexSimple();
var docTemp = new RDocument(storageTemp, spatialIndexTemp);
var diTemp = new RDocumentInterface(docTemp);

doc.selectAllEntities();
var co = new RCopyOperation(new RVector(0,0), doc);
diTemp.applyOperation(co);


//TRY
debugger;
var layerIDsCheck = doc.queryAllLayers(); 
var layerIDsTempCheck = docTemp.queryAllLayers();
//Here, I get exactly the same hex values for doc and docTemp, and for layerIDsCheck and layerIDsTempCheck (5 elements each)

var layerIDs = getSortedLayerIDs(docTemp);

function getSortedLayerIDs(docu){
	var layerIDs = docu.queryAllLayers();
	//For me, docu does not have the same hex value as docTemp did, and layerIDs now holds 3 elements with values differing from those in layerIDsCheck and layerIDsTempCheck
	//...
}

The DXF I'm using has thousands of entities. If I reduce the DXF to only arc entities, for example, then in passing to

Code: Select all

getSortedLayerIDs()
, the IDs still change but the number of layers is maintained (might be some coincidence).


QCAD version: 3.26.1.0
Date: Mar 8 2021
Qt version: 5.13.2
Compiler version: MSVC++ 14.0 (2015)
Build date: Mar 8 2021
Revision: eec8166e891241909e2a1821e3bf9e3dd0aa2366
Architecture: x86_64
OS: Win10

Thank you for any help!

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

Re: document layers seem to be missing after passing to function

Post by andrew » Wed Mar 31, 2021 7:20 am

RCopyOperation copies all selected entities across. Layers are copied as needed. I.e. layer "X" is copied if one of the selected entities is on layer "X".

You can use co.setCopyAllLayers(true) to always copy all layers.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”