00001
00002
00003
00004
00005
00007 #include "stdafx.h"
00008
00009 #include "ComHelp.h"
00010 #include "GMECOM.h"
00011 #include <ComponentConfig.h>
00012 #include "RawComponent.h"
00013 #include "GridDlg.h"
00014
00015
00016
00017
00018 STDMETHODIMP RawComponent::Initialize(struct IMgaProject *) {
00019 return S_OK;
00020 }
00021
00022
00023
00024 STDMETHODIMP RawComponent::Invoke(IMgaProject* gme, IMgaFCOs *models, long param) {
00025 #ifdef SUPPORT_OLD_INVOKE
00026 CComPtr<IMgaFCO> focus;
00027 CComVariant parval = param;
00028 return InvokeEx(gme, focus, selected, parvar);
00029 #else
00030 if(interactive) {
00031 AfxMessageBox("This component does not support the obsolete invoke mechanism");
00032 }
00033 return E_MGA_NOT_SUPPORTED;
00034 #endif
00035 }
00036
00037
00038
00039
00040 STDMETHODIMP RawComponent::InvokeEx( IMgaProject *project, IMgaFCO *currentobj,
00041 IMgaFCOs *selectedobjs, long param) {
00042 COMTRY {
00043 if(interactive) {
00044 CComBSTR projname;
00045 CComBSTR focusname = "<nothing>";
00046 CComPtr<IMgaTerritory> terr;
00047 COMTHROW(project->CreateTerritory(NULL, &terr));
00048 COMTHROW(project->BeginTransaction(terr));
00049 try {
00050 CComPtr<IMgaFCOs> gridFCOs = NULL;
00051
00052 long count = 0;
00053 COMTHROW(selectedobjs->get_Count(&count));
00054
00055
00056
00057
00058
00059
00060 if (count > 0) {
00061 gridFCOs = selectedobjs;
00062 }
00063 else if (!currentobj) {
00064 IMgaFolder* rootFolder = NULL;
00065 COMTHROW(project->get_RootFolder(&rootFolder));
00066 COMTHROW(rootFolder->get_ChildFCOs(&gridFCOs));
00067 }
00068 else {
00069 IMgaMetaFCO* meta = NULL;
00070 objtype_enum type = OBJTYPE_NULL;
00071
00072 COMTHROW(currentobj->get_Meta(&meta));
00073 COMTHROW(meta->get_ObjType(&type));
00074
00075 if (type == OBJTYPE_MODEL) {
00076 IMgaModel* model = static_cast<IMgaModel*>(currentobj);
00077 COMTHROW(model->get_ChildFCOs(&gridFCOs));
00078 }
00079 else {
00080
00081 COMTHROW(gridFCOs.CoCreateInstance(L"Mga.MgaFCOs"));
00082 }
00083 }
00084
00085 CGridDlg m_Dlg(gridFCOs);
00086 m_Dlg.SetProject(project);
00087
00088 if( m_Dlg.DoModal() == IDCANCEL)
00089 COMTHROW(project->AbortTransaction());
00090 else
00091 COMTHROW(project->CommitTransaction());
00092
00093
00094 } catch(...) { project->AbortTransaction(); throw; }
00095
00096 }
00097 } COMCATCH(;);
00098 }
00099
00100
00101
00102 STDMETHODIMP RawComponent::ObjectsInvokeEx( IMgaProject *project, IMgaObject *currentobj, IMgaObjects *selectedobjs, long param) {
00103 if(interactive) {
00104 AfxMessageBox("Tho ObjectsInvoke method is not implemented");
00105 }
00106 return E_MGA_NOT_SUPPORTED;
00107 }
00108
00109
00110
00111 STDMETHODIMP RawComponent::get_ComponentParameter(BSTR name, VARIANT *pVal) {
00112 return S_OK;
00113 }
00114
00115 STDMETHODIMP RawComponent::put_ComponentParameter(BSTR name, VARIANT newVal) {
00116 return S_OK;
00117 }
00118
00119
00120 #ifdef GME_ADDON
00121
00122
00123 STDMETHODIMP RawComponent::GlobalEvent(globalevent_enum event) {
00124 if(event == GLOBALEVENT_UNDO) {
00125 AfxMessageBox("UNDO!!");
00126 }
00127 return S_OK;
00128 }
00129
00130 STDMETHODIMP RawComponent::ObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v) {
00131 if(eventmask & OBJEVENT_CREATED) {
00132 CComBSTR objID;
00133 COMTHROW(obj->get_ID(&objID));
00134 AfxMessageBox( "Object created! ObjID: " + CString(objID));
00135 }
00136 return S_OK;
00137 }
00138
00139 #endif