From e79395ee3b0d9f1857e2fe64f848b0461c95aca4 Mon Sep 17 00:00:00 2001
From: Riegel <alexander.riegel@hft-stuttgart.de>
Date: Tue, 7 Jan 2025 11:55:58 +0100
Subject: [PATCH] Feat: Add zipfile handling to GUI controller

---
 .../citydoctor2/gui/CityDoctorController.java | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java
index bce70ff..5bd8e42 100644
--- a/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java
+++ b/CityDoctorParent/Extensions/CityDoctorGUI/src/main/java/de/hft/stuttgart/citydoctor2/gui/CityDoctorController.java
@@ -12,6 +12,7 @@ import de.hft.stuttgart.citydoctor2.gui.tree.*;
 import de.hft.stuttgart.citydoctor2.mapper.citygml3.GMLValidationHandler;
 import de.hft.stuttgart.citydoctor2.parser.*;
 import de.hft.stuttgart.citydoctor2.utils.Localization;
+import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive;
 import javafx.application.Platform;
 import javafx.scene.chart.XYChart.Data;
 import javafx.scene.chart.XYChart.Series;
@@ -27,6 +28,7 @@ import org.citygml4j.core.model.core.CityModel;
 import org.xml.sax.SAXParseException;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
@@ -42,6 +44,7 @@ public class CityDoctorController {
     private CityDoctorModel model;
     private ParserConfiguration currentConfig;
     private String sourceFile;
+    private CityGmlZipArchive zipArchive;
 
     private Checker currentChecker;
 
@@ -82,6 +85,10 @@ public class CityDoctorController {
                 mainWindow.resetSearchBar();
                 mainWindow.resetFilterComboBox();
             });
+            if (path.endsWith(".zip")) {
+                loadCityGmlZipFile(path, numberOfRoundingPlaces, l, useValidation, lowMemory);
+                return;
+            }
             currentChecker = null;
             currentConfig = new ParserConfiguration(numberOfRoundingPlaces, useValidation, lowMemory);
             GMLValidationHandler handler = null;
@@ -138,6 +145,53 @@ public class CityDoctorController {
         }
     }
 
+    private void loadCityGmlZipFile(String path, int numberOfRoundingPlaces, ProgressListener l, boolean useValidation,
+                                    boolean lowMemory) throws CityGmlParseException, InvalidGmlFileException {
+        currentChecker = null;
+        currentConfig = new ParserConfiguration(numberOfRoundingPlaces, useValidation, lowMemory);
+        zipArchive = CityGmlZipArchive.register(path);
+
+        Platform.runLater(() -> {
+            try {
+                ZipEntryPicker picker = new ZipEntryPicker(mainWindow.getMainStage(), this);
+                picker.show();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        });
+        /**
+         model = CityGmlParser.parseCityGmlFile(path, currentConfig, l, handler, true);
+         if (!validationIssues.isEmpty()) {
+         StringJoiner sj = new StringJoiner("\n");
+         validationIssues.stream().forEach(sj::add);
+         throw new InvalidGmlFileException(sj.toString());
+         }
+         mainWindow.getClickHandler().setConfig(currentConfig);
+         sourceFile = path;
+         renderer.reset();
+         Platform.runLater(() -> {
+         mainWindow.addFileNameToTitle(path);
+         mainWindow.getCheckButton().setDisable(false);
+         mainWindow.getLod1Btn().setDisable(false);
+         mainWindow.getLod2Btn().setDisable(false);
+         mainWindow.getLod3Btn().setDisable(false);
+         mainWindow.getLod4Btn().setDisable(false);
+         mainWindow.getWorldBtn().setDisable(false);
+         mainWindow.getSaveBtn().setDisable(false);
+         mainWindow.getResetCameraBtn().setDisable(false);
+         mainWindow.getHideRoofBtn().setDisable(false);
+         mainWindow.getNorthArrow().setVisible(true);
+         mainWindow.alignNorthArrow();
+         setupFeatureTabs();
+         buildTrees();
+         });
+         **/
+    }
+
+    public CityGmlZipArchive getZipArchive() {
+        return zipArchive;
+    }
+
     private void setupFeatureTabs() {
         mainWindow.setDisableOfFeatureTab(FeatureType.BUILDING, model.getBuildings().isEmpty());
         mainWindow.setDisableOfFeatureTab(FeatureType.VEGETATION, model.getVegetation().isEmpty());
-- 
GitLab