Skip to content

Commit

Permalink
Robot: Apply clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Sep 11, 2023
1 parent 3acb817 commit 4bc2b1b
Show file tree
Hide file tree
Showing 47 changed files with 1,599 additions and 1,270 deletions.
18 changes: 11 additions & 7 deletions src/Mod/Robot/Gui/AppRobotGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ void loadRobotResource()
Gui::Translator::instance()->refresh();
}

namespace RobotGui {
class Module : public Py::ExtensionModule<Module>
namespace RobotGui
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("RobotGui")
Module()
: Py::ExtensionModule<Module>("RobotGui")
{
initialize("This module is the RobotGui module."); // register with Python
initialize("This module is the RobotGui module.");// register with Python
}

private:
Expand All @@ -67,7 +69,7 @@ PyObject* initModule()
return Base::Interpreter().addModule(new Module);
}

} // namespace RobotGui
}// namespace RobotGui


/* Python entry */
Expand All @@ -93,7 +95,7 @@ PyMOD_INIT_FUNC(RobotGui)
// default displacement while e.g. picking
Base::Interpreter().runString("_DefDisplacement = FreeCAD.Vector(0,0,0)");
}
catch(const Base::Exception& e) {
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
PyMOD_Return(nullptr);
}
Expand All @@ -106,15 +108,17 @@ PyMOD_INIT_FUNC(RobotGui)
CreateRobotCommandsInsertRobots();
CreateRobotCommandsTrajectory();

// clang-format off
// addition objects
RobotGui::Workbench ::init();
RobotGui::ViewProviderRobotObject ::init();
RobotGui::ViewProviderTrajectory ::init();
RobotGui::ViewProviderEdge2TracObject ::init();
RobotGui::ViewProviderTrajectoryCompound ::init();
RobotGui::ViewProviderTrajectoryDressUp ::init();
// clang-format on

// add resources and reloads the translators
// add resources and reloads the translators
loadRobotResource();

PyMOD_Return(mod);
Expand Down
190 changes: 105 additions & 85 deletions src/Mod/Robot/Gui/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
#include <QMessageBox>
#endif

#include <Gui/Application.h>
Expand All @@ -45,31 +45,31 @@ using namespace RobotGui;
DEF_STD_CMD_A(CmdRobotSetHomePos)

CmdRobotSetHomePos::CmdRobotSetHomePos()
:Command("Robot_SetHomePos")
: Command("Robot_SetHomePos")
{
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Set the home position");
sToolTipText = QT_TR_NOOP("Set the home position");
sWhatsThis = "Robot_SetHomePos";
sStatusTip = sToolTipText;
sPixmap = "Robot_SetHomePos";
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Set the home position");
sToolTipText = QT_TR_NOOP("Set the home position");
sWhatsThis = "Robot_SetHomePos";
sStatusTip = sToolTipText;
sPixmap = "Robot_SetHomePos";
}


void CmdRobotSetHomePos::activated(int)
{
const char * SelFilter =
"SELECT Robot::RobotObject COUNT 1 ";
const char* SelFilter = "SELECT Robot::RobotObject COUNT 1 ";

Gui::SelectionFilter filter(SelFilter);
Robot::RobotObject *pcRobotObject;
Robot::RobotObject* pcRobotObject;
if (filter.match()) {
pcRobotObject = static_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
}
else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one Robot to set home position"));
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select one Robot to set home position"));
return;
}

Expand All @@ -78,10 +78,20 @@ void CmdRobotSetHomePos::activated(int)

const char* n = FeatName.c_str();
openCommand("Set home");
doCommand(Doc,"App.activeDocument().%s.Home = [App.activeDocument().%s.Axis1,App.activeDocument().%s.Axis2,App.activeDocument().%s.Axis3,App.activeDocument().%s.Axis4,App.activeDocument().%s.Axis5,App.activeDocument().%s.Axis6]",n,n,n,n,n,n,n);
doCommand(Doc,
"App.activeDocument().%s.Home = "
"[App.activeDocument().%s.Axis1,App.activeDocument().%s.Axis2,App.activeDocument().%"
"s.Axis3,App.activeDocument().%s.Axis4,App.activeDocument().%s.Axis5,App."
"activeDocument().%s.Axis6]",
n,
n,
n,
n,
n,
n,
n);
updateActive();
commitCommand();

}

bool CmdRobotSetHomePos::isActive()
Expand All @@ -94,31 +104,31 @@ bool CmdRobotSetHomePos::isActive()
DEF_STD_CMD_A(CmdRobotRestoreHomePos)

CmdRobotRestoreHomePos::CmdRobotRestoreHomePos()
:Command("Robot_RestoreHomePos")
: Command("Robot_RestoreHomePos")
{
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Move to home");
sToolTipText = QT_TR_NOOP("Move to home");
sWhatsThis = "Robot_RestoreHomePos";
sStatusTip = sToolTipText;
sPixmap = "Robot_RestoreHomePos";
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Move to home");
sToolTipText = QT_TR_NOOP("Move to home");
sWhatsThis = "Robot_RestoreHomePos";
sStatusTip = sToolTipText;
sPixmap = "Robot_RestoreHomePos";
}


void CmdRobotRestoreHomePos::activated(int)
{
const char * SelFilter =
"SELECT Robot::RobotObject COUNT 1 ";
const char* SelFilter = "SELECT Robot::RobotObject COUNT 1 ";

Gui::SelectionFilter filter(SelFilter);
Robot::RobotObject *pcRobotObject;
Robot::RobotObject* pcRobotObject;
if (filter.match()) {
pcRobotObject = static_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
}
else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one Robot"));
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select one Robot"));
return;
}

Expand All @@ -127,15 +137,14 @@ void CmdRobotRestoreHomePos::activated(int)

const char* n = FeatName.c_str();
openCommand("Move to home");
doCommand(Doc,"App.activeDocument().%s.Axis1 = App.activeDocument().%s.Home[0]",n,n);
doCommand(Doc,"App.activeDocument().%s.Axis2 = App.activeDocument().%s.Home[1]",n,n);
doCommand(Doc,"App.activeDocument().%s.Axis3 = App.activeDocument().%s.Home[2]",n,n);
doCommand(Doc,"App.activeDocument().%s.Axis4 = App.activeDocument().%s.Home[3]",n,n);
doCommand(Doc,"App.activeDocument().%s.Axis5 = App.activeDocument().%s.Home[4]",n,n);
doCommand(Doc,"App.activeDocument().%s.Axis6 = App.activeDocument().%s.Home[5]",n,n);
doCommand(Doc, "App.activeDocument().%s.Axis1 = App.activeDocument().%s.Home[0]", n, n);
doCommand(Doc, "App.activeDocument().%s.Axis2 = App.activeDocument().%s.Home[1]", n, n);
doCommand(Doc, "App.activeDocument().%s.Axis3 = App.activeDocument().%s.Home[2]", n, n);
doCommand(Doc, "App.activeDocument().%s.Axis4 = App.activeDocument().%s.Home[3]", n, n);
doCommand(Doc, "App.activeDocument().%s.Axis5 = App.activeDocument().%s.Home[4]", n, n);
doCommand(Doc, "App.activeDocument().%s.Axis6 = App.activeDocument().%s.Home[5]", n, n);
updateActive();
commitCommand();

}

bool CmdRobotRestoreHomePos::isActive()
Expand All @@ -148,15 +157,15 @@ bool CmdRobotRestoreHomePos::isActive()
DEF_STD_CMD_A(CmdRobotConstraintAxle)

CmdRobotConstraintAxle::CmdRobotConstraintAxle()
:Command("Robot_Create")
: Command("Robot_Create")
{
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Place robot...");
sToolTipText = QT_TR_NOOP("Place a robot (experimental!)");
sWhatsThis = "Robot_Create";
sStatusTip = sToolTipText;
sPixmap = "Robot_CreateRobot";
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Place robot...");
sToolTipText = QT_TR_NOOP("Place a robot (experimental!)");
sWhatsThis = "Robot_Create";
sStatusTip = sToolTipText;
sPixmap = "Robot_CreateRobot";
}


Expand All @@ -167,15 +176,22 @@ void CmdRobotConstraintAxle::activated(int)
std::string KinematicPath = "Mod/Robot/Lib/Kuka/kr500_1.csv";

openCommand("Place robot");
doCommand(Doc,"App.activeDocument().addObject(\"Robot::RobotObject\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.RobotVrmlFile = App.getResourceDir()+\"%s\"",FeatName.c_str(),RobotPath.c_str());
doCommand(Doc,"App.activeDocument().%s.RobotKinematicFile = App.getResourceDir()+\"%s\"",FeatName.c_str(),KinematicPath.c_str());
doCommand(Doc,"App.activeDocument().%s.Axis2 = -90",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Axis3 = 90",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Axis5 = 45",FeatName.c_str());
doCommand(Doc,
"App.activeDocument().addObject(\"Robot::RobotObject\",\"%s\")",
FeatName.c_str());
doCommand(Doc,
"App.activeDocument().%s.RobotVrmlFile = App.getResourceDir()+\"%s\"",
FeatName.c_str(),
RobotPath.c_str());
doCommand(Doc,
"App.activeDocument().%s.RobotKinematicFile = App.getResourceDir()+\"%s\"",
FeatName.c_str(),
KinematicPath.c_str());
doCommand(Doc, "App.activeDocument().%s.Axis2 = -90", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Axis3 = 90", FeatName.c_str());
doCommand(Doc, "App.activeDocument().%s.Axis5 = 45", FeatName.c_str());
updateActive();
commitCommand();

}

bool CmdRobotConstraintAxle::isActive()
Expand All @@ -189,68 +205,74 @@ bool CmdRobotConstraintAxle::isActive()
DEF_STD_CMD_A(CmdRobotSimulate)

CmdRobotSimulate::CmdRobotSimulate()
:Command("Robot_Simulate")
: Command("Robot_Simulate")
{
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Simulate a trajectory");
sToolTipText = QT_TR_NOOP("Run a simulation on a trajectory");
sWhatsThis = "Robot_Simulate";
sStatusTip = sToolTipText;
sPixmap = "Robot_Simulate";
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Simulate a trajectory");
sToolTipText = QT_TR_NOOP("Run a simulation on a trajectory");
sWhatsThis = "Robot_Simulate";
sStatusTip = sToolTipText;
sPixmap = "Robot_Simulate";
}


void CmdRobotSimulate::activated(int)
{
#if 1
const char * SelFilter =
"SELECT Robot::RobotObject \n"
"SELECT Robot::TrajectoryObject ";
const char* SelFilter = "SELECT Robot::RobotObject \n"
"SELECT Robot::TrajectoryObject ";

Gui::SelectionFilter filter(SelFilter);
Robot::RobotObject *pcRobotObject;
Robot::TrajectoryObject *pcTrajectoryObject;
Robot::RobotObject* pcRobotObject;
Robot::TrajectoryObject* pcTrajectoryObject;

if (filter.match()) {
pcRobotObject = static_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
pcTrajectoryObject = static_cast<Robot::TrajectoryObject*>(filter.Result[1][0].getObject());;
pcTrajectoryObject = static_cast<Robot::TrajectoryObject*>(filter.Result[1][0].getObject());
;
}
else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one Robot and one Trajectory object."));
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select one Robot and one Trajectory object."));
return;
}

if(pcTrajectoryObject->Trajectory.getValue().getSize() < 2){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Trajectory not valid"),
if (pcTrajectoryObject->Trajectory.getValue().getSize() < 2) {
QMessageBox::warning(
Gui::getMainWindow(),
QObject::tr("Trajectory not valid"),
QObject::tr("You need at least two waypoints in a trajectory to simulate."));
return;
}

Gui::TaskView::TaskDialog* dlg = new TaskDlgSimulate(pcRobotObject,pcTrajectoryObject);
Gui::TaskView::TaskDialog* dlg = new TaskDlgSimulate(pcRobotObject, pcTrajectoryObject);
Gui::Control().showDialog(dlg);

#else
const char * SelFilter =
"SELECT Robot::RobotObject \n"
"SELECT Robot::TrajectoryObject ";
const char* SelFilter = "SELECT Robot::RobotObject \n"
"SELECT Robot::TrajectoryObject ";
Gui::SelectionFilter filter(SelFilter);
Robot::RobotObject *pcRobotObject;
Robot::TrajectoryObject *pcTrajectoryObject;
Robot::RobotObject* pcRobotObject;
Robot::TrajectoryObject* pcTrajectoryObject;
if(filter.match()){
if (filter.match()) {
pcRobotObject = dynamic_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(filter.Result[1][0].getObject());;
}else{
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one Robot and one Trajectory object."));
pcTrajectoryObject =
dynamic_cast<Robot::TrajectoryObject*>(filter.Result[1][0].getObject());
;
}
else {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select one Robot and one Trajectory object."));
}
RobotGui::TrajectorySimulate dlg(pcRobotObject,pcTrajectoryObject,Gui::getMainWindow());
RobotGui::TrajectorySimulate dlg(pcRobotObject, pcTrajectoryObject, Gui::getMainWindow());
dlg.exec();
#endif
}
Expand All @@ -261,17 +283,15 @@ bool CmdRobotSimulate::isActive()
}



// #####################################################################################################



void CreateRobotCommands()
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();

rcCmdMgr.addCommand(new CmdRobotRestoreHomePos());
rcCmdMgr.addCommand(new CmdRobotSetHomePos());
rcCmdMgr.addCommand(new CmdRobotConstraintAxle());
rcCmdMgr.addCommand(new CmdRobotSimulate());
}
}
Loading

0 comments on commit 4bc2b1b

Please sign in to comment.