[commit] r2404 - in trunk/GME: Annotator Gme MgaUtil

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Fri Dec 6 16:19:39 CST 2013


Author: ksmyth
Date: Fri Dec  6 16:19:38 2013
New Revision: 2404

Log:
Fix Annotation editor

Modified:
   trunk/GME/Annotator/AnnotationDefs.h
   trunk/GME/Gme/GMEView.cpp
   trunk/GME/Gme/GUIObject.cpp
   trunk/GME/Gme/GUIObject.h
   trunk/GME/MgaUtil/AnnotationBrowserDlg.cpp
   trunk/GME/MgaUtil/AnnotationNode.cpp
   trunk/GME/MgaUtil/AnnotationNode.h
   trunk/GME/MgaUtil/MgaUtil.rc

Modified: trunk/GME/Annotator/AnnotationDefs.h
==============================================================================
--- trunk/GME/Annotator/AnnotationDefs.h	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/Annotator/AnnotationDefs.h	Fri Dec  6 16:19:38 2013	(r2404)
@@ -10,7 +10,6 @@
 #define AN_ROOT						_T("annotations")
 #define AN_INHERITABLE				_T("inheritable")
 #define AN_HIDDEN					_T("hidden")
-#define AN_BROKEN_DERIV				_T("brokenDeriv")
 #define AN_COLOR_PREF				_T("color")
 #define AN_BGCOLOR_PREF				_T("bgcolor")
 #define AN_GRADIENTCOLOR_PREF		_T("gradientcolor")

Modified: trunk/GME/Gme/GMEView.cpp
==============================================================================
--- trunk/GME/Gme/GMEView.cpp	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/Gme/GMEView.cpp	Fri Dec  6 16:19:38 2013	(r2404)
@@ -2050,7 +2050,7 @@
 		CComPtr<IMgaRegNode> anNode;
 		anNode = MGACOLL_ITER;
 		bool arch = !isSubType && isType; // archetype if not subtype and not instance (type)
-		if( arch || !arch && CGuiAnnotator::Showable( anNode ))
+		if( arch || (!arch && CGuiAnnotator::Showable(anNode, baseType)))
 		{
 			CGuiAnnotator *annotator = new CGuiAnnotator(currentModel, anNode, this, guiMeta->NumberOfAspects());
 			annList.AddTail(annotator);

Modified: trunk/GME/Gme/GUIObject.cpp
==============================================================================
--- trunk/GME/Gme/GUIObject.cpp	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/Gme/GUIObject.cpp	Fri Dec  6 16:19:38 2013	(r2404)
@@ -612,27 +612,26 @@
 		if(_stscanf(str,_T("%d,%d"), &lx, &ly) == 2) {
 			decoratorData[aspect]->location.left = lx;
 			decoratorData[aspect]->location.top = ly;
-		}
-		else {
-			throw hresult_exception();
+			return;
 		}
 	}
 	catch (hresult_exception &) {
-		try {
-			CComPtr<IMgaRegNode> rootNode;
-			COMTHROW(aspNode->get_ParentNode(&rootNode));
-			CComBSTR bstrRoot;
-			COMTHROW(rootNode->get_Value(&bstrRoot));
-			CString strRoot(bstrRoot);
-			long lxr, lyr;
-			if(_stscanf(strRoot,_T("%d,%d"), &lxr, &lyr) == 2) {
-				decoratorData[aspect]->location.left = lxr;
-				decoratorData[aspect]->location.top = lyr;
-			}
-		}
-		catch (hresult_exception &) {
+	}
+	try {
+		CComPtr<IMgaRegNode> rootNode;
+		COMTHROW(aspNode->get_ParentNode(&rootNode));
+		CComBSTR bstrRoot;
+		COMTHROW(rootNode->get_Value(&bstrRoot));
+		CString strRoot(bstrRoot);
+		long lxr, lyr;
+		if(_stscanf(strRoot,_T("%d,%d"), &lxr, &lyr) == 2) {
+			decoratorData[aspect]->location.left = lxr;
+			decoratorData[aspect]->location.top = lyr;
+			return;
 		}
 	}
+	catch (hresult_exception &) {
+	}
 }
 
 void  CGuiAnnotator::WriteLocation(int aspect)
@@ -771,12 +770,6 @@
 
 	CComBSTR bstr(L"1");
 
-	// inheritance broken node inserted
-	CComPtr<IMgaRegNode> brokNode;
-	CComBSTR brokNm(AN_BROKEN_DERIV);
-	COMTHROW( mRootNode->get_SubNodeByName(brokNm, &brokNode));
-	COMTHROW( brokNode->put_Value(bstr));
-
 	// hidden node set to true
 	CComPtr<IMgaRegNode> hideNode;
 	CComBSTR hideNm(AN_HIDDEN);
@@ -787,7 +780,7 @@
 }
 
 // static
-bool CGuiAnnotator::Showable( CComPtr<IMgaRegNode>& mRootNode )
+bool CGuiAnnotator::Showable( CComPtr<IMgaRegNode>& mRootNode, CComPtr<IMgaFCO>& baseType )
 {   // decides whether an annotation should be displayed in case of a subtype/instance
 	// Subtype/instance may have: owned annotations (not present in the ancestor) -> main status = ATTSTATUS_HERE
 	//                            inherited annotations                           -> main status = ATTSTATUS_INHERITED1,2,...
@@ -796,41 +789,39 @@
 		CComBSTR bName;
 		COMTHROW(mRootNode->get_Name(&bName));
 
-		// if value of rootnode defined HERE, then show it only iff 'hide' not set
-		long status;
-		COMTHROW(mRootNode->get_Status(&status));
-		if( status == ATTSTATUS_HERE)
+		bool hidden_set = false;
+		CComPtr<IMgaRegNode> hideNode;
+		CComBSTR hideNm(AN_HIDDEN);
+		COMTHROW(mRootNode->get_SubNodeByName( hideNm, &hideNode));
+		if (hideNode)
 		{
-			bool hidden_set = false;
-			CComPtr<IMgaRegNode> hideNode;
-			CComBSTR hideNm(AN_HIDDEN);
-			COMTHROW(mRootNode->get_SubNodeByName( hideNm, &hideNode));
-			if (hideNode)
+			long hideStatus;
+			COMTHROW( hideNode->get_Status( &hideStatus));
+			if( hideStatus != ATTSTATUS_UNDEFINED)  // meta, here or inherited
 			{
-				long hideStatus;
-				COMTHROW( hideNode->get_Status( &hideStatus));
-				if( hideStatus != ATTSTATUS_UNDEFINED)  // meta, here or inherited
-				{
-					CComBSTR bstr;
-					COMTHROW( hideNode->get_Value( &bstr));
-					if( bstr == L"1")
-						hidden_set = true;
-				}
+				CComBSTR bstr;
+				COMTHROW( hideNode->get_Value( &bstr));
+				if( bstr == L"1")
+					return false;
 			}
-
-			return !hidden_set;
 		}
 
-		// the value of mRootNode is inherited (is NOT HERE)
-		CComPtr<IMgaRegNode> inheritNode;
-		CComBSTR inhName(AN_INHERITABLE);
-		COMTHROW(mRootNode->get_SubNodeByName( inhName, &inheritNode));
-
-		if (inheritNode) {
-			CComBSTR bstr;
-			COMTHROW(inheritNode->get_Value( &bstr));
-			if (bstr == L"1") // if "inheritable" is 1 show it
-				return true;
+		if (baseType->GetRegistryValue(mRootNode->Path).length())
+		{
+			CComPtr<IMgaRegNode> inheritNode;
+			CComBSTR inhName(AN_INHERITABLE);
+			COMTHROW(mRootNode->get_SubNodeByName( inhName, &inheritNode));
+
+			if (inheritNode) {
+				CComBSTR bstr;
+				COMTHROW(inheritNode->get_Value( &bstr));
+				if (bstr == L"1") // if "inheritable" is 1 show it
+					return true;
+			}
+		}
+		else
+		{
+			return true;
 		}
 	}
 	catch(hresult_exception &e) {

Modified: trunk/GME/Gme/GUIObject.h
==============================================================================
--- trunk/GME/Gme/GUIObject.h	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/Gme/GUIObject.h	Fri Dec  6 16:19:38 2013	(r2404)
@@ -145,7 +145,7 @@
 	static void MoveAnnotations(CGuiAnnotatorList& annList, CPoint& pt);
 	static void FindUpperLeft(CGuiAnnotatorList& anns, int& left, int& top);
 	static void ShiftAnnotations(CGuiAnnotatorList& annList, CPoint& shiftBy);
-	static bool Showable( CComPtr<IMgaRegNode>& mRootNode);
+	static bool Showable( CComPtr<IMgaRegNode>& mRootNode, CComPtr<IMgaFCO>& baseType);
 	static int  Hide( CComPtr<IMgaRegNode>& mRootNode);
 	CComPtr<IMgaElementDecorator> GetDecorator(int asp) { return decoratorData[asp]->decorator; }
 

Modified: trunk/GME/MgaUtil/AnnotationBrowserDlg.cpp
==============================================================================
--- trunk/GME/MgaUtil/AnnotationBrowserDlg.cpp	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/MgaUtil/AnnotationBrowserDlg.cpp	Fri Dec  6 16:19:38 2013	(r2404)
@@ -137,6 +137,7 @@
 		CComBSTR bstr_tmp;
 		COMTHROW(m_model->get_Name(&bstr_tmp));
 		CopyTo(bstr_tmp, m_modelName);
+		SetWindowTextW(L"Annotations for '" + m_modelName + "'");
 
 		CComPtr<IMgaMetaFCO> metaFco;
 		COMTHROW(m_model->get_Meta(&metaFco));
@@ -301,7 +302,7 @@
 		MGACOLL_ITERATE(IMgaRegNode, subNodes) {
 			CComPtr<IMgaRegNode> subNode;
 			subNode = MGACOLL_ITER;
-			CAnnotationNode *node = new CAnnotationNode(subNode);
+			CAnnotationNode *node = new CAnnotationNode(subNode, m_model->DerivedFrom);
 			node->Read(this);
 			m_annotations.AddTail(node);
 		}
@@ -410,11 +411,25 @@
 	m_inheritable.SetCheck( node->m_inheritable? BST_CHECKED:BST_UNCHECKED );
 	
 	// rederive btn
-	m_rederiveBtn.EnableWindow(node->m_canBeRederived || node->m_virtual);
+	m_rederiveBtn.EnableWindow(node->m_canBeRederived);
 	
 	// show/hide btn
 	m_showHideBtn.SetWindowText(node->m_hidden?show_str:hide_str);
-	m_showHideBtn.EnableWindow(node->m_hidden || node->m_canBeRederived || node->m_virtual);// show only in case of subtype/instance or if hidden
+	m_showHideBtn.EnableWindow(node->m_hidden);
+	if (node->m_hidden == false && node->m_archetype)
+	{
+		IMgaRegNodePtr archetypeRegNode = node->m_archetype->RegistryNode[node->m_regNode->Path];
+		long status = ATTSTATUS_UNDEFINED;
+		archetypeRegNode->GetStatus(&status);
+		if (status == ATTSTATUS_UNDEFINED)
+		{
+			m_showHideBtn.EnableWindow(FALSE);
+		}
+		else
+		{
+			m_showHideBtn.EnableWindow(TRUE);
+		}
+	}
 
 	memcpy(&m_anLogFont, &(node->m_logfont), sizeof(LOGFONT));
 	m_colorbtn.currentcolor = node->m_color;
@@ -533,7 +548,8 @@
 		CAnnotationNode *node = (CAnnotationNode *)m_wndAnnotationList.GetItemData(nItem);
 		
 		// rederive by clearing the node contents
-		if(node && !node->m_virtual) COMTHROW(node->m_regNode->RemoveTree());
+		if (node)
+			COMTHROW(node->m_regNode->RemoveTree());
 		
 		// read back the values from node->regNode, this time (i)nherited values are read
 		node->Read( this);

Modified: trunk/GME/MgaUtil/AnnotationNode.cpp
==============================================================================
--- trunk/GME/MgaUtil/AnnotationNode.cpp	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/MgaUtil/AnnotationNode.cpp	Fri Dec  6 16:19:38 2013	(r2404)
@@ -36,9 +36,10 @@
 bool CAnnotationNode::defRoundCornerRect	= false;
 int  CAnnotationNode::defRoundCornerRadius	= 9;
 
-CAnnotationNode::CAnnotationNode(const CComPtr<IMgaRegNode> &regNode)
+CAnnotationNode::CAnnotationNode(const CComPtr<IMgaRegNode> &regNode, IMgaFCOPtr& archetype)
 {
 	m_regNode = regNode;
+	m_archetype = archetype;
 	if (!classIsInitialized) {
 		InitializeClass();
 	}
@@ -46,37 +47,25 @@
 
 void CAnnotationNode::Read(CAnnotationBrowserDlg *dlg)
 {
-	// virtual: if status of m_regNode is 'inherited'
 	try {
-		m_virtual = false;
-		long st;
-		COMTHROW( m_regNode->get_Status( &st));
-		if( st > ATTSTATUS_HERE) // -1: meta, 0: here, >=1: inherited
-			m_virtual = true;
-	}
-	catch (hresult_exception &) {
-		ASSERT(("Error while reading annotation from registry.", false));
-		m_virtual = false;
-	}
-
-	// it can be rederived if 'broken deriv' entry present with '1'
-	try {
-		m_canBeRederived = defCanBeRederived;
-		CComBSTR bstr;
-		CComPtr<IMgaRegNode> lfNode;
-		CComBSTR lfName(AN_BROKEN_DERIV);
-		COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-		if (lfNode != NULL) {
-			COMTHROW(lfNode->get_Value(&bstr));
-			if (bstr == L"1")
-				m_canBeRederived = true;
+		m_canBeRederived = false;
+		if (m_archetype)
+		{
+			for_each_subnode([&](IMgaRegNodePtr& regnode)
+			{
+				long status = ATTSTATUS_UNDEFINED;
+				regnode->GetStatus(&status);
+				if (status == ATTSTATUS_HERE)
+				{
+					m_canBeRederived = true;
+				}
+			});
 		}
 	}
 	catch (hresult_exception &) {
-		m_canBeRederived = defCanBeRederived;
+		ASSERT(("Error while reading annotation from registry.", false));
 	}
 
-
 	// Annotation name
 	try {
 		CComBSTR bstr;
@@ -145,7 +134,7 @@
 		}
 		CString str(bstr);
 		if (!CAnnotationUtil::LogfontDecode(str, &m_logfont)) {
-			throw hresult_exception();
+			memcpy(&m_logfont, &defFont, sizeof(LOGFONT));
 		}
 	}
 	catch (hresult_exception &) {
@@ -170,7 +159,7 @@
 			m_color = RGB(r,g,b);
 		}
 		else {
-			throw hresult_exception();
+			m_color = defColor;
 		}
 	}
 	catch (hresult_exception &) {
@@ -458,38 +447,7 @@
 		CString old_m_text = bstr1;
 		old_m_text = CAnnotationUtil::ResolveNewLinesToCRLF(old_m_text);
 
-		if(!m_virtual) COMTHROW(m_regNode->RemoveTree()); // remove the old node if it was HERE, because we will write a new node there
-		else // virtual node: still inherited
-		{ 
-			// keep the derivation chain if the text has not been changed
-			if( old_m_text == m_text)
-				return;
-			else// This value will only signal that the chain is broken.
-				// By writing under the same node into a subtype's registry
-				// we can hide the inherited value with a HERE value.
-				broken_inheritance = true;
-		}
-
-		bool collision = true;
-		while (collision) {
-			m_regNode = NULL;
-			CComBSTR bstrName(m_name);
-			COMTHROW(parentNode->get_SubNodeByName(bstrName, &m_regNode));
-			long status;
-			COMTHROW(m_regNode->get_Status(&status));
-			if (status == ATTSTATUS_UNDEFINED) {
-				collision = false;
-			}
-			else {
-				if(broken_inheritance // if we broke right now the inheritance
-				 || m_canBeRederived) // or it was broken in the past
-					collision = false;// don't signal a 'collision' since we
-				                      // have to hide the old (i)nherited value
-				                      // with a (h)ere value
-				else
-					m_name += _T("Copy");
-			}
-		}
+		COMTHROW(m_regNode->RemoveTree()); // we will write a new one
 	}
 	catch (hresult_exception &) {
 		ASSERT(("Error while creating annotation to registry.", false));
@@ -506,50 +464,70 @@
 		ASSERT(("Error while writing annotation to registry.", false));
 	}
 
-	// Store 'broken derivation' preference (if text has been altered in the subtyped object's annotation)
-	// either broken in the past (canBeRederived) or broken right now(broken_inh)
-	if( m_canBeRederived || broken_inheritance) {
+	CComPtr<IMgaRegNode>& regNode = m_regNode;
+	auto storeInt = [&regNode](int default_, int value, const TCHAR* regName)
+	{
 		try {
-			CComBSTR bstr(L"1");
 			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_BROKEN_DERIV);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
+			CComBSTR lfName(regName);
+			COMTHROW(regNode->get_SubNodeByName(lfName, &lfNode));
+			if (default_ != value)
+			{
+				CString str;
+				str.Format(_T("%ld"), value);
+				CComBSTR bstr(str);
+				COMTHROW(lfNode->put_Value(bstr));
+			}
 		}
 		catch (hresult_exception &) {
 			ASSERT(("Error while writing annotation to registry.", false));
 		}
-	}
+	};
 
-	// Store 'inheritable' preference
+	auto storeBool = [&regNode](bool default_, bool value, const TCHAR* regName)
 	{
 		try {
-			CString str(m_inheritable?_T("1"):_T("0"));
-			CComBSTR bstr(str);
 			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_INHERITABLE);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
+			CComBSTR lfName(regName);
+			COMTHROW(regNode->get_SubNodeByName(lfName, &lfNode));
+			if (default_ != value)
+			{
+				CString str(value ? _T("1") : _T("0"));
+				CComBSTR bstr(str);
+				COMTHROW(lfNode->put_Value(bstr));
+			}
 		}
 		catch (hresult_exception &) {
 			ASSERT(("Error while writing annotation to registry.", false));
 		}
-	}
+	};
 
-	// Store 'hidden' preference
+	auto storeColorRef = [&regNode](COLORREF default_, COLORREF value, const TCHAR* regName)
 	{
 		try {
-			CString str(m_hidden?_T("1"):_T("0"));
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_HIDDEN);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
+			CComPtr<IMgaRegNode> colNode;
+			CComBSTR colName(regName);
+			COMTHROW(regNode->get_SubNodeByName(colName, &colNode));
+			if (default_ != value) {
+				unsigned long ival = value;
+				unsigned long r = (ival & 0xff0000) >> 16;
+				unsigned long g = (ival & 0xff00) >> 8;
+				unsigned long b = ival & 0xff;
+				ival = (unsigned long)(RGB(r,g,b));
+				CString str;
+				str.Format(_T("0x%06x"), (unsigned long)ival);
+				CComBSTR bstr(str);
+				COMTHROW(colNode->put_Value(bstr));
+			}
 		}
 		catch (hresult_exception &) {
 			ASSERT(("Error while writing annotation to registry.", false));
 		}
-	}
+	};
+
+	storeInt(defInheritable, m_inheritable, AN_INHERITABLE);
+
+	storeBool(defHidden, m_hidden, AN_HIDDEN);
 
 	// Store color,bgcolor,font preferences
 	if (memcmp(&m_logfont, &defFont, sizeof(LOGFONT)) != 0) {
@@ -567,198 +545,27 @@
 		}
 	}
 
-	if (m_color != defColor) {
-		try {
-			unsigned long ival = m_color;
-			unsigned long r = (ival & 0xff0000) >> 16;
-			unsigned long g = (ival & 0xff00) >> 8;
-			unsigned long b = ival & 0xff;
-			ival = (unsigned long)(RGB(r,g,b));
-			CString str;
-			str.Format(_T("0x%06x"), (unsigned long)ival);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> colNode;
-			CComBSTR colName(AN_COLOR_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(colName, &colNode));
-			COMTHROW(colNode->put_Value(bstr));
-		
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeColorRef(defColor, m_color, AN_COLOR_PREF);
 
-	if (m_bgcolor != defBgcolor) {
-		try {
-			unsigned long ival = m_bgcolor;
-			unsigned long r = (ival & 0xff0000) >> 16;
-			unsigned long g = (ival & 0xff00) >> 8;
-			unsigned long b = ival & 0xff;
-			ival = (unsigned long)(RGB(r,g,b));
-			CString str;
-			str.Format(_T("0x%06x"), (unsigned long)ival);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> bgcolNode;
-			CComBSTR bgcolName(AN_BGCOLOR_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(bgcolName, &bgcolNode));
-			COMTHROW(bgcolNode->put_Value(bstr));
-		
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeColorRef(defBgcolor, m_bgcolor, AN_BGCOLOR_PREF);
 
-	if (m_crShadow != defShadowcolor) {
-		try {
-			unsigned long ival = m_crShadow;
-			unsigned long r = (ival & 0xff0000) >> 16;
-			unsigned long g = (ival & 0xff00) >> 8;
-			unsigned long b = ival & 0xff;
-			ival = (unsigned long)(RGB(r,g,b));
-			CString str;
-			str.Format(_T("0x%06x"), (unsigned long)ival);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> bordercolNode;
-			CComBSTR bordercolName(AN_SHADOWCOLOR_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(bordercolName, &bordercolNode));
-			COMTHROW(bordercolNode->put_Value(bstr));
-		
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeColorRef(defShadowcolor, m_crShadow, AN_SHADOWCOLOR_PREF);
 
-	if (m_crGradient != defGradientcolor) {
-		try {
-			unsigned long ival = m_crGradient;
-			unsigned long r = (ival & 0xff0000) >> 16;
-			unsigned long g = (ival & 0xff00) >> 8;
-			unsigned long b = ival & 0xff;
-			ival = (unsigned long)(RGB(r,g,b));
-			CString str;
-			str.Format(_T("0x%06x"), (unsigned long)ival);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> gradientcolNode;
-			CComBSTR gradientcolName(AN_GRADIENTCOLOR_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(gradientcolName, &gradientcolNode));
-			COMTHROW(gradientcolNode->put_Value(bstr));
-		
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeColorRef(defGradientcolor, m_crGradient, AN_GRADIENTCOLOR_PREF);
 
-	// Store 'gradientfill' preference
-	{
-		try {
-			CString str(m_bGradientFill ? _T("1") : _T("0"));
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_GRADIENTFILL_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeBool(defGradientFill, m_bGradientFill, AN_GRADIENTFILL_PREF);
 
-	// Store 'gradientdirection' preference
-	{
-		try {
-			CString str;
-			str.Format(_T("%ld"), m_iGradientDirection);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_GRADIENTDIRECTION_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeInt(defGradientDirection, m_iGradientDirection, AN_GRADIENTDIRECTION_PREF);
 
-	// Store 'castshadow' preference
-	{
-		try {
-			CString str(m_bCastShadow ? _T("1") : _T("0"));
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_CASTSHADOW_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeBool(defCastShadow, m_bCastShadow, AN_CASTSHADOW_PREF);
 
-	// Store 'shadowdepth' preference
-	{
-		try {
-			CString str;
-			str.Format(_T("%ld"), m_iShadowDepth);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_SHADOWDEPTH_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeInt(defShadowDepth, m_iShadowDepth, AN_SHADOWDEPTH_PREF);
 
-	// Store 'shadowdirection' preference
-	{
-		try {
-			CString str;
-			str.Format(_T("%ld"), m_iShadowDirection);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_SHADOWDIRECTION_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeInt(defShadowDirection, m_iShadowDirection, AN_SHADOWDIRECTION_PREF);
 
-	// Store 'roundcornerrect' preference
-	{
-		try {
-			CString str(m_bRoundCornerRect ? _T("1") : _T("0"));
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_ROUNDCORNERRECT_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeBool(defRoundCornerRect, m_bRoundCornerRect, AN_ROUNDCORNERRECT_PREF);
 
-	// Store 'roundcornerradius' preference
-	{
-		try {
-			CString str;
-			str.Format(_T("%ld"), m_iRoundCornerRadius);
-			CComBSTR bstr(str);
-			CComPtr<IMgaRegNode> lfNode;
-			CComBSTR lfName(AN_ROUNDCORNERRADIUS_PREF);
-			COMTHROW(m_regNode->get_SubNodeByName(lfName, &lfNode));
-			COMTHROW(lfNode->put_Value(bstr));
-		}
-		catch (hresult_exception &) {
-			ASSERT(("Error while writing annotation to registry.", false));
-		}
-	}
+	storeInt(defRoundCornerRadius, m_iRoundCornerRadius, AN_ROUNDCORNERRADIUS_PREF);
 
 	// Store default location & aspect visibility
 	CComPtr<IMgaRegNode> aspRoot;
@@ -803,6 +610,26 @@
 			}
 		}
 	}
+
+	if (m_archetype)
+	{
+		for_each_subnode([&](IMgaRegNodePtr& regnode)
+		{
+			/*
+			IMgaRegNodePtr archetypeReg = m_archetype->RegistryNode[regnode->Path];
+			long status = ATTSTATUS_UNDEFINED;
+			archetypeReg->GetStatus(&status);
+			if (status != ATTSTATUS_UNDEFINED && archetypeReg->Value == regnode->Value)
+			{
+				regnode->
+			}*/
+			if (m_archetype->RegistryValue[regnode->Path] == regnode->Value)
+			{
+				regnode->Clear();
+			}
+		});
+	}
+
 }
 
 void CAnnotationNode::InitializeClass()

Modified: trunk/GME/MgaUtil/AnnotationNode.h
==============================================================================
--- trunk/GME/MgaUtil/AnnotationNode.h	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/MgaUtil/AnnotationNode.h	Fri Dec  6 16:19:38 2013	(r2404)
@@ -9,6 +9,8 @@
 #pragma once
 #endif // _MSC_VER > 1000
 
+#include "..\Annotator\AnnotationDefs.h"
+#include <deque>
 
 class CAnnotationBrowserDlg;
 class CAnnotationAspect;
@@ -31,6 +33,7 @@
 {
 public:
 	CComPtr<IMgaRegNode> m_regNode;
+	IMgaFCOPtr m_archetype;
 	LOGFONT		m_logfont;
 	COLORREF	m_color;
 	COLORREF	m_bgcolor;
@@ -46,7 +49,6 @@
 	bool		m_bRoundCornerRect;
 	int			m_iRoundCornerRadius;
 
-	bool		m_virtual;			// if status of the main regnode is 'inherited'
 	bool		m_canBeRederived;	// the "broken_deriv" entry signals that
 									// the annotation was once inherited,
 									// so it could be rederived
@@ -55,10 +57,34 @@
 	bool		m_hidden;			// hide inherited annotation in this subtype/instance only
 	CAnnotationAspectArray	m_aspects;
 
-	CAnnotationNode(const CComPtr<IMgaRegNode> &regNode);
+	CAnnotationNode(const CComPtr<IMgaRegNode> &regNode, IMgaFCOPtr& archetype);
 	void Read(CAnnotationBrowserDlg *dlg);
 	void Write(CAnnotationBrowserDlg *dlg);
 
+	template<typename Func>
+	void for_each_subnode(Func f)
+	{
+		std::deque<IMgaRegNodePtr> regnodes;
+		regnodes.push_back(IMgaRegNodePtr(m_regNode.p));
+		while (regnodes.size())
+		{
+			IMgaRegNodePtr regnode = regnodes.front();
+			regnodes.pop_front();
+			f(regnode);
+			IMgaRegNodesPtr subnodes = regnode->GetSubNodes(VARIANT_FALSE);
+			for (int i = 1; i <= subnodes->Count; i++)
+			{
+				auto subnode = subnodes->GetItem(i);
+				if (regnode == m_regNode && wcscmp(subnode->Name, AN_HIDDEN) == 0)
+				{
+					continue;
+				}
+				regnodes.push_back(subnodes->GetItem(i));
+			}
+		}
+	}
+
+
 public:
 	static void InitializeClass();
 	static bool classIsInitialized;

Modified: trunk/GME/MgaUtil/MgaUtil.rc
==============================================================================
--- trunk/GME/MgaUtil/MgaUtil.rc	Mon Nov 18 11:10:08 2013	(r2403)
+++ trunk/GME/MgaUtil/MgaUtil.rc	Fri Dec  6 16:19:38 2013	(r2404)
@@ -226,7 +226,7 @@
     CONTROL         "List1",IDC_ANNOTATION_LIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,0,20,200,330
     EDITTEXT        IDC_EDIT_NAME,240,34,155,14,ES_AUTOHSCROLL
     EDITTEXT        IDC_EDIT_TEXT,240,53,155,60,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
-    CONTROL         "Inheritable",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | BS_PUSHLIKE | WS_TABSTOP,214,115,54,14
+    CONTROL         "Inheritable",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,214,115,45,14
     PUSHBUTTON      "Rederive",IDC_REDERIVEBUTTON,279,115,54,14
     PUSHBUTTON      "Show/Hide",IDC_SHOWHIDEBUTTON,341,115,54,14
     CONTROL         "COLOR",IDC_COMBO_COLOR,"Button",BS_OWNERDRAW | WS_TABSTOP,270,131,125,14


More information about the gme-commit mailing list