Baufreigabe-Layout fix auf A3/A4
This commit is contained in:
@@ -10,7 +10,6 @@ in der PrintLogic.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
from sn_basis.functions.qt_wrapper import QFont
|
||||
@@ -33,11 +32,12 @@ MM = QgsUnitTypes.LayoutMillimeters
|
||||
|
||||
|
||||
class PrintLayoutBaufreigabe(PrintLayout):
|
||||
"""Erzeugt QGIS-Einzelblatt-Layouts mit fester DIN A3/A4 Querformat-Groesse und 120mm Kartenschild."""
|
||||
"""Erzeugt QGIS-Einzelblatt-Layouts mit fester DIN A3/A4 Querformat-Groesse und 80mm Kartenschild."""
|
||||
|
||||
_FRAME_STROKE_WIDTH_MM = 0.5
|
||||
_KARTENSCHILD_WIDTH_MM = 120.0 # Unterschied zu StandardLayout: 120mm statt 180mm
|
||||
_KARTENSCHILD_WIDTH_MM = 80.0
|
||||
_KARTENSCHILD_HEIGHT_MM = 92.0
|
||||
_ATLAS_FRAME_MARGIN_MM = 10.0
|
||||
_GRID_INTERVAL_MAP_UNITS = 500.0
|
||||
|
||||
# DIN-Formate: nur A3 und A4 im Querformat
|
||||
@@ -55,7 +55,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
"quellenangabe": {
|
||||
"id": "Quellenangabe",
|
||||
"object_name": "Quellenangabe",
|
||||
"size_mm": (120.0, 100.0), # Breite angepasst auf 120mm Kartenschild
|
||||
"size_mm": (80.0, 100.0),
|
||||
"format": "Format_1",
|
||||
},
|
||||
"textfeld": {
|
||||
@@ -69,7 +69,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
"legende": {
|
||||
"id": "Legende",
|
||||
"object_name": "Legende",
|
||||
"size_mm": (120.0, 60.0), # Breite angepasst auf 120mm Kartenschild
|
||||
"size_mm": (80.0, 60.0),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
extent: QgsRectangle der Kartenausdehnung
|
||||
plotmassstab: Plotmassstab (z.B. 5000 fuer 1:5000)
|
||||
thema: Name des Visibility-Presets (optional)
|
||||
fit_extent_to_map: Ob das Extent an die Kartengroe angepasst wird
|
||||
fit_extent_to_map: Wird fuer Baufreigabe ignoriert (feste Kartenflaeche)
|
||||
|
||||
Returns:
|
||||
QgsPrintLayout objektInstance (wird im Layout-Dialog geoeffnet)
|
||||
@@ -152,21 +152,45 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
map_height_mm,
|
||||
)
|
||||
|
||||
fitted_extent = extent
|
||||
if fit_extent_to_map:
|
||||
fitted_extent = self._fit_extent_to_map_item(extent, map_width_mm, map_height_mm)
|
||||
if fitted_extent is not None and hasattr(fitted_extent, "isNull") and callable(fitted_extent.isNull) and not fitted_extent.isNull():
|
||||
_ = fit_extent_to_map
|
||||
if extent is not None and hasattr(extent, "isNull") and callable(extent.isNull) and not extent.isNull():
|
||||
try:
|
||||
hauptkarte.setExtent(fitted_extent)
|
||||
hauptkarte.zoomToExtent(extent)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if isinstance(plotmassstab, (int, float)) and math.isfinite(plotmassstab) and plotmassstab > 0:
|
||||
if isinstance(plotmassstab, (int, float)) and plotmassstab > 0:
|
||||
try:
|
||||
hauptkarte.setScale(plotmassstab)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Hauptkarte standardmaessig Atlas-gesteuert:
|
||||
# - Extent folgt aktuellem Atlas-Objekt
|
||||
# - Skalierung automatisch
|
||||
# - Margin entspricht ca. 1 cm Rand innerhalb der Kartenflaeche
|
||||
set_atlas_driven = getattr(hauptkarte, "setAtlasDriven", None)
|
||||
if callable(set_atlas_driven):
|
||||
try:
|
||||
set_atlas_driven(True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
set_atlas_scaling_mode = getattr(hauptkarte, "setAtlasScalingMode", None)
|
||||
atlas_mode_auto = getattr(getattr(QgsLayoutItemMap, "AtlasScalingMode", object), "Auto", None)
|
||||
if callable(set_atlas_scaling_mode) and atlas_mode_auto is not None:
|
||||
try:
|
||||
set_atlas_scaling_mode(atlas_mode_auto)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
set_atlas_margin = getattr(hauptkarte, "setAtlasMargin", None)
|
||||
if callable(set_atlas_margin):
|
||||
try:
|
||||
set_atlas_margin(self._calc_atlas_margin_percent(map_width_mm, map_height_mm))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
set_frame_enabled = getattr(hauptkarte, "setFrameEnabled", None)
|
||||
if callable(set_frame_enabled):
|
||||
try:
|
||||
@@ -237,7 +261,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
) -> None:
|
||||
"""Erstellt Legende, Quellenangabe und Kartenschild fuer Baufreigabe-Layout.
|
||||
|
||||
Angepasst fuer 120mm Kartenschild statt 180mm, mit proportional skalierten Textfeldern.
|
||||
Angepasst fuer 80mm Kartenschild statt 180mm.
|
||||
"""
|
||||
if self._current_layout is None:
|
||||
raise RuntimeError("Kein Layout aktiv.")
|
||||
@@ -248,7 +272,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
kartenfenster_untere_rechte_ecke_mm[1] + rel_y_mm,
|
||||
)
|
||||
|
||||
# Legende: 120mm Breite (angepasst), hoehe adaptive wie Standard
|
||||
# Legende: 80mm Breite, hoehe adaptive wie Standard
|
||||
legende_x = kartenfenster_untere_rechte_ecke_mm[0] + 10.0
|
||||
legende_height_mm = max(map_height_mm - 122.0, 20.0)
|
||||
legende_y = map_top_mm
|
||||
@@ -270,7 +294,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
equal_column_width=False,
|
||||
)
|
||||
|
||||
# Quellenangabe: 120mm Breite
|
||||
# Quellenangabe: 80mm Breite
|
||||
quellenangabe_x, quellenangabe_y = _coords_rel_untere_rechte_ecke(10.0, -102.0)
|
||||
quellenangabe_hoehe_mm = 20.0
|
||||
quellenangabe_obere_y = quellenangabe_y - quellenangabe_hoehe_mm
|
||||
@@ -296,7 +320,7 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
object_name="Quellenangabe",
|
||||
)
|
||||
|
||||
# Kartenschild: 120mm Breite (angepasst)
|
||||
# Kartenschild: 80mm Breite
|
||||
kartenschild_x, kartenschild_y = _coords_rel_untere_rechte_ecke(10.0, 0.0)
|
||||
self._create_rectangle_box_item(
|
||||
self._current_layout,
|
||||
@@ -323,32 +347,29 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
stroke_width_mm=0.1,
|
||||
)
|
||||
|
||||
# Textfelder im Kartenschild: proportional skaliert auf 120mm
|
||||
# Skalierungsfaktor: 120/180 = 0.667 fuer horizontale Abstaende/Breiten
|
||||
scale_x = self._KARTENSCHILD_WIDTH_MM / 180.0
|
||||
base_x = 16.0 * scale_x # ~10.7mm statt 16mm
|
||||
label_width_scaled = 101.0 * scale_x # ~67.3mm statt 101mm
|
||||
# Textfelder im Kartenschild ohne Skalierungslogik.
|
||||
# Positionen werden bewusst als feste Werte gesetzt und bei Bedarf manuell angepasst.
|
||||
|
||||
labels = [
|
||||
("[% @sn_amt %]", base_x, -84.0, label_width_scaled, 4.0, "Format_1", "Herausgeber"),
|
||||
("[% @sn_bezeichnung %]", base_x, -75.0, label_width_scaled, 4.0, "Format_1", "Bezeichnung_Flurbereinigung"),
|
||||
("[% @sn_name %]", base_x, -64.0, label_width_scaled, 5.0, "Format_2", "Name_Flurbereinigung"),
|
||||
("[% @sn_gemeinden %]", base_x, -56.0, label_width_scaled, 4.0, "Format_1", "Stadt_Gemeinde"),
|
||||
("[% @sn_landkreise_proj %]", base_x, -48.0, label_width_scaled, 4.0, "Format_1", "Landkreis"),
|
||||
("[% @sn_kartenname %]", base_x, -32.0, label_width_scaled - 30, 12.0, "Format_3", "Kartenname"),
|
||||
("Gefertigt: ", base_x, -23.0, 40.0 * scale_x, 4.0, "Format_1", "Gefertigt"),
|
||||
("Geprueft: ", base_x + 40.0 * scale_x + 5.0, -23.0, 40.0 * scale_x, 4.0, "Format_1", "Geprueft"),
|
||||
("[% @sn_amt %]", 16.0, -84.0, 171.0, 4.0, "Format_1", "Herausgeber"),
|
||||
("[% @sn_bezeichnung %]", 16.0, -75.0, 171.0, 4.0, "Format_1", "Bezeichnung_Flurbereinigung"),
|
||||
("[% @sn_name %]", 16.0, -64.0, 171.0, 5.0, "Format_2", "Name_Flurbereinigung"),
|
||||
("[% @sn_gemeinden %]", 16.0, -56.0, 171.0, 4.0, "Format_1", "Stadt_Gemeinde"),
|
||||
("[% @sn_landkreise_proj %]", 16.0, -48.0, 171.0, 4.0, "Format_1", "Landkreis"),
|
||||
("[% @sn_kartenname %]", 16.0, -32.0, 137.0, 12.0, "Format_3", "Kartenname"),
|
||||
("Gefertigt: ", 16.0, -23.0, 81.0, 4.0, "Format_1", "Gefertigt"),
|
||||
("Geprueft: ", 101.0, -23.0, 81.0, 4.0, "Format_1", "Geprueft"),
|
||||
(
|
||||
"Massstab: 1 : [%round(map_get(item_variables('Hauptkarte'),'map_scale'),0)%]",
|
||||
base_x,
|
||||
16.0,
|
||||
-13.0,
|
||||
40.0 * scale_x,
|
||||
81.0,
|
||||
4.0,
|
||||
"Format_1",
|
||||
"Massstab",
|
||||
),
|
||||
("Ausgabedatum: [%format_date(now(), 'dd.MM.yyyy')%]", base_x + 40.0 * scale_x + 5.0, -13.0, 40.0 * scale_x, 4.0, "Format_1", "Ausgabedatum"),
|
||||
("Aktenzeichen: ", base_x, -3.0, label_width_scaled, 4.0, "Format_1", "Aktenzeichen"),
|
||||
("Ausgabedatum: [%format_date(now(), 'dd.MM.yyyy')%]", 101.0, -13.0, 81.0, 4.0, "Format_1", "Ausgabedatum"),
|
||||
("Aktenzeichen: ", 16.0, -3.0, 171.0, 4.0, "Format_1", "Aktenzeichen"),
|
||||
]
|
||||
|
||||
for text, rx, ry, w, h, fmt, obj_name in labels:
|
||||
@@ -363,3 +384,13 @@ class PrintLayoutBaufreigabe(PrintLayout):
|
||||
expression_enabled=True,
|
||||
object_name=obj_name,
|
||||
)
|
||||
|
||||
def _calc_atlas_margin_percent(self, map_width_mm: float, map_height_mm: float) -> float:
|
||||
"""Berechnet Atlas-Margin in Prozent, sodass etwa 10 mm Rand sichtbar bleiben."""
|
||||
margin_mm = self._ATLAS_FRAME_MARGIN_MM
|
||||
if map_width_mm <= 2 * margin_mm or map_height_mm <= 2 * margin_mm:
|
||||
return 5.0
|
||||
|
||||
p_width = (100.0 * margin_mm) / (map_width_mm - 2.0 * margin_mm)
|
||||
p_height = (100.0 * margin_mm) / (map_height_mm - 2.0 * margin_mm)
|
||||
return max(p_width, p_height)
|
||||
|
||||
+70
-34
@@ -51,7 +51,7 @@ ATLAS_CONFIG_BAUFREIGABE_DEFAULT: AtlasConfig = {
|
||||
"sort_expression": "",
|
||||
"sort_ascending": True,
|
||||
"hide_coverage": False,
|
||||
"limit_render_to_current_feature": False,
|
||||
"limit_render_to_current_feature": True,
|
||||
"description": "Baufreigabe Atlas mit Standardkonfiguration",
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ PLOTMASSSTAB_VAR = "plotmassstab"
|
||||
VIEW_VAR = "view"
|
||||
ZIELGROESSE_VAR = "zielgroesse"
|
||||
FORMFAKTOR_VAR = "formfaktor"
|
||||
ATLAS_ERZEUGEN_UI_VAR = "tab_b_atlas_erzeugen"
|
||||
DRUCKBEREICH_VAR = "druckbereich"
|
||||
DRUCKPUFFER_VAR = "druckpuffer"
|
||||
DRUCKRECHTECK_LAYER_NAME = "Druckrechteck"
|
||||
@@ -484,6 +485,27 @@ class PrintLogic:
|
||||
if atlas is None:
|
||||
return False
|
||||
|
||||
atlas_enabled = bool(atlas_config.get("enabled", True))
|
||||
if not atlas_enabled:
|
||||
set_enabled = getattr(atlas, "setEnabled", None)
|
||||
if callable(set_enabled):
|
||||
try:
|
||||
set_enabled(False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Hauptkarte ebenfalls aus Atlas-Steuerung lösen
|
||||
item_by_id = getattr(layout, "itemById", None)
|
||||
if callable(item_by_id):
|
||||
try:
|
||||
hauptkarte = item_by_id("Hauptkarte")
|
||||
set_atlas_driven = getattr(hauptkarte, "setAtlasDriven", None)
|
||||
if callable(set_atlas_driven):
|
||||
set_atlas_driven(False)
|
||||
except Exception:
|
||||
pass
|
||||
return True
|
||||
|
||||
coverage_layer_id = get_variable("sn_abdeckungslayer", scope="project") or ""
|
||||
if not coverage_layer_id:
|
||||
return True
|
||||
@@ -888,19 +910,15 @@ class PrintLogic:
|
||||
|
||||
def _get_baufreigabe_page_dimensions(
|
||||
self,
|
||||
kartenbild_w: float,
|
||||
kartenbild_h: float,
|
||||
zielgroesse: str,
|
||||
) -> tuple[str, float, float, float, float]:
|
||||
"""Berechnet Seitenformat und verfuegbare Kartenfenster fuer Baufreigabe.
|
||||
"""Berechnet feste Seiten- und Hauptkartengroessen fuer Baufreigabe.
|
||||
|
||||
Args:
|
||||
kartenbild_w: Berechnete Kartenbild-Breite aus Extent/Massstab
|
||||
kartenbild_h: Berechnete Kartenbild-Hoehe aus Extent/Massstab
|
||||
zielgroesse: "DIN A3" oder "DIN A4" (wird zu Querformat konvertiert)
|
||||
|
||||
Returns:
|
||||
(din_format, page_width_mm, page_height_mm, adjusted_map_w, adjusted_map_h)
|
||||
(din_format, page_width_mm, page_height_mm, map_w_mm, map_h_mm)
|
||||
"""
|
||||
# Nur A3/A4 im Querformat fuer Baufreigabe
|
||||
if zielgroesse == "DIN A3":
|
||||
@@ -910,18 +928,21 @@ class PrintLogic:
|
||||
din_format = "DIN A4"
|
||||
page_w, page_h = 297.0, 210.0
|
||||
|
||||
# Verfuegbare Flaeche fuer Kartenbild: Seite - Kartenschild und Maerchen
|
||||
kartenschild_w = 120.0
|
||||
# Feste Hauptkartenflaeche aus Querformat mit festen Rändern:
|
||||
# links 10 mm, oben 10 mm, rechts 10 mm, unten 10 mm,
|
||||
# plus 10 mm Abstand zum rechten Seitenbereich.
|
||||
kartenschild_w = 80.0
|
||||
kartenschild_h = 92.0
|
||||
margin = 10.0
|
||||
|
||||
avail_w = page_w - 2 * margin - kartenschild_w - margin
|
||||
avail_h = page_h - 2 * margin - kartenschild_h - margin
|
||||
map_w = page_w - (3 * margin + kartenschild_w)
|
||||
map_h = page_h - (2 * margin)
|
||||
|
||||
adjusted_map_w = min(kartenbild_w, avail_w)
|
||||
adjusted_map_h = min(kartenbild_h, avail_h)
|
||||
# Untergrenzen zur Sicherheit bei abweichenden Seiteneinstellungen
|
||||
map_w = max(map_w, 50.0)
|
||||
map_h = max(map_h, kartenschild_h + margin)
|
||||
|
||||
return din_format, page_w, page_h, adjusted_map_w, adjusted_map_h
|
||||
return din_format, page_w, page_h, map_w, map_h
|
||||
|
||||
def druckvorlage_anlegen(
|
||||
self,
|
||||
@@ -983,22 +1004,23 @@ class PrintLogic:
|
||||
ziel_w = min(plotgroesse_w, cap_w)
|
||||
ziel_h = min(plotgroesse_h, cap_h)
|
||||
|
||||
if ziel_w < DIN_GROESSEN["DIN A4"][0] or ziel_h < DIN_GROESSEN["DIN A4"][1]:
|
||||
self.pruefmanager.zeige_hinweis(
|
||||
"Blattgroesse kleiner als DIN A4",
|
||||
"Die Layouterstellung wird trotzdem fortgesetzt.",
|
||||
)
|
||||
if kartenname_auswahl != KARTENNAME_BAUFREIGABE:
|
||||
if ziel_w < DIN_GROESSEN["DIN A4"][0] or ziel_h < DIN_GROESSEN["DIN A4"][1]:
|
||||
self.pruefmanager.zeige_hinweis(
|
||||
"Blattgroesse kleiner als DIN A4",
|
||||
"Die Layouterstellung wird trotzdem fortgesetzt.",
|
||||
)
|
||||
|
||||
if plotgroesse_w > ziel_w or plotgroesse_h > ziel_h:
|
||||
if plotgroesse_w <= ziel_h and plotgroesse_h <= ziel_w:
|
||||
ziel_w, ziel_h = ziel_h, ziel_w
|
||||
if plotgroesse_w > ziel_w or plotgroesse_h > ziel_h:
|
||||
if plotgroesse_w <= ziel_h and plotgroesse_h <= ziel_w:
|
||||
ziel_w, ziel_h = ziel_h, ziel_w
|
||||
|
||||
if plotgroesse_w > ziel_w or plotgroesse_h > ziel_h:
|
||||
self.pruefmanager.zeige_hinweis(
|
||||
"Zielgroesse zu klein",
|
||||
"Die gewaehlte Zielgroesse reicht fuer den Einzelblatt-Druck nicht aus.",
|
||||
)
|
||||
return {"ok": False, "switch_to_tab_a": False, "atlas_seiten": 0}
|
||||
if plotgroesse_w > ziel_w or plotgroesse_h > ziel_h:
|
||||
self.pruefmanager.zeige_hinweis(
|
||||
"Zielgroesse zu klein",
|
||||
"Die gewaehlte Zielgroesse reicht fuer den Einzelblatt-Druck nicht aus.",
|
||||
)
|
||||
return {"ok": False, "switch_to_tab_a": False, "atlas_seiten": 0}
|
||||
|
||||
kartenname = get_variable(KARTENNAME_VAR, scope="project") or KARTENNAME_BY_AUSWAHL.get(
|
||||
kartenname_auswahl, "Vorlage"
|
||||
@@ -1018,10 +1040,8 @@ class PrintLogic:
|
||||
# Verzweigung: Baufreigabe vs. Standard-Layout
|
||||
try:
|
||||
if kartenname_auswahl == KARTENNAME_BAUFREIGABE:
|
||||
# Baufreigabe: feste DIN A3/A4 Querformat-Logik mit 120mm Kartenschild
|
||||
din_format, page_w, page_h, map_w, map_h = self._get_baufreigabe_page_dimensions(
|
||||
kartenbild_w, kartenbild_h, zielgroesse
|
||||
)
|
||||
# Baufreigabe: feste DIN A3/A4 Querformat-Logik mit 80mm Kartenschild
|
||||
din_format, page_w, page_h, map_w, map_h = self._get_baufreigabe_page_dimensions(zielgroesse)
|
||||
PrintLayoutBaufreigabe().create_baufreigabe_layout(
|
||||
name=vorlage_name if vorlage_name != kartenname else "Baufreigabe",
|
||||
din_format=din_format,
|
||||
@@ -1055,8 +1075,24 @@ class PrintLogic:
|
||||
)
|
||||
return {"ok": False, "switch_to_tab_a": False, "atlas_seiten": 0}
|
||||
|
||||
# Nach erfolgreicher Layout-Erstellung: Atlas konfigurieren (falls Baufreigabe)
|
||||
# Nach erfolgreicher Layout-Erstellung: Atlas ggf. konfigurieren (nur falls aktiviert)
|
||||
if kartenname_auswahl == KARTENNAME_BAUFREIGABE:
|
||||
self.configure_atlas_for_baufreigabe_layout()
|
||||
atlas_raw = get_variable(ATLAS_ERZEUGEN_UI_VAR, scope="project")
|
||||
atlas_erzeugen = True if atlas_raw in (None, "") else str(atlas_raw).strip().lower() in {
|
||||
"1",
|
||||
"true",
|
||||
"ja",
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
|
||||
if atlas_erzeugen:
|
||||
self.configure_atlas_for_baufreigabe_layout()
|
||||
else:
|
||||
self.configure_atlas_for_baufreigabe_layout(
|
||||
atlas_config={
|
||||
"enabled": False,
|
||||
}
|
||||
)
|
||||
|
||||
return {"ok": True, "switch_to_tab_a": False, "atlas_seiten": 1}
|
||||
|
||||
Reference in New Issue
Block a user