Modulo 1: serializacion Hull / Project en formato .arsd (Task 11)

- hull.py: Hull.to_dict() serializa a dict JSON con formato hull_v1
  (arrays numpy -> listas Python); Hull.from_dict() deserializa con
  validacion de claves y forma de array.

- project.py: Project.hull (property lazy) deserializa el Hull desde
  ship_data; Project.set_hull() persiste el Hull y marca is_modified.

- main_window.py: _on_new_project guarda el Hull en el proyecto;
  _on_project_loaded restaura el Hull en todos los visores al abrir
  un archivo .arsd; _on_hull_changed_from_editor mantiene el proyecto
  sincronizado con ediciones en el editor de offsets.

- test_serialization.py: 26 tests (round-trip dict, round-trip ZIP,
  5 familias parametricas, escritura atomica, proyecto sin Hull).

Suite total: 112 tests -- 112 passed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 08:33:34 -04:00
parent 2137b0a228
commit 3b0d5e9e50
4 changed files with 376 additions and 1 deletions
+10 -1
View File
@@ -1224,6 +1224,7 @@ class MainWindow(QMainWindow):
self._on_project_loaded()
if hull is not None:
self._current_hull = hull
self._project.set_hull(hull) # persistir en ship_data
self._load_hull_viewers(hull)
self.statusBar().showMessage(
f"Nuevo proyecto: {self._project.name}"
@@ -1282,6 +1283,12 @@ class MainWindow(QMainWindow):
def _on_project_loaded(self) -> None:
self._update_title()
self._layers_panel.set_project(self._project)
# Restaurar Hull si el proyecto contiene geometría guardada
hull = self._project.hull
if hull is not None:
self._current_hull = hull
self._load_hull_viewers(hull)
logger.info("Hull '%s' restaurado desde proyecto", hull.name)
def _load_hull_viewers(self, hull, *, _skip_offsets_editor: bool = False) -> None:
"""Carga el casco en todos los visores (2D, 3D, offsets) y actualiza hidrostáticos.
@@ -1306,8 +1313,10 @@ class MainWindow(QMainWindow):
self._update_hydrostatics(hull)
def _on_hull_changed_from_editor(self, hull) -> None:
"""Slot: el editor de offsets reconstruyo el Hull — propagar a los demas visores."""
"""Slot: el editor de offsets reconstruyo el Hull — propagar a visores y proyecto."""
self._current_hull = hull
if self._project is not None:
self._project.set_hull(hull) # mantener proyecto sincronizado
# _skip_offsets_editor=True para no re-poblar la tabla (ya esta actualizada)
self._load_hull_viewers(hull, _skip_offsets_editor=True)
self.statusBar().showMessage(f"Offsets actualizados — {hull.name}")