Skip to content

Commit 6edad80

Browse files
authored
Merge pull request #54 from scharlton2/develop-issue-53
Closes #53
2 parents 772e934 + 3ce8bf1 commit 6edad80

7 files changed

+224
-68
lines changed

mv/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ add_library(mv
6464
mvUtil.h
6565
shpopen.c
6666
shapefil.h
67+
win32/mvSaveCurrentDirectory.cpp
68+
win32/mvSaveCurrentDirectory.h
6769
)
6870

6971
# generate mvHeader for dll linkage
@@ -87,6 +89,10 @@ endif()
8789

8890
target_include_directories(mv PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
8991

92+
if (WIN32)
93+
target_include_directories(mv PRIVATE win32)
94+
endif()
95+
9096
target_link_libraries(mv ${VTK_LIBRARIES})
9197

9298
# precompiled headers

mv/mvManager.cpp

+49-65
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
#include "mvManager.h"
2+
3+
#include "mvAxes.h"
4+
#include "mvBoundingBox.h"
5+
#include "mvClipBox.h"
6+
#include "mvColorBar.h"
7+
#include "mvColorTable.h"
28
#include "mvCustomAppendPolyData.h"
3-
#include "mvModelList.h"
4-
#include "mvGUISettings.h"
5-
#include "mvPathlines.h"
6-
#include "mvGridLines.h"
9+
#include "mvDisplayText.h"
710
#include "mvGridLayer.h"
11+
#include "mvGridLines.h"
812
#include "mvGridShell.h"
13+
#include "mvGUISettings.h"
914
#include "mvHashTable.h"
10-
#include "mvBoundingBox.h"
11-
#include "mvAxes.h"
15+
#include "mvLogColorTable.h"
1216
#include "mvModelFeatures.h"
13-
#include "mvColorBar.h"
14-
#include "mvDisplayText.h"
17+
#include "mvModelList.h"
1518
#include "mvOverlay.h"
16-
#include "mvColorTable.h"
17-
#include "mvLogColorTable.h"
18-
#include "mvClipBox.h"
19+
#include "mvPathlines.h"
20+
#include "mvSaveCurrentDirectory.h"
1921
#include "mvUtil.h"
2022

2123
#include "vtkActor.h"
24+
#include "vtkAlgorithmOutput.h"
2225
#include "vtkBandedPolyDataContourFilter.h"
26+
#include "vtkCellArray.h"
27+
#include "vtkCellData.h"
2328
#include "vtkClipPolyData.h"
2429
#include "vtkContourFilter.h"
2530
#include "vtkCubeSource.h"
2631
#include "vtkCutter.h"
2732
#include "vtkDataSetMapper.h"
28-
#include "vtkExtractGrid.h"
29-
#include "vtkExtractCells.h"
3033
#include "vtkDoubleArray.h"
34+
#include "vtkExtractCells.h"
35+
#include "vtkExtractGeometry.h"
36+
#include "vtkExtractGrid.h"
3137
#include "vtkGeometryFilter.h"
3238
#include "vtkGlyph3D.h"
3339
#include "vtkHedgeHog.h"
34-
#include "vtkLookupTable.h"
40+
#include "vtkHexagonalPrism.h"
41+
#include "vtkHexahedron.h"
3542
#include "vtkLogLookupTable.h"
43+
#include "vtkLookupTable.h"
44+
#include "vtkMaskPoints.h"
45+
#include "vtkPentagonalPrism.h"
3646
#include "vtkPlane.h"
47+
#include "vtkPointData.h"
3748
#include "vtkPolyData.h"
3849
#include "vtkPolyDataMapper.h"
3950
#include "vtkPropCollection.h"
51+
#include "vtkProperty.h"
52+
#include "vtkProperty2D.h"
4053
#include "vtkStructuredGrid.h"
54+
#include "vtkTextProperty.h"
4155
#include "vtkThreshold.h"
4256
#include "vtkThresholdPoints.h"
43-
#include "vtkMaskPoints.h"
44-
#include "vtkExtractGeometry.h"
45-
#include "vtkPointData.h"
46-
#include "vtkProperty.h"
47-
#include "vtkProperty2D.h"
4857
#include "vtkUnstructuredGrid.h"
49-
#include "vtkCellData.h"
50-
#include "vtkTextProperty.h"
51-
#include "vtkAlgorithmOutput.h"
5258
#include "vtkWedge.h"
53-
#include "vtkHexahedron.h"
54-
#include "vtkPentagonalPrism.h"
55-
#include "vtkHexagonalPrism.h"
56-
#include "vtkCellArray.h"
57-
58-
#include "vtkConeSource.h"
5959

6060
#include <direct.h>
6161

@@ -4848,7 +4848,7 @@ char *mvManager::Serialize(const char *fileName, mvGUISettings *gui) const
48484848
cr = strchr(code, '\n');
48494849
*(cr) = '\0';
48504850
// Get relative paths for all file codes
4851-
std::string relative = GetRelativePath(fileName, code);
4851+
std::string relative = mvSaveCurrentDirectory::GetRelativePath(fileName, code);
48524852
out << "File code " << (i + 1) << " = " << relative.c_str() << endl;
48534853
code = cr + 1;
48544854
}
@@ -5101,7 +5101,9 @@ char *mvManager::Serialize(const char *fileName, mvGUISettings *gui) const
51015101
// Overlay
51025102
if (m_Overlay->HasData())
51035103
{
5104-
out << "Overlay file = " << m_Overlay->GetFileName() << endl;
5104+
std::string dir = mvSaveCurrentDirectory::GetDirName(fileName);
5105+
std::string relative = mvSaveCurrentDirectory::GetRelativePath(dir.c_str(), m_Overlay->GetFileName());
5106+
out << "Overlay file = " << relative << endl;
51055107
}
51065108
out << "Overlay data type = " << m_Overlay->GetType() << endl;
51075109
double x, y;
@@ -5141,8 +5143,9 @@ void mvManager::Deserialize(const char *fileName, mvGUISettings *gui, std::strin
51415143
return;
51425144
}
51435145

5146+
#if defined(_DEBUG)
51445147
// Set the working directory to the directory that contains
5145-
// the document (.mv) file. We assume that model data files
5148+
// the document (.mvmf6) file. We assume that model data files
51465149
// are also in this directory.
51475150
strcpy(buffer, fileName);
51485151
char *p = strrchr(buffer, '\\');
@@ -5151,7 +5154,11 @@ void mvManager::Deserialize(const char *fileName, mvGUISettings *gui, std::strin
51515154
p++;
51525155
}
51535156
*p = '\0';
5154-
_chdir(buffer);
5157+
///_chdir(buffer);
5158+
char curdir[1024];
5159+
::GetCurrentDirectory(1023, curdir);
5160+
ASSERT(strcmp(curdir, buffer) == 0);
5161+
#endif
51555162

51565163
// Create a hash table and read the data file into the hash table
51575164
mvHashTable *hashTable = new mvHashTable;
@@ -5198,7 +5205,7 @@ void mvManager::Deserialize(const char *fileName, mvGUISettings *gui, std::strin
51985205
}
51995206

52005207
// Get absolute paths for all file codes
5201-
std::string dirname = GetDirName(fileName);
5208+
std::string dirname = mvSaveCurrentDirectory::GetDirName(fileName);
52025209
char szDest[MAX_PATH];
52035210
char fullpath[MAX_PATH];
52045211
char * dataFileList = new char[ncode * 1024];
@@ -5237,6 +5244,13 @@ void mvManager::Deserialize(const char *fileName, mvGUISettings *gui, std::strin
52375244
strcat(dataFileList, "\n");
52385245
}
52395246

5247+
std::shared_ptr<mvSaveCurrentDirectory> spCurDir;
5248+
if (ncode == 1)
5249+
{
5250+
// save current directory and cd to dataFileList
5251+
spCurDir.reset(new mvSaveCurrentDirectory(dataFileList));
5252+
}
5253+
52405254
// Load the data and set up the visualization pipeline
52415255

52425256
char *err = LoadData(modelName, dataFileList);
@@ -6014,7 +6028,7 @@ void mvManager::Deserialize(const char *fileName, mvGUISettings *gui, std::strin
60146028
char *errMsg = 0;
60156029
if (hashTable->GetHashTableValue("Overlay file", filename))
60166030
{
6017-
SetOverlayFileName(filename);
6031+
SetOverlayFileName(mvSaveCurrentDirectory::GetFullPath(filename, dirname.c_str()).c_str());
60186032
if (!UpdateOverlay(errMsg))
60196033
{
60206034
strcat(m_WarningMessage, "Unable to load overlay file. Overlay will not be displayed.");
@@ -6087,7 +6101,7 @@ void mvManager::ClearOverlayData()
60876101
m_Overlay->ClearData();
60886102
}
60896103

6090-
void mvManager::SetOverlayFileName(char *filename)
6104+
void mvManager::SetOverlayFileName(const char *filename)
60916105
{
60926106
m_Overlay->SetFileName(filename);
60936107
}
@@ -6351,33 +6365,3 @@ int mvManager::GetGridDisplayMode()
63516365
{
63526366
return m_GridDisplayMode;
63536367
}
6354-
6355-
std::string mvManager::GetRelativePath(const char *pszFrom, const char *pszTo)
6356-
{
6357-
TCHAR szOut[MAX_PATH] = "";
6358-
if (strlen(pszTo) && PathIsSameRoot(pszFrom, pszTo))
6359-
{
6360-
std::string cpTo(pszTo);
6361-
std::replace(cpTo.begin(), cpTo.end(), '/', '\\');
6362-
VERIFY(PathCanonicalize(szOut, cpTo.c_str()));
6363-
cpTo = szOut;
6364-
VERIFY(PathRelativePathTo(szOut, pszFrom, FILE_ATTRIBUTE_NORMAL, cpTo.c_str(), FILE_ATTRIBUTE_NORMAL));
6365-
return std::string(szOut);
6366-
}
6367-
return std::string(pszTo);
6368-
}
6369-
6370-
std::string mvManager::GetDirName(const char *fullPath)
6371-
{
6372-
char szPath[MAX_PATH];
6373-
char szOut[MAX_PATH];
6374-
char szDrive[_MAX_DRIVE];
6375-
char szDir[_MAX_DIR];
6376-
char szDest[MAX_PATH];
6377-
6378-
ASSERT(!PathIsRelative(fullPath));
6379-
VERIFY(_tsplitpath_s(fullPath, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, NULL, 0, NULL, 0) == 0);
6380-
VERIFY(_tmakepath_s(szPath, _MAX_DIR, szDrive, szDir, NULL, NULL) == 0);
6381-
6382-
return std::string(szPath);
6383-
}

mv/mvManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class MV_EXPORT mvManager
190190
void HideOverlay();
191191
int IsOverlayVisible() const;
192192
void ClearOverlayData();
193-
void SetOverlayFileName(char *filename);
193+
void SetOverlayFileName(const char *filename);
194194
void SetOverlayType(int type);
195195
void SetOverlayCoordinatesAtGridOrigin(double xorig, double yorig);
196196
void SetOverlayElevation(double elev);

mv/mvOverlay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void mvOverlay::ClearData()
150150
m_YMax = 0;
151151
}
152152

153-
void mvOverlay::SetFileName(char *filename)
153+
void mvOverlay::SetFileName(const char *filename)
154154
{
155155
if (!filename)
156156
{

mv/mvOverlay.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MV_EXPORT mvOverlay : public mvDisplayObject
1717
mvOverlay();
1818
~mvOverlay();
1919

20-
void SetFileName(char *filename);
20+
void SetFileName(const char *filename);
2121
void SetType(int type);
2222
void SetCoordinatesAtGridOrigin(double xorig, double yorig);
2323
void SetAngle(double angle);

0 commit comments

Comments
 (0)