Mod/Robot/Gui/Command.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de)              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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/MainWindow.h>
00032 #include <Gui/Command.h>
00033 #include <Gui/FileDialog.h>
00034 #include <Gui/Selection.h>
00035 #include <Gui/SelectionFilter.h>
00036 #include <Gui/Document.h>
00037 #include <Gui/Control.h>
00038 
00039 #include <Mod/Robot/App/RobotObject.h>
00040 #include <Mod/Robot/App/TrajectoryObject.h>
00041 
00042 #include "TrajectorySimulate.h"
00043 #include "TaskDlgSimulate.h"
00044 
00045 
00046 using namespace std;
00047 using namespace RobotGui;
00048 
00049 DEF_STD_CMD_A(CmdRobotSetHomePos);
00050 
00051 CmdRobotSetHomePos::CmdRobotSetHomePos()
00052         :Command("Robot_SetHomePos")
00053 {
00054     sAppModule      = "Robot";
00055     sGroup          = QT_TR_NOOP("Robot");
00056     sMenuText       = QT_TR_NOOP("Set the home position");
00057     sToolTipText    = QT_TR_NOOP("Set the home position");
00058     sWhatsThis      = sToolTipText;
00059     sStatusTip      = sToolTipText;
00060     sPixmap         = "Robot_SetHomePos";
00061 }
00062 
00063 
00064 void CmdRobotSetHomePos::activated(int iMsg)
00065 {
00066    const char * SelFilter = 
00067         "SELECT Robot::RobotObject COUNT 1 ";
00068 
00069     Gui::SelectionFilter filter(SelFilter);
00070     Robot::RobotObject *pcRobotObject;
00071     if (filter.match()) {
00072         pcRobotObject = static_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
00073     }
00074     else {
00075         QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00076             QObject::tr("Select one Robot to set home postion"));
00077         return;
00078     }
00079 
00080 
00081     std::string FeatName = pcRobotObject->getNameInDocument();
00082  
00083     const char* n = FeatName.c_str();
00084     openCommand("Set home");
00085     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);
00086     updateActive();
00087     commitCommand();
00088       
00089 }
00090 
00091 bool CmdRobotSetHomePos::isActive(void)
00092 {
00093     return hasActiveDocument();
00094 }
00095 
00096 
00097 // #####################################################################################################
00098 DEF_STD_CMD_A(CmdRobotRestoreHomePos);
00099 
00100 CmdRobotRestoreHomePos::CmdRobotRestoreHomePos()
00101         :Command("Robot_RestoreHomePos")
00102 {
00103     sAppModule      = "Robot";
00104     sGroup          = QT_TR_NOOP("Robot");
00105     sMenuText       = QT_TR_NOOP("Move to home");
00106     sToolTipText    = QT_TR_NOOP("Move to home");
00107     sWhatsThis      = sToolTipText;
00108     sStatusTip      = sToolTipText;
00109     sPixmap         = "Robot_RestoreHomePos";
00110 }
00111 
00112 
00113 void CmdRobotRestoreHomePos::activated(int iMsg)
00114 {
00115     const char * SelFilter = 
00116         "SELECT Robot::RobotObject COUNT 1 ";
00117 
00118     Gui::SelectionFilter filter(SelFilter);
00119     Robot::RobotObject *pcRobotObject;
00120     if (filter.match()) {
00121         pcRobotObject = static_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
00122     }
00123     else {
00124         QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00125             QObject::tr("Select one Robot"));
00126         return;
00127     }
00128 
00129 
00130     std::string FeatName = pcRobotObject->getNameInDocument();
00131  
00132     const char* n = FeatName.c_str();
00133     openCommand("Move to home");
00134     doCommand(Doc,"App.activeDocument().%s.Axis1 = App.activeDocument().%s.Home[0]",n,n);
00135     doCommand(Doc,"App.activeDocument().%s.Axis2 = App.activeDocument().%s.Home[1]",n,n);
00136     doCommand(Doc,"App.activeDocument().%s.Axis3 = App.activeDocument().%s.Home[2]",n,n);
00137     doCommand(Doc,"App.activeDocument().%s.Axis4 = App.activeDocument().%s.Home[3]",n,n);
00138     doCommand(Doc,"App.activeDocument().%s.Axis5 = App.activeDocument().%s.Home[4]",n,n);
00139     doCommand(Doc,"App.activeDocument().%s.Axis6 = App.activeDocument().%s.Home[5]",n,n);
00140     updateActive();
00141     commitCommand();
00142       
00143 }
00144 
00145 bool CmdRobotRestoreHomePos::isActive(void)
00146 {
00147     return hasActiveDocument();
00148 }
00149 
00150 
00151 // #####################################################################################################
00152 DEF_STD_CMD_A(CmdRobotConstraintAxle);
00153 
00154 CmdRobotConstraintAxle::CmdRobotConstraintAxle()
00155         :Command("Robot_Create")
00156 {
00157     sAppModule      = "Robot";
00158     sGroup          = QT_TR_NOOP("Robot");
00159     sMenuText       = QT_TR_NOOP("Place robot...");
00160     sToolTipText    = QT_TR_NOOP("Place a robot (experimental!)");
00161     sWhatsThis      = sToolTipText;
00162     sStatusTip      = sToolTipText;
00163     sPixmap         = "Robot_CreateRobot";
00164 }
00165 
00166 
00167 void CmdRobotConstraintAxle::activated(int iMsg)
00168 {
00169     std::string FeatName = getUniqueObjectName("Robot");
00170     std::string RobotPath = "Mod/Robot/Lib/Kuka/kr500_1.wrl";
00171     std::string KinematicPath = "Mod/Robot/Lib/Kuka/kr500_1.csv";
00172 
00173     openCommand("Place robot");
00174     doCommand(Doc,"App.activeDocument().addObject(\"Robot::RobotObject\",\"%s\")",FeatName.c_str());
00175     doCommand(Doc,"App.activeDocument().%s.RobotVrmlFile = App.getResourceDir()+\"%s\"",FeatName.c_str(),RobotPath.c_str());
00176     doCommand(Doc,"App.activeDocument().%s.RobotKinematicFile = App.getResourceDir()+\"%s\"",FeatName.c_str(),KinematicPath.c_str());
00177     doCommand(Doc,"App.activeDocument().%s.Axis2 = -90",FeatName.c_str());
00178     doCommand(Doc,"App.activeDocument().%s.Axis3 = 90",FeatName.c_str());
00179     doCommand(Doc,"App.activeDocument().%s.Axis5 = 45",FeatName.c_str());
00180     updateActive();
00181     commitCommand();
00182       
00183 }
00184 
00185 bool CmdRobotConstraintAxle::isActive(void)
00186 {
00187     return hasActiveDocument();
00188 }
00189 
00190 
00191 // #####################################################################################################
00192 
00193 DEF_STD_CMD_A(CmdRobotSimulate);
00194 
00195 CmdRobotSimulate::CmdRobotSimulate()
00196         :Command("Robot_Simulate")
00197 {
00198     sAppModule      = "Robot";
00199     sGroup          = QT_TR_NOOP("Robot");
00200     sMenuText       = QT_TR_NOOP("Simulate a trajectory");
00201     sToolTipText    = QT_TR_NOOP("Run a simulation on a trajectory");
00202     sWhatsThis      = sToolTipText;
00203     sStatusTip      = sToolTipText;
00204     sPixmap         = "Robot_Simulate";
00205 }
00206 
00207 
00208 void CmdRobotSimulate::activated(int iMsg)
00209 {
00210 #if 1
00211     const char * SelFilter = 
00212         "SELECT Robot::RobotObject  \n"
00213         "SELECT Robot::TrajectoryObject  ";
00214 
00215     Gui::SelectionFilter filter(SelFilter);
00216     Robot::RobotObject *pcRobotObject;
00217     Robot::TrajectoryObject *pcTrajectoryObject;
00218 
00219     if (filter.match()) {
00220         pcRobotObject = static_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
00221         pcTrajectoryObject = static_cast<Robot::TrajectoryObject*>(filter.Result[1][0].getObject());;
00222     }
00223     else {
00224         QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00225             QObject::tr("Select one Robot and one Trajectory object."));
00226         return;
00227     }
00228 
00229     if(pcTrajectoryObject->Trajectory.getValue().getSize() < 2){
00230         QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Trajectory not valid"),
00231             QObject::tr("You need at least two way points in a trajectory to simulate."));
00232         return;
00233     }
00234 
00235     Gui::TaskView::TaskDialog* dlg = new TaskDlgSimulate(pcRobotObject,pcTrajectoryObject);
00236     Gui::Control().showDialog(dlg);
00237      
00238 #else
00239 
00240  
00241    const char * SelFilter = 
00242        "SELECT Robot::RobotObject  \n"
00243        "SELECT Robot::TrajectoryObject  ";
00244 
00245     Gui::SelectionFilter filter(SelFilter);
00246     Robot::RobotObject *pcRobotObject;
00247     Robot::TrajectoryObject *pcTrajectoryObject;
00248 
00249     if(filter.match()){
00250         pcRobotObject = dynamic_cast<Robot::RobotObject*>(filter.Result[0][0].getObject());
00251         pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(filter.Result[1][0].getObject());;
00252     }else{
00253         QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00254             QObject::tr("Select one Robot and one Trajectory object."));
00255     }
00256 
00257     RobotGui::TrajectorySimulate dlg(pcRobotObject,pcTrajectoryObject,Gui::getMainWindow());
00258     dlg.exec();
00259 #endif  
00260 }
00261 
00262 bool CmdRobotSimulate::isActive(void)
00263 {
00264     return (hasActiveDocument() && !Gui::Control().activeDialog());
00265 }
00266 
00267 
00268 
00269 // #####################################################################################################
00270 
00271 
00272 
00273 void CreateRobotCommands(void)
00274 {
00275     Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00276 
00277     rcCmdMgr.addCommand(new CmdRobotRestoreHomePos());
00278     rcCmdMgr.addCommand(new CmdRobotSetHomePos());
00279     rcCmdMgr.addCommand(new CmdRobotConstraintAxle());
00280     rcCmdMgr.addCommand(new CmdRobotSimulate());
00281  }

Generated on Wed Nov 23 19:00:02 2011 for FreeCAD by  doxygen 1.6.1