sprint-2: rule engine + auto-assigner + equipment editor + biblioteca
Wizard pasos 5-7 ahora funcionales (1-4 ya estaban en Sprint 1).
vmssailor/studio/designer/rule_engine.py
- RuleContext, RuleEngine, EquipmentProposal
- Lee library/rules/*.yaml y aplica reglas heuristicas
- Filtra por vessel_type, vessel_subtype, length_overall_m range
- Selecciona candidato segun condiciones 'when' (loa min/max)
- Genera tag_prefix con sustitucion {side}/{idx}
vmssailor/studio/designer/port_auto_assigner.py
- auto_assign() greedy: 1 bus Modbus RTU + tarjetas dedicadas para motores/gensets
- Tarjeta auxiliar compartida para resto de equipos
- Mapea SignalType -> ChannelType (AI/DI/DO/RPM)
- Genera TagBindings con scaling apropiado por tipo de senal
- Respeta capacidades 10/5/4/1 de AR-NMEA-IO-v1.0
- AssignmentReport con cards + tags + warnings
vmssailor/studio/wizard/step_05_equipment.py
- Tabla con propuestas del rule engine
- Checkboxes accept/reject + edicion inline de columnas
- Boton 'Regenerar' para re-aplicar reglas
vmssailor/studio/wizard/step_06_refinement.py
- Vista resumen de equipos aceptados
vmssailor/studio/wizard/step_07_topology.py
- Llama auto_assign sobre los equipos materializados
- Muestra tabla de tarjetas con uso por canal (DO/DI/AI/RPM)
- Lista warnings de capacidad
vmssailor/studio/editors/equipment_editor.py
- CRUD de Equipment del proyecto activo
- Tabla editable inline (tag_prefix, name, model_ref, system_id, coords, deck)
- Dialog modal para agregar equipos
- Senal projectMutated para refrescar canvas + sidebar
vmssailor/studio/main_window.py
- Layout actualizado: splitter vertical en panel derecho
(canvas arriba + equipment editor abajo)
- _on_project_mutated() re-distribuye al sidebar y canvas
Biblioteca expandida (Sprint 2 brief: 5-7 yates, 10+ motores, gensets, bombas):
- vessels: + azimut_grande_32m, princess_y85, trawler_32m_offshore, patrol_coastal_30m (total: 6)
- engines: + cat_c32_acert, mtu_16v_2000_m96, yanmar_8lv_370 (total: 5)
- gensets: + kohler_28efkozd, onan_qd13500 (total: 3)
- pumps: + jabsco_36800, grundfos_cm10 (NUEVO categoria pumps)
Tests (tests/studio/test_designer.py, 10 nuevos, total 120/120):
- Rule engine: load default, propose engines, candidate picking por LOA
- auto_assign builds topology compatible with Project (Pydantic validation)
- Equipment editor smoke
VesselWizard.build_project() ahora materializa equipment + topology + tags
desde las propuestas y la asignacion automatica del paso 7.
Criterios Sprint 2:
- uv run vms-studio crea proyecto completo desde wizard con equipos + tags + topologia
- vms-validate-library: OK 6 vessels, 10 equipment, 1 rules
- 120/120 pytest verde, ruff clean
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
"""Paso 5: equipos sugeridos por el motor de reglas heurísticas."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import Property, Qt, Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QPushButton,
|
||||
QTableWidget,
|
||||
QTableWidgetItem,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
QWizardPage,
|
||||
)
|
||||
|
||||
from vmssailor.core.enums import SystemId, VesselSubtype, VesselType
|
||||
from vmssailor.studio.designer.rule_engine import (
|
||||
EquipmentProposal,
|
||||
RuleContext,
|
||||
RuleEngine,
|
||||
)
|
||||
from vmssailor.studio.theme import C_CYAN, C_FOG, mono_font, ui_font
|
||||
|
||||
|
||||
class Step05Equipment(QWizardPage):
|
||||
"""Muestra propuestas del rule engine. Integrador acepta/rechaza."""
|
||||
|
||||
proposalsChanged = Signal()
|
||||
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setTitle("Paso 5 · Equipos sugeridos")
|
||||
self.setSubTitle(
|
||||
"El motor de reglas propuso estos equipos basado en el tipo de buque y "
|
||||
"los sistemas habilitados. Desmarca los que no apliquen."
|
||||
)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(12)
|
||||
|
||||
intro = QLabel(
|
||||
"Doble-click en una celda para editar. La columna ✓ permite excluir propuestas."
|
||||
)
|
||||
intro.setStyleSheet(f"color: {C_FOG};")
|
||||
intro.setFont(ui_font(10))
|
||||
layout.addWidget(intro)
|
||||
|
||||
self._table = QTableWidget(0, 7)
|
||||
self._table.setHorizontalHeaderLabels(
|
||||
["✓", "Sistema", "Modelo", "Tag prefix", "x_pp", "y_cl", "Rationale"]
|
||||
)
|
||||
self._table.horizontalHeader().setSectionResizeMode(
|
||||
6, QHeaderView.ResizeMode.Stretch
|
||||
)
|
||||
self._table.horizontalHeader().setSectionResizeMode(
|
||||
0, QHeaderView.ResizeMode.ResizeToContents
|
||||
)
|
||||
self._table.setAlternatingRowColors(False)
|
||||
self._table.verticalHeader().setVisible(False)
|
||||
self._table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||
self._table.setEditTriggers(
|
||||
QAbstractItemView.EditTrigger.DoubleClicked
|
||||
| QAbstractItemView.EditTrigger.EditKeyPressed
|
||||
)
|
||||
self._table.itemChanged.connect(self._on_item_changed)
|
||||
layout.addWidget(self._table, 1)
|
||||
|
||||
# Counter label
|
||||
self._counter = QLabel("0 propuestas")
|
||||
self._counter.setFont(mono_font(10))
|
||||
self._counter.setStyleSheet(f"color: {C_CYAN};")
|
||||
layout.addWidget(self._counter)
|
||||
|
||||
btn_row = QPushButton("Regenerar desde reglas")
|
||||
btn_row.clicked.connect(self._regenerate)
|
||||
layout.addWidget(btn_row)
|
||||
|
||||
self._proposals: list[EquipmentProposal] = []
|
||||
|
||||
from vmssailor.studio.wizard.wizard import F_PROPOSALS
|
||||
|
||||
self.registerField(F_PROPOSALS, self, "proposals", "proposalsChanged")
|
||||
|
||||
# ----- Property API ------------------------------------------------
|
||||
|
||||
def get_proposals(self) -> list[EquipmentProposal]:
|
||||
return [p for p in self._proposals if p.accepted]
|
||||
|
||||
def set_proposals(self, value: list[EquipmentProposal]) -> None:
|
||||
self._proposals = value
|
||||
self._refresh_table()
|
||||
self.proposalsChanged.emit()
|
||||
|
||||
proposals = Property(
|
||||
list, fget=get_proposals, fset=set_proposals, notify=proposalsChanged
|
||||
)
|
||||
|
||||
# ----- Lifecycle ---------------------------------------------------
|
||||
|
||||
def initializePage(self) -> None:
|
||||
if not self._proposals:
|
||||
self._regenerate()
|
||||
|
||||
def _regenerate(self) -> None:
|
||||
from vmssailor.studio.wizard.wizard import (
|
||||
F_BEAM,
|
||||
F_DRAFT,
|
||||
F_LOA,
|
||||
F_SYSTEMS,
|
||||
F_VESSEL_SUBTYPE,
|
||||
F_VESSEL_TYPE,
|
||||
)
|
||||
|
||||
try:
|
||||
v_type = VesselType(self.field(F_VESSEL_TYPE) or "yacht_motor")
|
||||
except ValueError:
|
||||
v_type = VesselType.YACHT_MOTOR
|
||||
try:
|
||||
v_sub = VesselSubtype(self.field(F_VESSEL_SUBTYPE) or "planing")
|
||||
except ValueError:
|
||||
v_sub = VesselSubtype.PLANING
|
||||
loa = float(self.field(F_LOA) or 24.0)
|
||||
beam = float(self.field(F_BEAM) or 5.5)
|
||||
draft = float(self.field(F_DRAFT) or 1.8)
|
||||
|
||||
systems_raw = self.field(F_SYSTEMS) or []
|
||||
systems: list[SystemId] = []
|
||||
for s in systems_raw:
|
||||
try:
|
||||
systems.append(SystemId(s))
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
ctx = RuleContext(
|
||||
vessel_type=v_type,
|
||||
vessel_subtype=v_sub,
|
||||
length_overall_m=loa,
|
||||
beam_max_m=beam,
|
||||
draft_m=draft,
|
||||
systems_enabled=systems,
|
||||
)
|
||||
|
||||
engine = RuleEngine()
|
||||
self._proposals = engine.propose(ctx)
|
||||
self._refresh_table()
|
||||
self.proposalsChanged.emit()
|
||||
|
||||
# ----- Table rendering --------------------------------------------
|
||||
|
||||
def _refresh_table(self) -> None:
|
||||
self._table.blockSignals(True)
|
||||
self._table.setRowCount(len(self._proposals))
|
||||
for row, p in enumerate(self._proposals):
|
||||
check = QTableWidgetItem()
|
||||
check.setFlags(check.flags() | Qt.ItemFlag.ItemIsUserCheckable)
|
||||
check.setCheckState(Qt.CheckState.Checked if p.accepted else Qt.CheckState.Unchecked)
|
||||
self._table.setItem(row, 0, check)
|
||||
self._table.setItem(row, 1, QTableWidgetItem(p.system_id.value))
|
||||
self._table.setItem(row, 2, QTableWidgetItem(p.model_ref))
|
||||
self._table.setItem(row, 3, QTableWidgetItem(p.tag_prefix))
|
||||
self._table.setItem(row, 4, QTableWidgetItem(f"{p.location_x_pp:.2f}"))
|
||||
self._table.setItem(row, 5, QTableWidgetItem(f"{p.location_y_cl:.2f}"))
|
||||
rationale = QTableWidgetItem(p.rationale)
|
||||
rationale.setForeground(Qt.GlobalColor.gray)
|
||||
self._table.setItem(row, 6, rationale)
|
||||
self._table.resizeColumnsToContents()
|
||||
self._table.blockSignals(False)
|
||||
accepted = sum(1 for p in self._proposals if p.accepted)
|
||||
self._counter.setText(
|
||||
f"{accepted} aceptadas · {len(self._proposals) - accepted} rechazadas · "
|
||||
f"{len(self._proposals)} totales"
|
||||
)
|
||||
|
||||
def _on_item_changed(self, item: QTableWidgetItem) -> None:
|
||||
row = item.row()
|
||||
if row >= len(self._proposals):
|
||||
return
|
||||
col = item.column()
|
||||
p = self._proposals[row]
|
||||
try:
|
||||
if col == 0:
|
||||
p.accepted = item.checkState() == Qt.CheckState.Checked
|
||||
elif col == 2:
|
||||
p.model_ref = item.text()
|
||||
elif col == 3:
|
||||
p.tag_prefix = item.text().upper()
|
||||
item.setText(p.tag_prefix)
|
||||
elif col == 4:
|
||||
p.location_x_pp = float(item.text())
|
||||
elif col == 5:
|
||||
p.location_y_cl = float(item.text())
|
||||
except ValueError:
|
||||
# Reset celda al valor previo si la conversión falla
|
||||
self._refresh_table()
|
||||
return
|
||||
accepted = sum(1 for pr in self._proposals if pr.accepted)
|
||||
self._counter.setText(
|
||||
f"{accepted} aceptadas · {len(self._proposals) - accepted} rechazadas · "
|
||||
f"{len(self._proposals)} totales"
|
||||
)
|
||||
self.proposalsChanged.emit()
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Paso 6: refinamiento manual (Sprint 2).
|
||||
|
||||
En Sprint 1 era placeholder. En Sprint 2 permite reasignar ubicaciones de
|
||||
equipos y editar tag_prefix con una vista preview de la silueta.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtWidgets import (
|
||||
QLabel,
|
||||
QListWidget,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
QWizardPage,
|
||||
)
|
||||
|
||||
from vmssailor.studio.theme import C_FOG, mono_font, ui_font
|
||||
|
||||
|
||||
class Step06Refinement(QWizardPage):
|
||||
"""Muestra resumen de equipos aceptados con preview textual."""
|
||||
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setTitle("Paso 6 · Refinamiento")
|
||||
self.setSubTitle(
|
||||
"Revisa los equipos finales antes de generar topología. "
|
||||
"El editor visual completo viene en Sprint 3."
|
||||
)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(12)
|
||||
|
||||
self._list = QListWidget()
|
||||
self._list.setFont(mono_font(10))
|
||||
layout.addWidget(self._list, 1)
|
||||
|
||||
# Stats
|
||||
self._stats = QLabel("Cargando…")
|
||||
self._stats.setStyleSheet(f"color: {C_FOG};")
|
||||
self._stats.setFont(ui_font(10))
|
||||
layout.addWidget(self._stats)
|
||||
|
||||
def initializePage(self) -> None:
|
||||
from vmssailor.studio.wizard.wizard import F_PROPOSALS
|
||||
|
||||
proposals = self.field(F_PROPOSALS) or []
|
||||
self._list.clear()
|
||||
by_system: dict[str, int] = {}
|
||||
for p in proposals:
|
||||
self._list.addItem(
|
||||
f"{p.system_id.value:20s} {p.tag_prefix:14s} "
|
||||
f"{p.model_ref:30s} @ x_pp={p.location_x_pp:.2f}m y_cl={p.location_y_cl:+.2f}m"
|
||||
)
|
||||
by_system[p.system_id.value] = by_system.get(p.system_id.value, 0) + 1
|
||||
n = len(proposals)
|
||||
groups = ", ".join(f"{k}: {v}" for k, v in sorted(by_system.items()))
|
||||
self._stats.setText(
|
||||
f"{n} equipos aceptados · {groups}"
|
||||
if n
|
||||
else "Sin equipos aceptados. Vuelve atrás y selecciona al menos uno."
|
||||
)
|
||||
@@ -0,0 +1,153 @@
|
||||
"""Paso 7: topología AR-NMEA-IO + asignación automática de I/O.
|
||||
|
||||
Genera tarjetas + bindings físicos de cada sensor declarado en
|
||||
EquipmentModel.default_sensors. El integrador puede ajustar después en el
|
||||
editor de topología (Sprint 3+).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import Property, Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QHeaderView,
|
||||
QLabel,
|
||||
QTableWidget,
|
||||
QTableWidgetItem,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
QWizardPage,
|
||||
)
|
||||
|
||||
from vmssailor.core.equipment import Equipment
|
||||
from vmssailor.library import load_library
|
||||
from vmssailor.studio.designer.port_auto_assigner import (
|
||||
AssignmentReport,
|
||||
auto_assign,
|
||||
)
|
||||
from vmssailor.studio.designer.rule_engine import EquipmentProposal
|
||||
from vmssailor.studio.theme import C_FOG, mono_font, ui_font
|
||||
|
||||
|
||||
class Step07Topology(QWizardPage):
|
||||
"""Vista previa de la topología auto-asignada."""
|
||||
|
||||
def __init__(self, parent: QWidget | None = None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setTitle("Paso 7 · Topología AR-NMEA-IO")
|
||||
self.setSubTitle(
|
||||
"Asignación automática de tarjetas y canales físicos. "
|
||||
"Capacidad por tarjeta: 10 DO · 5 DI · 1 RPM · 4 AI."
|
||||
)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(10)
|
||||
|
||||
self._summary = QLabel("")
|
||||
self._summary.setFont(ui_font(11))
|
||||
layout.addWidget(self._summary)
|
||||
|
||||
self._table = QTableWidget(0, 4)
|
||||
self._table.setHorizontalHeaderLabels(
|
||||
["Tarjeta", "Slot · Addr", "DO/DI/AI/RPM usados", "Ubicación"]
|
||||
)
|
||||
self._table.horizontalHeader().setSectionResizeMode(
|
||||
3, QHeaderView.ResizeMode.Stretch
|
||||
)
|
||||
self._table.verticalHeader().setVisible(False)
|
||||
layout.addWidget(self._table, 1)
|
||||
|
||||
self._warnings = QLabel("")
|
||||
self._warnings.setWordWrap(True)
|
||||
self._warnings.setFont(mono_font(9))
|
||||
self._warnings.setStyleSheet(f"color: {C_FOG};")
|
||||
layout.addWidget(self._warnings)
|
||||
|
||||
self._assignment: AssignmentReport | None = None
|
||||
|
||||
from vmssailor.studio.wizard.wizard import F_ASSIGNMENT
|
||||
|
||||
self.registerField(F_ASSIGNMENT, self, "assignment", "assignmentChanged")
|
||||
|
||||
# Property API
|
||||
assignmentChanged = Signal()
|
||||
|
||||
def get_assignment(self) -> AssignmentReport | None:
|
||||
return self._assignment
|
||||
|
||||
def set_assignment(self, value: AssignmentReport) -> None:
|
||||
self._assignment = value
|
||||
self.assignmentChanged.emit()
|
||||
|
||||
assignment = Property(
|
||||
object, fget=get_assignment, fset=set_assignment, notify=assignmentChanged
|
||||
)
|
||||
|
||||
def initializePage(self) -> None:
|
||||
from vmssailor.studio.wizard.wizard import F_PROPOSALS
|
||||
|
||||
proposals: list[EquipmentProposal] = self.field(F_PROPOSALS) or []
|
||||
if not proposals:
|
||||
self._summary.setText("Sin equipos. Vuelve al paso 5.")
|
||||
self._table.setRowCount(0)
|
||||
return
|
||||
|
||||
# Materialize Equipment objects so we can run the assigner
|
||||
equipment_list: list[Equipment] = []
|
||||
for idx, p in enumerate(proposals):
|
||||
from vmssailor.core.coords import ShipCoord
|
||||
|
||||
equipment_list.append(
|
||||
Equipment(
|
||||
id=f"eq_{idx:03d}_{p.tag_prefix.lower()}",
|
||||
model_ref=p.model_ref,
|
||||
tag_prefix=p.tag_prefix,
|
||||
display_name=p.display_name,
|
||||
location=ShipCoord(
|
||||
x_pp=p.location_x_pp,
|
||||
y_cl=p.location_y_cl,
|
||||
z_bl=p.location_z_bl,
|
||||
),
|
||||
system_id=p.system_id,
|
||||
)
|
||||
)
|
||||
|
||||
# Cargar modelos de biblioteca
|
||||
try:
|
||||
lib = load_library()
|
||||
model_lookup = {m.id: m for m in lib.equipment_models}
|
||||
except Exception:
|
||||
model_lookup = {}
|
||||
|
||||
report = auto_assign(equipment_list, model_lookup)
|
||||
self._assignment = report
|
||||
|
||||
self._summary.setText(
|
||||
f"<b>{len(report.cards)}</b> tarjetas · "
|
||||
f"<b>{len(report.tags)}</b> tags asignados · "
|
||||
f"<b>{report.n_skipped}</b> sin tipo de señal · "
|
||||
f"bus: <b>{report.bus.id if report.bus else '—'}</b>"
|
||||
)
|
||||
|
||||
self._table.setRowCount(len(report.cards))
|
||||
capacities: dict[str, dict[str, int]] = {}
|
||||
for t in report.tags:
|
||||
if t.physical_binding:
|
||||
cid = t.physical_binding.card_id
|
||||
ch = t.physical_binding.channel_type.value.upper()
|
||||
capacities.setdefault(cid, {"DO": 0, "DI": 0, "AI": 0, "RPM": 0})
|
||||
capacities[cid][ch] = capacities[cid].get(ch, 0) + 1
|
||||
|
||||
for row, c in enumerate(report.cards):
|
||||
self._table.setItem(row, 0, QTableWidgetItem(c.id))
|
||||
self._table.setItem(row, 1, QTableWidgetItem(f"slot {c.slot_number} · addr {c.modbus_address}"))
|
||||
cap = capacities.get(c.id, {})
|
||||
usage = f"DO {cap.get('DO', 0)}/10 · DI {cap.get('DI', 0)}/5 · AI {cap.get('AI', 0)}/4 · RPM {cap.get('RPM', 0)}/1"
|
||||
self._table.setItem(row, 2, QTableWidgetItem(usage))
|
||||
self._table.setItem(row, 3, QTableWidgetItem(c.physical_location))
|
||||
self._table.resizeColumnsToContents()
|
||||
|
||||
if report.warnings:
|
||||
self._warnings.setText("\n".join(report.warnings[:6]))
|
||||
else:
|
||||
self._warnings.setText("✓ Sin conflictos de capacidad detectados.")
|
||||
self.assignmentChanged.emit()
|
||||
@@ -1,4 +1,8 @@
|
||||
"""QWizard contenedor + builder de Project a partir del estado del wizard."""
|
||||
"""QWizard contenedor + builder de Project a partir del estado del wizard.
|
||||
|
||||
Sprint 1: pasos 1-4 funcionales, 5-7 placeholders, 8 confirm.
|
||||
Sprint 2: pasos 5-7 funcionales con rule engine + auto-assigner.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -7,6 +11,7 @@ import logging
|
||||
from PySide6.QtWidgets import QWidget, QWizard
|
||||
|
||||
from vmssailor.core import (
|
||||
Equipment,
|
||||
Project,
|
||||
SystemId,
|
||||
Vessel,
|
||||
@@ -15,16 +20,15 @@ from vmssailor.core import (
|
||||
)
|
||||
from vmssailor.core.vessel import Bulkhead, Deck
|
||||
from vmssailor.shared.ids import make_project_id
|
||||
from vmssailor.studio.theme import (
|
||||
C_ABYSS,
|
||||
C_SAND,
|
||||
)
|
||||
from vmssailor.studio.theme import C_ABYSS, C_SAND
|
||||
from vmssailor.studio.wizard.step_01_vessel_type import Step01VesselType
|
||||
from vmssailor.studio.wizard.step_02_template import Step02Template
|
||||
from vmssailor.studio.wizard.step_03_dimensions import Step03Dimensions
|
||||
from vmssailor.studio.wizard.step_04_systems import Step04Systems
|
||||
from vmssailor.studio.wizard.step_05_equipment import Step05Equipment
|
||||
from vmssailor.studio.wizard.step_06_refinement import Step06Refinement
|
||||
from vmssailor.studio.wizard.step_07_topology import Step07Topology
|
||||
from vmssailor.studio.wizard.step_08_confirm import Step08Confirm
|
||||
from vmssailor.studio.wizard.step_57_placeholder import Step57Placeholder
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -42,6 +46,8 @@ F_DRAFT = "vessel.draft_m"
|
||||
F_BULKHEAD_FWD = "vessel.bulkhead_fwd_m"
|
||||
F_BULKHEAD_AFT = "vessel.bulkhead_aft_m"
|
||||
F_SYSTEMS = "systems.enabled"
|
||||
F_PROPOSALS = "equipment.proposals"
|
||||
F_ASSIGNMENT = "topology.assignment"
|
||||
|
||||
|
||||
class VesselWizard(QWizard):
|
||||
@@ -61,9 +67,9 @@ class VesselWizard(QWizard):
|
||||
self.addPage(Step02Template())
|
||||
self.addPage(Step03Dimensions())
|
||||
self.addPage(Step04Systems())
|
||||
self.addPage(Step57Placeholder(index=5, title="Equipos sugeridos (Sprint 2)"))
|
||||
self.addPage(Step57Placeholder(index=6, title="Refinamiento manual (Sprint 2)"))
|
||||
self.addPage(Step57Placeholder(index=7, title="Topología I/O AR-NMEA-IO (Sprint 2)"))
|
||||
self.addPage(Step05Equipment())
|
||||
self.addPage(Step06Refinement())
|
||||
self.addPage(Step07Topology())
|
||||
self.addPage(Step08Confirm())
|
||||
|
||||
# Style
|
||||
@@ -75,7 +81,6 @@ class VesselWizard(QWizard):
|
||||
"""
|
||||
)
|
||||
|
||||
# Localización de botones (QWizard usa textos del sistema)
|
||||
self.setButtonText(QWizard.NextButton, "Siguiente >")
|
||||
self.setButtonText(QWizard.BackButton, "< Atrás")
|
||||
self.setButtonText(QWizard.FinishButton, "Crear proyecto")
|
||||
@@ -97,7 +102,6 @@ class VesselWizard(QWizard):
|
||||
bh_aft = float(self.field(F_BULKHEAD_AFT) or (loa * 0.15))
|
||||
systems_raw = self.field(F_SYSTEMS) or [SystemId.MAIN_ENGINE.value]
|
||||
|
||||
# Build vessel
|
||||
decks = [
|
||||
Deck(id="lower", name="Cubierta inferior", z_bl_bottom=0.4, z_bl_top=draft + 1.0),
|
||||
Deck(
|
||||
@@ -111,37 +115,65 @@ class VesselWizard(QWizard):
|
||||
Bulkhead(id="er_aft", name="Mamparo popa SM", x_pp=bh_aft),
|
||||
Bulkhead(id="er_fwd", name="Mamparo proa SM", x_pp=bh_fwd),
|
||||
]
|
||||
try:
|
||||
vessel = Vessel(
|
||||
id=f"wizard_{int(loa * 10)}m",
|
||||
name=vessel_name,
|
||||
type=VesselType(v_type),
|
||||
subtype=VesselSubtype(v_sub),
|
||||
length_overall_m=loa,
|
||||
beam_max_m=beam,
|
||||
draft_m=draft,
|
||||
decks=decks,
|
||||
bulkheads=bulkheads,
|
||||
data_source="user_input",
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error("Vessel build failed: %s", exc)
|
||||
raise
|
||||
vessel = Vessel(
|
||||
id=f"wizard_{int(loa * 10)}m",
|
||||
name=vessel_name,
|
||||
type=VesselType(v_type),
|
||||
subtype=VesselSubtype(v_sub),
|
||||
length_overall_m=loa,
|
||||
beam_max_m=beam,
|
||||
draft_m=draft,
|
||||
decks=decks,
|
||||
bulkheads=bulkheads,
|
||||
data_source="user_input",
|
||||
)
|
||||
|
||||
# Equipment + tags llegan en Sprint 2 (rule engine). Por ahora, vacío.
|
||||
try:
|
||||
systems_enabled = [SystemId(s) for s in systems_raw]
|
||||
except ValueError:
|
||||
systems_enabled = [SystemId.MAIN_ENGINE]
|
||||
|
||||
# Sprint 2: materializar Equipment desde las propuestas aceptadas
|
||||
proposals = self.field(F_PROPOSALS) or []
|
||||
equipment_list: list[Equipment] = []
|
||||
for idx, p in enumerate(proposals):
|
||||
equipment_list.append(
|
||||
Equipment(
|
||||
id=f"eq_{idx:03d}_{p.tag_prefix.lower()}",
|
||||
model_ref=p.model_ref,
|
||||
tag_prefix=p.tag_prefix,
|
||||
display_name=p.display_name,
|
||||
location=p.to_ship_coord(),
|
||||
system_id=p.system_id,
|
||||
)
|
||||
)
|
||||
|
||||
# Topología + tags del auto-assigner
|
||||
assignment = self.field(F_ASSIGNMENT)
|
||||
topology = assignment.topology() if assignment is not None else None
|
||||
tags = list(assignment.tags) if assignment is not None else []
|
||||
|
||||
project_id = make_project_id(customer or "cliente", vessel.id)
|
||||
|
||||
if topology is not None:
|
||||
return Project(
|
||||
id=project_id,
|
||||
name=project_name,
|
||||
customer=customer,
|
||||
vessel=vessel,
|
||||
systems_enabled=systems_enabled,
|
||||
equipment=equipment_list,
|
||||
tags=tags,
|
||||
topology=topology,
|
||||
notes="Creado desde wizard (Sprint 2 — rule engine + auto-assigner).",
|
||||
)
|
||||
return Project(
|
||||
id=project_id,
|
||||
name=project_name,
|
||||
customer=customer,
|
||||
vessel=vessel,
|
||||
systems_enabled=systems_enabled,
|
||||
equipment=[],
|
||||
tags=[],
|
||||
notes="Creado desde wizard Sprint 1. Sprint 2 agregará equipos sugeridos.",
|
||||
equipment=equipment_list,
|
||||
tags=tags,
|
||||
notes="Creado desde wizard (Sprint 2 — rule engine + auto-assigner).",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user