diff --git a/source/ArmarXGui/interface/WidgetDescription.ice b/source/ArmarXGui/interface/WidgetDescription.ice index 6bc1c8d41542d959edb2c3b0b89af42a1f5b7d0c..c58420a9ef7efe4e621cf362d086a9ef3fd63b7a 100644 --- a/source/ArmarXGui/interface/WidgetDescription.ice +++ b/source/ArmarXGui/interface/WidgetDescription.ice @@ -111,7 +111,7 @@ module armarx float min=0; float max=0; float defaultValue=0; - double steps = 100; + int steps = 100; int decimals = 3; }; class DoubleSpinBox extends ConfigWidget @@ -119,7 +119,7 @@ module armarx double min=0; double max=0; double defaultValue=0; - double steps = 100; + int steps = 100; int decimals = 3; }; class IntSlider extends ConfigWidget diff --git a/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.cpp b/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.cpp index f56401e70104aca8612a51f94b24f54fb45a5df0..3972f959fd1d8d0024d70a5b9ffdd567b14b9402 100644 --- a/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.cpp +++ b/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.cpp @@ -22,83 +22,264 @@ #include "DefaultWidgetDescriptions.h" +namespace armarx +{ + namespace WidgetDescription + { + //base widgets + LabeledWidgetPtr makeLabeledWidget(std::string name, WidgetPtr widget) + { + LabeledWidgetPtr w = new LabeledWidget; + w->label = std::move(name); + w->w = std::move(widget); + return w; + } -using namespace armarx; + HBoxLayoutPtr makeHBoxLayout(std::vector<WidgetPtr> elements) + { + HBoxLayoutPtr w = new HBoxLayout; + w->widgets = std::move(elements); + return w; + } + + VBoxLayoutPtr makeVBoxLayout(std::vector<WidgetPtr> elements) + { + VBoxLayoutPtr w = new VBoxLayout; + w->widgets = std::move(elements); + return w; + } + FormLayoutPtr makeFormLayout(std::vector<std::pair<std::string, WidgetPtr> > elements) + { + FormLayoutPtr l = new FormLayout; + l->widgets.reserve(elements.size()); + for (auto& elem : elements) + { + l->widgets.emplace_back(makeLabeledWidget(std::move(elem.first), std::move(elem.second))); + } + return l; + } + FormLayoutPtr makeFormLayout(std::vector<WidgetPtr> elements) + { + FormLayoutPtr l = new FormLayout; + l->widgets.reserve(elements.size()); + for (auto& elem : elements) + { + std::string name; + if (ConfigWidgetPtr::dynamicCast(elem)) + { + name = ConfigWidgetPtr::dynamicCast(elem)->name; + } + l->widgets.emplace_back(makeLabeledWidget(std::move(name), std::move(elem))); + } + return l; + } -WidgetDescription::HBoxLayoutPtr WidgetDescription::makeXYZRollPitchYawWidget( - const std::string& namePrefix, - float initX, - float initY, - float initz, - float initRoll, - float initPitch, - float initYaw, - FloatRange rangeX, - FloatRange rangeY, - FloatRange rangeZ, - FloatRange rangeRoll, - FloatRange rangePitch, - FloatRange rangeYaw) -{ - HBoxLayoutPtr layout = new HBoxLayout; - { - layout->widgets.emplace_back(new Label {"x / y / z"}); - { - FloatSpinBoxPtr spinX = new FloatSpinBox; - spinX->defaultValue = initX; - spinX->min = rangeX.min; - spinX->max = rangeX.max; - spinX->name = namePrefix + "X"; - layout->widgets.emplace_back(spinX); - } - { - FloatSpinBoxPtr spinY = new FloatSpinBox; - spinY->defaultValue = initY; - spinY->min = rangeY.min; - spinY->max = rangeY.max; - spinY->name = namePrefix + "Y"; - layout->widgets.emplace_back(spinY); - } - { - FloatSpinBoxPtr spinZ = new FloatSpinBox; - spinZ->defaultValue = initz; - spinZ->min = rangeZ.min; - spinZ->max = rangeZ.max; - spinZ->name = namePrefix + "Z"; - layout->widgets.emplace_back(spinZ); - } - layout->widgets.emplace_back(new Label {" "}); - layout->widgets.emplace_back(new Label {"rx / ry / rz"}); - { - FloatSpinBoxPtr spinRoll = new FloatSpinBox; - spinRoll->defaultValue = initRoll; - spinRoll->min = rangeRoll.min; - spinRoll->max = rangeRoll.max; - spinRoll->steps = 2000; - spinRoll->name = namePrefix + "Roll"; - layout->widgets.emplace_back(spinRoll); - } - { - FloatSpinBoxPtr spinPitch = new FloatSpinBox; - spinPitch->defaultValue = initPitch; - spinPitch->min = rangePitch.min; - spinPitch->max = rangePitch.max; - spinPitch->steps = 2000; - spinPitch->name = namePrefix + "Pitch"; - layout->widgets.emplace_back(spinPitch); - } - { - FloatSpinBoxPtr spinYaw = new FloatSpinBox; - spinYaw->defaultValue = initYaw; - spinYaw->min = rangeYaw.min; - spinYaw->max = rangeYaw.max; - spinYaw->steps = 2000; - spinYaw->name = namePrefix + "Yaw"; - layout->widgets.emplace_back(spinYaw); - layout->widgets.emplace_back(new Label {"rz"}); - } - return layout; + HSpacerPtr makeHSpacer() + { + return new HSpacer; + } + + VSpacerPtr makeVSpacer() + { + return new VSpacer; + } + + LabelPtr makeLabel(std::string text) + { + return new Label {std::move(text)}; + } + + CheckBoxPtr makeCheckBox(std::string name, bool defaultValue, std::string label) + { + CheckBoxPtr w = new CheckBox; + w->name = std::move(name); + w->label = std::move(label); + w->defaultValue = defaultValue; + return w; + } + CheckBoxPtr makeCheckBox(std::string name, bool defaultValue) + { + CheckBoxPtr w = new CheckBox; + w->name = std::move(name); + w->label = w->name; + w->defaultValue = defaultValue; + return w; + } + + IntSpinBoxPtr makeIntSpinBox(std::string name, int min, int max, int defaultValue) + { + IntSpinBoxPtr w = new IntSpinBox; + w->name = std::move(name); + w->min = min; + w->max = max; + w->defaultValue = defaultValue; + return w; + } + + FloatSpinBoxPtr makeFloatSpinBox(std::string name, float min, float max, float defaultValue, int steps, int decimals) + { + FloatSpinBoxPtr w = new FloatSpinBox; + w->name = std::move(name); + w->min = min; + w->max = max; + w->defaultValue = defaultValue; + w->steps = steps; + w->decimals = decimals; + return w; + } + + DoubleSpinBoxPtr makeDoubleSpinBox(std::string name, double min, double max, double defaultValue, int steps, int decimals) + { + DoubleSpinBoxPtr w = new DoubleSpinBox; + w->name = std::move(name); + w->min = min; + w->max = max; + w->defaultValue = defaultValue; + w->steps = steps; + w->decimals = decimals; + return w; + } + + IntSliderPtr makeIntSlider(std::string name, int min, int max, int defaultValue) + { + IntSliderPtr w = new IntSlider; + w->name = std::move(name); + w->min = min; + w->max = max; + w->defaultValue = defaultValue; + return w; + } + + FloatSliderPtr makeFloatSlider(std::string name, float min, float max, float defaultValue) + { + FloatSliderPtr w = new FloatSlider; + w->name = std::move(name); + w->min = min; + w->max = max; + w->defaultValue = defaultValue; + return w; + } + + DoubleSliderPtr makeDoubleSlider(std::string name, double min, double max, double defaultValue) + { + DoubleSliderPtr w = new DoubleSlider; + w->name = std::move(name); + w->min = min; + w->max = max; + w->defaultValue = defaultValue; + return w; + } + + StringComboBoxPtr makeStringComboBox(std::string name, std::vector<std::string> options, long defaultIndex) + { + StringComboBoxPtr w = new StringComboBox; + w->name = std::move(name); + w->options = std::move(options); + w->defaultIndex = defaultIndex; + return w; + } + + LineEditPtr makeLineEdit(std::string name, std::string defaultValue) + { + LineEditPtr w = new LineEdit; + w->name = std::move(name); + w->defaultValue = std::move(defaultValue); + return w; + } + + FloatLineEditPtr makeFloatLineEdit(std::string name, float defaultValue) + { + FloatLineEditPtr w = new FloatLineEdit; + w->name = std::move(name); + w->defaultValue = defaultValue; + return w; + } + + DoubleLineEditPtr makeDoubleLineEdit(std::string name, double defaultValue) + { + DoubleLineEditPtr w = new DoubleLineEdit; + w->name = std::move(name); + w->defaultValue = defaultValue; + return w; + } + + //more complex widgets + HBoxLayoutPtr makeXYZRollPitchYawWidget( + const std::string& namePrefix, + float initX, + float initY, + float initz, + float initRoll, + float initPitch, + float initYaw, + FloatRange rangeX, + FloatRange rangeY, + FloatRange rangeZ, + FloatRange rangeRoll, + FloatRange rangePitch, + FloatRange rangeYaw) + { + HBoxLayoutPtr layout = new HBoxLayout; + { + layout->widgets.emplace_back(new Label {"x / y / z"}); + { + FloatSpinBoxPtr spinX = new FloatSpinBox; + spinX->defaultValue = initX; + spinX->min = rangeX.min; + spinX->max = rangeX.max; + spinX->name = namePrefix + "X"; + layout->widgets.emplace_back(spinX); + } + { + FloatSpinBoxPtr spinY = new FloatSpinBox; + spinY->defaultValue = initY; + spinY->min = rangeY.min; + spinY->max = rangeY.max; + spinY->name = namePrefix + "Y"; + layout->widgets.emplace_back(spinY); + } + { + FloatSpinBoxPtr spinZ = new FloatSpinBox; + spinZ->defaultValue = initz; + spinZ->min = rangeZ.min; + spinZ->max = rangeZ.max; + spinZ->name = namePrefix + "Z"; + layout->widgets.emplace_back(spinZ); + } + layout->widgets.emplace_back(new Label {" "}); + layout->widgets.emplace_back(new Label {"rx / ry / rz"}); + { + FloatSpinBoxPtr spinRoll = new FloatSpinBox; + spinRoll->defaultValue = initRoll; + spinRoll->min = rangeRoll.min; + spinRoll->max = rangeRoll.max; + spinRoll->steps = 2000; + spinRoll->name = namePrefix + "Roll"; + layout->widgets.emplace_back(spinRoll); + } + { + FloatSpinBoxPtr spinPitch = new FloatSpinBox; + spinPitch->defaultValue = initPitch; + spinPitch->min = rangePitch.min; + spinPitch->max = rangePitch.max; + spinPitch->steps = 2000; + spinPitch->name = namePrefix + "Pitch"; + layout->widgets.emplace_back(spinPitch); + } + { + FloatSpinBoxPtr spinYaw = new FloatSpinBox; + spinYaw->defaultValue = initYaw; + spinYaw->min = rangeYaw.min; + spinYaw->max = rangeYaw.max; + spinYaw->steps = 2000; + spinYaw->name = namePrefix + "Yaw"; + layout->widgets.emplace_back(spinYaw); + layout->widgets.emplace_back(new Label {"rz"}); + } + return layout; + } + } } } diff --git a/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.h b/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.h index 52ab051bbf5c5613b91ba7c239c6d4f36569556e..67f75bd2be38f02f80cc2a9a52511cf591010655 100644 --- a/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.h +++ b/source/ArmarXGui/libraries/DefaultWidgetDescriptions/DefaultWidgetDescriptions.h @@ -29,6 +29,36 @@ namespace armarx { namespace WidgetDescription { + //base widgets + LabeledWidgetPtr makeLabeledWidget(std::string name, WidgetPtr widget); + + HBoxLayoutPtr makeHBoxLayout(std::vector<WidgetPtr> elements); + VBoxLayoutPtr makeVBoxLayout(std::vector<WidgetPtr> elements); + FormLayoutPtr makeFormLayout(std::vector<std::pair<std::string, WidgetPtr>> elements); + FormLayoutPtr makeFormLayout(std::vector<WidgetPtr> elements); + + HSpacerPtr makeHSpacer(); + VSpacerPtr makeVSpacer(); + LabelPtr makeLabel(std::string text); + + CheckBoxPtr makeCheckBox(std::string name, bool defaultValue, std::string label); + CheckBoxPtr makeCheckBox(std::string name, bool defaultValue = false); + + IntSpinBoxPtr makeIntSpinBox(std::string name, int min = 0, int max = 100, int defaultValue = 0); + FloatSpinBoxPtr makeFloatSpinBox(std::string name, float min = 0, float max = 100, float defaultValue = 0, int steps = 100, int decimals = 3); + DoubleSpinBoxPtr makeDoubleSpinBox(std::string name, double min = 0, double max = 100, double defaultValue = 0, int steps = 100, int decimals = 3); + + IntSliderPtr makeIntSlider(std::string name, int min = 0, int max = 100, int defaultValue = 0); + FloatSliderPtr makeFloatSlider(std::string name, float min = 0, float max = 100, float defaultValue = 0); + DoubleSliderPtr makeDoubleSlider(std::string name, double min = 0, double max = 100, double defaultValue = 0); + + StringComboBoxPtr makeStringComboBox(std::string name, std::vector<std::string> options, long defaultIndex = 0); + + LineEditPtr makeLineEdit(std::string name, std::string defaultValue = ""); + FloatLineEditPtr makeFloatLineEdit(std::string name, float defaultValue = 0); + DoubleLineEditPtr makeDoubleLineEdit(std::string name, double defaultValue = 0); + + //more complex widgets /** * @brief Values will have the names namePrefix{X,Y,Z,Roll,Pitch,Yaw} */ @@ -54,14 +84,6 @@ namespace armarx { return makeXYZRollPitchYawWidget(namePrefix, 0, 0, 0, 0, 0, 0, rangeLin, rangeLin, rangeLin, rangeAng, rangeAng, rangeAng); } - - inline LabeledWidgetPtr makeLabeledWidget(std::string name, WidgetPtr widget) - { - LabeledWidgetPtr w = new LabeledWidget; - w->label = std::move(name); - w->w = std::move(widget); - return w; - } } }