[mapguide-commits] r5130 - in sandbox/rfc94/Common: CoordinateSystem Geometry/CoordinateSystem

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Sep 13 04:43:18 EDT 2010


Author: baertelchen
Date: 2010-09-13 08:43:18 +0000 (Mon, 13 Sep 2010)
New Revision: 5130

Modified:
   sandbox/rfc94/Common/CoordinateSystem/CoordSysCategory.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysDictionaryBase.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysEnum.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCategory.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCoordinateSystemInCategory.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.h
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPathDictionary.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.h
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDefDictionary.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp
   sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.h
   sandbox/rfc94/Common/CoordinateSystem/MentorDictionary.h
   sandbox/rfc94/Common/CoordinateSystem/namestruct.cpp
   sandbox/rfc94/Common/CoordinateSystem/namestruct.h
   sandbox/rfc94/Common/Geometry/CoordinateSystem/CoordinateSystemGeodeticTransformDef.h
Log:
Due to the changes done in namestruct.cpp and namestruct.h where the char(s) are no longer held in a statically initialized array but the memory is dynamically allocated, clients must no longer have accessed TNameStruct.name directly. I haven't yet updated the code in CoordSysCategory*.* what yielded to heap corruptions because code there did set the name field directly. Set the name field private and added a new = operator so that clients can still set the field to the appropriate value.

Also added the new method "CreateTransformation" to the CoordSysGeodeticTransformDef class - this allows for creating a specific geodetic transformation (forward and inverse) without having CS Map determining the best transformation to use. It used to do that based on a source and target datum. This behavior will stay, of course. There shouldn't be any changes for existing API clients.

Remarks:
There're some changes not yet submitted from CS_Map; mainly headers.

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysCategory.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysCategory.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysCategory.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -46,7 +46,7 @@
 //
 char * CCoordinateSystemCategory::Name()
 {
-    return m_categoryName.name;
+    return const_cast<char*>(m_categoryName.Name());
 }
 
 //Saves the object to a file.  Purpose of the ulMinSize parameter:
@@ -102,7 +102,7 @@
     // 5. Blank space (if ulMinSize > size)
 
     //Name.
-    CS_fwrite(m_categoryName.name, sizeof(m_categoryName.name), 1, pFile);
+    CS_fwrite(m_categoryName.Name(), sizeof(char), knMaxCategoryNameLen, pFile);
 
     //Size.
     CS_fwrite(reinterpret_cast<char *>(&ulSize), sizeof(ulSize), 1, pFile);
@@ -114,7 +114,7 @@
     CSystemNameList::const_iterator iter;
     for (iter=m_listCoordinateSystemNames.begin(); iter!=m_listCoordinateSystemNames.end(); iter++)
     {
-        CS_fwrite((*iter).name, sizeof((*iter).name), 1, pFile);
+        CS_fwrite((*iter).Name(), sizeof(char), cs_KEYNM_DEF, pFile);
     }
 
     //Blank space, if needed
@@ -131,7 +131,7 @@
         CSystemName dummy(/*NOXLATE*/"fnord");
         for (UINT32 i=0; i<ulDiff; i++)
         {
-            CS_fwrite(dummy.name, sizeof(dummy.name), 1, pFile);
+            CS_fwrite(dummy.Name(), sizeof(char), cs_KEYNM_DEF, pFile);
         }
     }
 
@@ -185,13 +185,20 @@
     // 5. Blank space (if ulMinSize > size)
 
     //Name.
-    size_t nRead=CS_fread(m_categoryName.name, sizeof(m_categoryName.name), 1, pFile);
-    if (1!=nRead)
+    char tempCharBuffer[knMaxCategoryNameLen] = { '\0' };
+    const size_t expectedReadCount = sizeof(tempCharBuffer) / sizeof(char);
+    size_t nRead=CS_fread(tempCharBuffer, sizeof(char), expectedReadCount, pFile);
+    if (expectedReadCount != nRead)
     {
+        _ASSERT(0 == nRead); //otherwise something else is going on here...
+
         //we reached the end of the file
         throw new MgFileIoException(L"MgCoordinateSystemCategory.LoadFromFstream", __LINE__, __WFILE__, NULL, L"", NULL);
     }
 
+    //copy the category name into our [m_categoryName] TNameStruct
+    m_categoryName = tempCharBuffer;
+
     //Size.
     UINT32 ulSize;
     nRead=CS_fread(reinterpret_cast<char *>(&ulSize), sizeof(ulSize), 1, pFile);
@@ -213,18 +220,23 @@
         throw new MgFileIoException(L"MgCoordinateSystemCategory.LoadFromFstream", __LINE__, __WFILE__, NULL, L"", NULL);
     }
 
+    char keyNameBuffer[cs_KEYNM_DEF]  = { '\0' };
+    const size_t expectedBufferCountRead = sizeof(keyNameBuffer) / sizeof(char);
     //Coordinate system names.
     for (UINT32 i=0; i<ulSize; i++)
     {
-        nRead=CS_fread(member.name, sizeof(member.name), 1, pFile);
-        if (1!=nRead)
+        keyNameBuffer[0] = '\0';
+        nRead=CS_fread(keyNameBuffer, sizeof(char), expectedBufferCountRead, pFile);
+        if (expectedBufferCountRead != nRead)
         {
             throw new MgFileIoException(L"MgCoordinateSystemCategory.LoadFromFstream", __LINE__, __WFILE__, NULL, L"", NULL);
         }
 
+        member = keyNameBuffer;
+
         // TODO - WORKAROUND TO SKIP BAD COORDINATE SYSTEMS IN CURRENT DICTIONARIES
-        if((strcmp(member.name, "IGN63/Hiva") != 0) &&
-           (strcmp(member.name, "Phoenix") != 0))
+        if((strcmp(member.Name(), "IGN63/Hiva") != 0) &&
+           (strcmp(member.Name(), "Phoenix") != 0))
         {
             m_listCoordinateSystemNames.push_back(member);
         }
@@ -235,7 +247,7 @@
     ulDiff = ulMinSize - ulSize;
     if (ulDiff > 0)
     {
-        CS_fseek(pFile, CS_ftell(pFile) + ulDiff * sizeof(member.name), SEEK_SET);
+        CS_fseek(pFile, CS_ftell(pFile) + ulDiff * (sizeof(keyNameBuffer) / sizeof(char)), SEEK_SET);
     }
     if (ferror(pFile))
     {
@@ -297,7 +309,7 @@
     STRING sName;
 
     MG_TRY()
-    wchar_t *pName = Convert_Ascii_To_Wide(m_categoryName.name);
+    wchar_t *pName = Convert_Ascii_To_Wide(m_categoryName.Name());
     if (!pName)
     {
         throw new MgOutOfMemoryException(L"MgCoordinateSystemCategory.GetName", __LINE__, __WFILE__, NULL, L"", NULL);
@@ -326,7 +338,10 @@
     {
         throw new MgOutOfMemoryException(L"MgCoordinateSystemCategory.SetName", __LINE__, __WFILE__, NULL, L"", NULL);
     }
-    strcpy(m_categoryName.name, pName);
+    
+    //assign the name to our internal [TNameStruct]
+    m_categoryName = pName;
+
     delete [] pName;
     MG_CATCH_AND_THROW(L"MgCoordinateSystemCategory.SetName")
 }
@@ -346,7 +361,7 @@
 //
 bool CCoordinateSystemCategory::IsValid()
 {
-    return IsLegalName(m_categoryName.name);
+    return IsLegalName(m_categoryName.Name());
 }
 
 //Private member function which returns whether the specified string
@@ -546,7 +561,7 @@
     CSystemNameList::const_iterator iter;
     for (iter=m_listCoordinateSystemNames.begin(); iter!=m_listCoordinateSystemNames.end(); iter++)
     {
-        wchar_t *pName = Convert_Ascii_To_Wide((*iter).name);    //need to delete [] pName
+        wchar_t *pName = Convert_Ascii_To_Wide((*iter).Name());    //need to delete [] pName
         if (NULL == pName)
         {
             throw new MgOutOfMemoryException(L"MgCoordinateSystemCategory.GetCoordinateSystems", __LINE__, __WFILE__, NULL, L"", NULL);
@@ -670,7 +685,7 @@
 //
 void CCoordinateSystemCategory::Clear()
 {
-    memset(m_categoryName.name, 0, knMaxCategoryNameLen);
+    m_categoryName = "\0";
     m_listCoordinateSystemNames.clear();
 }
 

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysDictionaryBase.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysDictionaryBase.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysDictionaryBase.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -330,6 +330,10 @@
         if (NULL == allDictionaryEntries) //whatever happend here - the dictionay file seems to be invalid
             throw new MgCoordinateSystemLoadFailedException(L"CCoordinateSystemDictionaryBase.GetEnumImp", __LINE__, __WFILE__, NULL, L"", NULL);
     }
+    else
+    {
+        allDictionaryEntries = this->dictionaryItems;
+    }
 
     //create our enumerator we're returning to the caller
     pNew = new CCoordinateSystemEnum;
@@ -365,7 +369,7 @@
 T* DICTIONARY_BASE_TEMPLATE_METHOD::NewItem()
 {
     //new() throws an exception in case allocation fails; we don't take ownership
-    return new T(this->catalog);
+    return new T(this->catalog); //the callee has to incr. the ref counter, if it needs the catalog object
 }
 
 #endif //BUILD_DICTIONARY_BASE
\ No newline at end of file

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysEnum.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysEnum.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysEnum.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -110,7 +110,7 @@
             //success
             return pOutput.Detach();
         }
-        const char *kpName = (*m_iter).first.name;
+        const char *kpName = (*m_iter).first.Name();
         wchar_t* pStr = Convert_Ascii_To_Wide(kpName);
         if (NULL == pStr)
         {
@@ -160,7 +160,7 @@
             //success
             return pOutput.Detach();
         }
-        const char *kpName = (*m_iter).first.name;
+        const char *kpName = (*m_iter).first.Name();
         if (IsFilteredOut(kpName))
         {
             continue;
@@ -195,11 +195,11 @@
             //success
             return pOutput.Detach();
         }
-        if (IsFilteredOut((*m_iter).first.name))
+        if (IsFilteredOut((*m_iter).first.Name()))
         {
             continue;
         }
-        const char *kpDecsription = (*m_iter).second.name;
+        const char *kpDecsription = (*m_iter).second.Name();
         wchar_t *pwDecsription = Convert_Ascii_To_Wide(kpDecsription);
         if (NULL == pwDecsription)
         {
@@ -229,7 +229,7 @@
             //success
             return;
         }
-        const char *kpName = (*m_iter).first.name;
+        const char *kpName = (*m_iter).first.Name();
         if (IsFilteredOut(kpName))
         {
             continue;

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCategory.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCategory.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCategory.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -176,7 +176,7 @@
         }
 
         //get the category definition for the next name in the list
-        const char *kpName = (*(m_iter)).name;
+        const char *kpName = (*(m_iter)).Name();
         pStr = Convert_Ascii_To_Wide(kpName);
         if (NULL == pStr)
         {
@@ -229,7 +229,7 @@
             return pOutput.Detach();
         }
 
-        const char *kpName = (*m_iter).name;
+        const char *kpName = (*m_iter).Name();
         if (IsFilteredOut(kpName))
         {
             continue;
@@ -270,7 +270,7 @@
             //success
             return;
         }
-        const char *kpName = (*m_iter).name;
+        const char *kpName = (*m_iter).Name();
         if (IsFilteredOut(kpName))
         {
             continue;

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCoordinateSystemInCategory.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCoordinateSystemInCategory.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysEnumCoordinateSystemInCategory.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -111,7 +111,7 @@
         }
 
         //get the coordinate system name from the category
-        const char *kpName = (*m_iter).name;
+        const char *kpName = (*m_iter).Name();
 
         assert(IsLegalMentorName(kpName));
         pstr = Convert_Ascii_To_Wide(kpName);
@@ -163,7 +163,7 @@
             //success
             return pOutput.Detach();
         }
-        const char *kpName = (*m_iter).name;
+        const char *kpName = (*m_iter).Name();
 
         if (IsFilteredOut(kpName))
         {
@@ -213,7 +213,7 @@
             return pOutput.Detach();
         }
         //get the coordinate system name from the category
-        const char *kpName = (*m_iter).name;
+        const char *kpName = (*m_iter).Name();
 
         assert(IsLegalMentorName(kpName));
         pstr = Convert_Ascii_To_Wide(kpName);
@@ -264,7 +264,7 @@
             return;
         }
         //get the coordinate system name from the category
-        const char *kpName = (*m_iter).name;
+        const char *kpName = (*m_iter).Name();
         if (IsFilteredOut(kpName))
         {
             continue;

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -33,8 +33,10 @@
 #include "CoordSysMacro.h" //for DEFINE_GET_SET_STRING and DEFINE_GET_SET_NUMERIC
 
 CCoordinateSystemGeodeticPath::CCoordinateSystemGeodeticPath(MgCoordinateSystemCatalog* pCatalog)
-    : pathDefinition(NULL) //don't need the catalog
+    : pathDefinition(NULL), catalog(SAFE_ADDREF(pCatalog))
 {
+    if (NULL == pCatalog)
+        throw new MgNullArgumentException(L"CCoordinateSystemGeodeticPath.ctor", __LINE__, __WFILE__, NULL, L"", NULL);
 }
 
 CCoordinateSystemGeodeticPath::~CCoordinateSystemGeodeticPath()
@@ -78,7 +80,7 @@
 {
     VERIFY_INITIALIZED(L"CCoordinateSystemGeodeticPath.CreateClone");
 
-    Ptr<CCoordinateSystemGeodeticPath> clonedPath = new CCoordinateSystemGeodeticPath(NULL);
+    Ptr<CCoordinateSystemGeodeticPath> clonedPath = new CCoordinateSystemGeodeticPath(this->catalog);
     clonedPath->Initialize(*this->pathDefinition);
     clonedPath->pathDefinition->protect = 0; //unset the protection flag; otherwise the caller wouldn't be able to change any values
 

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.h
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.h	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPath.h	2010-09-13 08:43:18 UTC (rev 5130)
@@ -83,6 +83,7 @@
 
     private:
         cs_GeodeticPath_* pathDefinition;
+        Ptr<MgCoordinateSystemCatalog> catalog;
     };
 
 } //namespace CSLibrary

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPathDictionary.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPathDictionary.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticPathDictionary.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -117,10 +117,10 @@
 //-------------------------------------------------------------------------------
 MgCoordinateSystemGeodeticPath* CCoordinateSystemGeodeticPathDictionary::NewGeodeticPath()
 {
-    CCoordinateSystemGeodeticPath* newPathItem = this->m_pDictionary->NewItem();
+    Ptr<CCoordinateSystemGeodeticPath> newPathItem = this->m_pDictionary->NewItem();
     newPathItem->Reset(); //sets up the [cs_geodeticpath_] struct; it can thus be used by 
     
-    return newPathItem;
+    return newPathItem.Detach();
 }
 
 //-----------------------------------------------------------------------------

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -19,6 +19,7 @@
 #include "CoordSysCommon.h"
 #include "CriticalSection.h"
 
+#include "CoordSysGeodeticTransformation.h"
 #include "CoordSysGeodeticTransformDefParams.h"
 #include "CoordSysGeodeticAnalyticalTransformDefParams.h"
 #include "CoordSysGeodeticInterpolationTransformDefParams.h"
@@ -36,8 +37,11 @@
 #include "CoordSysMacro.h" //for DEFINE_GET_SET_STRING and DEFINE_GET_SET_NUMERIC
 
 CCoordinateSystemGeodeticTransformDef::CCoordinateSystemGeodeticTransformDef(MgCoordinateSystemCatalog* pCatalog)
-    : transformationDefType(0), transformDefinition(NULL)
+    : transformationDefType(0), transformDefinition(NULL), catalog(SAFE_ADDREF(pCatalog) /* make sure, we take a count on it */)
 {
+    //have we been passed a non-null argument?
+    if (NULL == this->catalog)
+        throw new MgNullArgumentException(L"CCoordinateSystemGeodeticTransformDef.ctor", __LINE__, __WFILE__, NULL, L"", NULL); 
 }
 
 CCoordinateSystemGeodeticTransformDef::~CCoordinateSystemGeodeticTransformDef()
@@ -130,7 +134,7 @@
     case cs_DTCMTH_BURSA:
     case cs_DTCMTH_FRAME:
     case cs_DTCMTH_7PARM:
-    case cs_DTCMTH_BDKUS:
+    case cs_DTCMTH_BDKAS:
         transformationType = MgCoordinateSystemGeodeticTransformDefType::Analytical;
         break;
 
@@ -178,11 +182,21 @@
     *this->transformDefinition = transformDef;
 }
 
+MgCoordinateSystemGeodeticTransformation* CCoordinateSystemGeodeticTransformDef::CreateTransformation(bool createInverse)
+{
+    VERIFY_INITIALIZED(L"CCoordinateSystemGeodeticTransformDef.CreateTransformation");
+    
+    //we don't take ownership of the transformation being returned but
+    //will release [sourceDatum] and [targetDatum];
+    //new [CCoordinateSystemGeodeticTransformation] will have to ADDREF if needed
+    return new CCoordinateSystemGeodeticTransformation(this->catalog, this, createInverse);
+}
+
 MgCoordinateSystemGeodeticTransformDef* CCoordinateSystemGeodeticTransformDef::CreateClone()
 {
     VERIFY_INITIALIZED(L"CCoordinateSystemGeodeticTransformDef.CreateClone");
 
-    Ptr<CCoordinateSystemGeodeticTransformDef> clonedTransformDef = new CCoordinateSystemGeodeticTransformDef(NULL);
+    Ptr<CCoordinateSystemGeodeticTransformDef> clonedTransformDef = new CCoordinateSystemGeodeticTransformDef(this->catalog.p);
     clonedTransformDef->Initialize(*this->transformDefinition);
     clonedTransformDef->transformDefinition->protect = 0; //unset the protection flag; otherwise the caller wouldn't be able to change any values
 

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.h
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.h	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDef.h	2010-09-13 08:43:18 UTC (rev 5130)
@@ -85,6 +85,8 @@
 
     virtual INT32 GetTransformDefType();
 
+    MgCoordinateSystemGeodeticTransformation* CreateTransformation(bool createInverse);
+
     //helper - don't delete
     virtual bool IsEncrypted();
     
@@ -100,6 +102,7 @@
 private:
     INT32 transformationDefType;
     cs_GeodeticTransform_* transformDefinition;
+    Ptr<MgCoordinateSystemCatalog> catalog;
 };
 
 } //namespace CSLibrary

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDefDictionary.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDefDictionary.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformDefDictionary.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -72,10 +72,10 @@
 
 MgCoordinateSystemGeodeticTransformDef* CCoordinateSystemGeodeticTransformDefDictionary::NewGeodeticTransformationDef(INT32 transformationDefType)
 {
-    CCoordinateSystemGeodeticTransformDef* newTransformDef = this->m_pDictionary->NewItem();
+    Ptr<CCoordinateSystemGeodeticTransformDef> newTransformDef = this->m_pDictionary->NewItem();
+    newTransformDef->Reset(transformationDefType); //sets up the [cs_geodeticTransfrom_] struct and initializes it to [transformationDefType]
     
-    newTransformDef->Reset(transformationDefType); //sets up the [cs_geodeticTransfrom_] struct and initializes it to [transformationDefType]
-    return newTransformDef; //this instance is not yet initialized
+    return newTransformDef.Detach(); //this instance is not yet initialized
 }
 
 MgCoordinateSystemGeodeticTransformDef* CCoordinateSystemGeodeticTransformDefDictionary::GetGeodeticTransformationDef(CREFSTRING transformationName)

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -40,6 +40,23 @@
 }
 
 //-----------------------------------------------------------------------------
+CCoordinateSystemGeodeticTransformation::CCoordinateSystemGeodeticTransformation(MgCoordinateSystemCatalog* pCatalog, MgCoordinateSystemGeodeticTransformDef* transformationDef, bool createInversed)
+: m_pDtcprm(NULL), m_pDtSource(NULL), m_pDtTarget(NULL)
+{
+    if (NULL == pCatalog || NULL == transformationDef)
+        throw new MgNullArgumentException(L"CCoordinateSystemGeodeticTransformation.ctor", __LINE__, __WFILE__, NULL, L"", NULL);
+
+    //this->Uninitialize(); //not needed - this does release the resourced held by this instance; we haven't set anything yet
+
+    this->SetCatalog(pCatalog);
+    
+    //now - setup ourselves from the [MgCoordinateSystemGeodeticTransformDef] we've been passed
+    //we'll not pass a source and a target datum to CS Map so it constructs the cs_Dtcprm_ struct
+    //but we'll do that because we already have a transformation
+    this->SetupFromTransformationDef(transformationDef, createInversed);
+}
+
+//-----------------------------------------------------------------------------
 CCoordinateSystemGeodeticTransformation::~CCoordinateSystemGeodeticTransformation()
 {
     Uninitialize();
@@ -337,6 +354,44 @@
     assert(!IsInitialized());
 }
 
+//Initializes this transformation instance from an [MgCoordinateSystemGeodeticTransformDef] object;
+//That is, we don't let CS Map find the appropriate transformation based on a source and a target
+//datum but will instruct CS Map to use the transformation defition we pass to it
+//
+void CCoordinateSystemGeodeticTransformation::SetupFromTransformationDef(MgCoordinateSystemGeodeticTransformDef* transformationDef, bool createInversed)
+{
+    char* transformName = Convert_Wide_To_Ascii(transformationDef->GetTransformName().c_str());
+    
+    MG_TRY()
+    
+    
+    //protect the call to the lib files; the calls to the [datumDictionary] below
+    //we also enter the critical section but on the same thread - i.e. no problem;
+    //putting the check here saves us from [enter, leave, enter leave]
+    SmartCriticalClass criticalSection(true);
+
+    //ask CS_Map for the transformation
+    cs_Dtcprm_* datumTransform = CSdtcsu1(transformName, createInversed ? cs_DTCDIR_INV : cs_DTCDIR_FWD, cs_DTCFLG_BLK_W);
+
+    if (NULL == datumTransform)
+        throw new MgInvalidArgumentException(L"CCoordinateSystemGeodeticTransformation.SetupFromTransformationDef", __LINE__, __WFILE__, NULL, L"", NULL);
+    
+    Ptr<MgCoordinateSystemDatumDictionary> datumDictionary = this->m_pCatalog->GetDatumDictionary();
+    Ptr<MgCoordinateSystemDatum> srcDatum = datumDictionary->GetDatum(transformationDef->GetSourceDatum());
+    Ptr<MgCoordinateSystemDatum> trgDatum = datumDictionary->GetDatum(transformationDef->GetTargetDatum());
+
+    this->m_pDtcprm = datumTransform;
+    this->m_pDtSource = srcDatum.Detach();  //m_pDtSource is no auto pointer
+    this->m_pDtTarget = trgDatum.Detach();  //m_pDtTarget is no auto pointer
+
+    MG_CATCH(L"CCoordinateSystemGeodeticTransformation.SetupFromTransformationDef")
+
+    if (NULL != transformName)
+        delete[] transformName;
+
+    MG_THROW()
+}
+
 //-----------------------------------------------------------------------------
 MgCoordinateSystemDatum* CCoordinateSystemGeodeticTransformation::GetWGS84()
 {

Modified: sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.h
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.h	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/CoordSysGeodeticTransformation.h	2010-09-13 08:43:18 UTC (rev 5130)
@@ -25,6 +25,7 @@
 {
 public:
     CCoordinateSystemGeodeticTransformation(MgCoordinateSystemCatalog* pCatalog, MgCoordinateSystemDatum* pSource, MgCoordinateSystemDatum *pTarget);
+    CCoordinateSystemGeodeticTransformation(MgCoordinateSystemCatalog* pCatalog, MgCoordinateSystemGeodeticTransformDef* transformationDef, bool createInversed);
     virtual ~CCoordinateSystemGeodeticTransformation();
 
     virtual void SetSourceAndTarget(MgCoordinateSystemDatum *pSource, MgCoordinateSystemDatum *pTarget);
@@ -66,6 +67,7 @@
     void SetCatalog(MgCoordinateSystemCatalog* pCatalog);
     bool GetDefinitionForGeodeticTransformationParameter(cs_Dtdef_& def);
     MgCoordinateSystemDatum* GetWGS84();
+    void SetupFromTransformationDef(MgCoordinateSystemGeodeticTransformDef* transformationDef, bool createInversed);
 
 protected:
     //Data members

Modified: sandbox/rfc94/Common/CoordinateSystem/MentorDictionary.h
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/MentorDictionary.h	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/MentorDictionary.h	2010-09-13 08:43:18 UTC (rev 5130)
@@ -244,7 +244,7 @@
                 //it.  (We can't just change the key in-place by
                 //modifying (*iter).first, since the key in a std::map
                 //pair is a const object.)
-                if (0 == strcmp(keyName, (*iter).first.name))
+                if (0 == strcmp(keyName, (*iter).first.Name()))
                 {
                     //The key name is unchanged; we can just update
                     //the summary.
@@ -254,7 +254,7 @@
                 {
                     //The name changed (case changed only).  We need
                     //to delete the item and re-insert it.
-                    assert(0 == CS_stricmp(keyName, (*iter).first.name));
+                    assert(0 == CS_stricmp(keyName, (*iter).first.Name()));
                     try
                     {
                         pmapSystemNameDescription->erase(iter);

Modified: sandbox/rfc94/Common/CoordinateSystem/namestruct.cpp
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/namestruct.cpp	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/namestruct.cpp	2010-09-13 08:43:18 UTC (rev 5130)
@@ -62,7 +62,7 @@
     name[stringLength] = '\0'; // finally, set the terminating NULL char in any case; the buffer is at least 1 char long
 }
 
-//Assignment operator
+//Assignment operator; assign based on other TNameStruct
 //
 TNameStruct& 
 TNameStruct::operator=(const TNameStruct& other)
@@ -71,6 +71,14 @@
     return *this;
 }
 
+//Assignment operator; assign based on string
+TNameStruct&
+TNameStruct::operator=(const char* newName)
+{
+    this->Init(newName);
+    return *this;
+}
+
 //Comparison operator (alphabetic, case-insensitive).
 //
 bool
@@ -104,4 +112,12 @@
 TNameStruct::operator!=(const TNameStruct& other) const
 {
     return (_stricmp(name, other.name) != 0);
+}
+
+//Returns this [TNameStruct] current char* pointer
+//
+const char*
+TNameStruct::Name() const
+{
+    return this->name;
 }
\ No newline at end of file

Modified: sandbox/rfc94/Common/CoordinateSystem/namestruct.h
===================================================================
--- sandbox/rfc94/Common/CoordinateSystem/namestruct.h	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/CoordinateSystem/namestruct.h	2010-09-13 08:43:18 UTC (rev 5130)
@@ -77,13 +77,21 @@
     //assignment
     TNameStruct& operator=(const TNameStruct&);
     
-    //data members
-    char* name;
+    //assignment
+    TNameStruct& operator=(const char* newName);
 
+    //misc. methods
+    const char* Name() const;
+    void Reset();
+
 private:
     //methods
     void Init(const char *kpName = NULL);
     void Release();
+
+private:
+    //data members
+    char* name;
 };
 
 //This struct holds a summary of a definition (just name and description,

Modified: sandbox/rfc94/Common/Geometry/CoordinateSystem/CoordinateSystemGeodeticTransformDef.h
===================================================================
--- sandbox/rfc94/Common/Geometry/CoordinateSystem/CoordinateSystemGeodeticTransformDef.h	2010-09-10 21:33:03 UTC (rev 5129)
+++ sandbox/rfc94/Common/Geometry/CoordinateSystem/CoordinateSystemGeodeticTransformDef.h	2010-09-13 08:43:18 UTC (rev 5130)
@@ -75,7 +75,7 @@
 
     virtual MgCoordinateSystemGeodeticTransformDef* CreateClone() = 0;
     
-    //MgCoordinateSystemGeodeticTransformation* CreateTransformation();
+    virtual MgCoordinateSystemGeodeticTransformation* CreateTransformation(bool createInverse) = 0;
 
 protected:
     /////////////////////////////////////////////////////////////////



More information about the mapguide-commits mailing list