00001
00002
00003
00004
00005
00007 #include "stdafx.h"
00008
00009 #include <Gdiplus.h>
00010 #pragma comment(lib, "gdiplus.lib")
00011
00012
00013
00014 #include "ComponentLib.h"
00015 #include "ComponentConfig.h"
00016 #include "RawComponent.h"
00017 #include "CommonSmart.h"
00018 #include "GMEGraph.h"
00019 #include "DlgAutoLayout.h"
00020
00021
00022
00023 STDMETHODIMP RawComponent::Initialize(struct IMgaProject *) {
00024 return S_OK;
00025 }
00026
00027
00028
00029 STDMETHODIMP RawComponent::Invoke(IMgaProject* gme, IMgaFCOs *models, long param) {
00030 #ifdef SUPPORT_OLD_INVOKE
00031 CComPtr<IMgaFCO> focus;
00032 CComVariant parval = param;
00033 return InvokeEx(gme, focus, selected, parvar);
00034 #else
00035 if(interactive) {
00036 AfxMessageBox(_T("This component does not support the obsolete invoke mechanism"));
00037 }
00038 return E_MGA_NOT_SUPPORTED;
00039 #endif
00040 }
00041
00042
00043
00044
00045 STDMETHODIMP RawComponent::InvokeEx( IMgaProject *project, IMgaFCO *currentobj,
00046 IMgaFCOs *selectedobjs, long param) {
00047 COMTRY
00048 {
00049 CComBSTR projname;
00050 CComObjPtr<IMgaTerritory> terr;
00051 COMTHROW(project->CreateTerritory(NULL, PutOut(terr)));
00052 COMTHROW(project->BeginTransaction(terr));
00053 try
00054 {
00055 if(currentobj==NULL)
00056 throw 0;
00057
00058 objtype_enum objType;
00059 COMTHROW(currentobj->get_ObjType(&objType));
00060 if( objType != OBJTYPE_MODEL )
00061 {
00062 if (param != GME_SILENT_MODE)
00063 AfxMessageBox(_T("AutoLayout can only run on models."));
00064 throw 0;
00065 }
00066
00067 VARIANT_BOOL isInstance;
00068 COMTHROW(currentobj->get_IsInstance(&isInstance));
00069 if (isInstance != VARIANT_FALSE)
00070 {
00071 if (param != GME_SILENT_MODE)
00072 AfxMessageBox(_T("AutoLayout cannot run on instances. Please AutoLayout run on the basetype instead."));
00073 throw 0;
00074 }
00075
00076 CDlgAutoLayout dlg;
00077 dlg.initialize( project, (IMgaModel*)currentobj );
00078 if (param == GME_SILENT_MODE)
00079 {
00080 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
00081 Gdiplus::GdiplusStartupOutput gdiplusStartupOutput;
00082 ULONG_PTR gdiplusToken;
00083 ULONG_PTR gdiplusHookToken;
00084
00085
00086
00087 gdiplusStartupInput.SuppressBackgroundThread = TRUE;
00088 VERIFY(Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, &gdiplusStartupOutput) == Gdiplus::Ok);
00089 gdiplusStartupOutput.NotificationHook(&gdiplusHookToken);
00090
00091 dlg.OptimizeAllAspects();
00092
00093 CoFreeUnusedLibraries();
00094
00095 gdiplusStartupOutput.NotificationUnhook(gdiplusHookToken);
00096 Gdiplus::GdiplusShutdown(gdiplusToken);
00097 COMTHROW( project->CommitTransaction() );
00098 } else {
00099 INT_PTR dlgResult = dlg.DoModal();
00100 if (dlgResult == IDOK ) {
00101 COMTHROW( project->CommitTransaction() );
00102 } else {
00103 COMTHROW( project->AbortTransaction() );
00104 }
00105 }
00106 }
00107 catch(...)
00108 {
00109 project->AbortTransaction();
00110 }
00111 } COMCATCH(;);
00112 }
00113
00114
00115
00116 STDMETHODIMP RawComponent::ObjectsInvokeEx( IMgaProject *project, IMgaObject *currentobj, IMgaObjects *selectedobjs, long param) {
00117 if(interactive) {
00118 AfxMessageBox(_T("Tho ObjectsInvoke method is not implemented"));
00119 }
00120 return E_MGA_NOT_SUPPORTED;
00121 }
00122
00123
00124
00125 STDMETHODIMP RawComponent::get_ComponentParameter(BSTR name, VARIANT *pVal) {
00126 return S_OK;
00127 }
00128
00129 STDMETHODIMP RawComponent::put_ComponentParameter(BSTR name, VARIANT newVal) {
00130 return S_OK;
00131 }
00132
00133
00134 #ifdef GME_ADDON
00135
00136
00137 STDMETHODIMP RawComponent::GlobalEvent(globalevent_enum event) {
00138 if(event == GLOBALEVENT_UNDO) {
00139 AfxMessageBox(_T("UNDO!!"));
00140 }
00141 return S_OK;
00142 }
00143
00144 STDMETHODIMP RawComponent::ObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v) {
00145 if(eventmask & OBJEVENT_CREATED) {
00146 CComBSTR objID;
00147 COMTHROW(obj->get_ID(&objID));
00148 AfxMessageBox( _T("Object created! ObjID: ") + CString(objID));
00149 }
00150 return S_OK;
00151 }
00152
00153 #endif