VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtVreAssignmentTracker Class Reference

Detailed Description

DtVreAssignmentTracker provides a unified view of VR-Engage station assignments, combining confirmed assignments from DtVreStatusListener with pending user edits. It serves as the single source of truth for the Manager Panel UI, providing query methods for displaying assignment state and tracking conflicts when pending assignments would displace existing stations.

Key Concepts
  • Confirmed assignments: Current state from DtVreStatusListener, representing what stations are actually controlling
  • Pending assignments: User edits not yet submitted, stored locally in this tracker
  • Conflicts: When a pending assignment targets a role that already has a confirmed station
  • Conflict detection: Roles with 2+ non-spectator stations are flagged as conflicts that must be resolved before submission
Thread Safety
This class must only be used from the GUI thread.
Example Usage
// Create tracker attached to the status listener
DtVreAssignmentTracker tracker(statusListener);
// User assigns a station to a role
tracker.setPendingAssignment(stationId, entityUUID, "driver");
// Check if there are conflicts before submit
int pending, conflicts;
tracker.getPendingCounts(pending, conflicts);
if (conflicts > 0)
{
// Conflicts must be resolved before submit
return;
}
// Get stations that will be unassigned by pending assignments
auto toUnassign = tracker.getStationsToUnassign();
if (!toUnassign.empty())
{
showConfirmationDialog(toUnassign);
}
// Submit the assignments
for (const auto& assignment : tracker.getPendingAssignments())
{
sendAssignMessage(assignment);
}
tracker.clearAllPendingAssignments();
DtVreAssignmentTracker(DtVreStatusListener &statusListener, QObject *parent=nullptr)
Constructor.

#include <vreAssignmentTracker.h>

Inheritance diagram for makVre::DtVreAssignmentTracker:
[legend]

Classes

struct  PendingAssignment
 

Signals

void assignmentStateChanged ()
 
void stationAdded (std::string stationId)
 
void stationRemoved (std::string stationId)
 
void stationAssignmentChanged (std::string stationId)
 

Public Member Functions

 DtVreAssignmentTracker (DtVreStatusListener &statusListener, QObject *parent=nullptr)
 
virtual ~DtVreAssignmentTracker () override
 
Pending Assignment Management

Methods for creating and clearing pending (uncommitted) assignments.

virtual void setPendingAssignment (std::string stationId, const DtUUID &entityUUID, const std::string &roleName, bool spectatorMode=false)
 
virtual void setPendingSpectatorMode (std::string stationId, bool spectatorMode)
 
virtual void setPendingUnassignment (std::string stationId)
 
virtual void clearPendingAssignment (std::string stationId)
 
virtual void clearAllPendingAssignments ()
 
Query Methods

Methods for querying assignment state for UI display.

virtual std::vector< std::string > getAssignedStations (const DtUUID &entityUUID, const std::string &roleName, bool includePending=true) const
 
virtual std::vector< DtRoleAssignment > getRoleAssignments (const DtUUID &entityUUID, const std::vector< std::string > &availableRoles) const
 
virtual bool getStationAssignment (std::string stationId, DtUUID &entityUUID, std::string &roleName, bool &isPending) const
 
virtual bool hasConflict (std::string stationId) const
 
virtual bool hasUnresolvedConflicts () const
 
virtual int getConflictCount () const
 
virtual std::vector< std::string > getStationsToUnassign () const
 
virtual std::vector< DtPendingAssignmentInfo > getPendingAssignments () const
 
virtual std::vector< std::string > getPendingUnassignments () const
 
virtual bool hasPendingUnassignment (std::string stationId) const
 
virtual DtUUID getStationEntityUUID (std::string stationId) const
 
virtual std::string getStationRoleName (std::string stationId) const
 
virtual void getPendingCounts (int &pendingCount, int &conflictCount) const
 
virtual std::string getStationName (std::string stationId) const
 
virtual std::string getStationObjectName (std::string stationId) const
 
virtual bool isStationSpectator (std::string stationId) const
 
virtual void setSpectatorPreference (std::string stationId, bool spectatorMode)
 
Summary Queries

Methods for getting aggregate information about assignments.

virtual int getAssignedRoleCount (const DtUUID &entityUUID, const std::vector< std::string > &availableRoles) const
 
virtual int getUnassignedStationCount () const
 
virtual int getTotalStationCount () const
 
virtual bool hasPendingChanges () const
 
virtual std::vector< std::string > getAllStationIds () const
 
virtual bool isPlaceholderStation (std::string stationId) const
 
virtual std::vector< std::string > getPlaceholderStationIds () const
 
virtual std::vector< DtPersistedAssignmentRecord > exportAssignmentsForPersistence () const
 
virtual bool importAssignmentsForPersistence (const std::vector< DtPersistedAssignmentRecord > &records, const std::function< bool(const DtUUID &)> &entityExists, std::vector< std::string > &warnings, std::string &errorText)
 

Static Protected Member Functions

Callback Handlers

Static callbacks registered with DtVreStatusListener.

static void onStationAdded (const std::string &id, void *userData)
 
static void onStationRemoved (const std::string &id, void *userData)
 
static void onStationChanged (const std::string &id, void *userData)
 

Protected Attributes

DtVreStatusListener & myStatusListener
 
std::map< std::string, PendingAssignment > myPendingAssignments
 
std::set< std::string > myPendingUnassignments
 
std::set< std::string > myRemovedStationIds
 
std::map< std::string, bool > mySpectatorPreferences
 
unsigned int myNextPlaceholderStationId = 1
 
std::map< std::string, DtPlaceholderStation > myPlaceholderStations
 
std::map< std::string, std::string > myPlaceholderIdsByName
 

Static Protected Attributes

static constexpr const char * thePlaceholderStationIdPrefix = "PLACE_HOLDER_BASE_"
 

Private Member Functions

std::string allocatePlaceholderStationId ()
 
std::string ensurePlaceholderStation (const DtPersistedAssignmentRecord &record)
 
bool findLiveStationIdByName (const std::string &stationName, std::string &stationId) const
 
void wakePlaceholderForLiveStation (std::string liveStationId)
 
void removePlaceholderStation (std::string stationId)
 
 DtVreAssignmentTracker (const DtVreAssignmentTracker &)=delete
 
DtVreAssignmentTracker & operator= (const DtVreAssignmentTracker &)=delete
 

Constructor & Destructor Documentation

◆ DtVreAssignmentTracker() [1/2]

makVre::DtVreAssignmentTracker::DtVreAssignmentTracker ( DtVreStatusListener & statusListener,
QObject * parent = nullptr )

Constructor.

Parameters
statusListenerReference to the status listener for confirmed assignments
parentOptional parent QObject for Qt memory management

Creates a tracker that monitors the given status listener for confirmed assignment state. Registers callbacks with the listener to receive notifications when stations are added, removed, or changed.

Referenced by DtVreAssignmentTracker(), and operator=().

◆ ~DtVreAssignmentTracker()

virtual makVre::DtVreAssignmentTracker::~DtVreAssignmentTracker ( )
overridevirtual

Destructor.

Unregisters callbacks from the status listener.

◆ DtVreAssignmentTracker() [2/2]

makVre::DtVreAssignmentTracker::DtVreAssignmentTracker ( const DtVreAssignmentTracker & )
privatedelete

Copy constructor (deleted)

References DtVreAssignmentTracker().

Member Function Documentation

◆ setPendingAssignment()

virtual void makVre::DtVreAssignmentTracker::setPendingAssignment ( std::string stationId,
const DtUUID & entityUUID,
const std::string & roleName,
bool spectatorMode = false )
virtual

Sets a pending assignment for a station.

Parameters
stationIdThe station ID to assign
entityUUIDThe entity UUID to assign to
roleNameThe role name to assign (e.g., "driver", "gunner")
spectatorModeWhether spectator mode should be enabled

Creates or updates a pending assignment for the specified station. Multiple pending assignments to the same entity+role are allowed. This may create a conflict (2+ non-spectator on same role) that the user must resolve before submitting.

Emits assignmentStateChanged() after updating state.

◆ setPendingSpectatorMode()

virtual void makVre::DtVreAssignmentTracker::setPendingSpectatorMode ( std::string stationId,
bool spectatorMode )
virtual

Toggles spectator mode on an existing pending assignment.

Parameters
stationIdThe station ID with the pending assignment
spectatorModeTrue for spectator, false for normal

Changes the spectator flag on an existing pending assignment. Has no effect if the station has no pending assignment.

Emits assignmentStateChanged() if the flag was changed.

◆ setPendingUnassignment()

virtual void makVre::DtVreAssignmentTracker::setPendingUnassignment ( std::string stationId)
virtual

Sets a pending unassignment for a station.

Parameters
stationIdThe station ID to mark for unassignment

Marks a station with a confirmed assignment for unassignment. On submit, DtIfUnassignRolePlayer is sent to this station. If the station has a pending assignment, it is cleared first.

Emits assignmentStateChanged() after updating state.

◆ clearPendingAssignment()

virtual void makVre::DtVreAssignmentTracker::clearPendingAssignment ( std::string stationId)
virtual

Clears the pending assignment or unassignment for a station.

Parameters
stationIdThe station ID to clear

Removes any pending assignment or pending unassignment for the specified station, returning it to its confirmed state. Has no effect if the station has no pending state.

Emits assignmentStateChanged() if state was changed.

◆ clearAllPendingAssignments()

virtual void makVre::DtVreAssignmentTracker::clearAllPendingAssignments ( )
virtual

Clears all pending assignments.

Removes all pending assignments, returning all stations to their confirmed state. Typically called after Submit to clear the pending state, or on Revert to discard user edits.

Emits assignmentStateChanged() if any state was changed.

◆ getAssignedStations()

virtual std::vector< std::string > makVre::DtVreAssignmentTracker::getAssignedStations ( const DtUUID & entityUUID,
const std::string & roleName,
bool includePending = true ) const
virtual

Gets all stations assigned to a specific role.

Parameters
entityUUIDThe entity UUID
roleNameThe role name
includePendingIf true, includes pending assignments in results
Returns
List of station IDs assigned to this role

Returns confirmed station assignments, optionally merged with pending assignments. When includePending is true, pending assignments replace any confirmed assignment for the same station.

◆ getRoleAssignments()

virtual std::vector< DtRoleAssignment > makVre::DtVreAssignmentTracker::getRoleAssignments ( const DtUUID & entityUUID,
const std::vector< std::string > & availableRoles ) const
virtual

Gets role assignment information for all roles on an entity.

Parameters
entityUUIDThe entity UUID
availableRolesList of available role names for this entity
Returns
List of DtRoleAssignment structures with assignment status for each role

Returns complete assignment information for each role, suitable for populating the entity/role tree view. Each DtRoleAssignment contains both confirmed and pending state, plus conflict indicators.

◆ getStationAssignment()

virtual bool makVre::DtVreAssignmentTracker::getStationAssignment ( std::string stationId,
DtUUID & entityUUID,
std::string & roleName,
bool & isPending ) const
virtual

Gets the current assignment for a station.

Parameters
stationIdThe station ID to query
entityUUIDOutput parameter for entity UUID
roleNameOutput parameter for role name
isPendingOutput parameter indicating if assignment is pending
Returns
True if station has an assignment (confirmed or pending)

Returns the effective assignment for a station, preferring pending state over confirmed state when both exist.

◆ hasConflict()

virtual bool makVre::DtVreAssignmentTracker::hasConflict ( std::string stationId) const
virtual

Checks if a station is part of an unresolved conflict (2+ non-spectator stations on the same entity+role)

Parameters
stationIdThe station ID to check
Returns
True if the station is involved in an unresolved conflict

◆ hasUnresolvedConflicts()

virtual bool makVre::DtVreAssignmentTracker::hasUnresolvedConflicts ( ) const
virtual

Checks if any entity+role has 2+ non-spectator stations When true, the Submit button is disabled.

Returns
True if unresolved conflicts exist

◆ getConflictCount()

virtual int makVre::DtVreAssignmentTracker::getConflictCount ( ) const
virtual

Returns the number of roles with unresolved conflicts.

Returns
Count of entity+role pairs with 2+ non-spectator stations

◆ getStationsToUnassign()

virtual std::vector< std::string > makVre::DtVreAssignmentTracker::getStationsToUnassign ( ) const
virtual

Returns confirmed stations that will be unassigned on submit.

Returns confirmed non-spectator stations whose role is being taken by a pending assignment from a different station. Excludes stations that have their own pending reassignment to another role. Excludes spectator stations.

Returns
List of station IDs that will be unassigned

◆ getPendingAssignments()

virtual std::vector< DtPendingAssignmentInfo > makVre::DtVreAssignmentTracker::getPendingAssignments ( ) const
virtual

Gets all pending assignments for submit iteration.

Returns
List of pending assignment info structures

Returns all pending assignments in a form suitable for sending DtIfAssignRolePlayer messages during submit. Does not include pending unassignments (use getPendingUnassignments() for those).

◆ getPendingUnassignments()

virtual std::vector< std::string > makVre::DtVreAssignmentTracker::getPendingUnassignments ( ) const
virtual

Gets all stations with pending unassignments.

Returns
List of station IDs marked for unassignment

Returns station IDs that the user explicitly marked for unassignment. On submit, DtIfUnassignRolePlayer is sent to each.

◆ hasPendingUnassignment()

virtual bool makVre::DtVreAssignmentTracker::hasPendingUnassignment ( std::string stationId) const
virtual

Checks if a station has a pending unassignment.

Parameters
stationIdThe station ID to check
Returns
True if the station is marked for pending unassignment

◆ getStationEntityUUID()

virtual DtUUID makVre::DtVreAssignmentTracker::getStationEntityUUID ( std::string stationId) const
virtual

Gets the confirmed entity UUID for a station.

Parameters
stationIdThe station ID
Returns
Entity UUID or empty string if not assigned

Returns only the confirmed (not pending) entity UUID. Used to construct unassign messages for displaced stations.

◆ getStationRoleName()

virtual std::string makVre::DtVreAssignmentTracker::getStationRoleName ( std::string stationId) const
virtual

Gets the confirmed role name for a station.

Parameters
stationIdThe station ID
Returns
Role name or empty string if not assigned

Returns only the confirmed (not pending) role name.

◆ getPendingCounts()

virtual void makVre::DtVreAssignmentTracker::getPendingCounts ( int & pendingCount,
int & conflictCount ) const
virtual

Gets counts of pending changes and conflicts.

Parameters
pendingCountOutput for total pending assignment count
conflictCountOutput for count of entity+role pairs with unresolved conflicts

Provides summary counts for the Submit button display.

◆ getStationName()

virtual std::string makVre::DtVreAssignmentTracker::getStationName ( std::string stationId) const
virtual

Gets the display name for a station.

Parameters
stationIdThe station ID
Returns
Station name or empty string if station not found

◆ getStationObjectName()

virtual std::string makVre::DtVreAssignmentTracker::getStationObjectName ( std::string stationId) const
virtual

Gets the saved entity object name for an offline placeholder station.

Parameters
stationIdThe station ID
Returns
The object name persisted with the placeholder, or empty string when the station is not a placeholder or has no saved object name.

Offline placeholders carry the entity's object name from the saved layout so the station card can label the assignment without depending on the entity UUID round-tripping (a bare-hex UUID from an older save does not reconstruct to a valid DtUUID and cannot be resolved to a name).

◆ isStationSpectator()

virtual bool makVre::DtVreAssignmentTracker::isStationSpectator ( std::string stationId) const
virtual

Gets whether a station is in spectator mode.

Parameters
stationIdThe station ID to query
Returns
True if the station is in spectator mode (pending, confirmed, or preference)

Returns the effective spectator mode for a station. Checks in order:

  1. Pending assignment spectator flag
  2. Confirmed assignment spectator flag
  3. Spectator preference (set before any assignment exists)

◆ setSpectatorPreference()

virtual void makVre::DtVreAssignmentTracker::setSpectatorPreference ( std::string stationId,
bool spectatorMode )
virtual

Sets the spectator mode preference for a station.

Parameters
stationIdThe station ID
spectatorModeTrue for spectator, false for normal

Records a spectator preference that will be applied when a pending assignment is created for this station. This allows the user to pre-select spectator mode before choosing an entity/role. If the station already has a pending assignment, its spectator flag is updated in place.

Emits assignmentStateChanged() if the effective state changed.

◆ getAssignedRoleCount()

virtual int makVre::DtVreAssignmentTracker::getAssignedRoleCount ( const DtUUID & entityUUID,
const std::vector< std::string > & availableRoles ) const
virtual

Gets count of assigned roles for an entity.

Parameters
entityUUIDThe entity UUID
availableRolesList of available role names
Returns
Number of roles that have at least one station assigned

Counts roles with either confirmed or pending assignments. Used for the entity badge display (e.g., "2/3").

◆ getUnassignedStationCount()

virtual int makVre::DtVreAssignmentTracker::getUnassignedStationCount ( ) const
virtual

Gets count of unassigned stations.

Returns
Number of stations without a confirmed assignment. Pending changes are not considered.

◆ getTotalStationCount()

virtual int makVre::DtVreAssignmentTracker::getTotalStationCount ( ) const
virtual

Gets total station count.

Returns
Total number of known stations

◆ hasPendingChanges()

virtual bool makVre::DtVreAssignmentTracker::hasPendingChanges ( ) const
virtual

Checks if there are any pending changes.

Returns
True if any pending assignments exist

◆ getAllStationIds()

virtual std::vector< std::string > makVre::DtVreAssignmentTracker::getAllStationIds ( ) const
virtual

Gets all station IDs.

Returns
Vector of all known station IDs

Returns the IDs of all stations known to the status listener. Used by the station list model to populate its list.

◆ isPlaceholderStation()

virtual bool makVre::DtVreAssignmentTracker::isPlaceholderStation ( std::string stationId) const
virtual

Checks if a station ID is a synthetic placeholder.

◆ getPlaceholderStationIds()

virtual std::vector< std::string > makVre::DtVreAssignmentTracker::getPlaceholderStationIds ( ) const
virtual

Returns all synthetic placeholder station IDs.

◆ exportAssignmentsForPersistence()

virtual std::vector< DtPersistedAssignmentRecord > makVre::DtVreAssignmentTracker::exportAssignmentsForPersistence ( ) const
virtual

Exports the effective assignment snapshot for persistence.

Returns name-based records from the merged confirmed+pending view, excluding stations with pending unassignment.

◆ importAssignmentsForPersistence()

virtual bool makVre::DtVreAssignmentTracker::importAssignmentsForPersistence ( const std::vector< DtPersistedAssignmentRecord > & records,
const std::function< bool(const DtUUID &)> & entityExists,
std::vector< std::string > & warnings,
std::string & errorText )
virtual

Imports saved assignments as pending state.

For each record, if a live station with the saved name exists, creates a pending assignment on that station. Otherwise creates a placeholder. Records whose entity UUID fails the entityExists callback are skipped with a warning appended to warnings.

Existing pending assignments and placeholders are cleared before import.

Records whose entity UUID is not currently in the exercise are still imported as placeholder stations so the assignments are ready when the entity and station appear later. This makes the function safe to call before a scenario is loaded.

Parameters
recordsThe saved assignment records to import.
entityExistsCallback that returns true if an entity UUID is currently in the exercise. Used only for informational logging; a false result does not prevent the record from being imported.
warningsReceives non-fatal informational messages.
errorTextReceives a fatal error string; import is aborted when non-empty.
Returns
true on success (check warnings for informational notes).

◆ assignmentStateChanged

void makVre::DtVreAssignmentTracker::assignmentStateChanged ( )
signal

Emitted when any assignment state changes.

Emitted when pending assignments are added, cleared, or when confirmed state changes from the status listener. UI should refresh display when this signal is received.

◆ stationAdded

void makVre::DtVreAssignmentTracker::stationAdded ( std::string stationId)
signal

Emitted when a station is added.

Parameters
stationIdThe new station ID

◆ stationRemoved

void makVre::DtVreAssignmentTracker::stationRemoved ( std::string stationId)
signal

Emitted when a station is removed.

Parameters
stationIdThe removed station ID

◆ stationAssignmentChanged

void makVre::DtVreAssignmentTracker::stationAssignmentChanged ( std::string stationId)
signal

Emitted when a station's confirmed assignment changes.

Parameters
stationIdThe station ID

◆ onStationAdded()

static void makVre::DtVreAssignmentTracker::onStationAdded ( const std::string & id,
void * userData )
staticprotected

Callback invoked when a station is added to the listener.

Parameters
idThe station ID
userDataPointer to the DtVreAssignmentTracker instance

◆ onStationRemoved()

static void makVre::DtVreAssignmentTracker::onStationRemoved ( const std::string & id,
void * userData )
staticprotected

Callback invoked when a station is removed from the listener.

Parameters
idThe station ID
userDataPointer to the DtVreAssignmentTracker instance

◆ onStationChanged()

static void makVre::DtVreAssignmentTracker::onStationChanged ( const std::string & id,
void * userData )
staticprotected

Callback invoked when a station's confirmed state changes.

Parameters
idThe station ID
userDataPointer to the DtVreAssignmentTracker instance

◆ allocatePlaceholderStationId()

std::string makVre::DtVreAssignmentTracker::allocatePlaceholderStationId ( )
private

◆ ensurePlaceholderStation()

std::string makVre::DtVreAssignmentTracker::ensurePlaceholderStation ( const DtPersistedAssignmentRecord & record)
private

◆ findLiveStationIdByName()

bool makVre::DtVreAssignmentTracker::findLiveStationIdByName ( const std::string & stationName,
std::string & stationId ) const
private

◆ wakePlaceholderForLiveStation()

void makVre::DtVreAssignmentTracker::wakePlaceholderForLiveStation ( std::string liveStationId)
private

◆ removePlaceholderStation()

void makVre::DtVreAssignmentTracker::removePlaceholderStation ( std::string stationId)
private

◆ operator=()

DtVreAssignmentTracker & makVre::DtVreAssignmentTracker::operator= ( const DtVreAssignmentTracker & )
privatedelete

Assignment operator (deleted)

References DtVreAssignmentTracker().

Member Data Documentation

◆ myStatusListener

DtVreStatusListener& makVre::DtVreAssignmentTracker::myStatusListener
protected

Reference to status listener for confirmed assignments.

◆ myPendingAssignments

std::map<std::string, PendingAssignment> makVre::DtVreAssignmentTracker::myPendingAssignments
protected

Map of station ID to pending assignment.

Contains only stations with pending (uncommitted) assignments. Stations not in this map use their confirmed state from the listener.

◆ myPendingUnassignments

std::set<std::string> makVre::DtVreAssignmentTracker::myPendingUnassignments
protected

Set of station IDs with pending unassignments.

Contains station IDs that the user explicitly marked for unassignment. These stations currently have confirmed assignments that will be removed when the user clicks Submit.

◆ myRemovedStationIds

std::set<std::string> makVre::DtVreAssignmentTracker::myRemovedStationIds
protected

Station IDs that have been removed but may still be in the listener's map.

Handles the case where the removed callback fires before the listener erases the station from its map. Cleared on the next stationAdded call.

◆ mySpectatorPreferences

std::map<std::string, bool> makVre::DtVreAssignmentTracker::mySpectatorPreferences
protected

Map of station ID to pre-assignment spectator preference.

Stores spectator mode preferences for stations that do not yet have a pending or confirmed assignment. When a pending assignment is later created for a station with a preference, the preference is applied automatically. Cleared alongside pending state by clearAllPendingAssignments() / importAssignmentsForPersistence() and pruned per-station on station removal.

◆ thePlaceholderStationIdPrefix

const char* makVre::DtVreAssignmentTracker::thePlaceholderStationIdPrefix = "PLACE_HOLDER_BASE_"
staticconstexprprotected

Prefix for synthetic placeholder station IDs.

Placeholder IDs are allocated in a reserved string namespace so they can be distinguished from live station IDs while remaining valid string IDs.

◆ myNextPlaceholderStationId

unsigned int makVre::DtVreAssignmentTracker::myNextPlaceholderStationId = 1
protected

Next synthetic placeholder ID suffix to allocate.

◆ myPlaceholderStations

std::map<std::string, DtPlaceholderStation> makVre::DtVreAssignmentTracker::myPlaceholderStations
protected

Map of placeholder station ID to placeholder data.

◆ myPlaceholderIdsByName

std::map<std::string, std::string> makVre::DtVreAssignmentTracker::myPlaceholderIdsByName
protected

Map of station name to placeholder station ID for quick lookup.


The documentation for this class was generated from the following file: