neuray API Programmer's Manual

mdl_argument_editor.h File Reference

Description

Utility class for MDL material instances and function calls.

Code Example

mdl_argument_editor.h

‎//*****************************************************************************
// Copyright 1986, 2016 NVIDIA Corporation. All rights reserved.
//*****************************************************************************
//*****************************************************************************

#ifndef MI_NEURAYLIB_MDL_ARGUMENT_EDITOR_H
#define MI_NEURAYLIB_MDL_ARGUMENT_EDITOR_H

#include <mi/base/handle.h>
#include <mi/neuraylib/assert.h>
#include <mi/neuraylib/iarray.h>
#include <mi/neuraylib/iattachable.h>
#include <mi/neuraylib/idynamic_array.h>
#include <mi/neuraylib/ifactory.h>
#include <mi/neuraylib/imdl_function_call.h>
#include <mi/neuraylib/imdl_material_instance.h>
#include <mi/neuraylib/itransaction.h>
#include <mi/neuraylib/set_get.h>
#include <mi/neuraylib/version.h>

#include <string>

namespace mi {

namespace neuraylib {




















class Mdl_argument_editor
{
public:



    Mdl_argument_editor(
        ITransaction* transaction, const char* name, IFactory* factory);

    bool is_valid() const;
    
    Element_type 
               get_type() const;

    const char* get_name() const;

    const char* get_definition() const;

    Uint32 
               get_parameter_count() const;

    const char* get_parameter_name( Uint32 index) const;

    Sint32 
               get_parameter_index( const char* name) const;

    const char* get_parameter_type( Uint32 index) const;

    const char* get_parameter_type( const char* name) const;

    bool is_parameter_type_uniform( Uint32 index) const;

    bool is_parameter_type_uniform( const char* name) const;

    const char* get_argument_type( Uint32 index) const;

    const char* get_argument_type( const char* name) const;

    const char* get_return_type() const;

    bool is_return_type_varying() const;




    template <class T>
    Sint32 
               get_value( Uint32 argument_index, T& value) const;

    template <class T>
    Sint32 
               get_value( const char* argument_name, T& value) const;

    template <class T>
    Sint32 
               get_value( Uint32 argument_index, Size array_index, T& value) const;

    template <class T>
    Sint32 
               get_value( const char* argument_name, Size array_index, T& value) const;

    template <class T>
    Sint32 
               set_value( Uint32 argument_index, const T& value);

    template <class T>
    Sint32 
               set_value( const char* argument_name, const T& value);

    template <class T>
    Sint32 
               set_value( Uint32 argument_index, Size array_index, const T& value);

    template <class T>
    Sint32 
               set_value( const char* argument_name, Size array_index, const T& value);




    bool has_attachment( Uint32 argument_index) const;

    bool has_attachment( const char* argument_name) const;

    bool has_attachment( Uint32 argument_index, Size array_index) const;

    bool has_attachment( const char* argument_name, Size array_index) const;
    
    const char* get_attachment( Uint32 argument_index) const;

    const char* get_attachment( const char* argument_name) const;

    const char* get_attachment( Uint32 argument_index, Size array_index) const;

    const char* get_attachment( const char* argument_name, Size array_index) const;

    Sint32 
               set_attachment( Uint32 argument_index, const char* attachment_name);

    Sint32 
               set_attachment( const char* argument_name, const char* attachment_name);

    Sint32 
               set_attachment(
        Uint32 argument_index, Size array_index, const char* attachment_name);

    Sint32 
               set_attachment(
        const char* argument_name, Size array_index, const char* attachment_name);

    Sint32 
               remove_attachment( Uint32 argument_index);

    Sint32 
               remove_attachment( const char* argument_name);

    Sint32 
               remove_attachment( Uint32 argument_index, Size array_index);

    Sint32 
               remove_attachment( const char* argument_name, Size array_index);




    Sint32 
               get_array_length( Uint32 argument_index, Size& size) const;

    Sint32 
               get_array_length( const char* argument_name, Size& size) const;

    Sint32 
               set_array_length( Uint32 argument_index, Size size);

    Sint32 
               set_array_length( const char* argument_name, Size size);


private:
    void promote_to_edit_if_needed();

    base::Handle< neuraylib::ITransaction> m_transaction;
    base::Handle< neuraylib::IFactory> m_factory;
    base::Handle< const IScene_element> m_access;
    base::Handle< const IScene_element> m_old_access;
    base::Handle< IScene_element> m_edit;
    Element_type m_type;
    MISTD::string m_name;
};
 // end group mi_neuray_materials

inline Mdl_argument_editor::Mdl_argument_editor(
    ITransaction* transaction, const char* name, IFactory* factory)
{
    mi_neuray_assert( transaction);
    mi_neuray_assert( name);

    m_transaction = make_handle_dup( transaction);
    m_name = name;
    m_factory = make_handle_dup( factory);
    m_access = transaction->access<IScene_element>( name);
    m_type = m_access.is_valid_interface()
        ? m_access->get_element_type() : static_cast<Element_type>( 0);
}

inline bool Mdl_argument_editor::is_valid() const
{
    return m_access.is_valid_interface()
        && (m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE
        ||  m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL);
}

inline Element_type 
               Mdl_argument_editor::get_type() const
{
    return m_type;
}

inline const char* Mdl_argument_editor::get_name() const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_name();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_name();

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_definition() const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_material_definition();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_function_definition();

    } else
        return 0;
}

inline Uint32 
               Mdl_argument_editor::get_parameter_count() const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_parameter_count();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_parameter_count();

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_parameter_name( Uint32 index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_parameter_name( index);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_parameter_name( index);

    } else
        return 0;
}

inline Sint32 
               Mdl_argument_editor::get_parameter_index( const char* name) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_parameter_index( name);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_parameter_index( name);

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_parameter_type( Uint32 index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_parameter_type( index);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_parameter_type( index);

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_parameter_type( const char* name) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_parameter_type( name);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_parameter_type( name);

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_argument_type( Uint32 index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_argument_type( index);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_argument_type( index);

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_argument_type( const char* name) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->get_argument_type( name);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_argument_type( name);

    } else
        return 0;
}

inline bool Mdl_argument_editor::is_parameter_type_uniform( Uint32 index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->is_parameter_type_uniform( index);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->is_parameter_type_uniform( index);

    } else
        return false;
}

inline bool Mdl_argument_editor::is_parameter_type_uniform( const char* name) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        return mi->is_parameter_type_uniform( name);

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->is_parameter_type_uniform( name);

    } else
        return false;
}

inline const char* Mdl_argument_editor::get_return_type() const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        return 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->get_return_type();

    } else
        return 0;
}

inline bool Mdl_argument_editor::is_return_type_varying() const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        return 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        return fc->is_return_type_varying();

    } else
        return false;
}
























template <class T>
Sint32 
               Mdl_argument_editor::get_value( Uint32 argument_index, T& value) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IData> data( argument->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IData> data( argument->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::get_value( const char* argument_name, T& value) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IData> data( argument->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IData> data( argument->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::get_value( Uint32 argument_index, Size array_index, T& value) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< const IData> data( element->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< const IData> data( element->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::get_value( const char* argument_name, Size array_index, T& value) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< const IData> data( element->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< const IData> data( element->get_value());
        Sint32 result = mi::get_value( data.get(), value);
        return result == 0 ? 0 : -3;

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::set_value( Uint32 argument_index, const T& value)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IData> data( clone->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return mi->set_argument( argument_index, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IData> data( clone->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return fc->set_argument( argument_index, clone.get());

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::set_value( const char* argument_name, const T& value)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IData> data( clone->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return mi->set_argument( argument_name, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IData> data( clone->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return fc->set_argument( argument_name, clone.get());

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::set_value( Uint32 argument_index, Size array_index, const T& value)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< IData> data( element->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return mi->set_argument( argument_index, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< IData> data( element->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return fc->set_argument( argument_index, clone.get());

    } else
        return -1;
}

template <class T>
Sint32 
               Mdl_argument_editor::set_value( const char* argument_name, Size array_index, const T& value)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< IData> data( element->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return mi->set_argument( argument_name, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        base::Handle< IData> data( element->get_value());
        if( mi::set_value( data.get(), value) != 0)
            return -3;
        return fc->set_argument( argument_name, clone.get());

    } else
        return -1;
}

inline bool Mdl_argument_editor::has_attachment( Uint32 argument_index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return false;
        return argument->get_reference_name() != 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return false;
        return argument->get_reference_name() != 0;

    } else
        return false;
}

inline bool Mdl_argument_editor::has_attachment( const char* argument_name) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return false;
        return argument->get_reference_name() != 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return false;
        return argument->get_reference_name() != 0;

    } else
        return false;
}

inline bool Mdl_argument_editor::has_attachment( Uint32 argument_index, Size array_index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return false;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return false;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return false;
        return element->get_reference_name() != 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return false;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return false;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return false;
        return element->get_reference_name() != 0;

    } else
        return false;
}

inline bool Mdl_argument_editor::has_attachment( const char* argument_name, Size array_index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return false;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return false;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return false;
        return element->get_reference_name() != 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return false;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return false;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return false;
        return element->get_reference_name() != 0;

    } else
        return false;
}

inline const char* Mdl_argument_editor::get_attachment( Uint32 argument_index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return 0;
        return argument->get_reference_name();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return 0;
        return argument->get_reference_name();

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_attachment( const char* argument_name) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return 0;
        return argument->get_reference_name();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return 0;
        return argument->get_reference_name();

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_attachment(
    Uint32 argument_index, Size array_index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return 0;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return 0;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return 0;
        return element->get_reference_name();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return 0;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return 0;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return 0;
        return element->get_reference_name();

    } else
        return 0;
}

inline const char* Mdl_argument_editor::get_attachment(
    const char* argument_name, Size array_index) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return 0;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return 0;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return 0;
        return element->get_reference_name();

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return 0;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return 0;
        base::Handle< const IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return 0;
        return element->get_reference_name();

    } else
        return 0;
}

inline Sint32 
               Mdl_argument_editor::set_attachment(
    Uint32 argument_index, const char* attachment_name)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        if( clone->set_reference( attachment_name) != 0)
            return -3;
        return mi->set_argument( argument_index, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        if( clone->set_reference( attachment_name) != 0)
            return -3;
        return fc->set_argument( argument_index, clone.get());

    } else
        return -1;
}

inline Sint32 
               Mdl_argument_editor::set_attachment(
    const char* argument_name, const char* attachment_name)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        if( clone->set_reference( attachment_name) != 0)
            return -3;
        return mi->set_argument( argument_name, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        if( clone->set_reference( attachment_name) != 0)
            return -3;
        return fc->set_argument( argument_name, clone.get());

    } else
        return -1;
}

inline Sint32  
               Mdl_argument_editor::set_attachment(
    Uint32 argument_index, Size array_index, const char* attachment_index)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        if( element->set_reference( attachment_index) != 0)
            return -3;
        return mi->set_argument( argument_index, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        if( element->set_reference( attachment_index) != 0)
            return -3;
        return fc->set_argument( argument_index, clone.get());

    } else
        return -1;
}

inline Sint32  
               Mdl_argument_editor::set_attachment(
    const char* argument_name, Size array_index, const char* attachment_name)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        if( element->set_reference( attachment_name) != 0)
            return -3;
        return mi->set_argument( argument_name, clone.get());

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IArray> array( clone->get_value<IArray>());
        if( !array.is_valid_interface())
            return -2;
        base::Handle< IAttachable> element( array->get_element<IAttachable>( array_index));
        if( !element.is_valid_interface())
            return -2;
        if( element->set_reference( attachment_name) != 0)
            return -3;
        return fc->set_argument( argument_name, clone.get());

    } else
        return -1;
}

inline Sint32 
               Mdl_argument_editor::remove_attachment( Uint32 argument_index)
{
    return set_attachment( argument_index, 0);
}

inline Sint32 
               Mdl_argument_editor::remove_attachment( const char* argument_name)
{
    return set_attachment( argument_name, 0);
}

inline Sint32 
               Mdl_argument_editor::remove_attachment( Uint32 argument_index, Size array_index)
{
    return set_attachment( argument_index, array_index, 0);
}

inline Sint32 
               Mdl_argument_editor::remove_attachment( const char* argument_name, Size array_index)
{
    return set_attachment( argument_name, array_index, 0);
}

inline Sint32 
               Mdl_argument_editor::get_array_length( Uint32 argument_index, Size& size) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -4;
        size = array->get_length();
        return 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -4;
        size = array->get_length();
        return 0;

    } else
        return -1;
}

inline Sint32 
               Mdl_argument_editor::get_array_length( const char* argument_name, Size& size) const
{
    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< const IMdl_material_instance> mi(
            m_access->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -4;
        size = array->get_length();
        return 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< const IMdl_function_call> fc(
            m_access->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< const IArray> array( argument->get_value<IArray>());
        if( !array.is_valid_interface())
            return -4;
        size = array->get_length();
        return 0;

    } else
        return -1;
}

inline Sint32 
               Mdl_argument_editor::set_array_length( Uint32 argument_index, Size size)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
        if( !dynamic_array.is_valid_interface())
            return -4;
        dynamic_array->set_length( size);
        mi->set_argument( argument_index, clone.get());
        return 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_index));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
        if( !dynamic_array.is_valid_interface())
            return -4;
        dynamic_array->set_length( size);
        fc->set_argument( argument_index, clone.get());
        return 0;

    } else
        return -1;
}

inline Sint32 
               Mdl_argument_editor::set_array_length( const char* argument_name, Size size)
{
    promote_to_edit_if_needed();

    if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {

        base::Handle< IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
        base::Handle< const IAttachable> argument( mi->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
        if( !dynamic_array.is_valid_interface())
            return -4;
        dynamic_array->set_length( size);
        mi->set_argument( argument_name, clone.get());
        return 0;

    } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {

        base::Handle< IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
        base::Handle< const IAttachable> argument( fc->get_argument( argument_name));
        if( !argument.is_valid_interface())
            return -2;
        base::Handle< IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
        base::Handle< IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
        if( !dynamic_array.is_valid_interface())
            return -4;
        dynamic_array->set_length( size);
        fc->set_argument( argument_name, clone.get());
        return 0;

    } else
        return -1;
}

inline void Mdl_argument_editor::promote_to_edit_if_needed()
{
    if( m_edit.is_valid_interface())
        return;
    m_edit = m_transaction->edit<IScene_element>( m_name.c_str());
    mi_neuray_assert( m_edit.is_valid_interface());
    m_old_access = m_access;
    m_access = m_edit;
}

} // namespace neuraylib

#ifdef MI_NEURAYLIB_DEPRECATED_NAMESPACE_MI_TRANSITION
using neuraylib::ELEMENT_TYPE_MDL_FUNCTION_CALL;
using neuraylib::ELEMENT_TYPE_MDL_MATERIAL_INSTANCE;
using neuraylib::Element_type;
using neuraylib::IMdl_function_call;
using neuraylib::IMdl_material_instance;
using neuraylib::IScene_element;
using neuraylib::Mdl_argument_editor;
#endif // MI_NEURAYLIB_DEPRECATED_NAMESPACE_MI_TRANSITION

} // namespace mi

#endif // MI_NEURAYLIB_MDL_ARGUMENT_EDITOR_H

Namespaces

namespace 
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH. More...
namespace 
Namespace for the neuray API. More...

Classes

class 
A wrapper around the interfaces for MDL material instances and function calls. More...