// RcMaterialModifyExample.h : Declaration of the CRcMaterialModifyExample
/**
This example demonstrates using space3d material function set to work with materials. Example takes object path as parameter
(if '' specified first selected object is taken) and changes texture shader of first material into red color.
Example uses event recorder to handle undo/redo.

Use script command ExamplesPlugin.MaterialModifyExample() from command prompt to execute this example.

*/
#pragma once


//declare ID of a local command node connector. 
// {22D42037-A2E7-4d5b-BDEA-3E3375435EA1}
RS_DEFINE_GUID(CON_MME_SELECTION, 0x22d42037, 0xa2e7, 0x4d5b, 0xbd, 0xea, 0x3e, 0x33, 0x75, 0x43, 0x5e, 0xa1);

// IRcMaterialModifyExample
[
	object,
	uuid("7D1F66DB-2FD1-44aa-97AB-790F1EB994B1"),
	helpstring("IRcMaterialModifyExample Interface"),
	pointer_default(unique)
]
__interface IRcMaterialModifyExample : IUnknown
{
};


// CRcMaterialModifyExample
class ATL_NO_VTABLE CRcMaterialModifyExample : 
    public CComObjectRootEx<CComGlobalsThreadModel>,
    public IRsUnknownNode,
    public IRsCommand,
	public IRcMaterialModifyExample
{
private:
    CComPtr<IUnknown> m_spUnkAgg;

	CComPtr<IRsEventLogSession> m_spLogSession;

public:
    CRcMaterialModifyExample()
	{
	}

	HRESULT FinalConstruct();
	
	void FinalRelease() 
	{
        m_spUnkAgg.Release();
	}

	STDMETHOD(Execute)(void);
    STDMETHOD(Undo)(void);
    STDMETHOD(Redo)(void);
    STDMETHOD(HasUndo)(RtBool* isUndoable);
    STDMETHOD(OnGetValue)(CONID con_id, IRsDataCache* pDataCache, VARIANT* pVtData, RtBool* pHandled);
    STDMETHOD(OnSetValue)(CONID con_id, IRsDataCache* pDataCache, VARIANT* pvtData, RtBool* pHandled);
    STDMETHOD(OnDefaultValue)(CONID con_id, VARIANT* pVtData, RtBool* pHandled);
    STDMETHOD(OnInvalidate)(CONID con_id, RtBool* pHandled);
    STDMETHOD(OnInitialize)(void);
    STDMETHOD(OnLoadDefault)(void);
    STDMETHOD(OnDestroy)(void);

    // IRsObject
    RS_DECLARE_IRS_OBJECT(IRcMaterialModifyExample, L"Material modify example command")

    BEGIN_COM_MAP(CRcMaterialModifyExample)
        COM_INTERFACE_ENTRY(IRcMaterialModifyExample)
        COM_INTERFACE_ENTRY(IRsUnknownNode)
        COM_INTERFACE_ENTRY(IRsCommand)
        COM_INTERFACE_ENTRY2(IUnknown, IRsUnknownNode)
        COM_INTERFACE_ENTRY2(IRsObject, IRsUnknownNode)
        COM_INTERFACE_ENTRY_AGGREGATE(DEF_GUIDNAME(IRsBaseNode), m_spUnkAgg.p)
        COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_spUnkAgg.p)    // Just for safety, the speed is slower only for unknown interfaces
    END_COM_MAP()

    DECLARE_GET_CONTROLLING_UNKNOWN()
    DECLARE_PROTECT_FINAL_CONSTRUCT()
};
