Skip to content

Commit

Permalink
Add configurable SDF/URDF path resolution settings, including prefix …
Browse files Browse the repository at this point in the history
…remappings (o3de#505)

* First version of adding configurable prefix lookups and substitutions.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Tests/UrdfParserTest.cpp

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Source/SdfAssetBuilder/SdfAssetBuilderSettings.h

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Improved asset path resolution logic and unit tests.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Add SDFormat importer hooks (o3de#453)

Add sensors SDF importer hooks

Signed-off-by: Jan Hanca <jan.hanca@robotec.ai>

* use PrimitiveAssets Gem to visualize primitives (o3de#485)

Use PrimitiveAssets Gem to visualize primitives

---------

Signed-off-by: Jan Hanca <jan.hanca@robotec.ai>

* Warehouse automation gem (o3de#440)

Created the warehouse automation gem, adjusted to review

---------

Signed-off-by: Antoni Puch <antoni.puch@robotec.ai>

* Lidar component refactor (o3de#463)

Lidar Refactor

---------

Signed-off-by: Antoni Puch <antoni.puch@robotec.ai>
Signed-off-by: Antoni-Robotec <138497503+Antoni-Robotec@users.noreply.github.com>
Co-authored-by: Adam Dąbrowski <adam.dabrowski@robotec.ai>

* Added presentation of SDF messages (o3de#491)

* Added presentation of SDF messages

---------
Signed-off-by: Michał Pełka <michalpelka@gmail.com>
Co-authored-by: Jan Hanca <134940295+jhanca-robotecai@users.noreply.github.com>

* Fix missing include.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Fix resolution of file:// prefix.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Change string to Path.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Changed PathResolver to get read in wholesale from setreg file.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* PR feedback - changed file select dir to default to last-used file.
Also changes file select dir to match anything typed into the text box.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Source/RobotImporter/Utils/RobotImporterUtils.h

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Source/RobotImporter/Utils/RobotImporterUtils.cpp

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Source/RobotImporter/Utils/RobotImporterUtils.cpp

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Source/RobotImporter/Utils/RobotImporterUtils.cpp

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Update Gems/ROS2/Code/Source/RobotImporter/Utils/RobotImporterUtils.cpp

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* PR feedback
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* PR feedback

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Partial revert from path back to string.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Second half of path to string revert.
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Added all Path Resolver options to setreg for visibility.
Improved SetFindCallback to use the full set of path resolution options.
Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

---------

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
Signed-off-by: Jan Hanca <jan.hanca@robotec.ai>
Signed-off-by: Antoni Puch <antoni.puch@robotec.ai>
Signed-off-by: Antoni-Robotec <138497503+Antoni-Robotec@users.noreply.github.com>
Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Co-authored-by: Jan Hanca <134940295+jhanca-robotecai@users.noreply.github.com>
Co-authored-by: Antoni-Robotec <138497503+Antoni-Robotec@users.noreply.github.com>
Co-authored-by: Adam Dąbrowski <adam.dabrowski@robotec.ai>
Co-authored-by: Michał Pełka <michal.pelka@robotec.ai>
  • Loading branch information
6 people committed Sep 25, 2023
1 parent 71e9ba1 commit 4150b02
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 199 deletions.
43 changes: 40 additions & 3 deletions Gems/ROS2/Code/Source/RobotImporter/Pages/FileSelectionPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@
#include <QFileInfo>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSettings>

namespace ROS2
{
static constexpr const char FileSelectionPageDefaultFile[] = "RobotImporter/SelectFileDefaultFile";

FileSelectionPage::FileSelectionPage(QWizard* parent)
: QWizardPage(parent)
, m_sdfAssetBuilderSettings(AZStd::make_unique<SdfAssetBuilderSettings>())
{
m_fileDialog = new QFileDialog(this);
m_fileDialog->setDirectory(QString::fromUtf8(AZ::Utils::GetProjectPath().data()));
m_fileDialog->setNameFilter("URDF, XACRO, SDF, WORLD (*.urdf *.xacro *.sdf *.world)");
// Whenever the selected file is successfully changed via the File Dialog or the Text Edit widget,
// save the full file name with path into the QSettings so that it defaults correctly the next time it is opened.
connect(this, &QWizardPage::completeChanged, [this]()
{
if (m_fileExists)
{
QSettings settings;
const QString absolutePath = m_textEdit->text();
settings.setValue(FileSelectionPageDefaultFile, absolutePath);
}
});

m_button = new QPushButton("...", this);
m_textEdit = new QLineEdit("", this);
setTitle(tr("Load URDF/SDF file"));
Expand All @@ -46,8 +60,6 @@ namespace ROS2
m_sdfAssetBuilderSettingsEditor->Setup(serializeContext, nullptr, enableScrollBars);
m_sdfAssetBuilderSettingsEditor->AddInstance(m_sdfAssetBuilderSettings.get());
m_sdfAssetBuilderSettingsEditor->InvalidateAll();
// Make sure the SDF Asset Builder settings are expanded by default
m_sdfAssetBuilderSettingsEditor->ExpandAll();
layout->addWidget(m_sdfAssetBuilderSettingsEditor);

this->setLayout(layout);
Expand All @@ -59,8 +71,33 @@ namespace ROS2

FileSelectionPage::~FileSelectionPage() = default;

void FileSelectionPage::RefreshDefaultPath()
{
// The first time this dialog ever gets opened, default to the project's root directory.
// Once a URDF/SDF file has been selected or typed in, change the default directory to the location of that file.
// This gets stored in QSettings, so it will persist between Editor runs.
QSettings settings;
QString defaultFile(settings.value(FileSelectionPageDefaultFile).toString());
if (!defaultFile.isEmpty() && QFile(defaultFile).exists())
{
// Set both the default directory and the default file in that directory.
m_fileDialog->setDirectory(QFileInfo(defaultFile).absolutePath());
m_fileDialog->selectFile(QFileInfo(defaultFile).fileName());
}
else
{
// No valid file was found, so default back to the current project path.
m_fileDialog->setDirectory(QString::fromUtf8(AZ::Utils::GetProjectPath().c_str()));
m_fileDialog->selectFile("");
}
}

void FileSelectionPage::onLoadButtonPressed()
{
// Refresh the default path in the file dialog every time it is opened so that
// any changes in the text edit box are reflected in its default path and any Cancel
// pressed to escape from the file dialog *don't* change its default path.
RefreshDefaultPath();
m_fileDialog->show();
}

Expand Down
4 changes: 4 additions & 0 deletions Gems/ROS2/Code/Source/RobotImporter/Pages/FileSelectionPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ namespace ROS2

void onEditingFinished();

//! Refresh the default path in the file dialog based either on what was previously selected
//! or what was entered in on the text edit line.
void RefreshDefaultPath();

bool m_fileExists{ false };
};
} // namespace ROS2
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ namespace ROS2
// Read the SDF Settings from the Settings Registry into a local struct
SdfAssetBuilderSettings sdfBuilderSettings;
sdfBuilderSettings.LoadSettings();
// Set the parser config settings for SDF content
sdf::ParserConfig parserConfig;
parserConfig.URDFSetPreserveFixedJoint(sdfBuilderSettings.m_urdfPreserveFixedJoints);
// Set the parser config settings for URDF content
sdf::ParserConfig parserConfig = Utils::SDFormat::CreateSdfParserConfigFromSettings(sdfBuilderSettings, filePath);

auto parsedSdfOutcome = UrdfParser::ParseFromFile(filePath, parserConfig, sdfBuilderSettings);
if (!parsedSdfOutcome)
Expand All @@ -124,7 +123,7 @@ namespace ROS2
if (importAssetWithUrdf)
{
urdfAssetsMapping = AZStd::make_shared<Utils::UrdfAssetMap>(
Utils::CopyAssetForURDFAndCreateAssetMap(meshNames, filePath, collidersNames, visualNames));
Utils::CopyAssetForURDFAndCreateAssetMap(meshNames, filePath, collidersNames, visualNames, sdfBuilderSettings));
}
bool allAssetProcessed = false;
bool assetProcessorFailed = false;
Expand Down
10 changes: 6 additions & 4 deletions Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ namespace ROS2
const SdfAssetBuilderSettings& sdfBuilderSettings = m_fileSelectPage->GetSdfAssetBuilderSettings();

// Set the parser config settings for URDF content
sdf::ParserConfig parserConfig;
parserConfig.URDFSetPreserveFixedJoint(sdfBuilderSettings.m_urdfPreserveFixedJoints);
sdf::ParserConfig parserConfig = Utils::SDFormat::CreateSdfParserConfigFromSettings(sdfBuilderSettings, m_urdfPath);

if (Utils::IsFileXacro(m_urdfPath))
{
Expand Down Expand Up @@ -240,14 +239,17 @@ namespace ROS2
dirSuffix = paramsUuid.ToFixedString();
}

// Read the SDF Settings from PrefabMakerPage
const SdfAssetBuilderSettings& sdfBuilderSettings = m_fileSelectPage->GetSdfAssetBuilderSettings();

if (m_importAssetWithUrdf)
{
m_urdfAssetsMapping = AZStd::make_shared<Utils::UrdfAssetMap>(
Utils::CopyAssetForURDFAndCreateAssetMap(m_meshNames, m_urdfPath.String(), collidersNames, visualNames, dirSuffix));
Utils::CopyAssetForURDFAndCreateAssetMap(m_meshNames, m_urdfPath.String(), collidersNames, visualNames, sdfBuilderSettings, dirSuffix));
}
else
{
m_urdfAssetsMapping = AZStd::make_shared<Utils::UrdfAssetMap>(Utils::FindAssetsForUrdf(m_meshNames, m_urdfPath.String()));
m_urdfAssetsMapping = AZStd::make_shared<Utils::UrdfAssetMap>(Utils::FindAssetsForUrdf(m_meshNames, m_urdfPath.String(), sdfBuilderSettings));
for (const AZStd::string& meshPath : m_meshNames)
{
if (m_urdfAssetsMapping->contains(meshPath))
Expand Down
Loading

0 comments on commit 4150b02

Please sign in to comment.