void PicoModelLoader::initialiseModule(const ApplicationContext& ctx)
{
	rMessage() << "PicoModelLoader: " << getName() << " initialised." << std::endl;

	std::string extLower = boost::to_lower_copy(_extension);
	std::string filter("*." + extLower);

	// Register the model file extension in the FileTypRegistry
	GlobalFiletypes().registerPattern("model", FileTypePattern(_module->displayName, extLower, filter));
	GlobalFiletypes().registerModule("model", extLower, getName());
}
示例#2
0
void MD5ModelLoader::initialiseModule(const ApplicationContext& ctx)
{
	rMessage() << "MD5Model::initialiseModule called." << std::endl;

	std::string extLower = "md5mesh";
	std::string filter = "*." + extLower;

	// Register the model file extension in the FileTypRegistry
	GlobalFiletypes().registerPattern("model", FileTypePattern("MD5 Meshes", extLower, filter));
	GlobalFiletypes().registerModule("model", extLower, getName());
}
void Doom3PrefabFormat::initialiseModule(const ApplicationContext& ctx)
{
	rMessage() << getName() << ": initialiseModule called." << std::endl;

	// Register ourselves as map format
	GlobalMapFormatManager().registerMapFormat("pfb", shared_from_this());

	// Register the prefab file extension for the "map" filetype
	GlobalFiletypes().registerPattern("map", FileTypePattern(_("Doom 3 prefab"), "pfb", "*.pfb"));

	// Register the prefab file extensions for the "prefab" filetype
	GlobalFiletypes().registerPattern("prefab", FileTypePattern(_("Doom 3 prefab"), "pfb", "*.pfb"));
	GlobalFiletypes().registerPattern("prefab", FileTypePattern(_("Doom 3 map"), "map", "*.map"));
	GlobalFiletypes().registerPattern("prefab", FileTypePattern(_("Doom 3 region"), "reg", "*.reg"));
}
示例#4
0
NodeSmartReference Model_load(ModelLoader* loader, const char* path, const char* name, const char* type)
{
  if(loader != 0)
  {
    return ModelResource_load(loader, name);
  }
  else
  {
    const char* moduleName = findModuleName(&GlobalFiletypes(), MapFormat::Name(), type);
    if(string_not_empty(moduleName))
    {
      const MapFormat* format = ReferenceAPI_getMapModules().findModule(moduleName);
      if(format != 0)
      {
        return MapResource_load(*format, path, name);
      }
      else
      {
        globalErrorStream() << "ERROR: Map type incorrectly registered: \"" << moduleName << "\"\n";
        return g_nullModel;
      }
    }
    else
    {
      if(string_not_empty(type))
      {
        globalErrorStream() << "Model type not supported: \"" << name << "\"\n";
      }
      return g_nullModel;
    }
  }
}
示例#5
0
void PicoModelLoader::initialiseModule(const ApplicationContext& ctx) {
	globalOutputStream() << "PicoModelLoader: " << getName().c_str() << " initialised.\n"; 
	std::string filter("*." + boost::to_lower_copy(_extension));
	
	// Register the model file extension in the FileTypRegistry
	GlobalFiletypes().addType(
		"model", getName(), 
    	FileTypePattern(_module->displayName, filter.c_str())
    );
}
示例#6
0
/**
 * @brief Returns the model loader for the model \p type or 0 if the model \p type has no loader module
 */
ModelLoader* ModelLoader_forType (const std::string& type)
{
    const std::string moduleName = findModuleName(&GlobalFiletypes(), std::string(ModelLoader::Name()), type);
    if (!moduleName.empty()) {
        ModelLoader* table = ReferenceAPI_getModelModules().findModule(moduleName);
        if (table != 0) {
            return table;
        } else {
            globalErrorStream() << "ERROR:  Model type incorrectly registered: " << moduleName << "\n";
            return &g_NullModelLoader;
        }
    }
    return 0;
}
示例#7
0
NodeSmartReference Model_load (ModelLoader* loader, const std::string& path, const std::string& name, const std::string& type)
{
    if (loader != 0) {
        return ModelResource_load(loader, name);
    } else {
        // Get a loader module name for this type, if possible. If none is
        // found, try again with the "map" type, since we might be loading a
        // map with a different extension
        std::string moduleName = findModuleName(&GlobalFiletypes(), MapFormat::Name(), type);

        // Empty, try again with "map" type
        if (moduleName.empty()) {
            moduleName = findModuleName(&GlobalFiletypes(), MapFormat::Name(), "map");
        }

        const MapFormat* format = ReferenceAPI_getMapModules().findModule(moduleName);
        if (format != 0) {
            return MapResource_load(*format, path, name);
        } else {
            globalErrorStream() << "ERROR: Map type incorrectly registered: " << moduleName << "\n";
            return g_nullModel;
        }
    }
}
示例#8
0
// Utility method to select a map file
std::string MapFileManager::selectFile(bool open,
	const std::string& title, const std::string& type, const std::string& defaultFile)
{
	// Check, if the lastdir contains at least anything and load
	// the default map path if it's empty
	if (_lastDirs.find(type) == _lastDirs.end())
	{
		// Default to the map path, if the type is not yet associated
		_lastDirs[type] = GlobalRegistry().get(RKEY_MAP_PATH);
	}

	// Get the first extension from the list of possible patterns (e.g. *.pfb or *.map)
	FileTypePatterns patterns = GlobalFiletypes().getPatternsForType(type);

	std::string defaultExt = "";

	if (!patterns.empty())
	{
		defaultExt = "." + patterns.begin()->extension; // ".map"
	}

	// Display a file chooser dialog to get a new path
	gtkutil::FileChooser fileChooser(GlobalMainFrame().getTopLevelWindow(),
		title, open, false, type, defaultExt);

	fileChooser.setCurrentFile(defaultFile);
	fileChooser.setCurrentPath(_lastDirs[type]);

	// For prefabs, add a preview widget
	if (open && type == "prefab")
	{
		// Instantiate a new preview object
		MapFileChooserPreviewPtr preview(new MapFileChooserPreview());

		// attach the preview object
		fileChooser.attachPreview(preview);
	}

	std::string filePath = fileChooser.display();

	// If a filename was chosen, update the last path
	if (!filePath.empty())
	{
		_lastDirs[type] = filePath.substr(0, filePath.rfind("/"));
	}

	return gtkutil::IConv::localeFromUTF8(filePath);
}
示例#9
0
/// \brief Returns the model loader for the model \p type or 0 if the model \p type has no loader module
ModelLoader* ModelLoader_forType(const char* type)
{
  const char* moduleName = findModuleName(&GlobalFiletypes(), ModelLoader::Name(), type);
  if(string_not_empty(moduleName))
  {
    ModelLoader* table = ReferenceAPI_getModelModules().findModule(moduleName);
    if(table != 0)
    {
      return table;
    }
    else
    {
      globalErrorStream() << "ERROR: Model type incorrectly registered: \"" << moduleName << "\"\n";
      return &g_NullModelLoader;
    }
  }
  return 0;
}
示例#10
0
ModelLoaderPtr ModelCache::getModelLoaderForType(const std::string& type)
{
	// Get the module name from the Filetype registry
	std::string moduleName = GlobalFiletypes().findModule("model", type);

	if (!moduleName.empty())
	{
		ModelLoaderPtr modelLoader = boost::static_pointer_cast<ModelLoader>(
			module::GlobalModuleRegistry().getModule(moduleName)
		);

		if (modelLoader != NULL) {
			return modelLoader;
		}
		else {
			rError()	<< "ERROR: Model type incorrectly registered: \""
				<< moduleName << "\"" << std::endl;
		}
	}

	return NullModelLoader::InstancePtr();
}
示例#11
0
// Look for a module which loads the given extension, by searching under the
// given type category
std::string RadiantFileTypeRegistry::findModuleName(
	const std::string& moduleType, const std::string& extension)
{
	// Convert the file extension to lowercase
	std::string ext = boost::algorithm::to_lower_copy(extension);
	
	// Get the list of types for the type category
	ModuleTypeListPtr list = GlobalFiletypes().getTypesFor(moduleType);
	
	// Search in the list for the given extension
	for (ModuleTypeList::const_iterator i = list->begin();
		 i != list->end();
		 ++i)
	{
		std::string patternExt = os::getExtension(i->filePattern.pattern);
		if (patternExt == ext) {
			// Match
			return i->moduleName;	
		}
	}
	
	// Not found, return empty string
	return "";
}
示例#12
0
const char* file_dialog_show(GtkWidget* parent, bool open, const char* title, const char* path, const char* pattern)
{
  filetype_t type;

  if(pattern == 0)
  {
    pattern = "*";
  }

  FileTypeList typelist;
  GlobalFiletypes().getTypeList(pattern, &typelist);

  GTKMasks masks(typelist);

  if (title == 0)
    title = open ? "Open File" : "Save File";
    
  GtkWidget* dialog;
  if (open)
  {
    dialog = gtk_file_chooser_dialog_new(title,
                                        GTK_WINDOW(parent),
                                        GTK_FILE_CHOOSER_ACTION_OPEN,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                                        NULL);
  }
  else
  {
    dialog = gtk_file_chooser_dialog_new(title,
                                        GTK_WINDOW(parent),
                                        GTK_FILE_CHOOSER_ACTION_SAVE,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                                        NULL);
    gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "unnamed");
  }

  gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
  gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);

  // we expect an actual path below, if the path is 0 we might crash
  if (path != 0 && !string_empty(path))
  {
    ASSERT_MESSAGE(path_is_absolute(path), "file_dialog_show: path not absolute: " << makeQuoted(path));

    Array<char> new_path(strlen(path)+1);

    // copy path, replacing dir separators as appropriate
    Array<char>::iterator w = new_path.begin();
    for(const char* r = path; *r != '\0'; ++r)
    {
      *w++ = (*r == '/') ? G_DIR_SEPARATOR : *r;
    }
    // remove separator from end of path if required
    if(*(w-1) == G_DIR_SEPARATOR)
    {
      --w;
    }
    // terminate string
    *w = '\0';

    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), new_path.data());
  }

  // we should add all important paths as shortcut folder...
  // gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), "/tmp/", NULL);

  
  for(std::size_t i = 0; i < masks.m_filters.size(); ++i)
  {
    GtkFileFilter* filter = gtk_file_filter_new();
    gtk_file_filter_add_pattern(filter, masks.m_filters[i].c_str());
    gtk_file_filter_set_name(filter, masks.m_masks[i].c_str());
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
  }

  if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
  {
    strcpy(g_file_dialog_file, gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));

    if(!string_equal(pattern, "*"))
    {
      GtkFileFilter* filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog));
      if(filter != 0) // no filter set? some file-chooser implementations may allow the user to set no filter, which we treat as 'all files'
      {
        type = masks.GetTypeForGTKMask(gtk_file_filter_get_name(filter)).m_type;
        // last ext separator
        const char* extension = path_get_extension(g_file_dialog_file);
        // no extension
        if(string_empty(extension))
        {
          strcat(g_file_dialog_file, type.pattern+1);
        }
        else
        {
          strcpy(g_file_dialog_file + (extension - g_file_dialog_file), type.pattern+2);
        }
      }
    }

    // convert back to unix format
    for(char* w = g_file_dialog_file; *w!='\0'; w++)
    {
      if(*w=='\\') 
      {
        *w = '/';
      }
    }
  }
  else
  {
    g_file_dialog_file[0] = '\0';
  }

  gtk_widget_destroy(dialog);

  // don't return an empty filename
  if(g_file_dialog_file[0] == '\0') return NULL;

  return g_file_dialog_file;
}