-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to modify joint type (#1198)
* Support editing air pressure sensor in the GUI Signed-off-by: Nate Koenig <[email protected]> * Add noise to qrc Signed-off-by: Nate Koenig <[email protected]> * Add noise to qrc Signed-off-by: Nate Koenig <[email protected]> * Fix lint Signed-off-by: Michael Carroll <[email protected]> * Update sensor icon Signed-off-by: Nate Koenig <[email protected]> * Move AirPressure functions out of ComponentInspector (#1179) Signed-off-by: Louise Poubel <[email protected]> * Fix get decimals, and address comments Signed-off-by: Nate Koenig <[email protected]> * cleanup and simplification Signed-off-by: Nate Koenig <[email protected]> * Require sdf 12.1.0 Signed-off-by: Nate Koenig <[email protected]> * missign width Signed-off-by: Nate Koenig <[email protected]> * Added simulation state aware spin box Signed-off-by: Nate Koenig <[email protected]> * Remove console output Signed-off-by: Nate Koenig <[email protected]> * Allow user to modify joint type Signed-off-by: Michael Carroll <[email protected]> * Updated to use a separate class, and consolidate the look Signed-off-by: Nate Koenig <[email protected]> * Added recreate to joint add Signed-off-by: Nate Koenig <[email protected]> Co-authored-by: Nate Koenig <[email protected]> Co-authored-by: Louise Poubel <[email protected]>
- Loading branch information
1 parent
d392d0f
commit 9d0471f
Showing
8 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
#include <sdf/Joint.hh> | ||
|
||
#include <ignition/common/Console.hh> | ||
#include "ignition/gazebo/components/JointType.hh" | ||
#include "ignition/gazebo/components/ParentEntity.hh" | ||
#include "ignition/gazebo/components/Recreate.hh" | ||
#include <ignition/gazebo/EntityComponentManager.hh> | ||
|
||
#include "JointType.hh" | ||
#include "ComponentInspector.hh" | ||
#include "Types.hh" | ||
|
||
using namespace ignition; | ||
using namespace gazebo; | ||
|
||
///////////////////////////////////////////////// | ||
JointType::JointType(ComponentInspector *_inspector) | ||
{ | ||
_inspector->Context()->setContextProperty("JointTypeImpl", this); | ||
this->inspector = _inspector; | ||
|
||
ComponentCreator creator = | ||
[=](EntityComponentManager &_ecm, Entity _entity, QStandardItem *_item) | ||
{ | ||
auto comp = _ecm.Component<components::JointType>(_entity); | ||
if (nullptr == _item || nullptr == comp) | ||
return; | ||
|
||
const sdf::JointType joint = comp->Data(); | ||
|
||
_item->setData(QString("JointType"), | ||
ComponentsModel::RoleNames().key("dataType")); | ||
|
||
QString jointType; | ||
if (joint == sdf::JointType::BALL) | ||
jointType = "Ball"; | ||
else if (joint == sdf::JointType::CONTINUOUS) | ||
jointType = "Continuous"; | ||
else if (joint == sdf::JointType::FIXED) | ||
jointType = "Fixed"; | ||
else if (joint == sdf::JointType::GEARBOX) | ||
jointType = "Gearbox"; | ||
else if (joint == sdf::JointType::PRISMATIC) | ||
jointType = "Prismatic"; | ||
else if (joint == sdf::JointType::REVOLUTE) | ||
jointType = "Revolute"; | ||
else if (joint == sdf::JointType::REVOLUTE2) | ||
jointType = "Revolute2"; | ||
else if (joint == sdf::JointType::SCREW) | ||
jointType = "Screw"; | ||
else if (joint == sdf::JointType::UNIVERSAL) | ||
jointType = "Universal"; | ||
|
||
_item->setData(jointType, ComponentsModel::RoleNames().key("data")); | ||
}; | ||
|
||
this->inspector->RegisterComponentCreator( | ||
components::JointType::typeId, creator); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
Q_INVOKABLE void JointType::OnJointType(QString _jointType) | ||
{ | ||
ignition::gazebo::UpdateCallback cb = | ||
[=](EntityComponentManager &_ecm) | ||
{ | ||
components::JointType *comp = | ||
_ecm.Component<components::JointType>(this->inspector->Entity()); | ||
|
||
components::ParentEntity *parentComp = | ||
_ecm.Component<components::ParentEntity>(this->inspector->Entity()); | ||
|
||
if (comp && parentComp) | ||
{ | ||
if (_jointType == "Ball") | ||
comp->Data() = sdf::JointType::BALL; | ||
else if (_jointType == "Continuous") | ||
comp->Data() = sdf::JointType::CONTINUOUS; | ||
else if (_jointType == "Fixed") | ||
comp->Data() = sdf::JointType::FIXED; | ||
else if (_jointType == "Gearbox") | ||
comp->Data() = sdf::JointType::GEARBOX; | ||
else if (_jointType == "Prismatic") | ||
comp->Data() = sdf::JointType::PRISMATIC; | ||
else if (_jointType == "Revolute") | ||
comp->Data() = sdf::JointType::REVOLUTE; | ||
else if (_jointType == "Revolute2") | ||
comp->Data() = sdf::JointType::REVOLUTE2; | ||
else if (_jointType == "Screw") | ||
comp->Data() = sdf::JointType::SCREW; | ||
else if (_jointType == "Universal") | ||
comp->Data() = sdf::JointType::UNIVERSAL; | ||
|
||
// Make sure to mark the parent as needing recreation. This will | ||
// tell the server to rebuild the model with the new link. | ||
_ecm.CreateComponent(parentComp->Data(), components::Recreate()); | ||
} | ||
else if (!comp) | ||
{ | ||
ignerr << "Unable to get the joint type component.\n"; | ||
} | ||
else | ||
{ | ||
ignerr << "Unable to get the joint's parent entity component.\n"; | ||
} | ||
}; | ||
this->inspector->AddUpdateCallback(cb); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
#ifndef IGNITION_GAZEBO_GUI_COMPONENTINSPECTOR_JOINT_HH_ | ||
#define IGNITION_GAZEBO_GUI_COMPONENTINSPECTOR_JOINT_HH_ | ||
|
||
#include <ignition/gazebo/gui/GuiSystem.hh> | ||
|
||
namespace ignition | ||
{ | ||
namespace gazebo | ||
{ | ||
class ComponentInspector; | ||
|
||
/// \brief A class that handles joint changes. | ||
class JointType : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
/// \brief Constructor | ||
/// \param[in] _inspector The component inspector. | ||
public: explicit JointType(ComponentInspector *_inspector); | ||
|
||
/// \brief Callback in Qt thread when joint type changes. | ||
/// \param[in] _surface Surface model | ||
public: Q_INVOKABLE void OnJointType(QString _jointType); | ||
|
||
/// \brief Pointer to the component inspector. This is used to add | ||
/// update callbacks that modify the ECM. | ||
private: ComponentInspector *inspector{nullptr}; | ||
}; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
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 | ||
import QtQuick.Controls.Styles 1.4 | ||
import "qrc:/ComponentInspector" | ||
import "qrc:/qml" | ||
|
||
// Item displaying joint type information. | ||
Rectangle { | ||
id: jointTypeComponent | ||
height: jointType.height | ||
width: componentInspector.width | ||
color: index % 2 == 0 ? lightGrey : darkGrey | ||
|
||
// Left indentation | ||
property int indentation: 10 | ||
|
||
// Horizontal margins | ||
property int margin: 5 | ||
|
||
ListModel { | ||
id: jointTypes | ||
ListElement { type: "Ball" } | ||
ListElement { type: "Continuous" } | ||
ListElement { type: "Fixed" } | ||
ListElement { type: "Gearbox" } | ||
ListElement { type: "Prismatic" } | ||
ListElement { type: "Revolute" } | ||
ListElement { type: "Revolute2" } | ||
ListElement { type: "Screw" } | ||
ListElement { type: "Universal" } | ||
} | ||
|
||
function indexFromModel(_model) { | ||
if (_model && _model.data !== undefined) | ||
{ | ||
for (var i = 0; i < jointTypes.count; i++) | ||
{ | ||
if (jointTypes.get(i).type === _model.data) | ||
{ | ||
return i | ||
} | ||
} | ||
} | ||
return -1 | ||
} | ||
|
||
FontMetrics { | ||
id: fontMetrics | ||
font.family: "Roboto" | ||
} | ||
|
||
RowLayout { | ||
anchors.fill: parent | ||
|
||
Item { | ||
height: parent.height | ||
width: margin + indentation | ||
} | ||
|
||
TypeHeader { | ||
id: typeHeader | ||
} | ||
|
||
QtObject{ | ||
// Workaround to keep from using the ListModel as model | ||
id: indexObj | ||
property int index: indexFromModel(model) | ||
} | ||
|
||
ComboBox { | ||
id: jointType | ||
padding: 0 | ||
textRole: "type" | ||
model: jointTypes | ||
currentIndex: indexObj.index | ||
Layout.alignment: Qt.AlignRight | ||
background: Rectangle { | ||
color: "transparent" | ||
implicitWidth: 140 | ||
border.width: 1 | ||
border.color: "#dedede" | ||
} | ||
enabled: componentInspector.getSimPaused() | ||
onActivated: { | ||
JointTypeImpl.OnJointType(currentText) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters