mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-09-28 12:02:02 +02:00
Multiple cameras on one pole
This commit is contained in:
@@ -7,27 +7,45 @@ import '../models/osm_node.dart';
|
||||
|
||||
// ------------------ AddNodeSession ------------------
|
||||
class AddNodeSession {
|
||||
AddNodeSession({this.profile, this.directionDegrees = 0});
|
||||
NodeProfile? profile;
|
||||
OperatorProfile? operatorProfile;
|
||||
double directionDegrees;
|
||||
LatLng? target;
|
||||
List<double> directions; // All directions [90, 180, 270]
|
||||
int currentDirectionIndex; // Which direction we're editing (e.g. 1 = editing the 180°)
|
||||
|
||||
AddNodeSession({
|
||||
this.profile,
|
||||
double initialDirection = 0,
|
||||
this.operatorProfile,
|
||||
this.target,
|
||||
}) : directions = [initialDirection],
|
||||
currentDirectionIndex = 0;
|
||||
|
||||
// Slider always shows the current direction being edited
|
||||
double get directionDegrees => directions[currentDirectionIndex];
|
||||
set directionDegrees(double value) => directions[currentDirectionIndex] = value;
|
||||
}
|
||||
|
||||
// ------------------ EditNodeSession ------------------
|
||||
class EditNodeSession {
|
||||
EditNodeSession({
|
||||
required this.originalNode,
|
||||
this.profile,
|
||||
required this.directionDegrees,
|
||||
required this.target,
|
||||
});
|
||||
|
||||
final OsmNode originalNode; // The original node being edited
|
||||
NodeProfile? profile;
|
||||
OperatorProfile? operatorProfile;
|
||||
double directionDegrees;
|
||||
LatLng target; // Current position (can be dragged)
|
||||
List<double> directions; // All directions [90, 180, 270]
|
||||
int currentDirectionIndex; // Which direction we're editing (e.g. 1 = editing the 180°)
|
||||
|
||||
EditNodeSession({
|
||||
required this.originalNode,
|
||||
this.profile,
|
||||
required double initialDirection,
|
||||
required this.target,
|
||||
}) : directions = [initialDirection],
|
||||
currentDirectionIndex = 0;
|
||||
|
||||
// Slider always shows the current direction being edited
|
||||
double get directionDegrees => directions[currentDirectionIndex];
|
||||
set directionDegrees(double value) => directions[currentDirectionIndex] = value;
|
||||
}
|
||||
|
||||
class SessionState extends ChangeNotifier {
|
||||
@@ -60,12 +78,19 @@ class SessionState extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// Start with no profile selected if no match found - force user to choose
|
||||
// Initialize edit session with all existing directions
|
||||
final existingDirections = node.directionDeg.isNotEmpty ? node.directionDeg : [0.0];
|
||||
|
||||
_editSession = EditNodeSession(
|
||||
originalNode: node,
|
||||
profile: matchingProfile,
|
||||
directionDegrees: node.directionDeg ?? 0,
|
||||
initialDirection: existingDirections.first,
|
||||
target: node.coord,
|
||||
);
|
||||
|
||||
// Replace the default single direction with all existing directions
|
||||
_editSession!.directions = List<double>.from(existingDirections);
|
||||
_editSession!.currentDirectionIndex = 0; // Start editing the first direction
|
||||
_session = null; // Clear any add session
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -136,6 +161,49 @@ class SessionState extends ChangeNotifier {
|
||||
if (dirty) notifyListeners();
|
||||
}
|
||||
|
||||
// Add new direction at 0° and switch to editing it
|
||||
void addDirection() {
|
||||
if (_session != null) {
|
||||
_session!.directions.add(0.0);
|
||||
_session!.currentDirectionIndex = _session!.directions.length - 1;
|
||||
notifyListeners();
|
||||
} else if (_editSession != null) {
|
||||
_editSession!.directions.add(0.0);
|
||||
_editSession!.currentDirectionIndex = _editSession!.directions.length - 1;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove currently selected direction
|
||||
void removeDirection() {
|
||||
if (_session != null && _session!.directions.length > 1) {
|
||||
_session!.directions.removeAt(_session!.currentDirectionIndex);
|
||||
if (_session!.currentDirectionIndex >= _session!.directions.length) {
|
||||
_session!.currentDirectionIndex = _session!.directions.length - 1;
|
||||
}
|
||||
notifyListeners();
|
||||
} else if (_editSession != null && _editSession!.directions.length > 1) {
|
||||
_editSession!.directions.removeAt(_editSession!.currentDirectionIndex);
|
||||
if (_editSession!.currentDirectionIndex >= _editSession!.directions.length) {
|
||||
_editSession!.currentDirectionIndex = _editSession!.directions.length - 1;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle to next direction
|
||||
void cycleDirection() {
|
||||
if (_session != null && _session!.directions.length > 1) {
|
||||
_session!.currentDirectionIndex = (_session!.currentDirectionIndex + 1) % _session!.directions.length;
|
||||
notifyListeners();
|
||||
} else if (_editSession != null && _editSession!.directions.length > 1) {
|
||||
_editSession!.currentDirectionIndex = (_editSession!.currentDirectionIndex + 1) % _editSession!.directions.length;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void cancelSession() {
|
||||
_session = null;
|
||||
notifyListeners();
|
||||
|
||||
@@ -29,7 +29,7 @@ class UploadQueueState extends ChangeNotifier {
|
||||
void addFromSession(AddNodeSession session, {required UploadMode uploadMode}) {
|
||||
final upload = PendingUpload(
|
||||
coord: session.target!,
|
||||
direction: session.directionDegrees,
|
||||
direction: _formatDirectionsAsString(session.directions),
|
||||
profile: session.profile!, // Safe to use ! because commitSession() checks for null
|
||||
operatorProfile: session.operatorProfile,
|
||||
uploadMode: uploadMode,
|
||||
@@ -63,7 +63,7 @@ class UploadQueueState extends ChangeNotifier {
|
||||
void addFromEditSession(EditNodeSession session, {required UploadMode uploadMode}) {
|
||||
final upload = PendingUpload(
|
||||
coord: session.target,
|
||||
direction: session.directionDegrees,
|
||||
direction: _formatDirectionsAsString(session.directions),
|
||||
profile: session.profile!, // Safe to use ! because commitEditSession() checks for null
|
||||
operatorProfile: session.operatorProfile,
|
||||
uploadMode: uploadMode,
|
||||
@@ -109,7 +109,7 @@ class UploadQueueState extends ChangeNotifier {
|
||||
void addFromNodeDeletion(OsmNode node, {required UploadMode uploadMode}) {
|
||||
final upload = PendingUpload(
|
||||
coord: node.coord,
|
||||
direction: node.directionDeg ?? 0, // Direction not used for deletions but required for API
|
||||
direction: node.directionDeg.isNotEmpty ? node.directionDeg.first : 0, // Direction not used for deletions but required for API
|
||||
profile: null, // No profile needed for deletions - just delete by node ID
|
||||
uploadMode: uploadMode,
|
||||
operation: UploadOperation.delete,
|
||||
@@ -293,6 +293,13 @@ class UploadQueueState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to format multiple directions as a string or number
|
||||
dynamic _formatDirectionsAsString(List<double> directions) {
|
||||
if (directions.isEmpty) return 0.0;
|
||||
if (directions.length == 1) return directions.first;
|
||||
return directions.map((d) => d.round().toString()).join(';');
|
||||
}
|
||||
|
||||
// ---------- Queue persistence ----------
|
||||
Future<void> _saveQueue() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
Reference in New Issue
Block a user