VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Range Line (rangeLine)

The Range Line example demonstrates the following:

The Range Line example demonstrates how to add a new visual definition to show a line of range between two points.

The Range Line is added as a new tactical graphic object. It is also added to the existing entity fan to show how to modify an existing intervisibility object to add a range calculation from the origin to the outside of the entity fan

/*******************************************************************************
** Copyright (c) 2013 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file rangeLine.cxx
//This file defines the generic DT_DLL_VRF_PLUGIN_EXPORT_MACRO. Use that macro when
//you want to export symbols.
using namespace makVrf;
using namespace makVrv;
static DtUnicode theRangeLineDefinition = DtUnicode::fromAscii("Range_Line");
static DtUnicode theRangeVertexDefinition = DtUnicode::fromAscii("RangedVertex");
static DtUnicode theRangeVertexIVDefinition = DtUnicode::fromAscii("RangedIVVertex");
static const DtEntityMapperKey theRangeLineType(-1, 17,1,0,12,0,0,0); // Range line type
// Because the create menu is recreated with each new scenario, need to manipulate the menu here after it
// has been loaded. If the range line item is not present, add it
void DtCreateMenuConfigurationLoaded(DtDe* de, const DtFilename&, DtVrfModelSetManager* mgr)
{
if (!mgr->exactModelSetEntry(theRangeLineType))
{
// Put this into its own category for easy finding
DtRwNLengthStringVector cats("categories");
cats.add("Distance");
DtModelSetEntry* entry = mgr->addModelSetEntry("Range Line", theRangeLineType, cats);
entry->setOnlyOnPalette("TacticalGraphicCreationPalette");
// After added, add an icon for it
entry->setMenuIcon("$(DATA_DIR)/images/overlays/small/line.png");
}
}
void disableHATLinesFor(DtDe& de, DtVisualizerDefinitionSet& set)
{
std::vector<DtVisualizerDefinition*> defs;
set.findVisualizerDefinitions(DtBuiltInSchemas::theDtHATLineSchema().name(), defs);
if (defs.size())
{
// Now that we have it, change the vertex visualizer set used to our ranged vertex visualizer set by
// first disabling the HAT lines so they do not occlude the range
defs[0]->findOrCreateLocalAttribute("enabled"));
// Could not find, so create one
if (!setValue)
{
setValue =
dynamic_cast<DtVisualizerAttributeBool*>(
DtVisualizerAttributeFactory::instance(de).create(DtVisualizerAttributeBool::theTypeInfo().className));
setValue->setValue(false);
defs[0]->setAttribute("enabled", std::auto_ptr<DtVisualizerAttribute>(setValue));
}
else
{
*setValue = false;
}
}
}
DtVisualizerDefinition* createRangeVertexDefinition(DtDe& de, DtElementDefinitionNew* curDef, const DtUnicode& newDef)
{
DtElementDefinitionTypeManager& typeMgr = DtElementDefinitionTypeManager::instance(de);
DtElementDefinitionManager* manager = typeMgr.findElementManager(DtElementDefinitionTypeManager::TacticalGraphics);
DtElementDefinitionNew* rangeVertexDef = manager->createElementDefinition(newDef, curDef);
if (rangeVertexDef)
{
// For the 2D model set, find and disable the current vertex visualizer as we are going to replace it
disableHATLinesFor(de, set);
// And, finally, add the new ranged vertex definition
DtVisualizerDefinition* rangeDefinition = set.createVisualizerDefinition(
// Set up the minimal values to make sure the visualizer will work after being added
DtVisualizerAttributeFactory::instance(de).create(DtVisualizerAttributeString::theTypeInfo().className));
attr->setValue(DtUnicode::fromAscii("Main Object"));
rangeDefinition->setAttribute("parent", std::auto_ptr<DtVisualizerAttribute>(attr));
attr =
DtVisualizerAttributeFactory::instance(de).create(DtVisualizerAttributeString::theTypeInfo().className));
attr->setValue(DtUnicode::fromAscii("DtRangeLineTextVisualizer"));
rangeDefinition->setAttribute("type", std::auto_ptr<DtVisualizerAttribute>(attr));
attr =
DtVisualizerAttributeFactory::instance(de).create(DtVisualizerAttributeString::theTypeInfo().className));
attr->setValue(DtUnicode::fromAscii("main_model"));
rangeDefinition->setAttribute("visualtype", std::auto_ptr<DtVisualizerAttribute>(attr));
return rangeDefinition;
}
return 0;
}
//Now that the application has been initialized the new route line and visualizer can be added to our range line. This needs to be done
//here to make sure that any new additions are properly added to the communication thread
{
// Only going to add this new visualizer set to the range line, so, for the range line, create it as a
// child of the existing route visualizer, turn off the existing vertex visualizer and add the new vertex visualizer which is
// the range of the line -- which does not include height above terrain. Since this is only currently being supported in 2D (model set 5) this is
// the only changes that will be made to the visualizer definition
// For the mapped types, add the new type into the tactical graphic mapper to map to
// what will be the new range route definition
{
DtWriteSettingsLock<DtSharedSimulationSettings> settings(DtSharedSettingsManager::instance(de));
if (!settings->tacticalGraphicsMapper().findMappings(theRangeLineType))
{
settings->tacticalGraphicsMapper().addMapping(theRangeLineType, theRangeLineDefinition);
}
}
// Add the creator into the factory for the range line text visualizer
DtStateVisualizerFactory::instance(de).addStateVisualizerCreator(de, new DtRangeLineTextVisualizerCreator);
// First, get the tactical graphic manager
DtElementDefinitionTypeManager& typeMgr = DtElementDefinitionTypeManager::instance(de);
DtElementDefinitionManager* manager = typeMgr.findElementManager(DtElementDefinitionTypeManager::TacticalGraphics);
// First make sure the definition is not already there. If it is not, then add it
if (!manager->findElementDefinition(theRangeLineDefinition))
{
DtElementDefinitionNew* curDef = manager->findElementDefinition(DtUnicode::fromAscii("Route"));
if (curDef)
{
// Create the route definition as part of the parent
DtElementDefinitionNew* rangeLineDef = manager->createElementDefinition(theRangeLineDefinition, curDef);
if (rangeLineDef)
{
// For the 2D model set, find and disable the current vertex visualizer as we are going to replace it
disableHATLinesFor(de, set);
std::vector<DtVisualizerDefinition*> defs;
set.findVisualizerDefinitions(DtBuiltInSchemas::theDtShapeVertexSchema().name(), defs);
if (defs.size())
{
// Now that we have it, change the vertex visualizer set used to our ranged vertex visualizer set
defs[0]->findOrCreateLocalAttribute("vertexvisualizerset"));
if (setValue)
{
*setValue = theRangeVertexDefinition;
}
}
}
}
}
// Now see if we need to add the ranged vertex definition. This will be a child of the existing Vertex definition
// that will turn off the hat line visualizer and add the range line visualizer for 2D only
if (!manager->findElementDefinition(theRangeVertexDefinition))
{
DtElementDefinitionNew* curDef = manager->findElementDefinition(DtUnicode::fromAscii("Vertex"));
if (curDef)
{
createRangeVertexDefinition(de, curDef, theRangeVertexDefinition);
}
curDef = manager->findElementDefinition(DtUnicode::fromAscii("IntervisibilityVertex"));
if (curDef)
{
DtVisualizerDefinition* ivVertexDef = createRangeVertexDefinition(de, curDef, theRangeVertexIVDefinition);
// Since the only definition for the entity fan is at the origin for a vertex, compute the range as from this
// point to the next
if (ivVertexDef)
{
// Now that we have it, change the vertex visualizer set used to our ranged vertex visualizer set by
// first disabling the HAT lines so they do not occlude the range
ivVertexDef->findOrCreateLocalAttribute("computeToNextPoint"));
// Could not find, so create one
if (!setValue)
{
setValue =
dynamic_cast<DtVisualizerAttributeBool*>(
DtVisualizerAttributeFactory::instance(de).create(DtVisualizerAttributeBool::theTypeInfo().className));
setValue->setValue(true);
ivVertexDef->setAttribute("computeToNextPoint", std::auto_ptr<DtVisualizerAttribute>(setValue));
}
else
{
*setValue = true;
}
}
}
}
}
// Since the intervisibility dictionary is not created until the first post tick, we must connect to a post tick and finish the setup
// here
void completeIVSetup(DtDe* de)
{
DtElementDefinitionTypeManager& typeMgr = DtElementDefinitionTypeManager::instance(*de);
DtElementDefinitionManager* manager = typeMgr.findElementManager(DtElementDefinitionTypeManager::Intervisibility);
DtElementDefinitionNew* fanDef = manager->findElementDefinition(DtUnicode::fromAscii("IntervisibilityEntityFan"));
if (fanDef)
{
de->signal_postTick.disconnect(boost::bind(&completeIVSetup, de));
// For the 2D model set, find and disable the current vertex visualizer as we are going to replace it
disableHATLinesFor(*de, set);
std::vector<DtVisualizerDefinition*> defs;
set.findVisualizerDefinitions(DtIntervisibilityVertexVisualizer::theTypeInfo().schema.name(), defs);
if (defs.size())
{
// Now that we have it, change the vertex visualizer set used to our ranged vertex visualizer set
defs[0]->findOrCreateLocalAttribute("vertexvisualizerset"));
if (setValue)
{
*setValue = theRangeVertexIVDefinition;
}
}
}
// Else keep connected until the definitions are present
}
//This function is called by our plugin structure to make changes to the front end. This method will add a connection to
//be called when the create menu is loaded. At that point a new item will be added for the range line
bool initDeModule(DtDe* de)
{
//Because the create menu is now populated by a settings file that is part of
//each simulation model set, setup a signal connection to be made to remove
//the create menu item from the model set as it is loaded
(boost::bind(&DtCreateMenuConfigurationLoaded, de, _1, _2));
//Since the intervisibility dictionary is not complete until the first post tick, set up a
//connection here to complete the setup for a range line connected to the entity intervisibility fan
de->signal_postTick.connect(boost::bind(&completeIVSetup, de));
return true;
}
//This function is also called by our plugin structure and prints out information about this plugin
//to the logs. It's a good indicator that the plugin loaded if you are looking at the logs.
{
info.pluginName = "Range Line";
info.pluginDescription = "This example shows how to create a new object from scratch and create a new visualizer and updater";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "150 Cambridge Park Drive 3rd Floor - Cambridge, MA 02140 USA";
info.pluginContactPhone = "(617) 876 8085";
}

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)