Ejemplo n.º 1
0
void AssemblyCollectionItem::slot_create()
{
    const string assembly_name =
        get_entity_name_dialog(
            treeWidget(),
            "Create Assembly",
            "Assembly Name:",
            make_unique_name("assembly", m_parent.assemblies()));

    // todo: schedule creation of assembly when rendering.
    if (!assembly_name.empty())
    {
        auto_release_ptr<Assembly> assembly(
            AssemblyFactory().create(assembly_name.c_str(), ParamArray()));

        AssemblyItem* assembly_item =
            static_cast<AssemblyItem*>(m_parent_item->add_item(assembly.get()));

        m_parent.assemblies().insert(assembly);

        const string assembly_instance_name =
            make_unique_name(
                assembly_name + "_inst",
                m_parent.assembly_instances());

        assembly_item->instantiate(assembly_instance_name);

        m_editor_context.m_project_builder.slot_notify_project_modification();
    }
}
void MaterialCollectionItem::do_create_material(const char* model)
{
    typedef EntityTraits<Material> EntityTraits;

    const string window_title =
        string("Create ") +
        EntityTraits::get_human_readable_entity_type_name();

    const string name_suggestion =
        make_unique_name(
            EntityTraits::get_entity_type_name(),
            EntityTraits::get_entity_container(Base::m_parent));

    typedef EntityTraits::FactoryRegistrarType FactoryRegistrarType;

    auto_ptr<EntityEditor::IFormFactory> form_factory(
        new FixedModelEntityEditorFormFactory<FactoryRegistrarType>(
            m_editor_context.m_project_builder.get_factory_registrar<Material>(),
            name_suggestion,
            model));

    auto_ptr<EntityEditor::IEntityBrowser> entity_browser(
        new EntityBrowser<Assembly>(Base::m_parent));

    auto_ptr<CustomEntityUI> custom_entity_ui;

#ifdef APPLESEED_WITH_DISNEY_MATERIAL
    if (strcmp(model, "disney_material") == 0)
    {
        custom_entity_ui.reset(
            new DisneyMaterialCustomUI(
                m_editor_context.m_project,
                m_editor_context.m_settings));
    }
#endif

    open_entity_editor(
        QTreeWidgetItem::treeWidget(),
        window_title,
        m_editor_context.m_project,
        form_factory,
        entity_browser,
        custom_entity_ui,
        Dictionary(),
        this,
        SLOT(slot_create_applied(foundation::Dictionary)),
        SLOT(slot_create_accepted(foundation::Dictionary)),
        SLOT(slot_create_canceled(foundation::Dictionary)));
}
Ejemplo n.º 3
0
void AssemblyItem::slot_instantiate()
{
    const string instance_name_suggestion =
        make_unique_name(
            string(m_assembly.get_name()) + "_inst",
            m_parent.assembly_instances());

    const string instance_name =
        get_entity_name_dialog(
            treeWidget(),
            "Instantiate Assembly",
            "Assembly Instance Name:",
            instance_name_suggestion);

    if (!instance_name.empty())
        instantiate(instance_name);
}
Ejemplo n.º 4
0
void ObjectItem::slot_instantiate()
{
    const string instance_name_suggestion =
        make_unique_name(
            string(m_entity->get_name()) + "_inst",
            m_parent.object_instances());

    const string instance_name =
        get_entity_name_dialog(
            treeWidget(),
            "Instantiate Object",
            "Object Instance Name:",
            instance_name_suggestion);

    if (!instance_name.empty())
    {
        if (m_project_builder.get_rendering_manager().is_rendering())
            schedule_instantiate(instance_name);
        else
            do_instantiate(instance_name);
    }
}
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
}
Ejemplo n.º 6
0
bool
p11_save_finish_file (p11_save_file *file,
                      char **path_out,
                      bool commit)
{
	bool ret = true;
	char *path;

	if (!file)
		return false;

	if (!commit) {
		close (file->fd);
		unlink (file->temp);
		filo_free (file);
		return true;
	}

	if (asprintf (&path, "%s%s", file->bare, file->extension) < 0)
		return_val_if_reached (false);

	if (close (file->fd) < 0) {
		p11_message_err (errno, "couldn't write file: %s", file->temp);
		ret = false;

#ifdef OS_UNIX
	/* Set the mode of the file, readable by everyone, but not writable */
	} else if (chmod (file->temp, S_IRUSR | S_IRGRP | S_IROTH) < 0) {
		p11_message_err (errno, "couldn't set file permissions: %s", file->temp);
		ret = false;

	/* Atomically rename the tempfile over the filename */
	} else if (file->flags & P11_SAVE_OVERWRITE) {
		if (rename (file->temp, path) < 0) {
			p11_message_err (errno, "couldn't complete writing file: %s", path);
			ret = false;
		} else {
			unlink (file->temp);
		}

	/* Create a unique name if requested unique file name */
	} else if (file->flags & P11_SAVE_UNIQUE) {
		free (path);
		path = make_unique_name (file->bare, file->extension,
		                         on_unique_try_link, file);
		if (!path)
			ret = false;
		unlink (file->temp);

	/* When not overwriting, link will fail if filename exists. */
	} else {
		if (link (file->temp, path) < 0) {
			p11_message_err (errno, "couldn't complete writing of file: %s", path);
			ret = false;
		}
		unlink (file->temp);

#else /* OS_WIN32 */

	/* Windows does not do atomic renames, so delete original file first */
	} else {
		/* Create a unique name if requested unique file name */
		if (file->flags & P11_SAVE_UNIQUE) {
Ejemplo n.º 7
0
	/* When not overwriting, link will fail if filename exists. */
	} else {
		if (link (file->temp, path) < 0) {
			p11_message_err (errno, "couldn't complete writing of file: %s", path);
			ret = false;
		}
		unlink (file->temp);

#else /* OS_WIN32 */

	/* Windows does not do atomic renames, so delete original file first */
	} else {
		/* Create a unique name if requested unique file name */
		if (file->flags & P11_SAVE_UNIQUE) {
			free (path);
			path = make_unique_name (file->bare, file->extension,
			                         on_unique_try_rename, file);
			if (!path)
				ret = false;

		} else if ((file->flags & P11_SAVE_OVERWRITE) &&
			    unlink (path) < 0 && errno != ENOENT) {
			p11_message_err (errno, "couldn't remove original file: %s", path);
			ret = false;
		}

		if (ret == true &&
		    rename (file->temp, path) < 0) {
			p11_message_err (errno, "couldn't complete writing file: %s", path);
			ret = false;
		}