CommandExport.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QMessageBox>
00027 #endif
00028
00029 #include <App/Application.h>
00030 #include <Gui/Application.h>
00031 #include <Gui/Command.h>
00032 #include <Gui/MainWindow.h>
00033 #include <Gui/FileDialog.h>
00034 #include <Gui/Selection.h>
00035 #include <Gui/Document.h>
00036
00037 #include <Mod/Robot/App/RobotObject.h>
00038 #include <Mod/Robot/App/TrajectoryObject.h>
00039
00040 #include "TrajectorySimulate.h"
00041
00042 using namespace std;
00043
00044 DEF_STD_CMD_A(CmdRobotExportKukaCompact);
00045
00046 CmdRobotExportKukaCompact::CmdRobotExportKukaCompact()
00047 :Command("Robot_ExportKukaCompact")
00048 {
00049 sAppModule = "Robot";
00050 sGroup = QT_TR_NOOP("Robot");
00051 sMenuText = QT_TR_NOOP("Kuka compact subroutine...");
00052 sToolTipText = QT_TR_NOOP("Export the trajectory as a compact KRL subroutine.");
00053 sWhatsThis = sToolTipText;
00054 sStatusTip = sToolTipText;
00055 sPixmap = "Robot_Export";
00056 }
00057
00058
00059 void CmdRobotExportKukaCompact::activated(int iMsg)
00060 {
00061 unsigned int n1 = getSelection().countObjectsOfType(Robot::RobotObject::getClassTypeId());
00062 unsigned int n2 = getSelection().countObjectsOfType(Robot::TrajectoryObject::getClassTypeId());
00063
00064 if (n1 != 1 || n2 != 1) {
00065 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00066 QObject::tr("Select one Robot and one Trajectory object."));
00067 return;
00068 }
00069
00070 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00071
00072
00073 Robot::RobotObject *pcRobotObject;
00074 if(Sel[0].pObject->getTypeId() == Robot::RobotObject::getClassTypeId())
00075 pcRobotObject = dynamic_cast<Robot::RobotObject*>(Sel[0].pObject);
00076 else if(Sel[1].pObject->getTypeId() == Robot::RobotObject::getClassTypeId())
00077 pcRobotObject = dynamic_cast<Robot::RobotObject*>(Sel[1].pObject);
00078 std::string RoboName = pcRobotObject->getNameInDocument();
00079
00080 Robot::TrajectoryObject *pcTrajectoryObject;
00081 if(Sel[0].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00082 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[0].pObject);
00083 else if(Sel[1].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00084 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[1].pObject);
00085 std::string TrakName = pcTrajectoryObject->getNameInDocument();
00086
00087 QStringList filter;
00088 filter << QObject::tr("KRL file(*.src)");
00089 filter << QObject::tr("All Files (*.*)");
00090 QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export program"), QString(), filter.join(QLatin1String(";;")));
00091 if (fn.isEmpty())
00092 return;
00093
00094
00095 doCommand(Doc,"from KukaExporter import ExportCompactSub");
00096 doCommand(Doc,"ExportCompactSub(App.activeDocument().%s,App.activeDocument().%s,'%s')",pcRobotObject->getNameInDocument(),pcTrajectoryObject->getNameInDocument(),(const char*)fn.toLatin1());
00097
00098
00099 }
00100
00101 bool CmdRobotExportKukaCompact::isActive(void)
00102 {
00103 return hasActiveDocument();
00104 }
00105
00106
00107
00108
00109 DEF_STD_CMD_A(CmdRobotExportKukaFull);
00110
00111 CmdRobotExportKukaFull::CmdRobotExportKukaFull()
00112 :Command("Robot_ExportKukaFull")
00113 {
00114 sAppModule = "Robot";
00115 sGroup = QT_TR_NOOP("Robot");
00116 sMenuText = QT_TR_NOOP("Kuka full subroutine...");
00117 sToolTipText = QT_TR_NOOP("Export the trajectory as a full KRL subroutine.");
00118 sWhatsThis = sToolTipText;
00119 sStatusTip = sToolTipText;
00120 sPixmap = "Robot_Export";
00121 }
00122
00123
00124 void CmdRobotExportKukaFull::activated(int iMsg)
00125 {
00126 unsigned int n1 = getSelection().countObjectsOfType(Robot::RobotObject::getClassTypeId());
00127 unsigned int n2 = getSelection().countObjectsOfType(Robot::TrajectoryObject::getClassTypeId());
00128
00129 if (n1 != 1 || n2 != 1) {
00130 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00131 QObject::tr("Select one Robot and one Trajectory object."));
00132 return;
00133 }
00134
00135 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00136
00137
00138 Robot::RobotObject *pcRobotObject;
00139 if(Sel[0].pObject->getTypeId() == Robot::RobotObject::getClassTypeId())
00140 pcRobotObject = dynamic_cast<Robot::RobotObject*>(Sel[0].pObject);
00141 else if(Sel[1].pObject->getTypeId() == Robot::RobotObject::getClassTypeId())
00142 pcRobotObject = dynamic_cast<Robot::RobotObject*>(Sel[1].pObject);
00143 std::string RoboName = pcRobotObject->getNameInDocument();
00144
00145 Robot::TrajectoryObject *pcTrajectoryObject;
00146 if(Sel[0].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00147 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[0].pObject);
00148 else if(Sel[1].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00149 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[1].pObject);
00150 std::string TrakName = pcTrajectoryObject->getNameInDocument();
00151
00152 QStringList filter;
00153 filter << QObject::tr("KRL file(*.src)");
00154 filter << QObject::tr("All Files (*.*)");
00155 QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export program"), QString(), filter.join(QLatin1String(";;")));
00156 if (fn.isEmpty())
00157 return;
00158
00159 doCommand(Doc,"from KukaExporter import ExportFullSub");
00160 doCommand(Doc,"ExportFullSub(App.activeDocument().%s,App.activeDocument().%s,'%s')",pcRobotObject->getNameInDocument(),pcTrajectoryObject->getNameInDocument(),(const char*)fn.toLatin1());
00161
00162
00163
00164 }
00165
00166 bool CmdRobotExportKukaFull::isActive(void)
00167 {
00168 return hasActiveDocument();
00169 }
00170
00171
00172
00173
00174
00175 void CreateRobotCommandsExport(void)
00176 {
00177 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00178
00179 rcCmdMgr.addCommand(new CmdRobotExportKukaFull());
00180 rcCmdMgr.addCommand(new CmdRobotExportKukaCompact());
00181 }