TrajectorySimulate.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 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 
00026 #ifndef _PreComp_
00027 #endif
00028 
00029 #include <QTimer>
00030 #include "TrajectorySimulate.h"
00031 #include <Gui/Application.h>
00032 #include <Gui/Document.h>
00033 #include <Gui/BitmapFactory.h>
00034 #include <Gui/ViewProvider.h>
00035 #include <Gui/WaitCursor.h>
00036 #include <Base/Console.h>
00037 #include <Gui/Selection.h>
00038 
00039 #include <Mod/Robot/App/Waypoint.h>
00040 
00041 
00042 using namespace RobotGui;
00043 using namespace Gui;
00044 
00045 TrajectorySimulate::TrajectorySimulate(Robot::RobotObject *pcRobotObject,Robot::TrajectoryObject *pcTrajectoryObject,QWidget *parent)
00046     : QDialog( parent),
00047       sim(pcTrajectoryObject->Trajectory.getValue(),pcRobotObject->getRobot()),
00048       Run(false),
00049       block(false),
00050       timePos(0.0)
00051 {
00052     this->setupUi(this);
00053     QMetaObject::connectSlotsByName(this);
00054 
00055     // set Tool
00056     sim.Tool = pcRobotObject->Tool.getValue();
00057 
00058     trajectoryTable->setSortingEnabled(false);
00059 
00060     Robot::Trajectory trac = pcTrajectoryObject->Trajectory.getValue();
00061     trajectoryTable->setRowCount(trac.getSize());
00062     duration = trac.getDuration();
00063     timeSpinBox->setMaximum(duration);
00064 
00065     for(unsigned int i=0;i<trac.getSize();i++){
00066         Robot::Waypoint pt = trac.getWaypoint(i);
00067         switch(pt.Type){
00068             case Robot::Waypoint::UNDEF: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("UNDEF")));break;
00069             case Robot::Waypoint::CIRC: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("CIRC")));break;
00070             case Robot::Waypoint::PTP: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("PTP")));break;
00071             case Robot::Waypoint::LINE: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("LIN")));break;
00072             default: trajectoryTable->setItem(i, 0, new QTableWidgetItem(QString::fromAscii("UNDEF")));break;
00073         }
00074         trajectoryTable->setItem(i, 1, new QTableWidgetItem(QString::fromUtf8(pt.Name.c_str())));
00075         if(pt.Cont)
00076             trajectoryTable->setItem(i, 2, new QTableWidgetItem(QString::fromAscii("|")));
00077         else
00078             trajectoryTable->setItem(i, 2, new QTableWidgetItem(QString::fromAscii("-")));
00079         trajectoryTable->setItem(i, 3, new QTableWidgetItem(QString::number(pt.Velocity)));
00080         trajectoryTable->setItem(i, 4, new QTableWidgetItem(QString::number(pt.Accelaration)));
00081 
00082     }
00083 
00084     QObject::connect(ButtonStepStart    ,SIGNAL(clicked()),this,SLOT(start()));
00085     QObject::connect(ButtonStepStop     ,SIGNAL(clicked()),this,SLOT(stop()));
00086     QObject::connect(ButtonStepRun      ,SIGNAL(clicked()),this,SLOT(run()));
00087     QObject::connect(ButtonStepBack     ,SIGNAL(clicked()),this,SLOT(back()));
00088     QObject::connect(ButtonStepForward  ,SIGNAL(clicked()),this,SLOT(forward()));
00089     QObject::connect(ButtonStepEnd      ,SIGNAL(clicked()),this,SLOT(end()));
00090 
00091 
00092     // set up timer
00093     timer = new QTimer( this );
00094     timer->setInterval(100);
00095     QObject::connect(timer      ,SIGNAL(timeout ()),this,SLOT(timerDone()));
00096 
00097     QObject::connect( timeSpinBox       ,SIGNAL(valueChanged(double)), this, SLOT(valueChanged(double)) );
00098     QObject::connect( timeSlider        ,SIGNAL(valueChanged(int)   ), this, SLOT(valueChanged(int)) );
00099 
00100     // get the view provider
00101     ViewProv = dynamic_cast<ViewProviderRobotObject*>(Gui::Application::Instance->activeDocument()->getViewProvider(pcRobotObject) );
00102 
00103     setTo();
00104 }
00105 
00106 TrajectorySimulate::~TrajectorySimulate()
00107 {
00108 }
00109 
00110 void TrajectorySimulate::setTo(void)
00111 {
00112     sim.setToTime(timePos);
00113     ViewProv->setAxisTo(sim.Axis[0],sim.Axis[1],sim.Axis[2],sim.Axis[3],sim.Axis[4],sim.Axis[5],sim.Rob.getTcp());
00114 }
00115 
00116 void TrajectorySimulate::start(void)
00117 {
00118     timePos = 0.0f;
00119     timeSpinBox->setValue(timePos);
00120     timeSlider->setValue(int((timePos/duration)*1000));
00121     setTo();
00122 
00123 }
00124 void TrajectorySimulate::stop(void)
00125 {
00126     timer->stop();
00127     Run = false;
00128 }
00129 void TrajectorySimulate::run(void)
00130 {
00131     timer->start();
00132     Run = true;
00133 }
00134 void TrajectorySimulate::back(void)
00135 {
00136 }
00137 void TrajectorySimulate::forward(void)
00138 {
00139 }
00140 void TrajectorySimulate::end(void)
00141 {
00142     timePos = duration;
00143     timeSpinBox->setValue(timePos);
00144     timeSlider->setValue(int((timePos/duration)*1000));
00145     setTo();
00146 }
00147 
00148 void TrajectorySimulate::timerDone(void)
00149 {
00150     if(timePos < duration){
00151         timePos += .1f;
00152         timeSpinBox->setValue(timePos);
00153         timeSlider->setValue(int((timePos/duration)*1000));
00154         setTo();
00155         timer->start();
00156     }else{
00157         timer->stop();
00158         Run = false;
00159     }
00160 }
00161 
00162 void TrajectorySimulate::valueChanged ( int value )
00163 {
00164     if(!block){
00165         timePos = duration*(value/1000.0);
00166         block=true;
00167         timeSpinBox->setValue(timePos);
00168         block=false;
00169         setTo();
00170     }
00171 }
00172 
00173 void TrajectorySimulate::valueChanged ( double value )
00174 {
00175     if(!block){
00176         timePos = value;
00177         block=true;
00178         timeSlider->setValue(int((timePos/duration)*1000));
00179         block=false;
00180         setTo();
00181     }
00182 }
00183 
00184 
00185 #include "moc_TrajectorySimulate.cpp"

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