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

Grid config: set values from startup and improve layout #324

Merged
merged 12 commits into from
Dec 8, 2021
36 changes: 36 additions & 0 deletions examples/config/grid_config.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>

<plugin filename="MinimalScene">
<ignition-gui>
<title>View 1</title>
<property type="string" key="state">docked</property>
</ignition-gui>
<engine>ogre2</engine>
<scene>scene</scene>
<ambient_light>1 1 1</ambient_light>
<background_color>0.8 0.8 0.8</background_color>
<camera_pose>-6 3 6 0 0.5 0</camera_pose>
</plugin>
<plugin filename="InteractiveViewControl" name="Interactive view control">
<ignition-gui>
<anchors target="View 1">
<line own="right" target="right"/>
<line own="top" target="top"/>
</anchors>
<property key="resizable" type="bool">false</property>
<property key="width" type="double">5</property>
<property key="height" type="double">5</property>
<property key="state" type="string">floating</property>
<property key="showTitleBar" type="bool">false</property>
</ignition-gui>
</plugin>
<plugin filename="GridConfig" name="Grid config">
<ignition-gui>
<property type="string" key="state">docked</property>
</ignition-gui>
<cell_count>3</cell_count>
<vertical_cell_count>2</vertical_cell_count>
<cell_length>2</cell_length>
<pose>1 2 3 0 0 0</pose>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<pose>1 2 3 0 0 0</pose>
<pose>1 2 3 0 0 0</pose>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to get in the habit of separating position and rotation with an extra space as suggested on Specifying pose: Proposal for a better pose:

libsdformat and SDFormat tutorials should encourage additional whitespace, e.g. to separate translation and rotation, use 3 spaces (instead of 1) as a delimiter between values if they fit on one line, or use a newline (possibly with hanging indents) if they do not fit on one line.

<color>1 0 0 1</color>
</plugin>
80 changes: 44 additions & 36 deletions src/plugins/grid_config/GridConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
*
*/

#include <string>

#include <ignition/common/Console.hh>
#include <ignition/gui/Application.hh>
#include <ignition/gui/Conversions.hh>
#include <ignition/gui/GuiEvents.hh>
#include <ignition/gui/MainWindow.hh>
#include <ignition/plugin/Register.hh>
Expand Down Expand Up @@ -75,11 +78,49 @@ GridConfig::GridConfig()
GridConfig::~GridConfig() = default;

/////////////////////////////////////////////////
void GridConfig::LoadConfig(const tinyxml2::XMLElement *)
void GridConfig::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
{
if (this->title.empty())
this->title = "Grid config";

// Configuration
if (_pluginElem)
{
// For grid to be configured at startup
if (auto cellCountElem = _pluginElem->FirstChildElement("cell_count"))
cellCountElem->QueryIntText(&this->dataPtr->gridParam.hCellCount);

if (auto vElem = _pluginElem->FirstChildElement("vertical_cell_count"))
vElem->QueryIntText(&this->dataPtr->gridParam.vCellCount);

if (auto lengthElem = _pluginElem->FirstChildElement("cell_length"))
lengthElem->QueryDoubleText(&this->dataPtr->gridParam.cellLength);

auto elem = _pluginElem->FirstChildElement("pose");
if (nullptr != elem && nullptr != elem->GetText())
{
std::stringstream poseStr;
poseStr << std::string(elem->GetText());
poseStr >> this->dataPtr->gridParam.pose;
}

elem = _pluginElem->FirstChildElement("color");
if (nullptr != elem && nullptr != elem->GetText())
{
std::stringstream colorStr;
colorStr << std::string(elem->GetText());
colorStr >> this->dataPtr->gridParam.color;
}
this->newParams(
this->dataPtr->gridParam.hCellCount,
this->dataPtr->gridParam.vCellCount,
this->dataPtr->gridParam.cellLength,
convert(this->dataPtr->gridParam.pose.Pos()),
convert(this->dataPtr->gridParam.pose.Rot().Euler()),
convert(this->dataPtr->gridParam.color));
this->dataPtr->dirty = true;
}

ignition::gui::App()->findChild<
ignition::gui::MainWindow *>()->installEventFilter(this);
}
Expand Down Expand Up @@ -149,42 +190,9 @@ void GridConfig::UpdateGrid()
/////////////////////////////////////////////////
void GridConfig::LoadGrid()
{
auto loadedEngNames = rendering::loadedEngines();
if (loadedEngNames.empty())
return;

// assume there is only one engine loaded
auto engineName = loadedEngNames[0];
if (loadedEngNames.size() > 1)
{
igndbg << "More than one engine is available. "
<< "Grid config plugin will use engine ["
<< engineName << "]" << std::endl;
}
auto engine = rendering::engine(engineName);
if (!engine)
{
ignerr << "Internal error: failed to load engine [" << engineName
<< "]. Grid plugin won't work." << std::endl;
return;
}

if (engine->SceneCount() == 0)
return;

// assume there is only one scene
// load scene
auto scene = engine->SceneByIndex(0);
if (!scene)
{
ignerr << "Internal error: scene is null." << std::endl;
auto scene = rendering::sceneFromFirstRenderEngine();
if (nullptr == scene)
return;
}

if (!scene->IsInitialized() || nullptr == scene->RootVisual())
{
return;
}

// load grid
// if gridPtr found, load the existing gridPtr to class
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/grid_config/GridConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ namespace gui
/// \param[in] _checked indicates show or hide grid
public slots: void OnShow(bool _checked);

/// \brief Notify QML that grid values have changed.
/// \param[in] _hCellCount Horizontal cell count
/// \param[in] _vCellCount Vertical cell count
/// \param[in] _cellLength Cell length
/// \param[in] _pos XYZ Position
/// \param[in] _rot RPY orientation
/// \param[in] _color Grid color
signals: void newParams(
int _hCellCount,
int _vCellCount,
double _cellLength,
QVector3D _pos,
QVector3D _rot,
QColor _color);

/// \internal
/// \brief Pointer to private data.
private: std::unique_ptr<GridConfigPrivate> dataPtr;
Expand Down
Loading