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 #include <Gui/Placement.h>
00037 #include <Gui/Control.h>
00038
00039
00040 #include <Mod/Part/App/PartFeature.h>
00041 #include <Mod/Robot/App/RobotObject.h>
00042 #include <Mod/Robot/App/TrajectoryObject.h>
00043 #include <Mod/Robot/App/Edge2TracObject.h>
00044 #include <Mod/Robot/App/TrajectoryDressUpObject.h>
00045 #include <Mod/Robot/App/TrajectoryCompound.h>
00046 #include "TaskDlgEdge2Trac.h"
00047
00048 #include "TrajectorySimulate.h"
00049
00050 using namespace std;
00051 using namespace RobotGui;
00052
00053
00054
00055 DEF_STD_CMD_A(CmdRobotCreateTrajectory);
00056
00057 CmdRobotCreateTrajectory::CmdRobotCreateTrajectory()
00058 :Command("Robot_CreateTrajectory")
00059 {
00060 sAppModule = "Robot";
00061 sGroup = QT_TR_NOOP("Robot");
00062 sMenuText = QT_TR_NOOP("Create trajectory");
00063 sToolTipText = QT_TR_NOOP("Create a new empty trajectory ");
00064 sWhatsThis = sToolTipText;
00065 sStatusTip = sToolTipText;
00066 sPixmap = "Robot_CreateTrajectory";
00067 }
00068
00069
00070 void CmdRobotCreateTrajectory::activated(int iMsg)
00071 {
00072 std::string FeatName = getUniqueObjectName("Trajectory");
00073
00074 openCommand("Create trajectory");
00075 doCommand(Doc,"App.activeDocument().addObject(\"Robot::TrajectoryObject\",\"%s\")",FeatName.c_str());
00076 updateActive();
00077 commitCommand();
00078
00079 }
00080
00081 bool CmdRobotCreateTrajectory::isActive(void)
00082 {
00083 return hasActiveDocument();
00084 }
00085
00086
00087
00088 DEF_STD_CMD_A(CmdRobotInsertWaypoint);
00089
00090 CmdRobotInsertWaypoint::CmdRobotInsertWaypoint()
00091 :Command("Robot_InsertWaypoint")
00092 {
00093 sAppModule = "Robot";
00094 sGroup = QT_TR_NOOP("Robot");
00095 sMenuText = QT_TR_NOOP("Insert in trajectory");
00096 sToolTipText = QT_TR_NOOP("Insert robot Tool location into trajectory");
00097 sWhatsThis = sToolTipText;
00098 sStatusTip = sToolTipText;
00099 sPixmap = "Robot_InsertWaypoint";
00100 sAccel = "A";
00101 }
00102
00103
00104 void CmdRobotInsertWaypoint::activated(int iMsg)
00105 {
00106 unsigned int n1 = getSelection().countObjectsOfType(Robot::RobotObject::getClassTypeId());
00107 unsigned int n2 = getSelection().countObjectsOfType(Robot::TrajectoryObject::getClassTypeId());
00108
00109 if (n1 != 1 || n2 != 1) {
00110 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00111 QObject::tr("Select one Robot and one Trajectory object."));
00112 return;
00113 }
00114
00115 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00116
00117 Robot::RobotObject *pcRobotObject;
00118 if(Sel[0].pObject->getTypeId() == Robot::RobotObject::getClassTypeId())
00119 pcRobotObject = dynamic_cast<Robot::RobotObject*>(Sel[0].pObject);
00120 else if(Sel[1].pObject->getTypeId() == Robot::RobotObject::getClassTypeId())
00121 pcRobotObject = dynamic_cast<Robot::RobotObject*>(Sel[1].pObject);
00122 std::string RoboName = pcRobotObject->getNameInDocument();
00123
00124 Robot::TrajectoryObject *pcTrajectoryObject;
00125 if(Sel[0].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00126 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[0].pObject);
00127 else if(Sel[1].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00128 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[1].pObject);
00129 std::string TrakName = pcTrajectoryObject->getNameInDocument();
00130
00131 openCommand("Insert waypoint");
00132 doCommand(Doc,"App.activeDocument().%s.Trajectory = App.activeDocument().%s.Trajectory.insertWaypoints(Robot.Waypoint(App.activeDocument().%s.Tcp.multiply(App.activeDocument().%s.Tool),type='LIN',name='Pt',vel=_DefSpeed,cont=_DefCont,acc=_DefAccelaration,tool=1))",TrakName.c_str(),TrakName.c_str(),RoboName.c_str(),RoboName.c_str());
00133 updateActive();
00134 commitCommand();
00135
00136 }
00137
00138 bool CmdRobotInsertWaypoint::isActive(void)
00139 {
00140 return hasActiveDocument();
00141 }
00142
00143
00144
00145 DEF_STD_CMD_A(CmdRobotInsertWaypointPreselect);
00146
00147 CmdRobotInsertWaypointPreselect::CmdRobotInsertWaypointPreselect()
00148 :Command("Robot_InsertWaypointPreselect")
00149 {
00150 sAppModule = "Robot";
00151 sGroup = QT_TR_NOOP("Robot");
00152 sMenuText = QT_TR_NOOP("Insert in trajectory");
00153 sToolTipText = QT_TR_NOOP("Insert preselection position into trajectory (W)");
00154 sWhatsThis = sToolTipText;
00155 sStatusTip = sToolTipText;
00156 sPixmap = "Robot_InsertWaypointPre";
00157 sAccel = "W";
00158
00159 }
00160
00161
00162 void CmdRobotInsertWaypointPreselect::activated(int iMsg)
00163 {
00164
00165 if (getSelection().size() != 1 ) {
00166 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00167 QObject::tr("Select one Trajectory object."));
00168 return;
00169 }
00170
00171 std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
00172
00173 const Gui::SelectionChanges & PreSel = getSelection().getPreselection();
00174 float x = PreSel.x;
00175 float y = PreSel.y;
00176 float z = PreSel.z;
00177
00178
00179 Robot::TrajectoryObject *pcTrajectoryObject;
00180 if(Sel[0].pObject->getTypeId() == Robot::TrajectoryObject::getClassTypeId())
00181 pcTrajectoryObject = dynamic_cast<Robot::TrajectoryObject*>(Sel[0].pObject);
00182 else {
00183 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00184 QObject::tr("Select one Trajectory object."));
00185 return;
00186 }
00187 std::string TrakName = pcTrajectoryObject->getNameInDocument();
00188
00189 if(PreSel.pDocName == 0){
00190 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No preselection"),
00191 QObject::tr("You have to hover above a geometry (Preselection) with the mouse to use this command. See documentation for details."));
00192 return;
00193 }
00194
00195 openCommand("Insert waypoint");
00196 doCommand(Doc,"App.activeDocument().%s.Trajectory = App.activeDocument().%s.Trajectory.insertWaypoints(Robot.Waypoint(FreeCAD.Placement(FreeCAD.Vector(%f,%f,%f)+_DefDisplacement,_DefOrientation),type='LIN',name='Pt',vel=_DefSpeed,cont=_DefCont,acc=_DefAccelaration,tool=1))",TrakName.c_str(),TrakName.c_str(),x,y,z);
00197 updateActive();
00198 commitCommand();
00199
00200 }
00201
00202 bool CmdRobotInsertWaypointPreselect::isActive(void)
00203 {
00204 return hasActiveDocument();
00205 }
00206
00207
00208
00209 DEF_STD_CMD_A(CmdRobotSetDefaultOrientation);
00210
00211 CmdRobotSetDefaultOrientation::CmdRobotSetDefaultOrientation()
00212 :Command("Robot_SetDefaultOrientation")
00213 {
00214 sAppModule = "Robot";
00215 sGroup = QT_TR_NOOP("Robot");
00216 sMenuText = QT_TR_NOOP("Set default orientation");
00217 sToolTipText = QT_TR_NOOP("set the default orientation for subsequent commands for waypoint creation");
00218 sWhatsThis = sToolTipText;
00219 sStatusTip = sToolTipText;
00220 sPixmap = 0;
00221
00222 }
00223
00224
00225 void CmdRobotSetDefaultOrientation::activated(int iMsg)
00226 {
00227
00228 Gui::Dialog::Placement *Dlg = new Gui::Dialog::Placement();
00229 Base::Placement place;
00230 Dlg->setPlacement(place);
00231 if(Dlg->exec() == QDialog::Accepted ){
00232 place = Dlg->getPlacement();
00233 Base::Rotation rot = place.getRotation();
00234 Base::Vector3d disp = place.getPosition();
00235 doCommand(Doc,"_DefOrientation = FreeCAD.Rotation(%f,%f,%f,%f)",rot[0],rot[1],rot[2],rot[3]);
00236 doCommand(Doc,"_DefDisplacement = FreeCAD.Vector(%f,%f,%f)",disp[0],disp[1],disp[2]);
00237 }
00238
00239 }
00240
00241 bool CmdRobotSetDefaultOrientation::isActive(void)
00242 {
00243 return true;
00244 }
00245
00246
00247
00248 DEF_STD_CMD_A(CmdRobotSetDefaultValues);
00249
00250 CmdRobotSetDefaultValues::CmdRobotSetDefaultValues()
00251 :Command("Robot_SetDefaultValues")
00252 {
00253 sAppModule = "Robot";
00254 sGroup = QT_TR_NOOP("Robot");
00255 sMenuText = QT_TR_NOOP("Set default values");
00256 sToolTipText = QT_TR_NOOP("set the default values for speed, acceleration and continuity for subsequent commands of waypoint creation");
00257 sWhatsThis = sToolTipText;
00258 sStatusTip = sToolTipText;
00259 sPixmap = 0;
00260
00261 }
00262
00263
00264 void CmdRobotSetDefaultValues::activated(int iMsg)
00265 {
00266
00267 bool ok;
00268 QString text = QInputDialog::getText(0, QObject::tr("set default speed"),
00269 QObject::tr("speed: (e.g. 1 m/s or 3 cm/s)"), QLineEdit::Normal,
00270 QString::fromAscii("1 m/s"), &ok);
00271 if ( ok && !text.isEmpty() ) {
00272 doCommand(Doc,"_DefSpeed = '%s'",text.toAscii().constData());
00273 }
00274
00275 QStringList items;
00276 items << QString::fromAscii("False") << QString::fromAscii("True");
00277
00278 QString item = QInputDialog::getItem(0, QObject::tr("set default continuity"),
00279 QObject::tr("continuous ?"), items, 0, false, &ok);
00280 if (ok && !item.isEmpty())
00281 doCommand(Doc,"_DefCont = %s",item.toAscii().constData());
00282
00283 text.clear();
00284
00285 text = QInputDialog::getText(0, QObject::tr("set default acceleration"),
00286 QObject::tr("acceleration: (e.g. 1 m/s^2 or 3 cm/s^2)"), QLineEdit::Normal,
00287 QString::fromAscii("1 m/s^2"), &ok);
00288 if ( ok && !text.isEmpty() ) {
00289 doCommand(Doc,"_DefAccelaration = '%s'",text.toAscii().constData());
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 }
00306
00307 bool CmdRobotSetDefaultValues::isActive(void)
00308 {
00309 return true;
00310 }
00311
00312
00313
00314 DEF_STD_CMD_A(CmdRobotEdge2Trac);
00315
00316 CmdRobotEdge2Trac::CmdRobotEdge2Trac()
00317 :Command("Robot_Edge2Trac")
00318 {
00319 sAppModule = "Robot";
00320 sGroup = QT_TR_NOOP("Robot");
00321 sMenuText = QT_TR_NOOP("Edge to Trajectory...");
00322 sToolTipText = QT_TR_NOOP("Generate a Trajectory from a set of edges");
00323 sWhatsThis = sToolTipText;
00324 sStatusTip = sToolTipText;
00325 sPixmap = "Robot_Edge2Trac";
00326
00327 }
00328
00329
00330 void CmdRobotEdge2Trac::activated(int iMsg)
00331 {
00332
00333
00334
00335
00336
00337
00338
00339
00340 Gui::SelectionFilter ObjectFilter("SELECT Robot::Edge2TracObject COUNT 1");
00341 Gui::SelectionFilter EdgeFilter ("SELECT Part::Feature SUBELEMENT Edge COUNT 1..");
00342
00343 if (ObjectFilter.match()) {
00344 Robot::Edge2TracObject *EdgeObj = static_cast<Robot::Edge2TracObject*>(ObjectFilter.Result[0][0].getObject());
00345 openCommand("Edit Edge2TracObject");
00346 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",EdgeObj->getNameInDocument());
00347 }else if (EdgeFilter.match()) {
00348
00349
00350 std::string obj_sub = EdgeFilter.Result[0][0].getAsPropertyLinkSubString();
00351
00352 std::string FeatName = getUniqueObjectName("Edge2Trac");
00353
00354 openCommand("Create a new Edge2TracObject");
00355 doCommand(Doc,"App.activeDocument().addObject('Robot::Edge2TracObject','%s')",FeatName.c_str());
00356 doCommand(Gui,"App.activeDocument().%s.Source = %s",FeatName.c_str(),obj_sub.c_str());
00357 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00358
00359 }else {
00360 std::string FeatName = getUniqueObjectName("Edge2Trac");
00361
00362 openCommand("Create a new Edge2TracObject");
00363 doCommand(Doc,"App.activeDocument().addObject('Robot::Edge2TracObject','%s')",FeatName.c_str());
00364 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00365 }
00366
00367
00368
00369 }
00370
00371 bool CmdRobotEdge2Trac::isActive(void)
00372 {
00373 return true;
00374 }
00375
00376
00377
00378 DEF_STD_CMD_A(CmdRobotTrajectoryDressUp);
00379
00380 CmdRobotTrajectoryDressUp::CmdRobotTrajectoryDressUp()
00381 :Command("Robot_TrajectoryDressUp")
00382 {
00383 sAppModule = "Robot";
00384 sGroup = QT_TR_NOOP("Robot");
00385 sMenuText = QT_TR_NOOP("Dress up trajectory...");
00386 sToolTipText = QT_TR_NOOP("Create a dress up object which overide som aspects of a trajectory");
00387 sWhatsThis = sToolTipText;
00388 sStatusTip = sToolTipText;
00389 sPixmap = "Robot_TrajectoryDressUp";
00390
00391 }
00392
00393
00394 void CmdRobotTrajectoryDressUp::activated(int iMsg)
00395 {
00396 Gui::SelectionFilter ObjectFilterDressUp("SELECT Robot::TrajectoryDressUpObject COUNT 1");
00397 Gui::SelectionFilter ObjectFilter("SELECT Robot::TrajectoryObject COUNT 1");
00398
00399 if (ObjectFilterDressUp.match()) {
00400 Robot::TrajectoryDressUpObject *Object = static_cast<Robot::TrajectoryDressUpObject*>(ObjectFilterDressUp.Result[0][0].getObject());
00401 openCommand("Edit Sketch");
00402 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Object->getNameInDocument());
00403 }else if (ObjectFilter.match()) {
00404 std::string FeatName = getUniqueObjectName("DressUpObject");
00405 Robot::TrajectoryObject *Object = static_cast<Robot::TrajectoryObject*>(ObjectFilter.Result[0][0].getObject());
00406 openCommand("Create a new TrajectoryDressUp");
00407 doCommand(Doc,"App.activeDocument().addObject('Robot::TrajectoryDressUpObject','%s')",FeatName.c_str());
00408 doCommand(Gui,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),Object->getNameInDocument());
00409 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Object->getNameInDocument());
00410 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00411 }else {
00412 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00413 QObject::tr("Select the Trajectory which you want to dress up."));
00414 return;
00415 }
00416 }
00417
00418 bool CmdRobotTrajectoryDressUp::isActive(void)
00419 {
00420 return true;
00421 }
00422
00423
00424
00425 DEF_STD_CMD_A(CmdRobotTrajectoryCompound);
00426
00427 CmdRobotTrajectoryCompound::CmdRobotTrajectoryCompound()
00428 :Command("Robot_TrajectoryCompound")
00429 {
00430 sAppModule = "Robot";
00431 sGroup = QT_TR_NOOP("Robot");
00432 sMenuText = QT_TR_NOOP("Trajectory compound...");
00433 sToolTipText = QT_TR_NOOP("Group and connect some trajectories to one");
00434 sWhatsThis = sToolTipText;
00435 sStatusTip = sToolTipText;
00436 sPixmap = "Robot_TrajectoryCompound";
00437
00438 }
00439
00440
00441 void CmdRobotTrajectoryCompound::activated(int iMsg)
00442 {
00443 Gui::SelectionFilter ObjectFilter("SELECT Robot::TrajectoryCompound COUNT 1");
00444
00445 if (ObjectFilter.match()) {
00446 Robot::TrajectoryCompound *Object = static_cast<Robot::TrajectoryCompound*>(ObjectFilter.Result[0][0].getObject());
00447 openCommand("Edit TrajectoryCompound");
00448 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",Object->getNameInDocument());
00449 }else {
00450 std::string FeatName = getUniqueObjectName("TrajectoryCompound");
00451
00452 openCommand("Create a new TrajectoryDressUp");
00453 doCommand(Doc,"App.activeDocument().addObject('Robot::TrajectoryCompound','%s')",FeatName.c_str());
00454 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00455 }
00456 }
00457
00458 bool CmdRobotTrajectoryCompound::isActive(void)
00459 {
00460 return true;
00461 }
00462
00463
00464
00465
00466
00467
00468
00469 void CreateRobotCommandsTrajectory(void)
00470 {
00471 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00472
00473 rcCmdMgr.addCommand(new CmdRobotCreateTrajectory());
00474 rcCmdMgr.addCommand(new CmdRobotInsertWaypoint());
00475 rcCmdMgr.addCommand(new CmdRobotInsertWaypointPreselect());
00476 rcCmdMgr.addCommand(new CmdRobotSetDefaultOrientation());
00477 rcCmdMgr.addCommand(new CmdRobotSetDefaultValues());
00478 rcCmdMgr.addCommand(new CmdRobotEdge2Trac());
00479 rcCmdMgr.addCommand(new CmdRobotTrajectoryDressUp());
00480 rcCmdMgr.addCommand(new CmdRobotTrajectoryCompound());
00481 }