// RcCreate3DLoader.h : Declaration of the CRcCreate3DLoader
// Purpose of this command is to create the Rn3DLoader node object,
// put it into Dependency Graph and properly set its parameters.


#pragma once

#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

// IRcCreate3DLoader
MIDL_INTERFACE("D7F53E22-1DB1-4042-AF88-792A25B54F07")
IRcCreate3DLoader :IUnknown
{
};

// CRcCreate3DLoader
class ATL_NO_VTABLE CRcCreate3DLoader :
    public CComObjectRootEx<CComGlobalsThreadModel>,
    public IRsUnknownNode,
    public IRsCommand,
	public IRcCreate3DLoader
{
public:
    CRcCreate3DLoader()
	{
	}

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

    // IRsCommand interface
	STDMETHOD(Execute)(void);
    STDMETHOD(Undo)(void);
    STDMETHOD(Redo)(void);
    STDMETHOD(HasUndo)(RtBool* isUndoable);

    // IRsUnknownNode interface
    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 interface
    RS_DECLARE_IRS_OBJECT(IRcCreate3DLoader, L"Create3DLoader command")

    BEGIN_COM_MAP(CRcCreate3DLoader)
        COM_INTERFACE_ENTRY(IRsUnknownNode)
        COM_INTERFACE_ENTRY(IRsCommand)
        COM_INTERFACE_ENTRY(IRcCreate3DLoader)
        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()

private:
    HRESULT GetPathDir(BSTR *pPathDir);

private:
    CComPtr<IUnknown> m_spUnkAgg;   // Store reference on Base Node object
    CComBSTR m_bstr3DLoaderID;      // Used by Undo method to remember the object created by this command
    CComBSTR m_bstrPathDir;         // Used by Redo method to remember the selected directory path
};
