diff options
author | donbright <hugh.m.bright@gmail.com> | 2013-05-27 05:28:56 (GMT) |
---|---|---|
committer | donbright <hugh.m.bright@gmail.com> | 2013-05-27 05:28:56 (GMT) |
commit | ef7b80656fc39dc0fd4012231633cf858e6aa10b (patch) | |
tree | 17e5a57dfa154821918094cab47476189771ce00 /src | |
parent | 0967a26bff45951d7b86fe628e8b1156e6e40ede (diff) | |
parent | 37dc9342a14206f5862447eb9d3d5049ec67f638 (diff) |
Merge pull request #368 from openscad/issue125
Issue125
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALEvaluator.cc | 2 | ||||
-rw-r--r-- | src/CSGTermEvaluator.cc | 2 | ||||
-rw-r--r-- | src/CocoaUtils.h | 3 | ||||
-rw-r--r-- | src/CocoaUtils.mm | 5 | ||||
-rw-r--r-- | src/MainWindow.h | 1 | ||||
-rw-r--r-- | src/MainWindow.ui | 6 | ||||
-rw-r--r-- | src/PlatformUtils-mac.mm | 7 | ||||
-rw-r--r-- | src/PlatformUtils-posix.cc | 10 | ||||
-rw-r--r-- | src/PlatformUtils-win.cc | 70 | ||||
-rw-r--r-- | src/PlatformUtils.cc | 40 | ||||
-rw-r--r-- | src/PlatformUtils.h | 14 | ||||
-rw-r--r-- | src/cgaladv.cc | 1 | ||||
-rw-r--r-- | src/control.cc | 2 | ||||
-rw-r--r-- | src/csgops.cc | 1 | ||||
-rw-r--r-- | src/import.cc | 2 | ||||
-rw-r--r-- | src/mainwin.cc | 18 | ||||
-rw-r--r-- | src/parsersettings.cc | 13 | ||||
-rw-r--r-- | src/system-gl.cc | 3 |
18 files changed, 181 insertions, 19 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index d0140fa..686bde1 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -279,7 +279,7 @@ Response CGALEvaluator::visit(State &state, const CsgNode &node) if (state.isPostfix()) { CGAL_Nef_polyhedron N; if (!isCached(node)) { - CGALEvaluator::CsgOp op; + CGALEvaluator::CsgOp op = CGE_UNION; switch (node.type) { case CSG_TYPE_UNION: op = CGE_UNION; diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc index 9fc3147..a6b654c 100644 --- a/src/CSGTermEvaluator.cc +++ b/src/CSGTermEvaluator.cc @@ -126,7 +126,7 @@ Response CSGTermEvaluator::visit(State &state, const AbstractPolyNode &node) Response CSGTermEvaluator::visit(State &state, const CsgNode &node) { if (state.isPostfix()) { - CsgOp op; + CsgOp op = CSGT_UNION; switch (node.type) { case CSG_TYPE_UNION: op = CSGT_UNION; diff --git a/src/CocoaUtils.h b/src/CocoaUtils.h index ad5518b..8543d84 100644 --- a/src/CocoaUtils.h +++ b/src/CocoaUtils.h @@ -1,13 +1,10 @@ #ifndef COCOAUTILS_H_ #define COCOAUTILS_H_ -#include <string> - class CocoaUtils { public: static void endApplication(); - static std::string documentsPath(); }; #endif diff --git a/src/CocoaUtils.mm b/src/CocoaUtils.mm index 295ceb9..b72583c 100644 --- a/src/CocoaUtils.mm +++ b/src/CocoaUtils.mm @@ -1,6 +1,5 @@ #include "CocoaUtils.h" #import <Foundation/Foundation.h> -#include <stdio.h> void CocoaUtils::endApplication() { @@ -9,7 +8,3 @@ void CocoaUtils::endApplication() object:nil]; } -std::string CocoaUtils::documentsPath() -{ - return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); -} diff --git a/src/MainWindow.h b/src/MainWindow.h index 378705e..bd32bdd 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -101,6 +101,7 @@ private slots: void actionSave(); void actionSaveAs(); void actionReload(); + void actionShowLibraryFolder(); private slots: void pasteViewportTranslation(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 8e995cd..e9bd96e 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -137,6 +137,7 @@ <addaction name="fileActionOpen"/> <addaction name="menuOpenRecent"/> <addaction name="menuExamples"/> + <addaction name="fileShowLibraryFolder"/> <addaction name="separator"/> <addaction name="fileActionClose"/> <addaction name="fileActionSave"/> @@ -688,6 +689,11 @@ <string>Check for Update..</string> </property> </action> + <action name="fileShowLibraryFolder"> + <property name="text"> + <string>Show Library Folder...</string> + </property> + </action> </widget> <customwidgets> <customwidget> diff --git a/src/PlatformUtils-mac.mm b/src/PlatformUtils-mac.mm new file mode 100644 index 0000000..1e2ba43 --- /dev/null +++ b/src/PlatformUtils-mac.mm @@ -0,0 +1,7 @@ +#include "PlatformUtils.h" +#import <Foundation/Foundation.h> + +std::string PlatformUtils::documentsPath() +{ + return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); +} diff --git a/src/PlatformUtils-posix.cc b/src/PlatformUtils-posix.cc new file mode 100644 index 0000000..d7b7b6d --- /dev/null +++ b/src/PlatformUtils-posix.cc @@ -0,0 +1,10 @@ +#include "PlatformUtils.h" +#include "boosty.h" + +std::string PlatformUtils::documentsPath() +{ + fs::path docpath(getenv("HOME")); + docpath = docpath / ".local" / "share"; + + return boosty::stringy(docpath); +} diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc new file mode 100644 index 0000000..a58a346 --- /dev/null +++ b/src/PlatformUtils-win.cc @@ -0,0 +1,70 @@ +#include "PlatformUtils.h" +#include "printutils.h" +#include <windows.h> +#ifndef _WIN32_IE +#define _WIN32_IE 0x0501 // SHGFP_TYPE_CURRENT +#endif +#include <shlobj.h> + +// convert from windows api w_char strings (usually utf16) to utf8 std::string +std::string winapi_wstr_to_utf8( std::wstring wstr ) +{ + UINT CodePage = CP_UTF8; + DWORD dwFlags = 0; + LPCWSTR lpWideCharStr = &wstr[0]; + int cchWideChar = (int)wstr.size(); + LPSTR lpMultiByteStr = NULL; + int cbMultiByte = 0; + LPCSTR lpDefaultChar = NULL; + LPBOOL lpUsedDefaultChar = NULL; + + int numbytes = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, + cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); + + //PRINTB("utf16 to utf8 conversion: numbytes %i",numbytes); + + std::string utf8_str(numbytes,0); + lpMultiByteStr = &utf8_str[0]; + cbMultiByte = numbytes; + + int result = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, + cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); + + if (result != numbytes) { + PRINT("ERROR: error converting w_char str to utf8 string"); + PRINTB("ERROR: error code %i",GetLastError()); + } + + return utf8_str; +} + + +// retrieve the path to 'My Documents' for the current user under windows +// In XP this is 'c:\documents and settings\username\my documents' +// In Vista, 7, 8+ this is 'c:\users\username\documents' +// This code may have problems with unusual dir types in Vista because +// Mingw does not provide access to the updated SHGetKnownFolderPath +std::string PlatformUtils::documentsPath() +{ + std::string retval; + std::wstring path(MAX_PATH,0); + + HWND hwndOwner = 0; + int nFolder = CSIDL_PERSONAL; + HANDLE hToken = NULL; + DWORD dwFlags = SHGFP_TYPE_CURRENT; + LPTSTR pszPath = &path[0]; + + int result = SHGetFolderPathW( hwndOwner, nFolder, hToken, dwFlags, pszPath ); + + if (result == S_OK) { + path = std::wstring( path.c_str() ); // stip extra NULLs + //std::wcerr << "wchar path:" << "\n"; + retval = winapi_wstr_to_utf8( path ); + //PRINTB("Path found: %s",retval); + } else { + PRINT("ERROR: Could not find My Documents location"); + retval = ""; + } + return retval; +} diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc new file mode 100644 index 0000000..5dd007d --- /dev/null +++ b/src/PlatformUtils.cc @@ -0,0 +1,40 @@ +#include "PlatformUtils.h" +#include "boosty.h" + +bool PlatformUtils::createLibraryPath() +{ + std::string path = PlatformUtils::libraryPath(); + bool OK = false; + try { + if (!fs::exists(fs::path(path))) { + //PRINTB("Creating library folder %s", path ); + OK = fs::create_directories( path ); + } + if (!OK) { + PRINTB("ERROR: Cannot create %s", path ); + } + } catch (const fs::filesystem_error& ex) { + PRINTB("ERROR: %s",ex.what()); + } + return OK; +} + +std::string PlatformUtils::libraryPath() +{ + fs::path path; + try { + std::string pathstr = PlatformUtils::documentsPath(); + if (pathstr=="") return ""; + path = boosty::canonical(fs::path( pathstr )); + //PRINTB("path size %i",boosty::stringy(path).size()); + //PRINTB("lib path found: [%s]", path ); + if (path.empty()) return ""; + path /= "OpenSCAD"; + path /= "libraries"; + //PRINTB("Appended path %s", path ); + //PRINTB("Exists: %i", fs::exists(path) ); + } catch (const fs::filesystem_error& ex) { + PRINTB("ERROR: %s",ex.what()); + } + return boosty::stringy( path ); +} diff --git a/src/PlatformUtils.h b/src/PlatformUtils.h new file mode 100644 index 0000000..089b3ca --- /dev/null +++ b/src/PlatformUtils.h @@ -0,0 +1,14 @@ +#ifndef PLATFORMUTILS_H_ +#define PLATFORMUTILS_H_ + +#include <string> + +namespace PlatformUtils { + + std::string documentsPath(); + std::string libraryPath(); + bool createLibraryPath(); + +} + +#endif diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 70590f7..ee3d657 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -142,6 +142,7 @@ std::string CgaladvNode::name() const default: assert(false); } + return "internal_error"; } std::string CgaladvNode::toString() const diff --git a/src/control.cc b/src/control.cc index 7786e36..c5ad09b 100644 --- a/src/control.cc +++ b/src/control.cc @@ -114,7 +114,7 @@ AbstractNode *ControlModule::instantiate(const Context *ctx, const ModuleInstant // assert(filectx->evalctx); if (filectx->evalctx) { - if (n < filectx->evalctx->numChildren()) { + if (n < (int)filectx->evalctx->numChildren()) { node = filectx->evalctx->getChild(n)->evaluate(filectx->evalctx); } else { diff --git a/src/csgops.cc b/src/csgops.cc index 92b97e7..8ac1d4f 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -69,6 +69,7 @@ std::string CsgNode::name() const default: assert(false); } + return "internal_error"; } void register_builtin_csgops() diff --git a/src/import.cc b/src/import.cc index 2180684..b5d67d2 100644 --- a/src/import.cc +++ b/src/import.cc @@ -204,7 +204,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const boost::regex ex_vertices("\\s*vertex\\s+([^\\s]+)\\s+([^\\s]+)\\s+([^\\s]+)"); bool binary = false; - int file_size = f.tellg(); + std::streampos file_size = f.tellg(); f.seekg(80); if (!f.eof()) { uint32_t facenum = 0; diff --git a/src/mainwin.cc b/src/mainwin.cc index 8151e29..08f0435 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -53,6 +53,7 @@ #ifdef Q_OS_MAC #include "CocoaUtils.h" #endif +#include "PlatformUtils.h" #include <QMenu> #include <QTime> @@ -104,6 +105,8 @@ #define OPENCSG_VERSION_STRING "unknown, <1.3.2" #endif +#include "boosty.h" + extern QString examplesdir; // Global application state @@ -227,6 +230,7 @@ MainWindow::MainWindow(const QString &filename) connect(this->fileActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs())); connect(this->fileActionReload, SIGNAL(triggered()), this, SLOT(actionReload())); connect(this->fileActionQuit, SIGNAL(triggered()), this, SLOT(quit())); + connect(this->fileShowLibraryFolder, SIGNAL(triggered()), this, SLOT(actionShowLibraryFolder())); #ifndef __APPLE__ QList<QKeySequence> shortcuts = this->fileActionSave->shortcuts(); shortcuts.push_back(QKeySequence(Qt::Key_F2)); @@ -951,6 +955,20 @@ void MainWindow::actionSaveAs() } } +void MainWindow::actionShowLibraryFolder() +{ + std::string path = PlatformUtils::libraryPath(); + if (!fs::exists(path)) { + PRINTB("WARNING: Library path %s doesnt exist. Creating", path); + if (!PlatformUtils::createLibraryPath()) { + PRINTB("ERROR: Cannot create library path: %s",path); + } + } + QString url = QString::fromStdString( path ); + //PRINTB("Opening file browser for %s", url.toStdString() ); + QDesktopServices::openUrl(QUrl::fromLocalFile( url )); +} + void MainWindow::actionReload() { if (checkEditorModified()) refreshDocument(); diff --git a/src/parsersettings.cc b/src/parsersettings.cc index cb7c93d..8db33a8 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -3,9 +3,7 @@ #include <boost/foreach.hpp> #include "boosty.h" #include <boost/algorithm/string.hpp> -#ifdef __APPLE__ -#include "CocoaUtils.h" -#endif +#include "PlatformUtils.h" namespace fs = boost::filesystem; @@ -104,12 +102,15 @@ void parser_init(const std::string &applicationpath) } } - // FIXME: Add ~/.openscad/libraries -#if defined(__APPLE__) && !defined(OPENSCAD_TESTING) - fs::path docdir(CocoaUtils::documentsPath()); + // This is the built-in user-writable library path +#ifndef OPENSCAD_TESTING + // This will resolve to ~/Documents on Mac, "My Documents" on Windows and + // ~/.local/share on Linux + fs::path docdir(PlatformUtils::documentsPath()); add_librarydir(boosty::stringy(docdir / "OpenSCAD" / "libraries")); #endif + // This is the built-in read-only library path std::string librarydir; fs::path libdir(applicationpath); fs::path tmpdir; diff --git a/src/system-gl.cc b/src/system-gl.cc index 0c436e5..098dcb2 100644 --- a/src/system-gl.cc +++ b/src/system-gl.cc @@ -46,7 +46,8 @@ string glew_extensions_dump() sort( extensions.begin(), extensions.end() ); stringstream out; out << "GL Extensions:"; - for ( int i=0;i<extensions.size();i++ ) out << extensions[i] << "\n"; + for ( unsigned int i=0;i<extensions.size();i++ ) + out << extensions[i] << "\n"; return out.str(); } |