Răsfoiți Sursa

fixed lots of issues with file_dialog.*, template in tt

Former-commit-id: 15766d58ddc0fffb0359ef93cd8ac8d7cbd0008f
Alec Jacobson 11 ani în urmă
părinte
comite
1ca72046b6

+ 0 - 143
include/igl/file_dialog.cpp

@@ -1,143 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-// 
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
-// obtain one at http://mozilla.org/MPL/2.0/.
-
-#define FILE_DIALOG_MAX_BUFFER 1024
-
-std::string IGL_INLINE igl::file_dialog_open()
-{
-  char buffer[FILE_DIALOG_MAX_BUFFER];
-  
-#ifdef __APPLE__
-  // For apple use applescript hack
-  FILE * output = popen(
-                        "osascript -e \""
-                        "   tell application \\\"System Events\\\"\n"
-                        "           activate\n"
-                        "           set existing_file to choose file\n"
-                        "   end tell\n"
-                        "   set existing_file_path to (POSIX path of (existing_file))\n"
-                        "\" 2>/dev/null | tr -d '\n' ","r");
-  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL ){
-  }
-#elif _WIN32
-  
-  // Use native windows file dialog box
-  // (code contributed by Tino Weinkauf)
-
-  OPENFILENAME ofn;       // common dialog box structure
-  char szFile[260];       // buffer for file name
-  HWND hwnd;              // owner window
-  HANDLE hf;              // file handle
-
-  // Initialize OPENFILENAME
-  ZeroMemory(&ofn, sizeof(ofn));
-  ofn.lStructSize = sizeof(ofn);
-  ofn.hwndOwner = NULL;//hwnd;
-  ofn.lpstrFile = new wchar_t[100];
-  // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
-  // use the contents of szFile to initialize itself.
-  ofn.lpstrFile[0] = '\0';
-  ofn.nMaxFile = sizeof(szFile);
-  ofn.lpstrFilter = L"*.*\0";//off\0*.off\0obj\0*.obj\0mp\0*.mp\0";
-  ofn.nFilterIndex = 1;
-  ofn.lpstrFileTitle = NULL;
-  ofn.nMaxFileTitle = 0;
-  ofn.lpstrInitialDir = NULL;
-  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
-
-  // Display the Open dialog box. 
-  int pos = 0;
-  if (GetOpenFileName(&ofn)==TRUE)
-  {
-    while(ofn.lpstrFile[pos] != '\0')
-    {
-      buffer[pos] = (char)ofn.lpstrFile[pos];
-      pos++;
-    }
-    buffer[pos] = 0;
-  } 
-  
-#else
-  
-  // For linux use zenity
-  FILE * output = popen("/usr/bin/zenity --file-selection","r");
-  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL ){
-  }
-  
-  if (strlen(buffer) > 0)
-    buffer[strlen(buffer)-1] = 0;
-#endif
-  return std::string(buffer);
-}
-
-std::string IGL_INLINE igl::file_dialog_save()
-{
-  char buffer[FILE_DIALOG_MAX_BUFFER];
-#ifdef __APPLE__
-  // For apple use applescript hack
-  // There is currently a bug in Applescript that strips extensions off
-  // of chosen existing files in the "choose file name" dialog
-  // I'm assuming that will be fixed soon
-  FILE * output = popen(
-                        "osascript -e \""
-                        "   tell application \\\"System Events\\\"\n"
-                        "           activate\n"
-                        "           set existing_file to choose file name\n"
-                        "   end tell\n"
-                        "   set existing_file_path to (POSIX path of (existing_file))\n"
-                        "\" 2>/dev/null | tr -d '\n' ","r");
-  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL ){
-  }
-#elif _WIN32
-
-  // Use native windows file dialog box
-  // (code contributed by Tino Weinkauf)
-
-  OPENFILENAME ofn;       // common dialog box structure
-  char szFile[260];       // buffer for file name
-  HWND hwnd;              // owner window
-  HANDLE hf;              // file handle
-
-  // Initialize OPENFILENAME
-  ZeroMemory(&ofn, sizeof(ofn));
-  ofn.lStructSize = sizeof(ofn);
-  ofn.hwndOwner = NULL;//hwnd;
-  ofn.lpstrFile = new wchar_t[100];
-  // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
-  // use the contents of szFile to initialize itself.
-  ofn.lpstrFile[0] = '\0';
-  ofn.nMaxFile = sizeof(szFile);
-  ofn.lpstrFilter = L"";
-  ofn.nFilterIndex = 1;
-  ofn.lpstrFileTitle = NULL;
-  ofn.nMaxFileTitle = 0;
-  ofn.lpstrInitialDir = NULL;
-  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
-
-  // Display the Open dialog box. 
-  int pos = 0;
-  if (GetSaveFileName(&ofn)==TRUE)
-  {
-    while(ofn.lpstrFile[pos] != '\0')
-    {
-      buffer[pos] = (char)ofn.lpstrFile[pos];
-      pos++;
-    }
-    buffer[pos] = 0;
-  }
-
-#else
-  // For every other machine type use zenity
-  FILE * output = popen("/usr/bin/zenity --file-selection --save","r");
-  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL ){
-  }
-  
-  if (strlen(buffer) > 0)
-    buffer[strlen(buffer)-1] = 0;
-#endif
-}

+ 0 - 44
include/igl/file_dialog.h

@@ -1,44 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-// 
-// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
-// obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef IGL_FILE_DIALOG_H
-#define IGL_FILE_DIALOG_H
-
-#include <stdio.h>
-#include <string>
-
-#ifdef _WIN32
- #include <Commdlg.h>
-#endif
-
-namespace igl
-{
-
-// Returns a string with a path to an existing file
-// The string is returned empty if no file is selected
-// (on Linux machines, it assumes that Zenity is installed)
-//
-// Usage:
-//   std::string str = get_open_file_path();
-std::string IGL_INLINE file_dialog_open();
-
-// Returns a string with a path to a new/existing file
-// The string is returned empty if no file is selected
-// (on Linux machines, it assumes that Zenity is installed)
-//
-// Usage:
-//   char buffer[FILE_DIALOG_MAX_BUFFER];
-//   get_save_file_path(buffer);
-std::string IGL_INLINE file_dialog_save();
-
-}
-
-#ifdef IGL_HEADER_ONLY
-#  include "file_dialog.cpp"
-#endif
-
-#endif

+ 86 - 0
include/igl/file_dialog_open.cpp

@@ -0,0 +1,86 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#include "file_dialog_open.h"
+#include <cstdio>
+
+
+#ifdef _WIN32
+ #include <Commdlg.h>
+#endif
+
+IGL_INLINE std::string igl::file_dialog_open()
+{
+  const int FILE_DIALOG_MAX_BUFFER = 1024;
+  char buffer[FILE_DIALOG_MAX_BUFFER];
+  
+#ifdef __APPLE__
+  // For apple use applescript hack
+  FILE * output = popen(
+    "osascript -e \""
+    "   tell application \\\"System Events\\\"\n"
+    "           activate\n"
+    "           set existing_file to choose file\n"
+    "   end tell\n"
+    "   set existing_file_path to (POSIX path of (existing_file))\n"
+    "\" 2>/dev/null | tr -d '\n' ","r");
+  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL )
+  {
+  }
+#elif _WIN32
+  
+  // Use native windows file dialog box
+  // (code contributed by Tino Weinkauf)
+
+  OPENFILENAME ofn;       // common dialog box structure
+  char szFile[260];       // buffer for file name
+  HWND hwnd;              // owner window
+  HANDLE hf;              // file handle
+
+  // Initialize OPENFILENAME
+  ZeroMemory(&ofn, sizeof(ofn));
+  ofn.lStructSize = sizeof(ofn);
+  ofn.hwndOwner = NULL;//hwnd;
+  ofn.lpstrFile = new wchar_t[100];
+  // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
+  // use the contents of szFile to initialize itself.
+  ofn.lpstrFile[0] = '\0';
+  ofn.nMaxFile = sizeof(szFile);
+  ofn.lpstrFilter = L"*.*\0";//off\0*.off\0obj\0*.obj\0mp\0*.mp\0";
+  ofn.nFilterIndex = 1;
+  ofn.lpstrFileTitle = NULL;
+  ofn.nMaxFileTitle = 0;
+  ofn.lpstrInitialDir = NULL;
+  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
+
+  // Display the Open dialog box. 
+  int pos = 0;
+  if (GetOpenFileName(&ofn)==TRUE)
+  {
+    while(ofn.lpstrFile[pos] != '\0')
+    {
+      buffer[pos] = (char)ofn.lpstrFile[pos];
+      pos++;
+    }
+    buffer[pos] = 0;
+  } 
+  
+#else
+  
+  // For linux use zenity
+  FILE * output = popen("/usr/bin/zenity --file-selection","r");
+  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL )
+  {
+  }
+  
+  if (strlen(buffer) > 0)
+  {
+    buffer[strlen(buffer)-1] = 0;
+  }
+#endif
+  return std::string(buffer);
+}

+ 30 - 0
include/igl/file_dialog_open.h

@@ -0,0 +1,30 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_FILE_DIALOG_OPEN_H
+#define IGL_FILE_DIALOG_OPEN_H
+#include "igl_inline.h"
+
+#include <string>
+
+namespace igl
+{
+  // Returns a string with a path to an existing file
+  // The string is returned empty if no file is selected
+  // (on Linux machines, it assumes that Zenity is installed)
+  //
+  // Usage:
+  //   std::string str = get_open_file_path();
+  IGL_INLINE std::string file_dialog_open();
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "file_dialog_open.cpp"
+#endif
+
+#endif
+

+ 87 - 0
include/igl/file_dialog_save.cpp

@@ -0,0 +1,87 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#include "file_dialog_save.h"
+#include <cstdio>
+
+
+#ifdef _WIN32
+ #include <Commdlg.h>
+#endif
+
+IGL_INLINE std::string igl::file_dialog_save()
+{
+  const int FILE_DIALOG_MAX_BUFFER = 1024;
+  char buffer[FILE_DIALOG_MAX_BUFFER];
+#ifdef __APPLE__
+  // For apple use applescript hack
+  // There is currently a bug in Applescript that strips extensions off
+  // of chosen existing files in the "choose file name" dialog
+  // I'm assuming that will be fixed soon
+  FILE * output = popen(
+    "osascript -e \""
+    "   tell application \\\"System Events\\\"\n"
+    "           activate\n"
+    "           set existing_file to choose file name\n"
+    "   end tell\n"
+    "   set existing_file_path to (POSIX path of (existing_file))\n"
+    "\" 2>/dev/null | tr -d '\n' ","r");
+  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL )
+  {
+  }
+#elif _WIN32
+
+  // Use native windows file dialog box
+  // (code contributed by Tino Weinkauf)
+
+  OPENFILENAME ofn;       // common dialog box structure
+  char szFile[260];       // buffer for file name
+  HWND hwnd;              // owner window
+  HANDLE hf;              // file handle
+
+  // Initialize OPENFILENAME
+  ZeroMemory(&ofn, sizeof(ofn));
+  ofn.lStructSize = sizeof(ofn);
+  ofn.hwndOwner = NULL;//hwnd;
+  ofn.lpstrFile = new wchar_t[100];
+  // Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
+  // use the contents of szFile to initialize itself.
+  ofn.lpstrFile[0] = '\0';
+  ofn.nMaxFile = sizeof(szFile);
+  ofn.lpstrFilter = L"";
+  ofn.nFilterIndex = 1;
+  ofn.lpstrFileTitle = NULL;
+  ofn.nMaxFileTitle = 0;
+  ofn.lpstrInitialDir = NULL;
+  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
+
+  // Display the Open dialog box. 
+  int pos = 0;
+  if (GetSaveFileName(&ofn)==TRUE)
+  {
+    while(ofn.lpstrFile[pos] != '\0')
+    {
+      buffer[pos] = (char)ofn.lpstrFile[pos];
+      pos++;
+    }
+    buffer[pos] = 0;
+  }
+
+#else
+  // For every other machine type use zenity
+  FILE * output = popen("/usr/bin/zenity --file-selection --save","r");
+  while ( fgets(buffer, FILE_DIALOG_MAX_BUFFER, output) != NULL )
+  {
+  }
+  
+  if (strlen(buffer) > 0)
+  {
+    buffer[strlen(buffer)-1] = 0;
+  }
+#endif
+  return std::string(buffer);
+}

+ 31 - 0
include/igl/file_dialog_save.h

@@ -0,0 +1,31 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_FILE_DIALOG_SAVE_H
+#define IGL_FILE_DIALOG_SAVE_H
+#include "igl_inline.h"
+
+#include <string>
+
+namespace igl
+{
+  // Returns a string with a path to a new/existing file
+  // The string is returned empty if no file is selected
+  // (on Linux machines, it assumes that Zenity is installed)
+  //
+  // Usage:
+  //   char buffer[FILE_DIALOG_MAX_BUFFER];
+  //   get_save_file_path(buffer);
+  IGL_INLINE std::string file_dialog_save();
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "file_dialog_save.cpp"
+#endif
+
+#endif
+

+ 1 - 0
include/igl/tt.cpp

@@ -103,4 +103,5 @@ IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<Scalar>& V,
 template void igl::tt<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::tt<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
 template void igl::tt<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
 template void igl::tt<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
+template void igl::tt<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif
 #endif