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

Added add entity action for the box through graphical interface #26

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions src/core/simulator/query_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,42 @@ namespace argos {
/****************************************/
/****************************************/

/**
* Get the plug-ins for a certain query in the vector.
* Clears the vector.
* @param str_query The given query to be searched.
* @param vec_plugins The vector in which the results will be added.
*/
void GetPlugins(const std::string& str_query, std::vector<std::string>& vec_plugins)
{
/* Clear contents of vector */
vec_plugins.clear();
/* Add all plug-ins to the vector */
if(str_query == "actuators") {
GetQueryList<CSimulatedActuator>(vec_plugins);
} else if(str_query == "sensors") {
GetQueryList<CSimulatedSensor>(vec_plugins);
} else if(str_query == "physics_engines") {
GetQueryList<CPhysicsEngine>(vec_plugins);
} else if(str_query == "media") {
GetQueryList<CMedium>(vec_plugins);
} else if(str_query == "visualizations") {
GetQueryList<CVisualization>(vec_plugins);
} else if(str_query == "entities") {
GetQueryList<CEntity>(vec_plugins);
} else if(str_query == "all") {
GetQueryList<CSimulatedActuator>(vec_plugins);
GetQueryList<CSimulatedSensor> (vec_plugins);
GetQueryList<CPhysicsEngine> (vec_plugins);
GetQueryList<CMedium> (vec_plugins);
GetQueryList<CVisualization> (vec_plugins);
GetQueryList<CEntity> (vec_plugins);
} else {
QueryShowPluginDescription(str_query);
}
}

/****************************************/
/****************************************/

}
29 changes: 29 additions & 0 deletions src/core/simulator/query_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ namespace argos {
/****************************************/
/****************************************/

/**
* Query the plug-ins and get the results in a vector.
* Clears the vector.
* @param str_query The query.
* @param vec_plugins The vector to which the results will be added.
*/
void GetPlugins(const std::string& str_query,
std::vector<std::string>& vec_plugins);

/****************************************/
/****************************************/

/**
* Get the type map for the class in a vector.
* @param vec_queries The vector to which the type map will be added.
*/
template <class TYPE>
void GetQueryList(std::vector<std::string>& vec_queries) {
typename CFactory<TYPE>::TTypeMap& tTypeMap = CFactory<TYPE>::GetTypeMap();
for(typename CFactory<TYPE>::TTypeMap::iterator it = tTypeMap.begin();
it != tTypeMap.end();
++it) {
vec_queries.push_back(it->first);
}
}

/****************************************/
/****************************************/

}

#endif
Expand Down
13 changes: 13 additions & 0 deletions src/core/simulator/simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ namespace argos {
}
return *(it->second);
}

/****************************************/
/****************************************/

std::vector<std::string> CSimulator::GetControllerIds() const{
std::vector<std::string> vecControllerIds;
for(TControllerConfigurationMap::const_iterator it = m_mapControllerConfig.begin();
it != m_mapControllerConfig.end();
++it) {
vecControllerIds.push_back(it->first);
}
return vecControllerIds;
}

/****************************************/
/****************************************/
Expand Down
6 changes: 6 additions & 0 deletions src/core/simulator/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ namespace argos {
*/
TConfigurationNode& GetConfigForController(const std::string& str_id);

/**
* Creates and returns a vector of strings containing all the available controller ids.
* @return A vector of strings containing all the available controller ids.
*/
std::vector<std::string> GetControllerIds() const;

/**
* Loads an already-parsed XML configuration tree.
* The tree should have the same structure as an ARGoS file.
Expand Down
40 changes: 40 additions & 0 deletions src/core/utility/datatypes/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,46 @@ namespace argos {
}
}

/**
* Gets one of the predefined colors from a string.
* The input string can contain predefined color names, such as <tt>red</tt>.
* @param str_color The input string specifying the color name.
*/
static CColor GetColor(const std::string& str_color) {
if (str_color == "black") return CColor::BLACK;
else if (str_color == "white") return CColor::WHITE;
else if (str_color == "red") return CColor::RED;
else if (str_color == "green") return CColor::GREEN;
else if (str_color == "blue") return CColor::BLUE;
else if (str_color == "magenta") return CColor::MAGENTA;
else if (str_color == "cyan") return CColor::CYAN;
else if (str_color == "yellow") return CColor::YELLOW;
else if (str_color == "orange") return CColor::ORANGE;
else if (str_color == "brown") return CColor::BROWN;
else if (str_color == "purple") return CColor::PURPLE;
else if (str_color == "gray10") return CColor::GRAY10;
else if (str_color == "gray20") return CColor::GRAY20;
else if (str_color == "gray30") return CColor::GRAY30;
else if (str_color == "gray40") return CColor::GRAY40;
else if (str_color == "gray50") return CColor::GRAY50;
else if (str_color == "gray60") return CColor::GRAY60;
else if (str_color == "gray70") return CColor::GRAY70;
else if (str_color == "gray80") return CColor::GRAY80;
else if (str_color == "gray90") return CColor::GRAY90;
else return CColor::WHITE;
}

/**
* Creates and returns a vector containing all the predefined colors.
* @returns All the predefined colors as a vector of strings.
*/
static inline std::vector<std::string> GetDefaultColors(){
static const char* pnColors[] = {"yellow", "red", "green", "blue", "magenta",
"cyan", "orange", "brown", "purple", "black", "white", "gray10", "gray20",
"gray30", "gray40", "gray50", "gray60", "gray70", "gray80", "gray90"};
return std::vector<std::string>(pnColors , pnColors+20);
}

/**
* Cast operator.
* Casts the color into a 32-bit structure.
Expand Down
39 changes: 39 additions & 0 deletions src/plugins/simulator/visualizations/qt-opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,34 @@ set(ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL_MODELS
models/qtopengl_box.h
models/qtopengl_cylinder.h
models/qtopengl_light.h)
# argos3/plugins/simulator/visualizations/qt-opengl/dialogs/layouts
set(ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL_DIALOGS_LAYOUTS
dialogs/layouts/qtopengl_entity_dialog_layout.h
dialogs/layouts/qtopengl_embodied_entity_dialog_layout.h
dialogs/layouts/qtopengl_box_entity_dialog_layout.h
dialogs/layouts/qtopengl_cylinder_entity_dialog_layout.h
dialogs/layouts/qtopengl_light_entity_dialog_layout.h
dialogs/layouts/qtopengl_bot_entity_dialog_layout.h
dialogs/layouts/qtopengl_epuck_entity_dialog_layout.h
dialogs/layouts/qtopengl_eyebot_entity_dialog_layout.h
dialogs/layouts/qtopengl_footbot_entity_dialog_layout.h
dialogs/layouts/qtopengl_spiri_entity_dialog_layout.h)
# argos3/plugins/simulator/visualizations/qt-opengl/dialogs
set(ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL_DIALOGS
dialogs/qtopengl_add_entity_dialog.h)
# argos3/plugins/simulator/visualizations/qt-opengl
set(ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL
dialogs/layouts/qtopengl_entity_dialog_layout.h
dialogs/layouts/qtopengl_embodied_entity_dialog_layout.h
dialogs/layouts/qtopengl_box_entity_dialog_layout.h
dialogs/layouts/qtopengl_cylinder_entity_dialog_layout.h
dialogs/layouts/qtopengl_light_entity_dialog_layout.h
dialogs/layouts/qtopengl_bot_entity_dialog_layout.h
dialogs/layouts/qtopengl_epuck_entity_dialog_layout.h
dialogs/layouts/qtopengl_eyebot_entity_dialog_layout.h
dialogs/layouts/qtopengl_footbot_entity_dialog_layout.h
dialogs/layouts/qtopengl_spiri_entity_dialog_layout.h
dialogs/qtopengl_add_entity_dialog.h
qtopengl_application.h
qtopengl_camera.h
qtopengl_log_stream.h
Expand Down Expand Up @@ -36,6 +62,17 @@ set(ARGOS3_SOURCES_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL
models/qtopengl_box.cpp
models/qtopengl_cylinder.cpp
models/qtopengl_light.cpp
dialogs/layouts/qtopengl_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_embodied_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_box_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_cylinder_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_light_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_bot_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_epuck_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_eyebot_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_footbot_entity_dialog_layout.cpp
dialogs/layouts/qtopengl_spiri_entity_dialog_layout.cpp
dialogs/qtopengl_add_entity_dialog.cpp
qtopengl_application.cpp
qtopengl_camera.cpp
qtopengl_main_window.cpp
Expand Down Expand Up @@ -66,6 +103,8 @@ target_link_libraries(argos3plugin_${ARGOS_BUILD_FOR}_qtopengl argos3plugin_${AR

install(DIRECTORY icons textures DESTINATION include/argos3/plugins/simulator/visualizations/qt-opengl)
install(FILES ${ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL_MODELS} DESTINATION include/argos3/plugins/simulator/visualizations/qt-opengl/models)
install(FILES ${ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL_DIALOGS_LAYOUTS} DESTINATION include/argos3/plugins/simulator/visualizations/qt-opengl/dialogs/layouts)
install(FILES ${ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL_DIALOGS} DESTINATION include/argos3/plugins/simulator/visualizations/qt-opengl/dialogs)
install(FILES ${ARGOS3_HEADERS_PLUGINS_SIMULATOR_VISUALIZATIONS_QTOPENGL} DESTINATION include/argos3/plugins/simulator/visualizations/qt-opengl)
install(TARGETS argos3plugin_${ARGOS_BUILD_FOR}_qtopengl
RUNTIME DESTINATION bin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @file <argos3/plugins/simulator/visualizations/qt-opengl/dialogs/layouts/qtopengl_bot_entity_dialog_layout.cpp>
*
* @author Ewout Merckx - <[email protected]>
*/

#include "qtopengl_bot_entity_dialog_layout.h"

#include <QGroupBox>
#include <QLabel>
#include <QStringList>

namespace argos {

/****************************************/
/****************************************/

CQTOpenGLBotEntityDialogLayout::CQTOpenGLBotEntityDialogLayout(QWidget* pc_parent_widget)
: CQTOpenGLEmbodiedEntityDialogLayout(pc_parent_widget)
{
this->Init();
}

/****************************************/
/****************************************/

void CQTOpenGLBotEntityDialogLayout::Init()
{
// initialize controller id input field
m_pcEnityControllerIdComboBox = new QComboBox;
std::vector<std::string> vecControllerIds = CSimulator::GetInstance().GetControllerIds();
QStringList cControllerIdsStringList;
for(size_t i=0; i<vecControllerIds.size(); i++) {
cControllerIdsStringList.append(vecControllerIds[i].c_str());
}
m_pcEnityControllerIdComboBox->addItems(cControllerIdsStringList);

// add controller id input fields to group box
QGroupBox* pcEntityControllerIdGroupBox = new QGroupBox(tr("Controller id*"));
QHBoxLayout *pcEntityControllerIdGroupBoxLayout = new QHBoxLayout;
pcEntityControllerIdGroupBoxLayout->addWidget(m_pcEnityControllerIdComboBox);
pcEntityControllerIdGroupBox->setLayout(pcEntityControllerIdGroupBoxLayout);

// add group box to layout
this->insertWidget(0, pcEntityControllerIdGroupBox);
}

/****************************************/
/****************************************/

void CQTOpenGLBotEntityDialogLayout::CheckInput()
{
CQTOpenGLEmbodiedEntityDialogLayout::CheckInput();

// check controller id
if(this->GetControllerId() == "") {
THROW_ARGOSEXCEPTION("Please define a controller for the entity.");
}
}

/****************************************/
/****************************************/

CEntity& CQTOpenGLBotEntityDialogLayout::GetEntity()
{
THROW_ARGOSEXCEPTION("In CQTOpenGLBotEntityDialogLayout::GetEntity(), "
<< "there is no entity to get.");
}

/****************************************/
/****************************************/

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file <argos3/plugins/simulator/visualizations/qt-opengl/dialogs/layouts/qtopengl_bot_entity_dialog_layout.h>
*
* @author Ewout Merckx - <[email protected]>
*/

#ifndef QTOPENGL_BOT_ENTITY_DIALOG_LAYOUT
#define QTOPENGL_BOT_ENTITY_DIALOG_LAYOUT

namespace argos {
class CQTOpenGLBotEntityDialogLayout;
}

#include <argos3/plugins/simulator/visualizations/qt-opengl/dialogs/layouts/qtopengl_embodied_entity_dialog_layout.h>

#include <argos3/core/simulator/simulator.h>

#include <QComboBox>

namespace argos {

class CQTOpenGLBotEntityDialogLayout : public CQTOpenGLEmbodiedEntityDialogLayout {

Q_OBJECT

public:

/**
* Constructor.
* @param pc_parent_widget The pointer to the parent widget
*/
CQTOpenGLBotEntityDialogLayout(QWidget* pc_parent_widget = 0);

/**
* Creates and returns the entity using the specified values
* @returns The entity using the specified values
*/
virtual CEntity& GetEntity();

/**
* Getter for the controller id
* @returns The controller id specified in the combo box
*/
inline std::string GetControllerId() const
{
return m_pcEnityControllerIdComboBox->currentText().toStdString();
}

protected:

/**
* Validates the filled in values
*/
virtual void CheckInput();

private:

/**
* Initializes the layout
*/
virtual void Init();

public slots:

private:
QComboBox* m_pcEnityControllerIdComboBox;

};
}

#endif
Loading