[mapguide-commits] r4375 - in trunk/MgDev/Common: CoordinateSystem Foundation Foundation/Exception Foundation/System Geometry Geometry/CoordinateSystem

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Dec 4 11:33:49 EST 2009


Author: NormOlsen
Date: 2009-12-04 11:33:48 -0500 (Fri, 04 Dec 2009)
New Revision: 4375

Added:
   trunk/MgDev/Common/Foundation/Exception/GridDensityException.cpp
   trunk/MgDev/Common/Foundation/Exception/GridDensityException.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrsGridSquarePosition.h
Modified:
   trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h
   trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp
   trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h
   trunk/MgDev/Common/Foundation/Foundation.h
   trunk/MgDev/Common/Foundation/Foundation.vcproj
   trunk/MgDev/Common/Foundation/FoundationBuild.cpp
   trunk/MgDev/Common/Foundation/Makefile.am
   trunk/MgDev/Common/Foundation/System/FoundationClassId.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemCommon.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemErrorCode.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h
   trunk/MgDev/Common/Geometry/Geometry.vcproj
   trunk/MgDev/Common/Geometry/GeometryCommon.h
   trunk/MgDev/Common/Geometry/Makefile.am
Log:
Testing has shown that the Grid/Graticule feature (RFC 76) needs to manage the amount of memory it consumes.  This is true as it is rather easy to make a request of the Grid/Graticule API to produce grids which are so dense they consume an extraordinary amount of memory.  Rather than place arbitrary limits on the functionality of the interface, it was decided to maintain the amount of memory used by the API and throw an exception when memory use exceeds certain limits.

Rather liberal limits are hard coded into the API so that applications would normally not need to concern themselves with this issue.  The API now provides a means by which these hard coded limits can be increased (or decreased) at run time on a grid by grid basis.  Additionally, AIP functions have been added so that an application can obtain an estimate of the amount of memory will be required to comply with a request of the interface.  THus, systems which have sufficiant memory to accomodate dense grid generation can easily be porogrammed to do so.  Thus, the memory situation can be easily managed without coding artificially limits to the capabilities of the grid/graticule API.

The hard coded limits are currently set at 50MB for grid lines, 20MB for grid ticks, and 100MB for MGRS regions.  It turns out that the MGRS regions are the real memory pigs, perhaps some design changes to improve memory efficiently here will be implemented over time.

As this implementation changed the API of the entire Grid interface, an additional change is included to facilitate application development (since API changes can be rather painful at the development level).  This change is to add one published (and two internal) interfaces to the MGRS string to longitude and latitude functionality.  The new functionality enables the calling application to specify one of nine positions within the reference MGRS grid cell whose position is to be returned.


Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -26,10 +26,17 @@
 
 using namespace CSLibrary;
 
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+const INT32 CCoordinateSystemGridGeneric::m_GridLineExceptionLevelK   =  50000000L;     //   50MB
+const INT32 CCoordinateSystemGridGeneric::m_GridRegionExceptionLevelK =  50000000L;      //  50MB
+const INT32 CCoordinateSystemGridGeneric::m_GridTickExceptionLevelK   =  20000000L;      //  20MB
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 CCoordinateSystemGridGeneric::CCoordinateSystemGridGeneric(bool bSetExceptionsOn)
                             :
-                       m_bExceptionsOn (bSetExceptionsOn),
+                       m_bExceptionsOn            (bSetExceptionsOn),
+                       m_GridLineExceptionLevel   (m_GridLineExceptionLevelK),
+                       m_GridRegionExceptionLevel (m_GridRegionExceptionLevelK),
+                       m_GridTickExceptionLevel   (m_GridTickExceptionLevelK),
                        m_nLastError    (0),
                        m_pCsSource     (),
                        m_pCsTarget     (),
@@ -41,7 +48,10 @@
                                                            MgCoordinateSystem* pTargetCs,
                                                            bool bSetExceptionsOn)
                             :
-                       m_bExceptionsOn (bSetExceptionsOn),
+                       m_bExceptionsOn            (bSetExceptionsOn),
+                       m_GridLineExceptionLevel   (m_GridLineExceptionLevelK),
+                       m_GridRegionExceptionLevel (m_GridRegionExceptionLevelK),
+                       m_GridTickExceptionLevel   (m_GridTickExceptionLevelK),
                        m_nLastError    (0),
                        m_pCsSource     (),
                        m_pCsTarget     (),
@@ -66,6 +76,8 @@
 {
     m_FrameBoundary = SAFE_ADDREF (pFrameBoundary);
     m_TheGrid = new CCoordinateSystemOneGrid (m_FrameBoundary,m_pCsSource,m_pCsTarget);
+    m_TheGrid->SetGridLineExceptionLevel (m_GridLineExceptionLevel);
+    m_TheGrid->SetGridTickExceptionLevel (m_GridTickExceptionLevel);
 }
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 MgCoordinateSystemGridBoundary* CCoordinateSystemGridGeneric::GetBoundary(void)
@@ -97,13 +109,90 @@
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 double CCoordinateSystemGridGeneric::GetConvergenceAngle (MgCoordinate* location)
 {
-    return 0.0;
+    double longitude;
+    double latitude;
+    double convergence;
+
+    longitude = location->GetX ();
+    latitude  = location->GetY ();
+    convergence = m_pCsTarget->GetConvergence (longitude,latitude);
+    return convergence;
 }
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 double CCoordinateSystemGridGeneric::GetProjectiveGridScale (MgCoordinate* location)
 {
-    return 1.0;
+    double longitude;
+    double latitude;
+    double scale;
+
+    longitude = location->GetX ();
+    latitude  = location->GetY ();
+    scale = m_pCsTarget->GetScale (longitude,latitude);
+    return scale;
 }
+INT32 CCoordinateSystemGridGeneric::ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 memoryUse (-1);
+
+    if (m_FrameBoundary != 0)
+    {
+        memoryUse = m_TheGrid->ApproxGridLineMemoryUsage (specification);
+    }
+    return memoryUse;
+}
+INT32 CCoordinateSystemGridGeneric::ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 memoryUse;
+    
+    memoryUse = (m_FrameBoundary != 0) ? 0 : -1;
+    return memoryUse;
+}
+INT32 CCoordinateSystemGridGeneric::ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 memoryUse (-1);
+
+    if (m_FrameBoundary != 0)
+    {
+        memoryUse = m_TheGrid->ApproxGridTickMemoryUsage (specification);
+    }
+    return memoryUse;
+}
+INT32 CCoordinateSystemGridGeneric::SetGridLineExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridLineExceptionLevel;
+    if (memoryUseMax > 0)
+    {
+        m_GridLineExceptionLevel = memoryUseMax;
+        if (m_TheGrid != 0)
+        {
+            m_TheGrid->SetGridLineExceptionLevel (m_GridLineExceptionLevel);
+        }
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemGridGeneric::SetGridRegionExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridRegionExceptionLevel;
+    if (memoryUseMax > 0)
+    {
+        m_GridRegionExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemGridGeneric::SetGridTickExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridTickExceptionLevel;
+    if (memoryUseMax > 0)
+    {
+        m_GridTickExceptionLevel = memoryUseMax;
+        if (m_TheGrid != 0)
+        {
+            m_TheGrid->SetGridTickExceptionLevel (m_GridTickExceptionLevel);
+        }
+    }
+    return rtnValue;
+}
+
 INT32 CCoordinateSystemGridGeneric::GetLastError()
 {
     return m_nLastError;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGridGeneric.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -25,6 +25,9 @@
 
 class CCoordinateSystemGridGeneric : public MgCoordinateSystemGridGeneric
 {
+    static const INT32 m_GridLineExceptionLevelK;
+    static const INT32 m_GridRegionExceptionLevelK;
+    static const INT32 m_GridTickExceptionLevelK;
 public:
     CCoordinateSystemGridGeneric(bool bSetExceptionsOn);
     CCoordinateSystemGridGeneric(MgCoordinateSystem* pSourceCs,MgCoordinateSystem* pTargetCs,bool bSetExceptionsOn);
@@ -40,6 +43,14 @@
     double GetConvergenceAngle (MgCoordinate* location);
     double GetProjectiveGridScale (MgCoordinate* location);
 
+    INT32 ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+    INT32 ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+    INT32 ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+
+    INT32 SetGridLineExceptionLevel (INT32 memoryUseMax);
+    INT32 SetGridRegionExceptionLevel (INT32 memoryUseMax);
+    INT32 SetGridTickExceptionLevel (INT32 memoryUseMax);
+
     INT32 GetLastError();
     void ResetLastError();
     bool AreExceptionsOn();
@@ -49,8 +60,15 @@
     //from MgDisposable
     void Dispose();
 
-    // Data Memebrs
+    // Data Memebers -- The m_GridRegionExcpetionLevel member is not really
+    // applicable to generic grids.  However, since the ApproxGridRegionMemoryUsage
+    // and SetGridRegionExceptionLevel functions are pure virtual functions in the
+    // interface, the functions need to exist.  So, for now we _pretend_ that
+    // the 'Region' memory limits are applicable to generic grids.
     bool m_bExceptionsOn;
+    INT32 m_GridLineExceptionLevel;
+    INT32 m_GridRegionExceptionLevel;
+    INT32 m_GridTickExceptionLevel;
     INT32 m_nLastError;
     Ptr<MgCoordinateSystem> m_pCsSource;
     Ptr<MgCoordinateSystem> m_pCsTarget;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -50,7 +50,8 @@
                                                                                 m_TickEastingIncrement  (0),
                                                                                 m_TickNorthingIncrement (0),
                                                                                 m_UnitType              (MgCoordinateSystemUnitType::Linear),
-                                                                                m_UnitCode              (MgCoordinateSystemUnitCode::Meter)
+                                                                                m_UnitCode              (MgCoordinateSystemUnitCode::Meter),
+                                                                                m_MaxCurvePoints        (0)
 {
 }
 CCoordinateSystemGridSpecification::CCoordinateSystemGridSpecification (const CCoordinateSystemGridSpecification& source)
@@ -63,7 +64,8 @@
                                                                         m_TickEastingIncrement  (source.m_TickEastingIncrement),
                                                                         m_TickNorthingIncrement (source.m_TickNorthingIncrement),
                                                                         m_UnitType              (source.m_UnitType),
-                                                                        m_UnitCode              (source.m_UnitCode)
+                                                                        m_UnitCode              (source.m_UnitCode),
+                                                                        m_MaxCurvePoints        (source.m_MaxCurvePoints)
 {
 }
 CCoordinateSystemGridSpecification::~CCoordinateSystemGridSpecification (void)
@@ -82,6 +84,7 @@
         m_TickNorthingIncrement = rhs.m_TickNorthingIncrement;
         m_UnitType              = rhs.m_UnitType;
         m_UnitCode              = rhs.m_UnitCode;
+        m_MaxCurvePoints        = rhs.m_MaxCurvePoints;
     }
     return *this;
 }
@@ -117,6 +120,14 @@
 {
     return m_UnitCode;
 }
+double CCoordinateSystemGridSpecification::GetCurvePrecision(void)
+{
+    return m_CurvePrecision;
+}
+INT32 CCoordinateSystemGridSpecification::GetMaxCurvePoints(void)
+{
+    return m_MaxCurvePoints;
+}
 bool CCoordinateSystemGridSpecification::IsSameAs(MgCoordinateSystemGridSpecification* specification)
 {
     bool areTheSame (false);
@@ -138,10 +149,6 @@
 
     return areTheSame;
 }
-double CCoordinateSystemGridSpecification::GetCurvePrecision(void)
-{
-    return m_CurvePrecision;
-}
 
 void CCoordinateSystemGridSpecification::SetGridBase(double eastingBase,double northingBase)
 {
@@ -177,6 +184,10 @@
 {
     m_CurvePrecision = curvePrecision;
 }
+void CCoordinateSystemGridSpecification::SetMaxCurvePoints (INT32 maxCurvePoints)
+{
+    m_CurvePrecision = maxCurvePoints;
+}
 // The following functions are identical to the published version, with the
 // exception that the values returned are always converted to the units requested
 // by the resultUnitCode argument.
@@ -258,6 +269,25 @@
     precisionInCsUnits = precisionInMeters * csUnitConversion;
     return precisionInCsUnits;
 }
+double CCoordinateSystemGridSpecification::GetCurvePrecision (MgCoordinateSystemGridBoundary* gridBoundary,
+                                                              MgCoordinateSystem* gridCS)
+{
+    double precisionInCsUnits;
+
+    precisionInCsUnits = GetCurvePrecision (gridCS);
+    return precisionInCsUnits;
+}
+double CCoordinateSystemGridSpecification::GetMaxCurvePoints (MgCoordinateSystemGridBoundary* frameBoundary,
+                                                              MgCoordinateSystem* frameCS)
+{
+    INT32 maxPoints (511);
+
+    if (m_MaxCurvePoints > 0)
+    {
+        maxPoints = m_MaxCurvePoints;
+    }
+    return maxPoints;
+}
 bool CCoordinateSystemGridSpecification::IsConsistent ()
 {
     bool ok (false);
@@ -630,6 +660,28 @@
 {
     return SAFE_ADDREF(m_LineSegments.p);
 }
+INT32 CCoordinateSystemGridLine::GetMemoryUsage ()
+{
+    static const INT32 sizeOfMgCoordinateXY = 24;
+    INT32 lineIndex;
+    INT32 lineCount;
+    INT32 memoryUse = sizeof (CCoordinateSystemGridLine);
+
+    lineCount = m_LineSegments->GetCount ();
+    for (lineIndex = 0;lineIndex < lineCount;lineIndex += 1)
+    {
+        Ptr<MgLineString> lineStringPtr = m_LineSegments->GetItem (lineIndex);
+        if (lineStringPtr != 0)
+        {
+            Ptr<MgCoordinateIterator> pointItr = lineStringPtr->GetCoordinates ();
+            while (pointItr->MoveNext ())
+            {
+                memoryUse += sizeOfMgCoordinateXY;
+            }
+        }
+    }
+    return memoryUse;
+}
 void CCoordinateSystemGridLine::SetSegmentCollection (MgLineStringCollection* segmentCollection)
 {
     m_LineSegments = SAFE_ADDREF (segmentCollection);
@@ -645,7 +697,7 @@
 void CCoordinateSystemGridLine::ClearSegments (void)
 {
     m_LineSegments->Clear ();
-}    
+}
 void CCoordinateSystemGridLine::AddSegment (MgLineString* newSegment)
 {
     m_LineSegments->Add (newSegment);
@@ -752,7 +804,22 @@
 {
     return SAFE_ADDREF(m_WestLine.p);
 }
+INT32 CCoordinateSystemGridRegion::GetMemoryUsage ()
+{
+    INT32 memoryUse;
+    static const INT32 sizeOfMgCoordinateXY = 24;
 
+    memoryUse  = sizeof (CCoordinateSystemGridRegion);
+    memoryUse += sizeof (STRING);
+    memoryUse += m_RegionLabel.capacity () * sizeof (wchar_t);
+    memoryUse += sizeOfMgCoordinateXY;
+    memoryUse += PolygonMemoryUse (m_RegionBoundary.p);
+    memoryUse += LineStringCollectionMemoryUse (m_SouthLine.p);
+    memoryUse += LineStringCollectionMemoryUse (m_EastLine.p);
+    memoryUse += LineStringCollectionMemoryUse (m_NorthLine.p);
+    memoryUse += LineStringCollectionMemoryUse (m_WestLine.p);
+    return memoryUse;
+}
 void CCoordinateSystemGridRegion::SetRegionBoundary (MgPolygon* boundary)
 {
     m_RegionBoundary = SAFE_ADDREF (boundary);
@@ -777,6 +844,51 @@
 {
     delete this;
 }
+INT32 CCoordinateSystemGridRegion::PolygonMemoryUse (MgPolygon* polygon)
+{
+    // WHile MgPolygon objects support holes, there are no holes in a Region
+    // (so far anyway); so we only evaluate the exterior ring.
+
+    static const INT32 sizeOfMgCoordinateXY = 24;
+    INT32 memoryUse (0);
+
+    if (polygon != 0)
+    {
+        Ptr<MgCoordinateIterator> pointItr = polygon->GetCoordinates ();
+        while (pointItr->MoveNext ())
+        {
+            memoryUse += sizeOfMgCoordinateXY;
+        }
+    }
+    return memoryUse;
+}
+INT32 CCoordinateSystemGridRegion::LineStringCollectionMemoryUse (MgLineStringCollection* lineCollection)
+{
+    static const INT32 sizeOfMgCoordinateXY = 24;
+    INT32 memoryUse (0);
+    INT32 lineCount;
+    INT32 lineIndex;
+
+    if (lineCollection != 0)
+    {
+        memoryUse += sizeof (MgLineStringCollection);
+        lineCount = lineCollection->GetCount ();
+        for (lineIndex = 0;lineIndex < lineCount;lineIndex += 1)
+        {
+            Ptr<MgLineString> lineStringPtr = lineCollection->GetItem (lineIndex);
+            if (lineStringPtr != 0)
+            {
+                memoryUse += sizeof (MgLineString);
+                Ptr<MgCoordinateIterator> pointItr = lineStringPtr->GetCoordinates ();
+                while (pointItr->MoveNext ())
+                {
+                    memoryUse += sizeOfMgCoordinateXY;
+                }
+            }
+        }
+    }
+    return memoryUse;
+}
 //=============================================================================
 // CCoordinateSystemGridTick -- Defines the location of a grid tick mark.
 //
@@ -840,6 +952,13 @@
 {
     return SAFE_ADDREF(m_Direction.p);
 }
+INT32 CCoordinateSystemGridTick::GetMemoryUsage ()
+{
+    static const INT32 MgSizeOfCoordinateXY = 24;
+    INT32 memoryUse = sizeof (CCoordinateSystemGridTick);
+    memoryUse += 2 * MgSizeOfCoordinateXY;
+    return memoryUse;
+}
 void CCoordinateSystemGridTick::Dispose ()
 {
     delete this;
@@ -850,10 +969,12 @@
 // appear first in ascending order by grid value (easting in this case);
 // followed by grid vertical lines in ascending order by grid value (northing
 // in this case).
-CCoordinateSystemGridLineCollection::CCoordinateSystemGridLineCollection (void)
+CCoordinateSystemGridLineCollection::CCoordinateSystemGridLineCollection (INT32 gridLineExceptionLevel)
                                         :
                                      MgCoordinateSystemGridLineCollection (),
-                                     m_GridLineCollection ()
+                                     m_MemoryUse                          (0),
+                                     m_GridLineExceptionLevel             (gridLineExceptionLevel),
+                                     m_GridLineCollection                 ()
 {
     m_GridLineCollection = new MgDisposableCollection();
 }
@@ -904,14 +1025,24 @@
 }
 void CCoordinateSystemGridLineCollection::RemoveAt (INT32 index)
 {
+    INT32 memoryUse (0);
+
     // The MgDisposableCollection object checks the index argument, and throws if appropriate.
     // The MgDisposableCollection object performs the "SAFE_RELEASE" operation.
+
+    Ptr<MgCoordinateSystemGridLine> gridLinePtr = this->GetItem (index);
+    if (gridLinePtr != 0)
+    {
+        memoryUse = gridLinePtr->GetMemoryUsage ();
+    }
     m_GridLineCollection->RemoveAt (index);
+    m_MemoryUse -= memoryUse;
 }
 void CCoordinateSystemGridLineCollection::Clear()
 {
     // The MgDisposableCollection object performs the "SAFE_RELEASE" operation.
     m_GridLineCollection->Clear ();
+    m_MemoryUse = 0;
 }
 void CCoordinateSystemGridLineCollection::SetItem (INT32 index,MgCoordinateSystemGridLine* value)
 {
@@ -921,6 +1052,19 @@
 }
 void CCoordinateSystemGridLineCollection::Add (MgCoordinateSystemGridLine* value)
 {
+    INT32 memoryUse;
+
+    memoryUse = value->GetMemoryUsage ();
+    if ((memoryUse + m_MemoryUse) < m_GridLineExceptionLevel)
+    {
+        m_GridLineCollection->Add (value);
+        m_MemoryUse += memoryUse;
+    }
+    else
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridLineCollection.Add", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
+
     // The MgDIsposableCollection object does the "SAFE_ADDREF" operation.
     m_GridLineCollection->Add (value);
 }
@@ -935,12 +1079,24 @@
         for (index = 0;index < toAddCount;index += 1)
         {
             aGridLine = aGridLineCollection->GetItem (index);
-            // This Add refers to the "this" object.
-            m_GridLineCollection->Add (aGridLine);
+            this->Add (aGridLine);
         }
     MG_CATCH_AND_THROW(L"CCoordinateSystemGridLineCollection::IndexOf")
     return;
 }
+INT32 CCoordinateSystemGridLineCollection::SetGridLineExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridLineExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridLineExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemGridLineCollection::GetMemoryUsage (void)
+{
+    return m_MemoryUse;
+}
 void CCoordinateSystemGridLineCollection::Dispose(void)
 {
     delete this;
@@ -949,10 +1105,12 @@
 //=============================================================================
 // A CCoordinateSystemGridRegionCollection is collection of
 // CCoordinateSystemGridRegion objects.
-CCoordinateSystemGridRegionCollection::CCoordinateSystemGridRegionCollection ()
+CCoordinateSystemGridRegionCollection::CCoordinateSystemGridRegionCollection (INT32 gridRegionExceptionLevel)
                                          :
                                        MgCoordinateSystemGridRegionCollection (),
-                                       m_GridRegionCollection ()
+                                       m_MemoryUse                            (0),
+                                       m_GridRegionExceptionLevel             (gridRegionExceptionLevel),
+                                       m_GridRegionCollection                 ()
 {
     m_GridRegionCollection = new MgDisposableCollection();
 }
@@ -981,17 +1139,42 @@
 void CCoordinateSystemGridRegionCollection::Clear()
 {
     m_GridRegionCollection->Clear ();
+    m_MemoryUse = 0;
 }
 void CCoordinateSystemGridRegionCollection::SetItem (INT32 index, MgCoordinateSystemGridRegion* value)
 {
-    // The MgDisposableCollection object checks the index argument, and throws if appropriate.
-    // The MgDisposableCollection object performs the "SAFE_RELEASE" & "SAFE_ADDREF" operations.
-    m_GridRegionCollection->SetItem (index,value);
+    INT32 memoryUse;
+
+    Ptr<MgCoordinateSystemGridRegion> currentPtr = static_cast<MgCoordinateSystemGridRegion*>(m_GridRegionCollection->GetItem (index));
+    if (currentPtr != 0)
+    {
+        m_MemoryUse -= currentPtr->GetMemoryUsage ();
+    }
+    memoryUse = value->GetMemoryUsage ();
+    if ((memoryUse + m_MemoryUse) < m_GridRegionExceptionLevel)
+    {
+        m_GridRegionCollection->SetItem (index,value);
+        m_MemoryUse += memoryUse;
+    }
+    else
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridRegionCollection.SetItem", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
 }
 void CCoordinateSystemGridRegionCollection::Add (MgCoordinateSystemGridRegion* value)
 {
-    // The MgDisposableCollection object performs the "SAFE_ADDREF" operation.
-    m_GridRegionCollection->Add (value);
+    INT32 memoryUse;
+
+    memoryUse = value->GetMemoryUsage ();
+    if ((memoryUse + m_MemoryUse) < m_GridRegionExceptionLevel)
+    {
+        m_GridRegionCollection->Add (value);
+        m_MemoryUse += memoryUse;
+    }
+    else
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridRegionCollection.Add", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
 }
 void CCoordinateSystemGridRegionCollection::AddCollection (MgCoordinateSystemGridRegionCollection* aGridRegionCollection)
 {
@@ -1005,11 +1188,24 @@
         {
             aGridRegion = aGridRegionCollection->GetItem (index);
             // This Add refers to the "this" object.
-            m_GridRegionCollection->Add (aGridRegion);
+            this->Add (aGridRegion);
         }
     MG_CATCH_AND_THROW(L"CCoordinateSystemGridRegionCollection::AddCollection")
     return;
 }
+INT32 CCoordinateSystemGridRegionCollection::SetGridRegionExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridRegionExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridRegionExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemGridRegionCollection::GetMemoryUsage (void)
+{
+    return m_MemoryUse;
+}
 void CCoordinateSystemGridRegionCollection::Dispose (void)
 {
     // Destructor deletes the contents of the collection.
@@ -1021,10 +1217,12 @@
 // CCoordinateSystemGridTick objects.  CCoordinateSystemGridTickCollection
 // objects will contain MgCoordinateSystemGridTick objects for the entire
 // boundary or for an individual grid line.
-CCoordinateSystemGridTickCollection::CCoordinateSystemGridTickCollection (void)
+CCoordinateSystemGridTickCollection::CCoordinateSystemGridTickCollection (INT32 gridTickExceptionLevel)
                                         :
                                      MgCoordinateSystemGridTickCollection (),
-                                     m_GridTickCollection ()
+                                     m_MemoryUse                          (0),
+                                     m_GridTickExceptionLevel             (gridTickExceptionLevel),
+                                     m_GridTickCollection                 ()
 {
     m_GridTickCollection = new MgDisposableCollection();
 }
@@ -1049,6 +1247,7 @@
 void CCoordinateSystemGridTickCollection::Clear()
 {
     m_GridTickCollection->Clear ();
+    m_MemoryUse = 0;
 }
 void CCoordinateSystemGridTickCollection::SetItem (INT32 index, MgCoordinateSystemGridTick* value)
 {
@@ -1056,7 +1255,18 @@
 }
 void CCoordinateSystemGridTickCollection::Add (MgCoordinateSystemGridTick* value)
 {
-    m_GridTickCollection->Add (value);
+    INT32 memoryUse;
+
+    memoryUse = value->GetMemoryUsage ();
+    if ((memoryUse + m_MemoryUse) < m_GridTickExceptionLevel)
+    {
+        m_GridTickCollection->Add (value);
+        m_MemoryUse += memoryUse;
+    }
+    else
+    {
+        throw new MgGridDensityException(L"CCoordinateSystemGridTickCollection.Add", __LINE__, __WFILE__, NULL, L"", NULL);
+    }
 }
 void CCoordinateSystemGridTickCollection::AddCollection (MgCoordinateSystemGridTickCollection* aGridTickCollection)
 {
@@ -1069,11 +1279,24 @@
         for (index = 0;index < toAddCount;index += 1)
         {
             aGridTick = aGridTickCollection->GetItem (index);
-            m_GridTickCollection->Add (aGridTick);
+            this->Add (aGridTick);
         }
     MG_CATCH_AND_THROW(L"CCoordinateSystemGridTickCollection::AddCollection")
     return;
 }
+INT32 CCoordinateSystemGridTickCollection::SetGridTickExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridTickExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridTickExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemGridTickCollection::GetMemoryUsage ()
+{
+    return m_MemoryUse;
+}
 void CCoordinateSystemGridTickCollection::Dispose (void)
 {
     delete this;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysGrids.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -43,12 +43,14 @@
     INT32 GetUnitCode(void);
     bool IsSameAs(MgCoordinateSystemGridSpecification* specification);
     double GetCurvePrecision(void);
+    INT32 GetMaxCurvePoints(void);
 
     void SetGridBase(double eastingBase,double northingBase);
     void SetGridIncrement(double eastingIncrement,double northingIncrement);
     void SetTickIncrements(double eastingIncrement,double northingIncrement);
     void SetUnits (INT32 unitCode,INT32 unitType = MgCoordinateSystemUnitType::Linear);
     void SetCurvePrecision (double curvePrecision);
+    void SetMaxCurvePoints (INT32 maxCurvePoints);
 
     // The following function identically to the published version, with the
     // exception that the value returned is always converted to the units
@@ -60,10 +62,15 @@
     double GetTickEastingIncrement (INT32 resultUnitCode);
     double GetTickNorthingIncrement (INT32 resultUnitCode);
 
-    // This function will generate a suitable value if the host application
+    // These functions will generate a suitable value if the host application
     // left the curve precision unspecified.
     double GetCurvePrecision(MgCoordinateSystem* gridCS);
+    double GetCurvePrecision(MgCoordinateSystemGridBoundary* gridBoundary,MgCoordinateSystem* gridCS);
 
+    // This function will generate a suitable value if the host application
+    // left the max curve points unspecified.
+    double GetMaxCurvePoints (MgCoordinateSystemGridBoundary* frameBoundary,MgCoordinateSystem* frameCS);
+
     // The following is used by the CoordinateSystemFactory object to verify
     // that all of the information provided to it is consistent with the
     // requirements of the object.
@@ -83,6 +90,7 @@
     double m_TickNorthingIncrement;
     INT32 m_UnitType;
     INT32 m_UnitCode;
+    INT32 m_MaxCurvePoints;
 };
 
 //=============================================================================
@@ -277,6 +285,7 @@
     INT32 GetCount (void);
     MgLineString* GetSegment (INT32 index);
     MgLineStringCollection* GetSegmentCollection (void);
+    INT32 GetMemoryUsage (void);
 
     void SetGridOrientation (INT32 orientation);
     void SetRealValue (double realValue);
@@ -318,6 +327,7 @@
     MgLineStringCollection* GetEastLine (void);
     MgLineStringCollection* GetNorthLine (void);
     MgLineStringCollection* GetWestLine (void);
+    INT32 GetMemoryUsage (void);
 
     void SetRegionBoundary (MgPolygon* boundary);
     void SetSouthLine (MgLineStringCollection* southLine);
@@ -335,7 +345,10 @@
     Ptr<MgLineStringCollection> m_NorthLine;
     Ptr<MgLineStringCollection> m_WestLine;
 
-private:            // Not implemented
+private:
+    INT32 PolygonMemoryUse (MgPolygon* polygon);
+    INT32 LineStringCollectionMemoryUse (MgLineStringCollection* lineCollection);
+    // Not implemented
     CCoordinateSystemGridRegion (void);
     CCoordinateSystemGridRegion (const CCoordinateSystemGridRegion& source);
 };
@@ -361,6 +374,7 @@
     double GetValue (void);
     MgCoordinate* GetPosition (void);
     MgCoordinate* GetDirectionVector (void);
+    INT32 GetMemoryUsage (void);
 
 protected:
     void Dispose (void);
@@ -385,7 +399,7 @@
 class CCoordinateSystemGridLineCollection : public MgCoordinateSystemGridLineCollection
 {
 public:
-    CCoordinateSystemGridLineCollection (void);
+    CCoordinateSystemGridLineCollection (INT32 gridLineExceptionLevel);
     ~CCoordinateSystemGridLineCollection(void);
 
     INT32 GetCount () const;
@@ -397,10 +411,17 @@
     void SetItem (INT32 index,MgCoordinateSystemGridLine* value);
     void Add (MgCoordinateSystemGridLine* value);
     void AddCollection (MgCoordinateSystemGridLineCollection* aGridLineCollection);
+    INT32 SetGridLineExceptionLevel (INT32 memoryUseMax);
+    INT32 GetMemoryUsage (void);
+
 protected:
     void Dispose(void);
+    INT32 m_MemoryUse;
+    INT32 m_GridLineExceptionLevel;
     Ptr<MgDisposableCollection> m_GridLineCollection;
+
 private:
+    // Not Implemented
     CCoordinateSystemGridLineCollection (const CCoordinateSystemGridLineCollection& source);
     CCoordinateSystemGridLineCollection& operator= (const CCoordinateSystemGridLineCollection& rhs);
 };
@@ -411,7 +432,7 @@
 class CCoordinateSystemGridRegionCollection : public MgCoordinateSystemGridRegionCollection
 {
 public:
-    CCoordinateSystemGridRegionCollection (void);
+    CCoordinateSystemGridRegionCollection (INT32 gridRegionExceptionLevel);
     ~CCoordinateSystemGridRegionCollection (void);
 
     INT32 GetCount () const;
@@ -422,11 +443,17 @@
     void SetItem (INT32 index, MgCoordinateSystemGridRegion* value);
     void Add (MgCoordinateSystemGridRegion* value);
     void AddCollection (MgCoordinateSystemGridRegionCollection* aGridRegionCollection);
+    INT32 SetGridRegionExceptionLevel (INT32 memoryUseMax);
+    INT32 GetMemoryUsage (void);
 
 protected:
     void Dispose (void);
+    INT32 m_MemoryUse;
+    INT32 m_GridRegionExceptionLevel;
     Ptr<MgDisposableCollection> m_GridRegionCollection;
+
 private:
+    // Not Implemented
     CCoordinateSystemGridRegionCollection (const CCoordinateSystemGridRegionCollection& source);
     CCoordinateSystemGridRegionCollection& operator= (const CCoordinateSystemGridRegionCollection& rhs);
 };
@@ -439,7 +466,7 @@
 class CCoordinateSystemGridTickCollection : public MgCoordinateSystemGridTickCollection 
 {
 public:
-    CCoordinateSystemGridTickCollection (void);
+    CCoordinateSystemGridTickCollection (INT32 gridLineExceptionLevel);
     ~CCoordinateSystemGridTickCollection (void);
 
     INT32 GetCount () const;
@@ -449,12 +476,17 @@
     void SetItem (INT32 index, MgCoordinateSystemGridTick* value);
     void Add (MgCoordinateSystemGridTick* value);
     void AddCollection (MgCoordinateSystemGridTickCollection* aGridTickCollection);
+    INT32 SetGridTickExceptionLevel (INT32 memoryUseMax);
+    INT32 GetMemoryUsage (void);
 
 protected:
     void Dispose (void);
+    INT32 m_MemoryUse;
+    INT32 m_GridTickExceptionLevel;
     Ptr<MgDisposableCollection> m_GridTickCollection;
 
 private:
+    // Not Implemented
     CCoordinateSystemGridTickCollection (const CCoordinateSystemGridTickCollection& source);
     CCoordinateSystemGridTickCollection& operator= (const CCoordinateSystemGridTickCollection& rhs);  
 };

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -27,6 +27,10 @@
 
 using namespace CSLibrary;
 
+const INT32 CCoordinateSystemMgrs::m_GridLineExceptionLevelK   =  50000000L;    //  50MB
+const INT32 CCoordinateSystemMgrs::m_GridRegionExceptionLevelK = 100000000L;    // 100MB
+const INT32 CCoordinateSystemMgrs::m_GridTickExceptionLevelK   =  20000000L;    //  20MB
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Static constants.
 const CCoordinateSystemMgrs::CCoordinateSystemMgrsSeries CCoordinateSystemMgrs::MgrsSeriesNormal [6] =
@@ -62,33 +66,39 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
 CCoordinateSystemMgrs::CCoordinateSystemMgrs(INT8 nLetteringScheme, bool bSetExceptionsOn)
                             :
-                       m_nLetteringScheme(nLetteringScheme),
-                       m_bExceptionsOn (bSetExceptionsOn),
-                       m_bUseFrameDatum (false),
-                       m_nLastError (0),
-                       m_pCsTarget (),
-                       m_pCsMgrs (NULL),
-                       m_GridBoundary (),
-                       m_ZoneCollection (),
-                       m_GraticuleUtm (),
-                       m_GraticuleUpsNorth (),
-                       m_GraticuleUpsSouth ()
+                       m_nLetteringScheme         (nLetteringScheme),
+                       m_bExceptionsOn            (bSetExceptionsOn),
+                       m_bUseFrameDatum           (false),
+                       m_GridLineExceptionLevel   (m_GridLineExceptionLevelK),
+                       m_GridRegionExceptionLevel (m_GridRegionExceptionLevelK),
+                       m_GridTickExceptionLevel   (m_GridTickExceptionLevelK),
+                       m_nLastError               (0),
+                       m_pCsTarget                (),
+                       m_pCsMgrs                  (NULL),
+                       m_GridBoundary             (),
+                       m_ZoneCollection           (),
+                       m_GraticuleUtm             (),
+                       m_GraticuleUpsNorth        (),
+                       m_GraticuleUpsSouth        ()
 {
 }
 CCoordinateSystemMgrs::CCoordinateSystemMgrs(MgCoordinateSystem* pTargetCs,INT8 nLetteringScheme,
                                                                            bool bSetExceptionsOn)
                             :
-                       m_nLetteringScheme(nLetteringScheme),
-                       m_bExceptionsOn (bSetExceptionsOn),
-                       m_bUseFrameDatum (false),
-                       m_nLastError (0),
-                       m_pCsTarget (),
-                       m_pCsMgrs (NULL),
-                       m_GridBoundary (),
-                       m_ZoneCollection (),
-                       m_GraticuleUtm (),
-                       m_GraticuleUpsNorth (),
-                       m_GraticuleUpsSouth ()
+                       m_nLetteringScheme         (nLetteringScheme),
+                       m_bExceptionsOn            (bSetExceptionsOn),
+                       m_bUseFrameDatum           (false),
+                       m_GridLineExceptionLevel   (m_GridLineExceptionLevelK),
+                       m_GridRegionExceptionLevel (m_GridRegionExceptionLevelK),
+                       m_GridTickExceptionLevel   (m_GridTickExceptionLevelK),
+                       m_nLastError               (0),
+                       m_pCsTarget                (),
+                       m_pCsMgrs                  (NULL),
+                       m_GridBoundary             (),
+                       m_ZoneCollection           (),
+                       m_GraticuleUtm             (),
+                       m_GraticuleUpsNorth        (),
+                       m_GraticuleUpsSouth        ()
 
 {
     m_pCsTarget = SAFE_ADDREF (pTargetCs);
@@ -244,8 +254,15 @@
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 MgCoordinate* CCoordinateSystemMgrs::ConvertToLonLat(CREFSTRING sMgrs)
 {
+    MgCoordinate* lonLat;
+    lonLat = ConvertToLonLat(sMgrs,MgCoordinateSystemMgrsGridSquarePosition::Center);
+    return lonLat;
+}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+MgCoordinate* CCoordinateSystemMgrs::ConvertToLonLat(CREFSTRING sMgrs, INT32 grdSqrPosition)
+{
     double dLongitude, dLatitude;
-    INT32 nResult=ConvertToLonLat(sMgrs, dLongitude, dLatitude);
+    INT32 nResult=ConvertToLonLat(sMgrs, dLongitude, dLatitude, grdSqrPosition);
     if (MgCoordinateSystemErrorCode::Ok==nResult)
     {
         MgCoordinate* pLonLat=new MgCoordinateXY(dLongitude, dLatitude);
@@ -385,7 +402,7 @@
     }
 
     MG_TRY ()
-        theGridLineCollection = new CCoordinateSystemGridLineCollection ();
+        theGridLineCollection = new CCoordinateSystemGridLineCollection (m_GridLineExceptionLevel);
 
         // Determine the grid type.
         unitType = specification->GetUnitType();
@@ -407,7 +424,7 @@
                 // The specification calls for a grid.  The following function
                 // is smart enough to deal with the special nature of zones
                 // 31 through 37 at the higher northern latitudes.
-                aGridLineCollection = mgrsZoneGrid->GetGridLines (m_GridBoundary,specification);
+                aGridLineCollection = mgrsZoneGrid->GetGridLines (m_GridBoundary,specification,m_GridLineExceptionLevel);
             }
             else
             {
@@ -415,7 +432,7 @@
                 // smart enough to deal with band X (which is 12 degrees high)
                 // and the special nature of zones 31 through 37 at the higher
                 // northern latitudes.
-                aGridLineCollection = mgrsZoneGrid->GetGraticuleLines (m_GridBoundary,specification);
+                aGridLineCollection = mgrsZoneGrid->GetGraticuleLines (m_GridBoundary,specification,m_GridLineExceptionLevel);
             }
             if (aGridLineCollection != 0)
             {
@@ -443,13 +460,13 @@
     }
 
     MG_TRY ()
-        theGridRegionCollection = new CCoordinateSystemGridRegionCollection ();
+        theGridRegionCollection = new CCoordinateSystemGridRegionCollection (m_GridRegionExceptionLevel);
         zoneCount = m_ZoneCollection->GetCount ();
         for (index = 0;index < zoneCount;index += 1)
         {
             mgrsZoneGrid = m_ZoneCollection->GetItem (index);
             Ptr<MgCoordinateSystemGridRegionCollection> aGridRegionCollection;
-            aGridRegionCollection = mgrsZoneGrid->GetGridRegions (m_GridBoundary,specification);
+            aGridRegionCollection = mgrsZoneGrid->GetGridRegions (m_GridBoundary,specification,m_GridRegionExceptionLevel);
             theGridRegionCollection->AddCollection (aGridRegionCollection);
         }
     MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrs::GetGridRegions")
@@ -475,7 +492,7 @@
     }
 
     MG_TRY ()
-        theGridTickCollection = new CCoordinateSystemGridTickCollection ();
+        theGridTickCollection = new CCoordinateSystemGridTickCollection (m_GridTickExceptionLevel);
         unitType = specification->GetUnitType();
         specIsGrid = (unitType ==  MgCoordinateSystemUnitType::Linear);
         if (specIsGrid)
@@ -524,6 +541,88 @@
     return 1.0;
 }
 
+INT32 CCoordinateSystemMgrs::ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 index;
+    INT32 zoneCount;
+    INT32 memoryGuess (-1);
+
+    if (m_GridBoundary != 0)
+    {
+        memoryGuess = 0;
+        zoneCount = m_ZoneCollection->GetCount ();
+        for (index = 0;index < zoneCount;index += 1)
+        {
+            Ptr<CCoordinateSystemMgrsZone> mgrsZoneGrid = m_ZoneCollection->GetItem (index);
+            memoryGuess += mgrsZoneGrid->ApproxGridLineMemoryUsage (specification);
+        }
+    }
+    return memoryGuess;
+}
+INT32 CCoordinateSystemMgrs::ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 index;
+    INT32 zoneCount;
+    INT32 memoryGuess (-1);
+
+    if (m_GridBoundary != 0)
+    {
+        memoryGuess = 0;
+        zoneCount = m_ZoneCollection->GetCount ();
+        for (index = 0;index < zoneCount;index += 1)
+        {
+            Ptr<CCoordinateSystemMgrsZone> mgrsZoneGrid = m_ZoneCollection->GetItem (index);
+            memoryGuess += mgrsZoneGrid->ApproxGridRegionMemoryUsage (specification);
+        }
+    }
+    return memoryGuess;
+}
+INT32 CCoordinateSystemMgrs::ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 index;
+    INT32 zoneCount;
+    INT32 memoryGuess (-1);
+
+    if (m_GridBoundary != 0)
+    {
+        memoryGuess = 0;
+        zoneCount = m_ZoneCollection->GetCount ();
+        for (index = 0;index < zoneCount;index += 1)
+        {
+            Ptr<CCoordinateSystemMgrsZone> mgrsZoneGrid = m_ZoneCollection->GetItem (index);
+            memoryGuess += mgrsZoneGrid->ApproxGridTickMemoryUsage (specification);
+        }
+    }
+    return memoryGuess;
+}
+INT32 CCoordinateSystemMgrs::SetGridLineExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridLineExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridLineExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemMgrs::SetGridRegionExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridRegionExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridRegionExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemMgrs::SetGridTickExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridTickExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridTickExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+
 //INTERNAL_API
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 INT32 CCoordinateSystemMgrs::ConvertFromLonLat(double dLongitude, double dLatitude, INT32 nPrecision, REFSTRING sMgrs)
@@ -604,10 +703,16 @@
     //no need to check the dimension of the MgCoordinate as we only care about X and Y
     return ConvertFromLonLat(pLonLat->GetX(), pLonLat->GetY(), nPrecision, sMgrs);
 }
-
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 INT32 CCoordinateSystemMgrs::ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat)
 {
+    INT32 nResult;
+    nResult = ConvertToLonLat(sMgrs,pLonLat,MgCoordinateSystemMgrsGridSquarePosition::Center);
+    return nResult;
+}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+INT32 CCoordinateSystemMgrs::ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat, INT32 grdSqrPosition)
+{
     if (!pLonLat)
     {
         if (m_bExceptionsOn)
@@ -624,7 +729,7 @@
     //no need to check the dimension of the MgCoordinate as we only care about X and Y
     double dLongitude=pLonLat->GetX();
     double dLatitude=pLonLat->GetY();
-    INT32 nResult=ConvertToLonLat(sMgrs, dLongitude, dLatitude);
+    INT32 nResult=ConvertToLonLat(sMgrs, dLongitude, dLatitude, grdSqrPosition);
     if (nResult==MgCoordinateSystemErrorCode::Ok)
     {
         pLonLat->SetX(dLongitude);
@@ -632,10 +737,16 @@
     }
     return nResult;
 }
-
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 INT32 CCoordinateSystemMgrs::ConvertToLonLat(CREFSTRING sMgrs, double& dLongitude, double& dLatitude)
 {
+    INT32 nResult;
+    nResult = ConvertToLonLat(sMgrs,dLongitude,dLatitude,MgCoordinateSystemMgrsGridSquarePosition::Center);
+    return nResult;
+}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+INT32 CCoordinateSystemMgrs::ConvertToLonLat(CREFSTRING sMgrs, double& dLongitude, double& dLatitude, INT32 grdSqrPosition)
+{
     if (!m_pCsMgrs)
     {
         if (m_bExceptionsOn)
@@ -649,6 +760,20 @@
         }
     }
 
+    if (grdSqrPosition <= MgCoordinateSystemMgrsGridSquarePosition::None ||
+        grdSqrPosition >= MgCoordinateSystemMgrsGridSquarePosition::Unknown)
+    {
+        if (m_bExceptionsOn)
+        {
+            throw new MgInvalidArgumentException(L"MgCoordinateSystemMgrs.ConvertToLonLat", __LINE__, __WFILE__, NULL, L"", NULL);
+        }
+        else
+        {
+            m_nLastError=MgCoordinateSystemErrorCode::InvalidArgument;
+            return m_nLastError;
+        }
+    }
+
     //Convert to a char*
     char *pMgrs = Convert_Wide_To_Ascii(sMgrs.c_str()); //need to delete[] pStr
     if (NULL == pMgrs)
@@ -665,7 +790,7 @@
     }
 
     double latLng [2];
-    int nResult=CScalcLlFromMgrs (m_pCsMgrs, latLng, pMgrs);
+    int nResult=CScalcLlFromMgrsEx (m_pCsMgrs, latLng, pMgrs, grdSqrPosition);
 
     //Free the converted string
     delete [] pMgrs;
@@ -1221,7 +1346,7 @@
 }
 bool CCoordinateSystemMgrs::CanDoPoles (MgCoordinateSystem* frameCRS)
 {
-	// MENTOR_MAINTENANCE --> a new projection may need to be added to this list.
+    // MENTOR_MAINTENANCE --> a new projection may need to be added to this list.
     static INT32 polarCapable [] =
     {
         MgCoordinateSystemProjectionCode::Tm,

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrs.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -25,10 +25,14 @@
 {
     struct CCoordinateSystemMgrsSeries
     {
-	    wchar_t easting [9];
-	    wchar_t northing [21];
+        wchar_t easting [9];
+        wchar_t northing [21];
     };
 
+    static const INT32 m_GridLineExceptionLevelK;
+    static const INT32 m_GridRegionExceptionLevelK;
+    static const INT32 m_GridTickExceptionLevelK;
+
 public:
     // Static Constants, Variables (hopefully not), and Functions.
     static const CCoordinateSystemMgrsSeries MgrsSeriesNormal [6];
@@ -66,6 +70,7 @@
     STRING ConvertFromLonLat(double dLongitude, double dLatitude, INT32 nPrecision);
     STRING ConvertFromLonLat(MgCoordinate* pLonLat, INT32 nPrecision);
     MgCoordinate* ConvertToLonLat(CREFSTRING sMgrs);
+    MgCoordinate* ConvertToLonLat(CREFSTRING sMgrs, INT32 grdSqrPosition);
     INT8 GetLetteringScheme();
 
     INT32 GetSpecializationType ();
@@ -78,6 +83,14 @@
     double GetConvergenceAngle (MgCoordinate* location);
     double GetProjectiveGridScale (MgCoordinate* location);
 
+    INT32 ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+    INT32 ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+    INT32 ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+
+    INT32 SetGridLineExceptionLevel (INT32 memoryUseMax);
+    INT32 SetGridRegionExceptionLevel (INT32 memoryUseMax);
+    INT32 SetGridTickExceptionLevel (INT32 memoryUseMax);
+
     INT32 GetLastError();
     void ResetLastError();
     bool AreExceptionsOn();
@@ -86,8 +99,10 @@
 INTERNAL_API:
     INT32 ConvertFromLonLat(double dLongitude, double dLatitude, INT32 nPrecision, REFSTRING sMgrs);
     INT32 ConvertFromLonLat(MgCoordinate* pLonLat, INT32 nPrecision, REFSTRING sMgrs);
-    INT32 ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat);
-    INT32 ConvertToLonLat(CREFSTRING sMgrs, double& dLongitude, double& dLatitude);
+INT32 ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat);
+INT32 ConvertToLonLat(CREFSTRING sMgrs, double& dLongitude, double& dLatitude);
+    INT32 ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat, INT32 grdSqrPosition);
+    INT32 ConvertToLonLat(CREFSTRING sMgrs, double& dLongitude, double& dLatitude, INT32 grdSqrPosition);
 
 protected:          // Still INTERNAL API only.
     // Given a frame/viewport boundary, and the coordinate system thereof,
@@ -112,6 +127,9 @@
     INT8 m_nLetteringScheme;
     bool m_bExceptionsOn;
     bool m_bUseFrameDatum;
+    INT32 m_GridLineExceptionLevel;
+    INT32 m_GridRegionExceptionLevel;
+    INT32 m_GridTickExceptionLevel;
     INT32 m_nLastError;
     Ptr<MgCoordinateSystem> m_pCsTarget;
     struct cs_Mgrs_* m_pCsMgrs;

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -37,12 +37,10 @@
                                                         :
                                                       CCoordinateSystemOneGrid (),
                                                       m_UtmZone                (utmZoneNbr),
-                                                      m_LetteringScheme        (letteringScheme),
-                                                      m_RegionCollection       ()
+                                                      m_LetteringScheme        (letteringScheme)
 {
     MgCoordinateSystemFactory csFactory;
     Ptr<MgCoordinateSystem> utmZoneCRS;
-    m_RegionCollection = new CCoordinateSystemGridRegionCollection ();
 
     STRING utmZoneCode = CCoordinateSystemMgrs::ZoneNbrToUtmCs (m_UtmZone);
     utmZoneCRS = csFactory.CreateFromCode (utmZoneCode);
@@ -54,13 +52,19 @@
 {
 }
 CCoordinateSystemGridRegionCollection* CCoordinateSystemMgrsZone::GetGridRegions (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                                                  MgCoordinateSystemGridSpecification* specification)
+                                                                                  MgCoordinateSystemGridSpecification* specification,
+                                                                                  INT32 exceptionLvl)
 {
-    BuildRegionCollection (frameBoundary,specification);
-    return SAFE_ADDREF(m_RegionCollection.p);
+    Ptr<CCoordinateSystemGridRegionCollection> regionCollection;
+
+    MG_TRY ()
+        regionCollection = BuildRegionCollection (frameBoundary,specification,exceptionLvl);
+    MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrsZone::GetGridRegions")
+    return SAFE_ADDREF(regionCollection.p);
 }
 CCoordinateSystemGridLineCollection* CCoordinateSystemMgrsZone::GetGridLines (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                                              MgCoordinateSystemGridSpecification* specification)
+                                                                              MgCoordinateSystemGridSpecification* specification,
+                                                                              INT32 exceptionLvl)
 {
     // For now, we just call the generic OneGrid grid line function.
     // Later on we might need to add some special logic for zones 31
@@ -69,7 +73,8 @@
     return dynamic_cast<CCoordinateSystemGridLineCollection*>(gridLines);
 }
 CCoordinateSystemGridLineCollection* CCoordinateSystemMgrsZone::GetGraticuleLines (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                                                   MgCoordinateSystemGridSpecification* specification)
+                                                                                   MgCoordinateSystemGridSpecification* specification,
+                                                                                   INT32 exceptionLvl)
 {
     const INT32 maxPoints = 512;
 
@@ -96,14 +101,14 @@
 
     MgCoordinateSystemFactory csFactory;
 
-    Ptr<CCoordinateSystemGridLineCollection> gridLineCollection = new CCoordinateSystemGridLineCollection ();
+    Ptr<CCoordinateSystemGridLineCollection> gridLineCollection = new CCoordinateSystemGridLineCollection (exceptionLvl);
 
     MG_TRY ()
         fromPoint = new MgCoordinateXY ();
         toPoint = new MgCoordinateXY ();
         CCoordinateSystemGridSpecification* mySpecPtr = dynamic_cast<CCoordinateSystemGridSpecification*>(specification);
         precision = mySpecPtr->GetCurvePrecision (m_GridCRS);
- 
+
         // To be are successful, we'll need a Transform which will convert
         // 'LL' to the frame coordinate system.
         llCRS = csFactory.CreateFromCode (L"LL");
@@ -221,6 +226,79 @@
     MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrsZone::GetGraticuleLines")
    return gridLineCollection.Detach ();
 }
+INT32 CCoordinateSystemMgrsZone::ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    INT32 regionSize;
+    INT32 regionCount;
+    INT32 memoryGuess (0);
+
+    
+
+    // Estimate the size of a major region object.  Eventually, should include
+    // MaxPoints and curve precision from the specification object.
+    regionSize = (GridFrameCrsAreTheSame ()) ? 512 : 50000;
+
+    MG_TRY ()
+        if (specification->GetUnitType () == MgCoordinateSystemUnitType::Angular)
+        {
+            double eastingIncrement = specification->GetEastingIncrement (MgCoordinateSystemUnitCode::Degree);
+            double northingIncrement = specification->GetNorthingIncrement (MgCoordinateSystemUnitCode::Degree);
+            if (MgMathUtility::DblCmp (eastingIncrement,6.0) &&
+                MgMathUtility::DblCmp (northingIncrement,8.0))
+            {
+                double lngMin,lngMax;
+                double latMin,latMax;
+                Ptr<CCoordinateSystemMgrsMajorRegionCollection> mjrRegionCollection;
+
+                // Determine the number of regions included in the boundary.
+                GetGeographicExtents (lngMin,lngMax,latMin,latMax);
+                mjrRegionCollection = new CCoordinateSystemMgrsMajorRegionCollection (m_UtmZone,latMin,latMax);
+                regionCount = mjrRegionCollection->GetCount ();
+
+                // Make a guess at the amount of memory required.
+                memoryGuess = regionSize * regionCount;
+            }
+        }
+        else if (specification->GetUnitType () == MgCoordinateSystemUnitType::Linear)
+        {
+            double eastingIncrement = specification->GetEastingIncrement (MgCoordinateSystemUnitCode::Meter);
+            double northingIncrement = specification->GetNorthingIncrement (MgCoordinateSystemUnitCode::Meter);
+            if (MgMathUtility::DblCmp (eastingIncrement,100000.0) &&
+                MgMathUtility::DblCmp (northingIncrement,100000.0))
+            {
+                INT32 beginEast, endEast;
+                INT32 beginNorth, endNorth;
+
+                double delta;
+                double curvePrecision;
+                double  eastMin, eastMax;
+                double northMin, northMax;
+
+                curvePrecision = 1.0;
+                // Estimate the number of minor regions.
+                GetGridExtents (eastMin,eastMax,northMin,northMax,curvePrecision);
+ 
+                delta = fabs (fmod (eastMin,100000.0));
+                beginEast = static_cast<INT32>(eastMin - ((eastMin >= 0.0) ? delta : (100000.0 - delta)));
+                delta = fabs (fmod (eastMax,100000.0));
+                endEast = static_cast<INT32>(eastMax + ((eastMax >= 0.0) ? (100000.0 - delta) : -delta));
+
+                delta = fabs (fmod (northMin,100000.0));
+                beginNorth = static_cast<INT32>(northMin - ((northMin >= 0.0) ? delta : (100000.0 - delta)));
+                delta = fabs (fmod (northMax,100000.0));
+                endNorth = static_cast<INT32>(northMax + ((northMax >= 0.0) ? (100000.0 - delta) : -delta));
+
+                INT32 verticalCount   = (endNorth - beginNorth) / 100000;
+                INT32 horizontalCount = (endEast - beginEast) / 100000;
+                regionCount = horizontalCount * verticalCount;
+
+                memoryGuess = regionSize * regionCount;
+            }
+        }
+    MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrsZone::ApproxGridRegionMemoryUsage")
+
+    return memoryGuess;
+}
 INT32 CCoordinateSystemMgrsZone::GetUtmZoneNbr (void)
 {
     // m_UtmZoneNbr is positive for northern hemisphere, negative for the
@@ -228,37 +306,44 @@
     // is the uninitialized/unknown/error value.
     return m_UtmZone;
 }
-void CCoordinateSystemMgrsZone::BuildRegionCollection (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                       MgCoordinateSystemGridSpecification* specification)
+CCoordinateSystemGridRegionCollection* CCoordinateSystemMgrsZone::BuildRegionCollection (MgCoordinateSystemGridBoundary* frameBoundary,
+                                                                                         MgCoordinateSystemGridSpecification* specification,
+                                                                                         INT32 exceptionLvl)
 {
     double curvePrecision;
     double eastingIncrement;
     double northingIncrement;
+    Ptr<CCoordinateSystemGridRegionCollection> regionCollection;
 
-    curvePrecision = specification->GetCurvePrecision ();
-
-    if (specification->GetUnitType () == MgCoordinateSystemUnitType::Angular)
-    {
-        eastingIncrement = specification->GetEastingIncrement (MgCoordinateSystemUnitCode::Degree);
-        northingIncrement = specification->GetNorthingIncrement (MgCoordinateSystemUnitCode::Degree);
-        if (MgMathUtility::DblCmp (eastingIncrement,6.0) &&
-            MgMathUtility::DblCmp (northingIncrement,8.0))
+    MG_TRY ()
+        regionCollection = new CCoordinateSystemGridRegionCollection (exceptionLvl);
+        curvePrecision = specification->GetCurvePrecision ();
+        if (specification->GetUnitType () == MgCoordinateSystemUnitType::Angular)
         {
-            BuildMajorRegions (frameBoundary,curvePrecision);
+            eastingIncrement = specification->GetEastingIncrement (MgCoordinateSystemUnitCode::Degree);
+            northingIncrement = specification->GetNorthingIncrement (MgCoordinateSystemUnitCode::Degree);
+            if (MgMathUtility::DblCmp (eastingIncrement,6.0) &&
+                MgMathUtility::DblCmp (northingIncrement,8.0))
+            {
+                BuildMajorRegions (regionCollection,frameBoundary,curvePrecision);
+            }
         }
-    }
-    else if (specification->GetUnitType () == MgCoordinateSystemUnitType::Linear)
-    {
-        eastingIncrement = specification->GetEastingIncrement (MgCoordinateSystemUnitCode::Meter);
-        northingIncrement = specification->GetNorthingIncrement (MgCoordinateSystemUnitCode::Meter);
-        if (MgMathUtility::DblCmp (eastingIncrement,100000.0) &&
-            MgMathUtility::DblCmp (northingIncrement,100000.0))
+        else if (specification->GetUnitType () == MgCoordinateSystemUnitType::Linear)
         {
-            BuildMinorRegions (frameBoundary,curvePrecision);
+            eastingIncrement = specification->GetEastingIncrement (MgCoordinateSystemUnitCode::Meter);
+            northingIncrement = specification->GetNorthingIncrement (MgCoordinateSystemUnitCode::Meter);
+            if (MgMathUtility::DblCmp (eastingIncrement,100000.0) &&
+                MgMathUtility::DblCmp (northingIncrement,100000.0))
+            {
+                BuildMinorRegions (regionCollection,frameBoundary,curvePrecision);
+            }
         }
-    }
+    MG_CATCH_AND_THROW(L"MgCoordinateSystemMgrsZone::GetGraticuleLines")
+    return regionCollection.Detach ();
 }
-void CCoordinateSystemMgrsZone::BuildMajorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double curvePrecision)
+void CCoordinateSystemMgrsZone::BuildMajorRegions (CCoordinateSystemGridRegionCollection* regionCollection,
+                                                   MgCoordinateSystemGridBoundary* frameBoundary,
+                                                   double curvePrecision)
 {
     const INT32 maxPoints = 512;
 
@@ -275,7 +360,7 @@
     Ptr<CCoordinateSystemGridBoundary> rgnBoundary;
     Ptr<CCoordinateSystemGridRegion> pMjrRegion;
     Ptr<CCoordinateSystemMgrsMajorRegion> regionPtr;
-    Ptr<CCoordinateSystemMgrsMajorRegionCollection> regionCollection;
+    Ptr<CCoordinateSystemMgrsMajorRegionCollection> mjrRegionCollection;
 
     MgCoordinateSystemFactory csFactory;
 
@@ -294,14 +379,14 @@
         // grid in geographic coordinate form, and work from there.
         GetGeographicExtents (lngMin,lngMax,latMin,latMax);
         
-        regionCollection = new CCoordinateSystemMgrsMajorRegionCollection (m_UtmZone,latMin,latMax);
-        if (regionCollection != 0)
+        mjrRegionCollection = new CCoordinateSystemMgrsMajorRegionCollection (m_UtmZone,latMin,latMax);
+        if (mjrRegionCollection != 0)
         {
-            INT32 regionCount = regionCollection->GetCount ();
-            for (index = 0;index < regionCount;index += 1)
+            INT32 mjrRegionCount = mjrRegionCollection->GetCount ();
+            for (index = 0;index < mjrRegionCount;index += 1)
             {
                 // We have a region.
-                regionPtr = regionCollection->GetItem (index);
+                regionPtr = mjrRegionCollection->GetItem (index);
                 southwest->SetX (regionPtr->GetWestEdgeLng ());
                 southwest->SetY (regionPtr->GetSouthEdgeLat ());
                 northeast->SetX (regionPtr->GetEastEdgeLng ());
@@ -313,7 +398,7 @@
                                                                           northeast,
                                                                           curvePrecision,
                                                                           maxPoints);
-                m_RegionCollection->Add (pMjrRegion);
+                regionCollection->Add (pMjrRegion);
             }
         }
         else if (m_UtmZone == 61)
@@ -326,7 +411,9 @@
         }
     MG_CATCH_AND_THROW(L"MgCoordinateSystemOneGrid::BuildMajorRegions")
 }
-void CCoordinateSystemMgrsZone::BuildMinorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double curvePrecision)
+void CCoordinateSystemMgrsZone::BuildMinorRegions (CCoordinateSystemGridRegionCollection* regionCollection,
+                                                   MgCoordinateSystemGridBoundary* frameBoundary,
+                                                   double curvePrecision)
 {
     const INT32 maxPoints = 512;
 
@@ -398,7 +485,7 @@
                                                                               northeast,
                                                                               curvePrecision,
                                                                               maxPoints);
-                    m_RegionCollection->Add (pMnrRegion);
+                    regionCollection->Add (pMnrRegion);
                 }
             }
         }

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysMgrsZone.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -54,19 +54,28 @@
     ~CCoordinateSystemMgrsZone (void);
 
     CCoordinateSystemGridLineCollection* GetGridLines (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                       MgCoordinateSystemGridSpecification* specification);
+                                                       MgCoordinateSystemGridSpecification* specification,
+                                                       INT32 exceptionLvl);
     CCoordinateSystemGridLineCollection* GetGraticuleLines (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                            MgCoordinateSystemGridSpecification* specification);
+                                                            MgCoordinateSystemGridSpecification* specification,
+                                                            INT32 exceptionLvl);
     CCoordinateSystemGridRegionCollection* GetGridRegions (MgCoordinateSystemGridBoundary* frameBoundary,
-                                                           MgCoordinateSystemGridSpecification* specification);
+                                                           MgCoordinateSystemGridSpecification* specification,
+                                                           INT32 exceptionLvl);
+    INT32 ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification);
     INT32 GetUtmZoneNbr (void);
- 
+
 protected:
-    void BuildRegionCollection (MgCoordinateSystemGridBoundary* frameBoundary,
-                                MgCoordinateSystemGridSpecification* specification);
+    CCoordinateSystemGridRegionCollection* BuildRegionCollection (MgCoordinateSystemGridBoundary* frameBoundary,
+                                                                  MgCoordinateSystemGridSpecification* specification,
+                                                                  INT32 exceptionLvl);
 private:
-    void BuildMajorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double boundaryPrecision);
-    void BuildMinorRegions (MgCoordinateSystemGridBoundary* frameBoundary,double boundaryPrecision);
+    void BuildMajorRegions (CCoordinateSystemGridRegionCollection* regionCollection,
+                            MgCoordinateSystemGridBoundary* frameBoundary,
+                            double boundaryPrecision);
+    void BuildMinorRegions (CCoordinateSystemGridRegionCollection* regionCollection,
+                            MgCoordinateSystemGridBoundary* frameBoundary,
+                            double boundaryPrecision);
     ///////////////////////////////////////////////////////////////////////////
     // Data members
     // m_UtmZoneNbr is positive for northern hemisphere, negative for the
@@ -74,7 +83,7 @@
     // Zero is the uninitialized/unknown/error value.
     INT32 m_UtmZone;
     INT8 m_LetteringScheme;
-    Ptr<CCoordinateSystemGridRegionCollection> m_RegionCollection;
+//    Ptr<CCoordinateSystemGridRegionCollection> m_RegionCollection;
 
     // Not implemented
     CCoordinateSystemMgrsZone (const CCoordinateSystemMgrsZone& source);

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -21,6 +21,7 @@
 #include "CriticalSection.h"
 
 #include "CoordSys.h"
+#include "CoordSysMathComparator.h"
 #include "CoordSysTransform.h"              //for CCoordinateSystemTransform
 #include "CoordSysGrids.h"
 #include "CoordSysOneGrid.h"
@@ -30,17 +31,23 @@
 //=============================================================================
 // CCoordinateSystemOneGrid
 const INT32 CCoordinateSystemOneGrid::MaxCurvePoints = 511;
-CCoordinateSystemOneGrid::CCoordinateSystemOneGrid () : MgGuardDisposable   (),
-                                                        m_UserID            (0),
-                                                        m_MaxCurvePoints    (MaxCurvePoints),
-                                                        m_Label             (),
-                                                        m_GridCRS           (),
-                                                        m_FrameCRS          (),
-                                                        m_ToFrameXform      (),
-                                                        m_ToGridXform       (),
-                                                        m_BoundaryPrecision (0.0),
-                                                        m_GridBoundary      (),
-                                                        m_FrameBoundary     ()
+const INT32 CCoordinateSystemOneGrid::m_GridLineExceptionLevelK = 50000000L;   // 50MB
+const INT32 CCoordinateSystemOneGrid::m_GridTickExceptionLevelK = 20000000L;   // 20MB
+
+CCoordinateSystemOneGrid::CCoordinateSystemOneGrid () : MgGuardDisposable        (),
+                                                        m_GridFrameCrsSame       (false),
+                                                        m_UserID                 (0),
+                                                        m_MaxCurvePoints         (MaxCurvePoints),
+                                                        m_Label                  (),
+                                                        m_GridLineExceptionLevel (m_GridLineExceptionLevelK),
+                                                        m_GridTickExceptionLevel (m_GridTickExceptionLevelK),
+                                                        m_GridCRS                (),
+                                                        m_FrameCRS               (),
+                                                        m_ToFrameXform           (),
+                                                        m_ToGridXform            (),
+                                                        m_BoundaryPrecision      (0.0),
+                                                        m_GridBoundary           (),
+                                                        m_FrameBoundary          ()
 {
     Ptr<MgCoordinateSystemFactory> csFactory = new MgCoordinateSystemFactory();
 }
@@ -48,17 +55,20 @@
                                                     MgCoordinateSystem* gridCRS,
                                                     MgCoordinateSystem* frameCRS)
                                                         :
-                                                    MgGuardDisposable   (),
-                                                    m_UserID            (0),
-                                                    m_MaxCurvePoints    (MaxCurvePoints),
-                                                    m_Label             (),
-                                                    m_GridCRS           (),
-                                                    m_FrameCRS          (),
-                                                    m_ToFrameXform      (),
-                                                    m_ToGridXform       (),
-                                                    m_BoundaryPrecision (0.0),
-                                                    m_GridBoundary      (),
-                                                    m_FrameBoundary     ()
+                                                    MgGuardDisposable        (),
+                                                    m_GridFrameCrsSame       (false),
+                                                    m_UserID                 (0),
+                                                    m_MaxCurvePoints         (MaxCurvePoints),
+                                                    m_Label                  (),
+                                                    m_GridLineExceptionLevel (m_GridLineExceptionLevelK),
+                                                    m_GridTickExceptionLevel (m_GridTickExceptionLevelK),
+                                                    m_GridCRS                (),
+                                                    m_FrameCRS               (),
+                                                    m_ToFrameXform           (),
+                                                    m_ToGridXform            (),
+                                                    m_BoundaryPrecision      (0.0),
+                                                    m_GridBoundary           (),
+                                                    m_FrameBoundary          ()
 {
     SetUp (frameBoundary,gridCRS,frameCRS);
 }
@@ -74,17 +84,27 @@
                                       MgCoordinateSystem* frameCRS)
 {
     MgCoordinateSystemFactory csFactory;
+    CCoordinateSystemMathComparator csMathComparator;
 
     m_FrameBoundary = SAFE_ADDREF (frameBoundary);
     m_GridCRS = SAFE_ADDREF (gridCRS);
     m_FrameCRS = SAFE_ADDREF (frameCRS);
+
     m_ToFrameXform = csFactory.GetTransform (m_GridCRS,m_FrameCRS);
     m_ToFrameXform->IgnoreDatumShiftWarning (true);
     m_ToFrameXform->IgnoreOutsideDomainWarning (true);
+
     m_ToGridXform = csFactory.GetTransform (m_FrameCRS,m_GridCRS);
     m_ToGridXform->IgnoreDatumShiftWarning (true);
     m_ToGridXform->IgnoreOutsideDomainWarning (true);
+
+    m_GridFrameCrsSame = csMathComparator.Same (gridCRS,frameCRS);
+
 }
+bool CCoordinateSystemOneGrid::GridFrameCrsAreTheSame ()
+{
+    return m_GridFrameCrsSame;
+}
 bool CCoordinateSystemOneGrid::IsGeographic (void)
 {
     bool isGeographic;
@@ -136,7 +156,7 @@
     Ptr<MgLineStringCollection> lineStringCollection;
     Ptr<CCoordinateSystemGridLine> gridLine;
 
-    Ptr<CCoordinateSystemGridLineCollection> gridLineCollection = new CCoordinateSystemGridLineCollection ();
+    Ptr<CCoordinateSystemGridLineCollection> gridLineCollection = new CCoordinateSystemGridLineCollection (m_GridLineExceptionLevel);
 
     MG_TRY()
         gridCrsUnitCode = m_GridCRS->GetUnitCode ();
@@ -279,7 +299,7 @@
         gridCrsUnitCode = m_GridCRS->GetUnitCode ();
 
         CCoordinateSystemGridSpecification* mySpecPtr = dynamic_cast<CCoordinateSystemGridSpecification*>(specs);
-        tickCollection = new CCoordinateSystemGridTickCollection ();
+        tickCollection = new CCoordinateSystemGridTickCollection (m_GridTickExceptionLevel);
 
         // Get the grid extents.
         curvePrecision = mySpecPtr->GetCurvePrecision();
@@ -395,6 +415,34 @@
     MG_CATCH_AND_THROW(L"MgCoordinateSystemOneGrid::GetGridLines")
     return tickCollection.Detach ();
 }
+
+INT32 CCoordinateSystemOneGrid::ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    return 50000;
+}
+INT32 CCoordinateSystemOneGrid::ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification)
+{
+    return 10000;
+}
+
+INT32 CCoordinateSystemOneGrid::SetGridLineExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridLineExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridLineExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
+INT32 CCoordinateSystemOneGrid::SetGridTickExceptionLevel (INT32 memoryUseMax)
+{
+    INT32 rtnValue = m_GridTickExceptionLevel;
+    if (memoryUseMax > 0L)
+    {
+        m_GridTickExceptionLevel = memoryUseMax;
+    }
+    return rtnValue;
+}
 MgCoordinateSystemGridBoundary* CCoordinateSystemOneGrid::GetFrameBoundary (void)
 {
     return SAFE_ADDREF (m_FrameBoundary.p);

Modified: trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/CoordinateSystem/CoordSysOneGrid.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -40,6 +40,8 @@
 
 class CCoordinateSystemOneGrid : public MgGuardDisposable
 {
+    static const INT32 m_GridLineExceptionLevelK;
+    static const INT32 m_GridTickExceptionLevelK;
 public:
     static const INT32 MaxCurvePoints;
     CCoordinateSystemOneGrid (void);
@@ -54,6 +56,7 @@
 
     // Returns true if the grid coordinate system is geographic; use this to
     // determine if this is a graticule (as opposed to a grid).
+    bool GridFrameCrsAreTheSame ();
     bool IsGeographic (void);
     INT32 GetUserID (void);
     STRING GetLabel (void);
@@ -65,6 +68,12 @@
     MgCoordinateSystemGridLineCollection* GetGridLines (MgCoordinateSystemGridSpecification* specs);
     CCoordinateSystemGridTickCollection* GetBoundaryTicks (MgCoordinateSystemGridSpecification* specs);
 
+    INT32 ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+    INT32 ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification);
+
+    INT32 SetGridLineExceptionLevel (INT32 memoryUseMax);
+    INT32 SetGridTickExceptionLevel (INT32 memoryUseMax);
+
 protected:
     MgCoordinateSystemGridBoundary* GetFrameBoundary (void);
     MgCoordinateSystem* GetFrameCRS (void);
@@ -76,9 +85,12 @@
     void GetGridExtents (double& eastMin,double& eastMax,double& northMin,double& northMax,double precision = 0.25);
     void Dispose (void);
 
+    bool m_GridFrameCrsSame;
     INT32 m_UserID;                                      // For user convenience (i.e. UTM zone)
     INT32 m_MaxCurvePoints;
     STRING m_Label;                                      // For user conveinence (i.e. MGRS)
+    INT32 m_GridLineExceptionLevel;
+    INT32 m_GridTickExceptionLevel;
     Ptr<MgCoordinateSystem> m_GridCRS;                   // The grid coordinate system
     Ptr<MgCoordinateSystem> m_FrameCRS;                  // The frame coordinate system
     Ptr<MgCoordinateSystemTransform> m_ToFrameXform;     // Converts grid coordinates to frame coordinates

Added: trunk/MgDev/Common/Foundation/Exception/GridDensityException.cpp
===================================================================
--- trunk/MgDev/Common/Foundation/Exception/GridDensityException.cpp	                        (rev 0)
+++ trunk/MgDev/Common/Foundation/Exception/GridDensityException.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -0,0 +1,40 @@
+//
+//  Copyright (C) 2004-2009 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "Foundation.h"
+
+IMPLEMENT_EXCEPTION_DEFAULTS(MgGridDensityException, MgApplicationException)
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
+/// Construct a MgGridDensityException object.
+///
+MgGridDensityException::MgGridDensityException(CREFSTRING methodName,
+    INT32 lineNumber, CREFSTRING fileName, MgStringCollection* whatArguments,
+    CREFSTRING whyMessageId, MgStringCollection* whyArguments) throw() :
+    MgApplicationException(methodName, lineNumber, fileName,
+        whatArguments, whyMessageId, whyArguments)
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
+/// Destruct the MgGridDensityException object.
+///
+MgGridDensityException::~MgGridDensityException() throw()
+{
+}

Added: trunk/MgDev/Common/Foundation/Exception/GridDensityException.h
===================================================================
--- trunk/MgDev/Common/Foundation/Exception/GridDensityException.h	                        (rev 0)
+++ trunk/MgDev/Common/Foundation/Exception/GridDensityException.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -0,0 +1,71 @@
+//
+//  Copyright (C) 2004-2009 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+/// \ingroup Exceptions_Module
+
+#ifndef MG_GRID_DENSITY_EXCEPTION_H_
+#define MG_GRID_DENSITY_EXCEPTION_H_
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
+/// Thrown when an error occurs in a date/time routine.
+///
+class MG_FOUNDATION_API MgGridDensityException : public MgApplicationException
+{
+    DECLARE_CLASSNAME(MgGridDensityException)
+
+EXTERNAL_API:
+
+    ///////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Construct a MgGridDensityException object.
+    ///
+    /// \param methodName
+    /// Name of the method where the exception occurred.
+    /// \param lineNumber
+    /// Line number where the exception occurred.
+    /// \param fileName
+    /// File name where the exception occurred.
+    /// \param whatArguments
+    /// Collection of arguments used to format the message that describes what the exception is.
+    /// \param whyMessageId
+    /// ID of the message that describes why the exception occurs.
+    /// \param whyArguments
+    /// Collection of arguments used to format the message that describes why the exception occurs.
+    /// \param thirdPartyMessage
+    /// Exception message from the third party component
+    ///
+    MgGridDensityException(CREFSTRING methodName, INT32 lineNumber,
+        CREFSTRING fileName, MgStringCollection* whatArguments,
+        CREFSTRING whyMessageId, MgStringCollection* whyArguments) throw();
+
+    ///////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Destruct the MgGridDensityException object.
+    ///
+    virtual ~MgGridDensityException() throw();
+
+INTERNAL_API:
+
+    DECLARE_EXCEPTION_DEFAULTS(MgGridDensityException)
+
+CLASS_ID:
+
+    static const INT32 m_cls_id = Foundation_Exception_MgGridDensityException;
+};
+
+#endif

Modified: trunk/MgDev/Common/Foundation/Foundation.h
===================================================================
--- trunk/MgDev/Common/Foundation/Foundation.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Foundation/Foundation.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -147,6 +147,7 @@
 #include "Exception/DuplicateObjectException.h"
 #include "Exception/EncryptionException.h"
 #include "Exception/FileNotFoundException.h"
+#include "Exception/GridDensityException.h"
 #include "Exception/IndexOutOfRangeException.h"
 #include "Exception/InvalidArgumentException.h"
 #include "Exception/InvalidCastException.h"

Modified: trunk/MgDev/Common/Foundation/Foundation.vcproj
===================================================================
--- trunk/MgDev/Common/Foundation/Foundation.vcproj	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Foundation/Foundation.vcproj	2009-12-04 16:33:48 UTC (rev 4375)
@@ -1073,6 +1073,30 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Exception\GridDensityException.cpp"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\Exception\GridDensityException.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Exception\IndexOutOfRangeException.cpp"
 				>
 				<FileConfiguration

Modified: trunk/MgDev/Common/Foundation/FoundationBuild.cpp
===================================================================
--- trunk/MgDev/Common/Foundation/FoundationBuild.cpp	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Foundation/FoundationBuild.cpp	2009-12-04 16:33:48 UTC (rev 4375)
@@ -52,6 +52,7 @@
 #include "Exception/Exception.cpp"
 #include "Exception/FileIoException.cpp"
 #include "Exception/FileNotFoundException.cpp"
+#include "Exception/GridDensityException.cpp"
 #include "Exception/IndexOutOfRangeException.cpp"
 #include "Exception/InvalidArgumentException.cpp"
 #include "Exception/InvalidCastException.cpp"

Modified: trunk/MgDev/Common/Foundation/Makefile.am
===================================================================
--- trunk/MgDev/Common/Foundation/Makefile.am	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Foundation/Makefile.am	2009-12-04 16:33:48 UTC (rev 4375)
@@ -41,6 +41,7 @@
   Exception/Exception.cpp \
   Exception/FileIoException.cpp \
   Exception/FileNotFoundException.cpp \
+  Exception/GridDensityException.cpp \
   Exception/IndexOutOfRangeException.cpp \
   Exception/InvalidArgumentException.cpp \
   Exception/InvalidCastException.cpp \
@@ -144,6 +145,7 @@
   Exception/ExceptionDefs.h \
   Exception/FileIoException.h \
   Exception/FileNotFoundException.h \
+  Exception/GridDensityException.h \
   Exception/IndexOutOfRangeException.h \
   Exception/InvalidArgumentException.h \
   Exception/InvalidCastException.h \

Modified: trunk/MgDev/Common/Foundation/System/FoundationClassId.h
===================================================================
--- trunk/MgDev/Common/Foundation/System/FoundationClassId.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Foundation/System/FoundationClassId.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -94,6 +94,7 @@
 #define Foundation_Exception_MgUnderflowException                               FOUNDATION_EXCEPTION_ID+48
 #define Foundation_Exception_MgXmlException                                     FOUNDATION_EXCEPTION_ID+49
 #define Foundation_Exception_MgXmlParserException                               FOUNDATION_EXCEPTION_ID+50
+#define Foundation_Exception_MgGridDensityException                             FOUNDATION_EXCEPTION_ID+51
 
 // Foundation Property
 

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemCommon.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemCommon.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemCommon.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -52,6 +52,7 @@
 #include "CoordinateSystemProjectionFormatType.h"           //for MgCoordinateSystemProjectionFormatType
 #include "CoordinateSystemProjectionParameterType.h"        //for MgCoordinateSystemProjectionParameterType
 #include "CoordinateSystemErrorCode.h"                      //for MgCoordinateSystemErrorCode
+#include "CoordinateSystemMgrsGridSquarePosition.h"         //for MgCoordinateSystemMgrsGridSquarePosition
 #include "CoordinateSystemMgrs.h"                           //for MgCoordinateSystemMgrs
 #include "CoordinateSystemMgrsLetteringScheme.h"            //for MgCoordinateSystemMgrsLetteringScheme
 

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemErrorCode.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemErrorCode.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemErrorCode.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -92,6 +92,7 @@
     static const INT32 InitializationFailed = 1002;
     static const INT32 ConversionFailed     = 1003;
     static const INT32 NullArgument         = 1004;
+    static const INT32 InvalidArgument      = 1005;
 };
 /// \}
 

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemGrids.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -460,6 +460,39 @@
 
     ///////////////////////////////////////////////////////////////////////////
     /// \brief
+    /// Sets the maximum number of points to generate for a complex curve
+    /// approximation.
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual void SetMaxCurvePoints (double curvePrecision);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual void SetMaxCurvePoints (double curvePrecision);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual void SetMaxCurvePoints (double curvePrecision);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param maxCurvePoints (INT32)
+    /// The desired maximum number of points to be generated for a complex
+    /// curve approximation.  Default is 511.
+    ///
+    /// \remarks
+    /// Generating a grid line of one coordinate system in the model space
+    /// based on another coordinate system requires that an approximation
+    /// of the complex curve be generated by a series of straight line
+    /// segments.  Use this value to limit the number of points generated
+    /// to a specific value.  The traditional, and default, value is 511.
+    /// Large values will significantly increase memeory usage and reduce
+    /// performance.  Using a smaller value is an easy way to reduce
+    /// memory consumption.
+    ///
+    virtual void SetMaxCurvePoints (INT32 maxCurvePoints) = 0;
+
+
+    ///////////////////////////////////////////////////////////////////////////
+    /// \brief
     /// Checks the internal contents of the object for consistency.
     ///
     /// <!-- Syntax in .Net, Java, and PHP -->
@@ -696,6 +729,26 @@
     virtual double GetConvergenceAngle (MgCoordinate* location) = 0;
     virtual double GetProjectiveGridScale (MgCoordinate* location) = 0;
 
+    // The following may be used to determine if a specific grid generation
+    // should be attempted.  The returned values are approximate and is in bytes.
+    // The proposed grid boundary for the grid object hosting this interface must
+    // set prior to calling this function.  Failure to do so will cause a -1
+    // return value.
+    virtual INT32 ApproxGridLineMemoryUsage (MgCoordinateSystemGridSpecification* specification) = 0;
+    virtual INT32 ApproxGridRegionMemoryUsage (MgCoordinateSystemGridSpecification* specification) = 0;
+    virtual INT32 ApproxGridTickMemoryUsage (MgCoordinateSystemGridSpecification* specification) = 0;
+
+    // Each grid object establishes a hard coded value and will throw an exception
+    // before generating a grid which, accordinag to the grid object estimates, will
+    // cause memory usage to exceed the hard coded value.  Use the following functions
+    // to modify the threshold for the exception.  Such modification remains in effect
+    // only within the existence of the modified object.
+    // These functions return the previous value and make no changes if the argument
+    // value is less than 10MB.  The memoryUseMax argument is always in bytes.
+    virtual INT32 SetGridLineExceptionLevel (INT32 memoryUseMax) = 0;
+    virtual INT32 SetGridRegionExceptionLevel (INT32 memoryUseMax) = 0;
+    virtual INT32 SetGridTickExceptionLevel (INT32 memoryUseMax) = 0;
+
     virtual INT32 GetLastError() = 0;
     virtual void ResetLastError()= 0;
     virtual bool AreExceptionsOn() = 0;
@@ -723,6 +776,7 @@
     virtual MgLineStringCollection* GetSegmentCollection(void)= 0;
     virtual void SetSegmentCollection (MgLineStringCollection* segmentCollection) = 0;
 INTERNAL_API:
+    virtual INT32 GetMemoryUsage (void) = 0;
 protected:
     INT32 GetClassId(){return m_cls_id;};
 CLASS_ID:
@@ -750,6 +804,7 @@
     virtual MgLineStringCollection* GetWestLine (void) = 0;
 
 INTERNAL_API:
+    virtual INT32 GetMemoryUsage (void) = 0;
 protected:
     INT32 GetClassId(){return m_cls_id;};
 CLASS_ID:
@@ -773,6 +828,7 @@
     virtual MgCoordinate* GetPosition () = 0;
     virtual MgCoordinate* GetDirectionVector () = 0;
 INTERNAL_API:
+    virtual INT32 GetMemoryUsage (void) = 0;
 protected:
     INT32 GetClassId(){return m_cls_id;};
 CLASS_ID:
@@ -797,6 +853,7 @@
     virtual void SetItem (INT32 index, MgCoordinateSystemGridLine* value)=0;
     virtual void Add (MgCoordinateSystemGridLine* value)=0;
     virtual void AddCollection (MgCoordinateSystemGridLineCollection* aGridLineCollection)=0;
+    virtual INT32 GetMemoryUsage (void) = 0;
 
 protected:
     INT32 GetClassId(){return m_cls_id;};
@@ -817,6 +874,8 @@
 INTERNAL_API:
     virtual void SetItem (INT32 index, MgCoordinateSystemGridRegion* value)=0;
     virtual void Add (MgCoordinateSystemGridRegion* value)=0;
+    virtual INT32 GetMemoryUsage (void) = 0;
+
 protected:
     INT32 GetClassId(){return m_cls_id;};
 CLASS_ID:
@@ -838,6 +897,8 @@
 INTERNAL_API:
     virtual void SetItem (INT32 index, MgCoordinateSystemGridTick* value)=0;
     virtual void Add (MgCoordinateSystemGridTick* value)=0;
+    virtual INT32 GetMemoryUsage (void) = 0;
+
 protected:
     INT32 GetClassId(){return m_cls_id;};
 CLASS_ID:

Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrs.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -76,11 +76,25 @@
     /// The MGRS string to be converted.
     /// /returns
     /// The geographic coordinates of the location identified by the provided
-    /// MGRS string.
+    /// MGRS string (center of the grid sqaure).
     virtual MgCoordinate* ConvertToLonLat(CREFSTRING sMgrs)=0;
 
     ///////////////////////////////////////////////////////////////////////////
     /// /brief
+    /// Converts an MGRS string to geographic coordinates.
+    /// /param sMgrs
+    /// The MGRS string to be converted.
+    /// /param grdSqrPosition
+    /// A value from the MgCoordinateSystemMgrsGridSquarePosition enumeration
+    /// which indicates the position within the grid sqaure referenced by
+    /// the sMgrs argumjent which is to be returned.
+    /// /returns
+    /// The geographic coordinates of the location identified by the provided
+    /// MGRS string.
+    virtual MgCoordinate* ConvertToLonLat(CREFSTRING sMgrs, INT32 grdSqrPosition)=0;
+
+    ///////////////////////////////////////////////////////////////////////////
+    /// /brief
     /// Returns a value as defined by the MgCoordinateSystemMgrsLetteringScheme
     /// object indicating which lettering scheme is currently active.
     /// /returns
@@ -92,7 +106,7 @@
     //section that reads/writes MGRS coordinates
     virtual INT32 ConvertFromLonLat(double dLongitude, double dLatitude, INT32 nPrecision, REFSTRING sMgrs)=0;
     virtual INT32 ConvertFromLonLat(MgCoordinate* pLonLat, INT32 nPrecision, REFSTRING sMgrs)=0;
-    virtual INT32 ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat)=0;
+    virtual INT32 ConvertToLonLat(CREFSTRING sMgrs, MgCoordinate* pLonLat, INT32 grdSqrPosition)=0;
 
 protected:
     INT32 GetClassId(){return m_cls_id;};

Added: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrsGridSquarePosition.h
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrsGridSquarePosition.h	                        (rev 0)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystemMgrsGridSquarePosition.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -0,0 +1,83 @@
+//
+//  Copyright (C) 2004-2009 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef _MGCOORDINATESYSTEMMGRSGRIDSQUAREPOSITION_H_
+#define _MGCOORDINATESYSTEMMGRSGRIDSQUAREPOSITION_H_
+
+///////////////////////////////////////////////////////////////////////////////
+///<summary>
+/// MgCoordinateSystemMgrsGridSquarePosition defines enumerated values used to
+/// specify the the location desired relative to the subject MGRS grid sqaure
+/// when evaluating an MGRS string.
+///
+/// Note that the values used in this enumeration match those used by the
+// CS-MAP interface.
+///</summary>
+class MG_GEOMETRY_API MgCoordinateSystemMgrsGridSquarePosition
+{
+    // MENTOR_MAINTENANCE --> These enumeration values are assumed to be the
+    // same as those used by CS-MAP.
+public:
+    ///////////////////////////////////////////////////////////////////////////
+    ///<summary>
+    /// Specifies the grid square position is not set as yet.
+    ///</summary>
+    static const INT32 None = 0;
+    ///<summary>
+    /// Specifies the center of the grid square; the default previous to this
+    /// reivison (Dec 2009).
+    ///</summary>
+    static const INT32 Center = 1;
+    ///<summary>
+    /// Specifies the southwest corner of the MGRS grid square.
+    ///</summary>
+    static const INT32 SouthWest = 2;
+    ///<summary>
+    /// Specifies the midpoint of the western edge of the MGRS grid square.
+    ///</summary>
+    static const INT32 West = 3;
+    ///<summary>
+    /// Specifies the northwest corner of the MGRS grid square.
+    ///</summary>
+    static const INT32 NorthWest = 4;
+    ///<summary>
+    /// Specifies the midpoint of the northern edge of the MGRS grid square.
+    ///</summary>
+    static const INT32 North = 5;
+    ///<summary>
+    /// Specifies the southwest corner of the MGRS grid square.
+    ///</summary>
+    static const INT32 NorthEast = 6;
+    ///<summary>
+    /// Specifies the midpoint of the eastern edge of the MGRS grid square.
+    ///</summary>
+    static const INT32 East = 7;
+    ///<summary>
+    /// Specifies the southeast corner of the MGRS grid square.
+    ///</summary>
+    static const INT32 SouthEast = 8;
+    ///<summary>
+    /// Specifies the midpoint of the southern edge of the MGRS grid square.
+    ///</summary>
+    static const INT32 South = 9;
+    ///<summary>
+    /// Specifies an error return value, end of table, or other abnormal situation.
+    ///</summary>
+    static const INT32 Unknown = 10;
+};
+
+#endif //_MGCOORDINATESYSTEMMGRSGRIDSQUAREPOSITION_H_

Modified: trunk/MgDev/Common/Geometry/Geometry.vcproj
===================================================================
--- trunk/MgDev/Common/Geometry/Geometry.vcproj	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/Geometry.vcproj	2009-12-04 16:33:48 UTC (rev 4375)
@@ -3298,6 +3298,10 @@
 			>
 		</File>
 		<File
+			RelativePath=".\CoordinateSystem\CoordinateSystemMgrsGridSquarePosition.h"
+			>
+		</File>
+		<File
 			RelativePath=".\CoordinateXY.cpp"
 			>
 			<FileConfiguration

Modified: trunk/MgDev/Common/Geometry/GeometryCommon.h
===================================================================
--- trunk/MgDev/Common/Geometry/GeometryCommon.h	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/GeometryCommon.h	2009-12-04 16:33:48 UTC (rev 4375)
@@ -145,6 +145,7 @@
 #include "CoordinateSystem/CoordinateSystemGridGeneric.h"                   //for MgCoordinateSystemGridGeneric
 #include "CoordinateSystem/CoordinateSystemMgrsGridLevel.h"                 //for MgCoordinateSystemMgrsGridLevel
 #include "CoordinateSystem/CoordinateSystemMgrsLetteringScheme.h"           //for MgCoordinateSystemMgrsLetteringScheme
+#include "CoordinateSystem/CoordinateSystemMgrsGridSquarePosition.h"        //for MgCoordinateSystemMgrsGridSquarePosition
 #include "CoordinateSystem/CoordinateSystemMgrs.h"                          //for MgCoordinateSystemMgrs
 #include "CoordinateSystem/CoordinateSystemFactory.h"
 

Modified: trunk/MgDev/Common/Geometry/Makefile.am
===================================================================
--- trunk/MgDev/Common/Geometry/Makefile.am	2009-12-04 00:00:33 UTC (rev 4374)
+++ trunk/MgDev/Common/Geometry/Makefile.am	2009-12-04 16:33:48 UTC (rev 4375)
@@ -327,6 +327,7 @@
   CoordinateSystem/CoordinateSystemGrids.h \
   CoordinateSystem/CoordinateSystemGridGeneric.h \
   CoordinateSystem/CoordinateSystemMgrsGridLevel.h \
+  CoordinateSystem/CoordinateSystemMgrsGridSquarePosition.h \
   CoordinateSystem/CoordinateSystemMgrsLetteringScheme.h \
   CoordinateSystem/CoordinateSystemMgrs.h \
   Exception/CoordinateSystemComputationFailedException.h \



More information about the mapguide-commits mailing list