void PythonConsoleWidget::slot_open_file() { if (!can_close_file()) return; // todo: we shouldn't have to go through the Python interpreter to retrieve application settings. ParamArray& settings = PythonInterpreter::instance().get_main_window()->get_application_settings(); QString filepath = get_open_filename( this, "Open...", "Python Script File (*.py)", settings, SETTINGS_FILE_DIALOG_PYTHON_SCRIPTS); if (!filepath.isEmpty()) { filepath = QDir::toNativeSeparators(filepath); open_file(filepath.toStdString()); } }
void MaterialCollectionItem::slot_import_disney() { #ifdef APPLESEED_WITH_DISNEY_MATERIAL QString filepath = get_open_filename( 0, "Import...", "Disney Material (*.dmt);;All Files (*.*)", m_editor_context.m_settings, SETTINGS_FILE_DIALOG_PROJECTS); if (!filepath.isEmpty()) { filepath = QDir::toNativeSeparators(filepath); const bf::path root_path(Application::get_root_path()); const bf::path schema_file_path = root_path / "schemas" / "settings.xsd"; SettingsFileReader reader(global_logger()); ParamArray parameters; const bool success = reader.read( filepath.toStdString().c_str(), schema_file_path.string().c_str(), parameters); if (!success) { show_error_message_box( "Importing Error", "Failed to import the Disney Material file " + filepath.toStdString()); return; } string name = parameters.get("__name"); const string model = parameters.get("__model"); parameters.strings().remove("__name"); parameters.strings().remove("__model"); if (model != "disney_material") { show_error_message_box( "Importing Error", "Material model " + model + " is not supported."); return; } // If there is already a material with the same name, rename the imported material. for (const_each<MaterialContainer> i = m_parent.materials(); i; ++i) { if (strcmp(i->get_name(), name.c_str()) == 0) { name = make_unique_name(name, m_parent.materials()); break; } } auto_release_ptr<Material> material = DisneyMaterialFactory().create(name.c_str(), parameters); Material* material_ptr = material.get(); add_item(material_ptr); EntityTraits<Material>::insert_entity(material, m_parent); m_editor_context.m_project_builder.notify_project_modification(); m_editor_context.m_project_explorer.select_entity(material_ptr->get_uid()); } #endif }