VR-Vantage
Loading...
Searching...
No Matches
exampleMilUnitsPlugin

Overview

Show how to add a shared display unit setting (Mils Orientation).

Expected Result

'Mil' Units Result

Example details

This example show how to add a custom "Orientation" unit converter. A new class DtMilsConverter that derived from DtOrientationUnitConverter class is created. That class implement the necessary functions to do the needed units conversion. Once created the new converter is added to the DtDisplayUnitsSettingsManager.

Building the Example

VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a plug-in. You can run it by running ./bin64/exampleMilUnits_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleMilUnits_stealth.sh (on Linux). Menu "Settings->Display...", select "Display Units Settings", the new "Mils" unit was added to "Orientation" drop down list. For more information about running examples, please see Running Applications and Examples.

Example Source Files


exampleMilUnitsPlugin.h

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#ifndef exampleMilUnitsPlugin_H_
#define exampleMilUnitsPlugin_H_
#ifdef _WIN32
#ifdef EXAMPLEMILUNITSPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEMILUNITSPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEMILUNITSPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEMILUNITSPLUGIN
#endif
#endif

exampleMilUnitsPluginInit.cxx

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
#include <matrix/vlMath.h>
{
return true;
}
using namespace makArchives;
namespace makVrv
{
namespace vrvExampleMilUnitsPlugin
{
inline double DtRad2Mil(double rad)
{
return ((rad / M_PI) * 3200.);
}
inline double DtMil2Rad(double mil)
{
return ((mil * M_PI) / 3200.0);
}
class DtMilsConverter : public DtOrientationUnitConverter
{
public:
DtMilsConverter()
: DtOrientationUnitConverter( UnitsMils )
{
}
~DtMilsConverter()
{
}
double radiansToLocal( double radians ) const
{
return DtRad2Mil(radians);
}
double localToRadians( double local ) const
{
return DtMil2Rad(local);
}
DtUnitConverter* clone() const
{
return new DtMilsConverter();
}
};
void installUnitConverter(DtDe& de)
{
//we don't want to autosave this , it's enabled in master by default.
de.sharedState().coordinateSystem().units().addUnitConverter(
DtDisplayUnitsSettingsRecord::Orientation, UnitsMils,
new DtMilsConverter() );
{
DtWriteSettingsLock<DtSharedDisplayUnitsSettings>
writeSettings( DtSharedSettingsManager::instance( de ) );
if (writeSettings->getUnitAttributes(DtDisplayUnitsSettingsRecord::Orientation, attr))
{
attr.push_back(DtSharedDisplayUnitsSettings::UnitEntry(
DtUnicode::tr("Mils"), DtUnicode::tr("Mils"), UnitsMils));
writeSettings->setUnitAttributes(DtDisplayUnitsSettingsRecord::Orientation, attr);
}
}
}
void init(DtDe& de)
{
// We only want to add the new unit converter if we are running in master mode.
if (de.isInMasterMode())
{
// The unit converter must be created after the DE's initialization of
// shared state is finished, but before any de observer announcements.
de.signal_initializeDefaultState.connect(boost::bind(
&installUnitConverter, std::ref(de) ));
}
}
}
}
Contains the DtCoordinateDisplayCollection class declaration.
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtDeSharedState class.
Contains the DtDisplayUnitsSettingsManager class declaration.
Contains the DtDisplayUnitsSettingsRecord class declaration.
Contains the DtSharedDisplayUnitsSettings class declaration.
Contains the DtUnitConverterCollection class declaration.
OrientationUnits
Enumeration of the different orientation units.
Definition DtDisplayUnitsSettingsRecord.h:103
@ OrientationUserStart
Definition DtDisplayUnitsSettingsRecord.h:107
virtual void setAutoSave(bool doit)
Sets whether autosave is enabled for the settings manager. If autosave is enabled,...
Definition DtBaseSettingsManager.h:75
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
static DtDisplayUnitsSettingsManager & instance(DtDe &de)
Get an instance of the settings manager.
std::vector< UnitEntry > Units
A vector of unit names and unit notations.
Definition DtSharedDisplayUnitsSettings.h:199
static DtSharedSettingsManager & instance(DtDe &)
Get an instance of the shared settings manager from the DtDe;.
static DtUnicode tr(const char *ascii)
Definition DtUnicode.h:92
Contains DLL export macros.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Definition DtAddPropsRuleRecord.h:20
DT_DLL_EXAMPLEMILUNITSPLUGIN void init(DtDe &anIG)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16

exampleMilUnitsPluginInit.h

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEMILUNITSPLUGIN
// Export plugging function bool initDeModule(DtDe* de);
namespace makVrv
{
class DtDe;
namespace vrvExampleMilUnitsPlugin
{
}
}
#define DT_DLL_EXAMPLEMILUNITSPLUGIN
Definition exampleMilUnitsPlugin.h:19