// isoview.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "isoview.h"
#include "direct.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char* name = "isocam1";

//
//	Note!
//
//		If this DLL is dynamically linked against the MFC
//		DLLs, any functions exported from this DLL which
//		call into MFC must have the AFX_MANAGE_STATE macro
//		added at the very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

/////////////////////////////////////////////////////////////////////////////
// CIsoviewApp

BEGIN_MESSAGE_MAP(CIsoviewApp, CWinApp)
	//{{AFX_MSG_MAP(CIsoviewApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIsoviewApp construction

CIsoviewApp::CIsoviewApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CIsoviewApp object

CIsoviewApp theApp;

///////////////////////////////////////////////////////////////////////////////

// this is your camera creation function - if the iso camera is already in the
// scene then a new one will not be created
void CreateIsometricCamera( char *pName )
{
	// look for existing object
	tsxGNODE *pGNode = NULL;
	if ( tsxGNodeFindByName( &pGNode, NULL, pName ) == e_tsxFALSE )
	{
		tsxSOBJ *mySOBJ;
		_chdir("c:\\");
		mySOBJ = tsxObjectLoad( pName );
	}

}

// Saved tsxid for one installation of this extension
// Note: Using single global this will prevent it from being installed on more
// than one button.
int g_tsxid =0; 
// First function called from trueSpace, on loading the tSX
int tsxGetData (tsxData* tsx_data, int tsxid)
{
// Put at beginning of exported functions if using MFC,
// or your plugin is likely to crash
AFX_MANAGE_STATE(AfxGetStaticModuleState());
static tsxData MyTsxData =
{ "isoview", "Plugin Developer", IDB_TSXBUTTON, IDS_TSXHELP};
*tsx_data = MyTsxData;
// Save tsxid for this extension, for use with Callback functions.
g_tsxid = tsxid;
return tsxPLUG_DONE;
}

// this function will be called when the tSX button is left-clicked
int tsxOnLeftClick()
{
// Put at beginning of exported functions if using MFC,
// or your plugin is likely to crash
AFX_MANAGE_STATE(AfxGetStaticModuleState()); 

	CreateIsometricCamera( name );
	
// nothing functional here now
return tsxPLUG_DONE;
}

// this function will be called when the tSx button is right-clicked
void tsxOnRightClick()
{
// Put at beginning of exported functions if using MFC,
// or your plugin is likely to crash
AFX_MANAGE_STATE(AfxGetStaticModuleState()); 


// nothing functional here now
}

// This funciton will be called whenever the tSx is deactivated
// - User left-clicks on the tSX button
// - User selects some other tool
// - User exits trueSpace
void tsxDeactivate()
{
// Put at beginning of exported functions if using MFC,
// or your plugin is likely to crash
AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
// nothing functional here now
}

// new for tS5, this function allows plugin authors to specify which
// version of the API they need:
// 500 is version 5.0, 430 is version 4.3, etc.
int tsxGetVersion(int tsxid)
{
// Put at beginning of exported functions if using MFC,
// or your plugin is likely to crash
AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
return 751;
}
