From 0cb5469278c93bfb1a2d29ea7b6d14bb93aaa764 Mon Sep 17 00:00:00 2001 From: Nils Schmidt Date: Sun, 10 Dec 2023 11:48:26 +0100 Subject: [PATCH] Prepared fix for issue #1009. --- primitive_rules.txt | 9 ++ .../primitive/CompositePrimitive.java | 87 ++++++++++++------- 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/primitive_rules.txt b/primitive_rules.txt index dbc29677e..1a8d732b6 100644 --- a/primitive_rules.txt +++ b/primitive_rules.txt @@ -47,5 +47,14 @@ Znap; Title "znap5.dat"; Matches ".*Znap.*" Torus; Title "t01q1429.dat" Torus|Inside; Title "t01i3333.dat"; Contains "Torus_Inside" +Torus|Inside (mixed); Title "48\tm06i8000.dat"; Contains "Mixed-Mode_Torus_Inner" Torus|Outside; Title "t01o4000.dat"; Contains "Torus_Outside" +Torus|Outside (mixed); Title "48\tm04o4000.dat"; Contains "Mixed-Mode_Torus_Outer" Torus|Tube; Title "t01q1429.dat"; Contains "Torus_Tube" + +Logo; Title "logo-technic-1.dat"; Matches "Logo.*" + +_Standard Bricks; Title "3002.dat" +_Standard Bricks|_Brick; Title "3005.dat"; Matches "Brick.*" +_Standard Bricks|_Plate; Title "3024.dat"; Matches "Plate.*" +_Standard Bricks|_Tile; Title "3070b.dat"; Matches "Tile.*" diff --git a/src/org/nschmidt/ldparteditor/composite/primitive/CompositePrimitive.java b/src/org/nschmidt/ldparteditor/composite/primitive/CompositePrimitive.java index 4c34ac78c..32d7ca570 100644 --- a/src/org/nschmidt/ldparteditor/composite/primitive/CompositePrimitive.java +++ b/src/org/nschmidt/ldparteditor/composite/primitive/CompositePrimitive.java @@ -652,35 +652,6 @@ private void load(boolean waitForRenderer) { setSelectedPrimitive(null); primitives.clear(); - List searchPaths = new ArrayList<>(); - String ldrawPath = WorkbenchManager.getUserSettingState().getLdrawFolderPath(); - if (ldrawPath != null) { - searchPaths.add(ldrawPath + File.separator + "p" + File.separator); //$NON-NLS-1$ - searchPaths.add(ldrawPath + File.separator + "P" + File.separator); //$NON-NLS-1$ - searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - } - String unofficial = WorkbenchManager.getUserSettingState().getUnofficialFolderPath(); - if (unofficial != null) { - searchPaths.add(unofficial + File.separator + "p" + File.separator); //$NON-NLS-1$ - searchPaths.add(unofficial + File.separator + "P" + File.separator); //$NON-NLS-1$ - searchPaths.add(unofficial + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(unofficial + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(unofficial + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(unofficial + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - } - String project = Project.getProjectPath(); - if (project != null) { - searchPaths.add(project + File.separator + "p" + File.separator); //$NON-NLS-1$ - searchPaths.add(project + File.separator + "P" + File.separator); //$NON-NLS-1$ - searchPaths.add(project + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(project + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(project + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - searchPaths.add(project + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ - } - Map titleMap = new HashMap<>(); Map leavesTitleMap = new HashMap<>(); Map primitiveMap = new HashMap<>(); @@ -689,6 +660,7 @@ private void load(boolean waitForRenderer) { Map> leavesRulesMap = new HashMap<>(); final String lowResSuffix = File.separator + "8" + File.separator; //$NON-NLS-1$ final String hiResSuffix = File.separator + "48" + File.separator; //$NON-NLS-1$ + try { // Creating the categories / Rules @@ -952,6 +924,37 @@ private void load(boolean waitForRenderer) { NLogger.error(CompositePrimitive.class, e); } } + + List searchPaths = new ArrayList<>(); + String ldrawPath = WorkbenchManager.getUserSettingState().getLdrawFolderPath(); + if (ldrawPath != null) { + searchPaths.add(ldrawPath + File.separator + "p" + File.separator); //$NON-NLS-1$ + searchPaths.add(ldrawPath + File.separator + "P" + File.separator); //$NON-NLS-1$ + searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + } + String unofficial = WorkbenchManager.getUserSettingState().getUnofficialFolderPath(); + if (unofficial != null) { + searchPaths.add(unofficial + File.separator + "p" + File.separator); //$NON-NLS-1$ + searchPaths.add(unofficial + File.separator + "P" + File.separator); //$NON-NLS-1$ + searchPaths.add(unofficial + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(unofficial + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(unofficial + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(unofficial + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + } + String project = Project.getProjectPath(); + if (project != null) { + searchPaths.add(project + File.separator + "p" + File.separator); //$NON-NLS-1$ + searchPaths.add(project + File.separator + "P" + File.separator); //$NON-NLS-1$ + searchPaths.add(project + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(project + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(project + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + searchPaths.add(project + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$ + } + + searchPaths.add(ldrawPath + File.separator + "parts" + File.separator); //$NON-NLS-1$ boolean isUppercase = false; boolean isEmpty = true; @@ -961,7 +964,7 @@ private void load(boolean waitForRenderer) { isUppercase = !isUppercase; continue; } - final File[] files = libFolder.listFiles(); + final File[] files = listFiles(ldrawPath, libFolder); if (files == null) { isUppercase = !isUppercase; continue; @@ -1218,6 +1221,30 @@ private void load(boolean waitForRenderer) { }); } + private File[] listFiles(String ldrawPath, File libFolder) { + final String partsFolder; + if ("parts".equals(libFolder.getName())) { //$NON-NLS-1$ + partsFolder = "parts"; //$NON-NLS-1$ + } else if ("PARTS".equals(libFolder.getName())) { //$NON-NLS-1$ + partsFolder = "PARTS"; //$NON-NLS-1$ + } else { + return libFolder.listFiles(); + } + + final String[] standardBricks = ( + """ + 3001.dat,3002.dat, + 3005.dat, + 3024.dat, + 3070b.dat""").split(",");//$NON-NLS-1$ //$NON-NLS-2$ + final File[] result = new File[standardBricks.length]; + for (int i = 0; i < result.length; i++) { + result[i] = new File(ldrawPath + File.separator + partsFolder + File.separator + standardBricks[i].trim()); + } + + return result; + } + // What follows now is a very minimalistic DAT file parser (<500LOC) private static final Pattern WHITESPACE = Pattern.compile("\\s+"); //$NON-NLS-1$