[Mobies-commit] [commit] r4381 - in GReAT/trunk/Tools/MetaGME2UMX: . MetaGME2UMX Interpreters

ksmyth at redhat3.isis.vanderbilt.edu ksmyth at redhat3.isis.vanderbilt.edu
Fri Jul 22 16:30:44 CDT 2016


Author: ksmyth
Date: Fri Jul 22 16:30:44 2016
New Revision: 4381

Log:
Upgrade MetaGME2UML to latest Udm interpreter wizard, return real error messages to GME instead of just MessageBox()

Added:
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmConsole.cpp
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmConsole.h
Modified:
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.cpp
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.h
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UML_interpreterVS2010.vcxproj
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UMT_interpreterVS2010.vcxproj
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.cpp
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.h
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/StdAfx.h
   GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmApp.cpp

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.cpp
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.cpp	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.cpp	Fri Jul 22 16:30:44 2016	(r4381)
@@ -26,8 +26,6 @@
 #include "cctype"
 #include "UmlExt.h"
 
-#include "Mga.h"
-
 using namespace std;
 
 bool AskUserForConstraint(long);

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.h
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.h	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UML.h	Fri Jul 22 16:30:44 2016	(r4381)
@@ -26,9 +26,29 @@
 #include "stdafx.h"
 #include <string>
 #define MESSAGE_OUT(STR) if(param != GME_SILENT_MODE) AfxMessageBox(STR); else cout << STR << endl
-#include "Console.h"
+
+#if _MSC_VER >= 1900 || !defined(__INTELLISENSE__)
+// #import Meta, Mga, GME libs
+#import "libid:0adeec71-d83a-11d3-b36b-005004d38590" no_implementation auto_search no_namespace no_search_namespace
+#import "libid:270b4f86-b17c-11d3-9ad1-00aa00b6fe26" no_implementation auto_search no_namespace no_search_namespace
+#import "libid:0ADEEC71-D83A-11D3-B36B-005004CC8592" no_implementation auto_search no_namespace no_search_namespace
+#else
+// IntelliSense has a known issue with the above lines.
+//  http://connect.microsoft.com/VisualStudio/feedback/details/533526/vc-2010-intellisense-import-directive-using-libid-does-not-work
+#ifdef _DEBUG
+// If IntelliSense reports "Cannot open source file", compile then reopen the project
+#include "Debug\Meta.tlh"
+#include "Debug\Mga.tlh"
+#else
+#include "UMLRelease\Meta.tlh"
+#include "UMLRelease\Mga.tlh"
+#endif
+#endif
+
+
+#include "UdmConsole.h"
 static void ConsoleMessage(const std::string& msg) {
-	GMEConsole::Console::Out::WriteLine(CString(msg.c_str()));
+	GMEConsole::Console::Out::writeLine(msg.c_str());
 }
 #else
 #include <string>

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UML_interpreterVS2010.vcxproj
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UML_interpreterVS2010.vcxproj	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UML_interpreterVS2010.vcxproj	Fri Jul 22 16:30:44 2016	(r4381)
@@ -568,7 +568,6 @@
     <ClCompile Include="$(GME_ROOT)\Sdk\Bon\Common\ComponentDll.cpp">
     </ClCompile>
     <ClCompile Include="$(GME_ROOT)\SDK\BON\Common\ComponentObj.cpp" />
-    <ClCompile Include="$(GME_ROOT)\SDK\BON\Common\Console.cpp" />
     <ClCompile Include="$(GME_ROOT)\Sdk\Bon\Common\Exceptions.cpp" />
     <ClCompile Include="..\MetaGME2UML.cpp">
     </ClCompile>
@@ -596,6 +595,7 @@
     </ClCompile>
     <ClCompile Include="UdmApp.cpp">
     </ClCompile>
+    <ClCompile Include="UdmConsole.cpp" />
   </ItemGroup>
   <ItemGroup>
     <None Include="Component.def" />
@@ -691,6 +691,7 @@
     <ClInclude Include="StdAfx.h" />
     <ClInclude Include="UdmApp.h" />
     <ClInclude Include="UdmConfig.h" />
+    <ClInclude Include="UdmConsole.h" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\..\Libraries\MetaGMEAPI\MetaGMEAPIVS2010.vcxproj">

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UMT_interpreterVS2010.vcxproj
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UMT_interpreterVS2010.vcxproj	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/MetaGME2UMT_interpreterVS2010.vcxproj	Fri Jul 22 16:30:44 2016	(r4381)
@@ -614,7 +614,6 @@
       <Optimization Condition="'$(Configuration)|$(Platform)'=='ReleaseVS9|Win32'">MinSpace</Optimization>
       <Optimization Condition="'$(Configuration)|$(Platform)'=='ReleaseVS9|x64'">MinSpace</Optimization>
     </ClCompile>
-    <ClCompile Include="$(GME_ROOT)\SDK\BON\Common\Console.cpp" />
     <ClCompile Include="$(GME_ROOT)\SDK\BON\Common\Exceptions.cpp" />
     <ClCompile Include="..\MetaGME2UML.cpp">
       <Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
@@ -702,6 +701,7 @@
       <Optimization Condition="'$(Configuration)|$(Platform)'=='ReleaseVS9|Win32'">MinSpace</Optimization>
       <Optimization Condition="'$(Configuration)|$(Platform)'=='ReleaseVS9|x64'">MinSpace</Optimization>
     </ClCompile>
+    <ClCompile Include="UdmConsole.cpp" />
   </ItemGroup>
   <ItemGroup>
     <None Include="Component.def" />
@@ -797,6 +797,7 @@
     <ClInclude Include="StdAfx.h" />
     <ClInclude Include="UdmApp.h" />
     <ClInclude Include="UdmConfig.h" />
+    <ClInclude Include="UdmConsole.h" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\..\Libraries\MetaGMEAPI\MetaGMEAPIVS2010.vcxproj">

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.cpp
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.cpp	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.cpp	Fri Jul 22 16:30:44 2016	(r4381)
@@ -6,12 +6,33 @@
 ///////////////////////////////////////////////////////////////////////////
 #include "stdafx.h"
 
-#include "ComHelp.h"
-#include "GMECOM.h"
+#include <ComHelp.h>
+#include <GMECOM.h>
 #include "ComponentConfig.h"
 #include "UdmConfig.h"
+#if _MSC_VER >= 1900 || !defined(__INTELLISENSE__)
+// #import Meta, Mga, GME libs
+#import "libid:0adeec71-d83a-11d3-b36b-005004d38590" no_implementation auto_search no_namespace no_search_namespace
+#import "libid:270b4f86-b17c-11d3-9ad1-00aa00b6fe26" no_implementation auto_search no_namespace no_search_namespace
+#import "libid:0adeec71-d83a-11d3-b36b-005004d38590" implementation_only auto_search no_namespace no_search_namespace
+#import "libid:270b4f86-b17c-11d3-9ad1-00aa00b6fe26" implementation_only auto_search no_namespace no_search_namespace
+#import "libid:0ADEEC71-D83A-11D3-B36B-005004CC8592" no_implementation auto_search no_namespace no_search_namespace
+#import "libid:0ADEEC71-D83A-11D3-B36B-005004CC8592" implementation_only auto_search no_namespace no_search_namespace
+#else
+// IntelliSense has a known issue with the above lines.
+//  http://connect.microsoft.com/VisualStudio/feedback/details/533526/vc-2010-intellisense-import-directive-using-libid-does-not-work
+#ifdef _DEBUG
+// If IntelliSense reports "Cannot open source file", compile then reopen the project
+#include "Debug\Meta.tlh"
+#include "Debug\Mga.tlh"
+#else
+#include "Release\Meta.tlh"
+#include "Release\Mga.tlh"
+#endif
+#endif
+
 #include "RawComponent.h"
-#include "Console.h"
+#include "UdmConsole.h"
 
 // Udm includes
 #include "UdmBase.h"
@@ -24,6 +45,7 @@
 
 #include "UdmApp.h"
 
+__declspec(noreturn) void ThrowComError(HRESULT hr, LPOLESTR err); // from ComHelp.cpp
 // Global config object
 _config config;
 
@@ -43,7 +65,7 @@
 	return InvokeEx(gme, focus, selected, parvar);
 #else
 	if(interactive) {
-		AfxMessageBox("This component does not support the obsolete invoke mechanism");
+		AfxMessageBox(_T("This component does not support the obsolete invoke mechanism"));
 	}
 	return E_MGA_NOT_SUPPORTED;
 #endif
@@ -53,6 +75,7 @@
 			void dummy(void) {; } // Dummy function for UDM meta initialization
 #endif
 
+
 // This is the main component method for interpereters and plugins. 
 // May als be used in case of invokeable addons
 STDMETHODIMP RawComponent::InvokeEx( IMgaProject *project,  IMgaFCO *currentobj,  
@@ -64,19 +87,16 @@
 		return S_FALSE;
 	}
 
+	COMTRY {
 	CComPtr<IMgaProject>ccpProject(project);
 	try
 	{
 		CComBSTR projname;
 		CComBSTR focusname = "<nothing>";
-		CComPtr<IMgaTerritory> terr;
-		COMTHROW(ccpProject->CreateTerritory(NULL, &terr));
 
 		CComPtr<IMgaProject> mgaProject = project;
-		CComBSTR    connString;
-		COMTHROW(mgaProject->get_ProjectConnStr(&connString));
 
-		CString mgaFilePath = connString;
+		CString mgaFilePath = static_cast<const wchar_t*>(mgaProject->ProjectConnStr);
 		int e = mgaFilePath.ReverseFind('\\');
 		if(e != -1)
 		{	
@@ -91,7 +111,7 @@
 					
 		try
 		{
-			COMTHROW(ccpProject->BeginTransactionInNewTerr(TRANSACTION_NON_NESTED, &terr));
+			ccpProject->BeginTransactionInNewTerr(TRANSACTION_NON_NESTED);
 			try {
 			// Opening backend
 			dngBackend.OpenExisting(ccpProject, Udm::CHANGES_LOST_DEFAULT, true);
@@ -123,42 +143,32 @@
 			CUdmApp::UdmMain(&dngBackend,currentObject,selectedObjects,param);
 			// Closing backend
 			dngBackend.CloseWithUpdate();
+			ccpProject->CommitTransaction();
 			} catch (...) {
-				ccpProject->AbortTransaction();
+				ccpProject->raw_AbortTransaction();
 				throw;
 			}
-			COMTHROW(ccpProject->CommitTransaction());
 
 		}
 		catch(udm_exception &exc) 
 		{
-#ifdef _META_ACCESS_MEMORY
-			dnCacheBackend.CloseNoUpdate();
-#endif
 			// Close GME Backend (we may close it twice, but GmeDataNetwork handles it)
 			dngBackend.CloseNoUpdate();			
 
-			if (interactive)
-				AfxMessageBox(exc.what());
-			GMEConsole::Console::Error::WriteLine(exc.what());
-			return E_FAIL;
+				ThrowComError(E_FAIL, GMEConsole::BSTRFromUTF8(exc.what()));
 		}
 	}
-	catch(udm_exception &exc) 
-	{	
-		if (interactive)
-			AfxMessageBox(exc.what());
-		GMEConsole::Console::Error::WriteLine(exc.what());
-		return E_FAIL;
-	}			 
-	catch(...) 
-	{
-		ccpProject->AbortTransaction();
-		if (interactive)
-			AfxMessageBox("An unexpected error has occured during the interpretation process.");
-		GMEConsole::Console::Error::WriteLine("An unexpected error has occured during the interpretation process.");
-		return E_UNEXPECTED;
+		catch (udm_exception& e)
+		{
+			GMEConsole::Console::gmeoleapp = 0;
+			ThrowComError(E_FAIL, GMEConsole::BSTRFromUTF8(e.what()));
+		}
+		catch (_com_error& e)
+		{
+			GMEConsole::Console::gmeoleapp = 0;
+			throw;
 	}
+	} COMCATCH(GMEConsole::Console::gmeoleapp = 0;)
 	return S_OK;
 }
 
@@ -182,23 +192,3 @@
 }
 
 
-#ifdef GME_ADDON
-
-// these two functions are the main 
-STDMETHODIMP RawComponent::GlobalEvent(globalevent_enum event) { 
-	if(event == GLOBALEVENT_UNDO) {
-		AfxMessageBox("UNDO!!");
-	}
-	return S_OK; 
-}
-
-STDMETHODIMP RawComponent::ObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v) {
-	if(eventmask & OBJEVENT_CREATED) {
-		CComBSTR objID;
-		COMTHROW(obj->get_ID(&objID));
-		AfxMessageBox( "Object created! ObjID: " + CString(objID)); 
-	}		
-	return S_OK;
-}
-
-#endif

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.h
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.h	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/RawComponent.h	Fri Jul 22 16:30:44 2016	(r4381)
@@ -1,16 +1,15 @@
 #ifndef RAWCOMPONENT_H
 #define RAWCOMPONENT_H
 
-#include "Mga.h"
-
-
 // Declaration of the main RAW COM component interface class
-#include "Mga.h"
+
 
 #ifdef BUILDER_OBJECT_NETWORK
 #error   This file should only be included in the RAW COM configurations
 #endif
 
+
+
 class RawComponent {
 ////////////////////
 // Insert your application specific member and method definitions here
@@ -42,5 +41,4 @@
 };
 
 
-
 #endif //RAWCOMPONENT_H
\ No newline at end of file

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/StdAfx.h
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/StdAfx.h	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/StdAfx.h	Fri Jul 22 16:30:44 2016	(r4381)
@@ -10,6 +10,7 @@
 #include "targetver.h"
 
 #define _ATL_APARTMENT_THREADED
+#define GME_COMPONENT_ISUPPORTERRORINFO 1
 
 #include <afx.h>
 #include <afxwin.h>

Modified: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmApp.cpp
==============================================================================
--- GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmApp.cpp	Thu Jul 21 16:36:25 2016	(r4380)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmApp.cpp	Fri Jul 22 16:30:44 2016	(r4381)
@@ -39,7 +39,23 @@
 #include "UmlGME.h"
 #include "MetaGME2UML.h"
 
-#include "Mga.h"
+#include "UdmConfig.h"
+#if _MSC_VER >= 1900 || !defined(__INTELLISENSE__)
+// #import Meta, Mga, GME libs
+#import "libid:0adeec71-d83a-11d3-b36b-005004d38590" no_implementation auto_search no_namespace no_search_namespace
+#import "libid:270b4f86-b17c-11d3-9ad1-00aa00b6fe26" no_implementation auto_search no_namespace no_search_namespace
+#else
+// IntelliSense has a known issue with the above lines.
+//  http://connect.microsoft.com/VisualStudio/feedback/details/533526/vc-2010-intellisense-import-directive-using-libid-does-not-work
+#ifdef _DEBUG
+// If IntelliSense reports "Cannot open source file", compile then reopen the project
+#include "Debug\Meta.tlh"
+#include "Debug\Mga.tlh"
+#else
+#include "UMLRelease\Meta.tlh"
+#include "UMLRelease\Mga.tlh"
+#endif
+#endif
 
 using namespace std;
 
@@ -107,8 +123,6 @@
 					 set<Udm::Object> selectedObjects,	// Selected objects
 					 long param)						// Parameters
 {	
-	// TODO: Your Code Comes Here...
-	try
 	{
 		unsigned int transconfig = 0;
 				
@@ -144,9 +158,8 @@
 		Udm::SmartDataNetwork umlGme(UmlGME::diagram);
 		if (filename.Right(4) == ".mga") {
 			mgaProject.CoCreateInstance(L"Mga.MgaProject", NULL, CLSCTX_INPROC);
-			COMTHROW(mgaProject->Create(_bstr_t(CString(_T("MGA=")) + filename), _bstr_t(L"Uml")));
-			CComPtr<IMgaTerritory> terr;
-			COMTHROW(mgaProject->BeginTransactionInNewTerr(TRANSACTION_NON_NESTED, &terr));
+			mgaProject->Create(_bstr_t(CString(_T("MGA=")) + filename), _bstr_t(L"Uml"));
+			mgaProject->BeginTransactionInNewTerr(TRANSACTION_NON_NESTED);
 			umlGme.OpenExisting_([&](const Udm::UdmDiagram &metaroot, Udm::UdmProject* pr) -> Udm::DataNetwork* {
 				std::auto_ptr<UdmGme::GmeDataNetwork> dn1(new UdmGme::GmeDataNetwork(metaroot, pr));
 				dn1->OpenExisting(mgaProject, Udm::CHANGES_LOST_DEFAULT, true);
@@ -211,9 +224,9 @@
 		}
 		if (mgaProject)
 		{
-			COMTHROW(mgaProject->CommitTransaction());
-			COMTHROW(mgaProject->Save(L"", VARIANT_TRUE));
-			COMTHROW(mgaProject->Close(VARIANT_TRUE));
+			mgaProject->CommitTransaction();
+			mgaProject->Save(L"", VARIANT_TRUE);
+			mgaProject->Close(VARIANT_TRUE);
 		}
 		
 		CString fn;
@@ -233,23 +246,7 @@
 		{	cout << "1. "<< fn << " has been Created\\Modified.\n2. Changes have been made to this metamodel.\n\nRun MetaGME Interpreter to reflect these changes in the paradigm.\n";
 		}
 	}
-	catch(udm_exception &exc) 
-	{	if(param != GME_SILENT_MODE)
-		{	AfxMessageBox(exc.what());
-		}
-		else
-		{	cerr << exc.what();
-		}
-	}  
-	catch(_com_error ce) 
-	{	if(param != GME_SILENT_MODE)
-		{	AfxMessageBox(ce.Description());
-		}
-		else
-		{	cerr << (char*)ce.Description();
-		}
-	}
-														
+													
 }
 
 

Added: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmConsole.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmConsole.cpp	Fri Jul 22 16:30:44 2016	(r4381)
@@ -0,0 +1,128 @@
+#include "stdafx.h"
+#include "Gme.h"
+#include "UdmConsole.h"
+#include "UdmBase.h"
+
+
+namespace GMEConsole
+{
+	CComBSTR BSTRFromUTF8(const std::string& utf8)
+	{
+		if (utf8.empty())
+			return CComBSTR();
+
+		// Fail if an invalid input character is encountered
+		const DWORD conversionFlags = MB_ERR_INVALID_CHARS;
+
+		const int utf16Length = ::MultiByteToWideChar(CP_UTF8, conversionFlags, utf8.data(), utf8.length(), NULL, 0);
+		if (utf16Length == 0)
+		{
+			DWORD error = ::GetLastError();
+
+			throw udm_exception(
+				(error == ERROR_NO_UNICODE_TRANSLATION) ? 
+					"Invalid UTF-8 sequence found in input string." :
+					"Can't get length of UTF-16 string (MultiByteToWideChar failed).");
+		}
+
+		BSTR utf16 = SysAllocStringByteLen(NULL, utf16Length*2);
+		if (utf16 == NULL)
+			throw std::bad_alloc();
+
+		if (!::MultiByteToWideChar(CP_UTF8, 0, utf8.data(), utf8.length(), utf16, utf16Length))
+		{
+			DWORD error = ::GetLastError();
+			SysFreeString(utf16);
+			throw udm_exception("Can't convert string from UTF-8 to UTF-16 (MultiByteToWideChar failed).");
+		}
+
+		CComBSTR ret;
+		ret.m_str = utf16;
+		return ret;
+	}
+
+	CComPtr<IGMEOLEApp> Console::gmeoleapp=0;
+
+	void Console::setupConsole(CComPtr<IMgaProject> project)
+	{
+		CComPtr<IMgaClient> client;	
+		CComQIPtr<IDispatch> pDispatch;
+		HRESULT s1 = project->GetClientByName(CComBSTR(L"GME.Application"),&client);
+
+		if ((SUCCEEDED(s1)) && (client != 0))
+		{
+			HRESULT s2 = client->get_OLEServer(&pDispatch);
+			if ((SUCCEEDED(s2)) && (pDispatch != 0))
+			{
+				// release here in case setupConsole was called twice
+				gmeoleapp.Release();
+				HRESULT s3 = pDispatch->QueryInterface(&gmeoleapp);
+				if ((SUCCEEDED(s3)) && (gmeoleapp != 0))
+				{
+					// gmeoleapp->ConsoleClear();
+					gmeoleapp->put_ConsoleContents(NULL);
+				}
+				else
+				{
+					throw udm_exception("GME Console could not be accessed.");
+				}
+			}
+		}
+	}
+
+	void Console::writeLine(const std::string& message, msgtype_enum type)
+	{
+		if (gmeoleapp == 0) {
+			switch (type) {
+			case MSG_NORMAL:
+			case MSG_INFO:
+			case MSG_WARNING:
+				printf("%s", message.c_str());
+				break;
+			case MSG_ERROR:
+				fprintf(stderr, "%s", message.c_str());
+				break;
+			}
+		} else {
+			if(S_OK != gmeoleapp->ConsoleMessage(CComBSTR((int)message.length(), message.c_str()), type))
+				throw udm_exception("Could not write to GME console.");
+		}
+	}
+
+	void Console::writeLine(const std::wstring& message, msgtype_enum type)
+	{
+		if (gmeoleapp == 0) {
+			switch (type) {
+			case MSG_NORMAL:
+			case MSG_INFO:
+			case MSG_WARNING:
+				wprintf(L"%s", message.c_str());
+				break;
+			case MSG_ERROR:
+				fwprintf(stderr, L"%s", message.c_str());
+				break;
+			}
+		} else {
+			if(S_OK != gmeoleapp->ConsoleMessage(CComBSTR((int)message.length(), message.c_str()), type))
+				throw udm_exception("Could not write to GME console.");
+		}
+	}
+
+	void Console::setContents(const std::string& contents)
+	{
+		if (gmeoleapp != 0)
+			if(S_OK != gmeoleapp->put_ConsoleContents( CComBSTR((int)contents.length(),contents.c_str()) ))
+				throw udm_exception("Could not set the contents of GME console.");
+	}
+	void Console::setContents(const std::wstring& contents)
+	{
+		if (gmeoleapp != 0)
+			if(S_OK != gmeoleapp->put_ConsoleContents( CComBSTR((int)contents.length(),contents.c_str()) ))
+				throw udm_exception("Could not set the contents of GME console.");
+	}
+
+	void Console::SetupConsole(::ATL::CComPtr<IMgaProject> project)
+	{
+		Console::setupConsole(project);
+	}
+}
\ No newline at end of file

Added: GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmConsole.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ GReAT/trunk/Tools/MetaGME2UMX/MetaGME2UMX Interpreters/UdmConsole.h	Fri Jul 22 16:30:44 2016	(r4381)
@@ -0,0 +1,101 @@
+#pragma once
+#include "stdafx.h"
+#include "ComHelp.h"
+#include "GMECOM.h"
+#include "UdmBase.h"
+#include <string>
+#include "GMEVersion.h"
+
+namespace GMEConsole
+{
+	CComBSTR BSTRFromUTF8(const std::string & utf8);
+
+	class Console
+	{
+	friend class RawComponent;
+
+#if GME_VERSION_MAJOR <= 10 && GME_VERSION_MINOR <= 2
+	private:
+#else
+	public:
+#endif
+		static CComPtr<IGMEOLEApp> gmeoleapp;
+	public:
+		static void setupConsole(CComPtr<IMgaProject> project);
+		static void freeConsole()
+		{
+			if (gmeoleapp != 0)
+			{
+				gmeoleapp.Release();
+				gmeoleapp = 0;
+			}
+		}
+		static void SetupConsole(::ATL::CComPtr<::IMgaProject> project);
+
+		static void writeLine(const std::string& message, msgtype_enum type);
+
+		static void writeLine(const std::wstring& message, msgtype_enum type);
+
+		static void clear()
+		{
+			if(gmeoleapp!=0)
+				gmeoleapp->put_ConsoleContents(NULL);
+		}
+
+		static void setContents(const std::string& contents);
+		static void setContents(const std::wstring& contents);
+
+		class Error
+		{
+		public:
+			static void writeLine(const std::string& message)
+			{
+				Console::writeLine(message,MSG_ERROR);
+			}
+			static void writeLine(const std::wstring& message)
+			{
+				Console::writeLine(message,MSG_ERROR);
+			}
+		};
+		class Out
+		{
+		public:
+			static void writeLine(const std::string& message)
+			{
+				Console::writeLine(message, MSG_NORMAL);
+			}
+			static void WriteLine(const std::string& message)
+			{
+				Console::writeLine(message, MSG_NORMAL);
+			}
+			static void writeLine(const std::wstring& message)
+			{
+				Console::writeLine(message, MSG_NORMAL);
+			}
+		};
+		class Warning
+		{
+		public:
+			static void writeLine(const std::string& message)
+			{
+				Console::writeLine(message, MSG_WARNING);
+			}
+			static void writeLine(const std::wstring& message)
+			{
+				Console::writeLine(message, MSG_WARNING);
+			}
+		};
+		class Info
+		{
+		public:
+			static void writeLine(const std::string& message)
+			{
+				Console::writeLine(message,MSG_INFO);
+			}
+			static void writeLine(const std::wstring& message)
+			{
+				Console::writeLine(message,MSG_INFO);
+			}
+		};
+	};
+}
\ No newline at end of file


More information about the Mobies-commit mailing list