OpenCOVER
coVRFileManager.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef COVR_FILE_MANAGER_H
9#define COVR_FILE_MANAGER_H
10
23#include <util/coExport.h>
24#include <list>
25#include <limits.h>
26#include <map>
27#include <memory>
28#include <osg/ref_ptr>
29#include <osg/Texture2D>
30#include <osgDB/ReadFile>
31#include <string>
32#include <vector>
33#include <vrb/client/SharedState.h>
35
36namespace osg
37{
38class Node;
39class Group;
40class Texture2D;
41}
42
43namespace osgText
44{
45class Font;
46}
47namespace covise
48{
49class Message;
50}
51namespace opencover
52{
53
54namespace ui
55{
56class Owner;
57class Group;
58class FileBrowser;
59}
60
61class coTUIFileBrowserButton;
62class coVRIOReader;
63
64struct LoadedFile;
65
66class COVEREXPORT Url
67{
68public:
69 Url(const std::string &url);
70 static Url fromFileOrUrl(const std::string &furl);
71 static std::string decode(const std::string &str, bool path=false);
72
73 std::string str() const;
74 operator std::string() const;
75
76 std::string extension() const;
77 bool valid() const;
78 bool isLocal() const;
79
80 const std::string &scheme() const;
81 const std::string &authority() const;
82 const std::string &path() const;
83 const std::string &query() const;
84 const std::string &fragment() const;
85
86private:
87
88 bool m_valid = false;
89
90 std::string m_scheme;
91 std::string m_authority;
92 bool m_haveAuthority = false;
93 std::string m_userinfo;
94 std::string m_host;
95 std::string m_port;
96 std::string m_path;
97 std::string m_query;
98 std::string m_fragment;
99
100 Url();
101};
102
103
104typedef struct
105{
106 int (*loadUrl)(const Url &url, osg::Group *parent, const char *covise_key);
107 int (*loadFile)(const char *filename, osg::Group *parent, const char *covise_key);
108 int (*unloadFile)(const char *filename, const char *covise_key);
109 const char *extension;
111
112
113
114class COVEREXPORT coVRFileManager : public vrui::coUpdateable
115{
116 friend struct LoadedFile;
117 static coVRFileManager *s_instance;
118
119public:
122
123 std::string findFileExt(const Url &url);
124
125 // returns the full path for file
126 const char *getName(const char *file);
127 //if filePath starts with sharedDataPath, return true and remove sharedDataPath from filePath. Ignore upper/lower case differences
128 bool makeRelativeToSharedDataLink(std::string &fileName);
129 //return true if fileName contains tmp path
130 bool isInTmpDir(const std::string& fileName);
131 //changes fileName to be relative to basePath
132 bool makeRelativePath(std::string& fileName, const std::string& basePath);
133 //search file locally, in sharedData and then try to remote fetch the file(if activated) until a the file gets found. Return "" if no file found. Use isTmp to eventually delete tmp files
134 std::string findOrGetFile(const std::string &fileName, bool *isTmp = (bool *)false);
135 // load a OSG or VRML97 or other (via plugin) file
136 osg::Node *loadFile(const char *file, coTUIFileBrowserButton *fb = NULL, osg::Group *parent = NULL, const char *covise_key = "");
137
138 // replace the last loaded Performer or VRML97 file
139 osg::Node *replaceFile(const char *file, coTUIFileBrowserButton *fb = NULL, osg::Group *parent = NULL, const char *covise_key = "");
140
141 // reload the previously loaded /*VRML*/ file
143
144 // unload the previously loaded file
145 void unloadFile(const char *file=NULL);
146
147 // set name of a file to store Viewpoints; if unset, this is derived from the loaded FileName
148 void setViewPointFile(const std::string &viewPointFile);
149
150 // getName of a file to store Viewpoints
151 // this is derived from the loaded FileName
152 std::string getViewPointFile();
153
154 // load an icon file, looks in covise/icons/$LookAndFeel or covise/icons
155 // returns NULL, if nothing found
156 osg::Node *loadIcon(const char *filename);
157
158 // loads a font
159 // fontname can be NULL, which loads the default specified in the config (DroidSansFallbackFull.ttf if not in config), or "myfont.ttf"
160 std::string getFontFile(const char *fontname);
161 osg::ref_ptr<osgText::Font> loadFont(const char *fontname);
162
163 // load an texture, looks in covise/icons/$LookAndFeel or covise/icons for filename.rgb
164 // returns NULL, if nothing found
165 osg::Texture2D *loadTexture(const char *texture);
166
167 // tries to fopen() fileName
168 // returns true if exists otherwise false
169 bool fileExist(const char *fileName);
170 bool fileExist(const std::string& fileName);
171 // builds filename for icon files, looks in covise/icons/$LookAndFeel or covise/icons for filename.rgb
172 const char *buildFileName(const char *);
173
174 // register a loader, ... for a file type
175 int registerFileHandler(const FileHandler *handler);
177
178 // unregister a loader, ... for a file type
181
182 // get list of extensions as required by a filebrowser
183 std::string getFilterList();
184
185 // get list of extensions for saving as required by a filebrowser
186 std::string getWriteFilterList();
187
188 // get a loader for a file type, if available
189 const FileHandler *getFileHandler(const char *extension);
190 coVRIOReader *findIOHandler(const char *extension);
191
192 // find a loader, load plugin if no loader available
193 const FileHandler *findFileHandler(const char *extension);
194
196
198
200
201 virtual bool update();
202 //send a requested File to vrb
203 void sendFile(covise::TokenBuffer &tb);
204
206 std::string remoteFetch(const std::string &filePath, int fileOwner = -1);
208 int getFileId(const char* url);
209
211 std::string getFileName(const std::string& filePath);
212
213private:
214 // Get the configured font style.
215 int coLoadFontDefaultStyle();
216 //set in 'config/system/vrb/RemoteFetch value = "on" to enable remote fetch in local usr tmp directory.
217 bool remoteFetchEnabled = false;
218 //set in 'config/system/vrb/RemoteFetch path="your path" to chose a differen directory to remote Fetch to.
219 std::string remoteFetchPath;
220 std::string viewPointFile;
221 int m_loadCount = 0;
222 std::unique_ptr<ui::Owner> m_owner;
223 ui::Group *m_fileGroup = nullptr;
224 int uniqueNumber = 0;
225
226 typedef std::list<const FileHandler *> FileHandlerList;
227 FileHandlerList fileHandlerList;
228
229 typedef std::list<coVRIOReader *> IOReaderList;
230 IOReaderList ioReaderList;
231
232 typedef std::map<std::string, osg::ref_ptr<osg::Texture2D> > TextureMap;
233 TextureMap textureList;
234 std::map<std::string, coTUIFileBrowserButton *> fileFBMap;
235 coTUIFileBrowserButton *mDefaultFB = nullptr;
236
237 struct IOReadOperation
238 {
239 IOReadOperation()
240 {
241 reader = 0;
242 filename = "";
243 group = 0;
244 }
245 coVRIOReader *reader;
246 std::string filename;
247 osg::Group *group;
248 };
249
250 typedef std::map<std::string, std::list<IOReadOperation> > ReadOperations;
251 ReadOperations readOperations;
252
253 coVRFileManager();
254 LoadedFile *m_lastFile = nullptr;
255 LoadedFile *m_loadingFile = nullptr;
256 std::map<std::string, LoadedFile *> m_files;
257 typedef std::pair<std::string, int> fileOwner;
259 typedef std::vector<fileOwner> fileOwnerList;
261 void loadPartnerFiles();
262 struct Compare {
263 bool operator()(const std::string& first, const std::string& second) {
264 return first.size() > second.size();
265 }
266 };
269 void getSharedDataPath();
270 std::string m_sharedDataLink;
272 void convertBackslash(std::string &path);
274 std::string cutFileName(const std::string & filePath);
276 std::string reduceToAlphanumeric(const std::string & str);
277
279 std::string writeFile(const std::string& fileName, const char* content, int size);
281 int guessFileOwner(const std::string& filePath);
282 bool serializeFile(const std::string& fileName, covise::TokenBuffer& tb);
283 std::vector<covise::Message*> m_sendFileMessages;
284
285 //utility
286 public:
288 static std::string cutStringAt(const std::string &s, char delimiter);
290 static std::string resolveEnvs(const std::string& s);
291 osg::ref_ptr<osgDB::ReaderWriter::Options> options;
292};
293}
294#endif
Definition: ARToolKit.h:33
Definition: coClusterStat.h:29
Definition: coTabletUI.h:51
Definition: coVRFileManager.h:44
Definition: coTabletUI.h:277
Definition: coVRFileManager.h:67
static Url fromFileOrUrl(const std::string &furl)
const std::string & query() const
const std::string & scheme() const
const std::string & path() const
bool valid() const
static std::string decode(const std::string &str, bool path=false)
std::string str() const
std::string extension() const
Url(const std::string &url)
const std::string & fragment() const
bool isLocal() const
const std::string & authority() const
Definition: coVRFileManager.h:105
const char * extension
Definition: coVRFileManager.h:109
Definition: coVRFileManager.h:115
const FileHandler * getFileHandler(const char *extension)
coTUIFileBrowserButton * getMatchingFileBrowserInstance(std::string keyFileName)
void sendFile(covise::TokenBuffer &tb)
int registerFileHandler(const FileHandler *handler)
bool makeRelativeToSharedDataLink(std::string &fileName)
coVRIOReader * findIOHandler(const char *extension)
std::string getFontFile(const char *fontname)
std::string findFileExt(const Url &url)
std::string getWriteFilterList()
const FileHandler * findFileHandler(const char *extension)
osg::ref_ptr< osgText::Font > loadFont(const char *fontname)
static coVRFileManager * instance()
void setViewPointFile(const std::string &viewPointFile)
osg::Node * loadIcon(const char *filename)
std::string getViewPointFile()
bool isInTmpDir(const std::string &fileName)
int getFileId(const char *url)
compares the url with m_sharedFiles. If found returns its position in, else -1;
osg::Texture2D * loadTexture(const char *texture)
osg::Node * loadFile(const char *file, coTUIFileBrowserButton *fb=NULL, osg::Group *parent=NULL, const char *covise_key="")
std::string remoteFetch(const std::string &filePath, int fileOwner=-1)
request the file from vrb -> file gets copied to tmp
int unregisterFileHandler(const FileHandler *handler)
std::string findOrGetFile(const std::string &fileName, bool *isTmp=(bool *) false)
osg::ref_ptr< osgDB::ReaderWriter::Options > options
Definition: coVRFileManager.h:291
int registerFileHandler(coVRIOReader *handler)
static std::string cutStringAt(const std::string &s, char delimiter)
return the substring of s until the delimiter(delimiter is cut off)
bool fileExist(const std::string &fileName)
const char * getName(const char *file)
osg::Node * replaceFile(const char *file, coTUIFileBrowserButton *fb=NULL, osg::Group *parent=NULL, const char *covise_key="")
const char * buildFileName(const char *)
void unloadFile(const char *file=NULL)
bool makeRelativePath(std::string &fileName, const std::string &basePath)
std::string getFileName(const std::string &filePath)
get the filename + extension from a path: path/fileName -> fileName
int unregisterFileHandler(coVRIOReader *handler)
static std::string resolveEnvs(const std::string &s)
replaces all occurences of environmentvariables (env$ on win or $env/ on unix) with the first entry (...
void SetDefaultFB(coTUIFileBrowserButton *fb)
bool fileExist(const char *fileName)
Definition: coVRIOReader.h:21
objects that are derived from this class are called once per frame
Definition: coUpdateManager.h:20