Commit d932fac4 authored by whitlocb's avatar whitlocb

Refactor viewer into viewercore/viewer and use viewercore to enhance libsim.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@24562 18c085ea-50e0-402c-830e-de6fd14e8384
parent c8bc2690
......@@ -91,6 +91,7 @@ using StringHelpers::HumanReadableList;
bool avtDatabaseFactory::createMeshQualityExpressions = true;
bool avtDatabaseFactory::createTimeDerivativeExpressions = true;
bool avtDatabaseFactory::createVectorMagnitudeExpressions = true;
bool avtDatabaseFactory::checkFilePermissions = true;
FileOpenOptions avtDatabaseFactory::defaultFileOpenOptions;
avtPrecisionType avtDatabaseFactory::precisionType = AVT_PRECISION_NATIVE;
avtBackendType avtDatabaseFactory::backendType = AVT_BACKEND_VTK;
......@@ -361,6 +362,11 @@ avtDatabaseFactory::SetBackendType(const int bType)
// Mark C. Miller, Wed Jan 8 18:15:01 PST 2014
// Added some error checking for !NBLOCKS, !TIMES declarations and adjusted
// the debug output to be a little more helpful.
//
// Brad Whitlock, Thu Sep 18 23:02:07 PDT 2014
// Allow file permission check to be bypassed. We don't want it for batch
// in situ.
//
// ****************************************************************************
avtDatabase *
......@@ -447,7 +453,8 @@ avtDatabaseFactory::FileList(DatabasePluginManager *dbmgr,
//
// Make sure we can read the file before we proceed.
//
CheckPermissions(filelist[fileIndex]);
if(checkFilePermissions)
CheckPermissions(filelist[fileIndex]);
//
// If we were specifically told which format to use, then try that now.
......@@ -1180,90 +1187,23 @@ avtDatabaseFactory::VisitFile(DatabasePluginManager *dbmgr,
// Test for file's existence on Windows. Throwing the exception here can
// prevent engine crashing elsewhere. (conn_cmfe test with bad_file.silo).
//
// Brad Whitlock, Mon Sep 8 14:25:23 PDT 2014
// Moved code to FileFunctions.
//
// ****************************************************************************
#if defined(_WIN32)
static void
CheckPermissions(const char *filename)
{
VisItStat_t s;
int result = VisItStat(filename, &s);
if (result < 0)
FileFunctions::PermissionsResult result =
FileFunctions::CheckPermissions(filename);
if (result == FileFunctions::PERMISSION_RESULT_NOFILE)
{
EXCEPTION1(FileDoesNotExistException, filename);
}
}
#else
static bool setUpUserInfo = false;
static uid_t uid;
static gid_t gids[100];
static int ngids;
static void
SetUpUserInfo(void)
{
setUpUserInfo = true;
uid = getuid();
ngids = getgroups(100, gids);
}
static void
CheckPermissions(const char *filename)
{
if (!setUpUserInfo)
{
SetUpUserInfo();
}
VisItStat_t s;
int rv = VisItStat(filename, &s);
if (rv < 0)
else if (result == FileFunctions::PERMISSION_RESULT_NONREADABLE)
{
if(errno == ENOENT || errno == ENOTDIR)
{
EXCEPTION1(FileDoesNotExistException, filename);
}
else
{
EXCEPTION1(BadPermissionException, filename);
}
EXCEPTION1(BadPermissionException, filename);
}
mode_t mode = s.st_mode;
//
// If other has permission, then we are set.
//
if (mode & S_IROTH)
{
return;
}
//
// If we are the user and the user has permission, then we are set.
//
bool isuser = (s.st_uid == uid);
if (isuser && (mode & S_IRUSR))
{
return;
}
//
// If we are in the group and the group has permission, then we are set.
//
bool isgroup = false;
for (int i = 0 ; i < ngids ; i++)
{
if (gids[i] == s.st_gid)
{
isgroup = true;
}
}
if (isgroup && (mode & S_IRGRP))
{
return;
}
EXCEPTION1(BadPermissionException, filename);
}
#endif
......@@ -134,6 +134,9 @@ class DatabasePluginManager;
// Cameron Christensen, Wednesday, June 11, 2014
// Add methods for setting/getting backend type specified by user.
//
// Brad Whitlock, Thu Sep 18 23:02:56 PDT 2014
// Added methods for bypassing file permission checks.
//
// ****************************************************************************
class DATABASE_API avtDatabaseFactory
......@@ -176,6 +179,11 @@ class DATABASE_API avtDatabaseFactory
static void SetBackendType(const int bType);
static avtBackendType GetBackendType()
{ return backendType;}
static void SetCheckFilePermissions(bool val)
{ checkFilePermissions = val; }
static bool GetCheckFilePermissions()
{ return checkFilePermissions; }
protected:
static avtDatabase *SetupDatabase(CommonDatabasePluginInfo *,
const char * const *, int,
......@@ -186,6 +194,7 @@ class DATABASE_API avtDatabaseFactory
static bool createMeshQualityExpressions;
static bool createTimeDerivativeExpressions;
static bool createVectorMagnitudeExpressions;
static bool checkFilePermissions;
static FileOpenOptions defaultFileOpenOptions;
static avtPrecisionType precisionType;
static avtBackendType backendType;
......
......@@ -51,6 +51,7 @@
#include <avtFileDescriptorManager.h>
#include <DebugStream.h>
#include <FileFunctions.h>
#include <ImproperUseException.h>
#include <StringHelpers.h>
......@@ -755,7 +756,7 @@ avtFileFormat::GuessCycleOrTime(const char *fname, const char *re)
//
// Take out any of the name that comes from the directory structure.
//
fname = StringHelpers::Basename(fname);
fname = FileFunctions::Basename(fname);
string substr = StringHelpers::ExtractRESubstr(fname, re);
if (substr != "")
......
......@@ -73,6 +73,7 @@
#include <avtCommonDataFunctions.h>
#include <DebugStream.h>
#include <FileFunctions.h>
#include <ImproperUseException.h>
#include <NoCurveException.h>
#include <NoInputException.h>
......@@ -1252,7 +1253,7 @@ avtDatasetFileWriter::WritePOVRayFamily(const char *filename)
//
// Get the dir name in case user's not saving in current directory
//
string dirname(StringHelpers::Dirname(basename));
string dirname(FileFunctions::Dirname(basename));
//
// It's easiest and safest to collect data and spatial extents
......
......@@ -55,10 +55,19 @@
#include <DebugStream.h>
#include <vtkImageResample.h>
#include <snprintf.h>
// This array contains strings that correspond to the file types that are
// enumerated in the ImageFileFormat enum.
const char *avtImageFileWriter::extensions[] = {
".bmp", ".jpeg", ".png", ".ps", ".ppm", ".rgb", ".tif"};
const char *avtImageFileWriter::extensions[][4] = {
{".bmp", ".BMP", NULL, NULL},
{".jpeg", ".jpg", ".JPEG", ".JPG"},
{".png", ".PNG", NULL, NULL},
{".ps", ".PS", NULL, NULL},
{".ppm", ".PPM", NULL, NULL},
{".rgb", ".RGB", NULL, NULL},
{".tif", ".tiff", ".TIF", ".TIFF"}
};
// ****************************************************************************
......@@ -293,6 +302,11 @@ avtImageFileWriter::FileHasExtension(const char *filename, const char *ext) cons
// Fixed a problem that caused the file base from being ignored when files
// did not have an extension.
//
// Brad Whitlock, Thu Sep 18 22:55:57 PDT 2014
// Check some other file extensions before appending the default file
// extension for the format. This is because some file formats have allowable
// file extension variants.
//
// ****************************************************************************
char *
......@@ -301,6 +315,7 @@ avtImageFileWriter::CreateFilename(const char *base, bool family,
{
char *str = NULL;
int len = strlen(base);
int iformat = (int)format;
// Reset the nFilesWritten count if the file base changes.
if(family)
......@@ -320,23 +335,33 @@ avtImageFileWriter::CreateFilename(const char *base, bool family,
}
}
// Get memory for the filename. The 9 is for "0000.tif"
str = new char[len + 1 + 9];
// Get memory for the filename. The 10 is for "0000.jpeg"
len += (1 + 10);
str = new char[len];
// The family flag indicates whether or not to include the number of
// files written as part of the filename.
if(family)
{
sprintf(str, "%s%04d%s", base, nFilesWritten,
extensions[(int)format]);
SNPRINTF(str, len, "%s%04d%s", base, nFilesWritten,
extensions[iformat][0]);
}
else
{
sprintf(str, "%s", base);
SNPRINTF(str, len, "%s", base);
// We're passing a full filename. See if we need to append a
// file extension.
bool hasExtension = false;
for(int i = 0; i < 4; ++i)
{
if(extensions[iformat][i] != NULL)
hasExtension |= FileHasExtension(base, extensions[iformat][i]);
}
if(!FileHasExtension(base, extensions[(int)format]))
if(!hasExtension)
{
sprintf(str, "%s%s", base, extensions[(int)format]);
SNPRINTF(str, len, "%s%s", base, extensions[iformat][0]);
}
}
......@@ -347,7 +372,7 @@ avtImageFileWriter::CreateFilename(const char *base, bool family,
}
// ****************************************************************************
// Method: avtImageFileWriter::WriteToString
// Method: avtImageFileWriter::WriteToByteArray
//
// Purpose:
// Writes image to byte array
......
......@@ -96,7 +96,7 @@ class vtkImageWriter;
// have problems with them.
//
// Brad Whitlock, Mon Mar 6 17:35:28 PST 2006
// I made it reset nFilesWritten if the nase changes.
// I made it reset nFilesWritten if the base changes.
//
// ****************************************************************************
......@@ -127,7 +127,7 @@ class AVTFILEWRITER_API avtImageFileWriter : public avtTerminatingImageSink
bool FileHasExtension(const char *filename, const char *ext)
const;
static const char *extensions[];
static const char *extensions[][4];
int nFilesWritten;<