// RcTopologyExample.h : Declaration of the CRcTopologyExample
/**
This example demonstrates using event recorder for handling undo/redo of topology operations on dependency graph.
It also demonstrates how to create various rosetta nodes like encapsulator, shape or matrix and how to work with connectors.

Command is registered into system command factory by describing it in CRsCmdFactory::EnumCommandDesc and by 
creating it in CRsCmdFactory::CreateInstance when requested. 

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

*/
#pragma once


// IRcTopologyExample
[
	object,
	uuid("5A3B7DD9-CDEC-4657-86A7-FDE4F2A3AC18"),
	helpstring("IRcTopologyExampleInterface"),
	pointer_default(unique)
]
__interface IRcTopologyExample :IUnknown
{
};


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

	CComPtr<IRsEventLogSession> m_spLogSession;


	// create new encpapsulator
	HRESULT CreateEncapsulatorNode(IRnEncapsulator** ppNewEncapsNode);
	// add sphere node to encapsulator
	HRESULT AddSphereNode(IRnEncapsulator* pEncapsNode);
	// add transform node to encapsulator
	HRESULT AddTransformNode(IRnEncapsulator* pEncapsNode);

	// returns current scene 
	HRESULT GetCurrentScene(IRnEncapsulator** ppCurrSceneEncaps);

public:
    CRcTopologyExample()
	{
	}

	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(IRcTopologyExample, L"Topology example command")

    BEGIN_COM_MAP(CRcTopologyExample)
        COM_INTERFACE_ENTRY(IRcTopologyExample)
        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()
};
