├── test.stl ├── admeshgui.rc ├── Resources ├── admeshgui.icns ├── redo.svg ├── undo.svg ├── close.svg ├── hide.svg ├── open.svg ├── save.svg └── admeshgui.svg ├── Distribution ├── admeshgui.ico ├── screenshot1.png ├── screenshot2.png ├── 16x16 │ └── admeshgui.png ├── 32x32 │ └── admeshgui.png ├── 48x48 │ └── admeshgui.png ├── brewrun.sh ├── admeshgui.desktop ├── Info.plist ├── admeshgui.appdata.xml └── symbolic │ └── admeshgui-symbolic.svg ├── picking_fshader.glsl ├── picking_vshader.glsl ├── shaders.qrc ├── vshader.glsl ├── Resources.qrc ├── LOGO-LICENSE ├── fshader.glsl ├── homebrew.pri ├── .gitignore ├── admeshEventFilter.h ├── main.cpp ├── data.h ├── historylist.h ├── ADMeshGUI.pro ├── historylist.cpp ├── README.md ├── propertiesdialog.h ├── propertiesdialog.cpp ├── window.h ├── propertiesdialog.ui ├── meshobject.h ├── renderingwidget.h ├── meshobject.cpp ├── admeshcontroller.h ├── renderingwidget.cpp ├── window.cpp └── LICENSE /test.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/test.stl -------------------------------------------------------------------------------- /admeshgui.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "Resources/admeshgui.ico" 2 | -------------------------------------------------------------------------------- /Resources/admeshgui.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Resources/admeshgui.icns -------------------------------------------------------------------------------- /Distribution/admeshgui.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Distribution/admeshgui.ico -------------------------------------------------------------------------------- /Distribution/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Distribution/screenshot1.png -------------------------------------------------------------------------------- /Distribution/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Distribution/screenshot2.png -------------------------------------------------------------------------------- /Distribution/16x16/admeshgui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Distribution/16x16/admeshgui.png -------------------------------------------------------------------------------- /Distribution/32x32/admeshgui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Distribution/32x32/admeshgui.png -------------------------------------------------------------------------------- /Distribution/48x48/admeshgui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/admesh/ADMeshGUI/HEAD/Distribution/48x48/admeshgui.png -------------------------------------------------------------------------------- /picking_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform vec3 color; 4 | 5 | void main() 6 | { 7 | gl_FragColor = vec4(color, 1.0); 8 | } 9 | -------------------------------------------------------------------------------- /picking_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | attribute vec4 a_position; 4 | attribute vec3 a_normal; 5 | uniform mat4 mvp_matrix; 6 | 7 | void main() 8 | { 9 | gl_Position = mvp_matrix * a_position; 10 | } 11 | -------------------------------------------------------------------------------- /shaders.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | fshader.glsl 4 | vshader.glsl 5 | picking_fshader.glsl 6 | picking_vshader.glsl 7 | 8 | 9 | -------------------------------------------------------------------------------- /vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | attribute vec4 a_position; 4 | attribute vec3 a_normal; 5 | uniform mat4 mvp_matrix; 6 | varying vec3 v_normal; 7 | 8 | void main() 9 | { 10 | gl_Position = mvp_matrix * a_position; 11 | v_normal = a_normal; 12 | } 13 | -------------------------------------------------------------------------------- /Distribution/brewrun.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | realpath() { 4 | if [ -d "$(dirname "$1")" ]; then 5 | echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" 6 | fi 7 | } 8 | 9 | FILES=() 10 | for f in "$@"; do 11 | FILES+=("$(realpath "$f")") 12 | done 13 | 14 | open -n $(brew --prefix)/opt/admeshgui/ADMeshGUI.app --args "${FILES[@]}" 15 | -------------------------------------------------------------------------------- /Distribution/admeshgui.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Name=ADMeshGUI 4 | GenericName=STL viewer and manipulation tool 5 | Comment=Tool for manipulation and repairs of STL files 6 | Exec=admeshgui %F 7 | Icon=admeshgui 8 | Terminal=false 9 | StartupNotify=true 10 | Categories=Graphics;3DGraphics; 11 | MimeType=text/plain;application/octet-stream;application/sla; 12 | -------------------------------------------------------------------------------- /Resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resources/close.svg 4 | Resources/hide.svg 5 | Resources/redo.svg 6 | Resources/undo.svg 7 | Resources/open.svg 8 | Resources/save.svg 9 | Resources/admeshgui.svg 10 | Resources/admeshgui.icns 11 | 12 | 13 | -------------------------------------------------------------------------------- /LOGO-LICENSE: -------------------------------------------------------------------------------- 1 | The logo is licenced under the terms of either the GNU LGPL v3 or 2 | Creative Commons Attribution-Share Alike 3.0 United States License. 3 | 4 | To view a copy of the CC-BY-SA licence, visit 5 | http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative 6 | Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. 7 | 8 | When attributing the artwork, using "GNOME Project" is enough. 9 | Please link to http://www.gnome.org where available. 10 | -------------------------------------------------------------------------------- /fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform sampler2D texture; 4 | uniform vec3 color; 5 | uniform vec3 badColor; 6 | uniform bool differ_hue; 7 | varying vec3 v_normal; 8 | 9 | void main() 10 | { 11 | vec3 N = normalize(v_normal); 12 | float factor = (N.x + N.z + N.y + 3.0) / 6.0; 13 | if(!differ_hue) factor = 1.0; 14 | 15 | if (gl_FrontFacing){ 16 | gl_FragColor = vec4(color*factor, 1.0); 17 | } else { 18 | gl_FragColor = vec4(badColor*factor, 1.0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /homebrew.pri: -------------------------------------------------------------------------------- 1 | BREW_PREFIX = $$system(brew --prefix 2> /dev/null) 2 | !isEmpty(BREW_PREFIX){ 3 | exists($$BREW_PREFIX/opt/admesh/lib/*){ 4 | QMAKE_CXXFLAGS += -I/usr/local/opt/admesh/include 5 | LIBS += -L/usr/local/opt/admesh/lib 6 | } 7 | exists($$BREW_PREFIX/opt/stlsplit/lib/*){ 8 | QMAKE_CXXFLAGS += -I/usr/local/opt/stlsplit/include 9 | LIBS += -L/usr/local/opt/stlsplit/lib 10 | } 11 | exists($$BREW_PREFIX/opt/gettext/lib/*){ 12 | QMAKE_CXXFLAGS += -I/usr/local/opt/gettext/include 13 | LIBS += -L/usr/local/opt/gettext/lib 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Resources/redo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Resources/undo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Resources/close.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | .qmake.stash 28 | 29 | # Icon must end with two \r 30 | Icon 31 | 32 | 33 | # Thumbnails 34 | ._* 35 | 36 | # Files that might appear on external disk 37 | .Spotlight-V100 38 | .Trashes 39 | 40 | # Directories potentially created on remote AFP share 41 | .AppleDB 42 | .AppleDesktop 43 | Network Trash Folder 44 | Temporary Items 45 | .apdisk 46 | 47 | # Qt files to ignore 48 | *.pro.user 49 | 50 | # Project files to ignore 51 | admeshgui 52 | moc_*.cpp 53 | *.o 54 | Makefile 55 | ui_window.h 56 | ui_propertiesdialog.h 57 | qrc_shaders.cpp 58 | qrc_Resources.cpp 59 | ADMeshGUI.app 60 | -------------------------------------------------------------------------------- /Distribution/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | ADMeshGUI 7 | CFBundleIconFile 8 | @ICON@ 9 | CFBundlePackageType 10 | APPL 11 | CFBundleExecutable 12 | ADMeshGUI 13 | CFBundleIdentifier 14 | org.admesh.ADMeshGUI 15 | CFBundleVersion 16 | @SHORT_VERSION@ 17 | CFBundleShortVersionString 18 | @SHORT_VERSION@ 19 | LSEnvironment 20 | 21 | GUI_LAUNCHED 22 | 23 | 24 | CFBundleDocumentTypes 25 | 26 | 27 | CFBundleTypeExtensions 28 | 29 | stl 30 | 31 | CFBundleTypeName 32 | STL 3D file 33 | CFBundleTypeRole 34 | Editor 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Distribution/admeshgui.appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | admeshgui.desktop 4 | CC0-1.0 5 | AGPL-3.0 6 | ADMeshGUI 7 | STL viewer and manipulation tool 8 | 9 |

ADMeshGUI is a desktop application to view and manipulate STL 3D models. 10 | It supports viewing STL files and export them in STL, VRML and DXF formats.

11 |

Models can be viewed in 3 modes: solid, solid with highlighted edges and wireframe; 12 | they can also be manipulated, such as scaled, mirrored, rotated or translated. Files can also be split, merged or repaired.

13 |
14 | 15 | 16 | https://github.com/admesh/ADMeshGUI/raw/master/Distribution/screenshot1.png 17 | 18 | 19 | https://github.com/admesh/ADMeshGUI/raw/master/Distribution/screenshot2.png 20 | 21 | 22 | http://admesh.org/ 23 |
24 | -------------------------------------------------------------------------------- /admeshEventFilter.h: -------------------------------------------------------------------------------- 1 | #ifndef ADMESHEVENTFILTER_H 2 | #define ADMESHEVENTFILTER_H 3 | 4 | #include 5 | #include 6 | #include "window.h" 7 | 8 | /*! 9 | * \brief Filters events on given object. 10 | * 11 | * Mainly used for filtering FileOpen event on main application on Mac OS X. 12 | * [Inspired by openSCAD EventFilter class, accessible on https://github.com/openscad/openscad/blob/master/src/EventFilter.h, 13 | * version 4. 3. 2015, last access on 9. 5. 2015] 14 | */ 15 | class admeshEventFilter : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | admeshEventFilter(QObject *parent, Window *w) : QObject(parent) {window = w;} 20 | protected: 21 | bool eventFilter(QObject *obj, QEvent *event) { 22 | if (event->type() == QEvent::FileOpen) { 23 | QFileOpenEvent* ev = static_cast(event); 24 | window->openByFilename(ev->file().toStdString().c_str()); 25 | return true; 26 | } else { 27 | return QObject::eventFilter(obj, event); 28 | } 29 | } 30 | private: 31 | Window *window; 32 | }; 33 | 34 | #endif // ADMESHEVENTFILTER_H 35 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | /*[Information about Qt + OpenGL classes (e.g. how to use the API) obtained from Qt Reference Pages 3 | http://doc.qt.io/qt-5/reference-overview.html 9. 5. 2015]*/ 4 | 5 | #include 6 | #include 7 | 8 | #include "window.h" 9 | #include "data.h" 10 | #include "admeshEventFilter.h" 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | QApplication app(argc, argv); 15 | setlocale(LC_NUMERIC,"C"); 16 | textdomain("admeshgui"); 17 | 18 | QCoreApplication::setOrganizationName("ADMesh"); 19 | QCoreApplication::setApplicationName("ADMeshGUI"); 20 | 21 | QSurfaceFormat format; 22 | format.setDepthBufferSize(24); 23 | format.setSamples(4); 24 | QSurfaceFormat::setDefaultFormat(format); 25 | 26 | Window window; 27 | 28 | #ifdef Q_OS_MAC 29 | app.installEventFilter(new admeshEventFilter(&app, &window)); 30 | #endif 31 | 32 | window.setWindowIcon(QIcon::fromTheme("admeshgui", QIcon("://Resources/admeshgui.svg"))); 33 | window.resize(window.sizeHint()); 34 | int desktopArea = QApplication::desktop()->width() * 35 | QApplication::desktop()->height(); 36 | int widgetArea = window.width() * window.height(); 37 | 38 | window.setWindowTitle("ADMeshGUI"); 39 | 40 | if (((float)widgetArea / (float)desktopArea) < 0.75f) 41 | window.show(); 42 | else 43 | window.showMaximized(); 44 | 45 | for(int i=1;i 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Resources/open.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /data.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef DATA_H 4 | #define DATA_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /** 14 | This part until the END TAG was taken from OpenSCAD source code. Last entry 16. 3. 2015. 15 | Original source code accessible on: 16 | https://github.com/openscad/openscad/blob/master/src/qtgettext.h 17 | https://github.com/openscad/openscad/blob/master/src/printutils.h#L10 18 | */ 19 | #define N_(String) String 20 | inline char * _( const char * msgid ) { return gettext( msgid ); } 21 | inline QString _( const char *msgid, int category ) 22 | { 23 | Q_UNUSED( category ); 24 | return QString::fromUtf8( _( msgid ) ); 25 | } 26 | inline QString _( const char *msgid, const char *disambiguation ) 27 | { 28 | Q_UNUSED(disambiguation); 29 | return QString::fromUtf8(_(msgid)); 30 | } 31 | 32 | /** END TAG */ 33 | 34 | 35 | #define DEFAULT_RES_X 960 36 | #define DEFAULT_RES_Y 725 37 | 38 | #define AXIS_SIZE 500000.0f 39 | #define GRID_SIZE 10.0f 40 | #define MIN_ZOOM 0.01f 41 | #define MAX_ZOOM 50000.0f 42 | #define ZOOM_SPEED 10.0f 43 | #define PERSPECTIVE 50.0f 44 | #define MIN_VIEW_DISTANCE 0.1f 45 | #define MAX_VIEW_DISTANCE 500000.0f 46 | #define ITEMS_LIMIT 16646655 // 255 + 255*255 + 255*255*255 47 | 48 | #define GREEN QVector3D(0.0,1.0,0.0) 49 | #define RED QVector3D(1.0,0.0,0.0) 50 | #define BLUE QVector3D(0.0,0.0,1.0) 51 | #define BLACK QVector3D(0.0,0.0,0.0) 52 | #define GREY QVector3D(0.7,0.7,0.7) 53 | 54 | #define SOLID_SHORTCUT 'S' 55 | #define WIREFRAME_SHORTCUT 'W' 56 | #define EDGES_SHORTCUT 'E' 57 | #define AXES_SHORTCUT 'A' 58 | #define GRID_SHORTCUT 'G' 59 | #define INFO_SHORTCUT 'I' 60 | #define RESET_SHORTCUT 'R' 61 | #ifdef Q_OS_MAC 62 | #define CLOSE_SHORTCUT Qt::Key_Backspace 63 | #else 64 | #define CLOSE_SHORTCUT Qt::Key_Delete 65 | #endif 66 | #define PROPERTIES_SHORTCUT Qt::CTRL + Qt::Key_Comma 67 | #define EXPORT_SHORTCUT Qt::CTRL + Qt::Key_E 68 | #define FRONT_SHORTCUT Qt::Key_5 + Qt::KeypadModifier 69 | #define BACK_SHORTCUT Qt::Key_0 + Qt::KeypadModifier 70 | #define LEFT_SHORTCUT Qt::Key_4 + Qt::KeypadModifier 71 | #define RIGHT_SHORTCUT Qt::Key_6 + Qt::KeypadModifier 72 | #define TOP_SHORTCUT Qt::Key_8 + Qt::KeypadModifier 73 | #define BOTTOM_SHORTCUT Qt::Key_2 + Qt::KeypadModifier 74 | 75 | #define HISTORY_LIMIT 100 76 | 77 | #endif // DATA_H 78 | -------------------------------------------------------------------------------- /Resources/save.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /historylist.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef HISTORYLIST_H 4 | #define HISTORYLIST_H 5 | 6 | #include 7 | #include "data.h" 8 | #include "meshobject.h" 9 | 10 | using namespace std; 11 | 12 | class historyList 13 | { 14 | public: 15 | /*! 16 | * \brief Default constructor. 17 | * 18 | * Pushes one emtpy item at index 0 - better further manipulation. 19 | */ 20 | historyList(); 21 | 22 | /*! 23 | * \brief Destructor 24 | * 25 | * Cleans whole history. 26 | */ 27 | ~historyList(); 28 | 29 | /*! 30 | * \brief Set limit size of buffer. 31 | * 32 | * \param limit Limit size of buffer in bytes. 33 | */ 34 | void setLimitSize(int limit); 35 | 36 | /*! 37 | * \brief Add item into history 38 | * \param item Objects in current state to add to history. 39 | */ 40 | void add(QList item, unsigned long size); 41 | 42 | /*! 43 | * \brief Delete history item given by index 44 | * \param index Index of item to delete. 45 | */ 46 | void deleteRow(QList >::size_type index); 47 | 48 | /*! 49 | * \brief Returns item under current_index 50 | * \return Current item. 51 | */ 52 | QList current(); 53 | 54 | /*! 55 | * \brief Returns item one position back in history. 56 | * \return Previous item. 57 | */ 58 | QList undo(); 59 | 60 | /*! 61 | * \brief Returns item one position further in history. 62 | * \return Next item. 63 | */ 64 | QList redo(); 65 | 66 | /*! 67 | * \brief Delete oldest entries in history. 68 | * 69 | * Counted references of MeshObjects taken into account. 70 | */ 71 | void cutOldest(); 72 | 73 | /*! 74 | * \brief Delete "youngest" entries in history (which were undoed). 75 | * 76 | * Called during adding phase if current_index is not last. Newly added item replaces all items which were undoed. 77 | * Counted references of MeshObjects taken into account. 78 | */ 79 | void cutRedos(); 80 | 81 | /*! 82 | * \brief Returns whether it is possible to perform Undo. 83 | * \return true if list has item to be undone. 84 | */ 85 | bool hasUndos(); 86 | 87 | /*! 88 | * \brief Returns whether it is possible to perform Redo. 89 | * \return true if list has item to be redone. 90 | */ 91 | bool hasRedos(); 92 | private: 93 | QList > history; ///< Editation history list 94 | QList >::size_type current_index; ///< Current index position 95 | QList >::size_type max_index; ///< Maximum index position 96 | unsigned long long historySize; 97 | unsigned long long sizeLimit; 98 | }; 99 | 100 | #endif // HISTORYLIST_H 101 | -------------------------------------------------------------------------------- /ADMeshGUI.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2014-10-31T11:28:53 4 | # 5 | # [Information about Qt + OpenGL classes (e.g. how to use the API) obtained from Qt Reference Pages 6 | # http://doc.qt.io/qt-5/reference-overview.html 9. 5. 2015] 7 | # 8 | #------------------------------------------------- 9 | 10 | QT += core gui opengl widgets svg 11 | 12 | lessThan(QT_MAJOR_VERSION, 5) { 13 | error(ADMeshGUI requires Qt 5.4 to run. Older version detected.) 14 | } 15 | 16 | equals(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 4) { 17 | error(ADMeshGUI requires Qt 5.4 to run. Older version detected.) 18 | } 19 | 20 | TARGET = admeshgui 21 | TEMPLATE = app 22 | 23 | load(uic) 24 | uic.commands += -tr _ 25 | 26 | SOURCES += main.cpp\ 27 | window.cpp \ 28 | renderingwidget.cpp \ 29 | admeshcontroller.cpp \ 30 | meshobject.cpp \ 31 | historylist.cpp \ 32 | propertiesdialog.cpp 33 | 34 | HEADERS += window.h \ 35 | data.h \ 36 | renderingwidget.h \ 37 | admeshcontroller.h \ 38 | meshobject.h \ 39 | historylist.h \ 40 | propertiesdialog.h \ 41 | admeshEventFilter.h 42 | 43 | FORMS += window.ui \ 44 | propertiesdialog.ui 45 | 46 | LIBS += -ladmesh -lstlsplit 47 | macx { 48 | LIBS += -lintl 49 | TARGET = ADMeshGUI 50 | ICON = Resources/admeshgui.icns 51 | QMAKE_INFO_PLIST = Distribution/Info.plist 52 | include(homebrew.pri) 53 | app.files += ADMesGUI.app 54 | app.path = /Applications 55 | INSTALLS += app 56 | } 57 | 58 | win32 { 59 | LIBS += -lintl -liconv 60 | RC_FILE = admeshgui.rc 61 | } 62 | 63 | unix { 64 | isEmpty(PREFIX):PREFIX = /usr 65 | bin.files += admeshgui 66 | bin.path = $$PREFIX/bin 67 | mainico.files += Resources/admeshgui.svg 68 | mainico.path = $$PREFIX/share/icons/hicolor/scalable/apps 69 | 16ico.files += Distribution/16x16/admeshgui.png 70 | 16ico.path = $$PREFIX/share/icons/hicolor/16x16/apps 71 | 32ico.files += Distribution/32x32/admeshgui.png 72 | 32ico.path = $$PREFIX/share/icons/hicolor/32x32/apps 73 | 48ico.files += Distribution/48x48/admeshgui.png 74 | 48ico.path = $$PREFIX/share/icons/hicolor/48x48/apps 75 | symbico.files += Distribution/symbolic/admeshgui-symbolic.svg 76 | symbico.path = $$PREFIX/share/icons/hicolor/symbolic/apps 77 | desktop.files += Distribution/admeshgui.desktop 78 | desktop.path = $$PREFIX/share/applications 79 | appdata.files += Distribution/admeshgui.appdata.xml 80 | appdata.path = $$PREFIX/share/appdata 81 | INSTALLS += bin desktop mainico 16ico 32ico 48ico symbico appdata 82 | } 83 | 84 | DISTFILES += \ 85 | fshader.glsl \ 86 | vshader.glsl 87 | 88 | RESOURCES += \ 89 | shaders.qrc \ 90 | Resources.qrc 91 | 92 | OTHER_FILES += \ 93 | picking_vshader.glsl \ 94 | picking_fshader.glsl \ 95 | Info.plist \ 96 | homebrew.pri \ 97 | Distribution/admeshgui.ico \ 98 | admeshgui.rc 99 | 100 | 101 | -------------------------------------------------------------------------------- /historylist.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #include "historylist.h" 4 | 5 | historyList::historyList() 6 | { 7 | current_index = 0; 8 | max_index = 0; 9 | history.push_back(QList()); 10 | historySize = 0; 11 | sizeLimit = 0; 12 | } 13 | 14 | historyList::~historyList() 15 | { 16 | while(max_index != 0){ 17 | for(QList::size_type i = 0; i < history[max_index].size();i++){ 18 | if(history[max_index][i]->hasReferences()){ 19 | history[max_index][i]->removeReference(); 20 | }else{ 21 | delete history[max_index][i]; 22 | history[max_index][i]=NULL; 23 | } 24 | } 25 | history.pop_back(); 26 | --max_index; 27 | } 28 | } 29 | 30 | void historyList::setLimitSize(int limit) 31 | { 32 | sizeLimit = (unsigned long long)limit*1000000; //convert to MB 33 | } 34 | 35 | void historyList::add(QList item, unsigned long size) 36 | { 37 | if(current_index != max_index){ // not on the end of history 38 | cutRedos(); 39 | } 40 | cutOldest(); 41 | historySize += size; 42 | history.push_back(item); 43 | current_index++; 44 | max_index++; 45 | } 46 | 47 | QList historyList::current() 48 | { 49 | return history[current_index]; 50 | } 51 | 52 | QList historyList::undo() 53 | { 54 | if(current_index == 0 || current_index == 1){ 55 | return current(); 56 | }else{ 57 | --current_index; 58 | return current(); 59 | } 60 | } 61 | 62 | QList historyList::redo() 63 | { 64 | if(current_index < max_index) ++current_index; 65 | return current(); 66 | } 67 | 68 | void historyList::deleteRow(QList >::size_type index) 69 | { 70 | for(QList::size_type i = 0; i < history[index].size();i++){ 71 | if(history[index][i]->hasReferences()){ 72 | history[index][i]->removeReference(); 73 | }else{ 74 | if(history[index][i]->getSize() > historySize){ 75 | historySize = 0; 76 | }else{ 77 | historySize -= history[index][i]->getSize(); 78 | } 79 | delete history[index][i]; 80 | history[index][i]=NULL; 81 | } 82 | } 83 | } 84 | 85 | void historyList::cutOldest() 86 | { 87 | QList >::size_type index = 1; 88 | while(historySize > sizeLimit && current_index > 1){ 89 | deleteRow(index); 90 | --current_index; 91 | --max_index; 92 | history.erase(history.begin() + index); 93 | } 94 | } 95 | 96 | void historyList::cutRedos() 97 | { 98 | while(max_index != current_index){ 99 | deleteRow(max_index); 100 | history.pop_back(); 101 | --max_index; 102 | } 103 | } 104 | 105 | bool historyList::hasUndos() 106 | { 107 | if(current_index > 1) return true; 108 | else return false; 109 | } 110 | 111 | bool historyList::hasRedos() 112 | { 113 | if(max_index != current_index) return true; 114 | else return false; 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ADMeshGUI 2 | ========= 3 | 4 | STL viewer and manipulation tool. 5 | 6 | Manipulation and repair algorithms come from [ADMesh](https://github.com/admesh/admesh) library and [stlsplit](https://github.com/hroncok/stlsplit) library is used for splitting. 7 | ADMeshGUI is licensed under the _GNU Affero General Public License, version 3_. Whole text of the license comes in LICENSE file which is included in this package. 8 | 9 | ![Screenshot 1](./Distribution/screenshot1.png) 10 | ![Screenshot 2](./Distribution/screenshot2.png) 11 | 12 | Building 13 | -------- 14 | 15 | In order to run ADMeshGUI, [ADMesh library](https://github.com/admesh/admesh), [stlsplit library](https://github.com/hroncok/stlsplit), [Qt 5.4](http://www.qt.io/download/) (or higher) with qmake, OpenGL and g++ are necessary. 16 | 17 | On **Linux**, unzip downloaded package, navigate to target directory and type following into terminal: 18 | 19 | qmake # or qmake-qt5 on some distros 20 | make 21 | sudo make install 22 | 23 | On **Mac OS X** use [homebrew](https://github.com/homebrew/homebrew). You can install ADMeshGUI directly from our homebrew tap by typing following into terminal: 24 | 25 | brew tap admesh/admesh 26 | brew install admeshgui --HEAD 27 | brew linkapps admeshgui 28 | 29 | or if you prefer to build it manually, type following into terminal (installs all required dependencies): 30 | 31 | brew tap admesh/admesh 32 | brew install gettext qt5 admesh stlsplit 33 | /usr/local/opt/qt5/bin/qmake 34 | make 35 | 36 | On **Windows** download [admeshgui-win.zip](https://github.com/vyvledav/ADMeshGUI/releases) containing precompiled application. 37 | 38 | If you intend to build ADMeshGUI on Windows by yourself, the process is not that straightforward though. You must make sure Qt5 and all other dependendencies (admesh, stlsplit, gettext) are properly installed and paths set, so it is possible to link them. Then run *qmake* and *make* in terminal. 39 | 40 | It is also possible to build ADMeshGUI in Qt Creator which comes with Qt package. 41 | 42 | Running ADMeshGUI from command line tool 43 | ---------------------------------------- 44 | 45 | admeshgui file_1.stl file_2.stl file_3.stl ... file_n.stl 46 | 47 | Files given as parameters will be opened in ADMeshGUI. 48 | 49 | Features 50 | -------- 51 | 52 | * **View** STL files 53 | * Highlighted flaws 54 | * 3 modes: **solid**, **solid with highlighted edges** and **wireframe** 55 | * **Selection** of files. It is possible to have more files open and process only some. 56 | * User defined colors 57 | * **Scale** by _x_, _y_ and _z_ axes 58 | * **Mirror** along _xz_, _xy_ and _yz_ planes 59 | * **Rotate** along _x_, _y_ and _z_ axes 60 | * **Translate** in _x_, _y_ and _z_ directions 61 | * **Merge** files 62 | * **Split** files 63 | * **Repair** files 64 | * **Fill** holes 65 | * Repair facets **orientation** 66 | * Repair **normals** 67 | * Remove **degenerate** facets 68 | * Repair facets by **connecting nearby** facets that are within a given tolerance 69 | * **Save as** binary or ASCII STL 70 | * **Export** to .OBJ, .OFF, .VRML, .DXF file formats 71 | 72 | ADMeshGUI was succesfully run on following systems: Ubuntu 14.04 LTS, Fedora 21, Mac OS X 10.9 Mavericks, Mac OS X 10.10 Yosemite, Windows 7 64-bit 73 | -------------------------------------------------------------------------------- /propertiesdialog.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef PROPERTIESDIALOG_H 4 | #define PROPERTIESDIALOG_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include "data.h" 10 | #include "admeshcontroller.h" 11 | 12 | namespace Ui { 13 | class PropertiesDialog; 14 | } 15 | 16 | /*! 17 | * \brief Properties window. 18 | * 19 | * Used to set values (e.g. inverted mouse, history buffer limit, theme,...) . 20 | */ 21 | class PropertiesDialog : public QDialog 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | /*! 27 | * \brief Constructor. 28 | */ 29 | explicit PropertiesDialog(QWidget *parent = 0); 30 | /*! 31 | * \brief Destructor. 32 | */ 33 | ~PropertiesDialog(); 34 | /*! 35 | * \brief Set controller to handle operations. 36 | */ 37 | void setController(admeshController *cnt); 38 | 39 | public slots: 40 | /*! 41 | * \brief Set changed memory limit value. 42 | */ 43 | void setMemLimit(int val); 44 | /*! 45 | * \brief Set changed theme value. 46 | */ 47 | void toggleScheme(); 48 | /*! 49 | * \brief Set changed inverted mouse value. 50 | */ 51 | void toggleInvertMouse(); 52 | /*! 53 | * \brief Set changed color value. 54 | */ 55 | void setColor(); 56 | /*! 57 | * \brief Set changed bad color value. 58 | */ 59 | void setBadColor(); 60 | /*! 61 | * \brief Set default color value. 62 | */ 63 | void setDefaultColor(); 64 | /*! 65 | * \brief Set default bad color value. 66 | */ 67 | void setDefaultBadColor(); 68 | /*! 69 | * \brief Handle dialog finished. 70 | * 71 | * Upon succes (OK selected) change desired values to new values. 72 | * Changes are based on difference between new values set in dialog and old values read from configuration. 73 | */ 74 | void finished(int); 75 | 76 | signals: 77 | /*! 78 | * \brief Send signal to change scheme of main Window. 79 | */ 80 | void schemeSignal(); 81 | /*! 82 | * \brief Send signal to invert mouse in RenderingWidget. 83 | */ 84 | void mouseInvertSignal(); 85 | 86 | private: 87 | Ui::PropertiesDialog *ui; ///< Pointer to iterface of dialog. 88 | admeshController *controller; ///< Controller used to process changes. 89 | QPixmap colMap; ///< Color map. Displays color in dialog. 90 | QPixmap badColMap; ///< Bad color map. Displays bad color in dialog. 91 | QColor color; ///< Color. 92 | QColor i_color; ///< Color upon initialization. 93 | QColor badColor; ///< Bad color. 94 | QColor i_badColor; ///< Bad color upon initialization. 95 | int memLimit; ///< Memory limit. 96 | int i_memLimit; ///< Memory limit upon initialization. 97 | bool invertMouse; ///< Inverted mouse yes/no. 98 | bool i_invertMouse; ///< Inverted mouse yes/no upon initialization. 99 | bool darkTheme; ///< Dark theme yes/no. 100 | bool i_darkTheme; ///< Dark theme yes/no upon initialization. 101 | }; 102 | 103 | #endif // PROPERTIESDIALOG_H 104 | -------------------------------------------------------------------------------- /propertiesdialog.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #include "propertiesdialog.h" 4 | #include "ui_propertiesdialog.h" 5 | 6 | PropertiesDialog::PropertiesDialog(QWidget *parent) : 7 | QDialog(parent), 8 | ui(new Ui::PropertiesDialog) 9 | { 10 | ui->setupUi(this); 11 | controller = NULL; 12 | QSettings settings; 13 | i_darkTheme = darkTheme = settings.value("colorScheme",0).toBool(); 14 | if(i_darkTheme) ui->ThemeBox->setChecked(true); 15 | i_invertMouse = invertMouse = settings.value("invertMouse",false).toBool(); 16 | if(i_invertMouse) ui->InvertMouseBox->setChecked(true); 17 | i_color = color = settings.value("color",QColor(Qt::green)).value(); 18 | i_badColor = badColor = settings.value("badColor",QColor(Qt::red)).value(); 19 | i_memLimit = memLimit = settings.value("sizeLimit", HISTORY_LIMIT).toInt(); 20 | 21 | ui->MemLimBox->setValue(i_memLimit); 22 | ui->MemLimBox->setSuffix(" MB"); 23 | 24 | colMap = QPixmap(73,20); 25 | colMap.fill(i_color); 26 | ui->colorButton->setIcon(QIcon(colMap)); 27 | ui->colorButton->setIconSize(colMap.rect().size()); 28 | 29 | badColMap = QPixmap(73,20); 30 | badColMap.fill(i_badColor); 31 | ui->badColorButton->setIcon(QIcon(badColMap)); 32 | ui->badColorButton->setIconSize(badColMap.rect().size()); 33 | 34 | connect(ui->ThemeBox, SIGNAL(stateChanged(int)), this, SLOT(toggleScheme())); 35 | connect(ui->InvertMouseBox, SIGNAL(stateChanged(int)), this, SLOT(toggleInvertMouse())); 36 | connect(ui->MemLimBox, SIGNAL(valueChanged(int)), this, SLOT(setMemLimit(int))); 37 | connect(ui->colorButton, SIGNAL(clicked()), this, SLOT(setColor())); 38 | connect(ui->badColorButton, SIGNAL(clicked()), this, SLOT(setBadColor())); 39 | connect(ui->defaultColButton, SIGNAL(clicked()), this, SLOT(setDefaultColor())); 40 | connect(ui->defaultBadColButton, SIGNAL(clicked()), this, SLOT(setDefaultBadColor())); 41 | 42 | connect(this, SIGNAL(schemeSignal()), parent, SLOT(toggleColorScheme())); 43 | connect(this, SIGNAL(mouseInvertSignal()), parent, SLOT(toggleMouseInvert())); 44 | connect(this, SIGNAL(finished (int)), this, SLOT(finished(int))); 45 | } 46 | 47 | PropertiesDialog::~PropertiesDialog() 48 | { 49 | delete ui; 50 | } 51 | 52 | void PropertiesDialog::setController(admeshController *cnt) 53 | { 54 | controller = cnt; 55 | } 56 | 57 | void PropertiesDialog::setMemLimit(int val) 58 | { 59 | memLimit = val; 60 | } 61 | 62 | void PropertiesDialog::toggleScheme() 63 | { 64 | darkTheme = !darkTheme; 65 | } 66 | 67 | void PropertiesDialog::toggleInvertMouse() 68 | { 69 | invertMouse = !invertMouse; 70 | } 71 | 72 | void PropertiesDialog::setColor() 73 | { 74 | QColor tmp = QColorDialog::getColor(color, this); 75 | if(tmp.isValid()) color = tmp; 76 | colMap.fill(color); 77 | ui->colorButton->setIcon(QIcon(colMap)); 78 | } 79 | 80 | void PropertiesDialog::setBadColor() 81 | { 82 | QColor tmp = QColorDialog::getColor(badColor, this); 83 | if(tmp.isValid()) badColor = tmp; 84 | badColMap.fill(badColor); 85 | ui->badColorButton->setIcon(QIcon(badColMap)); 86 | } 87 | 88 | void PropertiesDialog::setDefaultColor() 89 | { 90 | color = Qt::green; 91 | colMap.fill(color); 92 | ui->colorButton->setIcon(QIcon(colMap)); 93 | } 94 | 95 | void PropertiesDialog::setDefaultBadColor() 96 | { 97 | badColor = Qt::red; 98 | badColMap.fill(badColor); 99 | ui->badColorButton->setIcon(QIcon(badColMap)); 100 | } 101 | 102 | void PropertiesDialog::finished(int val) 103 | { 104 | if(val == QDialog::Accepted){ 105 | QSettings settings; 106 | if(darkTheme != i_darkTheme) { 107 | schemeSignal(); 108 | settings.setValue("colorScheme", darkTheme); 109 | } 110 | if((color != i_color || badColor != i_badColor) && controller) { 111 | settings.setValue("color", color); 112 | settings.setValue("badColor", badColor); 113 | controller->setDrawColor(color, badColor); 114 | } 115 | if((memLimit != i_memLimit) && controller){ 116 | controller->setHistoryLimit(memLimit); 117 | settings.setValue("sizeLimit", memLimit); 118 | } 119 | if(invertMouse != i_invertMouse){ 120 | mouseInvertSignal(); 121 | settings.setValue("invertMouse", invertMouse); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Distribution/symbolic/admeshgui-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | image/svg+xml 9 | 10 | Gnome Symbolic Icon Theme 11 | 12 | 13 | 14 | 15 | 16 | 17 | Gnome Symbolic Icon Theme 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /window.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef WINDOW_H 4 | #define WINDOW_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include "admeshcontroller.h" 10 | #include "propertiesdialog.h" 11 | 12 | namespace Ui { 13 | class Window; 14 | } 15 | 16 | /*! 17 | * \brief Main application window. 18 | * 19 | * Contains main rendering widget, menu, buttons layout. 20 | */ 21 | class Window : public QWidget 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | /*! 27 | * \brief Constructor. 28 | */ 29 | explicit Window(QWidget *parent = 0); 30 | 31 | /*! 32 | * \brief Destructor. 33 | */ 34 | ~Window(); 35 | 36 | public slots: 37 | /*! 38 | * \brief Sends command to controller to open file. 39 | * \param filename Filename given. 40 | */ 41 | void openByFilename(const char* filename); 42 | 43 | /*! 44 | * \brief Sets solid mode. 45 | */ 46 | void setSolid(); 47 | 48 | /*! 49 | * \brief Sets wireframe mode. 50 | */ 51 | void setWireframe(); 52 | 53 | /*! 54 | * \brief Sets solid mode with thick edges. 55 | */ 56 | void setSolidWithEdges(); 57 | 58 | /*! 59 | * \brief Toggle color scheme. Light and dark scheme supported. 60 | */ 61 | void toggleColorScheme(); 62 | 63 | /*! 64 | * \brief Set selected color scheme. 65 | */ 66 | void setColorScheme(); 67 | 68 | /*! 69 | * \brief Toggle inverted mouse. 70 | */ 71 | void toggleMouseInvert(); 72 | 73 | /*! 74 | * \brief Initialize and exec properties dialog. 75 | */ 76 | void initProperties(); 77 | 78 | /*! 79 | * \brief Enable/disable Undo based on value. 80 | * \param val given value 81 | */ 82 | void allowUndo(bool val); 83 | 84 | /*! 85 | * \brief Enable/disable Redo based on value. 86 | * \param val given value 87 | */ 88 | void allowRedo(bool val); 89 | 90 | /*! 91 | * \brief Enable/disable Save based on value. 92 | * \param val given value 93 | */ 94 | void allowSave(bool val); 95 | 96 | /*! 97 | * \brief Enable/disable Save as based on value. 98 | * \param val given value 99 | */ 100 | void allowSaveAs(bool val); 101 | 102 | /*! 103 | * \brief Enable/disable Export based on value. 104 | * \param val given value 105 | */ 106 | void allowExport(bool val); 107 | 108 | /*! 109 | * \brief Enable/disable Close based on value. 110 | * \param val given value 111 | */ 112 | void allowClose(bool val); 113 | 114 | protected: 115 | /*! 116 | * \brief Reimplemented method. Handles key press. 117 | */ 118 | void keyPressEvent(QKeyEvent *event); 119 | 120 | /*! 121 | * \brief Reimplemented method. Handles key release. 122 | */ 123 | void keyReleaseEvent(QKeyEvent *event); 124 | 125 | /*! 126 | * \brief Reimplemented method. Handles closed window (application exit). 127 | */ 128 | void closeEvent(QCloseEvent *event); 129 | 130 | void dropEvent(QDropEvent *event); 131 | 132 | void dragEnterEvent(QDragEnterEvent *event); 133 | 134 | admeshController *controller; ///< Main ADMeshController 135 | 136 | private: 137 | /*! 138 | * \brief Write settings to config. 139 | */ 140 | void writeSettings(); 141 | /*! 142 | * \brief Read settings from config. 143 | */ 144 | void readSettings(); 145 | int scheme; ///< Color scheme selected; 146 | Ui::Window *ui; ///< Holds user interface. 147 | void addActions(); ///< Creates menu actions. 148 | void addMenus(); ///< Creates menu. 149 | void addToolbars(); ///< Creates toolbar. 150 | QMenu *fileMenu; ///< File menu. 151 | QMenu *editMenu; ///< Editation menu. 152 | QMenu *viewMenu; ///< View menu. 153 | QAction *openAct; ///< Open file action. 154 | QAction *saveAct; ///< Save file action. 155 | QAction *saveAsAct; ///< Save as file action. 156 | QAction *exportAct; ///< Export file action. 157 | QAction *closeAct; ///< Close selected objects. 158 | QAction *quitAct; ///< Quit application. 159 | QAction *axesAct; ///< Show axes action. 160 | QAction *gridAct; ///< Show grid action. 161 | QAction *solidAct; ///< Solid mode on. 162 | QAction *wireframeAct; ///< Wireframe mode on. 163 | QAction *solidwithedgesAct; ///< Solid mode with edges on. 164 | QAction *infoAct; ///< Show/hide mesh info. 165 | QAction *frontAct; ///< Set front view. 166 | QAction *backAct; ///< Set back view. 167 | QAction *leftAct; ///< Set left view. 168 | QAction *rightAct; ///< Set right view. 169 | QAction *topAct; ///< Set top view. 170 | QAction *bottomAct; ///< Set bottom view. 171 | QAction *centerAct; ///< Reset view to center. 172 | QAction *selectAllAct; ///< Select all objects. 173 | QAction *selectInverseAct; ///< Select inverse. 174 | QAction *undoAct; ///< Undo. 175 | QAction *redoAct; ///< Redo. 176 | QAction *propertiesAct; ///< Properties dialog. 177 | QToolButton* openButton; ///< Open file button. 178 | QToolButton* saveButton; ///< Save file button. 179 | QToolButton* undoButton; ///< Undo button. 180 | QToolButton* redoButton; ///< Redo button. 181 | QToolButton* closeButton; ///< Close file button. 182 | }; 183 | 184 | #endif // WINDOW_H 185 | -------------------------------------------------------------------------------- /propertiesdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | PropertiesDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 376 10 | 242 11 | 12 | 13 | 14 | Preferences 15 | 16 | 17 | 18 | 19 | 20 20 | 200 21 | 341 22 | 32 23 | 24 | 25 | 26 | Qt::Horizontal 27 | 28 | 29 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 30 | 31 | 32 | 33 | 34 | 35 | 10 36 | 90 37 | 131 38 | 22 39 | 40 | 41 | 42 | <html><head/><body><p>Invert mouse for rotation and translation in 3D view. Changes move direction.</p></body></html> 43 | 44 | 45 | Invert mouse 46 | 47 | 48 | 49 | 50 | 51 | 10 52 | 120 53 | 121 54 | 22 55 | 56 | 57 | 58 | Dark theme 59 | 60 | 61 | 62 | 63 | 64 | 10 65 | 141 66 | 351 67 | 61 68 | 69 | 70 | 71 | 72 | 73 | 74 | History memory limit 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 999999999 85 | 86 | 87 | 88 | 89 | 90 | 91 | Too large memory limit may cause slowing down! 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 14 101 | 22 102 | 271 103 | 62 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 0 112 | 0 113 | 114 | 115 | 116 | 117 | 75 118 | 0 119 | 120 | 121 | 122 | Front color 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 0 138 | 0 139 | 140 | 141 | 142 | 143 | 90 144 | 0 145 | 146 | 147 | 148 | To default 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 0 157 | 0 158 | 159 | 160 | 161 | 162 | 75 163 | 0 164 | 165 | 166 | 167 | Back color 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 0 183 | 0 184 | 185 | 186 | 187 | 188 | 90 189 | 0 190 | 191 | 192 | 193 | To default 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | buttonBox 204 | accepted() 205 | PropertiesDialog 206 | accept() 207 | 208 | 209 | 248 210 | 254 211 | 212 | 213 | 157 214 | 274 215 | 216 | 217 | 218 | 219 | buttonBox 220 | rejected() 221 | PropertiesDialog 222 | reject() 223 | 224 | 225 | 316 226 | 260 227 | 228 | 229 | 286 230 | 274 231 | 232 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /meshobject.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef MESHOBJECT_H 4 | #define MESHOBJECT_H 5 | 6 | #include 7 | #include 8 | #include "data.h" 9 | 10 | /*! 11 | * \brief Encapsulation of stl_file structure of ADMesh 12 | * 13 | * Stores one STL file and according vertex buffer object. 14 | * stl_file structure allows directly only deprecated style of OpenGL drawing. 15 | * This class enables to use modern drawing style via vertex buffer object. 16 | */ 17 | class MeshObject : protected QGLFunctions 18 | { 19 | public: 20 | /*! 21 | * \brief Constructor. Initializes new stl structure. 22 | */ 23 | MeshObject(); 24 | 25 | /*! 26 | * \brief Constructor. Initializes with given stl structure. 27 | * 28 | * \param item Given stl_file item. 29 | */ 30 | MeshObject(stl_file* item, QString name); 31 | 32 | /*! 33 | * \brief Copy constructor. Creates deep copy of MeshObject. 34 | */ 35 | MeshObject(const MeshObject& m); 36 | 37 | /*! 38 | * \brief Read in given file. 39 | * 40 | * Checks if file exist/is proper STL file. 41 | * Generates vertex buffer object. 42 | * 43 | * \param filename Input STL file. 44 | * \return True upon successful load. 45 | */ 46 | bool loadGeometry(QString filename); 47 | 48 | /*! 49 | * \brief Append "_merged" to filename. 50 | */ 51 | void mergedFilename(); 52 | 53 | /*! 54 | * \brief Set filename to "filename_part_index.stl". 55 | * 56 | * \param index Given index. 57 | */ 58 | void setSplitName(int index); 59 | 60 | /*! 61 | * \brief Set filename to "filename_duplicated.stl". 62 | */ 63 | void setDuplicatedName(); 64 | 65 | /*! 66 | * \brief Update geometry (update VBO) 67 | * 68 | * Copies vertex and normal coordinates from stl_file structure into VBO. 69 | */ 70 | void updateGeometry(); 71 | 72 | /*! 73 | * \brief Draw mesh. 74 | * \param program Shader program used for drawing. 75 | */ 76 | void drawGeometry(QGLShaderProgram *program); 77 | 78 | /*! 79 | * \brief Get vector [min x, min y, max z] for camera purposes. 80 | * \return vector of mininaml values. 81 | */ 82 | QVector3D getMin(); 83 | 84 | /*! 85 | * \brief Get maximal diameter of last object in list. Maximal absolute value from all axes. 86 | * 87 | * \return diameter 88 | */ 89 | float getDiameter(); 90 | 91 | /*! 92 | * \brief Get info about mesh. 93 | * \return array containing info. 94 | */ 95 | float* getInfo(); 96 | 97 | QString getName(); 98 | 99 | /*! 100 | * \brief Save mesh as STL. 101 | * \param filename Output STL filename. 102 | * \param type File type - ASCII or binary 103 | */ 104 | void saveAs(QString filename, int type); 105 | 106 | /*! 107 | * \brief Save mesh in its default format. 108 | */ 109 | void save(); 110 | 111 | /*! 112 | * \brief True if stored filename is valid. 113 | */ 114 | bool hasValidName(); 115 | 116 | /*! 117 | * \brief True if current state of mesh is saved. 118 | */ 119 | bool isSaved(); 120 | 121 | /*! 122 | * \brief Export mesh as OFF, VRML, DXF or OBJ. 123 | * \param filename Exported filename. 124 | * \param type File File type. 125 | */ 126 | void exportSTL(QString, int type); 127 | 128 | /*! 129 | * \brief Scale stl file by versor. 130 | * \param versor Scaling versor. 131 | */ 132 | void scale(float versor[3]); 133 | 134 | /*! 135 | * \brief Mirror model by XY plane. 136 | */ 137 | void mirrorXY(); 138 | 139 | /*! 140 | * \brief Mirror model by YZ plane. 141 | */ 142 | void mirrorYZ(); 143 | 144 | /*! 145 | * \brief Mirror model by XZ plane. 146 | */ 147 | void mirrorXZ(); 148 | 149 | /*! 150 | * \brief Rotate stl file along X axis. 151 | * \param angle Angle of rotation. 152 | */ 153 | void rotateX(float angle); 154 | 155 | /*! 156 | * \brief Rotate stl file along Y axis. 157 | * \param angle Angle of rotation. 158 | */ 159 | void rotateY(float angle); 160 | 161 | /*! 162 | * \brief Rotate stl file along Z axis. 163 | * \param angle Angle of rotation. 164 | */ 165 | void rotateZ(float angle); 166 | 167 | /*! 168 | * \brief Translate stl file. All axes together. 169 | * \param relative Relative translation on/off. 170 | * \param x_trans X axis translation factor. 171 | * \param y_trans Y axis translation factor. 172 | * \param z_trans Z axis translation factor. 173 | */ 174 | void translate(bool relative, float x_trans, float y_trans, float z_trans); 175 | 176 | /*! 177 | * \brief Translate stl file to be centered around origin. 178 | */ 179 | void center(); 180 | 181 | /*! 182 | * \brief Snap stl file to zero Z coordinate. 183 | */ 184 | void snapZ(); 185 | 186 | /*! 187 | * \brief Reverse all facets orientation. 188 | */ 189 | void reverseAll(); 190 | 191 | /*! 192 | * \brief Repair stl file. Repair differs with parameters. 193 | * \param fixall_flag Fix all errors in STL file. 194 | * \param tolerance_flag Used tolerance for checking faces. 195 | * \param tolerance Y Given tolerance. 196 | * \param increment_flag Used tolerance increment in iterations. 197 | * \param increment Given increment. 198 | * \param nearby_flag Check for nearby faces. 199 | * \param iterations Number of iterations used for checking. 200 | * \param remove_unconnected_flag Remove unconnected vertices. 201 | * \param fill_holes_flag Fill holes. 202 | * \param normal_directions_flag Repair normal directions. All out. 203 | * \param normal_values_flag Repair normal values. Normalization. 204 | * \param reverse_all_flag Reverse all faces. 205 | */ 206 | void repair(int fixall_flag, int exact_flag, int tolerance_flag, float tolerance, int increment_flag, float increment, int nearby_flag, int iterations, int remove_unconnected_flag, int fill_holes_flag, int normal_directions_flag, int normal_values_flag, int reverse_all_flag); 207 | 208 | /*! 209 | * \brief Set selected. 210 | */ 211 | void setSelected(); 212 | 213 | /*! 214 | * \brief Set deselected. 215 | */ 216 | void setDeselected(); 217 | 218 | /*! 219 | * \brief Toggle selected. 220 | */ 221 | void toggleSelected(); 222 | 223 | /*! 224 | * \brief Is selected? 225 | * 226 | * \return true upon selected 227 | */ 228 | bool isSelected(); 229 | 230 | /*! 231 | * \brief Is active? 232 | * 233 | * \return true upon selected and visible 234 | */ 235 | bool isActive(); 236 | 237 | /*! 238 | * \brief Hide item 239 | */ 240 | void setHidden(); 241 | 242 | /*! 243 | * \brief Reveal hidden item 244 | */ 245 | void setVisible(); 246 | 247 | /*! 248 | * \brief Is hidden? 249 | * 250 | * \return true upon hidden 251 | */ 252 | bool isHidden(); 253 | 254 | /*! 255 | * \brief Destructor. Closes stl structure. Deletes vbo. 256 | */ 257 | virtual ~MeshObject(); 258 | 259 | /*! 260 | * \brief Has references? 261 | * 262 | * return true upon references > 0 263 | */ 264 | bool hasReferences(); 265 | 266 | /*! 267 | * \brief Raise references count by 1. 268 | */ 269 | void addReference(); 270 | 271 | /*! 272 | * \brief Decrease references count by 1. 273 | */ 274 | void removeReference(); 275 | 276 | /*! 277 | * \brief Get pointer to stl_file structure stored. 278 | * 279 | * return stored stl file structure 280 | */ 281 | stl_file* getStlPointer(); 282 | 283 | unsigned long getSize(); 284 | 285 | private: 286 | void countSize(); 287 | 288 | stl_file* stl; ///< Stored STL file 289 | GLuint vbo; ///< Vertex buffer object used to store STL file for drawing 290 | bool selected; ///< Set active/inactive 291 | bool hidden; ///< Is hidden/visible 292 | bool saved; ///< Is saved/unsaved 293 | QString file; ///< File name 294 | unsigned int references; ///< Count if references - how many history items use this object. 295 | unsigned long size; 296 | }; 297 | 298 | #endif // MESHOBJECT_H 299 | -------------------------------------------------------------------------------- /renderingwidget.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef MYGLWIDGET_H 4 | #define MYGLWIDGET_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include "data.h" 19 | #include "admeshcontroller.h" 20 | 21 | /*! 22 | * \brief Main rendering class 23 | * 24 | * Reimplements QOpenGLWidget (Qt version >= 5.4). 25 | * Handles drawing and direct user input. 26 | */ 27 | class RenderingWidget : public QOpenGLWidget, protected QGLFunctions 28 | { 29 | Q_OBJECT 30 | public: 31 | /*! 32 | * \brief Constructor. Sets default values. 33 | */ 34 | explicit RenderingWidget(QWidget *parent = 0); 35 | 36 | /*! 37 | * \brief Sets controller used. 38 | * 39 | * Necessary for calling drawAll method. 40 | * 41 | * \param cnt Controller to be set. 42 | */ 43 | void setController(admeshController* cnt); 44 | 45 | /*! 46 | * \brief Destructor. 47 | */ 48 | ~ RenderingWidget(); 49 | 50 | /*! 51 | * \brief Write settings to config. 52 | */ 53 | void writeSettings(); 54 | 55 | /*! 56 | * \brief Set background color. 57 | * 58 | * \param background Background color to set. 59 | */ 60 | void setBackground(QColor background); 61 | 62 | /*! 63 | * \brief Set text color. 64 | * 65 | * \param text Text color to set. 66 | */ 67 | void setTextCol(QColor text); 68 | 69 | /*! 70 | * \brief Invert mouse. 71 | */ 72 | void invertMouse(); 73 | 74 | protected: 75 | /*! 76 | * \brief Initializes OpenGL. Makes all default calls. 77 | */ 78 | void initializeGL(); 79 | 80 | /*! 81 | * \brief Initializes Shaders from source files. 82 | */ 83 | void initShaders(); 84 | 85 | /*! 86 | * \brief Reimplemented main drawing method. 87 | * 88 | * Makes all drawing calls each time widget is updated. 89 | * Draws 3D first: main content + corner axes. 90 | * Than draws 2D text over 3D content using QPainter. 91 | * Calculates and sets PVM matrix uniform. 92 | */ 93 | void paintGL(); 94 | 95 | /*! 96 | * \brief Reimplemented resize method. 97 | * 98 | * Calles upon resize of window. 99 | */ 100 | void resizeGL(int width, int height); 101 | 102 | /*! 103 | * \brief Reimplemented timer. Send update(); signal. 104 | * 105 | * Used only when mouse is moving otherwise update() is called only upon actions performed (lower CPU usage). 106 | * 107 | * \param e Timer event sent. 108 | */ 109 | void timerEvent(QTimerEvent *e); 110 | 111 | /*! 112 | * \brief Reimplemented method. Gives minimal size of widget. 113 | */ 114 | QSize minimumSizeHint() const; 115 | 116 | /*! 117 | * \brief Reimplemented method. Gives default size of widget. 118 | */ 119 | QSize sizeHint() const; 120 | 121 | /*! 122 | * \brief Reimplemented method. Handles mouse wheel to zoom. 123 | * \param event Wheel event sent. 124 | */ 125 | void wheelEvent(QWheelEvent* event); 126 | 127 | /*! 128 | * \brief Reimplemented method. Handles mouse button pressed. 129 | * \param event Press event sent. 130 | */ 131 | void mousePressEvent(QMouseEvent *event); 132 | 133 | /*! 134 | * \brief Reimplemented method. Handles mouse button released. 135 | * \param event Released event sent. 136 | */ 137 | void mouseReleaseEvent(QMouseEvent *event); 138 | 139 | /*! 140 | * \brief Reimplemented method. Handles mouse move. 141 | * \param event Mouse move event sent. 142 | */ 143 | void mouseMoveEvent(QMouseEvent *event); 144 | 145 | public slots: 146 | /*! 147 | * \brief Set front view angles. 148 | */ 149 | void setFrontView(); 150 | 151 | /*! 152 | * \brief Set back view angles. 153 | */ 154 | void setBackView(); 155 | 156 | /*! 157 | * \brief Set left view angles. 158 | */ 159 | void setLeftView(); 160 | 161 | /*! 162 | * \brief Set right view angles. 163 | */ 164 | void setRightView(); 165 | 166 | /*! 167 | * \brief Set top view angles. 168 | */ 169 | void setTopView(); 170 | 171 | /*! 172 | * \brief Set bottom view angles. 173 | */ 174 | void setBottomView(); 175 | 176 | /*! 177 | * \brief Changes axes mode. ON/OFF 178 | */ 179 | void toggleAxes(); 180 | 181 | /*! 182 | * \brief Changes grid mode. ON/OFF 183 | */ 184 | void toggleGrid(); 185 | 186 | /*! 187 | * \brief View or hide mesh info. 188 | */ 189 | void toggleInfo(); 190 | 191 | /*! 192 | * \brief Updates scene when necessary. 193 | */ 194 | void reDraw(); 195 | 196 | /*! 197 | * \brief Update scene zoom according to size of open file. 198 | */ 199 | void reCalculatePosition(); 200 | 201 | /*! 202 | * \brief Reset camera translation to zero. 203 | */ 204 | void centerPosition(); 205 | 206 | /*! 207 | * \brief Toggle Shift key pressed information. 208 | */ 209 | void toggleShift(); 210 | 211 | signals: 212 | 213 | private: 214 | /*! 215 | * \brief Initialize axes vertex buffer object and fill it. 216 | */ 217 | void initAxes(); 218 | 219 | /*! 220 | * \brief Initialize grid vertex buffer object and fill it. 221 | */ 222 | void initGrid(); 223 | 224 | /*! 225 | * \brief Convert point in 3D scene to screen coordinates. 226 | * \param worldCoords Coordinates of 3D point. 227 | * \return Coordinates of point in screen space. 228 | */ 229 | QVector2D getScreenCoords(QVector3D worldCoords); 230 | 231 | /*! 232 | * \brief Draw actual info. 233 | * \param painter Painter used for drawing. 234 | */ 235 | void drawInfo(QPainter *painter); 236 | 237 | /*! 238 | * \brief Draw labels for corner axes. 239 | * \param painter Painter used for drawing. 240 | */ 241 | void drawLabels(QPainter *painter); 242 | 243 | /*! 244 | * \brief Render x,y and z axes. 245 | */ 246 | void drawAxes(); 247 | 248 | /*! 249 | * \brief Render small corner x,y and z axes. 250 | */ 251 | void drawSmallAxes(); 252 | 253 | /*! 254 | * \brief Render x,y grid. 255 | */ 256 | void drawGrid(); 257 | 258 | /*! 259 | * \brief Normalizes camera rotation angles. 260 | */ 261 | void normalizeAngles(); 262 | 263 | /*! 264 | * \brief Calculate view matrix based on Euler angles. 265 | */ 266 | void getCamPos(); 267 | 268 | /*! 269 | * \brief Recalculate grid step according to current zoom factor. 270 | * 271 | * Calculated in range of {1,2,3,4,5,10,15,..} and further in multiples of 5. 272 | */ 273 | void recalculateGridStep(); 274 | 275 | /*! 276 | * \brief Determine projection near plane based on distance from objects. 277 | */ 278 | void recalculateProjectionNear(); 279 | 280 | /*! 281 | * \brief Do color based object picking. 282 | * 283 | * Uses offscreen color + depth framebuffer for drawing. Based on color of pixel clicked. 284 | */ 285 | void doPicking(); 286 | 287 | QBasicTimer timer; ///< Timer used to regular redrawing. 288 | 289 | int w; ///< Widget width. 290 | int h; ///< Widget height. 291 | 292 | QGLShaderProgram program; ///< Common shader program. 293 | QGLShaderProgram pick_program; ///< Picking shader program. 294 | QMatrix4x4 projection; ///< Projection matrix. 295 | QMatrix4x4 orthographic; ///< Orthographic projection matrix. 296 | QMatrix4x4 view; ///< View matrix. 297 | QMatrix4x4 smallView; ///< No zoom view. 298 | QMatrix4x4 model; ///< Model matrix. 299 | 300 | QOpenGLFramebufferObjectFormat pickFboFormat; ///< Framebuffer used offscreen for object picking. 301 | 302 | GLuint axes_vbo; ///< Vertex buffer object for axes. 303 | GLuint grid_vbo; ///< Vertex buffer object for grid. 304 | 305 | QColor background_col; ///< Background color. 306 | QColor text_col; ///< Text color. 307 | 308 | GLfloat minDiam; ///< Maximum axes diameter of objects in scene. 309 | 310 | GLfloat angleX; ///< X axis angle. 311 | GLfloat angleY; ///< Y axis angle. 312 | 313 | GLfloat xPos; ///< Camera X position. 314 | GLfloat yPos; ///< Camera Y position. 315 | GLfloat zPos; ///< Camera Z position. 316 | 317 | GLfloat zoom; ///< Camera zoom factor. 318 | 319 | QVector4D smallAxesBox; ///< Dimension and position of small axes box in screen coordinates. 320 | 321 | bool Axes; ///< Axes mode on/off. 322 | bool Grid; ///< Grid mode on/off. 323 | bool Info; ///< Info on/off. 324 | 325 | bool selection; ///< Object picking action. 326 | 327 | bool shiftPressed; ///< Shift key pressed. 328 | 329 | bool mouseInverted; ///< Mouse inverted yes/no. 330 | 331 | QPoint lastPos; ///< Last clicked position (LMB). 332 | QPoint lastTransPos; ///< Last clicked position (MMB). 333 | QPoint lastSelectionPos; ///< Last clicked position (RMB). 334 | 335 | GLfloat xTrans; ///< X direction translation factor. 336 | GLfloat yTrans; ///< Y direction translation factor. 337 | 338 | int gridStep; ///< Step between grid lines. 339 | 340 | admeshController *controller; ///< Pointer to main controller. 341 | 342 | QOpenGLVertexArrayObject vao; ///< Vertex array object. 343 | }; 344 | 345 | #endif // MYGLWIDGET_H 346 | -------------------------------------------------------------------------------- /meshobject.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #include "meshobject.h" 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | char* QStringToChar(QString str) 10 | { 11 | string s = str.toStdString(); 12 | char *cstr = new char[s.length() + 1]; 13 | strcpy(cstr, s.c_str()); 14 | return cstr; 15 | } 16 | 17 | MeshObject::MeshObject() 18 | { 19 | stl = new stl_file; 20 | stl_initialize(stl); 21 | selected = true; 22 | saved = true; 23 | file = "new"; 24 | references = 0; 25 | size = 0; 26 | hidden = false; 27 | } 28 | 29 | MeshObject::MeshObject(stl_file* item, QString name) 30 | { 31 | stl = item; 32 | selected = true; 33 | saved = false; 34 | references = 0; 35 | size = 0; 36 | hidden = false; 37 | file = name; 38 | stl_calculate_volume(stl); 39 | initializeGLFunctions(); 40 | glGenBuffers(1, &vbo); 41 | this->updateGeometry(); 42 | } 43 | 44 | MeshObject::MeshObject(const MeshObject& m) : QGLFunctions() 45 | { 46 | references = 0; 47 | hidden = m.hidden; 48 | file = m.file; 49 | saved = m.saved; 50 | selected = m.selected; 51 | stl = new stl_file; 52 | stl_initialize(stl); 53 | stl->fp = m.stl->fp; 54 | stl->stats = m.stl->stats; 55 | stl->M = m.stl->M; 56 | stl->error = m.stl->error; 57 | stl_reallocate(stl); 58 | for(int i=0; istats.number_of_facets;i++){ 59 | stl->facet_start[i] = m.stl->facet_start[i]; 60 | stl->neighbors_start[i] = m.stl->neighbors_start[i]; 61 | } 62 | initializeGLFunctions(); 63 | glGenBuffers(1, &vbo); 64 | this->updateGeometry(); 65 | } 66 | 67 | MeshObject::~MeshObject(){ 68 | stl_close(stl); 69 | delete(stl); 70 | glDeleteBuffers(1, &vbo); 71 | } 72 | 73 | bool MeshObject::loadGeometry(QString fileName) 74 | { 75 | char* filename = QStringToChar(fileName); 76 | stl_open(stl, filename); 77 | if(stl_get_error(stl)){ 78 | stl_clear_error(stl); 79 | return false; 80 | } 81 | delete []filename; 82 | stl_repair(stl,0,1,0,0,0,0,0,0,0,0,0,0,0,0); 83 | stl_calculate_volume(stl); 84 | initializeGLFunctions(); 85 | glGenBuffers(1, &vbo); 86 | this->updateGeometry(); 87 | file = fileName; 88 | return true; 89 | } 90 | 91 | void MeshObject::setSplitName(int index) 92 | { 93 | QString add = "_part_"+QString::number(index)+".stl"; 94 | file = file.section(".",0,0); 95 | file += add; 96 | } 97 | 98 | void MeshObject::setDuplicatedName() 99 | { 100 | QString add = "_duplicated.stl"; 101 | file = file.section(".",0,0); 102 | file += add; 103 | saved = false; 104 | } 105 | 106 | void MeshObject::mergedFilename() 107 | { 108 | QString add = "_merged.stl"; 109 | file = file.section(".",0,0); 110 | file += add; 111 | saved = false; 112 | } 113 | 114 | bool MeshObject::hasValidName() 115 | { 116 | if(file.size() < 5)return false; 117 | else if(file == "untitled")return false; 118 | else if(file == "split")return false; 119 | else return true; 120 | } 121 | 122 | stl_file* MeshObject::getStlPointer() 123 | { 124 | return stl; 125 | } 126 | 127 | bool MeshObject::isSaved() 128 | { 129 | return saved; 130 | } 131 | 132 | void MeshObject::saveAs(QString fileName, int type) 133 | { 134 | char* filename = QStringToChar(fileName); 135 | if(type == 1){ 136 | stl_write_ascii(stl, filename, "ADMeshSTLmodel"); 137 | }else if(type == 2){ 138 | stl_write_binary(stl, filename, "ADMeshSTLmodel"); 139 | } 140 | delete []filename; 141 | file = fileName; 142 | saved = true; 143 | } 144 | 145 | void MeshObject::save() 146 | { 147 | char* filename = QStringToChar(file); 148 | if(stl->stats.type == ascii){ 149 | stl_write_ascii(stl, filename, "ADMeshSTLmodel"); 150 | }else{ 151 | stl_write_binary(stl, filename, "ADMeshSTLmodel"); 152 | } 153 | delete []filename; 154 | saved = true; 155 | } 156 | 157 | void MeshObject::exportSTL(QString fileName, int type) 158 | { 159 | stl_check_facets_exact(stl); 160 | stl_generate_shared_vertices(stl); 161 | char* filename = QStringToChar(fileName); 162 | char label[] = "ADMeshDXFexport"; 163 | if(type == 1){ 164 | stl_write_obj(stl, filename); 165 | }else if(type == 2){ 166 | stl_write_off(stl, filename); 167 | }else if(type == 3){ 168 | stl_write_dxf(stl, filename, label); 169 | }else if(type == 4){ 170 | stl_write_vrml(stl, filename); 171 | } 172 | delete []filename; 173 | } 174 | 175 | QVector3D MeshObject::getMin() 176 | { 177 | QVector3D min = QVector3D( 178 | stl->stats.min.x, 179 | stl->stats.min.y, 180 | stl->stats.max.z 181 | ); 182 | return min; 183 | } 184 | 185 | float MeshObject::getDiameter() 186 | { 187 | float *arr = new float[6]; 188 | float val = 0.0; 189 | arr[0] = qAbs(stl->stats.min.x); 190 | arr[1] = qAbs(stl->stats.min.y); 191 | arr[2] = qAbs(stl->stats.min.z); 192 | arr[3] = qAbs(stl->stats.max.x); 193 | arr[4] = qAbs(stl->stats.max.y); 194 | arr[5] = qAbs(stl->stats.max.z); 195 | for(int i=0;i<6;i++){ 196 | if (arr[i] > val) val = arr[i]; 197 | } 198 | delete []arr; 199 | return val; 200 | } 201 | 202 | float* MeshObject::getInfo() 203 | { 204 | float *arr = new float[15]; 205 | arr[0] = stl->stats.min.x; 206 | arr[1] = stl->stats.min.y; 207 | arr[2] = stl->stats.min.z; 208 | arr[3] = stl->stats.max.x; 209 | arr[4] = stl->stats.max.y; 210 | arr[5] = stl->stats.max.z; 211 | arr[6] = (float)stl->stats.number_of_facets; 212 | arr[7] = (float)stl->stats.degenerate_facets; 213 | arr[8] = (float)stl->stats.edges_fixed; 214 | arr[9] = (float)stl->stats.facets_removed; 215 | arr[10] = (float)stl->stats.facets_added; 216 | arr[11] = (float)stl->stats.facets_reversed; 217 | arr[12] = (float)stl->stats.backwards_edges; 218 | arr[13] = (float)stl->stats.normals_fixed; 219 | arr[14] = stl->stats.volume; 220 | return arr; 221 | } 222 | 223 | QString MeshObject::getName() 224 | { 225 | return file; 226 | } 227 | 228 | void MeshObject::scale(float versor[3]) 229 | { 230 | stl_scale_versor(stl, versor); 231 | this->updateGeometry(); 232 | saved = false; 233 | } 234 | 235 | void MeshObject::mirrorXY() 236 | { 237 | stl_mirror_xy(stl); 238 | this->updateGeometry(); 239 | saved = false; 240 | } 241 | 242 | void MeshObject::mirrorYZ() 243 | { 244 | stl_mirror_yz(stl); 245 | this->updateGeometry(); 246 | saved = false; 247 | } 248 | 249 | void MeshObject::mirrorXZ() 250 | { 251 | stl_mirror_xz(stl); 252 | this->updateGeometry(); 253 | saved = false; 254 | } 255 | 256 | void MeshObject::rotateX(float angle) 257 | { 258 | stl_rotate_x(stl, angle); 259 | this->updateGeometry(); 260 | saved = false; 261 | } 262 | 263 | void MeshObject::rotateY(float angle) 264 | { 265 | stl_rotate_y(stl, angle); 266 | this->updateGeometry(); 267 | saved = false; 268 | } 269 | 270 | void MeshObject::rotateZ(float angle) 271 | { 272 | stl_rotate_z(stl, angle); 273 | this->updateGeometry(); 274 | saved = false; 275 | } 276 | 277 | void MeshObject::translate(bool relative, float x_trans, float y_trans, float z_trans) 278 | { 279 | if(relative){ 280 | stl_translate_relative(stl, x_trans, y_trans, z_trans); 281 | }else{ 282 | stl_translate(stl, x_trans, y_trans, z_trans); 283 | } 284 | this->updateGeometry(); 285 | saved = false; 286 | } 287 | 288 | void MeshObject::center() 289 | { 290 | float xHalfSize = stl->stats.size.x / 2; 291 | float yHalfSize = stl->stats.size.y / 2; 292 | float zHalfSize = stl->stats.size.z / 2; 293 | stl_translate(stl, -xHalfSize, -yHalfSize, -zHalfSize); 294 | this->updateGeometry(); 295 | saved = false; 296 | } 297 | 298 | void MeshObject::snapZ() 299 | { 300 | float minX = stl->stats.min.x; 301 | float minY = stl->stats.min.y; 302 | stl_translate(stl, minX, minY, 0.0); 303 | this->updateGeometry(); 304 | saved = false; 305 | } 306 | 307 | void MeshObject::reverseAll() 308 | { 309 | stl_reverse_all_facets(stl); 310 | this->updateGeometry(); 311 | saved = false; 312 | } 313 | 314 | void MeshObject::repair(int fixall_flag, int exact_flag, int tolerance_flag, float tolerance, int increment_flag, float increment, int nearby_flag, int iterations, int remove_unconnected_flag, int fill_holes_flag, int normal_directions_flag, int normal_values_flag, int reverse_all_flag) 315 | { 316 | stl_repair(stl, 317 | fixall_flag, 318 | exact_flag, 319 | tolerance_flag, 320 | tolerance, 321 | increment_flag, 322 | increment, 323 | nearby_flag, 324 | iterations, 325 | remove_unconnected_flag, 326 | fill_holes_flag, 327 | normal_directions_flag, 328 | normal_values_flag, 329 | reverse_all_flag, 330 | 0); 331 | stl_calculate_volume(stl); 332 | this->updateGeometry(); 333 | saved = false; 334 | } 335 | 336 | void MeshObject::setSelected() 337 | { 338 | selected = true; 339 | } 340 | 341 | void MeshObject::setDeselected() 342 | { 343 | selected = false; 344 | } 345 | 346 | void MeshObject::toggleSelected() 347 | { 348 | selected = !selected; 349 | } 350 | 351 | bool MeshObject::isSelected() 352 | { 353 | return selected; 354 | } 355 | 356 | bool MeshObject::isActive() 357 | { 358 | return(selected && !hidden); 359 | } 360 | 361 | void MeshObject::setHidden() 362 | { 363 | hidden = true; 364 | } 365 | 366 | void MeshObject::setVisible() 367 | { 368 | hidden = false; 369 | } 370 | 371 | bool MeshObject::isHidden() 372 | { 373 | return hidden; 374 | } 375 | 376 | bool MeshObject::hasReferences() 377 | { 378 | if(references > 0) return true; 379 | else return false; 380 | } 381 | 382 | void MeshObject::addReference() 383 | { 384 | references++; 385 | } 386 | 387 | void MeshObject::removeReference() 388 | { 389 | references--; 390 | } 391 | 392 | void MeshObject::countSize() 393 | { 394 | size = 2*stl->stats.number_of_facets*SIZEOF_STL_FACET; //for facets and neighbours 395 | size += sizeof(stl->stats); 396 | size += sizeof(stl_file); 397 | size += sizeof(*this); 398 | } 399 | 400 | unsigned long MeshObject::getSize() 401 | { 402 | return size; 403 | } 404 | 405 | void MeshObject::updateGeometry() 406 | { 407 | int N = stl->stats.number_of_facets; 408 | 409 | countSize(); 410 | GLfloat *vertices; 411 | vertices=new GLfloat[N*18]; 412 | for(int i=0;ifacet_start[i].vertex[0].x; 415 | vertices[index+1]=stl->facet_start[i].vertex[0].y; 416 | vertices[index+2]=stl->facet_start[i].vertex[0].z; 417 | vertices[index+3]=stl->facet_start[i].normal.x; 418 | vertices[index+4]=stl->facet_start[i].normal.y; 419 | vertices[index+5]=stl->facet_start[i].normal.z; 420 | 421 | vertices[index+6]=stl->facet_start[i].vertex[1].x; 422 | vertices[index+7]=stl->facet_start[i].vertex[1].y; 423 | vertices[index+8]=stl->facet_start[i].vertex[1].z; 424 | vertices[index+9]=stl->facet_start[i].normal.x; 425 | vertices[index+10]=stl->facet_start[i].normal.y; 426 | vertices[index+11]=stl->facet_start[i].normal.z; 427 | 428 | vertices[index+12]=stl->facet_start[i].vertex[2].x; 429 | vertices[index+13]=stl->facet_start[i].vertex[2].y; 430 | vertices[index+14]=stl->facet_start[i].vertex[2].z; 431 | vertices[index+15]=stl->facet_start[i].normal.x; 432 | vertices[index+16]=stl->facet_start[i].normal.y; 433 | vertices[index+17]=stl->facet_start[i].normal.z; 434 | } 435 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 436 | glBufferData(GL_ARRAY_BUFFER, N * 18 * sizeof(GLfloat), vertices, GL_DYNAMIC_DRAW); 437 | delete [] vertices; 438 | } 439 | 440 | void MeshObject::drawGeometry(QGLShaderProgram *program) 441 | { 442 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 443 | 444 | int vertexLocation = program->attributeLocation("a_position"); 445 | program->enableAttributeArray(vertexLocation); 446 | glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*6, 0); 447 | 448 | int normalLocation = program->attributeLocation("a_normal"); 449 | program->enableAttributeArray(normalLocation); 450 | glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*6, (const void *)(sizeof(GLfloat)*3)); 451 | 452 | glDrawArrays(GL_TRIANGLES, 0, stl->stats.number_of_facets*3); 453 | } 454 | 455 | -------------------------------------------------------------------------------- /Resources/admeshgui.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | image/svg+xml 57 | 58 | 59 | 60 | 61 | Lapo Calamandrei 62 | 63 | 64 | Swiss Army Knife 65 | 66 | 67 | utilities 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /admeshcontroller.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #ifndef ADMESHCONTROLLER_H 4 | #define ADMESHCONTROLLER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "data.h" 18 | #include "meshobject.h" 19 | #include "historylist.h" 20 | 21 | using namespace std; 22 | 23 | /*! 24 | * \brief Controls loaded MeshObjects and drawing 25 | */ 26 | class admeshController : public QObject 27 | { 28 | Q_OBJECT 29 | public: 30 | /*! 31 | * \brief Default constructor 32 | */ 33 | explicit admeshController(QObject *parent = 0); 34 | 35 | /*! 36 | * \brief Destructs holded MeshObjects 37 | */ 38 | ~admeshController(); 39 | 40 | /*! 41 | * \brief Draws all MeshObjects to the scene 42 | * \param program Shader program used to draw objects 43 | */ 44 | void drawAll(QGLShaderProgram *program); 45 | 46 | /*! 47 | * \brief Sets drawing colors 48 | * 49 | * Sets both default color and different color used to draw backfaces 50 | * 51 | * \param argc color Default color 52 | * \param args badColor Backfaces color 53 | */ 54 | void setDrawColor(QColor color,QColor badColor); 55 | 56 | /*! 57 | * \brief Set history limit to history list used. 58 | * 59 | * \param lim Limit in MB. 60 | */ 61 | void setHistoryLimit(int lim); 62 | 63 | /*! 64 | * \brief Get info about all selected meshes. 65 | * \return string containing formated info. 66 | */ 67 | QString getInfo(); 68 | 69 | /*! 70 | * \brief Add UI items pointers to be accessible from controller. 71 | * \param l Status bar label 72 | * \param v ListView for selection 73 | */ 74 | void addUIItems(QLabel *l,QListView *v); 75 | 76 | /*! 77 | * \brief Write settings to config. 78 | */ 79 | void writeSettings(); 80 | 81 | signals: 82 | /*! 83 | * \brief Sends signal to rendering widget to redraw 84 | * 85 | * Sent always after manipulation with STL files 86 | */ 87 | void reDrawSignal(); 88 | 89 | /*! 90 | * \brief Sends signal to recalculate view according to model size. 91 | */ 92 | void reCalculatePosition(); 93 | 94 | /*! 95 | * \brief Sends signal to enable or disable edit panel. 96 | * 97 | * 0 objects in scene = disabled edit 98 | */ 99 | void enableEdit(bool); 100 | 101 | /*! 102 | * \brief Sends signal to set all scale spinboxes to same value. 103 | */ 104 | void scaleSignal(double); 105 | 106 | /*! 107 | * \brief Sends signal to enable or disable Undo in menu and in toolbar. 108 | */ 109 | void allowUndo(bool); 110 | 111 | /*! 112 | * \brief Sends signal to enable or disable Redo in menu and in toolbar. 113 | */ 114 | void allowRedo(bool); 115 | 116 | /*! 117 | * \brief Sends signal to enable or disable Save in menu and in toolbar. 118 | */ 119 | void allowSave(bool); 120 | 121 | /*! 122 | * \brief Sends signal to enable or disable Save as in menu. 123 | */ 124 | void allowSaveAs(bool); 125 | 126 | /*! 127 | * \brief Sends signal to enable or disable Export in menu. 128 | */ 129 | void allowExport(bool); 130 | 131 | /*! 132 | * \brief Sends signal to enable or disable Close in menu and in toolbar. 133 | */ 134 | void allowClose(bool); 135 | 136 | public slots: 137 | /*! 138 | * \brief Handle selection in ListView. 139 | * 140 | * Toggle active state of item under given index. 141 | * 142 | * \param modelindex index of item to change. 143 | */ 144 | void handleSelectionChanged(QItemSelection selection, QItemSelection deselection); 145 | 146 | /*! 147 | * \brief Set rendering mode. 148 | * 149 | * Sets solid/wireframe or solid mode with thick edges. 150 | * 151 | * \param m Mode selected. 152 | */ 153 | void setMode(int m); 154 | 155 | /*! 156 | * \brief Get count of selected objects. 157 | * 158 | * \return count 159 | */ 160 | int selectedCount(); 161 | 162 | /*! 163 | * \brief Draw into picking offsreen buffer. 164 | * 165 | * Draws all objects into scene. Each object with own different color used to determine which one was clicked. 166 | * 167 | * \param program Shader program used. 168 | */ 169 | void drawPicking(QGLShaderProgram *program); 170 | 171 | /*! 172 | * \brief Set object active by given index. 173 | * \param id Index to be selected. 174 | */ 175 | void setActiveByIndex(GLuint id); 176 | 177 | /*! 178 | * \brief Set all objects active. 179 | */ 180 | void setAllActive(); 181 | 182 | /*! 183 | * \brief Set all objects ainctive. 184 | */ 185 | void setAllInactive(); 186 | 187 | /*! 188 | * \brief Inverse all objects active state. 189 | */ 190 | void setAllInverseActive(); 191 | 192 | /*! 193 | * \brief Hide all selected items. 194 | */ 195 | void hide(); 196 | 197 | /*! 198 | * \brief Unhide all selected items. 199 | */ 200 | void unhide(); 201 | 202 | /*! 203 | * \brief Unhide all items. 204 | */ 205 | void unhideAll(); 206 | 207 | /*! 208 | * \brief Open dialog window to open STL file 209 | */ 210 | void openSTL(); 211 | 212 | /*! 213 | * \brief Open STL file given by parameter 214 | */ 215 | void openSTLbyName(const char* file); 216 | 217 | /*! 218 | * \brief Close selected objects 219 | */ 220 | void closeSTL(); 221 | 222 | /*! 223 | * \brief Save STL file as binary or ascii 224 | */ 225 | void saveAs(); 226 | 227 | /*! 228 | * \brief Save selected STL files in default format 229 | */ 230 | void save(); 231 | 232 | /*! 233 | * \brief Save one MeshObject. Native save if filename is valid, otherwise save as. 234 | * 235 | * \param object Pointer to MeshObject to save 236 | */ 237 | void saveObject(MeshObject* object); 238 | 239 | /*! 240 | * \brief Ask for save of unsaved files upon application close. 241 | */ 242 | bool saveOnClose(); 243 | 244 | /*! 245 | * \brief Export STL file as OFF, VRML, DXF or OBJ 246 | */ 247 | void exportSTL(); 248 | 249 | /*! 250 | * \brief Get maximal diameter of last object in list. Called by RenderingWidget once new file is loaded. 251 | * 252 | * \return diameter 253 | */ 254 | float getMaxDiameter(); 255 | 256 | /*! 257 | * \brief Set scale versor X factor. 258 | * \param factor Factor 259 | */ 260 | void setVersorX(double factor); 261 | 262 | /*! 263 | * \brief Set scale versor Y factor. 264 | * \param factor Factor 265 | */ 266 | void setVersorY(double factor); 267 | 268 | /*! 269 | * \brief Set scale versor Z factor. 270 | * \param factor Factor 271 | */ 272 | void setVersorZ(double factor); 273 | 274 | /*! 275 | * \brief Use versor or not. 276 | */ 277 | void setVersor(); 278 | 279 | /*! 280 | * \brief Scale selected model by scale factor. 281 | */ 282 | void scale(); 283 | 284 | /*! 285 | * \brief Mirror selected model by XY plane. 286 | */ 287 | void mirrorXY(); 288 | 289 | /*! 290 | * \brief Mirror selected model by YZ plane. 291 | */ 292 | void mirrorYZ(); 293 | 294 | /*! 295 | * \brief Mirror selected model by XZ plane. 296 | */ 297 | void mirrorXZ(); 298 | 299 | /*! 300 | * \brief Set rotation angle. 301 | * \param angle Angle of rotation. 302 | */ 303 | void setRot(double angle); 304 | 305 | /*! 306 | * \brief Rotate selected model by angle along X axis. 307 | */ 308 | void rotateX(); 309 | 310 | /*! 311 | * \brief Rotate selected model by angle along Y axis. 312 | */ 313 | void rotateY(); 314 | 315 | /*! 316 | * \brief Rotate selected model by angle along Z axis. 317 | */ 318 | void rotateZ(); 319 | 320 | /*! 321 | * \brief Set X translation factor. 322 | * \param factor Factor of translation. 323 | */ 324 | void setXTranslate(double factor); 325 | 326 | /*! 327 | * \brief Set Y translation factor. 328 | * \param factor Factor of translation. 329 | */ 330 | void setYTranslate(double factor); 331 | 332 | /*! 333 | * \brief Set Z translation factor. 334 | * \param factor Factor of translation. 335 | */ 336 | void setZTranslate(double factor); 337 | 338 | /*! 339 | * \brief Switch between relative and non-relative translation. 340 | */ 341 | void setRelativeTranslate(); 342 | 343 | /*! 344 | * \brief Translate selected model with factors given. 345 | */ 346 | void translate(); 347 | 348 | /*! 349 | * \brief Translate selected model to be centered around origin. 350 | */ 351 | void center(); 352 | 353 | /*! 354 | * \brief Snap selected model to zero Z coordinate. 355 | */ 356 | void snapZ(); 357 | 358 | /*! 359 | * \brief Reverse all facets orientation of selected models. 360 | */ 361 | void reverseAll(); 362 | 363 | /*! 364 | * \brief Set fix all flag. 365 | */ 366 | void setFixAllFlag(); 367 | 368 | /*! 369 | * \brief Set exact flag. 370 | */ 371 | void setExactFlag(); 372 | 373 | /*! 374 | * \brief Set tolerance flag. 375 | */ 376 | void setToleranceFlag(); 377 | 378 | /*! 379 | * \brief Set tolerance. 380 | * \param val Tolerance value. 381 | */ 382 | void setTolerance(double val); 383 | 384 | /*! 385 | * \brief Set increment flag. 386 | */ 387 | void setIncrementFlag(); 388 | 389 | /*! 390 | * \brief Set increment. 391 | * \param val Increment value; 392 | */ 393 | void setIncrement(double val); 394 | 395 | /*! 396 | * \brief Set nearby flag. 397 | */ 398 | void setNearbyFlag(); 399 | 400 | /*! 401 | * \brief Set iterations. 402 | * \param val Number of iterations. 403 | */ 404 | void setIterations(int val); 405 | 406 | /*! 407 | * \brief Set remove unconnected vertices flag. 408 | */ 409 | void setRemoveUnconnectedFlag(); 410 | 411 | /*! 412 | * \brief Set fill holes flag. 413 | */ 414 | void setFillHolesFlag(); 415 | 416 | /*! 417 | * \brief Set repair normal directions flag. 418 | */ 419 | void setNormalDirFlag(); 420 | 421 | /*! 422 | * \brief Set repair normal values flag. 423 | */ 424 | void setNormalValFlag(); 425 | 426 | /*! 427 | * \brief Repair selected model according to selected flags. 428 | */ 429 | void repair(); 430 | 431 | /*! 432 | * \brief Merge all active models into one. 433 | */ 434 | void merge(); 435 | 436 | /*! 437 | * \brief Split all active models by shells if possible. 438 | */ 439 | void split(); 440 | 441 | /*! 442 | * \brief Duplicate all active models. 443 | */ 444 | void duplicate(); 445 | 446 | /*! 447 | * \brief Undo last operation. 448 | */ 449 | void undo(); 450 | 451 | /*! 452 | * \brief Redo last undoed operation. 453 | */ 454 | void redo(); 455 | 456 | private: 457 | /*! 458 | * \brief Add current items state into history list. 459 | */ 460 | void pushHistory(); 461 | /*! 462 | * \brief Prepare items for next operation. 463 | * 464 | * Active items are deep copied. 465 | * Reference for each inactive item is raised. 466 | */ 467 | void renewList(); 468 | 469 | /*! 470 | * \brief Update listView of items according to current item list. 471 | */ 472 | void renewListView(); 473 | 474 | /*! 475 | * \brief Add name of given item at the end of ListView. 476 | * 477 | * \param item Item to be processed. 478 | */ 479 | void addItemToView(MeshObject* item); 480 | 481 | /*! 482 | * \brief Allow use of selected actions based on scene state. 483 | * 484 | * E.g. allow undo/redo. 485 | */ 486 | void allowFunctions(); 487 | 488 | /*! 489 | * \brief Allow use of selected actions based on selection. 490 | * 491 | * E.g. allow save as/export. 492 | */ 493 | void allowSelectionFunctions(); 494 | 495 | historyList history; ///< History list 496 | QList objectList; ///< List of currently drawn objects. 497 | QVector3D color; ///< Default color 498 | QVector3D badColor; ///< Backface color 499 | QLabel* statusBar; ///< Status bar pointer. 500 | QListView *listView; ///< ListView pointer. 501 | QStandardItemModel *listModel; ///< Model to be displayed in ListView. 502 | QList ::size_type count; ///< Count of all objects. 503 | QIcon hiddenIcon; ///< Hidden icon 504 | QIcon visibleIcon; ///< Visible icon 505 | QString openPath; ///< Last path used for file open 506 | int mode; ///< Solid or wireframe or both mode 507 | float versor[3]; ///< Scale versor 508 | bool useVersor; ///< Use versor or not 509 | float rot; ///< Rotation angle 510 | float x_translate; ///< X translation factor 511 | float y_translate; ///< Y translation factor 512 | float z_translate; ///< Z translation factor 513 | bool rel_translate; ///< Relative translation 514 | bool fixall_flag; 515 | bool exact_flag; 516 | bool tolerance_flag; 517 | float tolerance; 518 | bool increment_flag; 519 | float increment; 520 | bool nearby_flag; 521 | int iterations; 522 | bool remove_unconnected_flag; 523 | bool fill_holes_flag; 524 | bool normal_directions_flag; 525 | bool normal_values_flag; 526 | clock_t start_time; 527 | }; 528 | 529 | #endif // ADMESHCONTROLLER_H 530 | -------------------------------------------------------------------------------- /renderingwidget.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #include 4 | #include 5 | #include 6 | #include "renderingwidget.h" 7 | 8 | RenderingWidget::RenderingWidget(QWidget *parent) 9 | : QOpenGLWidget(parent) 10 | { 11 | Axes = true; 12 | Grid = false; 13 | Info = true; 14 | xPos = 1.0f; 15 | yPos = 0.5f; 16 | zPos = 1.0f; 17 | angleX = 0.0f; 18 | angleY = 70.0f; 19 | zoom = 100.0f; 20 | model.setToIdentity(); 21 | model.rotate(90, -1.0f,0.0f,0.0f); //Rotate to OpenGL axes system 22 | smallAxesBox = QVector4D(5, 5, 105, 105); 23 | gridStep = 1; 24 | shiftPressed = false; 25 | minDiam = 1.0f; 26 | background_col = Qt::black; 27 | text_col = Qt::white; 28 | mouseInverted = false; 29 | w = DEFAULT_RES_X; 30 | h = DEFAULT_RES_Y; 31 | } 32 | 33 | 34 | RenderingWidget::~RenderingWidget() 35 | { 36 | glDeleteBuffers(1, &axes_vbo); 37 | glDeleteBuffers(1, &grid_vbo); 38 | } 39 | 40 | void RenderingWidget::writeSettings() 41 | { 42 | QSettings settings; 43 | settings.setValue("axes", Axes); 44 | settings.setValue("grid", Grid); 45 | settings.setValue("info", Info); 46 | } 47 | 48 | void RenderingWidget::invertMouse() 49 | { 50 | mouseInverted = !mouseInverted; 51 | } 52 | 53 | void RenderingWidget::setController(admeshController* cnt) 54 | { 55 | controller = cnt; 56 | } 57 | 58 | QSize RenderingWidget::minimumSizeHint() const 59 | { 60 | return QSize(50, 50); 61 | } 62 | 63 | QSize RenderingWidget::sizeHint() const 64 | { 65 | QSettings settings; 66 | return QSize(settings.value("width",DEFAULT_RES_X).toInt(), settings.value("height",DEFAULT_RES_Y).toInt()); 67 | } 68 | 69 | void RenderingWidget::setBackground(QColor b) 70 | { 71 | background_col = b; 72 | } 73 | 74 | void RenderingWidget::setTextCol(QColor text) 75 | { 76 | text_col = text; 77 | } 78 | 79 | void RenderingWidget::setFrontView() 80 | { 81 | angleX = 0; 82 | angleY = 90; 83 | reDraw(); 84 | } 85 | 86 | void RenderingWidget::setBackView() 87 | { 88 | angleX = 180; 89 | angleY = 90; 90 | reDraw(); 91 | } 92 | 93 | void RenderingWidget::setLeftView() 94 | { 95 | angleX = 270; 96 | angleY = 90; 97 | reDraw(); 98 | } 99 | 100 | void RenderingWidget::setRightView() 101 | { 102 | angleX = 90; 103 | angleY = 90; 104 | reDraw(); 105 | } 106 | 107 | void RenderingWidget::setTopView() 108 | { 109 | angleX = 0; 110 | angleY = 0; 111 | reDraw(); 112 | } 113 | 114 | void RenderingWidget::setBottomView() 115 | { 116 | angleX = 0; 117 | angleY = 180; 118 | reDraw(); 119 | } 120 | 121 | void RenderingWidget::toggleGrid() 122 | { 123 | Grid = !Grid; 124 | update(); 125 | } 126 | 127 | void RenderingWidget::toggleAxes() 128 | { 129 | Axes = !Axes; 130 | update(); 131 | } 132 | 133 | void RenderingWidget::toggleInfo() 134 | { 135 | Info = !Info; 136 | update(); 137 | } 138 | 139 | void RenderingWidget::initializeGL() 140 | { 141 | initializeGLFunctions(); 142 | initShaders(); 143 | glGenBuffers(1, &axes_vbo); 144 | glGenBuffers(1, &grid_vbo); 145 | vao.create(); 146 | selection = false; 147 | initAxes(); 148 | initGrid(); 149 | glClearColor(background_col.redF(),background_col.greenF(),background_col.blueF(),1.0); 150 | glEnable(GL_DEPTH_TEST); 151 | pickFboFormat.setAttachment(QOpenGLFramebufferObject::Depth); 152 | pickFboFormat.setTextureTarget(GL_TEXTURE_2D); 153 | pickFboFormat.setInternalTextureFormat(GL_RGBA8); 154 | recalculateGridStep(); 155 | reDraw(); 156 | } 157 | 158 | void RenderingWidget::initShaders(){ 159 | if (!program.addShaderFromSourceFile(QGLShader::Vertex, ":/vshader.glsl")) close(); 160 | 161 | if (!program.addShaderFromSourceFile(QGLShader::Fragment, ":/fshader.glsl")) close(); 162 | 163 | if (!program.link()) close(); 164 | 165 | if (!program.bind()) close(); 166 | 167 | if (!pick_program.addShaderFromSourceFile(QGLShader::Vertex, ":/picking_vshader.glsl")) close(); 168 | 169 | if (!pick_program.addShaderFromSourceFile(QGLShader::Fragment, ":/picking_fshader.glsl")) close(); 170 | 171 | if (!pick_program.link()) close(); 172 | 173 | if (!pick_program.bind()) close(); 174 | 175 | } 176 | 177 | void RenderingWidget::timerEvent(QTimerEvent *) 178 | { 179 | update(); 180 | } 181 | 182 | void RenderingWidget::paintGL() 183 | { 184 | QPainter painter; 185 | painter.begin(this); 186 | painter.setRenderHint(QPainter::Antialiasing); 187 | painter.beginNativePainting(); //Start rendering 3D content 188 | 189 | glClearColor(background_col.redF(),background_col.greenF(),background_col.blueF(),1.0); //Set OpenGl states 190 | glEnable(GL_DEPTH_TEST); 191 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 192 | 193 | vao.bind(); 194 | program.bind(); //Use shader program 195 | glViewport(0, 0, w, h); 196 | getCamPos(); 197 | 198 | program.setUniformValue("differ_hue", false); 199 | program.setUniformValue("mvp_matrix", projection * view * model); //Draw main window contents 200 | 201 | if(Axes) drawAxes(); 202 | if(Grid) drawGrid(); 203 | 204 | program.setUniformValue("mvp_matrix", projection * view * model); 205 | controller->drawAll(&program); 206 | 207 | glViewport(smallAxesBox.x(), smallAxesBox.y(), smallAxesBox.z(), smallAxesBox.w()); // xStart, yStart, xWidth, yWidth 208 | program.setUniformValue("mvp_matrix", orthographic * smallView * model); //Draw corner orthographic axes 209 | drawSmallAxes(); 210 | glBindBuffer(GL_ARRAY_BUFFER, 0); 211 | 212 | glDisable(GL_DEPTH_TEST); 213 | program.release(); 214 | vao.release(); 215 | painter.endNativePainting(); //Start rendering 2D content 216 | 217 | painter.setRenderHint(QPainter::TextAntialiasing); 218 | if(Info) drawInfo(&painter); 219 | drawLabels(&painter); 220 | 221 | if(selection){ //Handle picking 222 | painter.beginNativePainting(); 223 | vao.bind(); 224 | doPicking(); 225 | selection = false; 226 | vao.release(); 227 | } 228 | painter.end(); 229 | } 230 | 231 | void RenderingWidget::recalculateProjectionNear() 232 | { 233 | if(2*minDiam < zoom){ 234 | projection.setToIdentity(); 235 | projection.perspective(PERSPECTIVE, (GLfloat)width()/(GLfloat)height(), 1.0, MAX_VIEW_DISTANCE); 236 | }else{ 237 | projection.setToIdentity(); 238 | projection.perspective(PERSPECTIVE, (GLfloat)width()/(GLfloat)height(), MIN_VIEW_DISTANCE, MAX_VIEW_DISTANCE); 239 | } 240 | } 241 | 242 | void RenderingWidget::resizeGL(int width, int height) 243 | { 244 | w = width * this->devicePixelRatio(); 245 | h = height * this->devicePixelRatio(); 246 | glViewport(0, 0, w, h); 247 | projection.setToIdentity(); 248 | projection.perspective(PERSPECTIVE, (GLfloat)w/(GLfloat)h, MIN_VIEW_DISTANCE, MAX_VIEW_DISTANCE); 249 | orthographic.setToIdentity(); 250 | orthographic.ortho (-1.0f,1.0f,-1.0f,1.0f, -100, 100 ); 251 | } 252 | 253 | void RenderingWidget::doPicking(){ 254 | glViewport(0, 0, w, h); 255 | QOpenGLFramebufferObject fbo(w,h, pickFboFormat); 256 | fbo.bind(); 257 | glEnable(GL_DEPTH_TEST); 258 | glClearColor(1.0,1.0,1.0,1.0); 259 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 260 | pick_program.bind(); 261 | pick_program.setUniformValue("mvp_matrix", projection * view * model); 262 | controller->drawPicking(&pick_program); 263 | QImage img = fbo.toImage(); 264 | QRgb color = img.pixel(lastSelectionPos.x(),lastSelectionPos.y()); 265 | int id = qBlue(color) + qGreen(color)*255 + qRed(color)*255*255; 266 | if(shiftPressed){ 267 | controller->setActiveByIndex(id); 268 | }else{ 269 | controller->setAllInactive(); 270 | controller->setActiveByIndex(id); 271 | } 272 | pick_program.release(); 273 | fbo.release(); 274 | } 275 | 276 | void RenderingWidget::drawInfo(QPainter *painter) 277 | { 278 | glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); 279 | 280 | QString style; 281 | style = ""; 285 | 286 | QString text = style + controller->getInfo(); 287 | #ifdef QT_DEBUG 288 | QTextStream(&text) << ""<<_("Camera angle X:") <<""<" << 289 | ""<<_("Camera angle Y:") <<""<"; 290 | #endif 291 | if(Grid) QTextStream(&text) << ""<<_("Grid step:") <<""<"; 292 | else QTextStream(&text) << ""; 293 | QTextDocument* doc = new QTextDocument(this); 294 | doc->setUndoRedoEnabled(false); 295 | doc->setPageSize(QSizeF(qMin((int)(width()*0.7),300), height())); 296 | doc->setHtml(text); 297 | doc->setUseDesignMetrics(true); 298 | doc->setDefaultTextOption(QTextOption(Qt::AlignLeft)); 299 | doc->drawContents(painter); 300 | delete doc; 301 | } 302 | 303 | QVector2D RenderingWidget::getScreenCoords(QVector3D worldCoords){ 304 | QVector4D homogCoords = orthographic * smallView * model * QVector4D(worldCoords, 1.0); 305 | GLfloat X = homogCoords.x() / homogCoords.w(); 306 | GLfloat Y = homogCoords.y() / homogCoords.w(); 307 | return QVector2D(smallAxesBox.x() + smallAxesBox.z() * (X+1)/2,smallAxesBox.y() + smallAxesBox.w() * (Y+1)/2); 308 | } 309 | 310 | void RenderingWidget::drawLabels(QPainter *painter) 311 | { 312 | glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); 313 | QVector2D screenCoords = getScreenCoords(QVector3D(0.7, -0.5 , -0.55)); // X axis 314 | painter->setPen(Qt::red); 315 | painter->drawText(screenCoords.x(),height()-screenCoords.y(),"x"); 316 | screenCoords = getScreenCoords(QVector3D(-0.5, 0.7, -0.55)); // Y axis 317 | painter->setPen(Qt::green); 318 | painter->drawText(screenCoords.x(),height()-screenCoords.y(),"y"); 319 | screenCoords = getScreenCoords(QVector3D(-0.5, -0.5, 0.7)); // Z axis 320 | painter->setPen(Qt::blue); 321 | painter->drawText(screenCoords.x(),height()-screenCoords.y(),"z"); 322 | } 323 | 324 | void RenderingWidget::getCamPos() 325 | { 326 | xPos = sin(angleY*(M_PI/180)) * sin(angleX*(M_PI/180)); 327 | yPos = cos(angleY*(M_PI/180)); 328 | zPos = sin(angleY*(M_PI/180)) * cos(angleX*(M_PI/180)); 329 | 330 | GLfloat dt=1.0f; //Small difference to get second point 331 | 332 | GLfloat upX=sin(angleY*(M_PI/180)-dt) * sin(angleX*(M_PI/180)) -xPos; 333 | GLfloat upY=cos(angleY*(M_PI/180)-dt) -yPos; 334 | GLfloat upZ=sin(angleY*(M_PI/180)-dt) * cos(angleX*(M_PI/180)) -zPos; 335 | 336 | view.setToIdentity(); 337 | view.translate(xTrans, yTrans, -zoom); 338 | view.lookAt (QVector3D(xPos, yPos,zPos), QVector3D(0.0, 0.0, 0.0), QVector3D(upX, upY, upZ)); 339 | 340 | smallView.setToIdentity(); 341 | smallView.lookAt (QVector3D(xPos, yPos, zPos), QVector3D(0.0, 0.0, 0.0), QVector3D(upX, upY, upZ)); 342 | } 343 | 344 | void RenderingWidget::normalizeAngles() 345 | { 346 | if(angleX > 360.0f) angleX = fmod((double)angleX,360.0); 347 | if(angleY > 360.0f) angleY = fmod((double)angleY,360.0); 348 | if(angleX < 0.0f) angleX = 360.0f - angleX; 349 | if(angleY < 0.0f) angleY = 360.0f - angleY; 350 | } 351 | 352 | void RenderingWidget::recalculateGridStep() 353 | { 354 | int factor = (int)(zoom/GRID_SIZE); 355 | if(factor > 5){ 356 | int remainder = factor % 5; 357 | factor -= remainder; 358 | }else{ 359 | factor = qMax(1,factor); 360 | } 361 | if(factor != gridStep) { 362 | gridStep = factor; 363 | initGrid(); 364 | } 365 | } 366 | 367 | void RenderingWidget::toggleShift() 368 | { 369 | shiftPressed = !shiftPressed; 370 | } 371 | 372 | void RenderingWidget::wheelEvent(QWheelEvent* event) 373 | { 374 | float tmp = zoom; 375 | float factor; 376 | if(this->devicePixelRatio()>1) factor=1.1; 377 | else factor = 1.25; 378 | if(event->delta()<0){ 379 | tmp *= factor; 380 | }else{ 381 | tmp *= 1/factor; 382 | } 383 | if(tmp > MIN_ZOOM && tmp < MAX_ZOOM){ 384 | zoom = tmp; 385 | recalculateGridStep(); 386 | recalculateProjectionNear(); 387 | } 388 | reDraw(); 389 | } 390 | 391 | void RenderingWidget::mouseReleaseEvent(QMouseEvent *event) 392 | { 393 | timer.stop(); 394 | event->accept(); 395 | } 396 | 397 | void RenderingWidget::mousePressEvent(QMouseEvent *event) 398 | { 399 | timer.start(33, this); 400 | if(event->buttons() & Qt::LeftButton && !shiftPressed) lastPos = event->pos(); 401 | if(event->buttons() & Qt::RightButton) { 402 | lastSelectionPos = event->pos(); 403 | selection = true; 404 | } 405 | if((event->buttons() & Qt::MiddleButton) || (event->buttons() & Qt::LeftButton && shiftPressed)) lastTransPos = event->pos(); 406 | } 407 | 408 | void RenderingWidget::mouseMoveEvent(QMouseEvent *event) 409 | { 410 | if(event->buttons() & Qt::LeftButton && !shiftPressed) 411 | { 412 | int dx = event->x() - lastPos.x(); 413 | int dy = event->y() - lastPos.y(); 414 | 415 | if(!mouseInverted){ 416 | angleY -= dy; 417 | if(angleY>180)angleX += dx; //take care of opposite rotation upside down 418 | else angleX -=dx; 419 | }else{ 420 | angleY += dy; 421 | if(angleY>180)angleX -= dx; //take care of opposite rotation upside down 422 | else angleX +=dx; 423 | } 424 | 425 | normalizeAngles(); 426 | lastPos = event->pos(); 427 | } 428 | if((event->buttons() & Qt::MiddleButton) || (event->buttons() & Qt::LeftButton && shiftPressed)) 429 | { 430 | int dx = (event->x() - lastTransPos.x()); 431 | int dy = (event->y() - lastTransPos.y()); 432 | 433 | if(!mouseInverted){ 434 | xTrans += (GLfloat)dx/3; 435 | yTrans -= (GLfloat)dy/3; 436 | }else{ 437 | xTrans -= (GLfloat)dx/3; 438 | yTrans += (GLfloat)dy/3; 439 | } 440 | lastTransPos = event->pos(); 441 | } 442 | //reDraw(); 443 | } 444 | 445 | void RenderingWidget::initAxes(){ 446 | GLfloat val = 0.5; 447 | if(this->devicePixelRatio()>1) val = 1.5f; 448 | GLfloat vertices[]={ 449 | AXIS_SIZE, 0.0 , 0.0, //Main axes 450 | 1.0, 1.0, 1.0, 451 | 0.0, 0.0, 0.0, 452 | 1.0, 1.0, 1.0, 453 | 0.0, 0.0 , 0.0, 454 | 1.0, 1.0, 1.0, 455 | -AXIS_SIZE, 0.0, 0.0, 456 | 1.0, 1.0, 1.0, 457 | 0.0, AXIS_SIZE, 0.0, 458 | 1.0, 1.0, 1.0, 459 | 0.0, 0.0, 0.0, 460 | 1.0, 1.0, 1.0, 461 | 0.0, 0.0, 0.0, 462 | 1.0, 1.0, 1.0, 463 | 0.0, -AXIS_SIZE, 0.0, 464 | 1.0, 1.0, 1.0, 465 | 0.0, 0.0, AXIS_SIZE, 466 | 1.0, 1.0, 1.0, 467 | 0.0, 0.0, 0.0, 468 | 1.0, 1.0, 1.0, 469 | 0.0, 0.0, 0.0, 470 | 1.0, 1.0, 1.0, 471 | 0.0, 0.0, -AXIS_SIZE, 472 | 1.0, 1.0, 1.0, //Small corner axes 473 | val, -0.5 , -0.5, //x 474 | 1.0, 1.0, 1.0, 475 | -0.5, -0.5, -0.5, 476 | 1.0, 1.0, 1.0, 477 | -0.5, -0.5, -0.5, //y 478 | 1.0, 1.0, 1.0, 479 | -0.5, val, -0.5, 480 | 1.0, 1.0, 1.0, 481 | -0.5, -0.5, val, //z 482 | 1.0, 1.0, 1.0, 483 | -0.5, -0.5, -0.5, 484 | 1.0, 1.0, 1.0, 485 | 486 | }; 487 | glBindBuffer(GL_ARRAY_BUFFER, axes_vbo); 488 | glBufferData(GL_ARRAY_BUFFER, 108 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); 489 | } 490 | 491 | void RenderingWidget::initGrid(){ 492 | int size= (GRID_SIZE+1)* 4 * 4; // 4*4 for 4 sides of vertexes * 4 float 493 | GLfloat *vertices= new GLfloat[size]; 494 | for(int i = 0;i<= GRID_SIZE*2; i++){ 495 | vertices[i*4]=-GRID_SIZE*gridStep; 496 | vertices[i*4 + 1]=(i-GRID_SIZE)*gridStep; 497 | vertices[i*4 + 2]=GRID_SIZE*gridStep; 498 | vertices[i*4 + 3]=(i-GRID_SIZE)*gridStep; 499 | } 500 | int ind = GRID_SIZE*2*4+4; 501 | for(int i = 0;i<= GRID_SIZE*2; i++){ 502 | vertices[ind + (i*4)]=(i-GRID_SIZE)*gridStep; 503 | vertices[ind + (i*4+1)]=-GRID_SIZE*gridStep; 504 | vertices[ind + (i*4+2)]=(i-GRID_SIZE)*gridStep; 505 | vertices[ind + (i*4+3)]=GRID_SIZE*gridStep; 506 | } 507 | glBindBuffer(GL_ARRAY_BUFFER, grid_vbo); 508 | glBufferData(GL_ARRAY_BUFFER, (GRID_SIZE+1) * 4 * 4 * sizeof(GLfloat), vertices, GL_DYNAMIC_DRAW); 509 | delete []vertices; 510 | } 511 | 512 | void RenderingWidget::drawAxes() 513 | { 514 | glBindBuffer(GL_ARRAY_BUFFER, axes_vbo); 515 | 516 | int vertexLocation = program.attributeLocation("a_position"); 517 | program.enableAttributeArray(vertexLocation); 518 | glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*6, 0); 519 | 520 | int normalLocation = program.attributeLocation("a_normal"); 521 | program.enableAttributeArray(normalLocation); 522 | glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*6, (const void *)(sizeof(GLfloat)*3)); 523 | 524 | program.setUniformValue("color", RED); 525 | 526 | glDrawArrays(GL_LINES, 0, 4); 527 | program.setUniformValue("color", GREEN); 528 | glDrawArrays(GL_LINES, 4, 4); 529 | program.setUniformValue("color", BLUE); 530 | glDrawArrays(GL_LINES, 8, 4); 531 | } 532 | 533 | void RenderingWidget::drawSmallAxes() 534 | { 535 | glBindBuffer(GL_ARRAY_BUFFER, axes_vbo); 536 | int vertexLocation = program.attributeLocation("a_position"); 537 | program.enableAttributeArray(vertexLocation); 538 | glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*6, 0); 539 | 540 | int normalLocation = program.attributeLocation("a_normal"); 541 | program.enableAttributeArray(normalLocation); 542 | glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*6, (const void *)(sizeof(GLfloat)*3)); 543 | 544 | program.setUniformValue("color", RED); 545 | glDrawArrays(GL_LINES, 12, 2); 546 | program.setUniformValue("color", GREEN); 547 | glDrawArrays(GL_LINES, 14, 2); 548 | program.setUniformValue("color", BLUE); 549 | glDrawArrays(GL_LINES, 16, 2); 550 | } 551 | 552 | void RenderingWidget::drawGrid() 553 | { 554 | glBindBuffer(GL_ARRAY_BUFFER, grid_vbo); 555 | int vertexLocation = program.attributeLocation("a_position"); 556 | program.enableAttributeArray(vertexLocation); 557 | glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*2, 0); 558 | 559 | QColor gridCol; 560 | if(background_col == Qt::white) gridCol = Qt::gray; 561 | else gridCol = Qt::white; 562 | program.setUniformValue("color", QVector3D(gridCol.redF(),gridCol.greenF(),gridCol.blueF())); 563 | glDrawArrays(GL_LINES, 0, (GRID_SIZE)*8 +4); 564 | } 565 | 566 | void RenderingWidget::reDraw() 567 | { 568 | update(); 569 | } 570 | 571 | void RenderingWidget::reCalculatePosition() 572 | { 573 | float val = controller->getMaxDiameter(); 574 | xPos = 1.0f; 575 | yPos = 0.5f; 576 | zPos = 1.0f; 577 | angleX = 0.0f; 578 | angleY = 70.0f; 579 | if(val > 0.0) zoom = qMin(float(2.5*val),MAX_ZOOM); 580 | else zoom = 100; 581 | if (val>minDiam) minDiam = val; 582 | recalculateProjectionNear(); 583 | recalculateGridStep(); 584 | reDraw(); 585 | } 586 | 587 | void RenderingWidget::centerPosition() 588 | { 589 | xTrans = yTrans = 0; 590 | reDraw(); 591 | } 592 | 593 | -------------------------------------------------------------------------------- /window.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 David Vyvlečka, AGPLv3 2 | 3 | #include "window.h" 4 | #include "ui_window.h" 5 | #include "renderingwidget.h" 6 | 7 | Window::Window(QWidget *parent) : 8 | QWidget(parent), 9 | ui(new Ui::Window) 10 | { 11 | this->setAcceptDrops(true); 12 | ui->setupUi(this); 13 | 14 | ui->showButton->hide(); 15 | ui->showButtonLeft->hide(); 16 | ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers); 17 | 18 | controller = new admeshController(this); 19 | controller->addUIItems(ui->statusBar, ui->listView); 20 | ui->renderingWidget->setController(controller); 21 | ui->buttonWidget->setEnabled(false); 22 | connect(controller, SIGNAL(reDrawSignal()), ui->renderingWidget, SLOT(reDraw())); 23 | connect(controller, SIGNAL(reCalculatePosition()), ui->renderingWidget, SLOT(reCalculatePosition())); 24 | connect(controller, SIGNAL(enableEdit(bool)), ui->buttonWidget,SLOT(setEnabled(bool))); 25 | connect(controller, SIGNAL(scaleSignal(double)), ui->versorXBox,SLOT(setValue(double))); 26 | connect(controller, SIGNAL(scaleSignal(double)), ui->versorYBox,SLOT(setValue(double))); 27 | connect(controller, SIGNAL(scaleSignal(double)), ui->versorZBox,SLOT(setValue(double))); 28 | connect(controller, SIGNAL(allowUndo(bool)), this, SLOT(allowUndo(bool))); 29 | connect(controller, SIGNAL(allowRedo(bool)), this, SLOT(allowRedo(bool))); 30 | connect(controller, SIGNAL(allowSave(bool)), this, SLOT(allowSave(bool))); 31 | connect(controller, SIGNAL(allowSaveAs(bool)), this, SLOT(allowSaveAs(bool))); 32 | connect(controller, SIGNAL(allowExport(bool)), this, SLOT(allowExport(bool))); 33 | connect(controller, SIGNAL(allowClose(bool)), this, SLOT(allowClose(bool))); 34 | addActions(); 35 | addMenus(); 36 | addToolbars(); 37 | 38 | connect(ui->versorXBox, SIGNAL(valueChanged(double)), controller, SLOT(setVersorX(double))); 39 | connect(ui->versorYBox, SIGNAL(valueChanged(double)), controller, SLOT(setVersorY(double))); 40 | connect(ui->versorZBox, SIGNAL(valueChanged(double)), controller, SLOT(setVersorZ(double))); 41 | connect(ui->fixedRatioBox, SIGNAL(stateChanged(int)), controller, SLOT(setVersor())); 42 | connect(ui->scaleButton, SIGNAL(clicked()), controller, SLOT(scale())); 43 | connect(ui->mirrorxyButton, SIGNAL(clicked()), controller, SLOT(mirrorXY())); 44 | connect(ui->mirroryzButton, SIGNAL(clicked()), controller, SLOT(mirrorYZ())); 45 | connect(ui->mirrorxzButton, SIGNAL(clicked()), controller, SLOT(mirrorXZ())); 46 | connect(ui->RotateBox, SIGNAL(valueChanged(double)), controller, SLOT(setRot(double))); 47 | connect(ui->rotateXButton, SIGNAL(clicked()), controller, SLOT(rotateX())); 48 | connect(ui->rotateYButton, SIGNAL(clicked()), controller, SLOT(rotateY())); 49 | connect(ui->rotateZButton, SIGNAL(clicked()), controller, SLOT(rotateZ())); 50 | connect(ui->translateXBox, SIGNAL(valueChanged(double)), controller, SLOT(setXTranslate(double))); 51 | connect(ui->translateYBox, SIGNAL(valueChanged(double)), controller, SLOT(setYTranslate(double))); 52 | connect(ui->translateZBox, SIGNAL(valueChanged(double)), controller, SLOT(setZTranslate(double))); 53 | connect(ui->translateRelBox, SIGNAL(stateChanged(int)), controller, SLOT(setRelativeTranslate())); 54 | connect(ui->translateButton, SIGNAL(clicked()), controller, SLOT(translate())); 55 | connect(ui->centerButton, SIGNAL(clicked()), controller, SLOT(center())); 56 | connect(ui->snapZButton, SIGNAL(clicked()), controller, SLOT(snapZ())); 57 | connect(ui->mergeButton, SIGNAL(clicked()), controller, SLOT(merge())); 58 | connect(ui->splitButton, SIGNAL(clicked()), controller, SLOT(split())); 59 | connect(ui->duplicateButton, SIGNAL(clicked()), controller, SLOT(duplicate())); 60 | 61 | connect(ui->hideItemsButton, SIGNAL(clicked()), controller, SLOT(hide())); 62 | connect(ui->unhideItemsButton, SIGNAL(clicked()), controller, SLOT(unhide())); 63 | 64 | connect(ui->exactBox, SIGNAL(stateChanged(int)), controller, SLOT(setExactFlag())); 65 | connect(ui->toleranceBox, SIGNAL(stateChanged(int)), controller, SLOT(setToleranceFlag())); 66 | connect(ui->toleranceSpinBox, SIGNAL(valueChanged(double)), controller, SLOT(setTolerance(double))); 67 | connect(ui->incrementBox, SIGNAL(stateChanged(int)), controller, SLOT(setIncrementFlag())); 68 | connect(ui->incrementSpinBox, SIGNAL(valueChanged(double)), controller, SLOT(setIncrement(double))); 69 | connect(ui->nearbyBox, SIGNAL(stateChanged(int)), controller, SLOT(setNearbyFlag())); 70 | connect(ui->iterationsSpinBox, SIGNAL(valueChanged(int)), controller, SLOT(setIterations(int))); 71 | connect(ui->unconnectedBox, SIGNAL(stateChanged(int)), controller, SLOT(setRemoveUnconnectedFlag())); 72 | connect(ui->fillholesBox, SIGNAL(stateChanged(int)), controller, SLOT(setFillHolesFlag())); 73 | connect(ui->normalDirBox, SIGNAL(stateChanged(int)), controller, SLOT(setNormalDirFlag())); 74 | connect(ui->normalValBox, SIGNAL(stateChanged(int)), controller, SLOT(setNormalValFlag())); 75 | connect(ui->reverseButton, SIGNAL(clicked()), controller, SLOT(reverseAll())); 76 | connect(ui->fixAllBox, SIGNAL(stateChanged(int)), controller, SLOT(setFixAllFlag())); 77 | connect(ui->repairButton, SIGNAL(clicked()), controller, SLOT(repair())); 78 | 79 | readSettings(); 80 | } 81 | 82 | Window::~Window() 83 | { 84 | delete fileMenu; 85 | delete editMenu; 86 | delete viewMenu; 87 | delete ui; 88 | delete controller; 89 | } 90 | 91 | void Window::addActions(){ 92 | openAct = new QAction(_("&Open..."), this); 93 | openAct->setShortcuts(QKeySequence::Open); 94 | openAct->setStatusTip(_("Open STL file")); 95 | connect(openAct, SIGNAL(triggered()), controller, SLOT(openSTL())); 96 | 97 | saveAct = new QAction(_("&Save"), this); 98 | saveAct->setShortcuts(QKeySequence::Save); 99 | saveAct->setEnabled(false); 100 | saveAct->setStatusTip(_("Save in default STL format")); 101 | connect(saveAct, SIGNAL(triggered()), controller, SLOT(save())); 102 | 103 | saveAsAct = new QAction(_("Save &as..."), this); 104 | saveAsAct->setShortcuts(QKeySequence::SaveAs); 105 | saveAsAct->setEnabled(false); 106 | saveAsAct->setStatusTip(_("Save as ASCII or binary STL file")); 107 | connect(saveAsAct, SIGNAL(triggered()), controller, SLOT(saveAs())); 108 | 109 | exportAct = new QAction(_("&Export..."), this); 110 | exportAct->setShortcut(EXPORT_SHORTCUT); 111 | exportAct->setEnabled(false); 112 | exportAct->setStatusTip(_("Export as OBJ, OFF, DXF or VRML")); 113 | connect(exportAct, SIGNAL(triggered()), controller, SLOT(exportSTL())); 114 | 115 | closeAct = new QAction(_("&Close"), this); 116 | closeAct->setShortcut(CLOSE_SHORTCUT); 117 | closeAct->setEnabled(false); 118 | closeAct->setStatusTip(_("Close selected files")); 119 | connect(closeAct, SIGNAL(triggered()), controller, SLOT(closeSTL())); 120 | 121 | quitAct = new QAction(_("&Quit"), this); 122 | quitAct->setShortcuts(QKeySequence::Quit); 123 | quitAct->setStatusTip(_("Quit application")); 124 | connect(quitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); 125 | 126 | axesAct = new QAction(_("&Axes"), this); 127 | axesAct->setStatusTip(_("Show or hide axes")); 128 | axesAct->setCheckable(true); 129 | axesAct->setChecked(true); 130 | axesAct->setShortcut(AXES_SHORTCUT); 131 | connect(axesAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(toggleAxes())); 132 | 133 | gridAct = new QAction(_("&Grid"), this); 134 | gridAct->setStatusTip(_("Show or hide grid")); 135 | gridAct->setCheckable(true); 136 | gridAct->setChecked(false); 137 | gridAct->setShortcut(GRID_SHORTCUT); 138 | connect(gridAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(toggleGrid())); 139 | 140 | solidAct = new QAction(_("&Solid Mode"), this); 141 | solidAct->setStatusTip(_("Show solid mesh")); 142 | solidAct->setCheckable(true); 143 | solidAct->setChecked(true); 144 | solidAct->setShortcut(SOLID_SHORTCUT); 145 | connect(solidAct, SIGNAL(triggered()), this, SLOT(setSolid())); 146 | 147 | wireframeAct = new QAction(_("&Wireframe Mode"), this); 148 | wireframeAct->setStatusTip(_("Show wireframe mesh")); 149 | wireframeAct->setCheckable(true); 150 | wireframeAct->setChecked(false); 151 | wireframeAct->setShortcut(WIREFRAME_SHORTCUT); 152 | connect(wireframeAct, SIGNAL(triggered()), this, SLOT(setWireframe())); 153 | 154 | solidwithedgesAct = new QAction(_("Solid with &edged Mode"), this); 155 | solidwithedgesAct->setStatusTip(_("Show solid mesh with edges")); 156 | solidwithedgesAct->setCheckable(true); 157 | solidwithedgesAct->setChecked(false); 158 | solidwithedgesAct->setShortcut(EDGES_SHORTCUT); 159 | connect(solidwithedgesAct, SIGNAL(triggered()), this, SLOT(setSolidWithEdges())); 160 | 161 | infoAct = new QAction(_("&Info"), this); 162 | infoAct->setStatusTip(_("Show or hide info")); 163 | infoAct->setCheckable(true); 164 | infoAct->setChecked(true); 165 | infoAct->setShortcut(INFO_SHORTCUT); 166 | connect(infoAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(toggleInfo())); 167 | 168 | frontAct = new QAction(_("&Front view"), this); 169 | frontAct->setStatusTip(_("Set front view")); 170 | frontAct->setShortcut(FRONT_SHORTCUT); 171 | connect(frontAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(setFrontView())); 172 | 173 | backAct = new QAction(_("&Back view"), this); 174 | backAct->setStatusTip(_("Set back view")); 175 | backAct->setShortcut(BACK_SHORTCUT); 176 | connect(backAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(setBackView())); 177 | 178 | leftAct = new QAction(_("&Left view"), this); 179 | leftAct->setStatusTip(_("Set left view")); 180 | leftAct->setShortcut(LEFT_SHORTCUT); 181 | connect(leftAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(setLeftView())); 182 | 183 | rightAct = new QAction(_("&Right view"), this); 184 | rightAct->setStatusTip(_("Set right view")); 185 | rightAct->setShortcut(RIGHT_SHORTCUT); 186 | connect(rightAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(setRightView())); 187 | 188 | topAct = new QAction(_("&Top view"), this); 189 | topAct->setStatusTip(_("Set top view")); 190 | topAct->setShortcut(TOP_SHORTCUT); 191 | connect(topAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(setTopView())); 192 | 193 | bottomAct = new QAction(_("B&ottom view"), this); 194 | bottomAct->setStatusTip(_("Set bottom view")); 195 | bottomAct->setShortcut(BOTTOM_SHORTCUT); 196 | connect(bottomAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(setBottomView())); 197 | 198 | centerAct = new QAction(_("To ¢er"), this); 199 | centerAct->setStatusTip(_("Reset camera translation to zero")); 200 | centerAct->setShortcut(RESET_SHORTCUT); 201 | connect(centerAct, SIGNAL(triggered()), ui->renderingWidget, SLOT(centerPosition())); 202 | 203 | selectAllAct = new QAction(_("Select &all"), this); 204 | selectAllAct->setStatusTip(_("Make all objects in scene active")); 205 | selectAllAct->setShortcut(QKeySequence::SelectAll); 206 | connect(selectAllAct, SIGNAL(triggered()), controller, SLOT(setAllActive())); 207 | 208 | selectInverseAct = new QAction(_("Select &inverse"), this); 209 | selectInverseAct->setStatusTip(_("Active objects are set inactive and vice versa")); 210 | selectInverseAct->setShortcut(QKeySequence::Italic); 211 | connect(selectInverseAct, SIGNAL(triggered()), controller, SLOT(setAllInverseActive())); 212 | 213 | undoAct = new QAction(_("&Undo"), this); 214 | undoAct->setShortcuts(QKeySequence::Undo); 215 | undoAct->setStatusTip(_("Undo last action")); 216 | undoAct->setEnabled(false); 217 | connect(undoAct, SIGNAL(triggered()), controller, SLOT(undo())); 218 | 219 | redoAct = new QAction(_("&Redo"), this); 220 | redoAct->setShortcuts(QKeySequence::Redo); 221 | redoAct->setStatusTip(_("Redo last action")); 222 | redoAct->setEnabled(false); 223 | connect(redoAct, SIGNAL(triggered()), controller, SLOT(redo())); 224 | 225 | propertiesAct = new QAction(_("&Preferences..."), this); 226 | propertiesAct->setShortcut(PROPERTIES_SHORTCUT); 227 | propertiesAct->setStatusTip(_("Preferences dialog")); 228 | connect(propertiesAct, SIGNAL(triggered()), this, SLOT(initProperties())); 229 | } 230 | 231 | void Window::addMenus(){ 232 | QMenuBar *menu_bar = new QMenuBar(0); 233 | menu_bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 234 | menu_bar->setNativeMenuBar (true); 235 | ui->menuLayout->addWidget(menu_bar); 236 | menu_bar->setContentsMargins(0,0,0,0); 237 | fileMenu = new QMenu(_("&File")); 238 | fileMenu->addAction(openAct); 239 | fileMenu->addAction(saveAct); 240 | fileMenu->addAction(saveAsAct); 241 | fileMenu->addAction(exportAct); 242 | fileMenu->addSeparator(); 243 | fileMenu->addAction(closeAct); 244 | fileMenu->addAction(quitAct); 245 | menu_bar->addAction(fileMenu->menuAction()); 246 | editMenu = new QMenu(_("&Edit")); 247 | editMenu->addAction(undoAct); 248 | editMenu->addAction(redoAct); 249 | editMenu->addSeparator(); 250 | editMenu->addAction(selectAllAct); 251 | editMenu->addAction(selectInverseAct); 252 | #ifndef Q_OS_MAC 253 | editMenu->addSeparator(); 254 | #endif 255 | editMenu->addAction(propertiesAct); 256 | menu_bar->addAction(editMenu->menuAction()); 257 | viewMenu = new QMenu(_("&View")); 258 | viewMenu->addAction(infoAct); 259 | viewMenu->addAction(axesAct); 260 | viewMenu->addAction(gridAct); 261 | viewMenu->addSeparator(); 262 | viewMenu->addAction(solidAct); 263 | viewMenu->addAction(wireframeAct); 264 | viewMenu->addAction(solidwithedgesAct); 265 | viewMenu->addSeparator(); 266 | viewMenu->addAction(centerAct); 267 | viewMenu->addSeparator(); 268 | viewMenu->addAction(frontAct); 269 | viewMenu->addAction(backAct); 270 | viewMenu->addAction(leftAct); 271 | viewMenu->addAction(rightAct); 272 | viewMenu->addAction(topAct); 273 | viewMenu->addAction(bottomAct); 274 | menu_bar->addAction(viewMenu->menuAction()); 275 | menu_bar->show(); 276 | } 277 | 278 | void Window::addToolbars() 279 | { 280 | QToolBar *toolBar = new QToolBar(0); 281 | toolBar->show(); 282 | toolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 283 | ui->toolBarLayout->addWidget(toolBar); 284 | 285 | openButton = new QToolButton(); 286 | openButton->setDefaultAction(openAct); 287 | openButton->setIcon(QIcon::fromTheme("list-add", QIcon("://Resources/open.svg"))); 288 | openButton->setFixedSize(33, 30); 289 | toolBar->addWidget(openButton); 290 | 291 | saveButton = new QToolButton(); 292 | saveButton->setDefaultAction(saveAct); 293 | saveButton->setIcon(QIcon::fromTheme("document-save", QIcon("://Resources/save.svg"))); 294 | saveButton->setFixedSize(33, 30); 295 | toolBar->addWidget(saveButton); 296 | 297 | undoButton = new QToolButton(); 298 | undoButton->setDefaultAction(undoAct); 299 | undoButton->setIcon(QIcon::fromTheme("edit-undo", QIcon("://Resources/undo.svg"))); 300 | undoButton->setFixedSize(33, 30); 301 | toolBar->addWidget(undoButton); 302 | 303 | redoButton = new QToolButton(); 304 | redoButton->setDefaultAction(redoAct); 305 | redoButton->setIcon(QIcon::fromTheme("edit-redo", QIcon("://Resources/redo.svg"))); 306 | redoButton->setFixedSize(33, 30); 307 | toolBar->addWidget(redoButton); 308 | 309 | closeButton = new QToolButton(); 310 | closeButton->setDefaultAction(closeAct); 311 | closeButton->setIcon(QIcon::fromTheme("window-close", QIcon("://Resources/close.svg"))); 312 | closeButton->setFixedSize(33, 30); 313 | toolBar->addWidget(closeButton); 314 | } 315 | 316 | void Window::initProperties() 317 | { 318 | PropertiesDialog prop(this); 319 | prop.setController(controller); 320 | prop.show(); 321 | prop.exec(); 322 | ui->renderingWidget->reDraw(); 323 | } 324 | 325 | void Window::openByFilename(const char* filename){ 326 | controller->openSTLbyName(filename); 327 | } 328 | 329 | void Window::toggleColorScheme() 330 | { 331 | scheme = !scheme; 332 | setColorScheme(); 333 | } 334 | 335 | void Window::setColorScheme() 336 | { 337 | if(scheme == 0){ // light scheme 338 | ui->renderingWidget->setBackground(Qt::white); 339 | ui->renderingWidget->setTextCol(Qt::black); 340 | ui->showButton->setStyleSheet("color: grey;" 341 | "background-color: white;" 342 | "border-left: 1px solid rgb(239, 239, 239);" 343 | "border-right: 1px solid grey;"); 344 | ui->showButtonLeft->setStyleSheet("color: grey;" 345 | "background-color: white;" 346 | "border-right: 1px solid rgb(239, 239, 239);" 347 | "border-left: 1px solid grey;"); 348 | ui->hideButton->setStyleSheet("color: grey;" 349 | "background-color: white;" 350 | "border-left: 1px solid rgb(239, 239, 239);" 351 | "border-right: 1px solid grey;"); 352 | ui->hideButtonLeft->setStyleSheet("color: grey;" 353 | "background-color: white;" 354 | "border-right: 1px solid rgb(239, 239, 239);" 355 | "border-left: 1px solid grey;"); 356 | }else if(scheme == 1){ // dark scheme 357 | ui->renderingWidget->setBackground(QColor(53, 50, 47)); 358 | ui->renderingWidget->setTextCol(Qt::white); 359 | ui->showButton->setStyleSheet("color: white;" 360 | "background-color: rgb(53, 50, 47);" 361 | "border-left: 1px solid rgb(174, 173, 172);" 362 | "border-right: 1px solid grey;"); 363 | ui->showButtonLeft->setStyleSheet("color: white;" 364 | "background-color: rgb(53, 50, 47);" 365 | "border-right: 1px solid rgb(174, 173, 172);" 366 | "border-left: 1px solid grey;"); 367 | ui->hideButton->setStyleSheet("color: white;" 368 | "background-color: rgb(53, 50, 47);" 369 | "border-left: 1px solid rgb(174, 173, 172);" 370 | "border-right: 1px solid grey;"); 371 | ui->hideButtonLeft->setStyleSheet("color: white;" 372 | "background-color: rgb(53, 50, 47);" 373 | "border-right: 1px solid rgb(174, 173, 172);" 374 | "border-left: 1px solid grey;"); 375 | } 376 | ui->renderingWidget->reDraw(); 377 | } 378 | 379 | void Window::toggleMouseInvert() 380 | { 381 | ui->renderingWidget->invertMouse(); 382 | } 383 | 384 | void Window::allowUndo(bool val) 385 | { 386 | undoAct->setEnabled(val); 387 | undoButton->setIcon(QIcon::fromTheme("edit-undo", QIcon("://Resources/undo.svg"))); 388 | } 389 | 390 | void Window::allowRedo(bool val) 391 | { 392 | redoAct->setEnabled(val); 393 | redoButton->setIcon(QIcon::fromTheme("edit-redo", QIcon("://Resources/redo.svg"))); 394 | } 395 | 396 | void Window::allowSave(bool val) 397 | { 398 | saveAct->setEnabled(val); 399 | saveButton->setIcon(QIcon::fromTheme("document-save", QIcon("://Resources/save.svg"))); 400 | } 401 | 402 | void Window::allowSaveAs(bool val){ 403 | saveAsAct->setEnabled(val); 404 | } 405 | 406 | void Window::allowExport(bool val) 407 | { 408 | exportAct->setEnabled(val); 409 | } 410 | 411 | void Window::allowClose(bool val) 412 | { 413 | closeAct->setEnabled(val); 414 | closeButton->setIcon(QIcon::fromTheme("window-close", QIcon("://Resources/close.svg"))); 415 | } 416 | 417 | void Window::keyPressEvent(QKeyEvent *e) 418 | { 419 | if (e->key() == Qt::Key_Escape) 420 | close(); 421 | else if(e->key() == AXES_SHORTCUT){ 422 | ui->renderingWidget->toggleAxes(); 423 | axesAct->toggle(); 424 | } else if(e->key() == Qt::Key_Shift){ 425 | ui->renderingWidget->toggleShift(); 426 | }else { 427 | QWidget::keyPressEvent(e); 428 | } 429 | } 430 | 431 | 432 | void Window::keyReleaseEvent(QKeyEvent *event) 433 | { 434 | if (event->key() == Qt::Key_Shift){ 435 | ui->renderingWidget->toggleShift(); 436 | } else { 437 | QWidget::keyReleaseEvent(event); 438 | } 439 | } 440 | 441 | void Window::closeEvent(QCloseEvent *event) 442 | { 443 | if(controller->saveOnClose()){ 444 | writeSettings(); 445 | event->accept(); 446 | }else{ 447 | event->ignore(); 448 | } 449 | } 450 | 451 | void Window::dragEnterEvent(QDragEnterEvent *event) 452 | { 453 | event->accept(); 454 | } 455 | 456 | void Window::dropEvent(QDropEvent *event) 457 | { 458 | foreach(QUrl url, event->mimeData()->urls()){ 459 | QFileInfo fi = QFileInfo(url.toString()); 460 | QString fileName = fi.absoluteFilePath(); 461 | fileName = fileName.section("file:",-1); 462 | controller->openSTLbyName(fileName.toStdString().c_str()); 463 | } 464 | event->accept(); 465 | } 466 | 467 | void Window::setSolid() 468 | { 469 | controller->setMode(0); 470 | solidAct->setChecked(true); 471 | wireframeAct->setChecked(false); 472 | solidwithedgesAct->setChecked(false); 473 | ui->renderingWidget->reDraw(); 474 | } 475 | 476 | void Window::setWireframe() 477 | { 478 | controller->setMode(1); 479 | solidAct->setChecked(false); 480 | wireframeAct->setChecked(true); 481 | solidwithedgesAct->setChecked(false); 482 | ui->renderingWidget->reDraw(); 483 | } 484 | 485 | void Window::setSolidWithEdges() 486 | { 487 | controller->setMode(2); 488 | solidAct->setChecked(false); 489 | wireframeAct->setChecked(false); 490 | solidwithedgesAct->setChecked(true); 491 | ui->renderingWidget->reDraw(); 492 | } 493 | 494 | void Window::writeSettings() 495 | { 496 | QSettings settings; 497 | if(this->isMaximized())settings.setValue("maximized",true); 498 | else settings.setValue("maximized",false); 499 | settings.setValue("width", ui->renderingWidget->width()); 500 | settings.setValue("height", ui->renderingWidget->height()); 501 | settings.setValue("mode", 2); 502 | settings.setValue("colorScheme", scheme); 503 | if(ui->showButtonLeft->isVisible()){ 504 | settings.setValue("leftMenu", false); 505 | }else{ 506 | settings.setValue("leftMenu", true); 507 | } 508 | if(ui->showButton->isVisible()){ 509 | settings.setValue("rightMenu", false); 510 | }else{ 511 | settings.setValue("rightMenu", true); 512 | } 513 | controller->writeSettings(); 514 | ui->renderingWidget->writeSettings(); 515 | } 516 | 517 | void Window::readSettings() 518 | { 519 | QSettings settings; 520 | if(settings.value("maximized",false).toBool())this->showMaximized(); 521 | scheme = settings.value("colorScheme",0).toInt(); 522 | setColorScheme(); 523 | int mode = settings.value("rendermode",0).toInt(); 524 | switch(mode){ 525 | case 0: 526 | setSolid(); 527 | break; 528 | case 1: 529 | setWireframe(); 530 | break; 531 | case 2: 532 | setSolidWithEdges(); 533 | break; 534 | } 535 | if(!settings.value("leftMenu", true).toBool()) ui->hideButtonLeft->click(); 536 | if(!settings.value("rightMenu", true).toBool()) ui->hideButton->click(); 537 | if(!settings.value("axes", true).toBool()) axesAct->trigger(); 538 | if(settings.value("grid", true).toBool()) gridAct->trigger(); 539 | if(!settings.value("info", true).toBool()) infoAct->trigger(); 540 | if(settings.value("invertMouse", false).toBool()) ui->renderingWidget->invertMouse(); 541 | ui->renderingWidget->reDraw(); 542 | } 543 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------