Files
qt5-legatus-legacy/Lts/Plugins/BuildingViewer/Common/BgViewer/viewerCtrl/viewerinterface.h
T
2026-08-13 18:33:10 +02:00

696 lines
22 KiB
C++
Executable File

#pragma once
#if defined(_MSC_VER)
#include <winsock2.h>
#endif
#include <vector>
#include <map>
#include <string>
#include <QJsonValue>
#include <QList>
#include <QString>
#include <exccommands.h>
class QWidget;
namespace VCtrl
{
#if defined(_MSC_VER)
using Timer_t = __int64;
#else
using Timer_t = unsigned long long;
#endif
/**
* Class representing 2-dimensional float vector
*/
struct Vec2
{
Vec2() = default;
Vec2(float _x, float _y) : x(_x) , y(_y) { }
float x = 0;
float y = 0;
};
/**
* Class representing 3-dimensional float vector
*/
struct Vec3
{
Vec3() = default;
Vec3(float _x, float _y, float _z) : x(_x) , y(_y) , z(_z) { }
float x = 0;
float y = 0;
float z = 0;
};
/**
* Class representing 3-dimensional double vector
*/
struct Vec3d
{
Vec3d() = default;
Vec3d(double _x, double _y, double _z) : x(_x) , y(_y) , z(_z) { }
double x = 0;
double y = 0;
double z = 0;
};
/**
* Class representing a color value.
* Colors are encoded with 0.0 - 1.0 values for each channel.
* w component represents alpha / transparency.
*/
struct Color
{
Color() = default;
Color(float _x, float _y, float _z, float _w) : x(_x) , y(_y) , z(_z) , w(_w) { }
float x = 0;
float y = 0;
float z = 0;
float w = 0;
};
/**
* Class representing a quaternion.
* Used for representing rotations.
*/
struct Quat
{
Quat() = default;
Quat(double _x, double _y, double _z, double _w) : x(_x) , y(_y) , z(_z) , w(_w) { }
double x = 0;
double y = 0;
double z = 0;
double w = 1;
};
/**
* How to treat the z value
*/
enum class ZValue
{
AboveMsl, //!< treat z as above msl
RelativeBuildings, //!< the z position is relative to the buildings
};
/**
* Enumerates view modes for 2d building displays
*/
enum class ViewMode
{
ISOMETRIC,
ORTHOGRAPHIC
};
/**
* Enumerates view modes for 2d building displays
*/
enum class PlayerDisplayMode
{
Icons,
Dots
};
/**
* Callback class for receiving events from viewer side.
* Use with ViewerInterface::SetViewerCallback()
*/
class ViewerCallback
{
public:
virtual ~ViewerCallback() = default;
/**
* Gets called when building position map has finished loading and
* system is ready for use
*/
virtual void SystemReady() = 0;
/**
* Gets called when the position of an entity has changed
* @param id Id of moving entity
* @param pos Position of entity relative to terrain origin in meters
* @param attitude rotation of entity relative to posititive y axis
*/
virtual void TransformChanged(const std::string &id, const Vec3d &pos, const Quat &attitude) = 0;
/**
* Gets called when entity moves from one navmesh group (building or outside mesh)
* to the next
* @param id Id of moving entity
* @param grpname Name of navmesh group
*/
virtual void NavMeshGroupChanged(const std::string &id, const std::string &grpname) = 0;
/**
* Player has clicked on an entity symbol with the left mouse button.
* @param id Id of picked entity
*/
virtual void PlayerPicked(const std::string &id) = 0;
/**
* Player has clicked on an displayName with the left mouse button.
* @param buildingid Id of picked entity
* @param roomname roomname of picked entity
*/
virtual void DisplayNamePicked(const std::string& buildingid, const std::string& roomname) = 0;
/**
* A building view was opened.
* @param contextId id of graphics context. Can be used to close the view.
* @param viewmode Initial view mode of view
*/
virtual void ViewCreated(unsigned int contextId, ViewMode viewmode) = 0;
/**
* View mode of view was changed. This was either triggered by a call to
* ViewerInterface::ChangeViewMode or a click on the view mode buttons in the GUI
* @param contextId id of graphics context.
* @param viewmode New view mode of view
*/
virtual void ViewModeChanged(unsigned int contextId, ViewMode viewmode) = 0;
/**
* Line mode of view was changed. This was either triggered by a call to
* ViewerInterface::ChangeLineMode or a click on the line mode buttons in the GUI
* @param contextId id of graphics context.
* @param line Is line on or off
*/
virtual void ViewLineModeChanged(unsigned int contextId, bool line) = 0;
/**
* Name mode of view was changed. This was either triggered by a call to
* ViewerInterface::ChangeNameMode or a click on the name mode buttons in the GUI
* @param contextId id of graphics context.
* @param name Is name on or off
*/
virtual void ViewNameModeChanged(unsigned int contextId, bool name) = 0;
/**
* Lock ViewTransparencyChanged mode of view was changed. Triggered by slider
*/
virtual void ViewTransparencyChanged() = 0;
/**
* Lock Rotation mode of view was changed. This was either triggered by a call to
* ViewerInterface::LockViewRotationToMapRotation or a click on
* the lock checkbox in the GUI
* @param contextId id of graphics context.
* @param lock Is lock on or off
*/
virtual void ViewLockRotationChanged(unsigned int contextId, bool lock) = 0;
/**
* Player display mode of view was changed. This was either triggered by a call to
* ViewerInterface::SetViewerDisplayMode or a click on
* the display mode checkbox in the GUI
* @param contextId id of graphics context.
* @param mode Mode enumerator
*/
virtual void PlayerDisplayModeChanged(unsigned int contextId, PlayerDisplayMode mode) = 0;
/**
* View was closed via ViewerInterface::CloseView or click on window
* close GUI element
* @param contextId id of graphics context.
*/
virtual void ViewClosed(unsigned int contextId) = 0;
virtual void HandleViewerEvent(BuildingViewer::BgViewerEvents event,
const std::vector<std::string> &args) = 0;
virtual void ViewZoomChanged(const std::string &buildingId,
double top, double left, double bottom, double right) = 0;
enum class Severity
{
Always,
Debug,
Info,
Warning,
Error,
Fatal
};
/**
* Receives error and other log messages from viewer
* @param severity The severity of the message
* @param filename The file that the log command was called from
* @param methodname The name of the method containing the log command
* @param linenumber The line number the log command was issued from
* @param msg Text of the log message
*/
virtual void LogMessage(Severity &severity, const std::string &filename,
const std::string &methodname,
int linenumber, const std::string &msg) = 0;
};
class ViewerInterface
{
public:
virtual ~ViewerInterface() = default;
/**
* Register object for receiving viewer event callbacks
*/
virtual void SetViewerCallback(ViewerCallback *) = 0;
virtual void RemoveViewerCallback() = 0;
/**
* Is used to set location of project specific terrain and building data.
* Example: "/home/martin/ProjectAssetsBremen"
*/
virtual void SetProjectDataPaths(const std::vector<std::string> &paths) = 0;
/**
* Open 3d view of whole terrain - for debugging purposes only!
*/
virtual void OpenOverview() = 0;
virtual QWidget* getMainWindow() = 0;
virtual quintptr requestMainWindowHandle() = 0;
virtual void reloadPlayerIcons() = 0;
virtual void UpdatePlayerPartyColors(const std::map<std::string, VCtrl::Color>& mapPlayerColors) = 0;
/**
* @brief true if positioningsystem gets exact position of player. Will be used for all opened views (GLOBAL FLAG)
* @param exactPos
*/
virtual void UseExactPositioning(bool exactPos) = 0;
/**
* Open a new display showing the building identified by buildingid.
* @param buildingid ID of the building. Use GetBuildingIds() to get all building ids
* @param windowtitle Title to display on window top
* @param bgcolor Background color of window
* @param viewmode The perspective mode to show building in
* @param screennum Number of screen to open display on
* @param fullscreen Ignore width and position and display as fullscreen instead
* @param x X-Position of window
* @param y Y-Position of window
* @param width Width of display in pixels
* @param height Height of display in pixels
* @param contextId receives context ID of the new view. Use it to close the view programmatically.
* @param exactPos true if positioningsystem gets exact position of player
* @return true if success
*/
virtual bool OpenView(const std::string &buildingid, const std::string &windowtitle, const Color &bgcolor, ViewMode viewmode,
int screennum, bool fullscreen, int x, int y, int width, int height,
unsigned int &contextId, bool exactPos = true) = 0;
virtual void openViews(const std::vector<std::string> &bldIds, bool exactPos) = 0;
/**
* Is a certain view opened?
* @param bldId ID of the building.
*/
virtual bool isViewOpen(const std::string &bldId) const = 0;
/**
* Close display previously opened with OpenView
* @param contextid context id of view, as returned from OpenView()
*/
virtual void CloseView(unsigned int contextid) = 0;
virtual void closeViews(const std::vector<std::string> &bldIds) = 0;
/**
* Change view mode of an existing view.
* @param contextId context id of view, as returned from OpenView()
* @param viewmode Viewmode enum value
*/
virtual void ChangeViewMode(unsigned int contextId, ViewMode viewmode) = 0;
virtual void setViewMode(ViewMode m) = 0;
/**
* Change view mode of an existing view.
* @param contextId context id of view, as returned from OpenView()
* @param line true if view should show lines outside , false if not
*/
virtual void ChangeLineMode(unsigned int contextId, bool line) = 0;
/**
* Change view mode of an existing view.
* @param contextId context id of view, as returned from OpenView()
* @param name true if view should show names, false if not
*/
virtual void ChangeNameMode(unsigned int contextId, bool name) = 0;
/**
* Set if view should rotate in accord with map rotation
* @param contextId context id of view, as returned from OpenView()
* @param lock true if view should rotate, false if it should remain static
*/
virtual void LockViewRotationToMapRotation(unsigned int contextId, bool lock) = 0;
/**
* Set if view should display movable players as dots or as icons
* @param contextId context id of view, as returned from OpenView()
* @param mode Display mode enumerator
*/
virtual void SetPlayerDisplayMode(unsigned int contextId, PlayerDisplayMode mode) = 0;
virtual void setDisplayMode(PlayerDisplayMode m) = 0;
/**
* Set wall transparency for a building window.
* @param contextId context id of view, as returned from OpenView()
* @param transparency 0 equals opaque, 1 equals invisible
*/
virtual void SetWallTransparency(unsigned int contextId, float transparency) = 0;
virtual void setTransparency(double percent) = 0;
/**
* All views with "LockViewRotationToMapRotation" enabled will rotate their camera
* to have a camera angle looking towards north, rotated by input angle.
* @returnRotation angle in degrees from north CCW
*/
virtual float GetMapRotation() const = 0;
/**
* All views with "LockViewRotationToMapRotation" enabled will rotate their camera
* to have a camera angle looking towards north, rotated by input angle.
* @param angle Rotation angle in degrees from north CCW
*/
virtual void SetMapRotation(float angle) = 0;
/**
* add buildings to scene and recalculate navigation meshes
* @param path Load map from this path. example: "Projections/data.xml"
*/
virtual bool LoadBuildingPositionMap(const std::string &path, bool loadAllAvailableBuildings) = 0;
/**
* Create new player at (0,0,0). Player is initially invisible!
* @param id a unique string that can later be used to reference the player
* @param iconpath system file path to player icon. Can be relative to ProjectAssets folder root.
* @param color Initial color of the player
*/
virtual void CreatePlayer(const std::string &id, const std::string &iconpath, const Color &color) = 0;
/**
* Delete player with given id
* @param seconds Delete player n seconds from now
*/
virtual void DeletePlayer(const std::string &id, float seconds = 0) = 0;
/**
* This color is added to the player texture color.
*/
virtual void SetPlayerColor(const std::string &id, const Color &color) = 0;
/**
* Set icon path for existing player
* @param path system file path to player icon. Can be relative to ProjectAssets folder root.
* If path is to current icon path then icon is reloaded from file.
*/
virtual void SetPlayerIcon(const std::string &id, const std::string &path) = 0;
/**
* Return number of soldier instances
*/
virtual size_t GetNumPlayers() const = 0;
/**
* Fill vector with ids of all existing players
*/
virtual void GetPlayerIds(std::vector<std::string> &toFill) = 0;
/**
* Hide or unhide player with given id
* @param show true to show, false to hide
* @param when simulation time when show or hide should be executed - < 0 --> show immediatelly
*/
virtual void SetPlayerShown(const std::string &id, bool show, double when = -1) = 0;
/**
* Return number of building instances
*/
virtual size_t GetNumBuildings() const = 0;
/**
* Fill vector with ids of all existing buildings
*/
virtual void GetBuildingIds(std::vector<std::string> &toFill) const = 0;
/**
* Add or remove visible bounding box around entity
* @param id unique id of entity
* @param show set true to show box, false to make invisible
* @param duration If non-negative, remove box after duration seconds
*/
virtual void SetShowSelectionBox(const std::string &id,
bool show,
float duration = -1) = 0;
/**
* Add a line from start to end
* Line is deleted after duration seconds.
* If duration is 0 then line is never deleted
*/
virtual void Shoot(const int id,
const std::string &shooterId,
const std::string &targetId,
const Vec3d &shooterPos,
const Vec3d &targetPos,
int buildingIdSrc,
int roomNumberSrc,
int buildingIdDst,
int roomNumberDst,
int lineType,
double when) = 0;
/**
* Add a line from start to end where end is a room in the given building
* Line is deleted after duration seconds.
* If duration is 0 then line is never deleted
*/
virtual void Shoot(const int id,
const std::string &shooterId,
const std::string &targetBuildingId,
const std::string &targetRoomId,
const Vec3d &shooterPos,
int lineType,
double when) = 0;
/**
* Remove a line
*/
virtual void removeShoot(const int id) = 0;
/**
* Directly move player to target position, do not use pathfinding. Cancels current path following activity.
* @param id Id of player
* @param when Simulation time when teleport should happen
* @param target position to teleport to
* @param bldgname name of building containing position, empty string to ignore
* @param roomname name of room containing position, empty string to ignore
*/
virtual void Teleport(const std::string &id,
double when,
const Vec3d &target,
const std::string &bldgname,
int roomNumber,
const std::string &roomname,
ZValue zval) = 0;
/**
* Get names of all rooms in building
* @param id Id of building player
* @param names will be filled with room names
*/
virtual void GetRoomNames(const std::string &id, std::vector<std::string> &names) = 0;
/**
* Sets destruction value for room of a building.
* @param id Id of building player
* @param roomnumber number of room to set (ex: "2001")
* @param value destruction value. 0: not destroyed, 1: fully destroyed
* @return true if room was found
*/
virtual bool SetRoomDestructionValue(const std::string &id,
const std::string &roomname,
float value) = 0;
/**
* Sets destruction value for all rooms of a building.
* @param id Id of building player
* @param value destruction value. 0: not destroyed, 1: fully destroyed
* @return true if room was found
*/
virtual bool SetBuildingDestructionValue(const std::string &id, float value) = 0;
/**
* Get names of all cameras, loudspeakers and other devices in building
* @param buildingid Id of building player
* @param names will be filled with device names
*/
virtual void GetDeviceNames(const std::string &buildingid, std::vector<std::string> &names) = 0;
/**
* Show an icon at center position of device node
* @param id unique id for entity that can be used to hide it at a later point
* @param buildingid id of building containing the device
* @param devicename name of device node to show icon at
* @param iconpath absolute path to icon to show at device position
* @return true if device was found in building
*/
virtual bool ShowDeviceIcon(const std::string &id, const std::string &buildingid,
const std::string &devicename, const std::string &iconpath) = 0;
/**
* Show an icon at center position of device node
* @param id unique id for entity that can be used to hide it at a later point
* @param buildingid id of building containing the device
* @param position Position of camera relative to building
* @param iconpath absolute path to icon to show at device position
* @return true if device was found in building
*/
virtual bool ShowDeviceIcon(const std::string &id, const std::string &buildingid,
const Vec3d &position, const std::string &iconpath) = 0;
/**
* Hide device icon created with ShowDevice
* @param id Id used in call to ShowDevice
* @return true if device entity was found and successfully removed
*/
virtual bool HideDeviceIcon(const std::string &id) = 0;
/**
* Set the displayName of the given room in a given building
* @param buildingid id of building
* @param roomname
* @param strDisplayName
* @return true if room was found in building
*/
virtual bool SetDisplayName(const std::string& buildingid, const std::string& roomname,
const std::string& strDisplayName) = 0;
/**
* Show the displayName in a given building
* @param buildingid id of building
* @param show set true to show displayNames, false to make invisible
*/
virtual void ShowDisplayNames(const std::string& buildingid, bool show) = 0;
/**
* Add or remove visible bounding box around displayName entity
* @param buildingid unique id of building
* @param id id of room
* @param show set true to show box, false to make invisible
* @param duration If non-negative, remove box after duration seconds
*/
virtual void SetShowDisplayNamesSelectionBox(const std::string& buildingid,
const std::string& id,
bool show,
float duration = -1) = 0;
/**
* Get time scale. Scale 1 is normal, scale 2 is double normal speed
*/
virtual float GetTimeScale() const = 0;
/**
* Scale time. Scale 1 is normal, scale 2 is double normal speed
*/
virtual void SetTimeScale(float scale) = 0;
/**
* Set current simulation time in seconds
*/
virtual void SetSimulationTime(double t) = 0;
/**
* Get current simulation time in seconds
*/
virtual double GetSimulationTime() const = 0;
/**
* Pause simulation time and all events
*/
virtual void SetPaused(bool) = 0;
virtual bool GetPaused() const = 0;
/**
* Switch on or off non realtime mode.
* Non realtime mode is used for recording videos at faster than real time speed.
* Frames are rendered and compressed as fast as possible, simulation time
* does not correspond to real time.
*/
virtual void SetNonRealtimeMode(bool on) = 0;
/**
* Is non-realtime mode on or off?
*/
virtual bool GetNonRealtimeMode() const = 0;
/**
* Advance simulation until given simulation time is reached
*/
virtual void FastForwardSimulationTo(double t) = 0;
/**
* Remove all queued commands for soldiers
*/
virtual void DeleteQueuedCommands() = 0;
/**
* Start recording an mpeg video of the view.
* @param contextid context id of the view to record.
* @param path Record to this file. Extension should be .mpg
* @param w width of recorded video file (input is rescaled)
* @param h height of recorded video file (input is rescaled)
* @param framerate frames per second to record. Reasonable value: 15 - 30
* @param quality Compression quality in percent.
*/
virtual bool StartVideoRecording(unsigned int contextid, const std::string &path,
int w, int h, int framerate, int quality) = 0;
virtual bool StartVideoRecording(const std::string &buildingId, const std::string &path,
int w, int h, int framerate, int quality) = 0;
/**
* Stop recording
* @param contextid context id of the view to record.
*/
virtual bool StopVideoRecording(unsigned int contextid) = 0;
virtual bool StopVideoRecording(const std::string &buildingId) = 0;
virtual QJsonValue getViewState() const = 0;
virtual void setViewState(const QJsonValue &val) = 0;
virtual void highlightView(const std::string &buildingId) = 0;
virtual void setBuildingDisplayName(const std::string &buildingId, const std::string &displayName) = 0;
virtual void setHitLineDuration(uint32_t durationSec) = 0;
struct MountingPointDescription
{
std::string buildingId;
std::string mountingPointId;
Vec3d position;
BuildingViewer::AssetTypes assetType;
};
virtual void setMountingPointAsset(const MountingPointDescription &asset) = 0;
struct BuildingState
{
std::string buildingId;
std::string description;
int entityId = 0;
bool isShown = false;
};
virtual std::vector<BuildingState> getBuildingState() const = 0;
};
}