![]() |
VR-Forces 4.0.4 Class Documentation
|
/******************************************************************************* ** Copyright (c) 2012 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ //\file guiLocalCreateObjectMenu.h //This file defines all the menus and menu items that will be used for the object demo //Note that this demo expectes to be working on ground-db.mtf #include <vrfGuiCore/DtVrfStateViewCollectionManager.h> #include <vrvCoreQt/DtMenuItem.h> #include <vrvCoreQt/DtMenu.h> #pragma once namespace makVrf { class DtVrfObjectFacadeInterface; } namespace makVrv { class DtIntervisibilityElement; } //New main menu. This menu will be used to hold the Object Demo menu items class DtGuiLocalCreateObjectMenu : public makVrv::DtMenu { public: DtGuiLocalCreateObjectMenu(makVrv::DtDe& de); virtual ~DtGuiLocalCreateObjectMenu(); protected: virtual QMenu* createMenu(makVrv::DtDe& de, QWidget* parent ); }; //Base class for creating object demo menu items. Override the create() method to create the //appropriate local object class DtGuiLocalCreateObjectMenuItem : public makVrv::DtMenuItem { public: DtGuiLocalCreateObjectMenuItem(makVrv::DtDe&, const std::string& item); virtual ~DtGuiLocalCreateObjectMenuItem(); protected: virtual void on_triggered(); virtual void remove(); virtual makVrf::DtVrfObjectFacadeInterface* create() = 0; //Called when an object is to be deleted. If our interface, set to 0 and uncheck menu item if checked virtual void objectAboutToBeDeleted(makVrf::DtVrfObjectFacadeInterface*); protected: makVrv::DtDe& myDe; makVrf::DtVrfObjectFacadeInterface* myInterface; QAction* myAction; }; //Menu item for creating a line class DtGuiLocalCreateObjectLine : public DtGuiLocalCreateObjectMenuItem { public: DtGuiLocalCreateObjectLine(makVrv::DtDe& de); virtual ~DtGuiLocalCreateObjectLine(); //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); protected: virtual makVrf::DtVrfObjectFacadeInterface* create(); }; //Menu item for creating an area class DtGuiLocalCreateObjectArea : public DtGuiLocalCreateObjectMenuItem { public: DtGuiLocalCreateObjectArea(makVrv::DtDe& de); virtual ~DtGuiLocalCreateObjectArea(); //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); protected: virtual makVrf::DtVrfObjectFacadeInterface* create(); }; //Menu item for creating a waypoint class DtGuiLocalCreateObjectWaypoint : public DtGuiLocalCreateObjectMenuItem { public: DtGuiLocalCreateObjectWaypoint(makVrv::DtDe& de); virtual ~DtGuiLocalCreateObjectWaypoint(); //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); protected: virtual makVrf::DtVrfObjectFacadeInterface* create(); }; //Menu item for creating a M1A2 class DtGuiLocalCreateObjectM1A2 : public DtGuiLocalCreateObjectMenuItem { public: DtGuiLocalCreateObjectM1A2(makVrv::DtDe& de); virtual ~DtGuiLocalCreateObjectM1A2(); //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); protected: virtual makVrf::DtVrfObjectFacadeInterface* create(); }; //Menu item for creating a Airbus 320 class DtGuiLocalCreateObjectAirbus320 : public DtGuiLocalCreateObjectMenuItem { public: DtGuiLocalCreateObjectAirbus320(makVrv::DtDe& de); virtual ~DtGuiLocalCreateObjectAirbus320(); //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); protected: virtual makVrf::DtVrfObjectFacadeInterface* create(); }; //Creates an intervisibility fan class DtGuiLocalCreateObjectFan : public makVrv::DtMenuItem { public: DtGuiLocalCreateObjectFan(makVrv::DtDe&); virtual ~DtGuiLocalCreateObjectFan(); protected: //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); virtual void on_triggered(); protected: makVrv::DtIntervisibilityElement* myElement; makVrv::DtDe& myDe; QAction* myAction; }; //Creates intervisibility line and attaches to M1A2 and Airbus class DtGuiLocalCreateObjectAttachedLine : public makVrv::DtMenuItem { public: DtGuiLocalCreateObjectAttachedLine(makVrv::DtDe&); virtual ~DtGuiLocalCreateObjectAttachedLine(); protected: //Build a menu item (via an action). virtual QAction* createAction(makVrv::DtDe&, QWidget* parent); virtual void on_aboutToShow(); virtual void on_triggered(); //Called when state views are removed, if m1a2 or airbus, also remove this line if //created virtual void slot_stateViewAboutToBeRemoved(const makVrv::DtStateView<makVrv::DtVrlinkSimulatedBaseState>&); protected: makVrv::DtIntervisibilityElement* myElement; makVrv::DtDe& myDe; QAction* myAction; };
guiLocalCreateObjectMenu.cxx
/******************************************************************************* ** Copyright (c) 2012 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ //\file guiLocalCreateObjectMenu.cxx #include "guiLocalCreateObjectMenu.h" #include <vrfGuiCore/DtLocalObjectManager.h> #include <vrfGuiCore/DtEnvironmentalFacadeCollection.h> #include <vrfGuiCore/DtEntityDataInterface.h> #include <vrfGuiCore/DtEntityFacadeCollection.h> #include <vrfGuiCoreQt/DtCreateMenu.h> #include <vrvCore/DtIntervisibilityDriver.h> #include <vrvCore/DtIntervisibilityElement.h> #include <matrix/vlMath.h> #include <QtGui/QMenu> #include <QtGui/QAction> using namespace makVrv; using namespace makVrf; DtGuiLocalCreateObjectMenu::DtGuiLocalCreateObjectMenu(DtDe& de) : DtMenu(de, "DtGuiLocalCreateObjectMenu") { } DtGuiLocalCreateObjectMenu::~DtGuiLocalCreateObjectMenu() { } QMenu* DtGuiLocalCreateObjectMenu::createMenu(makVrv::DtDe& de, QWidget* parent ) { QMenu* menu = new QMenu(QObject::tr("Object Demo"), parent); return menu; } //Base object demo menu item DtGuiLocalCreateObjectMenuItem::DtGuiLocalCreateObjectMenuItem(DtDe& de, const std::string& item) : myDe(de) , DtMenuItem(item) , myAction(0) { } DtGuiLocalCreateObjectMenuItem::~DtGuiLocalCreateObjectMenuItem() { if (!myDe.destructing()) { DtLocalObjectManager::instance(myDe).signal_objectAboutToBeDeleted.disconnect(boost::bind(&DtGuiLocalCreateObjectMenuItem::objectAboutToBeDeleted, this, _1)); } } void DtGuiLocalCreateObjectMenuItem::on_triggered() { if (((QAction*)sender())->isChecked()) { DtLocalObjectManager::instance(myDe).signal_objectAboutToBeDeleted.connect(boost::bind(&DtGuiLocalCreateObjectMenuItem::objectAboutToBeDeleted, this, _1)); myInterface = create(); //Set interface to be non-editable if (myInterface) { DtLocalObjectManager::instance(myDe).setEditable(myInterface->uniqueID(), false); } } else if (myInterface) { remove(); } } void DtGuiLocalCreateObjectMenuItem::objectAboutToBeDeleted(DtVrfObjectFacadeInterface* i) { if (myInterface == i) { myInterface = 0; if (myAction && myAction->isChecked()) { myAction->setChecked(false); } } } void DtGuiLocalCreateObjectMenuItem::remove() { if (myInterface) { DtLocalObjectManager::instance(myDe).deleteLocal(myInterface->uniqueID()); DtLocalObjectManager::instance(myDe).signal_objectAboutToBeDeleted.disconnect(boost::bind(&DtGuiLocalCreateObjectMenuItem::objectAboutToBeDeleted, this, _1)); } } //Menu item for creating a line DtGuiLocalCreateObjectLine::DtGuiLocalCreateObjectLine(DtDe& de) : DtGuiLocalCreateObjectMenuItem(de, "DtGuiLocalCreateObjectLine") { } DtGuiLocalCreateObjectLine::~DtGuiLocalCreateObjectLine() { } QAction* DtGuiLocalCreateObjectLine::createAction(DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create Line"), parent); myAction->setCheckable(true); return myAction; } DtVrfObjectFacadeInterface* DtGuiLocalCreateObjectLine::create() { //Add vertices for line std::vector<DtVector> localLocations; localLocations.push_back(DtVector(0, 0, 0)); localLocations.push_back(DtVector(700, 700, 0)); localLocations.push_back(DtVector(900, 350, 0)); DtEnvironmentalCreationData envData; //Set up some data to be used for creation envData.setName("Demo Line"); envData.setLineWidth(10.); envData.setOverlayParent("Object Demo"); //Use name as it appears on create menu. Also could have used type DtEntityType(17, 0, 0, 2, 1, 1, 0) return DtLocalObjectManager::instance(myDe).create( DtCreateMenu::instance(myDe).nameToType("Route"), localLocations, 1, envData); } //Menu item for creating an area DtGuiLocalCreateObjectArea::DtGuiLocalCreateObjectArea(DtDe& de) : DtGuiLocalCreateObjectMenuItem(de, "DtGuiLocalCreateObjectArea") { } DtGuiLocalCreateObjectArea::~DtGuiLocalCreateObjectArea() { } QAction* DtGuiLocalCreateObjectArea::createAction(DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create Area"), parent); myAction->setCheckable(true); return myAction; } DtVrfObjectFacadeInterface* DtGuiLocalCreateObjectArea::create() { //Add vertices for line std::vector<DtVector> localLocations; localLocations.push_back(DtVector(100, 1700, 0)); localLocations.push_back(DtVector(1000, 1700, 0)); localLocations.push_back(DtVector(1000, 1600, 0)); localLocations.push_back(DtVector(100, 1600, 0)); DtEnvironmentalCreationData envData; //Set up some data to be used for creation envData.setName("Demo Area"); envData.setLineWidth(10.); envData.setOverlayParent("Object Demo"); envData.setColor(QColor(122, 122, 122, 122).rgba()); //Use name as it appears on create menu. Also could have used type DtEntityType(18, 0, 0, 1, 1, 0, 0) return DtLocalObjectManager::instance(myDe).create( DtCreateMenu::instance(myDe).nameToType("Area"), localLocations, 1, envData); } //Menu item for creating a waypoint DtGuiLocalCreateObjectWaypoint::DtGuiLocalCreateObjectWaypoint(DtDe& de) : DtGuiLocalCreateObjectMenuItem(de, "DtGuiLocalCreateObjectWaypoint") { } DtGuiLocalCreateObjectWaypoint::~DtGuiLocalCreateObjectWaypoint() { } QAction* DtGuiLocalCreateObjectWaypoint::createAction(DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create Waypoint"), parent); myAction->setCheckable(true); return myAction; } DtVrfObjectFacadeInterface* DtGuiLocalCreateObjectWaypoint::create() { //Add vertices for line std::vector<DtVector> localLocations; localLocations.push_back(DtVector(1500, 1500, 17.)); DtEnvironmentalCreationData envData; //Set up some data to be used for creation envData.setName("Demo Waypoint"); envData.setLineWidth(10.); envData.setOverlayParent("Object Demo"); //Use name as it appears on create menu. Also could have used type DtEntityType(16, 0, 0, 1, 0, 0, 0) return DtLocalObjectManager::instance(myDe).create( DtCreateMenu::instance(myDe).nameToType("Waypoint"), localLocations, 1, envData); } //Menu item for creating a M1A2 DtGuiLocalCreateObjectM1A2::DtGuiLocalCreateObjectM1A2(DtDe& de) : DtGuiLocalCreateObjectMenuItem(de, "DtGuiLocalCreateObjectM1A2") { } DtGuiLocalCreateObjectM1A2::~DtGuiLocalCreateObjectM1A2() { } QAction* DtGuiLocalCreateObjectM1A2::createAction(DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create M1A2"), parent); myAction->setCheckable(true); return myAction; } DtVrfObjectFacadeInterface* DtGuiLocalCreateObjectM1A2::create() { //Add vertices for line std::vector<DtVector> localLocations; DtEntityCreationData entData(DtCreateMenu::instance(myDe).nameToType("M1A2"), 1, DtVector(600, 600, 21.)); //Set up some data to be used for creation entData.setName("Demo M1A2"); entData.setHeading(DtDeg2Rad(45.0)); //Use name as it appears on create menu. return DtLocalObjectManager::instance(myDe).create(entData, "Object Demo"); } //Menu item for creating a Airbus 320 DtGuiLocalCreateObjectAirbus320::DtGuiLocalCreateObjectAirbus320(DtDe& de) : DtGuiLocalCreateObjectMenuItem(de, "DtGuiLocalCreateObjectAirbus320") { } DtGuiLocalCreateObjectAirbus320::~DtGuiLocalCreateObjectAirbus320() { } QAction* DtGuiLocalCreateObjectAirbus320::createAction(DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create Airbus 320"), parent); myAction->setCheckable(true); return myAction; } DtVrfObjectFacadeInterface* DtGuiLocalCreateObjectAirbus320::create() { //Add vertices for line std::vector<DtVector> localLocations; DtEntityCreationData entData(DtCreateMenu::instance(myDe).nameToType("Airbus 320"), 1, DtVector(1200, 1200, 210.)); //Set up some data to be used for creation entData.setName("Demo Airbus"); entData.setHeading(DtDeg2Rad(90.0)); //Use name as it appears on create menu. return DtLocalObjectManager::instance(myDe).create(entData, "Object Demo"); } //Creates an intervisibility fan DtGuiLocalCreateObjectFan::DtGuiLocalCreateObjectFan(makVrv::DtDe& de) : DtMenuItem("DtGuiLocalCreateObjectFan") , myDe(de) , myElement(0) , myAction(0) { } DtGuiLocalCreateObjectFan::~DtGuiLocalCreateObjectFan() { } QAction* DtGuiLocalCreateObjectFan::createAction(makVrv::DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create Intervisibility Fan"), parent); myAction->setCheckable(true); return myAction; } void DtGuiLocalCreateObjectFan::on_triggered() { if (myAction->isChecked()) { //Create the element via the intervisibility driver DtIntervisibilityDriver* driver = DtIntervisibilityDriver::findDriver(myDe); if (driver) { myElement = driver->createIntervisibilityFan(DtVector(700., 700., 30.), DtVector(700., 1200., 30.)); if (myElement) { myElement->setPickable(false); DtLocalObjectManager::instance(myDe).setEditable(myElement->elementID(), false); } } } else if (myElement) { DtLocalObjectManager::instance(myDe).setEditable(myElement->elementID(), true); DtIntervisibilityDriver* driver = DtIntervisibilityDriver::findDriver(myDe); driver->destroy(myElement->elementID()); myElement = 0; } } //Creates intervisibility line and attaches to M1A2 and Airbus DtGuiLocalCreateObjectAttachedLine::DtGuiLocalCreateObjectAttachedLine(makVrv::DtDe& de) : DtMenuItem("DtGuiLocalCreateObjectAttachedLine") , myDe(de) , myElement(0) , myAction(0) { DtVrfStateViewCollectionManager& svcMgr = DtVrfStateViewCollectionManager::instance( myDe ); svcMgr.simulatedBaseStateViewCollection()->signal_stateViewAboutToBeRemoved.connect (boost::bind(&DtGuiLocalCreateObjectAttachedLine::slot_stateViewAboutToBeRemoved, this, _1)); } DtGuiLocalCreateObjectAttachedLine::~DtGuiLocalCreateObjectAttachedLine() { } QAction* DtGuiLocalCreateObjectAttachedLine::createAction(makVrv::DtDe&, QWidget* parent) { if (myAction) { return myAction; } myAction = new QAction(tr("Create Intervisibility Line"), parent); myAction->setCheckable(true); return myAction; } void DtGuiLocalCreateObjectAttachedLine::on_aboutToShow() { if (myAction) { DtVrfStateViewCollectionManager& manager = DtVrfStateViewCollectionManager::instance(myDe); myAction->setEnabled(manager.findStateView("Demo M1A2") && manager.findStateView("Demo Airbus")); } } void DtGuiLocalCreateObjectAttachedLine::on_triggered() { if (myAction->isChecked()) { //Create the element via the intervisibility driver DtIntervisibilityDriver* driver = DtIntervisibilityDriver::findDriver(myDe); if (driver) { //Get the state views to attach to ids DtVrfStateViewCollectionManager& manager = DtVrfStateViewCollectionManager::instance(myDe); DtEntityDataInterfacePtr m1a2 = manager.lookupAndCastObjectData<DtEntityDataInterface>("Demo M1A2"); DtEntityDataInterfacePtr airbus = manager.lookupAndCastObjectData<DtEntityDataInterface>("Demo Airbus"); if (m1a2 && airbus) { DtIntervisibilityDriver::AttachPoints pts; myElement = driver->createIntervisibilityLine(m1a2->location(), airbus->location()); if (myElement) { myElement->setPickable(false); DtLocalObjectManager::instance(myDe).setEditable(myElement->elementID(), false); } } } } else if (myElement) { DtLocalObjectManager::instance(myDe).setEditable(myElement->elementID(), true); DtIntervisibilityDriver* driver = DtIntervisibilityDriver::findDriver(myDe); driver->destroy(myElement->elementID()); myElement = 0; } } void DtGuiLocalCreateObjectAttachedLine::slot_stateViewAboutToBeRemoved(const makVrv::DtStateView<makVrv::DtVrlinkSimulatedBaseState>& s) { if (myElement) { if ((s.state().myMarkingText == "Demo Airbus") || (s.state().myMarkingText == "Demo M1A2")) { DtLocalObjectManager::instance(myDe).setEditable(myElement->elementID(), true); DtIntervisibilityDriver* driver = DtIntervisibilityDriver::findDriver(myDe); driver->destroy(myElement->elementID()); myElement = 0; } } }