Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Pose3d with common widget pose #1571

Merged
merged 9 commits into from
Jul 14, 2022
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 34 additions & 222 deletions src/gui/plugins/component_inspector/Pose3d.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*
*/
import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Layouts 1.3
Expand All @@ -25,7 +24,7 @@ import "qrc:/qml"

// Item displaying 3D pose information.
Rectangle {
height: header.height + content.height
height: header.height + gzPoseContent.height
width: componentInspector.width
color: index % 2 == 0 ? lightGrey : darkGrey

Expand All @@ -35,83 +34,10 @@ Rectangle {
// Horizontal margins
property int margin: 5

// Maximum spinbox value
property double spinMax: 1000000

// Read-only / write
property bool readOnly: {
var isModel = entityType == "model"
return !(isModel) || nestedModel
}

// Loaded item for X
property var xItem: {}

// Loaded item for Y
property var yItem: {}

// Loaded item for Z
property var zItem: {}

// Loaded item for roll
property var rollItem: {}

// Loaded item for pitch
property var pitchItem: {}

// Loaded item for yaw
property var yawItem: {}

// Send new pose to C++
function sendPose() {
function sendPose(x, y, z, roll, pitch, yaw) {
// TODO(anyone) There's a loss of precision when these values get to C++
Pose3dImpl.OnPose(
xItem.value,
yItem.value,
zItem.value,
rollItem.value,
pitchItem.value,
yawItem.value
);
}

FontMetrics {
id: fontMetrics
font.family: "Roboto"
}

/**
* Used to create a spin box
*/
Component {
id: writableNumber
IgnSpinBox {
id: writableSpin
value: writableSpin.activeFocus ? writableSpin.value : numberValue
minimumValue: -spinMax
maximumValue: spinMax
decimals: getDecimals(writableSpin.width)
onEditingFinished: {
sendPose()
}
}
}

/**
* Used to create a read-only number
*/
Component {
id: readOnlyNumber
Text {
id: numberText
anchors.fill: parent
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: {
var decimals = getDecimals(numberText.width)
return numberValue.toFixed(decimals)
}
}
Pose3dImpl.OnPose(x, y, z, roll, pitch, yaw);
}

Column {
Expand All @@ -135,7 +61,7 @@ Rectangle {
sourceSize.width: indentation
fillMode: Image.Pad
Layout.alignment : Qt.AlignVCenter
source: content.show ?
source: gzPoseContent.show ?
"qrc:/Gazebo/images/minus.png" : "qrc:/Gazebo/images/plus.png"
}
TypeHeader {
Expand All @@ -150,7 +76,7 @@ Rectangle {
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
content.show = !content.show
gzPoseContent.show = !gzPoseContent.show
}
onEntered: {
header.color = highlightColor
Expand All @@ -160,166 +86,52 @@ Rectangle {
}
}
}

// Content
Rectangle {
id: content
AzulRadio marked this conversation as resolved.
Show resolved Hide resolved
property bool show: false
width: parent.width
height: show ? grid.height : 0
clip: true
color: "transparent"

Behavior on height {
NumberAnimation {
duration: 200;
easing.type: Easing.InOutQuad
}
}

GridLayout {
id: grid
width: parent.width
height: gzPoseContent.height
RowLayout {
id: gzPoseRow
width: parent.width
columns: 6

// Left spacer
Item {
Layout.rowSpan: 3
width: margin + indentation
}

Text {
text: 'X (m)'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
}

Item {
Layout.fillWidth: true
height: 40
Loader {
id: xLoader
anchors.fill: parent
property double numberValue: model.data[0]
sourceComponent: readOnly ? readOnlyNumber : writableNumber
onLoaded: {
xItem = xLoader.item
}
}
}

Text {
text: 'Roll (rad)'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
Layout.preferredWidth: margin + indentation
}

Item {
// Content
GzPose {
id: gzPoseContent
AzulRadio marked this conversation as resolved.
Show resolved Hide resolved
Layout.fillWidth: true
height: 40
Loader {
id: rollLoader
anchors.fill: parent
property double numberValue: model.data[3]
sourceComponent: readOnly ? readOnlyNumber : writableNumber
onLoaded: {
rollItem = rollLoader.item
}
}
}

// Right spacer
Item {
Layout.rowSpan: 3
width: margin
}

Text {
text: 'Y (m)'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
}

Item {
Layout.fillWidth: true
height: 40
Loader {
id: yLoader
anchors.fill: parent
property double numberValue: model.data[1]
sourceComponent: readOnly ? readOnlyNumber : writableNumber
onLoaded: {
yItem = yLoader.item
}
readOnly: {
var isModel = entityType == "model"
return !(isModel) || nestedModel
}
}

Text {
text: 'Pitch (rad)'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
}
xValue: model.data[0]
yValue: model.data[1]
zValue: model.data[2]
rollValue: model.data[3]
pitchValue: model.data[4]
yawValue: model.data[5]

Item {
Layout.fillWidth: true
height: 40
Loader {
id: pitchLoader
anchors.fill: parent
property double numberValue: model.data[4]
sourceComponent: readOnly ? readOnlyNumber : writableNumber
onLoaded: {
pitchItem = pitchLoader.item
}
onGzPoseSet: {
// _x, _y, _z, _roll, _pitch, _yaw are parameters of signal gzPoseSet
sendPose(_x, _y, _z, _roll, _pitch, _yaw)
}
}

Text {
text: 'Z (m)'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
}

Item {
Layout.fillWidth: true
height: 40
Loader {
id: zLoader
anchors.fill: parent
property double numberValue: model.data[2]
sourceComponent: readOnly ? readOnlyNumber : writableNumber
onLoaded: {
zItem = zLoader.item
}
}
}
// By default it is closed
show: false

Text {
text: 'Yaw (rad)'
leftPadding: 5
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
font.pointSize: 12
}
} // end gzPoseContent

// Right spacer
Item {
Layout.fillWidth: true
height: 40
Loader {
id: yawLoader
anchors.fill: parent
property double numberValue: model.data[5]
sourceComponent: readOnly ? readOnlyNumber : writableNumber
onLoaded: {
yawItem = yawLoader.item
}
}
Layout.preferredWidth: margin
}
}
}
}
}
} // end RowLayout
} // end Rectangle
} // end Column
} // end Rectangle