#include "FGCanvasSystemAdapter.hxx"
#include <Main/globals.hxx>
-#include <Scripting/NasalSys.hxx>
+#include <Main/util.hxx>
+#include <Network/HTTPClient.hxx>
#include <Viewer/renderer.hxx>
#include <osgDB/ReadFile>
//----------------------------------------------------------------------------
void FGCanvasSystemAdapter::removeCamera(osg::Camera* camera) const
{
- globals->get_renderer()->removeCamera(camera);
+ if( globals->get_renderer() )
+ globals->get_renderer()->removeCamera(camera);
}
//----------------------------------------------------------------------------
- osg::Image* FGCanvasSystemAdapter::getImage(const std::string& path) const
+ osg::ref_ptr<osg::Image> FGCanvasSystemAdapter::getImage(const std::string& path) const
{
- SGPath tpath = globals->resolve_resource_path(path);
- if( tpath.isNull() || !tpath.exists() )
+ if( SGPath(path).isAbsolute() )
{
- SG_LOG(SG_GL, SG_ALERT, "canvas::Image: No such image: " << path);
- return 0;
- }
-
- return osgDB::readImageFile(tpath.c_str());
- }
+ std::string valid_path = fgValidatePath(path, false);
+ if( !valid_path.empty() )
+ return osgDB::readImageFile(valid_path.c_str());
- /**
- * Get current FGNasalSys instance.
- */
- static FGNasalSys* getNasalSys()
- {
- static FGNasalSys* nasal_sys = 0;
- // TODO if Nasal is able to be removed and/or recreated at runtime we need
- // to ensure that always the current instance is used
- if( !nasal_sys )
+ SG_LOG(SG_IO, SG_ALERT, "canvas::Image: reading '" << path << "' denied");
+ }
+ else
{
- nasal_sys = dynamic_cast<FGNasalSys*>(globals->get_subsystem("nasal"));
- if( !nasal_sys )
- throw std::runtime_error("FGCanvasSystemAdapter: no NasalSys");
+ SGPath tpath = globals->resolve_resource_path(path);
+ if( !tpath.isNull() )
+ return osgDB::readRefImageFile(tpath.c_str());
+
+ SG_LOG(SG_IO, SG_ALERT, "canvas::Image: No such image: '" << path << "'");
}
- return nasal_sys;
+ return 0;
}
//----------------------------------------------------------------------------
- naContext FGCanvasSystemAdapter::getNasalContext() const
+ SGSubsystem*
+ FGCanvasSystemAdapter::getSubsystem(const std::string& name) const
{
- return getNasalSys()->context();
+ return globals->get_subsystem(name.c_str());
}
//----------------------------------------------------------------------------
- int FGCanvasSystemAdapter::gcSave(naRef r)
+ simgear::HTTP::Client* FGCanvasSystemAdapter::getHTTPClient() const
{
- return getNasalSys()->gcSave(r);
- }
+ FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
- //----------------------------------------------------------------------------
- void FGCanvasSystemAdapter::gcRelease(int key)
- {
- getNasalSys()->gcRelease(key);
- }
+ if( http )
+ return http->client();
- //------------------------------------------------------------------------------
- naRef FGCanvasSystemAdapter::callMethod( naRef code,
- naRef self,
- int argc,
- naRef* args,
- naRef locals )
- {
- return getNasalSys()->callMethod(code, self, argc, args, locals);
+ SG_LOG( SG_IO,
+ SG_ALERT,
+ "FGCanvasSystemAdapter: Failed to get HTTP subsystem" );
+ return 0;
}
}