GME  13
GMEViewFrame.cpp
Go to the documentation of this file.
00001 // GMEViewFrame.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "GMEViewFrame.h"
00006 #include "GMEViewCtrl.h"
00007 #include "GMEViewStd.h"
00008 
00009 #ifdef _DEBUG
00010 #define new DEBUG_NEW
00011 #undef THIS_FILE
00012 static char THIS_FILE[] = __FILE__;
00013 #endif
00014 
00015 
00016 
00018 // CGMEViewFrame dialog
00019 
00020 int                     CGMEViewFrame::instanceCount = 0;
00021 CString         CGMEViewFrame::strMyViewWndClass;
00022 
00023 
00024 IMPLEMENT_DYNCREATE(CGMEViewFrame, CMiniFrameWnd)
00025 
00026 CGMEViewFrame::CGMEViewFrame()
00027 {
00028         instanceCount++;
00029 
00030         //{{AFX_DATA_INIT(CGMEViewFrame)
00031                 // NOTE: the ClassWizard will add member initialization here
00032         //}}AFX_DATA_INIT
00033 
00034 }
00035 
00036 CGMEViewFrame::~CGMEViewFrame()
00037 {
00038 }
00039 
00040 void CGMEViewFrame::DoDataExchange(CDataExchange* pDX)
00041 {
00042         CMiniFrameWnd::DoDataExchange(pDX);
00043         //{{AFX_DATA_MAP(CGMEViewFrame)
00044 //      DDX_Control(pDX, IDC_ASPECT_TAB, tab);
00045         //}}AFX_DATA_MAP
00046 }
00047 
00048 BOOL CGMEViewFrame::PreCreateWindow(CREATESTRUCT& cs) 
00049 {
00050         cs.style &= ~WS_CAPTION;
00051         cs.style |= WS_CHILD;
00052         return CMiniFrameWnd::PreCreateWindow(cs);
00053 }
00054 
00055 void CGMEViewFrame::SetCurrentProject(CComPtr<IMgaProject> project)
00056 {
00057         mgaProject = project;
00058         viewWnd.SetCurrentProject(project);
00059 }
00060 
00061 void CGMEViewFrame::SetMetaModel(CComPtr<IMgaMetaModel> meta)
00062 {
00063         InitPropBarFromMeta(meta);
00064         viewWnd.SetMetaModel(meta);
00065 }
00066 
00067 void CGMEViewFrame::SetModel(CComPtr<IMgaModel> model)
00068 {
00069         InitPropBarFromModel(model);
00070         viewWnd.SetModel(model);
00071 }
00072 
00073 void CGMEViewFrame::ChangeAspect(int aspect)
00074 {
00075         SetAspectProperty(aspect);
00076         viewWnd.ChangeAspect(aspect + 1);
00077 }
00078 
00079 void CGMEViewFrame::Invalidate(void)
00080 {
00081         // TODO?
00082         viewWnd.Invalidate();
00083 }
00084 
00085 void CGMEViewFrame::InitPropBarFromMeta(CComPtr<IMgaMetaModel> meta)
00086 {
00087         InitAspectBox(meta);
00088         InitModelKindName(meta);
00089 }
00090 
00091 void CGMEViewFrame::InitPropBarFromModel(CComPtr<IMgaModel> mgaModel)
00092 {
00093         if (mgaModel) {
00094                 try     {
00095                         long status;
00096                         COMTHROW(mgaProject->get_ProjectStatus(&status));
00097                         bool inTrans = (status & 0x08L) != 0;
00098                         CComPtr<IMgaTerritory> terr;
00099                         if (!inTrans) {
00100                                 COMTHROW(mgaProject->CreateTerritory(NULL, &terr));
00101                                 COMTHROW(mgaProject->BeginTransaction(terr, TRANSACTION_READ_ONLY));
00102                         } else {
00103                                 COMTHROW(mgaProject->get_ActiveTerritory(&terr));
00104                         }
00105 
00106                         CComPtr<IMgaFCO> modelFco;
00107                         COMTHROW(terr->OpenFCO(mgaModel, &modelFco));
00108                         CComQIPtr<IMgaModel> model = modelFco;
00109 
00110                         status = OBJECT_ZOMBIE;
00111                         COMTHROW(model->get_Status(&status));
00112                         if (status == OBJECT_EXISTS) {
00113                                 InitModelName(model);
00114                                 InitModelType(model);
00115                         }
00116 
00117                         if (!inTrans) {
00118                                 mgaProject->CommitTransaction();
00119                         }
00120                 } catch(...) {
00121                         ASSERT(0);
00122                 }
00123         }
00124 }
00125 
00126 void CGMEViewFrame::InitAspectBox(CComPtr<IMgaMetaModel> meta)
00127 {
00128         CComboBox* box = (CComboBox*) propBar.GetDlgItem(IDC_ASPECT);
00129         if (meta) {
00130                 CComPtr<IMgaMetaAspects> mmAspects;
00131                 COMTHROW(meta->get_Aspects(&mmAspects));
00132                 CComPtr<IMgaMetaAspect> mmAspect;
00133                 MGACOLL_ITERATE(IMgaMetaAspect, mmAspects) {
00134                         mmAspect = MGACOLL_ITER;
00135 
00136                         CComBSTR bstr;
00137                         COMTHROW(mmAspect->get_DisplayedName(&bstr));
00138                         CString cString;
00139                         CopyTo(bstr, cString);
00140                         box->AddString(cString);
00141                 }
00142                 MGACOLL_ITERATE_END;
00143         }
00144 }
00145 
00146 void CGMEViewFrame::InitModelKindName(CComPtr<IMgaMetaModel> meta)
00147 {
00148         if (meta) {
00149                 CString kindName;
00150                 CComBSTR bstr;
00151                 COMTHROW(meta->get_DisplayedName(&bstr));
00152                 CopyTo(bstr, kindName);
00153                 SetKindNameProperty(kindName);
00154         }
00155 }
00156 
00157 void CGMEViewFrame::InitModelName(CComPtr<IMgaModel> mgaModel)
00158 {
00159         CString name;
00160         CComBSTR bstr;
00161         COMTHROW(mgaModel->get_Name(&bstr));
00162         CopyTo(bstr, name);
00163         SetNameProperty(name);
00164 }
00165 
00166 void CGMEViewFrame::InitModelType(CComPtr<IMgaModel> mgaModel)
00167 {
00168         CComPtr<IMgaFCO> baseType = NULL;
00169         VARIANT_BOOL b;
00170         COMTHROW(mgaModel->get_IsInstance(&b));
00171         bool isType = (b == VARIANT_FALSE);
00172         if (isType) {
00173                 COMTHROW(mgaModel->get_BaseType(&baseType));
00174         } else {
00175                 COMTHROW(mgaModel->get_Type(&baseType));
00176         }
00177         SetTypeProperty(isType);
00178         InitModelTypeName(baseType, mgaModel);
00179 }
00180 
00181 void CGMEViewFrame::InitModelTypeName(CComPtr<IMgaFCO> baseType, CComPtr<IMgaModel> mgaModel)
00182 {
00183         CComPtr<IMgaFCO> fco;
00184         CComBSTR bstr;
00185         CString typeName = "N/A";
00186         if (baseType != 0) {
00187                 COMTHROW(baseType->get_Name(&bstr));
00188                 CopyTo(bstr, typeName);
00189         }
00190         SetTypeNameProperty(typeName);
00191 }
00192 
00193 
00194 BEGIN_MESSAGE_MAP(CGMEViewFrame, CMiniFrameWnd)
00195         //{{AFX_MSG_MAP(CGMEViewFrame)
00196         ON_WM_CREATE()
00197         ON_WM_CLOSE()
00198         ON_WM_WINDOWPOSCHANGED()
00199         ON_CBN_SELCHANGE(IDC_ASPECT, OnSelchangeAspectBox)
00200         //}}AFX_MSG_MAP
00201 END_MESSAGE_MAP()
00202 
00204 // CGMEViewFrame message handlers
00205 
00206 BOOL CGMEViewFrame::OnInitDialog()
00207 {
00208 //      CMiniFrameWnd::OnInitDialog();
00209 
00210         return TRUE;    // return TRUE unless you set the focus to a control
00211                                         // EXCEPTION: OCX Property Pages should return FALSE
00212 }
00213 
00214 int CGMEViewFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
00215 {
00216         if (CMiniFrameWnd::OnCreate(lpCreateStruct) == -1)
00217                 return -1;
00218 
00219         // TODO: Add a menu item that will toggle the visibility of the
00220         // dialog bar named "ModelPropertiesBar":
00221         //   1. In ResourceView, open the menu resource that is used by
00222         //      the CChildFrame class
00223         //   2. Select the View submenu
00224         //   3. Double-click on the blank item at the bottom of the submenu
00225         //   4. Assign the new item an ID: ID_GMEVIEW_MODELPROPERTIESBAR
00226         //   5. Assign the item a Caption: ModelPropertiesBar
00227 
00228         // TODO: Change the value of ID_GMEVIEW_MODELPROPERTIESBAR to an appropriate value:
00229         //   1. Open the file resource.h
00230         // CG: The following block was inserted by the 'Dialog Bar' component
00231         {
00232                 // Initialize dialog bar propBar
00233                 if (propBar.Create(this, IDD_MODELPROPERTIESBAR,
00234                         CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
00235                         IDC_MODELPROPERTIESBAR) == FALSE)
00236                 {
00237                         TRACE0("Failed to create GME View dialog bar propBar\n");
00238                         return -1;
00239                         // fail to create
00240                 }
00241                 int zoomvals[] = { ZOOM_MIN, 10, 25, 50, 75, ZOOM_NO, 150, 200, 300, ZOOM_MAX, ZOOM_WIDTH, ZOOM_HEIGHT, ZOOM_ALL, 0 };
00242 //              int zoomvals[] = { ZOOM_NO, 150, 200, 250, 300, 350, 400, 0 }; // for test
00243                 propBar.SetZoomList(zoomvals);
00244         }
00245 
00246         {
00247                 if (strMyViewWndClass.IsEmpty()) {
00248                         try {
00249                                 strMyViewWndClass = AfxRegisterWndClass(
00250                                         CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW,
00251                                         ::LoadCursor(NULL, IDC_ARROW),
00252                                         (HBRUSH) ::GetStockObject(WHITE_BRUSH),
00253                                         ::LoadIcon(NULL, IDI_APPLICATION));
00254                         }
00255                         catch (CResourceException* pEx) {
00256                                 TRACE0("Couldn't register class! (Already registered?)");
00257                                 pEx->Delete();
00258                         }
00259                 }
00260                 // TODO
00261                 CRect rectClient;
00262                 GetClientRect(&rectClient);
00263                 if (!viewWnd.Create(strMyViewWndClass, "GME View Window", WS_VISIBLE | WS_CHILD, rectClient, this, 0)) {
00264                         TRACE0("Failed to create GME View dialog\n");
00265                         return -1;
00266                 }
00267         }
00268 
00269         return 0;
00270 }
00271 
00272 void CGMEViewFrame::OnClose()
00273 {
00274         CMiniFrameWnd::OnClose();
00275 
00276         // CMDIChildWnd::OnClose: when the last ChildWnd is closed
00277         // the document is considered closed and the title changes to Paradigm
00278         // that's why we call this:
00279 //      theApp.UpdateMainTitle();
00280 }
00281 
00282 void CGMEViewFrame::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
00283 {
00284         CMiniFrameWnd::OnWindowPosChanged(lpwndpos);
00285 
00286         CRect propBarRect;
00287         propBar.GetWindowRect(&propBarRect);
00288 
00289         CRect newModelDialogBarRect;
00290         GetClientRect(&newModelDialogBarRect);
00291         newModelDialogBarRect.top += propBarRect.Height();
00292         viewWnd.MoveWindow(newModelDialogBarRect, TRUE);
00293 }
00294 
00295 void CGMEViewFrame::OnSelchangeAspectBox(void)
00296 {
00297         int ind = GetAspectProperty();
00298         if (ind >= 0) {
00299                 viewWnd.ChangeAspect(ind + 1);
00300                 SendAspectChange(ind);
00301         }
00302 }
00303 
00304 int CGMEViewFrame::GetAspectProperty(void) const
00305 {
00306         CComboBox* box;
00307         box = (CComboBox*) propBar.GetDlgItem(IDC_ASPECT);
00308         ASSERT(box);
00309         return box->GetCurSel();
00310 }
00311 
00312 void CGMEViewFrame::SetAspectProperty(int ind)
00313 {
00314         CComboBox* box;
00315         box = (CComboBox*) propBar.GetDlgItem(IDC_ASPECT);
00316         ASSERT(box);
00317         box->SetCurSel(ind);
00318 }
00319 
00320 void CGMEViewFrame::SetKindNameProperty(CString& kindName)
00321 {
00322         CWnd* ctrl;
00323         ctrl = propBar.GetDlgItem(IDC_KINDNAME);
00324         ASSERT(ctrl);
00325         ctrl->SetWindowText(kindName);
00326 }
00327 
00328 void CGMEViewFrame::GetNameProperty(CString& txt) const
00329 {
00330         CWnd* ctrl;
00331         ctrl = propBar.GetDlgItem(IDC_NAME);
00332         ASSERT(ctrl);
00333         ctrl->GetWindowText(txt);
00334 }
00335 
00336 void CGMEViewFrame::SetNameProperty(CString& name)
00337 {
00338         CWnd* ctrl;
00339         ctrl = propBar.GetDlgItem(IDC_NAME);
00340         ASSERT(ctrl);
00341         ctrl->SetWindowText(name);
00342         // TODO?
00343 //      RetrievePath();
00344 //      frame->title = name + " - " + path;
00345 //      frame->OnUpdateFrameTitle(true);
00346 }
00347 
00348 void CGMEViewFrame::SetTypeProperty(bool isType)
00349 {
00350         if (isType)
00351                 propBar.ShowType();
00352         else
00353                 propBar.ShowInstance();
00354 }
00355 
00356 void CGMEViewFrame::SetTypeNameProperty(CString& typeName)
00357 {
00358         CWnd* ctrl;
00359         ctrl = propBar.GetDlgItem(IDC_TYPENAME);
00360         ASSERT(ctrl);
00361         ctrl->SetWindowText(typeName);
00362 //      RetrievePath();
00363 //      frame->title = name + " - " + path;
00364 //      frame->OnUpdateFrameTitle(true);
00365 }
00366 
00367 void CGMEViewFrame::SendAspectChange(long index)
00368 {
00369         CWnd* wnd = GetParent();
00370         if (wnd->IsKindOf(RUNTIME_CLASS(CGMEViewCtrl))) {
00371                 CGMEViewCtrl* ctrl = STATIC_DOWNCAST(CGMEViewCtrl, wnd);
00372                 ctrl->SendAspectChanged(index);
00373         }
00374 }
00375 
00376 void CGMEViewFrame::SendZoomChange(long index)
00377 {
00378         CWnd* wnd = GetParent();
00379         if (wnd->IsKindOf(RUNTIME_CLASS(CGMEViewCtrl))) {
00380                 CGMEViewCtrl* ctrl = STATIC_DOWNCAST(CGMEViewCtrl, wnd);
00381                 ctrl->SendZoomChanged(index);
00382         }
00383 }
00384 
00385 void CGMEViewFrame::SendWriteStatusZoom(long zoomVal)
00386 {
00387         CWnd* wnd = GetParent();
00388         if (wnd->IsKindOf(RUNTIME_CLASS(CGMEViewCtrl))) {
00389                 CGMEViewCtrl* ctrl = STATIC_DOWNCAST(CGMEViewCtrl, wnd);
00390                 ctrl->SendWriteStatusZoom(zoomVal);
00391         }
00392 }