www.pudn.com > 20065291434354190.rar > XLine.cpp


 
#include "StdAfx.h" 
 
#include "XLine.h" 
#include "XStations.h" 
 
XLine::XLine() 
{ 
	id = -1; 
	name = ""; 
	isOneWay = false; 
} 
 
XLine::~XLine() 
{ 
} 
 
XLine& XLine::operator = (const XLine& line) 
{ 
	if (&line == this) return *this; 
 
	id = line.id; 
	name = line.name; 
	isOneWay = line.isOneWay; 
	spots = line.spots; 
 
	return *this; 
} 
 
bool XLine::operator == (const XLine& line) 
{ 
	return  (id  == line.id); 
} 
 
bool XLine::IsInRect (float left, float top, float right, float bottom) 
{ 
	for (size_t i = 0; i < spots.size();i++) 
	{ 
		PointF position = spots[i].GetPosition (); 
		if (position.X >= left && position.X <= right 
			&& position.Y >= top && position.Y <= bottom) 
			return true; 
	} 
 
	return false; 
} 
  
int XLine::Append (XSpot& vSpot) 
{ 
	spots.push_back(vSpot); 
 
	return (int)spots.size(); 
} 
 
int XLine::Remove (XSpot& vSpot) 
{ 
	vector::iterator pos; 
 
	pos = find (spots.begin(),spots.end(),vSpot); 
	 
	//if (pos != spots.end()) 
		spots.erase (pos); 
 
	return -1; 
} 
 
int XLine::ToTube (RectF rect, XTube& tube) 
{ 
	tube.GetSpots ().clear (); 
	 
	size_t start = 0, end = 0; 
	for (start = 0; start < spots.size(); start++) 
	{ 
		if (rect.Contains(spots[start].GetPosition ())) 
			break; 
	} 
 
	for (end = spots.size()-1; end > start; end--) 
	{ 
		if (rect.Contains(spots[start].GetPosition ())) 
			break; 
	} 
 
	if (start > end) return 0; 
	if (start > 0) start --; 
	if (end < spots.size () -1) end ++; 
 
	for (size_t i = start; i <= end; i ++) 
		tube.Append (spots[i]); 
 
	return tube.GetCount (); 
} 
 
int  XLine::GetCount() 
{    
	return (int) spots.size();; 
} 
 
int XLine::ToXML (CMarkup& markup) 
{ 
	/* 
	markup.AddChildAttr ("name", name); 
 
 
	markup.AddChildElem ("stations"); 
 
	markup.IntoElem ();  
	for (int i = 0; i < size(); i++) 
	{ 
		markup.AddChildElem ("station"); 
		markup.AddChildAttr ("name", name); 
		markup.AddChildAttr ("longitude", position.X); 
		markup.AddChildAttr ("latitude", position.Y); 
		markup.AddChildAttr ("type", type); 
	} 
	markup.OutOfElem(); 
	*/ 
	return 0; 
} 
 
int XLine::FromXML (CMarkup& markup) 
{ 
	name = markup.GetChildAttr("name"); 
 
	if (markup.GetChildAttr("oneway") == "true") 
		isOneWay = true;  
	else  
		isOneWay = false; 
 
	markup.IntoElem (); 
	if (markup.FindChildElem("stations") ) 
	{ 
		markup.IntoElem (); 
		while(markup.FindChildElem("station")) 
		{ 
			PointF position; 
			SpotTypeEnum type; 
 
			CString vName = markup.GetChildAttr("name"); 
 
			position.X = float(atof(markup.GetChildAttr("longitude"))-116.0)*10000; 
			position.Y = float(40.0 - atof(markup.GetChildAttr("latitude")))*10000; 
 
			if (vName.IsEmpty()) 
				type = STE_NULL; 
			else 
				type = STE_SMALL_CIRCLE; 
			 
			Append(XSpot (position, type, vName)); 
		} 
		 
		markup.OutOfElem(); 
	} 
 
	markup.OutOfElem(); 
 
	return 0; 
}