// ShapePanel.cpp : implementation file
//

#include "stdafx.h"
#include "pixelwhippro.h"
#include "ShapePanel.h"
#include <ElementRenderer\ElementRenderer.hpp>

extern CPixelWhipProApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CShapePanel dialog


CShapePanel::CShapePanel(CWnd* pParent /*=NULL*/)
: CDynaPanel(CShapePanel::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShapePanel)
	// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

void CShapePanel::Set(void *dat)
{
	
	ShapeSpec=(gosFX::Shape__Specification *)dat;
}

void CShapePanel::DoDataExchange(CDataExchange* pDX)
{
	CDynaPanel::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShapePanel)
	// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CShapePanel, CDynaPanel)
//{{AFX_MSG_MAP(CShapePanel)
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShapePanel message handlers

void CShapePanel::OnBrowse() 
{
	CString doc_path=theApp.DocPath.Left(theApp.DocPath.ReverseFind('\\')),shape_path;
//	if(doc_path.GetLength()==0) 	GetCurrentDirectory(doc_path);
	SetCurrentDirectory(doc_path);
	
	CFileDialog dlg1(TRUE,"mlr",NULL,OFN_NOCHANGEDIR,"MLR Geometry(*.mlr)|*.mlr||",this);
	if(dlg1.DoModal()==IDOK)
	{
	shape_path=dlg1.GetPathName();
		if(doc_path.GetLength()>shape_path.GetLength() ||
			shape_path.Left(doc_path.GetLength()).CompareNoCase(doc_path)
			)
		{	
			MessageBox("Shape Path Error");
		}
		else
		{
			shape_path=shape_path.Mid(doc_path.GetLength()+1);

			ShapeSpec->SetShape(MString(shape_path));
			MidLevelRenderer::MLRTexturePool::Instance->LoadImages();	
		}
		
	}
	
	
}
