// PlugTest.h : main header file for the PLUGTEST DLL
//

#if !defined(AFX_LEGMIRROR_H__68E70A2D_B863_11D1_98AD_0040051EDCE7__INCLUDED_)
#define AFX_LEGMIRROR_H__68E70A2D_B863_11D1_98AD_0040051EDCE7__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif


#ifdef STRICT							// Already defined by stdafx,
#undef STRICT							// so we avoid warning linking msg
#endif
#ifdef _MBCS							// The same as above
#undef _MBCS
#endif

class LegMirrorPanel;

#include "AnimationSuite.h"
#include <Stuff\StuffHeaders.hpp>

#pragma pack(push,8)
#include "..\\MaxControls\\ExpCtrl.h"
#pragma pack(pop)

/////////////////////////////////////////////////////////////////////////////
// JointPrefrenceApp
// See PlugTest.cpp for the implementation of this class
//

#ifndef __LEGMIRROR__
#define __LEGMIRROR__


// Hold pointers to all the nodes that an expression a control uses.
class ExpControlDep
{
public:
	INode *ndes[6];
	ExpControlDep() {Clear();}
	void Clear() {for(int i=0;i<6;i++) ndes[i]=NULL;}
};


/////////////////////////////////////////////////////////////////////////////
// PlugPanel, manage the Plugins' display panel
class LegMirrorPanel : public UtilityObj {
	protected:
		HINSTANCE		m_hInstance;
		IUtil*			m_iu;
		HWND			m_hPanel;
		
		enum  LRFLAG {ISLEFT,ISRIGHT,ISNEITHER} ;

	public:
		Interface*		m_ip;

        // Constructor & Destructor
        LegMirrorPanel() {};
        virtual ~LegMirrorPanel() {};

        void DoFixExp();
		void GetExpDeps(INode *nde,ExpControlDep *dep);
		void AssignExpressions(INode *nde,ExpControlDep *dep);
		void AssignExpCtrl(ExprControl *expc,INode *nde);
		void FixExpressions(INode *nde);
		bool HasCircularReference(INode *,ExprControl *);
		void ReverseExpControl(ExprControl *expc);
		
		// Overides of the UtilityObj class
		void BeginEditParams(Interface* ip, IUtil* iu);
		void EndEditParams(Interface* ip, IUtil* iu);
		void DeleteThis()				{}
		void Init(HWND hWnd)			{}
		void Destroy(HWND hWnd)			{}

		//Specific Methods
		void DoMirror();
		void DoReverse();
		void DoExportAnims();
		void RevSites();

		void FixScale();
		void ScaleNodeAll(Control *c, float scale);
		void ScaleKey(Control *c, IKeyControl *ikeys, Stuff::Scalar amount, float median,int key_number);
		void ScaleNodePosition(INode *node, Stuff::Point3D scale);
	
		void ExportLights();
		void ImportMission();

	private:

		void ReverseAnimation(INode *nde);
		void ReverseExpressions(INode *nde);

		void ReverseKeys(INode *nde);
		void ReverseControl(IKeyControl *ikc,Class_ID id);

		void RevSiteOnNode(INode *nde);

		bool IsExprControl(Control *ctrl);
		void FixExpControl(INode *mynde,ExprControl *expc,int axis=0);
		void MirrorExpControl(ExprControl *expc);
		INode *GetDepNode(ExprControl *expc);
		void MirrorAnimation(INode *nde);
		void SwapAnimations(INode *nde1,INode *nde2);
		void SwapProperties(INode *nde1,INode *nde2);
		int  NegateKey(IKeyControl *ikc,Class_ID id);
		INode *FindCorespondingNode(INode *nde);
		void MirrorNode(INode *nde);
		LRFLAG TellSide(INode *nde);
		bool IsReversable(INode *nde);
		void SwapRotations(INode *nde1,INode *nde2);

        Control *GetControlByName(Animatable *nde,CString &cnme,int *subanim);
        void PlaceZeroKeys(INode *nde);
        void SwapExpressions(INode *nde);
        
		bool IsJoint(CString &str)		{ return !str.Left(5).CompareNoCase("JOINT");	}
		bool IsSite(CString &str)		{ return !str.Left(4).CompareNoCase("SITE");	}
		bool IsHandle(CString &str)		{ return !str.Left(6).CompareNoCase("HANDLE");	}
		bool IsTorsoJoint(CString &str) { return !str.CompareNoCase("JOINT_TORSO");		}
		bool IsRootJoint(CString &str)	{ return !str.CompareNoCase("JOINT_ROOT");		}

		void ILFree(LPITEMIDLIST pidl); 
};

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

#endif

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_LEGMIRROR_H__68E70A2D_B863_11D1_98AD_0040051EDCE7__INCLUDED_)
