QCAD Bugtracker

  • Status Assigned
  • Percent Complete
    0%
  • Task Type Bug Report
  • Category QCAD Community Edition
  • Assigned To
    QCAD Community
  • Operating System Linux (All / Other)
  • Severity Low
  • Priority Very Low
  • Reported Version 3.26.4
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: QCAD Bugtracker
Opened by zem - 17.11.2021
Last edited by Andrew - 18.11.2021

FS#2312 - Draw from CSV can not create Layers with NewLayer

NewLayer always complains about a missing parent layer.

I could not figure out how to create Layers from a CSV file,
I tried DrawCSV_Layer_test.csv which is a reference test from the qcad repo but NewLayer always returns “Parent layer doesn’t exist.”

Reading from file: /home/zem/DrawCSV_Layer_test.csv
Switched to semicolon/comma CSV style.
Layer doesn't exist, ignored. Text line 20 layer: 0 Entity Colors
Not a correct layer name. Text line 24 name: Invalid=`name`
Add/Update layer ignored.
Not a correct color. Text line 25 color: ByBlock
Add/Update layer ignored.
Not a correct Lineweight. Text line 26 weight: 999
Add/Update layer ignored.
Not a correct Linetype. Text line 27 type: Orange line
Add/Update layer ignored.
Parent layer doesn't exist. Text line 31 layer: MyLayerInvalid paren
Add/Update layer ignored.
Can not hide layer, ignored. Text line 34 layer: Invalid Hide
Can not freeze layer, ignored. Text line 35 layer: Invalid FreezeInvalid SUB
Can not lock layer, ignored. Text line 36 layer: Invalid Lock
Can not lock layer, ignored. Text line 37 layer: Invalid=`name`
Can not allow layer, ignored. Text line 38 layer: Invalid Allow
Can not switch to layer, ignored. Text line 39 layer: Invalid layer switch
Can not switch to layer, ignored. Text line 40 layer: Invalid=`name`
Parent layer doesn't exist. Text line 43 layer: 01 Gree
Add/Update layer ignored.
Parent layer doesn't exist. Text line 44 layer: 02 Parent
Add/Update layer ignored.
Parent layer doesn't exist. Text line 45 layer: 02 Parent1Sub
Add/Update layer ignored.
Parent layer doesn't exist. Text line 46 layer: 02 Parent1Sub1SubSub1 
Add/Update layer ignored.
Parent layer doesn't exist. Text line 47 layer: 03 Parent
Add/Update layer ignored.
Parent layer doesn't exist. Text line 48 layer: 03 Parent2Sub
Add/Update layer ignored.
Parent layer doesn't exist. Text line 49 layer: 03 Parent2Sub2SubSub
Add/Update layer ignored.
Parent layer doesn't exist. Text line 50 layer: 04 Parent
Add/Update layer ignored.
Parent layer doesn't exist. Text line 51 layer: 04 Parent3Sub
Add/Update layer ignored.
Parent layer doesn't exist. Text line 52 layer: 04 Parent3Sub3SubSub
Add/Update layer ignored.
Parent layer doesn't exist. Text line 53 layer: Last New &Curren
Add/Update layer ignored.
Can not hide layer, ignored. Text line 56 layer: 03 Parent2
Can not freeze layer, ignored. Text line 57 layer: 03 Parent2Sub2
Can not lock layer, ignored. Text line 58 layer: 03 Parent2Sub2SubSub2
Can not hide layer, ignored. Text line 60 layer: 04 Parent3
Can not freeze layer, ignored. Text line 61 layer: 04 Parent3
Can not lock layer, ignored. Text line 62 layer: 04 Parent3
Can not hide layer, ignored. Text line 63 layer: 04 Parent3Sub3
Can not freeze layer, ignored. Text line 64 layer: 04 Parent3Sub3
Can not lock layer, ignored. Text line 65 layer: 04 Parent3Sub3
Can not hide layer, ignored. Text line 66 layer: 04 Parent3Sub3SubSub3
Can not freeze layer, ignored. Text line 67 layer: 04 Parent3Sub3SubSub3
Can not lock layer, ignored. Text line 68 layer: 04 Parent3Sub3SubSub3
Can not allow layer, ignored. Text line 70 layer: 04 Parent3
Can not switch to layer, ignored. Text line 76 layer: 02 Parent1Sub1SubSub1 %
Layer doesn't exist, ignored. Text line 82 layer: 02 Parent1
Can not switch to layer, ignored. Text line 85 layer: 02 Parent1Sub1SubSub1 %
Casted entries : 4 with 90 text lines
Importing CSV complete. Command ended.

No layers are added in the resulting drawing.

OS here is fedora 34 and qcad is either from fedora or rpmfusion.

20.11.2021 : A task closure has been requested. Reason for request: Should be fixed with the update 3.04
zem commented on 18.11.2021 09:22

I have looked into it for a bit, to me it looks like in:

src/core/RLayerProxy.h line 38:

virtual QString getHierarchySeparator() = 0;

This returns an empty string as hierarchy separator. And I think DrawFromCSV.js at line 1641 is not prepared to deal with an empty string here.

How are those Layer Parents working anyway? Schould I we get rid of that parent code in DraqFromCSV.js alltogether or is it better to fix up parent handling if we get an empty separator string?

zem commented on 18.11.2021 10:24

I prepared a hotfix which is not complete as the Test still does not run completely. However it fixes up the NewLayer command well enough to be able to add new layers which is what I need to continue on my project.

diff --git a/contrib/DrawFromCSV/DrawFromCSV.js b/contrib/DrawFromCSV/DrawFromCSV.js
index aa28fc6..1ef9a23 100644
--- a/contrib/DrawFromCSV/DrawFromCSV.js
+++ b/contrib/DrawFromCSV/DrawFromCSV.js
@@ -323,7 +323,7 @@ DrawFromCSV.prototype.DrawFromCSVFile = function(di, fileName) {
             msg = "";    // Empty
             if (fieldsCount === 2) {   // With 2 fields
                 // Adapt naming to proper layer hierarchy separator:
-                fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());
+                // fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());^M
                 // Validate layer switch:
                 if (this.doc.hasLayer(fields[1])) {    // When the layer exists >
                     this.currentLayerName = fields[1];
@@ -356,7 +356,7 @@ DrawFromCSV.prototype.DrawFromCSVFile = function(di, fileName) {
             msg = "";    // Empty
             if (fieldsCount === 2) {   // With 2 fields
                 // Adapt naming to proper layer hierarchy separator:
-                fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());
+                // fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());^M
                 // Validate layer switch:
                 if (this.doc.hasLayer(fields[1])) {    // When the layer exists >
                     // Get the layer from the document:
@@ -386,7 +386,7 @@ DrawFromCSV.prototype.DrawFromCSVFile = function(di, fileName) {
             msg = "";    // Empty
             if (fieldsCount === 2) {   // With 2 fields
                 // Adapt naming to proper layer hierarchy separator:
-                fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());
+                // fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());^M
                 // Validate layer switch:
                 if (this.doc.hasLayer(fields[1])) {    // When the layer exists >
                     // Get the layer from the document:
@@ -416,7 +416,7 @@ DrawFromCSV.prototype.DrawFromCSVFile = function(di, fileName) {
             msg = "";    // Empty
             if (fieldsCount === 2) {   // With 2 fields
                 // Adapt naming to proper layer hierarchy separator:
-                fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());
+                // fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());^M
                 // Validate layer switch:
                 if (this.doc.hasLayer(fields[1])) {    // When the layer exists >
                     // Get the layer from the document:
@@ -446,7 +446,7 @@ DrawFromCSV.prototype.DrawFromCSVFile = function(di, fileName) {
             msg = "";    // Empty
             if (fieldsCount === 2) {   // With 2 fields
                 // Adapt naming to proper layer hierarchy separator:
-                fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());
+                // fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());^M
                 // Validate layer switch:
                 if (this.doc.hasLayer(fields[1])) {    // When the layer exists >
                     // Get the layer from the document:
@@ -1541,7 +1541,7 @@ DrawFromCSV.prototype.validateAttributes = function(fields, line) {
         switch (keyValue[0].toUpperCase()) {
         case "LAYER":
             // Adapt layer naming to proper layer hierarchy separator:
-            keyValue[1] = keyValue[1].replace(/\//g, RLayer.getHierarchySeparator());
+            // keyValue[1] = keyValue[1].replace(/\//g, RLayer.getHierarchySeparator());^M
 
             // Validate layer naming:
             layerName = this.validateLayerString(keyValue[1]);
@@ -1634,11 +1634,12 @@ DrawFromCSV.prototype.newOrUpdateLayer = function(fields, line) {
     var layerOp;
     var defaultColor, defaultType, defaultWeight;
     var msg = "";
-    var subSep = RLayer.getHierarchySeparator();
+    // var subSep = RLayer.getHierarchySeparator();^M
+    var subSep = "/";^M
 
 //debugger;
     // Adapt layer naming to proper layer hierarchy separator:
-    fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());
+    // fields[1] = fields[1].replace(/\//g, RLayer.getHierarchySeparator());^M
 
     // Validate layer naming:
     layerName = this.validateLayerString(fields[1]);
@@ -1646,7 +1647,7 @@ DrawFromCSV.prototype.newOrUpdateLayer = function(fields, line) {
         anyError = qsTr("Not a correct layer name ! Text line %1 name: %2").arg(line).arg(fields[1]);    // translated message
     } // End without name
     else {    // With a valid layer name >
-        if (layerName.indexOf(RLayer.getHierarchySeparator()) !== -1) {    // With parent/sub layer >
+        if (layerName.indexOf(subSep) !== -1) {    // With parent/sub layer >^M
             parentLayer = layerName.split(subSep, layerName.count(subSep)).join(subSep);
             if (!this.doc.hasLayer(parentLayer)) {    // Without a parent layer >
                 anyError = qsTr("Parent layer doesn't exist ! Text line %1 layer: %2").arg(line).arg(parentLayer);    // translated message
CVH commented on 18.11.2021 11:25

zem,
I have run the test again and it works fine over here.
In total 11 layers were added.
It is normal that you get 18 warnings in red.
Those faults are intentionally in the test CSV file.

At CSV line 43 it starts to go wrong!?
There a layer '01 Green' should be added.
I read in your report '01 Gree'.
Same for the next CSV line: '02 Parent1' vs '02 Parent'.
And so on.

RLayer.getHierarchySeparator() should return 3 dots + spaces aka ' ... '
One can verify that in the script shell:
- type the shortcut 'GE' to start the shell.
- confirm and then paste the next code:

">" + RLayer.getHierarchySeparator() + "<";

You can always reach me in direct by a personal message (PM) on the forum ... ;-)

Regards,
CVH

CVH commented on 20.11.2021 08:38

Andrew,
zem,

Should be fixed with the update 3.04
https://qcad.org/rsforum/viewtopic.php?f=30&t=8135#p35383

Regards,
CVH

Loading...

Available keyboard shortcuts

Tasklist

Task Details

Task Editing