// CommonObject.cpp : implementation file
//

#include "stdafx.h"
#include "INKS.h"
#include "CommonObject.h"

CCommonObject::CCommonObject(int nIn, int nOut, CString strName, CStringA strOrigin) 
	: m_strUniqueName(strName), m_strOrigin(strOrigin), m_nIn(nIn), m_nOut(nOut), m_gPath(NULL), m_gpText(NULL)
{

}

CCommonObject::~CCommonObject()
{
}
// CCommonObject message handlers


CCommonObject* CCommonObject::ConnectHitTest(CPoint point, int &nNumber)
{
	nNumber = 0;
	return NULL;
}

Rect* CCommonObject::GetBounds()
{
	int nPntCount = (int)m_gPath->GetPointCount();
	Point *pnts = new Point[nPntCount];
	m_gPath->GetPathPoints(pnts, nPntCount);
	int nXmin, nXmax, nYmin, nYmax;
	nXmax = nXmin = pnts[0].X;
	nYmax = nYmin = pnts[0].Y;
	for(int i=1; i<nPntCount; i++){
		if(pnts[i].X < nXmin)
			nXmin = pnts[i].X;
		if(pnts[i].Y < nYmin)
			nYmin = pnts[i].Y;
		if(pnts[i].X > nXmax)
			nXmax = pnts[i].X;
		if(pnts[i].Y > nYmax)
			nYmax = pnts[i].Y;
	}
	SAFE_DELETE_ARRAY(pnts);
	m_rectBounding.X = nXmin+10;
	m_rectBounding.Y = nYmin;
	m_rectBounding.Width = nXmax-nXmin-10;
	m_rectBounding.Height = nYmax-nYmin;
	return &m_rectBounding;
}

void CCommonObject::SetRotation(int nRotation)
{
	m_nRotation = nRotation;
	if(m_gPath){
		Matrix *pMat = new Matrix();
		pMat->Translate((REAL)-m_pointTopLeft.x, (REAL)-m_pointTopLeft.y);
		m_gPath->Transform(pMat);
		pMat->Reset();
		pMat->Rotate((REAL)nRotation);
		m_gPath->Transform(pMat);
		pMat->Reset();
		pMat->Translate((REAL)m_pointTopLeft.x, (REAL)m_pointTopLeft.y);
		m_gPath->Transform(pMat);
		SAFE_DELETE(pMat);
	}
}


void CCommonObject::SetConnection(bool bIn, int nPos, CCommonObject* pConnectTo)
{
}

void CCommonObject::DisconnectCObject(CCommonObject *pObject)
{
}

void CCommonObject::Disconnect()
{
}