// Rf3DLoader.h : Declaration of the CRf3DLoader
// This functions set helps the 3DLoader node in it's behavior.


#pragma once
#include "resource.h"       // main symbols

#define RF3DLOADER_NUM_ANIM_STEPS       16              // Number of animation steps
#define RF3DLOADER_Z_DISTANCE           1.0f            // Z distance between two thumbnails
#define RF3DLOADER_BOTTOM_Z_POS         1.3f            // Z position of the first thumbnail
#define RF3DLOADER_THUMB_Z_SCALE        0.1f            // Z scale of the thumbnails
#define RF3DLOADER_3DLOADER_PAD_NAME    L"3DLoaderBase" // 3D loader pad name (IDR_BIN_3DLOADER_BASE)

// Define help connectors' IDs

// FocusDir: MarkTime: Stored last update time
// {593B5EA7-5706-4897-B076-B53C06B48D65}
RS_DEFINE_GUID(CON_ID_3DLOADER_STR_MARKTIME,
0x593b5ea7, 0x5706, 0x4897, 0xb0, 0x76, 0xb5, 0x3c, 0x6, 0xb4, 0x8d, 0x65);

// FileTime: Stored last file write time
// {8F07EBDA-32EA-4437-97CE-7E4355F201C7}
RS_DEFINE_GUID(CON_ID_3DLOADER_STR_FILETIME,
0x8f07ebda, 0x32ea, 0x4437, 0x97, 0xce, 0x7e, 0x43, 0x55, 0xf2, 0x1, 0xc7);

// IRf3DLoader
[
	object,
	uuid("191DA51A-91D0-493a-88C7-2E8A233A3E45"),
	helpstring("IRf3DLoader Interface"),
	pointer_default(unique)
]
__interface IRf3DLoader : IUnknown
{
    /**
        Assign a 3DLoader space to the function set. The function set then
        will operate with the 3DLoader space.
        @pSpaceNode - Specify here the encapsulator node that store the thumbnails
    */
    [id(1), helpstring("method Assign")] HRESULT Assign([in] IUnknown *pNodeUnkn);

    /**
        Call to delete all the thumbnails from assigned space.
    */
    [id(2), helpstring("method RemoveAllThumbnails")] HRESULT RemoveAllThumbnails();

    /**
        This method is called when we starts enumerating the directory content.
    */
    [id(3), helpstring("method ThumbnailsCheckStart")] HRESULT ThumbnailsCheckStart();

    /**
        Create and add new thumbnail 3D pad object. If it exist, it will not be created.
    */
    [id(4), helpstring("method Add3DLoaderBase")] HRESULT Add3DLoaderBase();

    /**
        Create and add new thumbnail object. We suppose the node really doesn't exist.
        In another case the 3DLoader object will not work properly.
        @param pFileInfo - File info structure of the file we want to display as 3D Thumbnail
    */
    [id(5), helpstring("method AddThumbnailNode")] HRESULT AddThumbnailNode([in] IUnknown *pFileInfoUnkn);

    /**
        This method is called to update already existing thumbnail.
    */
    [id(6), helpstring("method UpdateThumbnailNode")] HRESULT UpdateThumbnailNode([in] IUnknown *pThumbnailNodeUnkn, [in] IUnknown *pFileInfoUnkn);

    /**
        Called to tell this function set that the enumerating is finished. We need this only to
        remove thumbnails of deleted files.
    */
    [id(7), helpstring("method ThumbnailsCheckFinish")] HRESULT ThumbnailsCheckFinish();

    /**
        Go through all thumbnails and compute new positions for them
    */
    [id(8), helpstring("method ArrangeThumbnails")] HRESULT ArrangeThumbnails();

    /**
        Go through all thumbnails and make one step to arrange them in 3D space
        by positions computed in ArrangeThumbnails method
    */
    [id(9), helpstring("method AnimateThumbnails")] HRESULT AnimateThumbnails();
};

// CRf3DLoader

class ATL_NO_VTABLE CRf3DLoader : 
    public CComObjectRootEx<CComGlobalsThreadModel>,
	public IRf3DLoader
{
public:
	CRf3DLoader()
	{
        m_dwUpdateMarkCounter = 0;
	}
    
    BEGIN_COM_MAP(CRf3DLoader)
        COM_INTERFACE_ENTRY(IRf3DLoader)
        COM_INTERFACE_ENTRY2(IUnknown, IRf3DLoader)
    END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

    // IRf3DLoader
    STDMETHOD(Assign)(IUnknown *pNodeUnkn);
    STDMETHOD(RemoveAllThumbnails)();
    STDMETHOD(ThumbnailsCheckStart)();
    STDMETHOD(Add3DLoaderBase)();
    STDMETHOD(AddThumbnailNode)(IUnknown *pFileInfoUnkn);
    STDMETHOD(UpdateThumbnailNode)(IUnknown *pThumbnailNodeUnkn, IUnknown *pFileInfoUnkn);
    STDMETHOD(ThumbnailsCheckFinish)();
    STDMETHOD(ArrangeThumbnails)();
    STDMETHOD(AnimateThumbnails)();

public:
    HRESULT AddThumbnailNodeObject(BSTR bstrName, IRsNode **ppThumbnailNodeObject);
    HRESULT ConnectWithTransformNode(IRsNode *pThumbnailNode);
    HRESULT AddTransformNode(IRsNode **ppTransformNode);
    HRESULT ExportConnector(IRsNode *pDstNode, const CONID *pConId, RtBool bSetValue = false);
    HRESULT GetFullFilePath(BSTR bstrFileName, BSTR *pbstrPath);

private:
    CComPtr<IRpFileIOPck> m_spRpFileIOPck;              // Reference to File IO package
    CComPtr<IRfEncapsulatorSet> m_spEncapsulatorSet;    // Encapsulator functions set

    CComPtr<IRsNode> m_sp3DLoaderNode;                  // Assigned space node
    CComPtr<IRnEncapsulator> m_spSpaceEnc;              // Assigned space encapsulator interface
    RtDWORD m_dwUpdateMarkCounter;                      // Help counter for thumbnails removing

    CAtlArray<RtFloat> m_afZPosition;                   // Used to store thumbnails' Z position
    RtDWORD m_dwAnimationFrame;                         // Remember last animation frame
};

