12. april 2006 - 13:04
Der er
6 kommentarer
udledning af tekststreng til variabel.
vi sidder et par gutter i øjeblikket og arbejder med noget programmering til en skole opgave. der for vi en tekststreng ud fra et GPS modulsomvi skl have udledt til nogle variabler.detharvi lidt problemer med. vores kodeindtil videre ser sådan ud:
char GSV[1][7];
char line[60] = "$GPGSV,3,954,11,07,68,167,,28,57,070,,08,47,134,,26,,281,*7B";
char *cp;
char laengde[3], bredde, tid;
printf("%s\n\n",line);
printf(" #1 = %s\n",cp);
cp = strtok(line, ",");
printf(" #1 = %s\n",cp);
if (cp= "$GPGGA"){
//
cp = strtok(NULL, ",");
printf(" #2 = %s\n",cp);
cp = strtok(NULL, ",");
printf(" #3 = %s\n",cp);
int i = 0;
do {
laengde[i]=*cp;
//printf("%s",laengde);
cp++;
i++;
} while(*laengde);
printf("%c",laengde);
problemet her er dog blot at vi kun for udlæst den ene karrakter der står hvor pointeren "peger" og ikke hele tallet eller "ordet", som er det vi skal bruge.. når vi har lavet den løkke er det i et desperat forsøg på at selv manuelt smide dataene ned i et char array. der for vi så blot noget garbage data med i udskrivningen... nogen der har en ide?
det er helt præcist er målet er at udlede de enkelte data, der står mellem kommaerne, til variabler, vi så kan læse efter behov...
Wulff
15. april 2006 - 18:09
#6
Det er en lang smøre...
// NMEA.h
#include "Coordinate.h"
class NMEA
{
public:
typedef enum {INVALID, ALL, GPGGA, GPGSA, GPRMC} NMEAType;
typedef enum {OK, WARNING} DataStatus;
typedef enum {MANUAL, AUTOMATIC} Mode;
typedef enum {NO_FIX, _2D, _3D} SatelliteMode;
typedef enum {Invalid, ValidSPS, ValidDGPS, ValidPPS} PositionFix;
typedef enum {NONE, METERS, KMH, MPS, KNOTS} Unit;
const static NMEAType GetTypeFromSentence(const CString& strNMEASentence);
const NMEAType GetType();
const CString GetTypeString();
static NMEA* DecodeNMEAString(const CString& strNMEASentence);
virtual bool Decode(const CString& strNMEASentence)=0;
virtual bool IsValid()=0;
const static CString GetSeparator() { return ","; }
protected:
NMEAType m_Type;
};
// GPGGA: Fix data
class NMEA_GPGGA : public NMEA
{
friend class NMEADecoder;
public:
NMEA_GPGGA() {m_Type = GPGGA;}
bool Decode(const CString& strNMEASentence);
bool IsValid();
protected:
// Attributes
CTime m_Time;
Coordinate m_Coordinate;
PositionFix m_PositionFix;
short m_SatellitesUsed;
float m_HDOP; // Horizontal dilution of precision
float m_Altitude;
Unit m_AltitudeUnit;
float m_GeoidSeperation;
Unit m_GeoidSeperationUnit;
float m_DGPSAge;
int m_DGPSStationID;
int m_Checksum; // Er egentlig et hexadecimalt tal, så oversættes ikke rigtig.
};
// GPGSA: Active satellites
class NMEA_GPGSA : public NMEA
{
friend class NMEADecoder;
public:
NMEA_GPGSA() {m_Type = GPGSA;}
bool Decode(const CString& strNMEASentence);
bool IsValid();
protected:
// Attributes
Mode m_Mode;
SatelliteMode m_SatelliteMode;
int m_IDs[12];
float m_PDOP;
float m_HDOP;
float m_VDOP;
int m_Checksum; // Er egentlig et hexadecimalt tal, så oversættes ikke rigtig.
};
// GPRMC: Position and time
class NMEA_GPRMC : public NMEA
{
friend class NMEADecoder;
public:
NMEA_GPRMC() {m_Type = GPRMC;}
bool Decode(const CString& strNMEASentence);
bool IsValid();
float GetSpeed(Unit unit=KMH);
protected:
// Attributes
CTime m_Time;
DataStatus m_DataStatus;
Coordinate m_Coordinate;
float m_Speed;
float m_Course;
float m_Variation;
int m_Checksum; // Er egentlig et hexadecimalt tal, så oversættes ikke rigtig.
};
// NMEA.cpp
#include "NMEA.h"
#include "../Utils/StringUtils.h"
using NMEA::NMEAType;
//-*-;
//////////////////////////////////////////////////////////////////////
// NMEA implementation
//////////////////////////////////////////////////////////////////////
const NMEAType NMEA::GetTypeFromSentence(const CString& strNMEASentence)
{
CString strNMEACode = strNMEASentence.Left(6);
if(strNMEACode == "$GPGGA")
return GPGGA;
if(strNMEACode == "$GPGSA")
return GPGSA;
if(strNMEACode == "$GPRMC")
return GPRMC;
return INVALID;
}
const NMEAType NMEA::GetType()
{
return m_Type;
}
const CString NMEA::GetTypeString()
{
switch(m_Type)
{
case GPGGA:
return _T("$GPGGA");
case GPGSA:
return _T("$GPGSA");
case GPRMC:
return _T("$GPRMC");
default:
return _T("INVALID");
}
}
NMEA* NMEA::DecodeNMEAString(const CString& strNMEASentence)
{
NMEAType type = GetTypeFromSentence(strNMEASentence);
if(type == INVALID)
return NULL;
NMEA* pNMEA = NULL;
if(type == GPGGA)
pNMEA = new NMEA_GPGGA;
else if(type == GPGSA)
pNMEA = new NMEA_GPGSA;
else if(type == GPRMC)
pNMEA = new NMEA_GPRMC;
if(pNMEA->Decode(strNMEASentence))
return pNMEA;
delete pNMEA;
return NULL;
}
//////////////////////////////////////////////////////////////////////
// NMEA_GPGGA implementation
//////////////////////////////////////////////////////////////////////
bool NMEA_GPGGA::Decode(const CString& strNMEASentence)
{
CTokenList TokenList;
int nTokens = StringUtils::Tokenize(strNMEASentence, GetSeparator(), TokenList);
if(nTokens != 15)
return false;
POSITION pos = TokenList.GetHeadPosition();
CString strToken = TokenList.GetNext(pos);
if(strToken != "$GPGGA")
return false;
// Get hour, min and sec
int nHour, nMin, nSec;
strToken = TokenList.GetNext(pos);
nHour = _ttoi(strToken.Left(2));
nMin = _ttoi(strToken.Mid(2, 2));
nSec = _ttoi(strToken.Mid(4, 2));
m_Time = CTime(2000, 1, 1, nHour, nMin, nSec); // We only have time, not date, so just put some default values
m_Coordinate.GetLatitude().SetPositionFromString(TokenList.GetNext(pos));
m_Coordinate.GetLatitude().SetDirectionFromString(TokenList.GetNext(pos));
m_Coordinate.GetLongitude().SetPositionFromString(TokenList.GetNext(pos));
m_Coordinate.GetLongitude().SetDirectionFromString(TokenList.GetNext(pos));
m_PositionFix = (PositionFix)_ttoi(TokenList.GetNext(pos));
m_SatellitesUsed = (short)_ttoi(TokenList.GetNext(pos));
m_HDOP = (float)_tcstod(TokenList.GetNext(pos), NULL);
m_Altitude = (float)_tcstod(TokenList.GetNext(pos), NULL);
strToken = TokenList.GetNext(pos);
if(strToken == "M")
m_AltitudeUnit = METERS;
m_GeoidSeperation = (float)_tcstod(TokenList.GetNext(pos), NULL);
strToken = TokenList.GetNext(pos);
if(strToken == "M")
m_GeoidSeperationUnit = METERS;
m_DGPSAge = (float)_tcstod(TokenList.GetNext(pos), NULL);
strToken = TokenList.GetNext(pos);
int nStarSepPos = strToken.Find('*');
m_DGPSStationID = _ttoi(strToken.Left(nStarSepPos));
m_Checksum = _ttoi(strToken.Mid(nStarSepPos+1));
return true;
}
bool NMEA_GPGGA::IsValid()
{
if(m_PositionFix == Invalid)
return false;
return true;
}
//////////////////////////////////////////////////////////////////////
// NMEA_GPGSA implementation
//////////////////////////////////////////////////////////////////////
bool NMEA_GPGSA::Decode(const CString& strNMEASentence)
{
CTokenList TokenList;
int nTokens = StringUtils::Tokenize(strNMEASentence, GetSeparator(), TokenList);
if(nTokens != 18)
return false;
POSITION pos = TokenList.GetHeadPosition();
CString strToken = TokenList.GetNext(pos);
if(strToken != "$GPGSA")
return false;
// Mode
strToken = TokenList.GetNext(pos);
if(strToken == "M") m_Mode = MANUAL;
else if(strToken == "A") m_Mode = AUTOMATIC;
// SatelliteMode
strToken = TokenList.GetNext(pos);
if(strToken == "1") m_SatelliteMode = NO_FIX;
else if(strToken == "2") m_SatelliteMode = _2D;
else if(strToken == "3") m_SatelliteMode = _3D;
// IDs
for(int i=0; i<12; ++i)
m_IDs[i] = _ttoi(TokenList.GetNext(pos));
m_PDOP = (float)_tcstod(TokenList.GetNext(pos), NULL);
m_HDOP = (float)_tcstod(TokenList.GetNext(pos), NULL);
strToken = TokenList.GetNext(pos);
int nStarSepPos = strToken.Find('*');
m_VDOP = (float)_tcstod(strToken.Left(nStarSepPos), NULL);
m_Checksum = _ttoi(strToken.Mid(nStarSepPos+1));
return true;
}
bool NMEA_GPGSA::IsValid()
{
return true;
}
//////////////////////////////////////////////////////////////////////
// NMEA_GPRMC implementation
//////////////////////////////////////////////////////////////////////
bool NMEA_GPRMC::Decode(const CString& strNMEASentence)
{
CTokenList TokenList;
int nTokens = StringUtils::Tokenize(strNMEASentence, GetSeparator(), TokenList);
if(nTokens != 12)
return false;
POSITION pos = TokenList.GetHeadPosition();
CString& strToken = TokenList.GetNext(pos);
if(strToken != "$GPRMC")
return false;
// Get hour, min and sec
int nYear, nMonth, nDay, nHour, nMin, nSec;
strToken = TokenList.GetNext(pos);
nHour = _ttoi(strToken.Left(2));
nMin = _ttoi(strToken.Mid(2, 2));
nSec = _ttoi(strToken.Mid(4, 2));
strToken = TokenList.GetNext(pos);
if(strToken == "A") m_DataStatus = OK;
else if(strToken == "V") m_DataStatus = WARNING;
m_Coordinate.GetLatitude().SetPositionFromString(TokenList.GetNext(pos));
m_Coordinate.GetLatitude().SetDirectionFromString(TokenList.GetNext(pos));
m_Coordinate.GetLongitude().SetPositionFromString(TokenList.GetNext(pos));
m_Coordinate.GetLongitude().SetDirectionFromString(TokenList.GetNext(pos));
m_Speed = (float)_tcstod(TokenList.GetNext(pos), NULL);
m_Course = (float)_tcstod(TokenList.GetNext(pos), NULL);
strToken = TokenList.GetNext(pos);
nDay = _ttoi(strToken.Left(2));
nMonth = _ttoi(strToken.Mid(2, 2));
nYear = _ttoi(strToken.Mid(4, 2));
m_Time = CTime(2000+nYear, nMonth, nDay, nHour, nMin, nSec);
m_Variation = (float)_tcstod(TokenList.GetNext(pos), NULL);
strToken = TokenList.GetNext(pos);
m_Checksum = _ttoi(strToken.Mid(1));
return true;
}
bool NMEA_GPRMC::IsValid()
{
if(m_DataStatus == WARNING)
return false;
return true;
}
float NMEA_GPRMC::GetSpeed(Unit unit)
{
switch(unit)
{
case KNOTS:
return m_Speed;
case KMH:
return m_Speed * 1.852f;
case MPS:
return (m_Speed * 1.852f * 1000) / 3600;
default:
return -1.0f;
}
}
// NMEADecoder.h: interface for the NMEADecoder class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NMEADECODER_H__D8246292_B2EE_4ABC_AF00_AC546E7BB775__INCLUDED_)
#define AFX_NMEADECODER_H__D8246292_B2EE_4ABC_AF00_AC546E7BB775__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxtempl.h>
#include "NMEA.h"
#include "DataArea.h"
typedef CList<NMEA*, NMEA*> NMEAList;
class NMEADecoder
{
public:
NMEADecoder();
virtual ~NMEADecoder();
bool AddNMEADataFromSentence(const CString& strNMEASentence, bool bOnlyValid=true);
bool LoadNMEADataFromFile(const CString& strFilename, bool bOnlyValid=true);
void ClearData();
NMEA* GetFirst(NMEA::NMEAType Type=NMEA::ALL);
NMEA* GetNext(NMEA::NMEAType Type=NMEA::ALL);
void CalculateDataArea();
DataArea& GetDataArea() { return m_DataArea; }
double GetPathDistance(NMEA_GPRMC* pFrom, NMEA_GPRMC* pTo);
private:
NMEAList m_NMEAData;
POSITION m_Pos;
DataArea m_DataArea;
};
#endif // !defined(AFX_NMEADECODER_H__D8246292_B2EE_4ABC_AF00_AC546E7BB775__INCLUDED_)
// NMEADecoder.cpp: implementation of the NMEADecoder class.
//
//////////////////////////////////////////////////////////////////////
#include "NMEADecoder.h"
#include "../Utils/TextFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
NMEADecoder::NMEADecoder()
: m_Pos(NULL)
{
}
NMEADecoder::~NMEADecoder()
{
ClearData();
}
bool NMEADecoder::AddNMEADataFromSentence(const CString& strNMEASentence, bool bOnlyValid)
{
NMEA* pNMEA = NMEA::DecodeNMEAString(strNMEASentence);
if(pNMEA == NULL)
return false;
if(bOnlyValid==true && pNMEA->IsValid()==false)
{
delete pNMEA;
return false;
}
m_NMEAData.AddTail(pNMEA);
return true;
}
bool NMEADecoder::LoadNMEADataFromFile(const CString& strFilename, bool bOnlyValid)
{
CTextFile File;
CFileException FileException;
BOOL bOpen = File.Open(strFilename, CFile::modeRead | CFile::shareDenyWrite, &FileException);
if(!bOpen)
return false;
CString strLine;
while(!File.AtEnd())
{
strLine = File.ReadLine();
AddNMEADataFromSentence(strLine, bOnlyValid);
}
CalculateDataArea();
return true;
}
void NMEADecoder::ClearData()
{
POSITION pos = m_NMEAData.GetHeadPosition();
while(pos)
{
NMEA* pNMEA = m_NMEAData.GetNext(pos);
delete pNMEA;
}
m_NMEAData.RemoveAll();
}
NMEA* NMEADecoder::GetFirst(NMEA::NMEAType Type)
{
m_Pos = m_NMEAData.GetHeadPosition();
return GetNext(Type);
}
NMEA* NMEADecoder::GetNext(NMEA::NMEAType Type)
{
if(!m_Pos)
return NULL;
NMEA* pNMEA = m_NMEAData.GetNext(m_Pos);
if(pNMEA->GetType() == Type)
return pNMEA;
else
return GetNext(Type);
}
void NMEADecoder::CalculateDataArea()
{
NMEA_GPRMC* pNMEA = (NMEA_GPRMC*)GetFirst(NMEA::GPRMC);
m_DataArea.m_left = pNMEA->m_Coordinate.GetLatitude();
m_DataArea.m_right = pNMEA->m_Coordinate.GetLatitude();
m_DataArea.m_top = pNMEA->m_Coordinate.GetLongitude();
m_DataArea.m_bottom = pNMEA->m_Coordinate.GetLongitude();
pNMEA = (NMEA_GPRMC*)GetNext(NMEA::GPRMC);
while(pNMEA)
{
if(pNMEA->m_Coordinate.GetLatitude() < m_DataArea.m_left)
m_DataArea.m_left = pNMEA->m_Coordinate.GetLatitude();
else if(pNMEA->m_Coordinate.GetLatitude() > m_DataArea.m_right)
m_DataArea.m_right = pNMEA->m_Coordinate.GetLatitude();
if(pNMEA->m_Coordinate.GetLongitude() < m_DataArea.m_top)
m_DataArea.m_top = pNMEA->m_Coordinate.GetLongitude();
else if(pNMEA->m_Coordinate.GetLongitude() > m_DataArea.m_bottom)
m_DataArea.m_bottom = pNMEA->m_Coordinate.GetLongitude();
// Get next
pNMEA = (NMEA_GPRMC*)GetNext(NMEA::GPRMC);
}
}
double NMEADecoder::GetPathDistance(NMEA_GPRMC* pFrom, NMEA_GPRMC* pTo)
{
// Find pFrom
NMEA_GPRMC* pNMEA = (NMEA_GPRMC*)GetFirst(NMEA::GPRMC);
while(pNMEA && pNMEA != pFrom)
pNMEA = (NMEA_GPRMC*)GetNext(NMEA::GPRMC);
if(!pNMEA)
return -1.0;
// Found, now add distances until we get to pTo
double dPathDistance=0.0;
while(pNMEA && pNMEA != pTo)
{
NMEA_GPRMC* pLast = pNMEA;
pNMEA = (NMEA_GPRMC*)GetNext(NMEA::GPRMC);
if(!pNMEA)
return -1.0;
dPathDistance += pNMEA->m_Coordinate.Distance(pLast->m_Coordinate);
if(pNMEA == pTo)
break;
}
return dPathDistance;
}
// Position.h: interface for the Position class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_POSITION_H__89B4DA15_84DA_4BB4_93FE_E583C633AFC3__INCLUDED_)
#define AFX_POSITION_H__89B4DA15_84DA_4BB4_93FE_E583C633AFC3__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Afx.h>
typedef enum {NORTH, SOUTH, EAST, WEST} Direction;
class Position
{
friend class DataArea;
public:
Position();
virtual ~Position();
bool SetPositionFromString(CString& strPosition);
bool SetDirectionFromString(CString& strDirection);
CString GetDirectionString(bool bLongFormat=false);
CString ToString();
double ToRadians();
double ToDecimal();
int GetDegrees() { return m_Degrees; }
double GetMinutes() { return m_Minutes; }
Direction GetDirection() { return m_Direction; }
bool operator <(Position& position);
bool operator >(Position& position);
bool operator ==(Position& position);
protected:
int m_Degrees;
double m_Minutes;
Direction m_Direction;
};
#endif // !defined(AFX_POSITION_H__89B4DA15_84DA_4BB4_93FE_E583C633AFC3__INCLUDED_)
// Position.cpp: implementation of the Position class.
//
//////////////////////////////////////////////////////////////////////
#include "Position.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Position::Position()
: m_Direction(NORTH), m_Degrees(0), m_Minutes(0.0f)
{
}
Position::~Position()
{
}
bool Position::SetPositionFromString(CString& strPosition)
{
// Ex: 4250.5589
int sepPos = strPosition.Find('.');
if(sepPos < 2) // We require at least two digits before the '.'
return false;
m_Degrees = _ttoi(strPosition.Left(sepPos-2));
m_Minutes = (float)_tcstod(strPosition.Mid(sepPos-2), NULL);
return true;
}
bool Position::SetDirectionFromString(CString& strDirection)
{
if(strDirection.CompareNoCase(CString("N")) == 0 || strDirection.CompareNoCase(CString("NORTH")) == 0)
{
m_Direction = NORTH;
return true;
}
if(strDirection.CompareNoCase(CString("S")) == 0 || strDirection.CompareNoCase(CString("SOUTH")) == 0)
{
m_Direction = SOUTH;
return true;
}
if(strDirection.CompareNoCase(CString("E")) == 0 || strDirection.CompareNoCase(CString("EAST")) == 0)
{
m_Direction = EAST;
return true;
}
if(strDirection.CompareNoCase(CString("W")) == 0 || strDirection.CompareNoCase(CString("WEST")) == 0)
{
m_Direction = WEST;
return true;
}
return false;
}
CString Position::GetDirectionString(bool bLongFormat)
{
switch(m_Direction)
{
case NORTH:
if(bLongFormat)
return _T("North");
else
return _T("N");
case SOUTH:
if(bLongFormat)
return _T("South");
else
return _T("S");
case EAST:
if(bLongFormat)
return _T("East");
else
return _T("E");
case WEST:
if(bLongFormat)
return _T("West");
else
return _T("W");
default:
return _T("Undefined");
}
}
CString Position::ToString()
{
CString fmt;
fmt.Format(_T("%s %d %f"), GetDirectionString(), m_Degrees, m_Minutes);
return fmt;
}
double Position::ToRadians()
{
static double RADIANSPERDEGREE = 0.017453293;
return ToDecimal() * RADIANSPERDEGREE;
}
double Position::ToDecimal()
{
return m_Degrees + m_Minutes/60.0;
}
bool Position::operator <(Position& position)
{
return ToDecimal() < position.ToDecimal();
}
bool Position::operator >(Position& position)
{
return ToDecimal() > position.ToDecimal();
}
bool Position::operator ==(Position& position)
{
return ToDecimal() == position.ToDecimal();
}
// StringUtils.h: interface for the StringUtils class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_STRINGUTILS_H__4E6C9C5E_7DB4_45CC_928A_353E348FC90B__INCLUDED_)
#define AFX_STRINGUTILS_H__4E6C9C5E_7DB4_45CC_928A_353E348FC90B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <Afx.h>
#include <afxtempl.h>
typedef CList<CString,CString&> CTokenList;
class StringUtils
{
public:
StringUtils();
virtual ~StringUtils();
static int Tokenize(const CString& strInput, const CString& strSeparator, CTokenList& outputTokens);
};
#endif // !defined(AFX_STRINGUTILS_H__4E6C9C5E_7DB4_45CC_928A_353E348FC90B__INCLUDED_)
// StringUtils.cpp: implementation of the StringUtils class.
//
//////////////////////////////////////////////////////////////////////
#include "StringUtils.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
StringUtils::StringUtils()
{
}
StringUtils::~StringUtils()
{
}
int StringUtils::Tokenize(const CString& strInput, const CString& strSeparator, CTokenList& outputTokens)
{
int nTokenBegin=0;
int nTokenEnd=0;
int nTokensFound=0;
nTokenEnd = strInput.Find(strSeparator);
while(nTokenEnd != -1)
{
CString strToken = strInput.Mid(nTokenBegin, nTokenEnd-nTokenBegin);
outputTokens.AddTail(strToken);
++nTokensFound;
nTokenBegin = nTokenEnd + strSeparator.GetLength();
nTokenEnd = strInput.Find(strSeparator, nTokenBegin);
if(nTokenEnd == -1)
{
strToken = strInput.Mid(nTokenBegin, strInput.GetLength()-nTokenBegin);
outputTokens.AddTail(strToken);
++nTokensFound;
}
}
return nTokensFound;
}
// DataArea.h: interface for the DataArea class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DATAAREA_H__D74A2DFC_3023_41E0_8121_29E29B608861__INCLUDED_)
#define AFX_DATAAREA_H__D74A2DFC_3023_41E0_8121_29E29B608861__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Position.h"
class DataArea
{
public:
DataArea();
virtual ~DataArea();
double Width() { return m_right.ToDecimal()-m_left.ToDecimal(); }
double Height() { return m_bottom.ToDecimal()-m_top.ToDecimal(); }
CString ToString();
void InflateArea(int nDegrees, double dMinutes, double dNormalX=0.5, double dNormalY=0.5);
void DeflateArea(int nDegrees, double dMinutes, double dNormalX=0.5, double dNormalY=0.5);
Position m_left;
Position m_top;
Position m_right;
Position m_bottom;
};
#endif // !defined(AFX_DATAAREA_H__D74A2DFC_3023_41E0_8121_29E29B608861__INCLUDED_)
// DataArea.cpp: implementation of the DataArea class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DataArea.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DataArea::DataArea()
// : m_left(0.0), m_top(0.0), m_right(0.0), m_bottom(0.0)
{
}
DataArea::~DataArea()
{
}
CString DataArea::ToString()
{
CString fmt;
fmt.Format("left=%s, top=%s, right=%s, bottom=%s", m_left.ToString(), m_top.ToString(), m_right.ToString(), m_bottom.ToString());
return fmt;
}
void DataArea::InflateArea(int nDegrees, double dMinutes, double dNormalX, double dNormalY)
{
//m_left.m_Degrees -= nDegrees * (1.0-dNormalX);
m_left.m_Minutes -= (dMinutes * (1.0-dNormalX));
//m_top.m_Degrees -= nDegrees * (1.0-dNormalY);
m_top.m_Minutes -= (dMinutes * (1.0-dNormalY));
//m_right.m_Degrees += nDegrees * dNormalX;
m_right.m_Minutes += (dMinutes * dNormalX);
//m_bottom.m_Degrees += nDegrees * dNormalY;
m_bottom.m_Minutes += (dMinutes * dNormalY);
}
void DataArea::DeflateArea(int nDegrees, double dMinutes, double dNormalX, double dNormalY)
{
//m_left.m_Degrees += nDegrees * dNormalX;
m_left.m_Minutes += (dMinutes * dNormalX);
//m_top.m_Degrees += nDegrees * dNormalY;
m_top.m_Minutes += (dMinutes * dNormalY);
//m_right.m_Degrees -= nDegrees * (1.0-dNormalX);
m_right.m_Minutes -= (dMinutes * (1.0-dNormalX));
//m_bottom.m_Degrees -= nDegrees * (1.0-dNormalY);
m_bottom.m_Minutes -= (dMinutes * (1.0-dNormalY));
}