qCNC 0.82-alpha
/home/trilog/Desktop/project/gui/Final/src/Gcode_dec.cpp
Go to the documentation of this file.
00001 
00041 #include "Gcode_dec.h"
00042 #include "global_includes.h"
00043 //#include "libtse.h"
00044 #include "mainwindow.h"
00045 
00046 gcode_linkedL firstptr;
00047 gcode_linkedL lastptr;
00048 double max_x;
00049 double max_y;
00050 double max_z;
00051 
00052 
00053 
00054 void Gcode_read(QString filename) {
00055     QStringList splitline;
00056     QString tempx;
00057     QString tempy;
00058     QString cmdtemp;
00059     QString temp;
00060     double x = 0.0;
00061     double y = 0.0;
00062     double z = 0.0;
00063     max_x = 0.0;
00064     max_y = 0.0;
00065     max_z = 0.0;
00066     firstptr.next = NULL;
00067     lastptr.next = NULL;
00068 
00069     double min_x = 0.0;
00070     double min_y = 0.0;
00071     double min_z = 0.0;
00072     if (filename.isEmpty()) {
00073         return;
00074     }
00075     QFile file(filename);
00076     QString line;
00077     if ( file.open(QFile::ReadOnly) ) {
00078         // file opened successfully
00079         QTextStream t( &file );        // use a text stream
00080         // until end of file...
00081         while ( !t.atEnd() ) {
00082             // read and parse the command line
00083             line = t.readLine();         // line of text excluding '\n'
00084         //    qDebug() << "Read line is "<< line << endl;
00085             if (line.isEmpty())
00086                 continue;
00087 
00088             splitline = line.split(" ");
00089             cmdtemp = splitline.at(0);
00090         //    qDebug() << splitline.size();
00091             if (splitline.at(0)[0] == 'N') {
00092             //    qDebug() << "Gcode_read | splitline.at(0)[0] : Found Line numbering. skipping\n";
00093                 temp = splitline.at(1);
00094                 if (splitline.size() <= 2) {
00095                     if ( temp.at(0) == 'X') {
00096                      //   qDebug() <<"Gcode_read | NULL : found X\n";
00097                         temp[0] = ' ';
00098                         x = temp.toDouble();
00099                     }
00100                     else if (temp.at(0) == 'Y') {
00101                     //    qDebug() <<"Gcode_read | NULL : found Y\n";
00102                         temp[0] = ' ';
00103                         y = temp.toDouble();
00104                     }
00105                     else if (temp.at(0) == 'Z') {
00106                        // qDebug() <<"Gcode_read | NULL : found Z\n";
00107                         temp[0] = ' ';
00108                         z = temp.toDouble();
00109                     }
00110                     if (temp.at(0) == 'M') {
00111                        // qDebug() <<"Gcode_read | NULL : found M instruction\n";
00112                         if (temp == "M30") {
00113                             qDebug() <<"Gcode_read | NULL : found M30. Terminate EOF reached\n";
00114                            // return;//exit(0);//return line;
00115                         }
00116 
00117                     }
00118 
00119                 }
00120                 else if (splitline.size() <=3 ) {
00121                     tempx = splitline.at(1);
00122                     tempy = splitline.at(2);
00123                     if ( tempx.at(0) == 'X') {
00124                        // qDebug() <<"Gcode_read | 3 : found X\n";
00125                         tempx[0] = ' ';
00126                         x = tempx.toDouble();
00127                     }
00128                     else if (tempx.at(0) == 'Y') {
00129                     //    qDebug() <<"Gcode_read | 3 : found Y\n";
00130                         tempx[0] = ' ';
00131                         y = tempx.toDouble();
00132                     }
00133                     else if (tempx.at(0) == 'Z') {
00134                      //   qDebug() <<"Gcode_read | 3 : found Z\n";
00135                         tempx[0] = ' ';
00136                         z = tempx.toDouble();
00137                     }
00138                     if (tempx.at(0) == 'M') {
00139                       //  qDebug() <<"Gcode_read | 3 : found M instruction\n";
00140                         if (tempx == "M30") {
00141                             qDebug() <<"Gcode_read | 3 : found M30. Terminate EOF reached\n";
00142                            // return;//exit(0);//return line;
00143                         }
00144 
00145                     }
00146                     if ( tempy.at(0) == 'X') {
00147                      //   qDebug() <<"Gcode_read | 3 : found X\n";
00148                         tempy[0] = ' ';
00149                         x = tempy.toDouble();
00150                     }
00151                     else if (tempy.at(0) == 'Y') {
00152                   //      qDebug() <<"Gcode_read | 3 : found Y\n";
00153                         tempy[0] = ' ';
00154                         y = tempy.toDouble();
00155                     }
00156                     else if (tempy.at(0) == 'Z') {
00157                  //       qDebug() <<"Gcode_read | 3 : found Z\n";
00158                         tempy[0] = ' ';
00159                         z = tempy.toDouble();
00160                     }
00161                     if (tempy.at(0) == 'M') {
00162                     //    qDebug() <<"Gcode_read | 3 : found M instruction\n";
00163                         if (tempy == "M30") {
00164                             qDebug() <<"Gcode_read | 3 : found M30. Terminate EOF reached\n";
00165                            // return;//exit(0);//return line;
00166                         }
00167 
00168                     }
00169 
00170                 }
00171             }
00172             else if (splitline.size() <= 1 && splitline.at(0)[0] != 'N') {
00173                 if (temp.at(0) == 'M') {
00174                   //  qDebug() <<"Gcode_read | NULL : found M instruction\n";
00175                     if (temp == "M30") {
00176                         qDebug() <<"Gcode_read | NULL : found M30. Terminate EOF reached\n";
00177                     }
00178 
00179                 }
00180                 if (temp.at(0) == 'G') {
00181                     qDebug() <<"Gcode_read | NULL : found G instruction\n";
00182 
00183 
00184                 }
00185             }
00186             //tempx = splitline.at(1);
00187             //tempy = splitline.at(2);
00188             if (x > max_x)
00189                 max_x = x;
00190             if (y >max_y)
00191                 max_y = y;
00192             if (z > max_z)
00193                 max_z = z;
00194             if (x < min_x)
00195                 min_x = x;
00196             if (y  < min_y)
00197                 min_y = y;
00198             if (z < min_z)
00199                 min_z = z;
00200 
00201            AppendtoList(&firstptr,x,y,z,&lastptr);
00202 
00203           //  qDebug() << x << " || "<< y << "\n" << z;
00204          //   qDebug() << "max values" <<max_x <<" || "<< max_y <<" || "<< max_z << endl;
00205          //    qDebug() << "min values" <<min_x <<" || "<< min_y <<" || "<< min_z << endl;
00206         }
00207 
00208         // Close the file
00209         file.close();
00210     }
00211 }
00212 
00213 
00214 gcode_linkedL *map_linkedlist (double *maxx, double *maxy, double *maxz ,gcode_linkedL *first, gcode_linkedL *last) {
00215 
00216     *first = firstptr;
00217     *maxx = max_x;
00218     *maxy = max_y;
00219     *maxz = max_z;
00220     if (lastptr.next != NULL)
00221         *last = lastptr;
00222     return NULL;
00223 }
00224 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines