├── g2m
├── g2m.h
├── calc_tolerance.hpp
├── CMakeLists.txt
├── nanotimer.hpp
├── point.hpp
├── canonMotion.cpp
├── linearMotion.hpp
├── canonMotionless.hpp
├── nanotimer.cpp
├── canonMotion.hpp
├── helicalMotion.hpp
├── canonLine.hpp
├── linearMotion.cpp
├── machineStatus.cpp
├── g2m.hpp
├── machineStatus.hpp
├── canonLine.cpp
├── canonMotionless.cpp
├── gplayer.hpp
├── g2m.cpp
└── helicalMotion.cpp
├── debian
├── compat
├── control
└── rules
├── .github
├── FUNDING.yml
└── workflows
│ ├── label.yml
│ └── main.yml
├── icons
└── qgcoder.png
├── doc
├── qgcoder-001.png
└── qgcoder-002.png
├── res.qrc
├── tests
└── ngc-urandom.sh
├── qgcoder.desktop
├── .gitignore
├── settings_dlg.h
├── view.h
├── README.md
├── settings_dlg.cpp
├── mainwin.h
├── main.cpp
├── qgcoder.pro
├── lex_analyzer.hpp
├── lex_analyzer.cpp
├── settings.ui
├── view.cpp
├── mainwin.cpp
├── mainwin.ui
└── LICENSE
/g2m/g2m.h:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/debian/compat:
--------------------------------------------------------------------------------
1 | 10
2 |
--------------------------------------------------------------------------------
/g2m/calc_tolerance.hpp:
--------------------------------------------------------------------------------
1 | #define CALC_TOLERANCE (1e-6)
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: koppi
2 | custom: 'https://koppi.github.io'
3 |
--------------------------------------------------------------------------------
/icons/qgcoder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QGCoder/qgcoder/HEAD/icons/qgcoder.png
--------------------------------------------------------------------------------
/doc/qgcoder-001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QGCoder/qgcoder/HEAD/doc/qgcoder-001.png
--------------------------------------------------------------------------------
/doc/qgcoder-002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/QGCoder/qgcoder/HEAD/doc/qgcoder-002.png
--------------------------------------------------------------------------------
/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | icons/qgcoder.png
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tests/ngc-urandom.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | N=$1; echo "F100"; cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | paste - - - | awk '{ print "G1 X"$1" Y"$2" Z"$3 }'|head -n $N; echo "M30"
4 |
--------------------------------------------------------------------------------
/qgcoder.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Encoding=UTF-8
3 | Version=1.0
4 | Name=qgcoder
5 | GenericName=qgcoder
6 | Comment=G-code editor with 3D preview
7 | Icon=/usr/share/icons/hicolor/256x256/apps/qgcoder.png
8 |
9 | Type=Application
10 | Categories=Engineering;
11 | MimeType=text/x.gcode
12 | Exec=qgcoder %f
13 | Terminal=false
14 |
--------------------------------------------------------------------------------
/debian/control:
--------------------------------------------------------------------------------
1 | Source: qgcoder
2 | Section: misc
3 | Priority: optional
4 | Maintainer: Jakob Flierl
5 | Uploaders: Jakob Flierl
6 | Build-Depends: debhelper (>= 7.0.50~), automake, libtool, qt5-qmake, qtbase5-dev, libqglviewer-dev-qt5, freeglut3-dev, libglew-dev
7 | Standards-Version: 3.9.1
8 | Homepage: https://github.com/QGCoder
9 | Vcs-Git: git://github.com/QGCoder/qgcoder
10 | Vcs-Browser: https://github.com/QGCoder/qgcoder
11 |
12 | Package: qgcoder
13 | Architecture: any
14 | Depends: ${shlibs:Depends}, ${misc:Depends}
15 | Description: qgcoder
16 | G-code editor with 3D preview.
17 |
--------------------------------------------------------------------------------
/.github/workflows/label.yml:
--------------------------------------------------------------------------------
1 | # This workflow will triage pull requests and apply a label based on the
2 | # paths that are modified in the pull request.
3 | #
4 | # To use this workflow, you will need to set up a .github/labeler.yml
5 | # file with configuration. For more information, see:
6 | # https://github.com/actions/labeler
7 |
8 | name: Labeler
9 | on: [pull_request]
10 |
11 | jobs:
12 | label:
13 |
14 | runs-on: ubuntu-latest
15 | permissions:
16 | contents: read
17 | pull-requests: write
18 |
19 | steps:
20 | - uses: actions/labeler@v2
21 | with:
22 | repo-token: "${{ secrets.GITHUB_TOKEN }}"
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | **.exe
2 |
3 | debug
4 | release
5 |
6 | Makefile.Debug
7 | Makefile.Release
8 | lib
9 |
10 | gcoder.pro.user*
11 |
12 | Makefile
13 |
14 | .moc
15 | .ui
16 | .obj
17 | .rcc
18 |
19 | **.swp
20 |
21 | *.o
22 |
23 | .qglviewer.xml
24 |
25 | bin
26 | gen
27 | target
28 |
29 | qgcoder
30 |
31 | build-stamp
32 | debian/qgcoder.debhelper.log
33 | debian/qgcoder.substvars
34 | debian/qgcoder/
35 | debian/files
36 |
37 | .qmake.stash
38 | gcoder-build-deps_0.0.0-ubuntu1_all.deb
39 | gcoder-build-deps_0.0.0-ubuntu1_amd64.buildinfo
40 | gcoder-build-deps_0.0.0-ubuntu1_amd64.changes
41 | x
42 |
43 | qgcoder.pro.user
44 |
45 | *.deb
46 | *.buildinfo
47 | *.changes
48 |
--------------------------------------------------------------------------------
/settings_dlg.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef SETTINGS_DLG_H
3 | #define SETTINGS_DLG_H
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include "ui_settings.h"
12 |
13 |
14 | class SettingsDialog : public QDialog , private Ui_Settings
15 | {
16 | Q_OBJECT
17 | public:
18 |
19 | SettingsDialog(QWidget* parent, QString& homedir);
20 |
21 | void setValues(QString& rs, QString& tbl, QString& gcode);
22 | QString rs274;
23 | QString tooltable;
24 | QString gcodefile;
25 |
26 | private:
27 | void onFileBrowse(int buttonNumber);
28 | QString home_dir;
29 |
30 | private slots:
31 | virtual void onFileBrowse1() {onFileBrowse(1);}
32 | virtual void onFileBrowse2() {onFileBrowse(2);}
33 | virtual void onFileBrowse3() {onFileBrowse(3);}
34 |
35 | virtual void onAccept();
36 | };
37 |
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/g2m/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project( g2m )
2 | cmake_minimum_required( VERSION 2.6 )
3 | set ( CMAKE_BUILD_TYPE Debug )
4 | add_definitions ( -Wall )
5 |
6 | find_package ( Qt4 REQUIRED )
7 |
8 | include ( ${QT_USE_FILE} )
9 | include_directories (
10 | ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
11 | ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR}
12 | )
13 |
14 | set ( g2m_HDRS
15 | g2m.hpp
16 | canonLine.hpp
17 | canonMotionless.hpp
18 | canonMotion.hpp
19 | linearMotion.hpp
20 | helicalMotion.hpp
21 | machineStatus.hpp
22 | nanotimer.hpp
23 | point.hpp
24 | gplayer.hpp
25 | )
26 |
27 | set ( g2m_SRCS
28 | g2m.cpp
29 | canonLine.cpp
30 | canonMotionless.cpp
31 | canonMotion.cpp
32 | linearMotion.cpp
33 | helicalMotion.cpp
34 | machineStatus.cpp
35 | nanotimer.cpp
36 | )
37 |
38 | # run qt MOC on these
39 | set( g2m_MOCS
40 | g2m.hpp
41 | gplayer.hpp
42 | )
43 |
44 | QT4_WRAP_CPP(MOCS ${g2m_MOCS})
45 |
46 | add_library (
47 | g2m
48 | SHARED
49 | ${g2m_SRCS}
50 | ${MOCS}
51 | )
52 | target_link_libraries ( g2m ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} )
53 |
54 | # install the shared library
55 | install(
56 | TARGETS g2m
57 | DESTINATION lib/g2m
58 | )
59 |
60 | # this installs the c++ include headers
61 | install(
62 | FILES ${g2m_HDRS}
63 | DESTINATION include/g2m
64 | PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
65 | )
66 |
--------------------------------------------------------------------------------
/view.h:
--------------------------------------------------------------------------------
1 | #ifndef VIEW_H
2 | #define VIEW_H
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 |
10 | #include "g2m.hpp"
11 |
12 | using namespace qglviewer;
13 | using namespace g2m;
14 |
15 | class View : public QGLViewer
16 | {
17 | Q_OBJECT;
18 | Q_PROPERTY(bool autoZoom READ autoZoom WRITE setAutoZoom RESET unsetAutoZoom);
19 |
20 | public:
21 | View(QWidget *parent = NULL);
22 | ~View();
23 |
24 | void resetCamView();
25 |
26 | void updateGLViewer() {
27 | #if QGLVIEWER_VERSION < 0x020700
28 | this->updateGL();
29 | #else
30 | this->update();
31 | #endif
32 | };
33 |
34 | bool autoZoom()const{ return _autoZoom; };
35 | void setAutoZoom(bool autoZoom){ _autoZoom = autoZoom; update(); };
36 | void unsetAutoZoom(){ _autoZoom = true; update(); };
37 |
38 | public slots:
39 | void close();
40 |
41 | void appendCanonLine(canonLine *l);
42 | void clear();
43 |
44 | void update();
45 |
46 | void keyPressEvent(QKeyEvent *e);
47 |
48 | protected:
49 | void init();
50 | void initializeGL();
51 |
52 | virtual void draw();
53 | virtual void fastDraw();
54 | virtual void postDraw();
55 |
56 | void drawObjects(bool simplified);
57 |
58 | private:
59 | Vec initialCameraPosition;
60 | Quaternion initialCameraOrientation;
61 |
62 | QMutex mutex;
63 |
64 | QSettings * settings;
65 |
66 | std::vector lines;
67 |
68 | bool dirty;
69 |
70 | double aabb[6];
71 |
72 | bool _autoZoom;
73 | };
74 |
75 | #endif // VIEW_H
76 |
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | An interactive G-code editing GUI.
4 |
5 | ## Installation
6 |
7 | * First install [https://github.com/QGCoder/libqgcodeeditor](https://github.com/QGCoder/libqgcodeeditor), a Qt5 designer widget plugin for editing G-code.
8 |
9 | * Next: clone, build and run ```qgcoder``` as follows:
10 | ```bash
11 | gh repo clone QGCoder/qgcoder && qgcoder
12 | qmake && make -j$(nproc)
13 | ./qgcoder
14 | ```
15 | or build and install a Ubuntu / Debian package as follows:
16 | ```bash
17 | gh repo clone QGCoder/qgcoder && cd qgcoder
18 | mk-build-deps -i -s sudo -t "apt --yes --no-install-recommends"
19 | dpkg-buildpackage -b -rfakeroot -us -uc
20 | sudo dpkg -i ../qgcoder*.deb
21 | sudo apt -f install
22 | ```
23 |
24 | – Tested with Ubuntu 24.04. - [](https://github.com/QGCoder/qgcoder/actions/workflows/main.yml)
25 |
26 | ## Overview
27 |
28 | When started first, you have to provide ```qgcoder``` three filenames, as seen in the following screenshot:
29 |
30 |
31 |
32 |
33 | A short [YouTube video](https://www.youtube.com/watch?v=9D3hMXP5-QM) shows, how you can interact inside ```qgcoder```.
34 |
35 | ## Author
36 |
37 | * **Jakob Flierl** - [koppi](https://github.com/koppi)
38 |
39 | ## Contributors
40 |
41 | * **ArcEye** - [ArcEye](https://github.com/ArcEye)
42 | * **Mark Pictor**
43 | * **Kazuyasu Hamada**
44 | * **Anders Wallin** - [aewallin](https://github.com/aewallin)
45 |
--------------------------------------------------------------------------------
/settings_dlg.cpp:
--------------------------------------------------------------------------------
1 | #include "settings_dlg.h"
2 | #include
3 |
4 | SettingsDialog::SettingsDialog(QWidget *parent, QString& homedir)
5 | :QDialog(parent)
6 | {
7 | QString str;
8 |
9 | // build the dialog from ui
10 | setupUi(this);
11 | home_dir = homedir;
12 |
13 | }
14 |
15 | void SettingsDialog::setValues(QString& rs, QString& tbl, QString& gcode)
16 | {
17 | le_path1->setText(rs274 = rs);
18 | le_path2->setText(tooltable = tbl);
19 | le_path3->setText(gcodefile = gcode);
20 | }
21 |
22 | void SettingsDialog::onFileBrowse(int buttonNumber)
23 | {
24 | QString pathStr;
25 | QString filename;
26 | QDir dir;
27 |
28 | if( buttonNumber == 1)
29 | {
30 | if(rs274.isEmpty())
31 | pathStr = "/usr/bin";
32 | else
33 | pathStr = dir.absoluteFilePath(rs274);
34 | }
35 | else if(buttonNumber == 2)
36 | {
37 | if(tooltable.isEmpty())
38 | pathStr = home_dir + "machinekit/configs";
39 | else
40 | pathStr = dir.absoluteFilePath(tooltable);
41 | }
42 | else
43 | {
44 | if(gcodefile.isEmpty())
45 | pathStr = "/tmp";
46 | else
47 | pathStr = dir.absoluteFilePath(gcodefile);
48 | }
49 |
50 | filename = QFileDialog::getOpenFileName(this, tr("Settings Paths"), pathStr, tr("All files (*)"));
51 | if(filename.length())
52 | {
53 | if( buttonNumber == 1)
54 | le_path1->setText(filename);
55 | else if(buttonNumber == 2)
56 | le_path2->setText(filename);
57 | else
58 | le_path3->setText(filename);
59 | }
60 | }
61 |
62 | void SettingsDialog::onAccept()
63 | {
64 | rs274 = le_path1->text();
65 | tooltable = le_path2->text();
66 | gcodefile = le_path3->text();
67 |
68 | QDialog::accept();
69 | }
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/mainwin.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include "view.h"
11 | #include "g2m.hpp"
12 | #include "settings_dlg.h"
13 |
14 | namespace Ui {
15 | class MainWindow;
16 | }
17 |
18 | class MainWindow : public QMainWindow
19 | {
20 | Q_OBJECT
21 |
22 | public:
23 | explicit MainWindow(QWidget *parent = 0, bool fileMode = false, QString fileName = "");
24 | ~MainWindow();
25 |
26 | void parseGcode();
27 | void parseCommand();
28 |
29 | signals:
30 | void setRS274(QString s);
31 | void setToolTable(QString s);
32 | void setGcodeFile(QString f);
33 | void interpret();
34 |
35 | public slots:
36 | // load the last command string from the settings
37 | // used during startup
38 | virtual void loadSettingsCommand();
39 | virtual void loadGCodeFile();
40 |
41 | virtual void changedGcode();
42 | virtual void changedCommand();
43 |
44 | virtual void onOpenFile();
45 | virtual void onSaveAs();
46 | virtual int onSettings();
47 |
48 | virtual void appendCanonLine(g2m::canonLine*);
49 |
50 | virtual void toggleAutoZoom();
51 | virtual void showFullScreen();
52 | virtual void zoomIn();
53 | virtual void zoomOut();
54 |
55 | virtual void helpIssues();
56 | virtual void helpChat();
57 |
58 | protected:
59 | void loadSettings();
60 | void saveSettings();
61 |
62 | private: // functions
63 | int openInViewer(QString filename);
64 | void openInBrowser(QString filename);
65 | int saveInBrowser(QString& filename);
66 |
67 | void closeEvent(QCloseEvent *) Q_DECL_OVERRIDE;
68 |
69 | void setStyle();
70 |
71 | private: // data
72 | QString home_dir, openFile;
73 | bool bFileMode = false;
74 |
75 | QString rs274;
76 | QString tooltable;
77 | QString gcodefile;
78 |
79 | Ui::MainWindow *ui;
80 |
81 | View *view;
82 |
83 | g2m::g2m *g2m;
84 |
85 | int fontSize;
86 |
87 | QSettings *settings;
88 | };
89 |
90 | #endif // MAINWINDOW_H
91 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "mainwin.h"
4 |
5 | #define APP_VERSION QString("2016")
6 | #define APP_NAME QString("gcoder")
7 | #define APP_NAME_FULL QString("GCoder")
8 | #define APP_ORGANIZATION QString("gcoder.koppi.github.com")
9 |
10 | int main(int argv, char **args)
11 | {
12 | QSharedPointer app;
13 |
14 | // workaround for https://forum.qt.io/topic/53298/qcommandlineparser-to-select-gui-or-non-gui-mode
15 |
16 | // On Linux: enable printing of version and help without DISPLAY variable set
17 |
18 | bool runCore = false;
19 | for (int i = 0; i < argv; i++) {
20 | if (QString(args[i]) == "-h" ||
21 | QString(args[i]) == "--help" ||
22 | QString(args[i]) == "-v" ||
23 | QString(args[i]) == "--version" ) {
24 | runCore = true;
25 | break;
26 | }
27 | }
28 |
29 | if (runCore) {
30 | app = QSharedPointer(new QCoreApplication(argv, args));
31 | } else {
32 | app = QSharedPointer(new QApplication(argv, args));
33 | }
34 |
35 | // end workaround
36 |
37 | setlocale(LC_NUMERIC,"C");
38 |
39 | //XXX app->setStyleSheet("QPlainTextEdit{ selection-background-color: darkblue } QWidget { font-size: 12pt; font-family: \"Courier\"; background-color: #00003B; color: #FFA700; font: bold }");
40 |
41 | QCoreApplication::setOrganizationName(APP_ORGANIZATION);
42 | QCoreApplication::setApplicationName(APP_NAME);
43 | QCoreApplication::setApplicationVersion(APP_VERSION);
44 | QCommandLineParser parser;
45 |
46 | parser.setApplicationDescription(QCoreApplication::applicationName());
47 | parser.addHelpOption();
48 | parser.addVersionOption();
49 | parser.addPositionalArgument("file", "The G-code file to open.");
50 |
51 | parser.process(*app);
52 |
53 | MainWindow *win;
54 |
55 | if (!parser.positionalArguments().isEmpty()) {
56 | win = new MainWindow(NULL, !parser.positionalArguments().isEmpty(), parser.positionalArguments().first());
57 | } else {
58 | win = new MainWindow();
59 | }
60 |
61 | win->show();
62 |
63 | return app->exec();
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/g2m/nanotimer.hpp:
--------------------------------------------------------------------------------
1 | // adapted from http://allmybrain.com/2008/06/10/timing-cc-code-on-linux/
2 | /**************************************************************************
3 | * Copyright (C) 2010 by Mark Pictor *
4 | * mpictor@gmail.com *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | **************************************************************************/
21 | #ifndef NANOTIMER_HH
22 | #define NANOTIMER_HH
23 |
24 | #include
25 | #include
26 |
27 | namespace g2m {
28 |
29 | /// a timing class for benchmarking and debugging.
30 | class nanotimer {
31 | private:
32 | /// time-stamp when start() was called
33 | timespec begin;
34 | public:
35 | nanotimer() {}
36 | /// start the timer()
37 | void start();
38 | /// return nanoseconds since start()
39 | long getElapsed();
40 | /// return seconds since start()
41 | double getElapsedS();
42 | /// return a QString with seconds, milliseconds, microseconds
43 | static QString humanreadable(double s);
44 | };
45 |
46 | }
47 | #endif //NANOTIMER_HH
48 |
--------------------------------------------------------------------------------
/debian/rules:
--------------------------------------------------------------------------------
1 | #!/usr/bin/make -f
2 |
3 | # Uncomment this to turn on verbose mode.
4 | export DH_VERBOSE=1
5 |
6 | CXXFLAGS = -Wall -g
7 |
8 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
9 | CXXFLAGS += -O0
10 | else
11 | CXXFLAGS += -O2
12 | endif
13 | ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
14 | INSTALL_PROGRAM += -s
15 | endif
16 |
17 | QMAKE_AFTER = -after \
18 | 'QMAKE_CXXFLAGS_RELEASE = $(CXXFLAGS)' \
19 | 'QMAKE_POST_LINK ~= s/strip/:'
20 |
21 | build: build-stamp
22 | build-stamp: $(QUILT_STAMPFN)
23 | dh_testdir
24 |
25 | qmake $(QMAKE_AFTER) qgcoder.pro && $(MAKE)
26 |
27 | touch $@
28 |
29 | clean:
30 | dh_testdir
31 | dh_testroot
32 | rm -f build-stamp
33 | [ ! -f Makefile ] || $(MAKE) clean
34 | dh_clean
35 |
36 | install: build
37 | dh_testdir
38 | dh_testroot
39 | dh_clean -k
40 | dh_installdirs
41 |
42 | $(MAKE) INSTALL_ROOT=$(CURDIR)/debian/qgcoder install
43 |
44 | # install -d -v -m 0755 $(CURDIR)/debian/qgcoder/usr/share/applications
45 | # chmod 664 $(CURDIR)/debian/qgcoder/usr/share/applications/qgcoder.desktop
46 |
47 | # install -d -v -m 0755 $(CURDIR)/debian/qgcoder/usr/share/icons/hicolor/scalable/apps
48 | # chmod 664 $(CURDIR)/debian/qgcoder/usr/share/icons/hicolor/scalable/apps/qgcoder.svg
49 |
50 | install -d -v -m 0755 $(CURDIR)/debian/qgcoder/usr/bin
51 | install -m 755 -p qgcoder $(CURDIR)/debian/qgcoder/usr/bin/qgcoder
52 |
53 | # Build architecture-independent files here.
54 | binary-indep: build install
55 | dh_testdir
56 | dh_testroot
57 | # dh_installchangelogs ChangeLog
58 | dh_installdocs -i
59 | dh_install -i
60 | dh_installman -i
61 | dh_compress -i --exclude=.cpp --exclude=.pri
62 | dh_fixperms
63 | dh_installdeb
64 | dh_gencontrol
65 | dh_md5sums
66 | dh_builddeb
67 |
68 | # Build architecture-dependent files here.
69 | binary-arch: build install
70 | dh_testdir
71 | dh_testroot
72 | # dh_installchangelogs ChangeLog
73 | dh_installdocs -s README.md
74 | dh_install -s --sourcedir=$(CURDIR)/debian/tmp
75 | # dh_installman qgcoder.1
76 | dh_installmime
77 | dh_installmenu
78 | dh_link
79 | dh_strip
80 | dh_compress -s
81 | dh_fixperms
82 | dh_makeshlibs
83 | dh_installdeb
84 | dh_shlibdeps
85 | dh_gencontrol
86 | dh_md5sums
87 | dh_builddeb
88 |
89 | binary: binary-indep binary-arch
90 | .PHONY: build clean binary-indep binary-arch binary install configure
91 |
--------------------------------------------------------------------------------
/g2m/point.hpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #ifndef POINT_HPP
6 | #define POINT_HPP
7 |
8 | //#include
9 |
10 | namespace g2m {
11 |
12 | /// a point in 3D space
13 | struct Point {
14 | /// Create point at (0,0,0)
15 | Point():x(0),y(0),z(0) {}
16 | /// Create point at given coordinates
17 | Point(double a, double b, double c):x(a),y(b),z(c) {}
18 | /// copy-constructor
19 | Point(const Point& other): x(other.x),y(other.y),z(other.z) {}
20 | /// distance to given other Point
21 | double Distance( Point other ) {
22 | return sqrt( (other.x-x)*(other.x-x) + (other.y-y)*(other.y-y) + (other.z-z)*(other.z-z) );
23 | }
24 | /// string representation
25 | std::string str() const {
26 | std::ostringstream o;
27 | o << "(" << x << ", " << y << ", " << z << ")";
28 | return o.str();
29 | }
30 | /// multiply Point with scalar
31 | Point& operator*=(const double &a) {
32 | x*=a;
33 | y*=a;
34 | z*=a;
35 | return *this;
36 | }
37 | /// multiply Point with scalar
38 | Point operator*(const double &a) const {
39 | return Point(*this) *= a;
40 | }
41 | /// vector addition
42 | Point& operator+=( const Point& p) {
43 | x+=p.x;
44 | y+=p.y;
45 | z+=p.z;
46 | return *this;
47 | }
48 |
49 | /// vector addition
50 | const Point operator+( const Point &p) const {
51 | return Point(*this) += p;
52 | }
53 |
54 | /// vector subtraction
55 | Point& operator-=( const Point& p) {
56 | x-=p.x;
57 | y-=p.y;
58 | z-=p.z;
59 | return *this;
60 | }
61 | /// vector subtraction
62 | const Point operator-( const Point &p) const {
63 | return Point(*this) -= p;
64 | }
65 |
66 | // DATA
67 | /// x-coordinate
68 | double x;
69 | /// y-coordinate
70 | double y;
71 | /// z-coordinate
72 | double z;
73 | };
74 |
75 | /// a pose is a complete 6-dimensional description of the position and rotation
76 | /// of an object in 3D space (e.g. a tool). This includes the position of the origin
77 | /// of the tool (loc) and the direction of the tool axis (dir)
78 | struct Pose {
79 | Pose() {}
80 | /// Create Pose with given location and direction
81 | /// \param a location
82 | /// \param b direction
83 | Pose( Point a, Point b ) {
84 | loc = a;
85 | dir = b;
86 | }
87 | /// location
88 | Point loc;
89 | /// direction -> angle
90 | Point dir;
91 | };
92 |
93 | } // end namespace
94 | #endif
95 |
--------------------------------------------------------------------------------
/g2m/canonMotion.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 |
22 | #include
23 | #include
24 |
25 | #include "canonMotion.hpp"
26 | #include "canonLine.hpp"
27 | #include "point.hpp"
28 |
29 | namespace g2m {
30 |
31 | canonMotion::canonMotion(std::string canonL, machineStatus prevStatus): canonLine(canonL,prevStatus) {
32 |
33 | }
34 |
35 | /// for STRAIGHT_* and ARC_FEED, first 3 are always xyz and last 3 always abc
36 | Pose canonMotion::getPoseFromCmd() {
37 | double x,y,z;
38 |
39 | //need 3,4,5,and -3,-2,-1
40 | x = tok2d(3);
41 | y = tok2d(4);
42 | z = tok2d(5);
43 | Point p(x,y,z);
44 |
45 | /* FIXME */
46 | double a,b,c;
47 | int s = canonTokens.size(); //a,b,c are last 3 numbers
48 | c = tok2d(s-1);
49 | b = tok2d(s-2);
50 | a = tok2d(s-3);
51 | // assert (a+b+c < 3.0 * Precision::Confusion());
52 | //now how to convert those angles to a unit vector (i.e. gp_Dir)?
53 |
54 | //for now we take the easy way out
55 |
56 | // Point d(0,0,1); //vertical, NO ROTATION!
57 | Point d(a,b,c);
58 | return Pose(p,d);
59 | }
60 |
61 | } // end namespace
62 |
--------------------------------------------------------------------------------
/g2m/linearMotion.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 | #ifndef LINEARMOTION_HH
22 | #define LINEARMOTION_HH
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include "canonMotion.hpp"
30 | #include "machineStatus.hpp"
31 |
32 | namespace g2m {
33 |
34 | /**
35 | \class linearMotion
36 | \brief For the canonical commands STRAIGHT_FEED and STRAIGHT_TRAVERSE.
37 | This class inherits from canonMotion.
38 | */
39 |
40 | class linearMotion: protected canonMotion {
41 | friend canonLine* canonLine::canonLineFactory(std::string l, machineStatus s);
42 | public:
43 | /// create linear motion
44 | linearMotion(std::string canonL, machineStatus prevStatus);
45 | MOTION_TYPE getMotionType();
46 | //std::vector points(); // points sampled along the motion
47 | /// return interpolated point along this move, a distance s from the start of the move
48 | Point point(double s);
49 | // std::cout << " linear feed: " << start.str() << " to " << end.str() << "\n";
50 | Point end;
51 | #ifdef MULTI_AXIS
52 | Point angle(double s);
53 | #endif
54 | /// return length of this move
55 | double length();
56 | };
57 |
58 | } // end namespace
59 |
60 | #endif //LINEARMOTION_HH
61 |
--------------------------------------------------------------------------------
/g2m/canonMotionless.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * *
5 | * This program is free software; you can redistribute it and/or modify *
6 | * it under the terms of the GNU General Public License as published by *
7 | * the Free Software Foundation; either version 2 of the License, or *
8 | * (at your option) any later version. *
9 | * *
10 | * This program is distributed in the hope that it will be useful, *
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 | * GNU General Public License for more details. *
14 | * *
15 | * You should have received a copy of the GNU General Public License *
16 | * along with this program; if not, write to the *
17 | * Free Software Foundation, Inc., *
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 | ***************************************************************************/
20 | #ifndef CANONMOTIONLESS_HH
21 | #define CANONMOTIONLESS_HH
22 |
23 | #include
24 | #include
25 |
26 | #include
27 | #include
28 |
29 | #include "canonLine.hpp"
30 | #include "machineStatus.hpp"
31 |
32 | namespace g2m {
33 |
34 | /**
35 | \class canonMotionless
36 | \brief A canonical command that (generally) does not cause or alter axis motion
37 | This class is for anything other than STRAIGHT_FEED, STRAIGHT_TRAVERSE, and ARC_FEED -
38 | * including changes in feedrate, spindle speed, tool, coolant, ending the program, etc
39 | */
40 |
41 | class canonMotionless: protected canonLine {
42 | friend canonLine* canonLine::canonLineFactory(std::string l, machineStatus s);
43 | public:
44 | /// create motionless canon-line
45 | canonMotionless(std::string canonL, machineStatus prevStatus);
46 | /// return false
47 | bool isMotion() {return false;};
48 | /// return type of motion
49 | MOTION_TYPE getMotionType() {return MOTIONLESS;};
50 | ///returns true if this command is a valid terminator for the NC file (i.e.
51 | bool isNCend() {return ncEnd;};
52 | protected:
53 | /// flag(?)
54 | bool match;
55 | /// flag indicating that this canon-line is handled
56 | bool handled;
57 | /// flag indicating end of g-code program
58 | bool ncEnd;
59 | };
60 |
61 | } // end namespace
62 |
63 | #endif //CANONMOTIONLESS_HH
64 |
--------------------------------------------------------------------------------
/qgcoder.pro:
--------------------------------------------------------------------------------
1 | TARGET = qgcoder
2 |
3 | TEMPLATE = app
4 |
5 | CONFIG += link_pkgconfig
6 |
7 | QMAKE_CXXFLAGS_RELEASE += -O2
8 | QMAKE_CXXFLAGS_DEBUG += -O0
9 |
10 | QMAKE_CXXFLAGS += -Wno-deprecated-copy
11 |
12 | MOC_DIR = .moc
13 | #OBJECTS_DIR = .obj
14 | UI_DIR = .ui
15 | RCC_DIR = .rcc
16 |
17 | CONFIG += qgcodeeditor
18 | CONFIG += qglviewer
19 |
20 | INCLUDEPATH += g2m
21 | INCLUDEPATH += /usr/include/QGCodeEditor
22 |
23 | HEADERS = \
24 | mainwin.h \
25 | view.h \
26 | g2m/canonLine.hpp g2m/canonMotionless.hpp g2m/gplayer.hpp g2m/linearMotion.hpp g2m/nanotimer.hpp \
27 | g2m/canonMotion.hpp g2m/g2m.hpp g2m/helicalMotion.hpp g2m/machineStatus.hpp g2m/point.hpp \
28 | lex_analyzer.hpp settings_dlg.h
29 |
30 |
31 | SOURCES = \
32 | main.cpp \
33 | mainwin.cpp \
34 | view.cpp \
35 | g2m/canonLine.cpp g2m/canonMotionless.cpp g2m/helicalMotion.cpp g2m/machineStatus.cpp \
36 | g2m/canonMotion.cpp g2m/g2m.cpp g2m/linearMotion.cpp g2m/nanotimer.cpp \
37 | lex_analyzer.cpp settings_dlg.cpp
38 |
39 | target.path = /usr/bin
40 |
41 | INSTALLS += target
42 |
43 | FORMS += \
44 | mainwin.ui settings.ui
45 |
46 | link_pkgconfig {
47 | # message("Using pkg-config "$$system(pkg-config --version)".")
48 |
49 | LSB_RELEASE_ID = $$system(. /etc/os-release; echo "$NAME")
50 | LSB_RELEASE_REL = $$system(. /etc/os-release; echo "$VERSION_ID")
51 |
52 | message(This is $$LSB_RELEASE_ID $$LSB_RELEASE_REL)
53 |
54 | contains(LSB_RELEASE_ID, Ubuntu): {
55 | contains(LSB_RELEASE_REL, 21.04) : {
56 | LIBS += -lQGLViewer-qt5 -lGLEW -lGLU -lGL -lglut
57 | }
58 | contains(LSB_RELEASE_REL, 22.04) : {
59 | LIBS += -lQGLViewer-qt5 -lGLEW -lGLU -lGL -lglut
60 | }
61 | contains(LSB_RELEASE_REL, 22.10) : {
62 | LIBS += -lQGLViewer-qt5 -lGLEW -lGLU -lGL -lglut
63 | }
64 | contains(LSB_RELEASE_REL, 24.04) : {
65 | LIBS += -lQGLViewer-qt5 -lGLEW -lGLU -lGL -lglut
66 | }
67 | } else {
68 | LIBS += -lQGLViewer-qt5 -lGLEW -lGLU -lGL -lglut
69 | }
70 | }
71 |
72 | CONFIG *= debug_and_release
73 | CONFIG *= qt opengl
74 | CONFIG += warn_on
75 | CONFIG += thread
76 |
77 | QT *= opengl xml gui core
78 |
79 | OTHER_FILES += README.md
80 |
81 | unix {
82 | qgcoder-deskop.path = /usr/share/applications
83 | qgcoder-deskop.files = qgcoder.desktop
84 | qgcoder-icon.path = /usr/share/icons/hicolor/256x256/apps
85 | qgcoder-icon.files = icons/qgcoder.png
86 |
87 | INSTALLS += qgcoder-deskop
88 | INSTALLS += qgcoder-icon
89 | }
90 |
91 | DIRS_DC = object_script.* .ui .moc .rcc .obj *.pro.user $$TARGET
92 |
93 | unix:QMAKE_DISTCLEAN += -r $$DIRS_DC
94 | win32:QMAKE_DISTCLEAN += /s /f /q $$DIRS_DC && rd /s /q $$DIRS_DC
95 |
96 | DISTFILES += \
97 | icons/qgcoder.png
98 |
99 | RESOURCES += \
100 | res.qrc
101 |
102 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | on:
2 | push:
3 | branches: [ main ]
4 | pull_request:
5 | branches: [ main ]
6 |
7 | jobs:
8 | build:
9 | name: ${{ matrix.target }}
10 | strategy:
11 | fail-fast: false
12 | matrix:
13 | target:
14 | - ubuntu-latest
15 | runs-on: ${{ matrix.target }}
16 | steps:
17 | - uses: actions/checkout@v3
18 |
19 | - name: Install devscripts
20 | run: |
21 | sudo apt update -qq
22 | sudo apt full-upgrade -y
23 | sudo DEBIAN_FRONTEND=noninteractive apt -qq -y install devscripts equivs lintian
24 | mk-build-deps -i -s sudo -t "apt --yes --no-install-recommends"
25 |
26 | - name: Build source package
27 | env:
28 | DEBFULLNAME: "Github Actions"
29 | DEBEMAIL: "jakob.flierl@gmail.com"
30 | run: |
31 | export TARGET=$(. /etc/lsb-release && echo $DISTRIB_CODENAME)
32 | git fetch --unshallow
33 | git fetch --tags
34 | VERSION="$(git tag -l | tail -n1 | sed -e "s/^v//" -e "s/-/+git/")"
35 | dch --create \
36 | --distribution ${TARGET} \
37 | --package qgcoder \
38 | --newversion ${VERSION}~${TARGET}1 \
39 | "Automatic build from Github"
40 | debuild -S -sa -us -uc -d
41 |
42 | - name: Build and install libqgcodeeditor
43 | env:
44 | DEBFULLNAME: "Jakob Flierl"
45 | DEBEMAIL: "jakob.flierl@gmail.com"
46 | run: |
47 | git clone https://github.com/QGCoder/libqgcodeeditor
48 | pushd libqgcodeeditor
49 | export TARGET=$(. /etc/lsb-release && echo $DISTRIB_CODENAME)
50 | VERSION="$(git tag -l | tail -n1 | sed -e "s/^v//" -e "s/-/+git/")"
51 | dch --create \
52 | --distribution ${TARGET} \
53 | --package libqgcodeeditor \
54 | --newversion ${VERSION}~${TARGET}1 \
55 | "Automatic build from Github"
56 | debuild -S -sa -us -uc -d
57 | mk-build-deps -i -s sudo -t "apt --yes --no-install-recommends"
58 | dpkg-buildpackage -b -rfakeroot -us -uc
59 | sudo dpkg -i ../libqgcodeeditor*deb
60 | sudo apt -y -f install
61 | qmake && make && sudo make install # fixme
62 | popd
63 |
64 | - name: Build binary package
65 | run: dpkg-buildpackage -b -rfakeroot -us -uc
66 |
67 | - name: Install binary package
68 | run: sudo dpkg -i ../qgcoder*deb
69 |
70 | - name: Install binary package dependencies
71 | run: sudo apt -f install
72 |
73 | - name: Run lintian
74 | run: lintian ../qgcoder*deb | lintian-info
75 |
76 | - name: Upload artifacts
77 | uses: actions/upload-artifact@v4
78 | with:
79 | name: ${{ matrix.target }}
80 | if-no-files-found: error
81 | path: |
82 | *.buildinfo
83 | *.changes
84 | *.dsc
85 | *.tar.*
86 | *.deb
87 | ~/**/*/*.buildinfo
88 | ~/**/*/*.changes
89 | ~/**/*/*.dsc
90 | ~/**/*/*.tar.*
91 | ~/**/*/*.deb
92 |
93 |
94 |
--------------------------------------------------------------------------------
/g2m/nanotimer.cpp:
--------------------------------------------------------------------------------
1 | // adapted from http://allmybrain.com/2008/06/10/timing-cc-code-on-linux/
2 |
3 | /**************************************************************************
4 | * Copyright (C) 2010 by Mark Pictor *
5 | * mpictor@gmail.com *
6 | * *
7 | * This program is free software; you can redistribute it and/or modify *
8 | * it under the terms of the GNU General Public License as published by *
9 | * the Free Software Foundation; either version 2 of the License, or *
10 | * (at your option) any later version. *
11 | * *
12 | * This program is distributed in the hope that it will be useful, *
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 | * GNU General Public License for more details. *
16 | * *
17 | * You should have received a copy of the GNU General Public License *
18 | * along with this program; if not, write to the *
19 | * Free Software Foundation, Inc., *
20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 | **************************************************************************/
22 |
23 | #include
24 | #include
25 |
26 | #include "nanotimer.hpp"
27 |
28 | //clock_gettime requires librt
29 | //CLOCK_MONOTONIC_RAW requires kernel 2.6.28 and libc6 >> 2.11.2
30 | //with earlier kernels use CLOCK_MONOTONIC or CLOCK_REALTIME
31 |
32 | namespace g2m {
33 |
34 | #ifndef CLOCK_MONOTONIC_RAW
35 | #define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
36 | #endif
37 |
38 |
39 |
40 | void nanotimer::start() {
41 | clock_gettime(CLOCK_MONOTONIC_RAW, &begin);
42 | }
43 |
44 | long nanotimer::getElapsed(){
45 | timespec now,delta;
46 | clock_gettime(CLOCK_MONOTONIC_RAW, &now);
47 | delta.tv_sec = now.tv_sec - begin.tv_sec;
48 | delta.tv_nsec = now.tv_nsec - begin.tv_nsec;
49 | return delta.tv_sec*1000000000 + delta.tv_nsec;
50 | }
51 |
52 | double nanotimer::getElapsedS(){
53 | timespec now,delta;
54 | clock_gettime(CLOCK_MONOTONIC_RAW, &now);
55 | delta.tv_sec = now.tv_sec - begin.tv_sec;
56 | delta.tv_nsec = now.tv_nsec - begin.tv_nsec;
57 | return delta.tv_sec + delta.tv_nsec/1000000000.0;
58 | }
59 |
60 | QString nanotimer::humanreadable(double s) {
61 | QString out;
62 | if (s > 60) {
63 | int m;
64 | m = s/60;
65 | s = s-(double)(m*60);
66 | out = QString::number(m) + QString("m, ");
67 | }
68 | if (s > .5) {
69 | out += QString::number(s);
70 | out += QString(" s");
71 | } else if (s> 0.0005) {
72 | out = QString::number(s*1000);
73 | out += QString(" ms");
74 | } else {
75 | out = QString::number(s*1000000);
76 | out += QString(" us");
77 | }
78 | return out;
79 | }
80 |
81 |
82 | } // end namespace
83 |
--------------------------------------------------------------------------------
/lex_analyzer.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 | #ifndef LEX_ANALIZER_HH
22 | #define LEX_ANALIZER_HH
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | namespace lex_analyzer {
33 | /**
34 | \class LexAnalyzer
35 | \brief A canonLine object represents one canonical command.
36 | Each gcode line produces one or more canonical commands. It can either be a
37 | * motion command (one of LINEAR_TRAVERSE LINEAR_FEED ARC_FEED), or a motionless
38 | * command (anything else)
39 | You cannot create objects of this class - instead, create an object of a class
40 | * that inherits from this class via canonLineFactory()
41 | */
42 | class LexAnalyzer {
43 |
44 | public:
45 | LexAnalyzer(std::string line): myLine(line) {
46 | tokenize(myLine, tokens);
47 | }
48 | /// return the line as a string
49 | const std::string getLine() { return myLine; };
50 | /// return the n:th token
51 | std::string getToken(unsigned int n);
52 |
53 | // keyword matching
54 | bool wordMatch(std::string word, unsigned int n = 0);
55 | // get double number
56 | double token2d(unsigned int n);
57 | // get integer number
58 | int token2i(unsigned int n, unsigned int offset = 0);
59 |
60 | protected:
61 | // tokenizer
62 | void tokenize(std::string str, std::vector& tokenV, const std::string& delimiters = "(), \t");
63 |
64 | // DATA
65 | /// the line as a string
66 | std::string myLine;
67 | /// the tokens in this line, set after tokenizing myLine
68 | std::vector tokens;
69 | };
70 |
71 | } // end namespace
72 |
73 | #endif //LEX_ANALIZER_HH
74 |
--------------------------------------------------------------------------------
/g2m/canonMotion.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 | #ifndef CANONMOTION_HH
22 | #define CANONMOTION_HH
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include "machineStatus.hpp"
30 | #include "canonLine.hpp"
31 |
32 | namespace g2m {
33 |
34 | /**
35 | \class canonMotion
36 | \brief This class is for the canonical commands STRAIGHT_TRAVERSE, STRAIGHT_FEED, and ARC_FEED.
37 | canonMotion is an ABC. Its children should only be instantiated via
38 | * canonLine::canonLineFactory(), which creates
39 | * linearMotion objects for STRAIGHT_TRAVERSE and STRAIGHT_FEED commands,
40 | * and helicalMotion objects for ARC_FEED commands.
41 |
42 | Note, you may find variations in the terminology I use - I misremembered some of
43 | * the canonical commands issued by the interpreter. For example, I thought it
44 | * issued LINEAR_FEED but it's actually STRAIGHT_FEED. So the class
45 | * linearMotion could have been named straightMotion.
46 |
47 | Also, rapid and traverse are used interchangeably, at least in my comments...
48 | */
49 |
50 | class canonMotion: protected canonLine {
51 |
52 | public:
53 | /// return type of motion
54 | virtual MOTION_TYPE getMotionType() {return NOT_DEFINED;}
55 | /// return true
56 | bool isMotion() {return true;};
57 | /// return start
58 | Point getStart() const {return start;}
59 | /// return end
60 | Point getEnd() const {return end;}
61 |
62 | protected:
63 | /// create canonMotion
64 | canonMotion(std::string canonL, machineStatus prevStatus);
65 | Pose getPoseFromCmd();
66 | /// start of this move
67 | Point start;
68 | /// end of this move
69 | Point end;
70 | #ifdef MULTI_AXIS
71 | /// the direction in which the current move starts
72 | Point startDir;
73 | /// the direction in which the current move ends
74 | Point endDir;
75 | #endif
76 | };
77 |
78 | } // end namespace
79 |
80 | #endif //CANONMOTION_HH
81 |
--------------------------------------------------------------------------------
/g2m/helicalMotion.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 |
22 | #ifndef HELICALMOTION_HH
23 | #define HELICALMOTION_HH
24 |
25 | #include
26 | #include
27 | #include
28 | #include
29 |
30 | #include "point.hpp"
31 | #include "canonMotion.hpp"
32 | #include "canonLine.hpp"
33 | #include "machineStatus.hpp"
34 |
35 | namespace g2m {
36 |
37 | /**
38 | \class helicalMotion
39 | \brief For the canonical command ARC_FEED.
40 | This class handles both planar arcs and helical arcs. Inherits from canonMotion.
41 | */
42 |
43 | class helicalMotion: protected canonMotion {
44 | friend canonLine* canonLine::canonLineFactory(std::string l, machineStatus s);
45 |
46 | public:
47 | /// create helical motion
48 | helicalMotion(std::string canonL, machineStatus prevStatus);
49 | MOTION_TYPE getMotionType() {return HELICAL;};
50 | /// return interpolated point along helix, a distance s from the start
51 | Point point(double s);
52 | #ifdef MULTI_AXIS
53 | Point angle(double s);
54 | #endif
55 | /// return the length of this helix move
56 | double length();
57 |
58 | private:
59 | void rotate(double &x, double &y, double c, double s);
60 |
61 | // DATA, this corresponds to the "tokens" on the ARC_FEED canon-line
62 | double x1,y1,z1; // endpoint for this move
63 | double a,b,c; // abc axis endpoints
64 | double rot; // rotation for this move
65 | double cx,cy; // center-point for this move
66 |
67 | // these are the parameters calculated from the canon-params x1,y1,z1,a,b,c,rot,cx,cy
68 | unsigned int X, Y, Z; // for shuffling around coordinate-indexes
69 | double d[6]; // 6-axis delta for this move, applies to linear interpolation
70 | double o[6]; // o=origin/start-point
71 | double dtheta; // change in angle for this move
72 | double tx,ty; // vector from start to center
73 | double radius;
74 | };
75 |
76 | } // end namespace
77 |
78 | #endif //HELICALMOTION_HH
79 |
--------------------------------------------------------------------------------
/lex_analyzer.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #include
28 |
29 | #include "lex_analyzer.hpp"
30 |
31 | namespace lex_analyzer {
32 |
33 | /** converts tokens[n] to double
34 | \param n this is the token to convert
35 | \returns token n, converted to double
36 | */
37 | double LexAnalyzer::token2d(uint n) {
38 | if (tokens.size() < n+1 )
39 | return NAN;
40 | char* end;
41 | double d = strtod( tokens[n].c_str(), &end );
42 | // assert ( *end == 0 );
43 | return d;
44 | }
45 |
46 | /** converts tokens[n] to int
47 | \param n this is the token to convert
48 | \param offset skip this many chars at the beginning of the token
49 | \returns token n, converted to integer
50 | */
51 | int LexAnalyzer::token2i(unsigned int n, unsigned int offset) {
52 | if (tokens.size() < n+1 )
53 | return INT_MIN;
54 | char * end;
55 | int i = strtol( &tokens[n].c_str()[offset], &end, 10 );
56 | //assert ( *end != 0 );
57 | return i;
58 | }
59 |
60 | /// return the n:th token
61 | std::string LexAnalyzer::getToken(unsigned int n) {
62 | if (n < tokens.size()) {
63 | return tokens[n];
64 | } else {
65 | std::cout << "malformed input line " << myLine << std::endl;
66 | std::string s = "";
67 | return s;
68 | }
69 | }
70 |
71 | ///return true if the n:th token matches 'm'
72 | bool LexAnalyzer::wordMatch(std::string m, unsigned int n) {
73 | if (tokens.size() < n+1)
74 | return false;
75 | return (m.compare(tokens[n]) == 0); //compare returns zero for a match
76 | }
77 |
78 | //from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
79 | /** Splits a string using delimiters.
80 | \param str the string to be split
81 | \param tokenV a vector of strings, each of which is a piece of str
82 | \param delimiters defaults to: both parenthesis, comma, space
83 | \sa tokenize()
84 | */
85 | void LexAnalyzer::tokenize( std::string str,
86 | std::vector& tokenV,
87 | const std::string& delimiters ) {
88 | // Skip delimiters at beginning.
89 | std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
90 | // Find first "non-delimiter".
91 | std::string::size_type pos = str.find_first_of(delimiters, lastPos);
92 |
93 | while (std::string::npos != pos || std::string::npos != lastPos)
94 | {
95 | // Found a token, add it to the vector.
96 | tokenV.push_back(str.substr(lastPos, pos - lastPos));
97 | // Skip delimiters. Note the "not_of"
98 | lastPos = str.find_first_not_of(delimiters, pos);
99 | // Find next "non-delimiter"
100 | pos = str.find_first_of(delimiters, lastPos);
101 | }
102 | }
103 |
104 | } // end namespace
105 |
106 |
--------------------------------------------------------------------------------
/g2m/canonLine.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * *
5 | * This program is free software; you can redistribute it and/or modify *
6 | * it under the terms of the GNU General Public License as published by *
7 | * the Free Software Foundation; either version 2 of the License, or *
8 | * (at your option) any later version. *
9 | * *
10 | * This program is distributed in the hope that it will be useful, *
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 | * GNU General Public License for more details. *
14 | * *
15 | * You should have received a copy of the GNU General Public License *
16 | * along with this program; if not, write to the *
17 | * Free Software Foundation, Inc., *
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 | ***************************************************************************/
20 | #ifndef CANONLINE_HH
21 | #define CANONLINE_HH
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include "machineStatus.hpp"
32 | #include "point.hpp"
33 |
34 | namespace g2m {
35 | /**
36 | \class canonLine
37 | \brief A canonLine object represents one canonical command.
38 | Each gcode line produces one or more canonical commands. It can either be a
39 | * motion command (one of LINEAR_TRAVERSE LINEAR_FEED ARC_FEED), or a motionless
40 | * command (anything else)
41 | You cannot create objects of this class - instead, create an object of a class
42 | * that inherits from this class via canonLineFactory()
43 | */
44 | class canonLine {
45 |
46 | public:
47 | /// return the canon-line as a string
48 | const std::string getLine() { return myLine; };
49 | /// return Pose at start of this move
50 | const Pose getStart() { return status.getStartPose(); };
51 | /// return the Pose at end of this move
52 | const Pose getEnd() { return status.getEndPose(); };
53 | int getN();
54 | ///returns the canon line number
55 | int getLineNum() { return tok2i(0); }
56 | //const std::string getCanonType();
57 | /// returns the machine's status after execution of this canon line
58 | const machineStatus* getStatus() { return &status; }
59 | /// return type of motion
60 | virtual MOTION_TYPE getMotionType() { return NOT_DEFINED; } //= 0;
61 | /// return false for motion
62 | virtual bool isMotion() { return false; }
63 | /// return true if this is the end of the nc-program
64 | virtual bool isNCend() { return false; }
65 | /// return length of the motion
66 | virtual double length() { assert(0); return -1; }
67 |
68 | #define UNUSED(x) (void)(x)
69 |
70 | /// return interpolated point at position t along the motion
71 | virtual Point point(double t) { UNUSED(t); assert(0); return Point(); }
72 | #ifdef MULTI_AXIS
73 | virtual Point angle(double t) { UNUSED(t); assert(0); return Point(); }
74 | #endif
75 | // produce a canonLine based on string l, and previous machineStatus s
76 | static canonLine* canonLineFactory (std::string l, machineStatus s);
77 |
78 | std::string cantok(unsigned int n);
79 | const std::string getLnum();
80 |
81 | protected:
82 | // protected ctor, create through factory
83 | canonLine(std::string canonL, machineStatus prevStatus);
84 | double tok2d(unsigned int n);
85 | int tok2i(unsigned int n, unsigned int offset=0);
86 | void tokenize(std::string str, std::vector& tokenV, const std::string& delimiters = "(), ");
87 | const std::string getCanonicalCommand();
88 | bool cmdMatch(std::string m);
89 | // DATA
90 | /// the canon-line as a string
91 | std::string myLine;
92 | /// the machine's status *after* execution of this canon line
93 | machineStatus status;
94 | /// the tokens in this canonLine, set after tokenizing myLine
95 | std::vector canonTokens;
96 | };
97 |
98 | } // end namespace
99 |
100 | #endif //CANONLINE_HH
101 |
--------------------------------------------------------------------------------
/g2m/linearMotion.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
5 | * *
6 | * This program is free software; you can redistribute it and/or modify *
7 | * it under the terms of the GNU General Public License as published by *
8 | * the Free Software Foundation; either version 2 of the License, or *
9 | * (at your option) any later version. *
10 | * *
11 | * This program is distributed in the hope that it will be useful, *
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 | * GNU General Public License for more details. *
15 | * *
16 | * You should have received a copy of the GNU General Public License *
17 | * along with this program; if not, write to the *
18 | * Free Software Foundation, Inc., *
19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 | ***************************************************************************/
21 | #include "calc_tolerance.hpp"
22 |
23 | #include "linearMotion.hpp"
24 |
25 | #include
26 | #include
27 |
28 | #include "machineStatus.hpp"
29 | #include "canonMotion.hpp"
30 | #include "canonLine.hpp"
31 |
32 | namespace g2m {
33 |
34 | linearMotion::linearMotion(std::string canonL, machineStatus prevStatus): canonMotion(canonL,prevStatus) {
35 | status.setMotionType(getMotionType());
36 | status.setEndPose(getPoseFromCmd());
37 | //Point start, end;
38 | start = status.getStartPose().loc + status.getOrigin().loc;
39 | end = status.getEndPose().loc + status.getOrigin().loc;
40 | #ifdef MULTI_AXIS
41 | //Point startDir, endDir;
42 | // startDir = (status.getStartPose().dir + status.getOrigin().dir) * (SIGN * M_PI/180.0);
43 | startDir.x = (status.getStartPose().dir.x + status.getOrigin().dir.x) * (SIGN_A * M_PI/180.0);
44 | startDir.y = (status.getStartPose().dir.y + status.getOrigin().dir.y) * (SIGN_B * M_PI/180.0);
45 | startDir.z = (status.getStartPose().dir.z + status.getOrigin().dir.z) * (SIGN_C * M_PI/180.0);
46 | // endDir = (status.getEndPose().dir + status.getOrigin().dir) * (SIGN * M_PI/180.0);
47 | endDir.x = (status.getEndPose().dir.x + status.getOrigin().dir.x) * (SIGN_A * M_PI/180.0);
48 | endDir.y = (status.getEndPose().dir.y + status.getOrigin().dir.y) * (SIGN_B * M_PI/180.0);
49 | endDir.z = (status.getEndPose().dir.z + status.getOrigin().dir.z) * (SIGN_C * M_PI/180.0);
50 | #endif
51 | }
52 |
53 | Point linearMotion::point(double s) {
54 | if ( length() == 0.0 ) {
55 | return start;
56 | } else {
57 | double t = s/this->length();
58 | //if ( !(t >= 0.0) || !(t <= 1.0 + CALC_TOLERANCE) )
59 | // std::cerr << "linearMotion::point() ERROR at s= " << s << " length= " << length() << " t evaluates to t= " << t << "\n";
60 | // assert( t >= 0.0); assert( t <= 1.0 + CALC_TOLERANCE );
61 | return start + (end-start)*t;
62 | }
63 | }
64 |
65 | double linearMotion::length() {
66 | #ifdef MULTI_AXIS
67 | double llinear = start.Distance(end);
68 | double lsdir = start.Distance(Point(0.0, 0.0, 0.0));
69 | double ledir = end.Distance(Point(0.0, 0.0, 0.0));
70 | double langle = startDir.Distance(endDir);
71 |
72 | langle = ((lsdir > ledir) ? lsdir : ledir) * langle;
73 | return llinear > langle ? llinear : langle;
74 | #else
75 | return start.Distance(end);
76 | #endif
77 | }
78 |
79 | #ifdef MULTI_AXIS
80 | Point linearMotion::angle(double s) {
81 | if ( length() == 0.0 ) {
82 | return startDir;
83 | } else {
84 | double t = s/this->length();
85 | if ( !(t >= 0.0) || !(t <= 1.0 + CALC_TOLERANCE) )
86 | std::cout << "linearMotion::angle() ERROR at s= " << s << " length= " << length() << " t evaluates to t= " << t << "\n";
87 | assert( t >= 0.0); assert( t <= 1.0 + CALC_TOLERANCE );
88 | return startDir + (endDir-startDir)*t;
89 | }
90 | }
91 | #endif
92 |
93 | //need to return RAPID for rapids...
94 | MOTION_TYPE linearMotion::getMotionType() {
95 | bool traverse = cmdMatch("STRAIGHT_TRAVERSE");
96 | if (traverse) {
97 | return TRAVERSE;
98 | } else {
99 | return STRAIGHT_FEED;
100 | }
101 | }
102 |
103 | } // end namespace
104 |
--------------------------------------------------------------------------------
/g2m/machineStatus.cpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * *
5 | * This program is free software; you can redistribute it and/or modify *
6 | * it under the terms of the GNU General Public License as published by *
7 | * the Free Software Foundation; either version 2 of the License, or *
8 | * (at your option) any later version. *
9 | * *
10 | * This program is distributed in the hope that it will be useful, *
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 | * GNU General Public License for more details. *
14 | * *
15 | * You should have received a copy of the GNU General Public License *
16 | * along with this program; if not, write to the *
17 | * Free Software Foundation, Inc., *
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 | ***************************************************************************/
20 |
21 | #include
22 | #include
23 |
24 | #include "machineStatus.hpp"
25 |
26 | namespace g2m {
27 |
28 | /// copy-constructor
29 | machineStatus::machineStatus(const machineStatus& oldStatus) {
30 | spindleStat = oldStatus.spindleStat;
31 | F = oldStatus.F;
32 | S = oldStatus.S;
33 | coolant = oldStatus.coolant;
34 | plane = oldStatus.plane;
35 | origin = oldStatus.origin;
36 | endPose = startPose = oldStatus.endPose;
37 | myTool = oldStatus.myTool;
38 | endDir = Point(0,0,-1);
39 | prevEndDir = oldStatus.endDir;
40 | first = oldStatus.first;
41 | motionType = NOT_DEFINED;
42 | /// lastMotionWasTraverse gets copied from the previous machine status,
43 | /// and only gets changed if the prev status was motion at feedrate
44 | /// (this way, motionless cmds don't mess things up)
45 | lastMotionWasTraverse = oldStatus.lastMotionWasTraverse;
46 | if ( oldStatus.motionType == STRAIGHT_FEED || oldStatus.motionType == HELICAL) {
47 | lastMotionWasTraverse = false;
48 | }
49 | }
50 |
51 | /**
52 | This constructor is only to be used when initializing the simulation; it would not be useful elsewhere.
53 | \param initial is the initial pose of the machine, as determined by the interp from the variable file.
54 | \sa machineStatus(machineStatus const& oldStatus)
55 | */
56 | machineStatus::machineStatus(Pose initial) {
57 | clearAll();
58 | startPose = endPose = initial;
59 | first = true;
60 | setTool(0);
61 | }
62 |
63 | machineStatus::machineStatus(Pose initial, Pose userOrigin) {
64 | clearAll();
65 | startPose = endPose = initial;
66 | origin = userOrigin;
67 | first = true;
68 | setTool(0);
69 | }
70 |
71 | /// reset machineStatus to reasonable defaults
72 | void machineStatus::clearAll() {
73 | F=S=0.0;
74 | plane = CANON_PLANE_XY;
75 | origin = Pose( Point(0,0,0), Point(0,0,0));
76 | coolant.flood = false;
77 | coolant.mist = false;
78 | coolant.spindle = false;
79 | endPose = startPose = Pose( Point(0,0,0), Point(0,0,1));
80 | endDir = prevEndDir = Point(0,0,-1);
81 | spindleStat = OFF;
82 | myTool = -1;
83 | motionType = NOT_DEFINED;
84 | lastMotionWasTraverse = false;
85 | }
86 |
87 | ///sets motion type, and checks whether this is the second (or later) motion command.
88 | void machineStatus::setMotionType(MOTION_TYPE m) {
89 | motionType = m;
90 | if (motionType == NOT_DEFINED) {
91 | std::cout << "motion type undef!! \n";
92 | } else if (motionType == TRAVERSE) {
93 | lastMotionWasTraverse = true;
94 | }
95 | static int count = 0;
96 | if ((first) && ((m == STRAIGHT_FEED) || (m == TRAVERSE) || (m == HELICAL)) ) {
97 | if (count == 0)
98 | count++;
99 | else
100 | first = false;
101 | }
102 | }
103 |
104 |
105 | /// setEndPose
106 | void machineStatus::setEndPose( Point p) {
107 | #ifdef MULTI_AXIS
108 | endPose = Pose( p, Point(0,0,0) );
109 | #else
110 | endPose = Pose( p, Point(0,0,1) );
111 | #endif
112 | }
113 |
114 | /// setEndPose
115 | void machineStatus::setEndPose( Pose newPose) {
116 | endPose = newPose;
117 | }
118 |
119 | /// set the current tool index
120 | void machineStatus::setTool(int n) {
121 | //std::cout << "adding tool " << n << ".\n";
122 | myTool = n;
123 | //canon::addTool(n);
124 | }
125 |
126 |
127 | }
128 |
129 |
130 |
--------------------------------------------------------------------------------
/g2m/g2m.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * modifications Copyright (C) 2011 by Anders Wallin *
5 | * anders.e.e.wallin@gmail.com *
6 | * modified by Kazuyasu Hamada 2015, k-hamada@gifu-u.ac.jp *
7 | * *
8 | * This program is free software; you can redistribute it and/or modify *
9 | * it under the terms of the GNU General Public License as published by *
10 | * the Free Software Foundation; either version 2 of the License, or *
11 | * (at your option) any later version. *
12 | * *
13 | * This program is distributed in the hope that it will be useful, *
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 | * GNU General Public License for more details. *
17 | * *
18 | * You should have received a copy of the GNU General Public License *
19 | * along with this program; if not, write to the *
20 | * Free Software Foundation, Inc., *
21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 | ***************************************************************************/
23 |
24 | #ifndef GTOM_HH
25 | #define GTOM_HH
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #include "canonLine.hpp"
37 |
38 | namespace g2m {
39 |
40 | /// \brief This class runs the interpreter ("rs274"), and creates a canonLine object for each canonical
41 | /// command generated by the interpreter.
42 | class g2m : public QObject {
43 | Q_OBJECT;
44 |
45 | public:
46 | g2m() { debug = false; initialPos = Pose( Point(0,0,0), Point(0,0,0) ); userOrigin = Pose( Point(0,0,0), Point(0,0,0) ); total_gcode_lines = 0; }
47 | /// return vector of canonLines
48 | std::vector getCanonLines() { return lineVector; }
49 | void setInitialPos(Pose init) { initialPos = init; }
50 | void setOrigin(Pose origin) { userOrigin = origin; }
51 | Pose getOrigin() { return userOrigin; }
52 |
53 | /*
54 | int toGcodeLineNo(int canonLineNo) {
55 | if ((unsigned)canonLineNo + 1 >= lineTable.size())
56 | return ++canonLineNo;
57 | else
58 | return lineTable[canonLineNo];
59 | }
60 | */
61 |
62 | public slots:
63 | /// run the interpreter
64 | void interpret_file();
65 | /// set the path to the .ngc g-code file
66 | void setFile(QString infile) {
67 | emit debugMessage( tr("g2m: setting file %1").arg(infile) );
68 | file = infile;
69 | }
70 | /// set the path to the tootable
71 | void setToolTable(QString tbl_file) {
72 | emit debugMessage( tr("g2m: setting tooltable %1").arg(tbl_file) );
73 | tooltable = tbl_file;
74 | }
75 | /// set the path to the rs274 binary
76 | void setInterp(QString interp_binary) {
77 | emit debugMessage( tr("g2m: setting rs274 path: %1").arg(interp_binary) );
78 | interp = interp_binary;
79 | }
80 |
81 | /// set debug mode on/off
82 | void setDebug(bool d) {debug = d;}
83 |
84 | signals:
85 | /// debug messages
86 | void debugMessage(QString s);
87 | /// emitted while .ngc g-code file is read. the g-code line read.
88 | void gcodeLineMessage(QString s);
89 | /// emitted during interpret(), the canon line as a string
90 | void canonLineMessage(QString s);
91 | /// emitted during interpret(), the current canonLine object
92 | void signalCanonLine(canonLine* line);
93 | // emitted when M2 is reached
94 | void signalNCend();
95 | // emitted when interpreter errored
96 | void signalError(QString s);
97 |
98 | protected:
99 | bool chooseToolTable();
100 | bool startInterp(QProcess &tc);
101 | void interpret();
102 | bool processCanonLine(std::string l);
103 | void infoMsg(std::string s);
104 | bool startInterp2(QProcess &tc, QString tempFile);
105 | void interpret2(QString tempFile);
106 | /// the canonLines produced when interpreting g-code
107 | std::vector lineVector;
108 | /// path to .ngc g-code file
109 | QString file;
110 | /// path to tooltable
111 | QString tooltable;
112 | /// path to rs274 executable
113 | QString interp;
114 | /// flag for debug mode
115 | bool debug;
116 | /// number of lines in the .ngc g-code file
117 | int gcode_lines;
118 |
119 | private:
120 | Pose initialPos;
121 | Pose userOrigin;
122 |
123 | int total_gcode_lines;
124 | //std::vector lineTable; not used for now
125 | };
126 |
127 | } // end namespace
128 | #endif //GTOM_HH
129 |
--------------------------------------------------------------------------------
/settings.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Settings
4 |
5 |
6 |
7 | 0
8 | 0
9 | 607
10 | 282
11 |
12 |
13 |
14 | Settings
15 |
16 |
17 | -
18 |
19 |
20 | rs274ngc interpreter:
21 |
22 |
23 |
-
24 |
25 |
26 | rs274 will be in the /bin dir
27 | of your machinekit installation
28 |
29 |
30 |
31 | -
32 |
33 |
34 | Browse
35 |
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 | Tool table (*.tbl) file:
45 |
46 |
47 |
-
48 |
49 |
50 | A xxx.tbl file will be in your
51 | machinekit machine config dir
52 |
53 |
54 |
55 | -
56 |
57 |
58 | Browse
59 |
60 |
61 |
62 |
63 |
64 |
65 | -
66 |
67 |
68 | Temporary G-code file:
69 |
70 |
71 |
-
72 |
73 |
74 | Only change this if you wish to start with a specific file
75 | Beware it could be overwritten.
76 |
77 |
78 | /tmp/gcode.ngc
79 |
80 |
81 |
82 | -
83 |
84 |
85 | Browse
86 |
87 |
88 |
89 |
90 |
91 |
92 | -
93 |
94 |
95 | Qt::Horizontal
96 |
97 |
98 |
99 | 269
100 | 20
101 |
102 |
103 |
104 |
105 | -
106 |
107 |
108 | Cancel
109 |
110 |
111 |
112 | -
113 |
114 |
115 | OK
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 | pb_browse1
125 | clicked()
126 | Settings
127 | onFileBrowse1()
128 |
129 |
130 | 362
131 | 50
132 |
133 |
134 | 389
135 | 80
136 |
137 |
138 |
139 |
140 | pb_browse2
141 | clicked()
142 | Settings
143 | onFileBrowse2()
144 |
145 |
146 | 357
147 | 130
148 |
149 |
150 | 382
151 | 167
152 |
153 |
154 |
155 |
156 | pb_browse3
157 | clicked()
158 | Settings
159 | onFileBrowse3()
160 |
161 |
162 | 352
163 | 210
164 |
165 |
166 | 389
167 | 237
168 |
169 |
170 |
171 |
172 | pushButton_2
173 | clicked()
174 | Settings
175 | onAccept()
176 |
177 |
178 | 345
179 | 263
180 |
181 |
182 | 327
183 | 280
184 |
185 |
186 |
187 |
188 | pushButton
189 | clicked()
190 | Settings
191 | reject()
192 |
193 |
194 | 217
195 | 265
196 |
197 |
198 | 137
199 | 267
200 |
201 |
202 |
203 |
204 |
205 | onFileBrowse1()
206 | onFileBrowse2()
207 | onFileBrowse3()
208 | onAccept()
209 |
210 |
211 |
--------------------------------------------------------------------------------
/g2m/machineStatus.hpp:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | * Copyright (C) 2010 by Mark Pictor *
3 | * mpictor@gmail.com *
4 | * *
5 | * This program is free software; you can redistribute it and/or modify *
6 | * it under the terms of the GNU General Public License as published by *
7 | * the Free Software Foundation; either version 2 of the License, or *
8 | * (at your option) any later version. *
9 | * *
10 | * This program is distributed in the hope that it will be useful, *
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 | * GNU General Public License for more details. *
14 | * *
15 | * You should have received a copy of the GNU General Public License *
16 | * along with this program; if not, write to the *
17 | * Free Software Foundation, Inc., *
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 | ***************************************************************************/
20 | #ifndef MACHINESTATUS_HH
21 | #define MACHINESTATUS_HH
22 |
23 | #include