diff --git a/Make/makedirdefs b/Make/makedirdefs index f8d1da03d..a1070d7c9 100644 --- a/Make/makedirdefs +++ b/Make/makedirdefs @@ -135,6 +135,7 @@ endif EXAMPLE_DIRS = \ osganimate\ + osgarchive\ osgautotransform\ osgbillboard\ osgcallback\ diff --git a/VisualStudio/VisualStudio.dsw b/VisualStudio/VisualStudio.dsw index dcdfafb3f..07e7bd520 100644 --- a/VisualStudio/VisualStudio.dsw +++ b/VisualStudio/VisualStudio.dsw @@ -459,6 +459,27 @@ Package=<4> ############################################################################### +Project: "Example osgarchive"=.\examples\osgarchive\osgarchive.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Core osg + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgDB + End Project Dependency + Begin Project Dependency + Project_Dep_Name Core osgUtil + End Project Dependency +}}} + +############################################################################### + Project: "Example osgcopy"=.\examples\osgcopy\osgcopy.dsp - Package Owner=<4> Package=<5> diff --git a/VisualStudio/examples/osgarchive/osgarchive.dsp b/VisualStudio/examples/osgarchive/osgarchive.dsp new file mode 100644 index 000000000..fa388d5e8 --- /dev/null +++ b/VisualStudio/examples/osgarchive/osgarchive.dsp @@ -0,0 +1,97 @@ +# Microsoft Developer Studio Project File - Name="Example osgarchive" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Example osgarchive - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "osgarchive.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "osgarchive.mak" CFG="Example osgarchive - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Example osgarchive - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Example osgarchive - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Example osgarchive - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +MTL=midl.exe +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm200 /c +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 OpenThreadsWin32.lib opengl32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgarchive.exe" /libpath:"../../../lib" /libpath:"../../../../OpenThreads/lib/win32" /libpath:"../../../../Producer/lib" /libpath:"../../../../3rdParty/lib" + +!ELSEIF "$(CFG)" == "Example osgarchive - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +MTL=midl.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /vd0 /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /c +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 OpenThreadsWin32d.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgarchived.exe" /pdbtype:sept /libpath:"../../../lib" /libpath:"../../../../OpenThreads/lib/win32" /libpath:"../../../../Producer/lib" /libpath:"../../../../3rdParty/lib" +# SUBTRACT LINK32 /incremental:no + +!ENDIF + +# Begin Target + +# Name "Example osgarchive - Win32 Release" +# Name "Example osgarchive - Win32 Debug" +# Begin Source File + +SOURCE=..\..\..\examples\osgarchive\osgarchive.cpp +# End Source File +# End Target +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Project diff --git a/VisualStudio/osgDB/osgDB.dsp b/VisualStudio/osgDB/osgDB.dsp index 39139f1de..ecd221348 100755 --- a/VisualStudio/osgDB/osgDB.dsp +++ b/VisualStudio/osgDB/osgDB.dsp @@ -95,6 +95,10 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=..\..\src\osgDB\Archive.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osgDB\DatabasePager.cpp # End Source File # Begin Source File @@ -167,6 +171,10 @@ SOURCE=..\..\Src\osgDB\WriteFile.cpp # PROP Default_Filter ";h;hpp;hxx;hm;inl" # Begin Source File +SOURCE=..\..\Include\osgDB\Archive +# End Source File +# Begin Source File + SOURCE=..\..\Include\osgDB\DatabasePager # End Source File # Begin Source File diff --git a/examples/osgarchive/GNUmakefile b/examples/osgarchive/GNUmakefile new file mode 100644 index 000000000..b189eedd1 --- /dev/null +++ b/examples/osgarchive/GNUmakefile @@ -0,0 +1,18 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgarchive.cpp\ + +LIBS += -losgProducer -lProducer -losgDB -losgUtil -losg $(GDAL_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +INSTFILES = \ + $(CXXFILES)\ + GNUmakefile.inst=GNUmakefile + +EXEC = osgarchive + +INC += $(X_INC) + +include $(TOPDIR)/Make/makerules + diff --git a/examples/osgarchive/GNUmakefile.inst b/examples/osgarchive/GNUmakefile.inst new file mode 100644 index 000000000..41953e5c5 --- /dev/null +++ b/examples/osgarchive/GNUmakefile.inst @@ -0,0 +1,13 @@ +TOPDIR = ../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + osgarchive.cpp\ + +LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) + +EXEC = osgarchive + +INC += $(X_INC) + +include $(TOPDIR)/Make/makerules diff --git a/examples/osgarchive/osgarchive.cpp b/examples/osgarchive/osgarchive.cpp new file mode 100644 index 000000000..b4db03bdf --- /dev/null +++ b/examples/osgarchive/osgarchive.cpp @@ -0,0 +1,98 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This application is open source and may be redistributed and/or modified + * freely and without restriction, both in commericial and non commericial applications, + * as long as this copyright notice is maintained. + * + * This application is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#include +#include + +#include + +#include + +int main( int argc, char **argv ) +{ + + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc,argv); + + // set up the usage document, in case we need to print out how to use this program. + arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); + arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); + + // create DataSet. + osgDB::Archive::Status status; + + // if user request help write it out to cout. + if (arguments.read("-h") || arguments.read("--help")) + { + arguments.getApplicationUsage()->write(std::cout); + return 1; + } + + std::string archiveFilename; + while (arguments.read("-a",archiveFilename) || arguments.read("--archive",archiveFilename)) + { + } + + bool insert = false; + while (arguments.read("-i") || arguments.read("--insert")) + { + insert = true; + } + + bool extract = false; + while (arguments.read("-e") || arguments.read("--extract")) + { + extract = true; + } + + bool list = false; + while (arguments.read("-l") || arguments.read("--list")) + { + list = true; + } + + typedef std::vector FileNameList; + FileNameList files; + for(int pos=1;pos +#include namespace osgDB { /** Base class for implementing database Archives. */ + + class OSGDB_EXPORT Archive : public ReaderWriter { public: Archive(); virtual ~Archive(); - - virtual const char* className() { return "Archive" }; + + virtual const char* libraryName() const { return "osgDB"; } + + virtual const char* className() const { return "Archive"; } + virtual bool acceptsExtension(const std::string& /*extension*/) { return true; } + + enum Status + { + READ, + WRITE + }; /** open the archive.*/ - virtual void open(const std::string& filename) {} - + virtual void create(const std::string& filename, unsigned int indexBlockSize=4096); + + /** open the archive.*/ + virtual void open(const std::string& filename, Status status); + /** close the archive.*/ - virtual void close() {} + virtual void close(); /** return true if file exists in archive.*/ - virtual bool fileExists(const std::string& filename) const {} + virtual bool fileExists(const std::string& filename) const; - virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readNode(const std::string& /*fileName*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readObject(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readImage(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readHeightField(const std::string& fileName,const Options* options=NULL); + virtual ReadResult readNode(const std::string& fileName,const Options* options=NULL); - virtual WriteResult writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL); + virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL); - virtual ReadResult readObject(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readImage(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readHeightField(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } - virtual ReadResult readNode(std::istream& /*fin*/,const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + virtual ReadResult readObject(std::istream& fin,const Options* options=NULL); + virtual ReadResult readImage(std::istream& fin,const Options* options=NULL); + virtual ReadResult readHeightField(std::istream& fin,const Options* options=NULL); + virtual ReadResult readNode(std::istream& fin,const Options* options=NULL); - virtual WriteResult writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } - virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + virtual WriteResult writeObject(const osg::Object& obj,std::ostream& fout,const Options* options=NULL); + virtual WriteResult writeImage(const osg::Image& image,std::ostream& fout,const Options* options=NULL); + virtual WriteResult writeHeightField(const osg::HeightField& heightField,std::ostream& fout,const Options* options=NULL); + virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* options=NULL); + + protected: + + typedef std::istream::pos_type pos_type; + + typedef std::map FileNamePositionMap; + + Status _status; + std::ifstream _input; + std::ofstream _output; + + FileNamePositionMap _indexMap; }; diff --git a/src/osgDB/Archive.cpp b/src/osgDB/Archive.cpp new file mode 100644 index 000000000..3bb26564a --- /dev/null +++ b/src/osgDB/Archive.cpp @@ -0,0 +1,73 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + +using namespace osgDB; + +Archive::Archive() +{ +} + +Archive::~Archive() +{ + close(); +} + +void Archive::create(const std::string& filename, unsigned int indexBlockSize) +{ +} + +void Archive::open(const std::string& filename, Status status) +{ + if (status==READ) + { + _input.open(filename.c_str()); + } + else // status==WRITE + { + _input.open(filename.c_str()); + } +} + +void Archive::close() +{ + _input.close(); + _output.close(); +} + + +bool Archive::fileExists(const std::string& filename) const +{ + return (_indexMap.count(filename)!=0); +} + +ReaderWriter::ReadResult Archive::readObject(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } +ReaderWriter::ReadResult Archive::readImage(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } +ReaderWriter::ReadResult Archive::readHeightField(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } +ReaderWriter::ReadResult Archive::readNode(const std::string& /*fileName*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + +ReaderWriter::WriteResult Archive::writeObject(const osg::Object& /*obj*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } +ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } +ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,const std::string& /*fileName*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } +ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,const std::string& /*fileName*/,const Options*) { return WriteResult(WriteResult::FILE_NOT_HANDLED); } + +ReaderWriter::ReadResult Archive::readObject(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } +ReaderWriter::ReadResult Archive::readImage(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } +ReaderWriter::ReadResult Archive::readHeightField(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } +ReaderWriter::ReadResult Archive::readNode(std::istream& /*fin*/,const Options*) { return ReadResult(ReadResult::FILE_NOT_HANDLED); } + +ReaderWriter::WriteResult Archive::writeObject(const osg::Object& /*obj*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } +ReaderWriter::WriteResult Archive::writeImage(const osg::Image& /*image*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } +ReaderWriter::WriteResult Archive::writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options*) {return WriteResult(WriteResult::FILE_NOT_HANDLED); } +ReaderWriter::WriteResult Archive::writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options*) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }