VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Object Filtering (objectFilter)

Table of Contents

The Object Filter example demonstrates the following:

Adding a Filter Criteria

The Object Filer example will demonstrate how to show or hide an object based on filter criteria. A few filters are defined for the demo, however, more filters may be added.

How to Run the Example

Usage

In the Launcher, click the Plug-ins button to bring up the Plug-ins Selection dialog. Enable the plugin.

To view the new behavior:

  1. Start VR-Forces GUI and SIM.
  2. Load an existing scenario - e.g. HawaiiGround.scnx.
  3. Choose Objects menu item
  4. Select the newly added Visibility sub-menu - e.g. Hide Entities
  5. Choose a filter to hide objects
  6. Objects that match the criteria of the filter will be hidden. Due to the nature of the example, newly created objects that meet the condition of the filter might be seen momentarily before being hidden

Classes

DtObjectFilterManagerThe manager used to maintain filters for hiding objects.
DtDestroyedFilterA filter created to hide all destroyed objects.

Plugin Entry Points

/*******************************************************************************
** Copyright (c) 2014 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//\file objectFilter.cxx
//This file defines the generic DT_DLL_VRF_PLUGIN_EXPORT_MACRO. Use that macro when
//you want to export symbols. Also, in your CMakeLists.txt file, make sure to
//define the VRFPLUGIN_EXPORTS define to tell the compiler to define the macro as an
//export
#include <vlpi/appearance.h>
#include <boost/bind.hpp>
#include <QMenu>
#include <QString>
#include <QtCore/QCoreApplication>
using namespace makVrv;
// This menu will be a submenu off of the Entities menu that will hold items that will
// allow the user to filter the display of objects
class DtObjectVisibilityMenu : public DtMenu
{
public:
DtObjectVisibilityMenu(DtDe& de)
: DtMenu(de, "DtObjectVisibilityMenu")
{
}
~DtObjectVisibilityMenu()
{
}
QMenu* createMenu( DtDe& de, QWidget* parent )
{
QMenu* menu = new QMenu(QObject::tr("Visibility"), parent);
return menu;
}
};
template <typename _Filter>
class DtObjectVisibilityMenuItem : public makVrv::DtCheckedItem
{
public:
DtObjectVisibilityMenuItem(makVrv::DtDe& de)
: DtCheckedItem(de, _Filter().className())
{
}
~DtObjectVisibilityMenuItem()
{
}
QAction* createAction(DtDe& de, QWidget* parent)
{
makVrv::DtUnicode text = makVrv::DtUnicode::tr("Hide ") + myFilter.filterName();
makVrv::DtUnicode toolTip = makVrv::DtUnicode::tr("Show/Hide ") + myFilter.filterName();
myOffText = text.translate<QString, QCoreApplication>();
myToolTip = toolTip.translate<QString, QCoreApplication>();
QAction* retVal = DtCheckedItem::createAction(de,parent);
updateValue();
return retVal;
}
void setValue( bool value )
{
}
bool getValue() const
{
}
protected:
_Filter myFilter;
};
template <typename _Filter>
class DtListViewObjectVisibilityMenuItem : public makVrv::DtCheckedItem
{
public:
DtListViewObjectVisibilityMenuItem(makVrv::DtDe& de)
: DtCheckedItem(de, _Filter().className())
{
}
~DtListViewObjectVisibilityMenuItem()
{
}
QAction* createAction(DtDe& de, QWidget* parent)
{
makVrv::DtUnicode text = makVrv::DtUnicode::tr("Hide On List Views ") + myFilter.filterName();
makVrv::DtUnicode toolTip = makVrv::DtUnicode::tr("Show/Hide On List Views ") + myFilter.filterName();
myOffText = text.translate<QString, QCoreApplication>();
myToolTip = toolTip.translate<QString, QCoreApplication>();
QAction* retVal = DtCheckedItem::createAction(de,parent);
updateValue();
return retVal;
}
void setValue( bool value )
{
if (value)
{
}
else
{
}
}
bool getValue() const
{
}
protected:
_Filter myFilter;
};
class DtHideEntitiesFilter : public makVrf::DtVrfKindLessThanFilter
{
public:
DtHideEntitiesFilter()
: DtVrfKindLessThanFilter("DtHideEntitiesFilterId", makVrv::DtUnicode::tr("Entities"), DtEntityType(11, -1, -1, -1, -1, -1, -1))
{
}
virtual DtVrfSelectionFilter* clone() const { return new DtHideEntitiesFilter(*this); };
};
class DtHideM1A2Filter : public makVrf::DtVrfSelectionObjectFilter
{
public:
DtHideM1A2Filter()
: DtVrfSelectionObjectFilter("DtHideM1A2FilterId", makVrv::DtUnicode::tr("M1A2"), DtEntityType(1, 1, 225, 1, 1, 3, -1))
{
}
virtual DtVrfSelectionFilter* clone() const { return new DtHideM1A2Filter(*this); };
};
class DtHideEntitiesByForceFilter : public makVrf::DtVrfKindLessThanFilter
{
public:
DtHideEntitiesByForceFilter(int force, const makVrv::DtUnicode& forceName)
: DtVrfKindLessThanFilter(("DtHideEntitiesByForceFilterId" + forceName.toAscii()),
(forceName + makVrv::DtUnicode::tr(" Entities")), DtEntityType(11, -1, -1, -1, -1, -1, -1), force)
{
}
};
class DtHideEntitiesByForceFriendlyFilter : public DtHideEntitiesByForceFilter
{
public:
DtHideEntitiesByForceFriendlyFilter()
: DtHideEntitiesByForceFilter(1, makVrv::DtUnicode::tr("Friendly"))
{
}
virtual DtVrfSelectionFilter* clone() const { return new DtHideEntitiesByForceFriendlyFilter(*this); };
};
class DtHideEntitiesByForceOpposingFilter : public DtHideEntitiesByForceFilter
{
public:
DtHideEntitiesByForceOpposingFilter()
: DtHideEntitiesByForceFilter(2, makVrv::DtUnicode::tr("Opposing"))
{
}
virtual DtVrfSelectionFilter* clone() const { return new DtHideEntitiesByForceOpposingFilter(*this); };
};
class DtHideEntitiesByForceNeutralFilter : public DtHideEntitiesByForceFilter
{
public:
DtHideEntitiesByForceNeutralFilter()
: DtHideEntitiesByForceFilter(3, makVrv::DtUnicode::tr("Neutral"))
{
}
virtual DtVrfSelectionFilter* clone() const { return new DtHideEntitiesByForceNeutralFilter(*this); };
};
class DtDestroyedFilter : public makVrf::DtVrfSelectionFilter
{
public:
DtDestroyedFilter()
: DtVrfSelectionFilter("DtDestroyedFilterId", makVrv::DtUnicode::tr("Destroyed"))
{
}
DtDestroyedFilter(const DtDestroyedFilter& orig)
: DtVrfSelectionFilter(orig)
{
}
virtual bool isValid(const makVrv::DtVrlinkSimulatedBaseState* s, const makVrf::DtVrfObjectDataState* objDataState) const
{
if (ent)
{
DtEntityType t(ent->myEntityType.c_str());
DtAppearance app(t);
app.setAppearance(ent->myAppearance);
return (app.damageState() == DtDamageDestroyed);
}
return false;
}
virtual void setForce(int)
{
}
virtual DtVrfSelectionFilter* clone() const { return new DtDestroyedFilter(*this); };
};
void initPluginMenus(DtVrvApplication& app, DtDe& de)
{
//First, register the creators with the menu assembler
DtQtMenuAssembler::instance(de).registerMenu(new DtObjectVisibilityMenu(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtObjectVisibilityMenuItem<DtHideEntitiesFilter>(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtObjectVisibilityMenuItem<DtDestroyedFilter>(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtObjectVisibilityMenuItem<DtHideEntitiesByForceFriendlyFilter>(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtObjectVisibilityMenuItem<DtHideEntitiesByForceOpposingFilter>(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtObjectVisibilityMenuItem<DtHideEntitiesByForceNeutralFilter>(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtListViewObjectVisibilityMenuItem<DtHideM1A2Filter>(de));
//Now, add the menu to the master mode configuration. mainMenu indicates that
//the example menu is going to be used as a top-level main menu rather than a
//sub-menu. Add it before the Task menu. To leave off the path will
//put the menu at the end of the menu bar
app.masterModeMenuConfiguration().addMenuPath(DtMenuPath::menu("DtObjectVisibilityMenu").item(DtHideEntitiesFilter().className()));
app.masterModeMenuConfiguration().addMenuPath(DtMenuPath::menu("DtObjectVisibilityMenu").
item(DtHideEntitiesByForceFriendlyFilter().className()));
app.masterModeMenuConfiguration().addMenuPath(DtMenuPath::menu("DtObjectVisibilityMenu").
item(DtHideEntitiesByForceOpposingFilter().className()));
app.masterModeMenuConfiguration().addMenuPath(DtMenuPath::menu("DtObjectVisibilityMenu").
item(DtHideEntitiesByForceNeutralFilter().className()));
app.masterModeMenuConfiguration().addMenuPath(DtMenuPath::menu("DtObjectVisibilityMenu").item(DtDestroyedFilter().className()));
app.masterModeMenuConfiguration().addMenuPath(DtMenuPath::menu("DtObjectVisibilityMenu").item(DtHideM1A2Filter().className()));
}
static void slot_activated(makVrv::DtDe* de)
{
}
bool initDeModule(DtDe* de)
{
if(igApp)
{
initPluginMenus(*igApp, *de);
if (announcer)
{
announcer->signal_deactivate.connect(boost::bind(&slot_activated, de));
}
return true;
}
else
{
return false;
}
}
{
info.pluginName = "Object Filter";
info.pluginDescription = "This example shows how to filter objects for visibility on the front-end.";
info.pluginVersion = "1.00";
info.pluginCreator = "MAK Technologies";
info.pluginCreatorEmail = "sales@mak.com";
info.pluginContactWebPage = "www.mak.com";
info.pluginContactMailingAddress = "10 Fawcett Street, Suite 204, Cambridge, MA 02138 USA";
info.pluginContactPhone = "(617) 876 8085";
}

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)