#include "stdafx.h"
#include "math.h"
#include "geom.h"
#include "bemsolve.h"

#include "bemsolveDoc.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////
// Class of nodes

IMPLEMENT_SERIAL (CNode,CObject,1);

CNode::CNode (float x,float y)
{
	xb=x;yb=y;
}	                              

CNode::CNode() {};

void CNode::Serialize(CArchive& ar)
{               
	CObject::Serialize(ar);
	if (ar.IsStoring())
	{           
		ar << xb << yb;
	}
	else
	{                                        
		ar >> xb >> yb;
	}
}

BOOL CNode::operator ==(const CNode& other) const
{
 return (fabs(other.xb-xb)<1e-6)&&(fabs(other.yb-yb)<1e-6);
}

void CNode::Coord (float& x,float &y)
{
	x=xb;y=yb;
}

//////////////////////////////////////////////////////////////////////////
//  Class of elements

IMPLEMENT_SERIAL (CElement,CObject,1);

CElement::CElement() {};

CElement::CElement (int u1,int u2)
{
	nod1=u1;nod2=u2;type=0;
}	

BOOL CElement::operator ==(const CElement& other) const { return &other == this; }

void CElement::Serialize(CArchive& ar)
{                                               
	CObject::Serialize(ar);
	if (ar.IsStoring())
	{                                                                        
		ar << nod1 << nod2 << type;
		ar << pot << der << level << kf0 << dist;
	}
	else
	{                                                            
		ar >> nod1 >> nod2 >> type;
		ar >> pot >> der >> level >> kf0 >> dist;
	}
}

/////////////////////////////////////////////////////////////////////////
// class of wells

IMPLEMENT_SERIAL (CWell,CObject,1);

CWell::CWell() {};

CWell::CWell (CString s,float x,float y,float *gc,float dis,float d)
{
	name=s;
	xz=x;yz=y;yield=dis;diam=d;
}

BOOL CWell::operator ==(const CWell& other) const { return &other == this; }

void CWell::Serialize(CArchive& ar)
{                                       
	CObject::Serialize(ar);
	if (ar.IsStoring())
	{            
		ar << name << xz << yz << yield << diam << drwdown;  
 	}
	else
	{   
		ar >> name >> xz >> yz >> yield >> diam >> drwdown;  
	}
}

/////////////////////////////////////////////////////////////////////////
// class of internal points

IMPLEMENT_SERIAL (CIntPoint,CObject,1);

CIntPoint::CIntPoint() {};

CIntPoint::CIntPoint (float x,float y,float *gc)
{
	xz=x;yz=y;
}

BOOL CIntPoint::operator ==(const CIntPoint& other) const { return &other == this; }

void CIntPoint::Serialize(CArchive& ar)
{                                       
	CObject::Serialize(ar);
	if (ar.IsStoring())
	{            
		ar << xz << yz << drwdown << vx << vy;
 	}
	else
	{   
		ar >> xz >> yz >> drwdown >> vx >> vy;
	}
}

/////////////////////////////////////////////////////////////////////////
// class of internal elements

IMPLEMENT_SERIAL (CIntElem,CObject,1);

CIntElem::CIntElem() {};

CIntElem::CIntElem (float *x,float *y,float pr)
{
	for (int i=0;i<3;i++) {xp[i]=x[i];yp[i]=y[i];}
	precip=pr;
}

void CIntElem::Serialize(CArchive& ar)
{                                       
	CObject::Serialize(ar);
	if (ar.IsStoring())
	{            
		ar.Write (xp,sizeof(xp));
		ar.Write (yp,sizeof(yp));
		ar << precip;
 	}
	else
	{   
		ar.Read (xp,sizeof(xp));
		ar.Read (yp,sizeof(yp));
		ar >> precip;
	}
}

