Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Packages/MIES/MIES_MiesUtilities_GUI.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
/// @file MIES_MiesUtilities_GUI.ipf
/// @brief This file holds MIES utility functions for GUI

Menu "GraphPopup"
"Export graph to SVG", /Q, ExportGraphToSVG(GetCurrentWindow())
End

/// @brief Return the dimension label for the special, aka non-unique, controls
Function/S GetSpecialControlLabel(variable channelType, variable controlType)

Expand Down Expand Up @@ -845,3 +849,58 @@ Function StoreWindowCoordinatesHook(STRUCT WMWinHookStruct &s)

return 0
End

/// @brief Export a graph to SVG format
///
/// Saves the graph as SVG to:
/// - Windows: Downloads folder (falls back to Documents if Downloads doesn't exist)
/// - Mac: Documents folder
/// @param winName Name of the window (graph) to export
Function ExportGraphToSVG(string winName)

string savePath, fileName, fullPath, timeStamp, documentsPath, msg

ASSERT(!IsEmpty(winName), "Window name must not be empty")
ASSERT(WindowExists(winName), "Window does not exist: " + winName)

// Get Documents folder path as fallback
#ifdef WINDOWS
documentsPath = GetUserDocumentsFolderPath()
#else
documentsPath = SpecialDirPath("Documents", 0, 0, 0)
#endif // WINDOWS
ASSERT(!IsEmpty(documentsPath), "Could not determine Documents folder location")
if(!FolderExists(documentsPath))
CreateFolderOnDisk(documentsPath)
endif
ASSERT(FolderExists(documentsPath), "Documents folder does not exist and could not be created")

savePath = documentsPath

#ifdef WINDOWS
// On Windows, prefer Downloads folder over Documents
string downloadsPath = GetUserDownloadsFolderPath()
ASSERT(!IsEmpty(downloadsPath), "Could not determine Downloads folder location")
if(!FolderExists(downloadsPath))
CreateFolderOnDisk(downloadsPath)
endif
ASSERT(FolderExists(downloadsPath), "Downloads folder does not exist and could not be created")
savePath = downloadsPath
#endif // WINDOWS

// Generate file name from window name and timestamp
timeStamp = GetISO8601TimeStamp(localTimeZone = 1)
ASSERT(!IsEmpty(timeStamp), "Timestamp must not be empty")
fileName = SanitizeFilename(winName + "_" + timeStamp) + ".svg"
ASSERT(!IsEmpty(fileName), "File name must not be empty")
fullPath = savePath + fileName

// Save graph as SVG (E=-9 is SVG format)
try
SavePICT/O/E=-9/WIN=$winName as fullPath; AbortOnRTE
catch
msg = GetRTErrMessage()
ClearRTError()
FATAL_ERROR("Failed to save SVG file: " + fullPath + ", RTE: " + msg)
endtry
End
12 changes: 11 additions & 1 deletion Packages/MIES/MIES_Utilities_File.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ Function StoreWaveOnDisk(WAVE wv, string name)
RemoveEmptyDataFolder(dfr)
End

/// @brief Returns the path to the users documents folder
/// @brief Returns the path to the user's documents folder
Function/S GetUserDocumentsFolderPath()

string userDir = GetEnvironmentVariable("USERPROFILE")
Expand All @@ -754,6 +754,16 @@ Function/S GetUserDocumentsFolderPath()
return userDir + "Documents:"
End

/// @brief Returns the path to the user's downloads folder
Function/S GetUserDownloadsFolderPath()

string userDir = GetEnvironmentVariable("USERPROFILE")

userDir = ParseFilePath(2, ParseFilePath(5, userDir, ":", 0, 0), ":", 0, 0)

return userDir + "Downloads:"
End

#ifdef MACINTOSH

threadsafe Function MU_GetFreeDiskSpace(string path)
Expand Down