Skip to content
Snippets Groups Projects
Commit a4e107bc authored by Fabian Paus's avatar Fabian Paus
Browse files

RemoteGui: Remove old example

New example can be found at ArmarXGui/applications/RemoteGuiExample
parent b22706ed
No related branches found
No related tags found
No related merge requests found
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package ArmarXGui::application::RemoteGuiExample
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2018
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include <ArmarXGui/components/RemoteGuiExample/RemoteGuiExample.h>
#include <ArmarXCore/core/application/Application.h>
#include <ArmarXCore/core/Component.h>
#include <ArmarXCore/core/logging/Logging.h>
int main(int argc, char* argv[])
{
return armarx::runSimpleComponentApp < armarx::RemoteGuiExample > (argc, argv, "RemoteGuiExample");
}
add_subdirectory(RemoteGuiProvider)
add_subdirectory(RemoteGuiExample)
\ No newline at end of file
armarx_component_set_name("RemoteGuiExample")
find_package(Eigen3 QUIET)
armarx_build_if(Eigen3_FOUND "Eigen is required for RemoteGui due to C++ stuff in the Ice interface :(")
find_package(Simox QUIET)
armarx_build_if(Simox_FOUND "Simox is required for RemoteGui due to C++ stuff in the Ice interface :(")
set(COMPONENT_LIBS
DecoupledSingleComponent
ArmarXGuiComponentPlugins
RemoteGui
)
set(SOURCES
RemoteGuiExample.cpp
)
set(HEADERS
RemoteGuiExample.h
)
armarx_add_component("${SOURCES}" "${HEADERS}")
target_link_libraries(RemoteGuiExample PUBLIC Eigen3::Eigen SimoxUtility)
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package ArmarXGui::ArmarXObjects::RemoteGuiExample
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2018
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "RemoteGuiExample.h"
#include <ArmarXGui/libraries/RemoteGui/WidgetBuilder.h>
#include <ArmarXGui/libraries/RemoteGui/Storage.h>
#include <ArmarXCore/core/time/CycleUtil.h>
namespace armarx
{
RemoteGuiExample::RemoteGuiExample()
: runningTask(new RunningTask<RemoteGuiExample>(this, &RemoteGuiExample::run))
{
}
void RemoteGuiExample::onInitComponent()
{
remoteGuiName = getProperty<std::string>("RemoteGuiName").getValue();
usingProxy(remoteGuiName);
mode = getProperty<RemoteGuiExampleMode>("Mode").getValue();
tabName = "Test";
}
void RemoteGuiExample::onConnectComponent()
{
remoteGui = getProxy<RemoteGuiInterfacePrx>(remoteGuiName);
switch (mode)
{
case RemoteGuiExampleMode::Widgets:
createTab_Widgets();
break;
case RemoteGuiExampleMode::Events:
createTab_Events();
break;
}
tab = RemoteGui::TabProxy(remoteGui, tabName);
runningTask->start();
}
void RemoteGuiExample::onDisconnectComponent()
{
ARMARX_INFO << "Stopping task";
if (!runningTask->isStopped())
{
runningTask->stop();
}
ARMARX_INFO << "Removing tab: " << tabName;
remoteGui->removeTab(tabName);
}
void RemoteGuiExample::onExitComponent()
{
onDisconnectComponent();
}
armarx::PropertyDefinitionsPtr RemoteGuiExample::createPropertyDefinitions()
{
return armarx::PropertyDefinitionsPtr(new RemoteGuiExamplePropertyDefinitions(
getConfigIdentifier()));
}
void RemoteGuiExample::run()
{
int cycleDurationMs = 20;
CycleUtil c(cycleDurationMs);
while (!runningTask->isStopped())
{
tab.receiveUpdates();
switch (mode)
{
case RemoteGuiExampleMode::Widgets:
updateTab_Widgets(tab);
break;
case RemoteGuiExampleMode::Events:
updateTab_Events(tab);
break;
}
tab.sendUpdates();
c.waitForCycleDuration();
}
}
using namespace RemoteGui;
void RemoteGuiExample::createTab_Widgets()
{
// Just add a lot of widgets...
tabName = "Widgets";
auto vLayout = makeVBoxLayout();
{
WidgetPtr label = makeTextLabel("Line: ").toolTip("tooltip");
WidgetPtr lineEdit = makeLineEdit("Line").toolTip("tooltip")
.value("Hello");
WidgetPtr line = makeHBoxLayout()
.children({label, lineEdit});
vLayout.addChild(line);
}
{
WidgetPtr label = makeTextLabel("Combo: ").toolTip("tooltip");
WidgetPtr combo = makeComboBox("Combo").toolTip("tooltip")
.options({"First", "Second", "Third", "Fourth"})
.value("Second");
WidgetPtr line = makeHBoxLayout()
.children({label, combo});
vLayout.addChild(line);
}
{
WidgetPtr label = makeTextLabel("Check: ").toolTip("tooltip");
WidgetPtr checkBox = makeCheckBox("Check").toolTip("tooltip")
.value(true);
WidgetPtr line = makeHBoxLayout()
.children({label, checkBox});
vLayout.addChild(line);
}
{
WidgetPtr label = makeTextLabel("Toggle: ").toolTip("tooltip");
WidgetPtr toggle = makeToggleButton("Toggle").toolTip("tooltip")
.label("Toggle")
.value(true);
WidgetPtr line = makeHBoxLayout()
.children({label, toggle});
vLayout.addChild(line);
}
{
WidgetPtr label = makeTextLabel("Int: ").toolTip("tooltip");
WidgetPtr slider = makeIntSlider("IntSlider").toolTip("tooltip")
.min(0).max(10)
.value(5);
WidgetPtr spin = makeIntSpinBox("IntSpin").toolTip("tooltip")
.min(0).max(10)
.value(5);
WidgetPtr line = makeHBoxLayout()
.children({label, slider, spin});
vLayout.addChild(line);
}
{
WidgetPtr label = makeTextLabel("Float: ").toolTip("tooltip");
WidgetPtr slider = makeFloatSlider("FloatSlider").toolTip("tooltip")
.min(0.0f).max(2.0f)
.value(0.0f);
WidgetPtr spin = makeFloatSpinBox("FloatSpin").toolTip("tooltip")
.min(0.0f).max(2.0f)
.steps(20).decimals(2)
.value(0.4f);
WidgetPtr line = makeHBoxLayout()
.children({label, slider, spin});
vLayout.addChild(line);
}
{
WidgetPtr label = makeTextLabel("Button: ").toolTip("tooltip");
WidgetPtr button = makeButton("Button").toolTip("tooltip")
.label("Button");
WidgetPtr line = makeHBoxLayout()
.children({label, button});
vLayout.addChild(line);
}
vLayout.addChild(new VSpacer);
WidgetPtr groupBox = makeGroupBox("GroupBox (with tool tips)")
.label("Group")
.child(vLayout)
.addChild(
makeSimpleGridLayout().cols(3)
.addChild(makeTextLabel("this sublayout has three cols").toolTip("tooltip"))
.addChild(makeTextLabel("elem2").toolTip("tooltip"))
.addChild(makeTextLabel("elem3").toolTip("tooltip"))
.addChild(makeTextLabel("elem4").toolTip("tooltip"))
.addChild(makeTextLabel("elem4").toolTip("tooltip"))
.addChild(makeTextLabel("elem6").toolTip("tooltip"))
.addChild(makeVector3fSpinBoxes("Vector3fSpinBoxes").toolTip("tooltip"), 3)
.addChild(makePosRPYSpinBoxes("PosRPYSpinBoxes").toolTip("tooltip"), 3)
.addHLine(2)
.addTextLabel("children can span over multiple rows. they might span over the number of columns you set in the beginning.", 2)
);
WidgetPtr gridGroupBox = makeGroupBox("GroupBox (with grid layout)").addChild(
makeGridLayout("grid me")
.addChild(makeButton("1"), 0, 0, 1, 2)
.addChild(makeButton("2"), 0, 2, 2, 1)
.addChild(makeButton("3"), 1, 1, 1, 1)
.addChild(makeButton("4"), 1, 0, 2, 1)
.addTextLabel("foooooooooooooooooo", 2, 1, 1, 2)
.addHSpacer(0, 3, 1, 1)
);
remoteGui->createTab(tabName,
makeVBoxLayout()
.addChild(groupBox)
.addChild(gridGroupBox)
.addChild(
makeGroupBox("this bos starts collapsed")
.collapsed()
.addTextLabel("now it is expanded"))
);
}
void RemoteGuiExample::updateTab_Widgets(TabProxy& tab)
{
// Sync the slider and the spin box manually (slider is the master)
ValueProxy<int> intSlider = tab.getValue<int>("IntSlider");
ValueProxy<int> intSpin = tab.getValue<int>("IntSpin");
int intSliderValue = intSlider.get();
intSpin.set(intSliderValue);
// And the other way around for the float slider/spin box
ValueProxy<float> floatBox = tab.getValue<float>("FloatSpin");
ValueProxy<float> floatSlider = tab.getValue<float>("FloatSlider");
float floatBoxValue = floatBox.get();
floatSlider.set(floatBoxValue);
// ARMARX_INFO << VAROUT(tab.getValue<Eigen::Vector3f>("Vector3fSpinBoxes").get());
// ARMARX_INFO << VAROUT(tab.getValue<Eigen::Matrix4f>("PosRPYSpinBoxes").get());
}
void RemoteGuiExample::createTab_Events()
{
tabName = "Events";
auto vLayout = makeVBoxLayout();
{
WidgetPtr label = makeTextLabel("Counter: ");
WidgetPtr spin = makeIntSpinBox("IntSpin")
.min(-10).max(10)
.value(0);
WidgetPtr line = makeHBoxLayout()
.children({label, spin});
vLayout.addChild(line);
}
{
WidgetPtr buttonUp = makeButton("UpButton")
.label("Up");
WidgetPtr buttonDown = makeButton("DownButton")
.label("Down");
WidgetPtr line = makeHBoxLayout()
.children({buttonUp, buttonDown});
vLayout.addChild(line);
}
vLayout.addChild(new VSpacer);
WidgetPtr groupBox = makeGroupBox("GroupBox")
.label("Group")
.child(vLayout);
remoteGui->createTab(tabName, groupBox);
}
void RemoteGuiExample::updateTab_Events(TabProxy& tab)
{
// Detect button clicks and update the counter accordingly
ValueProxy<int> intSpin = tab.getValue<int>("IntSpin");
ButtonProxy upButton = tab.getButton("UpButton");
ButtonProxy downButton = tab.getButton("DownButton");
int currentValue = intSpin.get();
bool upClicked = upButton.clicked();
bool downClicked = downButton.clicked();
if (upClicked)
{
++currentValue;
}
if (downClicked)
{
--currentValue;
}
remoteGui->setValue(tabName, "IntSpin", makeValue(currentValue));
}
}
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package ArmarXGui::ArmarXObjects::RemoteGuiExample
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2018
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <ArmarXGui/interface/RemoteGuiInterface.h>
#include <ArmarXGui/libraries/RemoteGui/WidgetProxy.h>
#include <ArmarXCore/core/Component.h>
#include <ArmarXCore/core/services/tasks/RunningTask.h>
namespace armarx
{
enum class RemoteGuiExampleMode
{
Widgets,
Events
};
/**
* @class RemoteGuiExamplePropertyDefinitions
* @brief
*/
class RemoteGuiExamplePropertyDefinitions:
public armarx::ComponentPropertyDefinitions
{
public:
RemoteGuiExamplePropertyDefinitions(std::string prefix):
armarx::ComponentPropertyDefinitions(prefix)
{
defineOptionalProperty<std::string>("RemoteGuiName", "RemoteGuiProvider", "Name of the remote GUI provider");
defineOptionalProperty<RemoteGuiExampleMode>("Mode", RemoteGuiExampleMode::Widgets, "Select which example to execute")
.map("Widgets", RemoteGuiExampleMode::Widgets)
.map("Events", RemoteGuiExampleMode::Events);
}
};
/**
* @defgroup Component-RemoteGuiExample RemoteGuiExample
* @ingroup ArmarXGui-Components
* A description of the component RemoteGuiExample.
*
* @class RemoteGuiExample
* @ingroup Component-RemoteGuiExample
* @brief Brief description of class RemoteGuiExample.
*
* Detailed description of class RemoteGuiExample.
*/
class RemoteGuiExample :
virtual public armarx::Component
{
public:
RemoteGuiExample();
/**
* @see armarx::ManagedIceObject::getDefaultName()
*/
std::string getDefaultName() const override
{
return "RemoteGuiExample";
}
protected:
/**
* @see armarx::ManagedIceObject::onInitComponent()
*/
void onInitComponent() override;
/**
* @see armarx::ManagedIceObject::onConnectComponent()
*/
void onConnectComponent() override;
/**
* @see armarx::ManagedIceObject::onDisconnectComponent()
*/
void onDisconnectComponent() override;
/**
* @see armarx::ManagedIceObject::onExitComponent()
*/
void onExitComponent() override;
/**
* @see PropertyUser::createPropertyDefinitions()
*/
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override;
private:
void run();
void createTab_Widgets();
void updateTab_Widgets(RemoteGui::TabProxy& tab);
void createTab_Events();
void updateTab_Events(RemoteGui::TabProxy& tab);
private:
std::string remoteGuiName;
RemoteGuiInterfacePrx remoteGui;
RemoteGuiExampleMode mode;
std::string tabName;
RemoteGui::TabProxy tab;
RunningTask<RemoteGuiExample>::pointer_type runningTask;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment