File size: 4,073 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | // SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
* *
* 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 <QMessageBox>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection/Selection.h>
#include <Mod/Robot/App/RobotObject.h>
#include "TrajectorySimulate.h"
using namespace std;
DEF_STD_CMD_A(CmdRobotAddToolShape)
CmdRobotAddToolShape::CmdRobotAddToolShape()
: Command("Robot_AddToolShape")
{
sAppModule = "Robot";
sGroup = QT_TR_NOOP("Robot");
sMenuText = QT_TR_NOOP("Tool");
sToolTipText = QT_TR_NOOP("Adds a tool shape to the robot");
sWhatsThis = "Robot_AddToolShape";
sStatusTip = sToolTipText;
sPixmap = "Robot_CreateRobot";
}
void CmdRobotAddToolShape::activated(int)
{
std::vector<App::DocumentObject*> robots = getSelection().getObjectsOfType(
Robot::RobotObject::getClassTypeId()
);
std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(
Base::Type::fromName("Part::Feature")
);
std::vector<App::DocumentObject*> VRMLs = getSelection().getObjectsOfType(
Base::Type::fromName("App::VRMLObject")
);
if (robots.size() != 1 || (shapes.size() != 1 && VRMLs.size() != 1)) {
QMessageBox::warning(
Gui::getMainWindow(),
QObject::tr("Wrong selection"),
QObject::tr("Select one robot and one shape or VRML object.")
);
return;
}
std::string RoboName = robots.front()->getNameInDocument();
std::string ShapeName;
if (shapes.size() == 1) {
ShapeName = shapes.front()->getNameInDocument();
}
else {
ShapeName = VRMLs.front()->getNameInDocument();
}
openCommand("Add tool to robot");
doCommand(
Doc,
"App.activeDocument().%s.ToolShape = App.activeDocument().%s",
RoboName.c_str(),
ShapeName.c_str()
);
// doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",ShapeName.c_str());
updateActive();
commitCommand();
}
bool CmdRobotAddToolShape::isActive()
{
// return false; // not yet implemented and thus not active
return hasActiveDocument();
}
void CreateRobotCommandsInsertRobots()
{
Gui::CommandManager& command_manager = Gui::Application::Instance->commandManager();
command_manager.addCommand(new CmdRobotAddToolShape());
}
|