VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
exampleMilUnitsPlugin

Table of Contents

Overview

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

Expected Result

exampleMilUnitsPlugin.png
'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) 2023 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.
DtDisplayUnitsSettingsManager::instance(de).setAutoSave(false);
new DtMilsConverter() );
{
writeSettings( DtSharedSettingsManager::instance( de ) );
DtSharedDisplayUnitsSettings::Units attr;
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.
&installUnitConverter, std::ref(de) ));
}
}
}
}

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
{
}
}

[<< Examples] [Home] [Top of Page]


Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)