![]() |
VR-Forces 4.0.4 Class Documentation
|
The DtCustomControlObjectDefinitionDialog and its associated logic and creator classes handles the creation, definition and function of the dialog associated with the creation of the custom control object. The dialog is derived from the DtShapeObjectDefinitionDialog and modified to display GUI elements allowing the user to input the custom parameters.
/****************************************************************************** ** Copyright (c) 2011 MAK Technologies, Inc. ** All rights reserved. ******************************************************************************/ /****************************************************************************** ** $RCSfile: DtCustomControlObjectDialog.h,v $ $Revision: 1.0 $ $State: Exp $ ******************************************************************************/ //\file DtCustomControlObjectDialog.h //\brief Contains DtCustomControlObjectDialog class. #pragma once #include <vrfGuiCoreQt/shapeObjectDefinitionDialog.h> #include <vlpi/entityType.h> #include <vrvCore/DtUniqueID.h> #include <string> class QLineEdit; namespace vrfCustomControlObjectExample { class DtCustomControlObjectDefinitionDialog; const DtEntityType DtCustomControlObjectType = DtEntityType(18,-1,-1,1,0,0,101); class DtCustomControlObjectDefinitionDialogLogic : public makVrf::DtShapeObjectDefinitionDialogLogic { public: DtCustomControlObjectDefinitionDialogLogic(makVrv::DtDe& de, DtCustomControlObjectDefinitionDialog* iface); virtual ~DtCustomControlObjectDefinitionDialogLogic(); virtual void setUserData(const std::string); virtual std::string userData(); virtual void processUserDataChanged(); virtual void processPopulateDialog(const makVrv::DtUniqueID& id ); protected: DtCustomControlObjectDefinitionDialog* myCustomDialog; }; class DtCustomControlObjectDefinitionDialog : public makVrf::DtShapeObjectDefinitionDialog { Q_OBJECT public: DtCustomControlObjectDefinitionDialog(makVrv::DtDe& de, QWidget* parent, const std::string title="", DtDialogInteractionMode mode=DtCreationMode); virtual ~DtCustomControlObjectDefinitionDialog(); virtual void init(); virtual int parameterOne(); virtual double parameterTwo(); virtual void setParameterOne(int); virtual void setParameterTwo(double); protected: virtual void setupGui(); void setupConnections(); protected slots: void slot_onUserDataChanged(); protected: DtCustomControlObjectDefinitionDialogLogic* myCustomLogic; QLineEdit* myParamOneLineEdit; QLineEdit* myParamTwoLineEdit; }; class DtCustomControlObjectDefinitionDialogCreator : public makVrf::DtVrfObjectModifierDialogCreator { public: virtual makVrf::DtCreateAndEditObjectDialogInterface* create( makVrv::DtDe& de, QWidget* parent, DtEntityType entityType, const std::string title="", makVrf::DtCreationSignalType signalCreation=makVrf::DtNoCreationSignal, makVrf::DtCreateAndEditObjectDialogInterface::DtDialogInteractionMode mode=makVrf::DtCreateAndEditObjectDialogInterface::DtCreationMode, const makVrf::DtVrfObjectManipulationManager::DtEditingType& editType=makVrf::DtVrfObjectManipulationManager::Context); }; }
/****************************************************************************** ** Copyright (c) 2011 MAK Technologies, Inc. ** All rights reserved. ******************************************************************************/ /****************************************************************************** ** $RCSfile: DtCustomControlObjectDialog.cxx,v $ $Revision: 1.0 $ $State: Exp $ ******************************************************************************/ //\file DtCustomControlObjectDialog.cxx //\brief Contains DtCustomControlObjectDialog #include <vrfGuiCoreQt/shapeObjectDefinitionDialog.h> #include "customControlObjectDefinitionDialog.h" #include <vrvCore/DtDeSharedState.h> #include <vrvCore/DtEntityState.h> #include <vrvCoreQt/DtQtDeMainWindow.h> #include <vlpi/entityType.h> #include <QBoxLayout> #include <QLabel> #include <QLineEdit> #include <vrvCore/DtUniqueID.h> #include <vrfGuiCore/DtVrfShapeManipulationHandler.h> #include <symbology/ttfUnitSymbol.h> #include <vlutil/vlString.h> #include <vrfGuiCore/DtVrfStateViewCollectionManager.h> #include <vrfGuiCore/DtEnvironmentState.h> using namespace makVrf; //The Logic class should namespace vrfCustomControlObjectExample { DtCustomControlObjectDefinitionDialogLogic::DtCustomControlObjectDefinitionDialogLogic(makVrv::DtDe& de, DtCustomControlObjectDefinitionDialog* iface) : DtShapeObjectDefinitionDialogLogic(de, iface) , myCustomDialog(iface) { } DtCustomControlObjectDefinitionDialogLogic::~DtCustomControlObjectDefinitionDialogLogic() { myCustomDialog = 0; } void DtCustomControlObjectDefinitionDialogLogic::setUserData(const std::string userData) { if (userData == "") { return; } DtString firstString(userData.c_str()); DtString secondString(userData.c_str()); firstString.snipBack(','); secondString.snipFront(','); myCustomDialog->setParameterOne(firstString.toInt()); myCustomDialog->setParameterTwo(secondString.toDouble()); } std::string DtCustomControlObjectDefinitionDialogLogic::userData() { DtString fullString(myCustomDialog->parameterOne()); fullString = fullString + "," + myCustomDialog->parameterTwo(); return fullString.c_str(); } void DtCustomControlObjectDefinitionDialogLogic::processUserDataChanged() { //This code is executed when either of the userData fields are modified DtVrfShapeManipulationHandler* handler = dynamic_cast<DtVrfShapeManipulationHandler*> (DtVrfObjectManipulationManager::instance(myDe).currentObjectManipulationHandler()); handler->setUserData(userData()); } void DtCustomControlObjectDefinitionDialogLogic::processPopulateDialog(const makVrv::DtUniqueID& id ) { DtShapeObjectDefinitionDialogLogic::processPopulateDialog(id); makVrf::DtEnvironmentStateView* envStateView = const_cast<makVrf::DtEnvironmentStateView*>( makVrf::DtVrfStateViewCollectionManager::instance(myDe).environmentStateViewCollection()->findStateView( id ) ); setUserData(envStateView->state().myUserData); } //========Dialog class =============== DtCustomControlObjectDefinitionDialog::DtCustomControlObjectDefinitionDialog(makVrv::DtDe& de, QWidget* parent, const std::string title, DtDialogInteractionMode mode) :DtShapeObjectDefinitionDialog(de, parent, title, mode) , myCustomLogic(0) , myParamOneLineEdit(0) , myParamTwoLineEdit(0) { } DtCustomControlObjectDefinitionDialog::~DtCustomControlObjectDefinitionDialog() { disconnect(myParamTwoLineEdit, SIGNAL(editingFinished()), this, SLOT(slot_onUserDataChanged())); disconnect(myParamOneLineEdit, SIGNAL(editingFinished()), this, SLOT(slot_onUserDataChanged())); myCustomLogic = 0; myParamOneLineEdit = 0; myParamTwoLineEdit = 0; } void DtCustomControlObjectDefinitionDialog::init() { myCustomLogic = new DtCustomControlObjectDefinitionDialogLogic(myDe, this); myLogic = myCustomLogic; setupGui(); makVrv::DtQtDeMainWindow* qtMainWindow = dynamic_cast<makVrv::DtQtDeMainWindow*>(myParent); qtMainWindow->addDockWidget(Qt::RightDockWidgetArea, this); setupConnections(); myCustomLogic->setupGui(); setDockType(DtAutoHideDock::Dialog); } void DtCustomControlObjectDefinitionDialog::setupConnections() { DtShapeObjectDefinitionDialog::setupConnections(); connect(myParamOneLineEdit, SIGNAL(editingFinished()), this, SLOT(slot_onUserDataChanged())); connect(myParamTwoLineEdit, SIGNAL(editingFinished()), this, SLOT(slot_onUserDataChanged())); } void DtCustomControlObjectDefinitionDialog::slot_onUserDataChanged() { myCustomLogic->processUserDataChanged(); } int DtCustomControlObjectDefinitionDialog::parameterOne() { return myParamOneLineEdit->text().toInt(); } double DtCustomControlObjectDefinitionDialog::parameterTwo() { return myParamTwoLineEdit->text().toDouble(); } void DtCustomControlObjectDefinitionDialog::setParameterOne(int inParameterOne) { myParamOneLineEdit->setText(QString::number(inParameterOne)); } void DtCustomControlObjectDefinitionDialog::setParameterTwo(double inParameterTwo) { myParamTwoLineEdit->setText(QString::number(inParameterTwo)); } void DtCustomControlObjectDefinitionDialog::setupGui() { DtShapeObjectDefinitionDialog::setupGui(); //Create an Hbox to be inserted QHBoxLayout* myQtHboxForParams = new QHBoxLayout(); myQtHboxForParams->setObjectName(QString::fromUtf8("myQtHboxForParams")); //Add and populate parameter one label QLabel* myParamOneLabel = new QLabel(); myParamOneLabel->setObjectName(QString::fromUtf8("myParamOneLabel")); myParamOneLabel->setToolTip(QApplication::translate("myUiImpl", "Custom Parameter One.", 0, QApplication::UnicodeUTF8)); myParamOneLabel->setText(QApplication::translate("myUiImpl", "Parameter One:", 0, QApplication::UnicodeUTF8)); //Add a lineEdit box for parameter one myParamOneLineEdit = new QLineEdit(); myParamOneLineEdit->setObjectName(QString::fromUtf8("myParamOneLineEdit")); //Add and populate parameter Two label QLabel* myParamTwoLabel = new QLabel(); myParamTwoLabel->setObjectName(QString::fromUtf8("myParamTwoLabel")); myParamTwoLabel->setToolTip(QApplication::translate("myUiImpl", "Custom Parameter Two.", 0, QApplication::UnicodeUTF8)); myParamTwoLabel->setText(QApplication::translate("myUiImpl", "Parameter Two:", 0, QApplication::UnicodeUTF8)); //Add a lineEdit box for parameter Two myParamTwoLineEdit = new QLineEdit(); myParamTwoLineEdit->setObjectName(QString::fromUtf8("myParamTwoLineEdit")); //Put these elements into the Hbox myQtHboxForParams->addWidget(myParamOneLabel); myQtHboxForParams->addWidget(myParamOneLineEdit); myQtHboxForParams->addWidget(myParamTwoLabel); myQtHboxForParams->addWidget(myParamTwoLineEdit); //insert the new Hbox into the UI myUiImpl.verticalLayout->insertLayout(4,myQtHboxForParams); } //===============CREATOR CLASS========================= DtCreateAndEditObjectDialogInterface* DtCustomControlObjectDefinitionDialogCreator::create(makVrv::DtDe& de, QWidget* parent, DtEntityType entityType, const std::string title,makVrf::DtCreationSignalType signalCreation, DtCreateAndEditObjectDialogInterface::DtDialogInteractionMode mode, const DtVrfObjectManipulationManager::DtEditingType& editType) { //Create the custom dialog, modify it depending on mode, //and then hand the pointer back out DtCustomControlObjectDefinitionDialog * thisObjectDefinitionDialog = new DtCustomControlObjectDefinitionDialog(de, parent, title, mode); thisObjectDefinitionDialog->init(); thisObjectDefinitionDialog->setTitle(title.c_str()); thisObjectDefinitionDialog->setAllowOverlaySelection(true); if (mode == DtCreateAndEditObjectDialogInterface::DtCreationMode) { thisObjectDefinitionDialog->populateOverlays(); //If signalCreation is set to creationAndStop then we are indicating that we only want one //object created. This is used when creating entities in plans. if (signalCreation == DtSignalCreationAndStop) { thisObjectDefinitionDialog->setCreateButtonVisible(true); } } else if (mode == DtCreateAndEditObjectDialogInterface::DtEditingMode) { thisObjectDefinitionDialog->setUpdateButtonVisible(true); thisObjectDefinitionDialog->setUpdateButtonText("OK"); thisObjectDefinitionDialog->setAttachObjectToMouse(editType != DtVrfObjectManipulationManager::Context); } return thisObjectDefinitionDialog; } }