GME  13
AnnotationNode.cpp
Go to the documentation of this file.
00001 // AnnotationNode.cpp: implementation of the CAnnotationNode class.
00002 //
00004 
00005 #include "stdafx.h"
00006 #include "mgautil.h"
00007 #include "AnnotationNode.h"
00008 #include "..\Annotator\AnnotationDefs.h"
00009 #include "AnnotationBrowserDlg.h"
00010 #include "AnnotationUtil.h"
00011 
00012 #ifdef _DEBUG
00013 #undef THIS_FILE
00014 static char THIS_FILE[]=__FILE__;
00015 #define new DEBUG_NEW
00016 #endif
00017 
00018 
00020 // Construction/Destruction
00022 LOGFONT CAnnotationNode::defFont;
00023 COLORREF CAnnotationNode::defColor;
00024 COLORREF CAnnotationNode::defBgcolor;
00025 COLORREF CAnnotationNode::defShadowcolor;
00026 COLORREF CAnnotationNode::defGradientcolor;
00027 bool CAnnotationNode::classIsInitialized        = false;
00028 bool CAnnotationNode::defInheritable            = false;
00029 bool CAnnotationNode::defHidden                         = false;
00030 bool CAnnotationNode::defCanBeRederived         = false;
00031 bool CAnnotationNode::defGradientFill           = false;
00032 int  CAnnotationNode::defGradientDirection      = 0;
00033 bool CAnnotationNode::defCastShadow                     = false;
00034 int  CAnnotationNode::defShadowDepth            = 9;
00035 int  CAnnotationNode::defShadowDirection        = 45;
00036 bool CAnnotationNode::defRoundCornerRect        = false;
00037 int  CAnnotationNode::defRoundCornerRadius      = 9;
00038 
00039 CAnnotationNode::CAnnotationNode(const CComPtr<IMgaRegNode> &regNode, IMgaFCOPtr& archetype)
00040 {
00041         m_regNode = regNode;
00042         m_archetype = archetype;
00043         if (!classIsInitialized) {
00044                 InitializeClass();
00045         }
00046 }
00047 
00048 void CAnnotationNode::Read(CAnnotationBrowserDlg *dlg)
00049 {
00050         try {
00051                 m_canBeRederived = false;
00052                 if (m_archetype)
00053                 {
00054                         for_each_subnode([&](IMgaRegNodePtr& regnode)
00055                         {
00056                                 long status = ATTSTATUS_UNDEFINED;
00057                                 regnode->GetStatus(&status);
00058                                 if (status == ATTSTATUS_HERE)
00059                                 {
00060                                         m_canBeRederived = true;
00061                                 }
00062                         });
00063                 }
00064         }
00065         catch (hresult_exception &) {
00066                 ASSERT(("Error while reading annotation from registry.", false));
00067         }
00068 
00069         // Annotation name
00070         try {
00071                 CComBSTR bstr;
00072                 COMTHROW(m_regNode->get_Name(&bstr));
00073                 m_name = bstr;
00074         }
00075         catch (hresult_exception &) {
00076                 ASSERT(("Error while reading annotation from registry.", false));
00077                 m_name = _T("ERROR!!!");
00078         }
00079         
00080         // Annotation text
00081         try {
00082                 CComBSTR bstr;
00083                 COMTHROW(m_regNode->get_Value(&bstr));
00084                 m_text = bstr;
00085                 m_text = CAnnotationUtil::ResolveNewLinesToCRLF(m_text);
00086         }
00087         catch (hresult_exception &) {
00088                 ASSERT(("Error while reading annotation from registry.", false));
00089                 m_text = _T("Unable to read annotation text.");
00090         }
00091 
00092         // 'Inheritable'
00093         try {
00094                 m_inheritable = defInheritable;
00095                 CComBSTR bstr;
00096                 CComPtr<IMgaRegNode> lfNode;
00097                 CComBSTR lfName(AN_INHERITABLE);
00098                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00099                 if (lfNode != NULL) {
00100                         COMTHROW(lfNode->get_Value(&bstr));
00101                         if (bstr == L"1")
00102                                 m_inheritable = true;
00103                 }
00104         }
00105         catch (hresult_exception &) {
00106                 m_inheritable = defInheritable;
00107         }
00108 
00109         // 'Hidden'
00110         try {
00111                 m_hidden = defHidden;
00112                 CComBSTR bstr;
00113                 CComPtr<IMgaRegNode> lfNode;
00114                 CComBSTR lfName(AN_HIDDEN);
00115                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00116                 if (lfNode != NULL) {
00117                         COMTHROW(lfNode->get_Value(&bstr));
00118                         if (bstr == L"1")
00119                                 m_hidden = true;
00120                 }
00121         }
00122         catch (hresult_exception &) {
00123                 m_hidden = defHidden;
00124         }
00125 
00126         // Font
00127         try {
00128                 CComBSTR bstr;
00129                 CComPtr<IMgaRegNode> lfNode;
00130                 CComBSTR lfName(AN_FONT_PREF);
00131                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00132                 if (lfNode != NULL) {
00133                         COMTHROW(lfNode->get_Value(&bstr));
00134                 }
00135                 CString str(bstr);
00136                 if (!CAnnotationUtil::LogfontDecode(str, &m_logfont)) {
00137                         memcpy(&m_logfont, &defFont, sizeof(LOGFONT));
00138                 }
00139         }
00140         catch (hresult_exception &) {
00141                 memcpy(&m_logfont, &defFont, sizeof(LOGFONT));
00142         }
00143 
00144         // Text Color
00145         try {
00146                 CComBSTR bstr;
00147                 CComPtr<IMgaRegNode> colNode;
00148                 CComBSTR colName(AN_COLOR_PREF);
00149                 COMTHROW(m_regNode->get_SubNodeByName(colName, &colNode));
00150                 if (colNode != NULL) {
00151                         COMTHROW(colNode->get_Value(&bstr));
00152                 }
00153                 CString strVal(bstr);
00154                 unsigned int val;
00155                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00156                         unsigned int r = (val & 0xff0000) >> 16;
00157                         unsigned int g = (val & 0xff00) >> 8;
00158                         unsigned int b = val & 0xff;
00159                         m_color = RGB(r,g,b);
00160                 }
00161                 else {
00162                         m_color = defColor;
00163                 }
00164         }
00165         catch (hresult_exception &) {
00166                 m_color = defColor;
00167         }
00168 
00169         // Background Color
00170         try {
00171                 CComBSTR bstr;
00172                 CComPtr<IMgaRegNode> bgcolNode;
00173                 CComBSTR bgcolName(AN_BGCOLOR_PREF);
00174                 COMTHROW(m_regNode->get_SubNodeByName(bgcolName, &bgcolNode));
00175                 if (bgcolNode != NULL) {
00176                         COMTHROW(bgcolNode->get_Value(&bstr));
00177                 }
00178                 CString strVal(bstr);
00179                 unsigned int val;
00180                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00181                         unsigned int r = (val & 0xff0000) >> 16;
00182                         unsigned int g = (val & 0xff00) >> 8;
00183                         unsigned int b = val & 0xff;
00184                         m_bgcolor = RGB(r,g,b);
00185                 }
00186                 else {
00187                         m_bgcolor = defBgcolor;
00188                 }
00189         }
00190         catch (hresult_exception &) {
00191                 m_bgcolor = AN_DEFAULT_BGCOLOR;
00192         }
00193 
00194         // Gradient Color
00195         try {
00196                 CComBSTR bstr;
00197                 CComPtr<IMgaRegNode> gradientcolNode;
00198                 CComBSTR gradientcolName(AN_GRADIENTCOLOR_PREF);
00199                 COMTHROW(m_regNode->get_SubNodeByName(gradientcolName, &gradientcolNode));
00200                 if (gradientcolNode != NULL) {
00201                         COMTHROW(gradientcolNode->get_Value(&bstr));
00202                 }
00203                 CString strVal(bstr);
00204                 unsigned int val;
00205                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00206                         unsigned int r = (val & 0xff0000) >> 16;
00207                         unsigned int g = (val & 0xff00) >> 8;
00208                         unsigned int b = val & 0xff;
00209                         m_crGradient = RGB(r,g,b);
00210                 }
00211                 else {
00212                         m_crGradient = defGradientcolor;
00213                 }
00214         }
00215         catch (hresult_exception &) {
00216                 m_crGradient = AN_DEFAULT_GRADIENTCOLOR;
00217         }
00218 
00219         // Shadow Color
00220         try {
00221                 CComBSTR bstr;
00222                 CComPtr<IMgaRegNode> bordercolNode;
00223                 CComBSTR bordercolName(AN_SHADOWCOLOR_PREF);
00224                 COMTHROW(m_regNode->get_SubNodeByName(bordercolName, &bordercolNode));
00225                 if (bordercolNode != NULL) {
00226                         COMTHROW(bordercolNode->get_Value(&bstr));
00227                 }
00228                 CString strVal(bstr);
00229                 unsigned int val;
00230                 if (_stscanf(strVal,_T("%x"),&val) == 1) {
00231                         unsigned int r = (val & 0xff0000) >> 16;
00232                         unsigned int g = (val & 0xff00) >> 8;
00233                         unsigned int b = val & 0xff;
00234                         m_crShadow = RGB(r,g,b);
00235                 }
00236                 else {
00237                         m_crShadow = defShadowcolor;
00238                 }
00239         }
00240         catch (hresult_exception &) {
00241                 m_crShadow = AN_DEFAULT_SHADOWCOLOR;
00242         }
00243 
00244         // 'GradienFill'
00245         try {
00246                 m_bGradientFill = defGradientFill;
00247                 CComBSTR bstr;
00248                 CComPtr<IMgaRegNode> lfNode;
00249                 CComBSTR lfName(AN_GRADIENTFILL_PREF);
00250                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00251                 if (lfNode != NULL) {
00252                         COMTHROW(lfNode->get_Value(&bstr));
00253                         if (bstr == L"1")
00254                                 m_bGradientFill = true;
00255                         else
00256                                 m_bGradientFill = false;
00257                 }
00258         }
00259         catch (hresult_exception &) {
00260                 m_bGradientFill = defGradientFill;
00261         }
00262 
00263         // 'GradientDirection'
00264         try {
00265                 m_iGradientDirection = defGradientDirection;
00266                 CComBSTR bstr;
00267                 CComPtr<IMgaRegNode> lfNode;
00268                 CComBSTR lfName(AN_GRADIENTDIRECTION_PREF);
00269                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00270                 if (lfNode != NULL) {
00271                         COMTHROW(lfNode->get_Value(&bstr));
00272                         CString strVal(bstr);
00273                         if (_stscanf(strVal,_T("%ld"),&m_iGradientDirection) != 1) {
00274                                 m_iGradientDirection = defGradientDirection;
00275                         }
00276                 }
00277         }
00278         catch (hresult_exception &) {
00279                 m_iGradientDirection = defGradientDirection;
00280         }
00281 
00282         // 'CastShadow'
00283         try {
00284                 m_bCastShadow = defCastShadow;
00285                 CComBSTR bstr;
00286                 CComPtr<IMgaRegNode> lfNode;
00287                 CComBSTR lfName(AN_CASTSHADOW_PREF);
00288                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00289                 if (lfNode != NULL) {
00290                         COMTHROW(lfNode->get_Value(&bstr));
00291                         if (bstr == L"1")
00292                                 m_bCastShadow = true;
00293                         else
00294                                 m_bCastShadow = false;
00295                 }
00296         }
00297         catch (hresult_exception &) {
00298                 m_bCastShadow = defCastShadow;
00299         }
00300 
00301         // 'ShadowDepth'
00302         try {
00303                 m_iShadowDepth = defShadowDepth;
00304                 CComBSTR bstr;
00305                 CComPtr<IMgaRegNode> lfNode;
00306                 CComBSTR lfName(AN_SHADOWDEPTH_PREF);
00307                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00308                 if (lfNode != NULL) {
00309                         COMTHROW(lfNode->get_Value(&bstr));
00310                         CString strVal(bstr);
00311                         if (_stscanf(strVal,_T("%ld"),&m_iShadowDepth) != 1) {
00312                                 m_iShadowDepth = defShadowDepth;
00313                         }
00314                 }
00315         }
00316         catch (hresult_exception &) {
00317                 m_iShadowDepth = defShadowDepth;
00318         }
00319 
00320         // 'ShadowDirection'
00321         try {
00322                 m_iShadowDirection = defShadowDirection;
00323                 CComBSTR bstr;
00324                 CComPtr<IMgaRegNode> lfNode;
00325                 CComBSTR lfName(AN_SHADOWDIRECTION_PREF);
00326                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00327                 if (lfNode != NULL) {
00328                         COMTHROW(lfNode->get_Value(&bstr));
00329                         CString strVal(bstr);
00330                         if (_stscanf(strVal,_T("%ld"),&m_iShadowDirection) != 1) {
00331                                 m_iShadowDirection = defShadowDirection;
00332                         }
00333                 }
00334         }
00335         catch (hresult_exception &) {
00336                 m_iShadowDirection = defShadowDirection;
00337         }
00338 
00339         // 'RoundCornerRect'
00340         try {
00341                 m_bRoundCornerRect = defRoundCornerRect;
00342                 CComBSTR bstr;
00343                 CComPtr<IMgaRegNode> lfNode;
00344                 CComBSTR lfName(AN_ROUNDCORNERRECT_PREF);
00345                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00346                 if (lfNode != NULL) {
00347                         COMTHROW(lfNode->get_Value(&bstr));
00348                         if (bstr == L"1")
00349                                 m_bRoundCornerRect = true;
00350                         else
00351                                 m_bRoundCornerRect = false;
00352                 }
00353         }
00354         catch (hresult_exception &) {
00355                 m_bRoundCornerRect = defRoundCornerRect;
00356         }
00357 
00358         // 'RoundCornerRadius'
00359         try {
00360                 m_iRoundCornerRadius = defRoundCornerRadius;
00361                 CComBSTR bstr;
00362                 CComPtr<IMgaRegNode> lfNode;
00363                 CComBSTR lfName(AN_ROUNDCORNERRADIUS_PREF);
00364                 COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00365                 if (lfNode != NULL) {
00366                         COMTHROW(lfNode->get_Value(&bstr));
00367                         CString strVal(bstr);
00368                         if (_stscanf(strVal,_T("%ld"),&m_iRoundCornerRadius) != 1) {
00369                                 m_iRoundCornerRadius = defRoundCornerRadius;
00370                         }
00371                 }
00372         }
00373         catch (hresult_exception &) {
00374                 m_iRoundCornerRadius = defRoundCornerRadius;
00375         }
00376 
00377         // Aspects
00378         m_aspects.SetSize(dlg->m_aspectNames.GetSize());
00379         CComPtr<IMgaRegNode> aspRoot;
00380         CComBSTR aspRootName(AN_ASPECTS);
00381         COMTHROW(m_regNode->get_SubNodeByName(aspRootName, &aspRoot));
00382         for (int aspIdx = 0; aspIdx < dlg->m_aspectNames.GetSize(); aspIdx++) {
00383                 if (aspIdx == 0) {
00384                         m_aspects[aspIdx].m_isLocDef = false;
00385 
00386                         CComBSTR defName(AN_DEFASPECT);
00387                         CComPtr<IMgaRegNode> defNode;
00388                         COMTHROW(aspRoot->get_SubNodeByName(defName, &defNode));
00389                         long status;
00390                         COMTHROW(defNode->get_Status(&status));
00391                         m_aspects[aspIdx].m_isVisible = (status != ATTSTATUS_UNDEFINED);
00392 
00393                         CComBSTR  rootVal;
00394                         COMTHROW(aspRoot->get_Value(&rootVal));
00395                         CString rootValStr(rootVal);
00396                         long lx, ly;
00397                         if(_stscanf(rootValStr,_T("%d,%d"), &lx, &ly) == 2) {
00398                                 m_aspects[aspIdx].m_loc = CPoint(lx,ly);        
00399                         }
00400                         else {
00401                                 m_aspects[aspIdx].m_loc = CPoint(0,0);
00402                         }
00403                 }
00404                 else {
00405                         CComBSTR aspName(dlg->m_aspectNames[aspIdx]);
00406                         CComPtr<IMgaRegNode> aspNode;
00407                         COMTHROW(aspRoot->get_SubNodeByName(aspName, &aspNode));
00408                         long status;
00409                         COMTHROW(aspNode->get_Status(&status));
00410                         if (status == ATTSTATUS_UNDEFINED) {
00411                                 m_aspects[aspIdx].m_isVisible = false;
00412                                 m_aspects[aspIdx].m_loc = m_aspects[0].m_loc;
00413                                 m_aspects[aspIdx].m_isLocDef = true;
00414                         }
00415                         else {
00416                                 m_aspects[aspIdx].m_isVisible = true;
00417                                 CComBSTR  aspVal;
00418                                 COMTHROW(aspNode->get_Value(&aspVal));
00419                                 CString aspValStr(aspVal);
00420                                 long lx, ly;
00421                                 if(_stscanf(aspValStr,_T("%d,%d"), &lx, &ly) == 2) {
00422                                         m_aspects[aspIdx].m_loc = CPoint(lx,ly);
00423                                         m_aspects[aspIdx].m_isLocDef = false;
00424                                 }
00425                                 else {
00426                                         m_aspects[aspIdx].m_loc = m_aspects[0].m_loc;
00427                                         m_aspects[aspIdx].m_isLocDef = true;
00428                                 }
00429                         }
00430                 }
00431         }
00432 }
00433 
00434 void CAnnotationNode::Write(CAnnotationBrowserDlg *dlg)
00435 {
00436         // it will notify if we just broke an annotation inheritance relationship (if text in the derived becomes different than the base's text)
00437         bool broken_inheritance = false;
00438 
00439         // Drop previous node, start new one
00440         try {
00441                 CComPtr<IMgaRegNode> parentNode;
00442                 COMTHROW(m_regNode->get_ParentNode(&parentNode));
00443 
00444                 // get the old text, used later to check if subtypes/instances break the derivation chain of the annotation
00445                 CComBSTR bstr1;
00446                 COMTHROW(m_regNode->get_Value(&bstr1));
00447                 CString old_m_text = bstr1;
00448                 old_m_text = CAnnotationUtil::ResolveNewLinesToCRLF(old_m_text);
00449 
00450                 COMTHROW(m_regNode->RemoveTree()); // we will write a new one
00451         }
00452         catch (hresult_exception &) {
00453                 ASSERT(("Error while creating annotation to registry.", false));
00454                 return;
00455         }
00456 
00457         // Store text
00458         try {
00459                 CString tmpstr = CAnnotationUtil::ResolveNewLinesToLF(m_text);
00460                 CComBSTR bstr(tmpstr);
00461                 COMTHROW(m_regNode->put_Value(bstr));
00462         }
00463         catch (hresult_exception &) {
00464                 ASSERT(("Error while writing annotation to registry.", false));
00465         }
00466 
00467         CComPtr<IMgaRegNode>& regNode = m_regNode;
00468         auto storeInt = [&regNode](int default_, int value, const TCHAR* regName)
00469         {
00470                 try {
00471                         CComPtr<IMgaRegNode> lfNode;
00472                         CComBSTR lfName(regName);
00473                         COMTHROW(regNode->get_SubNodeByName(lfName, &lfNode));
00474                         if (default_ != value)
00475                         {
00476                                 CString str;
00477                                 str.Format(_T("%ld"), value);
00478                                 CComBSTR bstr(str);
00479                                 COMTHROW(lfNode->put_Value(bstr));
00480                         }
00481                 }
00482                 catch (hresult_exception &) {
00483                         ASSERT(("Error while writing annotation to registry.", false));
00484                 }
00485         };
00486 
00487         auto storeBool = [&regNode](bool default_, bool value, const TCHAR* regName)
00488         {
00489                 try {
00490                         CComPtr<IMgaRegNode> lfNode;
00491                         CComBSTR lfName(regName);
00492                         COMTHROW(regNode->get_SubNodeByName(lfName, &lfNode));
00493                         if (default_ != value)
00494                         {
00495                                 CString str(value ? _T("1") : _T("0"));
00496                                 CComBSTR bstr(str);
00497                                 COMTHROW(lfNode->put_Value(bstr));
00498                         }
00499                 }
00500                 catch (hresult_exception &) {
00501                         ASSERT(("Error while writing annotation to registry.", false));
00502                 }
00503         };
00504 
00505         auto storeColorRef = [&regNode](COLORREF default_, COLORREF value, const TCHAR* regName)
00506         {
00507                 try {
00508                         CComPtr<IMgaRegNode> colNode;
00509                         CComBSTR colName(regName);
00510                         COMTHROW(regNode->get_SubNodeByName(colName, &colNode));
00511                         if (default_ != value) {
00512                                 unsigned long ival = value;
00513                                 unsigned long r = (ival & 0xff0000) >> 16;
00514                                 unsigned long g = (ival & 0xff00) >> 8;
00515                                 unsigned long b = ival & 0xff;
00516                                 ival = (unsigned long)(RGB(r,g,b));
00517                                 CString str;
00518                                 str.Format(_T("0x%06x"), (unsigned long)ival);
00519                                 CComBSTR bstr(str);
00520                                 COMTHROW(colNode->put_Value(bstr));
00521                         }
00522                 }
00523                 catch (hresult_exception &) {
00524                         ASSERT(("Error while writing annotation to registry.", false));
00525                 }
00526         };
00527 
00528         storeInt(defInheritable, m_inheritable, AN_INHERITABLE);
00529 
00530         storeBool(defHidden, m_hidden, AN_HIDDEN);
00531 
00532         // Store color,bgcolor,font preferences
00533         if (memcmp(&m_logfont, &defFont, sizeof(LOGFONT)) != 0) {
00534                 try {
00535                         CString str;
00536                         CAnnotationUtil::LogfontEncode(str, &m_logfont);
00537                         CComBSTR bstr(str);
00538                         CComPtr<IMgaRegNode> lfNode;
00539                         CComBSTR lfName(AN_FONT_PREF);
00540                         COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
00541                         COMTHROW(lfNode->put_Value(bstr));
00542                 }
00543                 catch (hresult_exception &) {
00544                         ASSERT(("Error while writing annotation to registry.", false));
00545                 }
00546         }
00547 
00548         storeColorRef(defColor, m_color, AN_COLOR_PREF);
00549 
00550         storeColorRef(defBgcolor, m_bgcolor, AN_BGCOLOR_PREF);
00551 
00552         storeColorRef(defShadowcolor, m_crShadow, AN_SHADOWCOLOR_PREF);
00553 
00554         storeColorRef(defGradientcolor, m_crGradient, AN_GRADIENTCOLOR_PREF);
00555 
00556         storeBool(defGradientFill, m_bGradientFill, AN_GRADIENTFILL_PREF);
00557 
00558         storeInt(defGradientDirection, m_iGradientDirection, AN_GRADIENTDIRECTION_PREF);
00559 
00560         storeBool(defCastShadow, m_bCastShadow, AN_CASTSHADOW_PREF);
00561 
00562         storeInt(defShadowDepth, m_iShadowDepth, AN_SHADOWDEPTH_PREF);
00563 
00564         storeInt(defShadowDirection, m_iShadowDirection, AN_SHADOWDIRECTION_PREF);
00565 
00566         storeBool(defRoundCornerRect, m_bRoundCornerRect, AN_ROUNDCORNERRECT_PREF);
00567 
00568         storeInt(defRoundCornerRadius, m_iRoundCornerRadius, AN_ROUNDCORNERRADIUS_PREF);
00569 
00570         // Store default location & aspect visibility
00571         CComPtr<IMgaRegNode> aspRoot;
00572         CComBSTR aspRootName(AN_ASPECTS);
00573         COMTHROW(m_regNode->get_SubNodeByName(aspRootName, &aspRoot));
00574         for (int aspIdx = 0; aspIdx < dlg->m_aspectNames.GetSize(); aspIdx++) {
00575                 if (aspIdx == 0) {
00576                         CString rootValStr;
00577                         rootValStr.Format(_T("%d,%d"), m_aspects[aspIdx].m_loc.x, m_aspects[aspIdx].m_loc.y);
00578                         CComBSTR  rootVal(rootValStr);
00579                         COMTHROW(aspRoot->put_Value(rootVal));
00580 
00581                         CComBSTR defName(AN_DEFASPECT);
00582                         CComPtr<IMgaRegNode> defNode;
00583                         COMTHROW(aspRoot->get_SubNodeByName(defName, &defNode));
00584                         if (m_aspects[aspIdx].m_isVisible) {
00585                                 CComBSTR defVal(AN_VISIBLE_DEFAULT);
00586                                 COMTHROW(defNode->put_Value(defVal));
00587                         }
00588                         else // by default a value is inserted into the AN_DEFASPECT key in the registry
00589                         {    // in CGMEView::OnCntxInsertannotation() so we remove in case the user 
00590                                  // did UNCHECK that option
00591                                 long st;
00592                                 COMTHROW( defNode->get_Status( &st));
00593                                 if( st == ATTSTATUS_HERE) COMTHROW( defNode->Clear());
00594                         }
00595                 }
00596                 else {
00597                         if (m_aspects[aspIdx].m_isVisible) {
00598                                 CComBSTR aspName(dlg->m_aspectNames[aspIdx]);
00599                                 CComPtr<IMgaRegNode> aspNode;
00600                                 COMTHROW(aspRoot->get_SubNodeByName(aspName, &aspNode));
00601                                 CString aspValStr;
00602                                 if (m_aspects[aspIdx].m_isLocDef) {
00603                                         aspValStr = AN_VISIBLE_DEFAULT;
00604                                 }
00605                                 else {
00606                                         aspValStr.Format(_T("%d,%d"), m_aspects[aspIdx].m_loc.x, m_aspects[aspIdx].m_loc.y);
00607                                 }
00608                                 CComBSTR  aspVal(aspValStr);
00609                                 COMTHROW(aspNode->put_Value(aspVal));
00610                         }
00611                 }
00612         }
00613 
00614         if (m_archetype)
00615         {
00616                 for_each_subnode([&](IMgaRegNodePtr& regnode)
00617                 {
00618                         /*
00619                         IMgaRegNodePtr archetypeReg = m_archetype->RegistryNode[regnode->Path];
00620                         long status = ATTSTATUS_UNDEFINED;
00621                         archetypeReg->GetStatus(&status);
00622                         if (status != ATTSTATUS_UNDEFINED && archetypeReg->Value == regnode->Value)
00623                         {
00624                                 regnode->
00625                         }*/
00626                         if (m_archetype->RegistryValue[regnode->Path] == regnode->Value)
00627                         {
00628                                 regnode->Clear();
00629                         }
00630                 });
00631         }
00632 
00633 }
00634 
00635 void CAnnotationNode::InitializeClass()
00636 {
00637         CAnnotationUtil::FillLogFontWithDefault(&defFont);
00638 
00639         defColor = AN_DEFAULT_COLOR;
00640 
00641         defBgcolor = AN_DEFAULT_BGCOLOR;
00642 
00643         defShadowcolor = AN_DEFAULT_SHADOWCOLOR;
00644 
00645         defGradientcolor = AN_DEFAULT_GRADIENTCOLOR;
00646 
00647         classIsInitialized = true;
00648 }