// SPDX-License-Identifier: LGPL-2.1-or-later /*************************************************************************** * Copyright (c) 2008 Jürgen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include #include #include #include #include #include #include #include #include using namespace std; DEF_STD_CMD_A(CmdRobotExportKukaCompact) CmdRobotExportKukaCompact::CmdRobotExportKukaCompact() : Command("Robot_ExportKukaCompact") { sAppModule = "Robot"; sGroup = QT_TR_NOOP("Robot"); sMenuText = QT_TR_NOOP("Kuka Compact Subroutine"); sToolTipText = QT_TR_NOOP("Exports the trajectory as a compact KRL subroutine"); sWhatsThis = "Robot_ExportKukaCompact"; sStatusTip = sToolTipText; sPixmap = "Robot_Export"; } void CmdRobotExportKukaCompact::activated(int) { unsigned int n1 = getSelection().countObjectsOfType(); unsigned int n2 = getSelection().countObjectsOfType(); if (n1 != 1 || n2 != 1) { QMessageBox::warning( Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Robot and one Trajectory object.") ); return; } std::vector Sel = getSelection().getSelection(); Robot::RobotObject* pcRobotObject = nullptr; if (Sel[0].pObject->is()) { pcRobotObject = static_cast(Sel[0].pObject); } else if (Sel[1].pObject->is()) { pcRobotObject = static_cast(Sel[1].pObject); } std::string RoboName = pcRobotObject->getNameInDocument(); Robot::TrajectoryObject* pcTrajectoryObject = nullptr; if (Sel[0].pObject->is()) { pcTrajectoryObject = static_cast(Sel[0].pObject); } else if (Sel[1].pObject->is()) { pcTrajectoryObject = static_cast(Sel[1].pObject); } // std::string TrakName = pcTrajectoryObject->getNameInDocument(); QStringList filter; filter << QStringLiteral("%1 (*.src)").arg(QObject::tr("KRL file")); filter << QStringLiteral("%1 (*.*)").arg(QObject::tr("All Files")); QString fn = Gui::FileDialog::getSaveFileName( Gui::getMainWindow(), QObject::tr("Export program"), QString(), filter.join(QLatin1String(";;")) ); if (fn.isEmpty()) { return; } doCommand(Doc, "from KukaExporter import ExportCompactSub"); doCommand( Doc, "ExportCompactSub(App.activeDocument().%s,App.activeDocument().%s,'%s')", pcRobotObject->getNameInDocument(), pcTrajectoryObject->getNameInDocument(), (const char*)fn.toLatin1() ); } bool CmdRobotExportKukaCompact::isActive() { return hasActiveDocument(); } // ##################################################################################################### DEF_STD_CMD_A(CmdRobotExportKukaFull) CmdRobotExportKukaFull::CmdRobotExportKukaFull() : Command("Robot_ExportKukaFull") { sAppModule = "Robot"; sGroup = QT_TR_NOOP("Robot"); sMenuText = QT_TR_NOOP("Kuka Full Subroutine"); sToolTipText = QT_TR_NOOP("Exports the trajectory as a full KRL subroutine"); sWhatsThis = "Robot_ExportKukaFull"; sStatusTip = sToolTipText; sPixmap = "Robot_Export"; } void CmdRobotExportKukaFull::activated(int) { unsigned int n1 = getSelection().countObjectsOfType(); unsigned int n2 = getSelection().countObjectsOfType(); if (n1 != 1 || n2 != 1) { QMessageBox::warning( Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one Robot and one Trajectory object.") ); return; } std::vector Sel = getSelection().getSelection(); Robot::RobotObject* pcRobotObject = nullptr; if (Sel[0].pObject->is()) { pcRobotObject = static_cast(Sel[0].pObject); } else if (Sel[1].pObject->is()) { pcRobotObject = static_cast(Sel[1].pObject); } // std::string RoboName = pcRobotObject->getNameInDocument(); Robot::TrajectoryObject* pcTrajectoryObject = nullptr; if (Sel[0].pObject->is()) { pcTrajectoryObject = static_cast(Sel[0].pObject); } else if (Sel[1].pObject->is()) { pcTrajectoryObject = static_cast(Sel[1].pObject); } // std::string TrakName = pcTrajectoryObject->getNameInDocument(); QStringList filter; filter << QStringLiteral("%1 (*.src)").arg(QObject::tr("KRL file")); filter << QStringLiteral("%1 (*.*)").arg(QObject::tr("All Files")); QString fn = Gui::FileDialog::getSaveFileName( Gui::getMainWindow(), QObject::tr("Export program"), QString(), filter.join(QLatin1String(";;")) ); if (fn.isEmpty()) { return; } doCommand(Doc, "from KukaExporter import ExportFullSub"); doCommand( Doc, "ExportFullSub(App.activeDocument().%s,App.activeDocument().%s,'%s')", pcRobotObject->getNameInDocument(), pcTrajectoryObject->getNameInDocument(), (const char*)fn.toLatin1() ); } bool CmdRobotExportKukaFull::isActive() { return hasActiveDocument(); } // ##################################################################################################### void CreateRobotCommandsExport() { Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdRobotExportKukaFull()); rcCmdMgr.addCommand(new CmdRobotExportKukaCompact()); }