[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [brprint3d] /: Add Code
From:       Lays Rodrigues <laysrodriguessilva () gmail ! com>
Date:       2015-12-01 1:35:00
Message-ID: E1a3ZqO-0000XT-FO () scm ! kde ! org
[Download RAW message or body]

Git commit 34ac02fd790c4235f7a9bc7e12cae40705ac4319 by Lays Rodrigues.
Committed on 01/12/2015 at 01:23.
Pushed by laysrodrigues into branch 'master'.

Add Code

This class was write by Ayrton, however i'm adding
this code to the project.
This code also was write when we dont use git. So
dont have commits about the develop of this class.

Signed-off-by: Lays Rodrigues <laysrodriguessilva@gmail.com>

M  +111  -1    FilCount.cpp
M  +38   -3    FilCount.h

http://commits.kde.org/brprint3d/34ac02fd790c4235f7a9bc7e12cae40705ac4319

diff --git a/FilCount.cpp b/FilCount.cpp
index 12bb46f..1347f0a 100644
--- a/FilCount.cpp
+++ b/FilCount.cpp
@@ -1,7 +1,117 @@
+/*=====================================================================
+
+ BRPrint3D, Open Source 3D Printing Host
+
+ (c) 2015 BRPrint3D Authors
+
+ This file is part of the BRPrint3D project
+
+ BRPrint3D is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BRPrint3D 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with BRPrint3D. If not, see <http://www.gnu.org/licenses/>.
+
+ ======================================================================*/
+
 #include "FilCount.h"
 
-FilCount::FilCount()
+FilCount::FilCount(const char *filePath) throw (std::string)
+{
+    char instring[100001], *X, *Y, *Z;
+    bool first = true;
+    double vX[2], vY[2], vZ[2] /*0 - Inicial, 1 - Final*/, temp;
+    this->GCode = fopen(filePath, "rt");
+    if(this->GCode == NULL){
+        std::string exc = "Could not open the file: ";
+        exc+=filePath;
+        exc+=".";
+        throw exc;
+    }
+    this->filePath = (char*)malloc((strlen(filePath) + 1) * sizeof(char));
+    strcpy(this->filePath, filePath);
+    this->totalSize = 0.0;
+    while(fscanf(this->GCode, "%[^\n]\n", instring) != EOF){
+        if(!first){
+            if(instring[0] == 'G'){
+                X = strstr(instring, "X");
+                if(X != NULL){
+                    sscanf(X, "X%lf", &vX[1]);
+                }else{
+                    vX[1] = vX[0];
+                }
+                Y = strstr(instring, "Y");
+                if(Y != NULL){
+                    sscanf(Y, "Y%lf", &vY[1]);
+                }else{
+                    vY[1] = vY[0];
+                }
+                temp = sqrt(pow((vX[1] - vX[0]),2) + pow((vY[1] - vY[0]), 2));
+                vX[0] = vX[1];
+                vY[0] = vY[1];
+                Z = strstr(instring, "Z");
+                if(Z != NULL){
+                    sscanf(Z, "Z%lf", &vZ[1]);
+                    this->totalSize += sqrt(pow(temp, 2) + pow((vZ[1] - vZ[0]), 2));
+                    vZ[0] = vZ[1];
+                }else{
+                    this->totalSize += temp;
+                }
+            }
+        }else{
+            if(instring[0] == 'G'){
+                X = strstr(instring, "X");
+                if(X == NULL){
+                    vX[0] = vX[1] = 0;
+                }else{
+                    sscanf(X, "X%lf", &vX[0]);
+                }
+                Y = strstr(instring, "Y");
+                if(Y == NULL){
+                    vY[0] = vY[1] = 0;
+                }else{
+                    sscanf(Y, "Y%lf", &vY[0]);
+                }
+                Z = strstr(instring, "Z");
+                if(Z == NULL){
+                    vZ[0] = vZ[1] = 0;
+                }else{
+                    sscanf(Z, "Z%lf", &vZ[0]);
+                }
+                first = false;
+            }
+        }
+    }
+}
+
+FilCount::~FilCount()
 {
+    free(this->filePath);
+    this->filePath = NULL;
+    this->totalSize = 0.0;
+    fclose(this->GCode);
+    this->GCode = NULL;
+}
 
+double FilCount::getTotalSize()
+{
+    return this->totalSize;
 }
 
+std::string FilCount::getFilePath()
+{
+    std::string ret = this->filePath;
+    return ret;
+}
+
+long FilCount::getTimeInSeconds(double speed)
+{
+    return (long)(this->totalSize/speed);
+}
diff --git a/FilCount.h b/FilCount.h
index 5194c14..056b546 100644
--- a/FilCount.h
+++ b/FilCount.h
@@ -1,11 +1,46 @@
+/*=====================================================================
+
+ BRPrint3D, Open Source 3D Printing Host
+
+ (c) 2015 BRPrint3D Authors
+
+ This file is part of the BRPrint3D project
+
+ BRPrint3D is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BRPrint3D 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with BRPrint3D. If not, see <http://www.gnu.org/licenses/>.
+
+ ======================================================================*/
 #ifndef FILCOUNT_H
 #define FILCOUNT_H
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <iostream>
 
-class FilCount
-{
+class FilCount{
+private:
+    char *filePath;
+    FILE *GCode;
+    double totalSize;
 public:
-    FilCount();
+    FilCount(const char *filePath) throw (std::string);
+    ~FilCount();
+    double getTotalSize();
+    std::string getFilePath();
+    long getTimeInSeconds(double speed);
 };
 
+
 #endif // FILCOUNT_H

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic