From e2772c70b862e3669c3a279f2540d746438ec38d Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 21 May 2013 17:45:24 -0400 Subject: Initial Windows implementation of built-in library path. Part of #125 diff --git a/openscad.pro b/openscad.pro index 542bcc3..c36c37b 100644 --- a/openscad.pro +++ b/openscad.pro @@ -384,7 +384,14 @@ macx { src/EventFilter.h \ src/CocoaUtils.h SOURCES += src/AppleEvents.cc - OBJECTIVE_SOURCES += src/CocoaUtils.mm + OBJECTIVE_SOURCES += src/CocoaUtils.mm \ + src/PlatformUtils.mm +} +unix:!macx { + SOURCES += src/PlatformUtils-posix.cc +} +win32* { + SOURCES += src/PlatformUtils-win32.cc } isEmpty(PREFIX):PREFIX = /usr/local 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 - 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 -#include 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/PlatformUtils-posix.cc b/src/PlatformUtils-posix.cc new file mode 100644 index 0000000..7ed6735 --- /dev/null +++ b/src/PlatformUtils-posix.cc @@ -0,0 +1,7 @@ +#include "PlatformUtils.h" + +std::string PlatformUtils::documentsPath() +{ + // FIXME: Implement + return ""; +} diff --git a/src/PlatformUtils-win32.cc b/src/PlatformUtils-win32.cc new file mode 100644 index 0000000..61382dd --- /dev/null +++ b/src/PlatformUtils-win32.cc @@ -0,0 +1,15 @@ +#include "PlatformUtils.h" +#include +#include + +std::string PlatformUtils::documentsPath() +{ + std::string retval; + CHAR my_documents[MAX_PATH]; + HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, + SHGFP_TYPE_CURRENT, my_documents); + + if (result != S_OK) retval = ""; + else retval = my_documents; + return retval; +} diff --git a/src/PlatformUtils.h b/src/PlatformUtils.h new file mode 100644 index 0000000..6448427 --- /dev/null +++ b/src/PlatformUtils.h @@ -0,0 +1,12 @@ +#ifndef PLATFORMUTILS_H_ +#define PLATFORMUTILS_H_ + +#include + +namespace PlatformUtils { + + std::string documentsPath(); + +} + +#endif diff --git a/src/PlatformUtils.mm b/src/PlatformUtils.mm new file mode 100644 index 0000000..1e2ba43 --- /dev/null +++ b/src/PlatformUtils.mm @@ -0,0 +1,7 @@ +#include "PlatformUtils.h" +#import + +std::string PlatformUtils::documentsPath() +{ + return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); +} diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 8d82744..b2ef1fa 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -3,9 +3,7 @@ #include #include "boosty.h" #include -#ifdef __APPLE__ -#include "CocoaUtils.h" -#endif +#include "PlatformUtils.h" namespace fs = boost::filesystem; @@ -44,9 +42,8 @@ void parser_init(const std::string &applicationpath) } } - // FIXME: Add ~/.openscad/libraries -#if defined(__APPLE__) && !defined(OPENSCAD_TESTING) - fs::path docdir(CocoaUtils::documentsPath()); +#ifndef OPENSCAD_TESTING + fs::path docdir(PlatformUtils::documentsPath()); add_librarydir(boosty::stringy(docdir / "OpenSCAD" / "libraries")); #endif -- cgit v0.10.1 From 13e4bcd50e324d5228ce920d1fc84aa3ba8d6e5e Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 21 May 2013 18:02:16 -0400 Subject: Added meny entry for disclosing the library path. Part of #125 diff --git a/openscad.pro b/openscad.pro index c36c37b..8bd24af 100644 --- a/openscad.pro +++ b/openscad.pro @@ -302,6 +302,7 @@ SOURCES += src/version_check.cc \ src/parsersettings.cc \ src/stl-utils.cc \ src/boost-utils.cc \ + src/PlatformUtils.cc \ \ src/nodedumper.cc \ src/traverser.cc \ @@ -385,7 +386,7 @@ macx { src/CocoaUtils.h SOURCES += src/AppleEvents.cc OBJECTIVE_SOURCES += src/CocoaUtils.mm \ - src/PlatformUtils.mm + src/PlatformUtils-mac.mm } unix:!macx { SOURCES += src/PlatformUtils-posix.cc 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 @@ + @@ -688,6 +689,11 @@ Check for Update.. + + + Show Library Folder... + + 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 + +std::string PlatformUtils::documentsPath() +{ + return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); +} diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc new file mode 100644 index 0000000..cea449b --- /dev/null +++ b/src/PlatformUtils.cc @@ -0,0 +1,7 @@ +#include "PlatformUtils.h" +#include "boosty.h" + +std::string PlatformUtils::libraryPath() +{ + return boosty::stringy(fs::path(PlatformUtils::documentsPath()) / "OpenSCAD" / "libraries"); +} diff --git a/src/PlatformUtils.h b/src/PlatformUtils.h index 6448427..202abaa 100644 --- a/src/PlatformUtils.h +++ b/src/PlatformUtils.h @@ -6,6 +6,7 @@ namespace PlatformUtils { std::string documentsPath(); + std::string libraryPath(); } diff --git a/src/PlatformUtils.mm b/src/PlatformUtils.mm deleted file mode 100644 index 1e2ba43..0000000 --- a/src/PlatformUtils.mm +++ /dev/null @@ -1,7 +0,0 @@ -#include "PlatformUtils.h" -#import - -std::string PlatformUtils::documentsPath() -{ - return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); -} diff --git a/src/mainwin.cc b/src/mainwin.cc index da3501d..9b490c7 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 #include @@ -227,6 +228,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 shortcuts = this->fileActionSave->shortcuts(); shortcuts.push_back(QKeySequence(Qt::Key_F2)); @@ -951,6 +953,11 @@ void MainWindow::actionSaveAs() } } +void MainWindow::actionShowLibraryFolder() +{ + QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(PlatformUtils::libraryPath()))); +} + void MainWindow::actionReload() { if (checkEditorModified()) refreshDocument(); -- cgit v0.10.1 From 41d1c94879f22f569082d4adf44427df2e7ed23b Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 21 May 2013 18:19:29 -0400 Subject: Starting point for Unix implementation of built-in library path. Part of #125 diff --git a/src/PlatformUtils-posix.cc b/src/PlatformUtils-posix.cc index 7ed6735..e581de6 100644 --- a/src/PlatformUtils-posix.cc +++ b/src/PlatformUtils-posix.cc @@ -1,7 +1,10 @@ #include "PlatformUtils.h" +#include "boosty.h" std::string PlatformUtils::documentsPath() { - // FIXME: Implement - return ""; + fs::path docpath(getenv("HOME")); + docpath /= ".local" / "share"; + + return boosty::stringy(docpath); } -- cgit v0.10.1 From 18c4eeebdc1f757fd1140c7620bc3573d47c2592 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Wed, 22 May 2013 00:28:41 +0200 Subject: compile fix diff --git a/src/PlatformUtils-posix.cc b/src/PlatformUtils-posix.cc index e581de6..d7b7b6d 100644 --- a/src/PlatformUtils-posix.cc +++ b/src/PlatformUtils-posix.cc @@ -4,7 +4,7 @@ std::string PlatformUtils::documentsPath() { fs::path docpath(getenv("HOME")); - docpath /= ".local" / "share"; + docpath = docpath / ".local" / "share"; return boosty::stringy(docpath); } -- cgit v0.10.1 From 164902fa76efac9f88bbd9aa6cbd1eb8c3fa00fb Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 21 May 2013 18:58:39 -0400 Subject: code comments diff --git a/src/parsersettings.cc b/src/parsersettings.cc index b2ef1fa..48a6cf8 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -42,11 +42,15 @@ void parser_init(const std::string &applicationpath) } } + // 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; -- cgit v0.10.1 From 31c88a434b3201d88819b485f74da843c2728cb2 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sat, 25 May 2013 22:37:26 -0500 Subject: merge branch to get windows "library path" working. tweak build system, eliminate several compiler warnings. diff --git a/bison.pri b/bison.pri index d2972d6..f28c6e0 100644 --- a/bison.pri +++ b/bison.pri @@ -3,7 +3,7 @@ bison.input = BISONSOURCES bison.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.cpp bison.commands = bison -d -p ${QMAKE_FILE_BASE} -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.cpp ${QMAKE_FILE_IN} - bison.commands += && mv ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.hpp ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.h + bison.commands += && if [ -e ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.hpp ]; then mv ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.hpp ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.h ; fi bison.CONFIG += target_predeps bison.variable_out = GENERATED_SOURCES silent:bison.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands @@ -11,7 +11,7 @@ bison_header.input = BISONSOURCES bison_header.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.h bison_header.commands = bison -d -p ${QMAKE_FILE_BASE} -o ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.cpp ${QMAKE_FILE_IN} - bison_header.commands += && mv ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.hpp ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.h + bison_header.commands += && if [ -e ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.hpp ]; then mv ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.hpp ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}_yacc.h ; fi bison_header.CONFIG += target_predeps no_link silent:bison_header.commands = @echo Bison ${QMAKE_FILE_IN} && $$bison.commands QMAKE_EXTRA_COMPILERS += bison_header diff --git a/openscad.pro b/openscad.pro index 8bd24af..c007330 100644 --- a/openscad.pro +++ b/openscad.pro @@ -31,7 +31,7 @@ isEmpty(QT_VERSION) { include(version.pri) # for debugging link problems (use nmake -f Makefile.Release > log.txt) -win32 { +win* { # QMAKE_LFLAGS += -VERBOSE } debug: DEFINES += DEBUG @@ -88,7 +88,7 @@ else { TARGET = openscad } -win32 { +win* { RC_FILE = openscad_win32.rc } @@ -171,7 +171,7 @@ CONFIG(mingw-cross-env) { include(mingw-cross-env.pri) } -win32 { +win* { FLEXSOURCES = src/lexer.l BISONSOURCES = src/parser.y } else { @@ -348,7 +348,7 @@ macx { SOURCES += src/imageutils-macosx.cc OBJECTIVE_SOURCES += src/OffscreenContextCGL.mm } -win32* { +win* { SOURCES += src/imageutils-lodepng.cc SOURCES += src/OffscreenContextWGL.cc } @@ -391,8 +391,8 @@ macx { unix:!macx { SOURCES += src/PlatformUtils-posix.cc } -win32* { - SOURCES += src/PlatformUtils-win32.cc +win* { + SOURCES += src/PlatformUtils-win.cc } isEmpty(PREFIX):PREFIX = /usr/local diff --git a/scripts/release-common.sh b/scripts/release-common.sh index 7d36907..8a1ed7c 100755 --- a/scripts/release-common.sh +++ b/scripts/release-common.sh @@ -52,13 +52,13 @@ elif [[ $OSTYPE == "linux-gnu" ]]; then fi if [ "`echo $* | grep mingw32`" ]; then - OS=LINXWIN + OS=UNIX_CROSS_WIN ARCH=32 echo Mingw-cross build using ARCH=32 fi if [ "`echo $* | grep mingw64`" ]; then - OS=LINXWIN + OS=UNIX_CROSS_WIN ARCH=64 echo Mingw-cross build using ARCH=64 fi @@ -90,7 +90,7 @@ fi echo "Checking pre-requisites..." case $OS in - LINXWIN) + UNIX_CROSS_WIN) MAKENSIS= if [ "`command -v makensis`" ]; then MAKENSIS=makensis @@ -120,10 +120,9 @@ echo "Building openscad-$VERSION ($VERSIONDATE) $CONFIGURATION..." if [ ! $NUMCPU ]; then echo "note: you can 'export NUMCPU=x' for multi-core compiles (x=number)"; - NUMCPU=2 -else - echo "NUMCPU: " $NUMCPU + NUMCPU=1 fi +echo "NUMCPU: " $NUMCPU CONFIG=deploy case $OS in @@ -138,7 +137,7 @@ case $OS in ZIPARGS="a -tzip" TARGET=release ;; - LINXWIN) + UNIX_CROSS_WIN) . ./scripts/setenv-mingw-xbuild.sh $ARCH TARGET=release ZIP="zip" @@ -148,7 +147,7 @@ esac case $OS in - LINXWIN) + UNIX_CROSS_WIN) cd $DEPLOYDIR && qmake VERSION=$VERSION OPENSCAD_COMMIT=$OPENSCAD_COMMIT CONFIG+=$CONFIG CONFIG+=mingw-cross-env CONFIG-=debug ../openscad.pro cd $OPENSCADDIR ;; @@ -158,7 +157,7 @@ case $OS in esac case $OS in - LINXWIN) + UNIX_CROSS_WIN) cd $DEPLOYDIR make clean ## comment out for test-run cd $OPENSCADDIR @@ -176,10 +175,17 @@ case $OS in #if the following files are missing their tried removal stops the build process on msys touch -t 200012121010 parser_yacc.h parser_yacc.cpp lexer_lex.cpp ;; + UNIX_CROSS_WIN) + # kludge to enable paralell make + touch -t 200012121010 $OPENSCADDIR/src/parser_yacc.h + touch -t 200012121010 $OPENSCADDIR/src/parser_yacc.cpp + touch -t 200012121010 $OPENSCADDIR/src/parser_yacc.hpp + touch -t 200012121010 $OPENSCADDIR/src/lexer_lex.cpp + ;; esac case $OS in - LINXWIN) + UNIX_CROSS_WIN) # make main openscad.exe cd $DEPLOYDIR make $TARGET -j$NUMCPU ## comment 4 test @@ -214,12 +220,12 @@ case $OS in EXAMPLESDIR=OpenSCAD.app/Contents/Resources/examples LIBRARYDIR=OpenSCAD.app/Contents/Resources/libraries ;; - LINXWIN) + UNIX_CROSS_WIN) EXAMPLESDIR=$DEPLOYDIR/openscad-$VERSION/examples/ LIBRARYDIR=$DEPLOYDIR/openscad-$VERSION/libraries/ rm -rf $DEPLOYDIR/openscad-$VERSION mkdir $DEPLOYDIR/openscad-$VERSION - ;; + ;; *) EXAMPLESDIR=openscad-$VERSION/examples/ LIBRARYDIR=openscad-$VERSION/libraries/ @@ -267,7 +273,7 @@ case $OS in rm -rf openscad-$VERSION echo "Binary created: openscad-$VERSION.zip" ;; - LINXWIN) + UNIX_CROSS_WIN) BINFILE=$DEPLOYDIR/OpenSCAD-$VERSION-x86-$ARCH.zip INSTFILE=$DEPLOYDIR/OpenSCAD-$VERSION-x86-$ARCH-Installer.exe diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index d0140fa..2ea7a8d 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -291,6 +291,7 @@ Response CGALEvaluator::visit(State &state, const CsgNode &node) op = CGE_INTERSECTION; break; default: + op = -1; assert(false); } N = applyToChildren(node, op); diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc index cea449b..a7efe40 100644 --- a/src/PlatformUtils.cc +++ b/src/PlatformUtils.cc @@ -3,5 +3,26 @@ std::string PlatformUtils::libraryPath() { - return boosty::stringy(fs::path(PlatformUtils::documentsPath()) / "OpenSCAD" / "libraries"); + fs::path path; + bool OK = true; + try { + path = boosty::canonical(fs::path(PlatformUtils::documentsPath())); + if (path.empty()) return ""; + PRINTB("path size %i",boosty::stringy(path).size()); + path /= "OpenSCAD"; + path /= "libraries"; + PRINTB("Appended path %s", path ); + PRINTB("Exists: %i", fs::exists(path) ); + if (!fs::exists(path)) { + PRINTB("Creating library folder %s", boosty::stringy(path) ); + OK &= fs::create_directories( path ); + } + if (!OK) { + PRINTB("ERROR: Cannot find nor create %s", boosty::stringy(path) ); + path = fs::path(""); + } + } catch (const fs::filesystem_error& ex) { + PRINTB("ERROR: %s",ex.what()); + } + return boosty::stringy( path ); } 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 9b490c7..f370f3d 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -955,7 +955,9 @@ void MainWindow::actionSaveAs() void MainWindow::actionShowLibraryFolder() { - QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(PlatformUtils::libraryPath()))); + QString url = QString::fromStdString(PlatformUtils::libraryPath()); + PRINTB("Opening file browser for %s", url.toStdString() ); + QDesktopServices::openUrl(QUrl::fromLocalFile( url )); } void MainWindow::actionReload() 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 Date: Sun, 26 May 2013 20:24:53 -0500 Subject: windows - library path find, also windows build fixes diff --git a/boost.pri b/boost.pri index f3619a0..2084c89 100644 --- a/boost.pri +++ b/boost.pri @@ -6,7 +6,7 @@ boost { !isEmpty(BOOST_DIR) { QMAKE_INCDIR += $$BOOST_DIR message("boost location: $$BOOST_DIR") - win32: QMAKE_LIBDIR += -L$$BOOST_DIR/lib + win*: QMAKE_LIBDIR += -L$$BOOST_DIR/lib } CONFIG(mingw-cross-env) { @@ -16,7 +16,7 @@ boost { BOOST_LINK_FLAGS = -lboost_thread_win32-mt -lboost_program_options-mt -lboost_filesystem-mt -lboost_system-mt -lboost_regex-mt -lboost_chrono-mt } - isEmpty(BOOST_LINK_FLAGS):win32 { + isEmpty(BOOST_LINK_FLAGS):win* { BOOST_LINK_FLAGS = -llibboost_thread-vc90-mt-s-1_46_1 -llibboost_program_options-vc90-mt-s-1_46_1 -llibboost_filesystem-vc90-mt-s-1_46_1 -llibboost_system-vc90-mt-s-1_46_1 -llibboost_regex-vc90-mt-s-1_46_1 } diff --git a/cgal.pri b/cgal.pri index ae532f0..241332a 100644 --- a/cgal.pri +++ b/cgal.pri @@ -6,7 +6,7 @@ cgal { CGAL_DIR = $$(CGALDIR) !isEmpty(CGAL_DIR) { QMAKE_INCDIR += $$CGAL_DIR/include - win32: QMAKE_INCDIR += $$CGAL_DIR/auxiliary/gmp/include + win*: QMAKE_INCDIR += $$CGAL_DIR/auxiliary/gmp/include QMAKE_LIBDIR += $$CGAL_DIR/lib message("CGAL location: $$CGAL_DIR") } @@ -15,7 +15,7 @@ cgal { LIBS += -lgmp -lmpfr -lCGAL QMAKE_CXXFLAGS += -frounding-math } else { - win32 { + win* { *-g++* { QMAKE_CXXFLAGS += -frounding-math } diff --git a/common.pri b/common.pri index 71aa510..7153ded 100644 --- a/common.pri +++ b/common.pri @@ -3,7 +3,7 @@ MOC_DIR = objects UI_DIR = objects RCC_DIR = objects -include(win32.pri) +include(win.pri) include(flex.pri) include(bison.pri) include(cgal.pri) diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 2ea7a8d..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; @@ -291,7 +291,6 @@ Response CGALEvaluator::visit(State &state, const CsgNode &node) op = CGE_INTERSECTION; break; default: - op = -1; assert(false); } N = applyToChildren(node, op); diff --git a/src/CSGTermEvaluator.cc b/src/CSGTermEvaluator.cc index 4624d4c..6b39c66 100644 --- a/src/CSGTermEvaluator.cc +++ b/src/CSGTermEvaluator.cc @@ -124,7 +124,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/PlatformUtils-win.cc b/src/PlatformUtils-win.cc new file mode 100644 index 0000000..d06df51 --- /dev/null +++ b/src/PlatformUtils-win.cc @@ -0,0 +1,57 @@ +#include "PlatformUtils.h" +#include "printutils.h" +#include +#define _WIN32_IE 0x0501 // SHGFP_TYPE_CURRENT +#include + +// convert from windows api w_char strings (usually utf16) to utf8 std::string +std::string winapi_wstr_to_utf8( std::wstring wstr ) +{ + std::string utf8_str(""); + + UINT CodePage = CP_UTF8; + DWORD dwFlags = 0; + LPCSTR lpMultiByteStr = NULL; + int cbMultiByte = 0; + LPWSTR lpWideCharStr = &wstr[0]; + int cchWideChar = (int)wstr.size(); + + int numbytes = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr, + cbMultiByte, lpWideCharStr, cchWideChar ); + + cbMultiByte = numbytes; + lpMultiByteStr = &utf8_str[0]; + + int result = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr, + cbMultiByte, lpWideCharStr, cchWideChar ); + + if (result != numbytes) { + PRINT("ERROR: error converting w_char str to utf8 string"); + } + + 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); + + HRESULT result = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, + SHGFP_TYPE_CURRENT, &path[0]); + + if (result == S_OK) { + path = std::wstring( path.c_str() ); // stip extra NULLs + retval = winapi_wstr_to_utf8( path ); + } else { + PRINT("ERROR: Could not find My Documents location"); + retval = ""; + } + return retval; +} diff --git a/src/PlatformUtils-win32.cc b/src/PlatformUtils-win32.cc deleted file mode 100644 index 61382dd..0000000 --- a/src/PlatformUtils-win32.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "PlatformUtils.h" -#include -#include - -std::string PlatformUtils::documentsPath() -{ - std::string retval; - CHAR my_documents[MAX_PATH]; - HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, - SHGFP_TYPE_CURRENT, my_documents); - - if (result != S_OK) retval = ""; - else retval = my_documents; - return retval; -} diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc index a7efe40..47569b0 100644 --- a/src/PlatformUtils.cc +++ b/src/PlatformUtils.cc @@ -1,26 +1,35 @@ #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; - bool OK = true; try { path = boosty::canonical(fs::path(PlatformUtils::documentsPath())); if (path.empty()) return ""; - PRINTB("path size %i",boosty::stringy(path).size()); path /= "OpenSCAD"; path /= "libraries"; - PRINTB("Appended path %s", path ); - PRINTB("Exists: %i", fs::exists(path) ); - if (!fs::exists(path)) { - PRINTB("Creating library folder %s", boosty::stringy(path) ); - OK &= fs::create_directories( path ); - } - if (!OK) { - PRINTB("ERROR: Cannot find nor create %s", boosty::stringy(path) ); - path = fs::path(""); - } + //PRINTB("path size %i",boosty::stringy(path).size()); + //PRINTB("Appended path %s", path ); + //PRINTB("Exists: %i", fs::exists(path) ); } catch (const fs::filesystem_error& ex) { PRINTB("ERROR: %s",ex.what()); } diff --git a/src/PlatformUtils.h b/src/PlatformUtils.h index 202abaa..089b3ca 100644 --- a/src/PlatformUtils.h +++ b/src/PlatformUtils.h @@ -7,6 +7,7 @@ namespace PlatformUtils { std::string documentsPath(); std::string libraryPath(); + bool createLibraryPath(); } diff --git a/win.pri b/win.pri new file mode 100644 index 0000000..bb41b09 --- /dev/null +++ b/win.pri @@ -0,0 +1,20 @@ +# win32-specific MSVC compiler general settings + +win32*msvc* { + #configure additional directories + INCLUDEPATH += $$(MPIRDIR) + INCLUDEPATH += $$(MPFRDIR) + + DEFINES += _USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS YY_NO_UNISTD_H + + # disable MSVC warnings that are of very low importance + # disable warning about too long decorated names + QMAKE_CXXFLAGS += -wd4503 + # CGAL casting int to bool + QMAKE_CXXFLAGS += -wd4800 + # CGAL's unreferenced formal parameters + QMAKE_CXXFLAGS += -wd4100 + # lexer uses strdup() & other POSIX stuff + QMAKE_CXXFLAGS += -D_CRT_NONSTDC_NO_DEPRECATE + +} diff --git a/win32.pri b/win32.pri deleted file mode 100644 index bb41b09..0000000 --- a/win32.pri +++ /dev/null @@ -1,20 +0,0 @@ -# win32-specific MSVC compiler general settings - -win32*msvc* { - #configure additional directories - INCLUDEPATH += $$(MPIRDIR) - INCLUDEPATH += $$(MPFRDIR) - - DEFINES += _USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS YY_NO_UNISTD_H - - # disable MSVC warnings that are of very low importance - # disable warning about too long decorated names - QMAKE_CXXFLAGS += -wd4503 - # CGAL casting int to bool - QMAKE_CXXFLAGS += -wd4800 - # CGAL's unreferenced formal parameters - QMAKE_CXXFLAGS += -wd4100 - # lexer uses strdup() & other POSIX stuff - QMAKE_CXXFLAGS += -D_CRT_NONSTDC_NO_DEPRECATE - -} -- cgit v0.10.1 From cd831d6922e52d85c73846e17354ddc434debb80 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 26 May 2013 20:45:28 -0500 Subject: add 'create library' call to mainwin.cc GUI. diff --git a/src/mainwin.cc b/src/mainwin.cc index f370f3d..39af31c 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -105,6 +105,8 @@ #define OPENCSG_VERSION_STRING "unknown, <1.3.2" #endif +#include "boosty.h" + extern QString examplesdir; // Global application state @@ -955,8 +957,15 @@ void MainWindow::actionSaveAs() void MainWindow::actionShowLibraryFolder() { - QString url = QString::fromStdString(PlatformUtils::libraryPath()); - PRINTB("Opening file browser for %s", url.toStdString() ); + 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 )); } -- cgit v0.10.1 From 53e778af703e40e91c2021d4ab12f8d30e14bd60 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 26 May 2013 22:03:16 -0500 Subject: fix bugs in win version diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc index d06df51..a314ebe 100644 --- a/src/PlatformUtils-win.cc +++ b/src/PlatformUtils-win.cc @@ -1,7 +1,9 @@ #include "PlatformUtils.h" #include "printutils.h" #include +#ifndef _WIN32_IE #define _WIN32_IE 0x0501 // SHGFP_TYPE_CURRENT +#endif #include // convert from windows api w_char strings (usually utf16) to utf8 std::string @@ -11,22 +13,25 @@ std::string winapi_wstr_to_utf8( std::wstring wstr ) UINT CodePage = CP_UTF8; DWORD dwFlags = 0; - LPCSTR lpMultiByteStr = NULL; - int cbMultiByte = 0; - LPWSTR lpWideCharStr = &wstr[0]; + LPCWSTR lpWideCharStr = &wstr[0]; int cchWideChar = (int)wstr.size(); + LPSTR lpMultiByteStr = NULL; + int cbMultiByte = 0; + LPCSTR lpDefaultChar = NULL; + LPBOOL lpUsedDefaultChar = NULL; - int numbytes = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr, - cbMultiByte, lpWideCharStr, cchWideChar ); + int numbytes = WideCharToMultiByte( CodePage, dwFlags, lpWideCharStr, + cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar ); - cbMultiByte = numbytes; lpMultiByteStr = &utf8_str[0]; + cbMultiByte = numbytes; - int result = MultiByteToWideChar( CodePage, dwFlags, lpMultiByteStr, - cbMultiByte, lpWideCharStr, cchWideChar ); + 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; -- cgit v0.10.1 From 6742ad55f4cf335fc767ab65784aab81e06b61d0 Mon Sep 17 00:00:00 2001 From: Don Bright Date: Sun, 26 May 2013 22:55:14 -0500 Subject: fix buggy string init. remove debug string diff --git a/src/PlatformUtils-win.cc b/src/PlatformUtils-win.cc index a314ebe..a58a346 100644 --- a/src/PlatformUtils-win.cc +++ b/src/PlatformUtils-win.cc @@ -9,8 +9,6 @@ // convert from windows api w_char strings (usually utf16) to utf8 std::string std::string winapi_wstr_to_utf8( std::wstring wstr ) { - std::string utf8_str(""); - UINT CodePage = CP_UTF8; DWORD dwFlags = 0; LPCWSTR lpWideCharStr = &wstr[0]; @@ -23,6 +21,9 @@ std::string winapi_wstr_to_utf8( std::wstring wstr ) 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; @@ -48,12 +49,19 @@ std::string PlatformUtils::documentsPath() std::string retval; std::wstring path(MAX_PATH,0); - HRESULT result = SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, - SHGFP_TYPE_CURRENT, &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 = ""; diff --git a/src/PlatformUtils.cc b/src/PlatformUtils.cc index 47569b0..5dd007d 100644 --- a/src/PlatformUtils.cc +++ b/src/PlatformUtils.cc @@ -7,7 +7,7 @@ bool PlatformUtils::createLibraryPath() bool OK = false; try { if (!fs::exists(fs::path(path))) { - PRINTB("Creating library folder %s", path ); + //PRINTB("Creating library folder %s", path ); OK = fs::create_directories( path ); } if (!OK) { @@ -23,11 +23,14 @@ std::string PlatformUtils::libraryPath() { fs::path path; try { - path = boosty::canonical(fs::path(PlatformUtils::documentsPath())); + 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("path size %i",boosty::stringy(path).size()); //PRINTB("Appended path %s", path ); //PRINTB("Exists: %i", fs::exists(path) ); } catch (const fs::filesystem_error& ex) { -- cgit v0.10.1