Files
Gas-Tank-AR-App/GasTankAR/Views/ProjectCreate.swift
Dennis Nemec b8536d4182 Add tank catalog with USDZ models and tank selection
Introduce TankDefinition/TankCatalog loaded from Tanks.json, bundle the
Drachengas USDZ tank models, add tank selection and preview views, and
update the AR experience, editor and project views to use the catalog.
Includes tests for catalog loading and model selection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 19:12:39 +02:00

84 lines
2.5 KiB
Swift

//
// ProjectCreate.swift
// GasTankAR
//
// Created by Dennis Nemec on 25.08.26.
//
import SwiftUI
import SwiftData
struct ProjectCreateView: View {
@Environment(\.modelContext) private var modelContext
@Environment(\.dismiss) private var dismiss
let onCreated: (Project) -> Void
@State private var leadID: String = ""
@State private var customerName: String = ""
@State private var creationDate: Date = .now
@State private var tank: Tank = Tank()
/// Whether the entered values are sufficient to create a project.
private var canSave: Bool {
!leadID.trimmingCharacters(in: .whitespaces).isEmpty
&& !customerName.trimmingCharacters(in: .whitespaces).isEmpty
}
var body: some View {
NavigationStack {
Form {
Section("Projektdaten") {
TextField("Lead-ID", text: $leadID)
.textInputAutocapitalization(.characters)
.autocorrectionDisabled()
TextField("Kundenname", text: $customerName)
.textInputAutocapitalization(.words)
DatePicker(
"Erstellungsdatum",
selection: $creationDate,
displayedComponents: [.date]
)
}
TankSelectionSection(tank: $tank)
}
.navigationTitle("Projekt erstellen")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Abbrechen", systemImage: "xmark") {
dismiss()
}
}
ToolbarItem(placement: .confirmationAction) {
Button("Speichern", systemImage: "checkmark") {
save()
}
.buttonStyle(.borderedProminent)
.disabled(!canSave)
}
}
}
}
private func save() {
let project = Project(
leadID: leadID.trimmingCharacters(in: .whitespaces),
customerName: customerName.trimmingCharacters(in: .whitespaces),
creationDate: creationDate,
tank: tank
)
modelContext.insert(project)
onCreated(project)
dismiss()
}
}
#Preview {
ProjectCreateView { _ in }
.modelContainer(for: Project.self, inMemory: true)
}