diff --git a/assets/atlasobjekte.qml b/assets/atlasobjekte.qml
new file mode 100644
index 0000000..952ddd5
--- /dev/null
+++ b/assets/atlasobjekte.qml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ui/layout.py b/ui/layout.py
index a4da86e..4aa52c8 100644
--- a/ui/layout.py
+++ b/ui/layout.py
@@ -199,3 +199,233 @@ class Layout:
open_layout_designer(layout)
print("[Layout] Layout Designer geöffnet")
return layout
+
+ def create_atlas_layout(
+ self,
+ name: str,
+ page_width_mm: float,
+ page_height_mm: float,
+ map_width_mm: float,
+ map_height_mm: float,
+ extent: Any,
+ plotmassstab: float,
+ atlas_layer: Any,
+ thema: str = "",
+ ) -> Any:
+ """Erzeugt ein Atlas-Layout mit Coverage-Layer ``Atlasobjekte``."""
+ layout_manager = self.project.layoutManager()
+ existing_layout = layout_manager.layoutByName(name)
+ if existing_layout is not None:
+ raise ValueError(f"Eine Vorlage mit der Bezeichnung '{name}' existiert bereits.")
+
+ layout = QgsPrintLayout(self.project)
+ layout.initializeDefaults()
+ layout.setName(name)
+
+ page = layout.pageCollection().page(0)
+ page.setPageSize(QgsLayoutSize(page_width_mm, page_height_mm, MM))
+ # Verifiziere, dass QGIS die Größe akzeptiert hat
+ page_size = page.pageSize() if hasattr(page, 'pageSize') else None
+ if page_size is not None and hasattr(page_size, 'width'):
+ actual_w = float(page_size.width())
+ actual_h = float(page_size.height())
+ print(f"[Layout] Atlas Page gesetzt: x=0, y=0, width={page_width_mm:.1f}mm→{actual_w:.1f}mm, height={page_height_mm:.1f}mm→{actual_h:.1f}mm")
+ else:
+ print(f"[Layout] Atlas Page: x=0, y=0, width={page_width_mm:.1f}mm, height={page_height_mm:.1f}mm")
+
+ map_left_mm = 10.0
+ map_top_mm = 10.0
+ map_right_mm = map_left_mm + map_width_mm
+ map_bottom_mm = map_top_mm + map_height_mm
+
+ hauptkarte = QgsLayoutItemMap(layout)
+ hauptkarte.setId("Hauptkarte")
+ layout.addLayoutItem(hauptkarte)
+ hauptkarte.attemptMove(QgsLayoutPoint(map_left_mm, map_top_mm, MM))
+ hauptkarte.attemptResize(QgsLayoutSize(map_width_mm, map_height_mm, MM))
+
+ # Verifiziere mit Units-bewussten Methoden (rect() kann andere Units verwenden).
+ actual_w = None
+ actual_h = None
+ actual_x = None
+ actual_y = None
+
+ # Versuche zuerst, die Größe mit Unit-Methoden zu lesen
+ try:
+ if hasattr(hauptkarte, 'sizeWithUnits'):
+ size_item = hauptkarte.sizeWithUnits()
+ if hasattr(size_item, 'width') and hasattr(size_item, 'height'):
+ actual_w = float(size_item.width())
+ actual_h = float(size_item.height())
+ except Exception:
+ pass
+
+ try:
+ if hasattr(hauptkarte, 'positionWithUnits'):
+ pos_item = hauptkarte.positionWithUnits()
+ if hasattr(pos_item, 'x') and hasattr(pos_item, 'y'):
+ actual_x = float(pos_item.x())
+ actual_y = float(pos_item.y())
+ except Exception:
+ pass
+
+ # Fallback: nutze rect() und teile durch UnitFaktor, falls nötig
+ if actual_w is None or actual_h is None:
+ try:
+ actual_rect = hauptkarte.rect()
+ if actual_rect is not None:
+ actual_w = float(actual_rect.width())
+ actual_h = float(actual_rect.height())
+ actual_x = float(actual_rect.x())
+ actual_y = float(actual_rect.y())
+ except Exception:
+ pass
+
+ if actual_w is not None and actual_h is not None:
+ print(f"[Layout] Atlas Hauptkarte gesetzt: x={map_left_mm:.1f}mm→{actual_x:.1f}mm, y={map_top_mm:.1f}mm→{actual_y:.1f}mm, width={map_width_mm:.1f}mm→{actual_w:.1f}mm, height={map_height_mm:.1f}mm→{actual_h:.1f}mm")
+ else:
+ print(f"[Layout] Atlas Hauptkarte: x={map_left_mm:.1f}mm, y={map_top_mm:.1f}mm, width={map_width_mm:.1f}mm, height={map_height_mm:.1f}mm")
+
+ if extent is not None and hasattr(extent, "isNull") and callable(extent.isNull) and not extent.isNull():
+ try:
+ hauptkarte.setExtent(extent)
+ except Exception:
+ pass
+
+ if isinstance(plotmassstab, (int, float)) and math.isfinite(plotmassstab) and plotmassstab > 0:
+ try:
+ hauptkarte.setScale(plotmassstab)
+ except Exception:
+ pass
+
+ set_frame_enabled = getattr(hauptkarte, "setFrameEnabled", None)
+ if callable(set_frame_enabled):
+ try:
+ set_frame_enabled(True)
+ except Exception:
+ pass
+
+ set_frame_stroke_width = getattr(hauptkarte, "setFrameStrokeWidth", None)
+ if callable(set_frame_stroke_width):
+ try:
+ set_frame_stroke_width(0.5)
+ except Exception:
+ pass
+
+ if thema and thema != "aktuell":
+ follow_theme = getattr(hauptkarte, "setFollowVisibilityPreset", None)
+ set_theme_name = getattr(hauptkarte, "setFollowVisibilityPresetName", None)
+ if callable(follow_theme):
+ try:
+ follow_theme(True)
+ except Exception:
+ pass
+ if callable(set_theme_name):
+ try:
+ set_theme_name(thema)
+ except Exception:
+ pass
+
+ set_atlas_driven = getattr(hauptkarte, "setAtlasDriven", None)
+ if callable(set_atlas_driven):
+ try:
+ set_atlas_driven(True)
+ except Exception:
+ pass
+
+ # Fester Atlas-Maßstab: plotmassstab bleibt unverändert.
+ set_scaling_mode = getattr(hauptkarte, "setAtlasScalingMode", None)
+ if callable(set_scaling_mode):
+ fixed_mode = getattr(QgsLayoutItemMap, "Fixed", None)
+ if fixed_mode is not None:
+ try:
+ set_scaling_mode(fixed_mode)
+ except Exception:
+ pass
+
+ set_atlas_margin = getattr(hauptkarte, "setAtlasMargin", None)
+ if callable(set_atlas_margin):
+ try:
+ set_atlas_margin(0.0)
+ except Exception:
+ pass
+
+ set_keep_layer_set = getattr(hauptkarte, "setKeepLayerSet", None)
+ if callable(set_keep_layer_set):
+ try:
+ set_keep_layer_set(True)
+ except Exception:
+ pass
+
+ # Sicherheit: Größe nochmal nach Atlas-Konfiguration setzen, um sicherzustellen, dass sie nicht von der Atlas-Einstellung überschrieben wurde.
+ hauptkarte.attemptResize(QgsLayoutSize(map_width_mm, map_height_mm, MM))
+ print(f"[Layout] Atlas Hauptkarte Größe nach Atlas-Konfiguration erneut gesetzt: {map_width_mm:.1f}mm × {map_height_mm:.1f}mm")
+
+ quellenangabe = QgsLayoutItemLabel(layout)
+ quellenangabe.setId("Quellenangabe")
+ quellenangabe.setText(
+ "Quelle Geobasisdaten: GeoSN, "
+ "dl-de/by-2-0
"
+ "Quelle Fachdaten: Darstellung auf der Grundlage von Daten und mit Erlaubnis des "
+ "Sächsischen Landesamtes für Umwelt, Landwirtschaft und Geologie