[GME-commit] GMESRC/GME/Gme GMEView.cpp, 1.188, 1.189 GMEView.h, 1.74, 1.75 GMEDoc.cpp, 1.35, 1.36 GMEDoc.h, 1.15, 1.16

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Wed Mar 7 16:41:28 CST 2007


Update of /project/gme-repository/GMESRC/GME/Gme
In directory escher:/tmp/cvs-serv23911

Modified Files:
	GMEView.cpp GMEView.h GMEDoc.cpp GMEDoc.h 
Log Message:
View:
1.Sends Open Model Event
2.History
3.RightClick/Connect accessible form shortcut: 'C' (if Mouse Over Selection Event is enabled)
4.Return hit on a Reference will also follow it and show the target
5.Aspect cycling.
6.Upon destroyEvent historian is notified to delete the object

Doc: History/Navigation implementation




CVS User: Zoltan Molnar, ISIS (zolmol)

Index: GMEView.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Gme/GMEView.cpp,v
retrieving revision 1.188
retrieving revision 1.189
diff -C2 -d -r1.188 -r1.189
*** GMEView.cpp	7 Dec 2006 19:07:40 -0000	1.188
--- GMEView.cpp	7 Mar 2007 22:41:26 -0000	1.189
***************
*** 135,138 ****
--- 135,144 ----
  		// PARENT EVENT!!!
  		if(eventmask & OBJEVENT_DESTROYED) {
+ 			if( theApp.isHistoryEnabled() && view && view->GetDocument())
+ 			{
+ 				CComBSTR id; 
+ 				COMTHROW( obj->get_ID( &id)); // get the id of the deleted object
+ 				view->GetDocument()->eraseFromHistory( PutInCString( id)); // clear from history
+ 			}
  			TRACE("   OBJEVENT_DESTROYED\n");
  			viewsToKill.AddTail(view);
***************
*** 370,373 ****
--- 376,380 ----
  	ON_COMMAND(ID_CNTX_REDIRECTIONPASTE, OnCntxRedirectionpaste)
  	ON_UPDATE_COMMAND_UI(ID_CNTX_REDIRECTIONPASTE, OnUpdateCntxRedirectionpaste)
+ 	ON_COMMAND(ID_KEY_CONNECT, OnKeyConnect)
  	ON_COMMAND(ID_CNTX_CONNECT, OnCntxConnect)
  	ON_UPDATE_COMMAND_UI(ID_CNTX_CONNECT, OnUpdateCntxConnect)
***************
*** 423,426 ****
--- 430,437 ----
  	ON_COMMAND(ID_VIEW_FOCUSBROWSER, OnFocusBrowser)
  	ON_COMMAND(ID_VIEW_FOCUSINSPECTOR, OnFocusInspector)
+ 	ON_COMMAND(ID_VIEW_CYCLEASPECTKEY, OnCycleAspect)
+ 	ON_COMMAND(ID_VIEW_CYCLEALLASPECTS, OnCycleAllAspects)
+ 	ON_COMMAND(ID_VIEW_HISTORYBACKKEY, OnHistoryBack)
+ 	ON_COMMAND(ID_VIEW_HISTORYFORWKEY, OnHistoryForw)
  
  END_MESSAGE_MAP()
***************
*** 464,467 ****
--- 475,480 ----
  	currentAspect = 0;
  	currentSet = 0;
+ 	lastObject = 0;
+ 	lastPort   = 0;
  	dragSource = 0;
  
***************
*** 909,912 ****
--- 922,927 ----
  	initDone = true;
  	EndWaitCursor();
+ 
+ 	SendOpenModelEvent();
  }
  
***************
*** 1299,1302 ****
--- 1314,1335 ----
  }
  
+ 
+ bool CGMEView::SendOpenModelEvent()
+ {
+ 	bool ok = true;
+ 	try {
+ 		BeginTransaction();
+ 
+ 		COMTHROW(currentModel->SendEvent(OBJEVENT_OPENMODEL));
+ 
+ 		CommitTransaction();
+ 	}
+ 	catch(hresult_exception &e) {
+ 		AbortTransaction(e.hr);
+ 		ok = false;
+ 	}
+ 	return ok;
+ }
+ 
  bool CGMEView::SendCloseModelEvent()
  {
***************
*** 2135,2138 ****
--- 2168,2176 ----
  		view->ChangeAspect(newAspect);
  	CMainFrame::theInstance->CreateNewView(view);
+ 	if( theApp.isHistoryEnabled())
+ 	{
+ 		doc->tellHistorian( model, newAspect);
+ 		doc->clearForwHistory();
+ 	}
  }
  
***************
*** 3538,3542 ****
  }
  
! void CGMEView::ChangeAspect(CString aspName)
  {
  	CGMEEventLogger::LogGMEEvent("CGMEView::ChangeAspect("+aspName+") in "+path+name+"\r\n");
--- 3576,3580 ----
  }
  
! void CGMEView::ChangeAspect(CString aspName, bool p_eraseStack /*=true*/)
  {
  	CGMEEventLogger::LogGMEEvent("CGMEView::ChangeAspect("+aspName+") in "+path+name+"\r\n");
***************
*** 3547,3550 ****
--- 3585,3601 ----
  			SetAspectProperty(currentAspect->index);
  			CGuiAnnotator::SetAspect(annotators, currentAspect->index);
+ 
+ 			if( theApp.isHistoryEnabled())
+ 			{
+ 				if( m_isActive) // only the active view's changeaspect event is recorded
+ 				{
+ 					GetDocument()->tellHistorian( currentModel, currentAspect?currentAspect->name:"");
+ 				}
+ 
+ 				if( p_eraseStack)
+ 				{
+ 					GetDocument()->clearForwHistory();
+ 				}
+ 			}
  			CGuiFco::SetAspect(children,currentAspect->index);
  			ResolveConnections();
***************
*** 3702,3705 ****
--- 3753,3761 ----
  		CGuiFco::SetAspect(children,currentAspect->index);
  		ResolveConnections();
+ 		if( theApp.isHistoryEnabled())
+ 		{
+ 			GetDocument()->tellHistorian( currentModel, currentAspect?currentAspect->name:"");
+ 			GetDocument()->clearForwHistory();
+ 		}
  
  		currentSet = 0;
***************
*** 5327,5330 ****
--- 5383,5391 ----
  	
  	if(bActivate) {
+ 		if( theApp.isHistoryEnabled())
+ 		{
+ 			GetDocument()->tellHistorian( currentModel, currentAspect?currentAspect->name:"");
+ 		}
+ 
  		modelGrid.Clear();
  		FillModelGrid();
***************
*** 6425,6430 ****
  		CoordinateTransfer(point);
  
! 		static CGuiObject *lastObject = 0;
! 		CGuiObject *object = self->FindObject(point);
  		if(object) {
  			if( object != lastObject)
--- 6486,6492 ----
  		CoordinateTransfer(point);
  
! 		//static CGuiObject *lastObject = 0;
! 		CGuiObject *object = self  ?self->FindObject(point):0;
! 		CGuiPort   *port   = object?object->FindPort(point):0;
  		if(object) {
  			if( object != lastObject)
***************
*** 6432,6435 ****
--- 6494,6498 ----
  		}
  		lastObject = object;
+ 		lastPort   = port;
  	}
  
***************
*** 7228,7232 ****
  				CommitTransaction();
  
! 				if( fco && ot == OBJTYPE_MODEL) GetDocument()->ShowObject( CComPtr<IUnknown>(fco));
  			}
  			catch(hresult_exception e) {
--- 7291,7337 ----
  				CommitTransaction();
  
! 				if( fco && ot == OBJTYPE_MODEL)
! 				{
! 					CComPtr<IMgaModel> cm;
! 					COMTHROW( fco.QueryInterface( &cm));
! 					if( cm) ShowModel( cm);
! 				}
! 				else if( fco && ot == OBJTYPE_REFERENCE) 
! 				{
! 					CComPtr<IMgaModel> next_mod;
! 					CComPtr<IMgaFCO> next_fco;
! 					CComQIPtr<IMgaReference> rf( fco);
! 					try {
! 						BeginTransaction(TRANSACTION_READ_ONLY);
! 						COMTHROW( rf->get_Referred( &next_fco));
! 						objtype_enum ot = OBJTYPE_ATOM;
! 						if( next_fco) 
! 						{
! 							COMTHROW( next_fco->get_ObjType( &ot));
! 							if( ot == OBJTYPE_MODEL)
! 							{
! 								COMTHROW( next_fco.QueryInterface( &next_mod));
! 							}
! 							else
! 							{
! 								CComPtr<IMgaObject> parent;
! 								COMTHROW( next_fco->GetParent( &parent));
! 								
! 								if( parent)
! 								{
! 									COMTHROW( parent.QueryInterface( &next_mod));
! 								}
! 							}
! 						}
! 						
! 						CommitTransaction();
! 					}
! 					catch(hresult_exception e) {
! 						AbortTransaction(e.hr);
! 						next_mod = 0;
! 					}
! 
! 					if( next_fco && next_mod) ShowModel( next_mod);
! 				}
  			}
  			catch(hresult_exception e) {
***************
*** 7249,7250 ****
--- 7354,7410 ----
  	if( hwnd) ::SetFocus( hwnd);
  }
+ 
+ // called when TAB is pressed
+ void CGMEView::OnCycleAspect()
+ {
+ 	ASSERT( currentAspect);
+ 	ASSERT( guiMeta);
+ 	if( !currentAspect || !guiMeta) return;
+ 	int aspNum = guiMeta->aspects.GetCount();
+ 	ASSERT( aspNum >= 1);
+ 	if( aspNum <= 1) return; // if 1 aspect no reason for continuing
+ 
+ 	ChangeAspect( (currentAspect->index + 1) % aspNum);
+ }
+ 
+ // called when '`' is pressed (above the TAB key)
+ void CGMEView::OnCycleAllAspects()
+ {
+ 	if( CMainFrame::theInstance)
+ 		CMainFrame::theInstance->CyclePartBrowserAspect();
+ }
+ 
+ void CGMEView::OnHistoryBack()
+ {
+ 	GetDocument()->back();
+ }
+ 
+ void CGMEView::OnHistoryForw()
+ {
+ 	GetDocument()->forw();
+ }
+ 
+ void CGMEView::OnKeyConnect()
+ {
+ 	CGMEEventLogger::LogGMEEvent("CGMEView::OnKeyConnect in "+path+name+"\r\n");
+ 	if( lastObject) {
+ 		CGuiObject *obj = lastObject;
+ 		if(obj) {
+ 			CGuiPort *port = lastPort;
+ 			if(connSrc == 0) {
+ 				connSrc = obj;
+ 				connSrcPort = port;
+ 				connSrcHotSide = GME_CENTER;
+ 				tmpConnectMode = true;
+ 				SetCursor(autoconnect2Cursor);
+ 			}
+ 			else {
+ 				Connect(connSrc,connSrcPort,connSrcHotSide,obj,port, GME_CENTER, ::GetKeyState(VK_SHIFT) < 0);
+ 				ClearConnSpecs();
+ 				tmpConnectMode = false;
+ 				SetCursor(editCursor);
+ 			}
+ 			ShowCursor(TRUE);
+ 		}
+ 	}
+ }
\ No newline at end of file

Index: GMEView.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Gme/GMEView.h,v
retrieving revision 1.74
retrieving revision 1.75
diff -C2 -d -r1.74 -r1.75
*** GMEView.h	7 Dec 2006 19:07:40 -0000	1.74
--- GMEView.h	7 Mar 2007 22:41:26 -0000	1.75
***************
*** 111,114 ****
--- 111,116 ----
  	int		  connTmpHotSide;
  
+ 	CGuiObject *lastObject;
+ 	CGuiPort   *lastPort;
  	CGuiObject *dragSource;
  
***************
*** 154,157 ****
--- 156,160 ----
  	void CreateAnnotators(CComPtr<IMgaRegNodes> &regNodes, CGuiAnnotatorList &annList);
  	void CreateAnnotators();
+ 	bool SendOpenModelEvent();
  	bool SendCloseModelEvent();
  	bool SendSelecEvent4Object( CGuiObject* selection);
***************
*** 213,217 ****
  	bool DoPasteNative(COleDataObject *pDataObject,bool drag,bool move,bool reference,bool derive,bool instance,CGuiObject *ref,CPoint pt);
  	void MakeSureGUIDIsUniqueForSmartCopy( CComPtr<IMgaFCO>& fco);
! 	void ChangeAspect(CString aspName);
  	void ChangeAspect(int ind);
  	CString &GetAspectName(int ind);
--- 216,220 ----
  	bool DoPasteNative(COleDataObject *pDataObject,bool drag,bool move,bool reference,bool derive,bool instance,CGuiObject *ref,CPoint pt);
  	void MakeSureGUIDIsUniqueForSmartCopy( CComPtr<IMgaFCO>& fco);
! 	void ChangeAspect(CString aspName, bool p_eraseStack = true);
  	void ChangeAspect(int ind);
  	CString &GetAspectName(int ind);
***************
*** 288,291 ****
--- 291,296 ----
  	void AttributepanelPage(long page);
  	void ZoomPercent(long percent);
+ 	void CycleAspect() { this->OnCycleAspect(); }
+ 	void CycleAllAspects() { this->OnCycleAllAspects(); }
  protected:
  	//{{AFX_MSG(CGMEView)
***************
*** 447,450 ****
--- 452,460 ----
  	afx_msg void OnFocusBrowser();
  	afx_msg void OnFocusInspector();
+ 	afx_msg void OnCycleAspect();
+ 	afx_msg void OnCycleAllAspects();
+ 	afx_msg void OnHistoryBack();
+ 	afx_msg void OnHistoryForw();
+ 	afx_msg void OnKeyConnect();
  	//}}AFX_MSG
  	DECLARE_MESSAGE_MAP()

Index: GMEDoc.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Gme/GMEDoc.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** GMEDoc.cpp	15 Aug 2006 17:48:48 -0000	1.35
--- GMEDoc.cpp	7 Mar 2007 22:41:26 -0000	1.36
***************
*** 11,16 ****
--- 11,18 ----
  #include "GMEView.h"
  #include "GuiObject.h"
+ #include "GuiMeta.h"
  #include "GMEEventLogger.h"
  #include "Parser.h"
+ #include "ChildFrm.h"
  
  #include "slist"
***************
*** 49,52 ****
--- 51,66 ----
  	ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE, OnUpdateFileClose)
  	ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
+ 	ON_COMMAND(ID_BUTTON33020, OnBtnBack)
+ 	ON_COMMAND(ID_BUTTON33021, OnBtnFrwd)
+ 	ON_COMMAND(ID_BUTTON33022, OnBtnHome)
+ 	ON_UPDATE_COMMAND_UI(ID_BUTTON33020, OnUpdateBtnBack)
+ 	ON_UPDATE_COMMAND_UI(ID_BUTTON33021, OnUpdateBtnFrwd)
+ 	ON_UPDATE_COMMAND_UI(ID_BUTTON33022, OnUpdateBtnHome)
+ 	ON_COMMAND(ID_BUTTON33027, OnBtnCloseActive)
+ 	ON_COMMAND(ID_BUTTON33028, OnBtnCloseAll)
+ 	ON_COMMAND(ID_BUTTON33033, OnBtnCloseAllButOne)
+ 	ON_COMMAND(ID_BUTTON33035, OnBtnCycleAspect)
+ 	ON_COMMAND(ID_BUTTON33037, OnBtnCycleAllAspects)
+ 	ON_COMMAND(ID_BUTTON33044, OnBtnCycleViews)
  	//}}AFX_MSG_MAP
  END_MESSAGE_MAP()
***************
*** 76,79 ****
--- 90,113 ----
  	CMainFrame::theInstance->DockControlBar(&modeBar,AFX_IDW_DOCKBAR_LEFT);
  
+ 	CRect rd;
+ 	CMainFrame::theInstance->RecalcLayout(TRUE);
+ 	modeBar.GetWindowRect(rd);
+ 	rd.OffsetRect( 0, rd.Height());
+ 	
+ 
+ 	naviBar.CreateEx( CMainFrame::theInstance,
+ 		TBSTYLE_TRANSPARENT | TBSTYLE_FLAT,
+ 		WS_CHILD|WS_VISIBLE|CBRS_ALIGN_LEFT,
+ 		CRect(0,0,0,0),
+ 		IDW_TOOLBAR_NAVIG); // unique!
+ 	naviBar.LoadToolBar( IDR_TOOLBAR_NAVIG);
+ 	naviBar.SetBarStyle( naviBar.GetBarStyle()
+ 		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
+ 	naviBar.EnableDocking(CBRS_ALIGN_ANY);
+ 	naviBar.SetWindowText(_T("Navigator")); // will show this title when floating
+ 
+ 	CMainFrame::theInstance->ShowControlBar(&naviBar, TRUE, FALSE);
+ 	CMainFrame::theInstance->DockControlBar(&naviBar,AFX_IDW_DOCKBAR_LEFT, rd);
+ 
  	try {
  	    COMTHROW( resolver.CoCreateInstance(L"Mga.MgaResolver"));
***************
*** 90,93 ****
--- 124,130 ----
  		CMainFrame::theInstance->ShowControlBar(&modeBar, FALSE, FALSE);
  	}
+ 	if (naviBar.GetSafeHwnd() && (!naviBar.IsWindowVisible())) {
+ 		CMainFrame::theInstance->ShowControlBar(&naviBar, FALSE, FALSE);
+ 	}
  }
  
***************
*** 612,615 ****
--- 649,657 ----
  			else {
  				view->SetCenterObject(fco);
+ 				if( theApp.isHistoryEnabled())
+ 				{
+ 					//clear history
+ 					clearForwHistory();
+ 				}
  			}
  		}
***************
*** 917,919 ****
--- 959,1389 ----
  	ResetAllViews();
  	CGMEBrowser::theInstance->RefreshAll();
+ }
+ 
+ // ---------------------------------------------------
+ // ----------- History related methods ---------------
+ // ---------------------------------------------------
+ void CGMEDoc::back()
+ {
+ 	if( theApp.isHistoryEnabled() && m_historian.isEnabledBack())
+ 	{
+ 		Historian::HistoryElem prev, curr;
+ 		m_historian.popB( prev, curr);
+ 		m_historian.pushF( curr);
+ 		if( !prev.id().empty())
+ 		{
+ 			presentModel( prev.id().c_str(), prev.aspect().c_str());
+ 		}
+ 		else
+ 			CGMEConsole::theInstance->Message( "Could not go further backward", 1);
+ 	}
+ }
+ 
+ void CGMEDoc::forw()
+ {
+ 	if( theApp.isHistoryEnabled() && m_historian.isEnabledFrwd())
+ 	{
+ 		Historian::HistoryElem e;
+ 		m_historian.popF( e);
+ 		m_historian.pushB( e); // this time we should preserve forward stack
+ 		if( !e.id().empty())
+ 		{
+ 			presentModel( e.id().c_str(), e.aspect().c_str());
+ 		}
+ 		else
+ 			CGMEConsole::theInstance->Message( "Could not go further forward", 1);
+ 	}
+ }
+ 
+ void CGMEDoc::home()
+ {
+ 	if( theApp.isHistoryEnabled() && !m_historian.isEmptyB())
+ 	{
+ 		Historian::HistoryElem home;
+ 		m_historian.frontB( home);
+ 		if( !home.id().empty())
+ 		{
+ 			presentModel( home.id().c_str(), home.aspect().c_str());
+ 		}
+ 		else
+ 			CGMEConsole::theInstance->Message( "Could not go home", 1);
+ 
+ 		//m_historian.totalBrainWash();
+ 	}
+ }
+ 
+ void CGMEDoc::clearTotalHistory()
+ {
+ 	m_historian.totalBrainWash();
+ }
+ 
+ void CGMEDoc::clearForwHistory() // could be called: userAction
+ {
+ 	m_historian.frwdBrainWash();
+ }
+ 
+ void CGMEDoc::closeActiveWnd()
+ {
+ 	CGMEView* v = CGMEView::GetActiveView();
+ 	if( !v) return;
+ 	v->alive = false;
+ 	v->frame->sendEvent = false;
+ 	v->frame->PostMessage(WM_CLOSE);
+ }
+ 
+ void CGMEDoc::closeAllWnd()
+ {
+ 	POSITION pos = GetFirstViewPosition();
+ 	while (pos != NULL) {
+ 		CGMEView* v = (CGMEView *) GetNextView( pos);
+ 		v->alive = false;
+ 		v->frame->sendEvent = false;
+ 		v->frame->PostMessage(WM_CLOSE);
+ 	}
+ }
+ 
+ void CGMEDoc::closeAllButActiveWnd()
+ {
+ 	CGMEView* actv = CGMEView::GetActiveView();
+ 
+ 	POSITION pos = GetFirstViewPosition();
+ 	while (pos != NULL) {
+ 		CGMEView* v = (CGMEView *) GetNextView( pos);
+ 		if( v != actv)
+ 		{
+ 			v->alive = false;
+ 			v->frame->sendEvent = false;
+ 			v->frame->PostMessage(WM_CLOSE);
+ 		}
+ 	}
+ }
+ 
+ void CGMEDoc::cycleAspect()
+ {
+ 	CGMEView* actv = CGMEView::GetActiveView();
+ 	if( actv)
+ 		actv->CycleAspect();
+ }
+ 
+ void CGMEDoc::cycleAllAspects()
+ {
+ 	CGMEView* actv = CGMEView::GetActiveView();
+ 	if( actv)
+ 		actv->CycleAllAspects();
+ }
+ 
+ void CGMEDoc::cycleViews()
+ {
+ 	CGMEView* nexv = 0;
+ 	CGMEView* actv = CGMEView::GetActiveView();
+ 	POSITION pos = GetFirstViewPosition();
+ 	while (pos != NULL) {
+ 		CGMEView* v = (CGMEView *) GetNextView( pos);
+ 		if( v == actv)
+ 		{
+ 			if( pos == NULL) // if at the end, go to the first
+ 				pos = GetFirstViewPosition();
+ 			nexv = (CGMEView *) GetNextView( pos);
+ 			break;
+ 		}
+ 	}
+ 
+ 	if( nexv)
+ 	{
+ 		//nexv->SetFocus();
+ 		CMainFrame::theInstance->CreateNewView( nexv);
+ 		::PostMessage(CMainFrame::theInstance->GetSafeHwnd(), WM_SETFOCUS, 0, 0);
+ 	}
+ }
+ 
+ void CGMEDoc::tellHistorian( CComPtr<IMgaModel>& model, CString asp)
+ { 
+ 	if( !theApp.isHistoryEnabled()) return;
+ 	if( theApp.multipleView) return; // do not bother with history in this scenario
+ 	if( !model)              return;
+ 
+ 	try	{
+ 		long status;
+ 		COMTHROW(theApp.mgaProject->get_ProjectStatus(&status));
+ 		bool inTrans = (status & 0x08L) != 0;
+ 		CComPtr<IMgaTerritory> terr;
+ 		if (!inTrans) {
+ 			COMTHROW(theApp.mgaProject->CreateTerritory(NULL, &terr));
+ 			COMTHROW(theApp.mgaProject->BeginTransaction(terr, TRANSACTION_READ_ONLY));
+ 		}
+ 		else {
+ 			COMTHROW(theApp.mgaProject->get_ActiveTerritory(&terr));
+ 		}
+ 
+ 		status = OBJECT_ZOMBIE;
+ 		
+ 		CComPtr<IMgaFCO>  nfco;
+ 		COMTHROW( terr->OpenFCO( CComPtr<IMgaFCO>( model), &nfco));
+ 		COMTHROW( nfco->get_Status( &status));
+ 		if( status == OBJECT_EXISTS) 
+ 		{
+ 			CComBSTR id;
+ 			COMTHROW( nfco->get_ID( &id));
+ 			
+ 			Historian::HistoryElem e( (LPCTSTR) PutInCString( id), (LPCTSTR) asp);
+ 			m_historian.erasePrevOccurencesB( e);
+ 			m_historian.pushB( e);
+ 		}
+ 
+ 		if (!inTrans) {
+ 			theApp.mgaProject->CommitTransaction();
+ 		}
+ 	} catch(...) {
+ 		ASSERT(0);
+ 		m_historian.totalBrainWash();
+ 	}
+ }
+ 
+ void CGMEDoc::eraseFromHistory( LPCTSTR p_id)
+ {
+ 	if( !theApp.isHistoryEnabled()) return;
+ 
+ 	m_historian.eraseOccurences( p_id);
+ }
+ 
+ void CGMEDoc::presentModel( LPCTSTR p_objectId, LPCTSTR p_aspectName)
+ {
+ 	if( !theApp.isHistoryEnabled()) return;
+ 
+ 	if( theApp.multipleView) return; // do not bother with history in this scenario
+ 	if( !theApp.mgaProject)  return;
+ 
+ 	bool               inTrans( false);
+ 	CComBSTR           model_id( p_objectId);
+ 	CComPtr<IMgaFCO>   object;
+ 	CComPtr<IMgaModel> model;
+ 
+ 	try {
+ 		long status;
+ 		COMTHROW(theApp.mgaProject->get_ProjectStatus(&status));
+ 		inTrans = (status & 0x08L) != 0;
+ 		CComPtr<IMgaTerritory> terr;
+ 		if (!inTrans) {
+ 			COMTHROW(theApp.mgaProject->CreateTerritory(NULL, &terr));
+ 			COMTHROW(theApp.mgaProject->BeginTransaction(terr, TRANSACTION_READ_ONLY));
+ 		}
+ 		else
+ 			COMTHROW(theApp.mgaProject->get_ActiveTerritory(&terr));
+ 
+ 		COMTHROW( theApp.mgaProject->GetFCOByID( model_id, &object));
+ 		status = OBJECT_ZOMBIE;
+ 		// check if object really exists
+ 		if( object)
+ 		{
+ 			COMTHROW( object.QueryInterface( &model));
+ 			COMTHROW( object->get_Status( &status));
+ 		}
+ 
+ 		if( status != OBJECT_EXISTS || !model)
+ 			throw hresult_exception( -1);
+ 
+ 		if( !inTrans)
+ 			theApp.mgaProject->CommitTransaction();
+ 	}
+ 	catch (hresult_exception e) {
+ 		if (!inTrans) 
+ 			theApp.mgaProject->AbortTransaction();
+ 
+ 		eraseFromHistory( p_objectId);
+ 		return;
+ 	}
+ 
+ 	ASSERT( model);
+ 	CGMEView *view  = FindView(model);
+ 	if( !view)
+ 	{
+ 		SetNextToView( model, p_aspectName, CComPtr<IMgaFCO>()); // p_aspectName used here
+ 	}
+ 	else if( view->currentAspect && view->currentAspect->name != p_aspectName)
+ 	{
+ 		view->ChangeAspect( p_aspectName, false);
+ 	}
+ 
+ 	// PETER: This is needed to get the focus (SetFocus does not work, since it uses SendMessage())
+ 	CMainFrame::theInstance->CreateNewView( view);
+ 	::PostMessage(CMainFrame::theInstance->GetSafeHwnd(), WM_SETFOCUS, 0, 0);
+ }
+ 
+ //**********************************************************************************************
+ //**********************************************************************************************
+ //*********   C L A S S        H I S T O R I A N     *******************************************
+ //**********************************************************************************************
+ //**********************************************************************************************
+ void CGMEDoc::Historian::pushB( const HistoryElem& e)
+ {
+ 	HistoryElem f = m_backStack.empty()? HistoryElem() : m_backStack.back();
+ 	if( f != e)
+ 		m_backStack.push_back( e);
+ }
+ void CGMEDoc::Historian::pushF( const HistoryElem& e)
+ {
+ 	HistoryElem f = m_frwdStack.empty()? HistoryElem() : m_frwdStack.back();
+ 	if( f != e)
+ 		m_frwdStack.push_back( e);
+ }
+ 
+ void CGMEDoc::Historian::popB( HistoryElem& p_prev, HistoryElem& p_current)
+ {
+ 	if( m_backStack.size() <= 1) return;
+ 	p_current = m_backStack.back();
+ 	m_backStack.pop_back(); // get rid of current
+ 	p_prev = m_backStack.back();
+ }
+ 
+ void CGMEDoc::Historian::popF( HistoryElem& e)
+ {
+ 	if( m_frwdStack.size() < 1) return;
+ 	e = m_frwdStack.back();
+ 	m_frwdStack.pop_back();
+ }
+ 
+ void CGMEDoc::Historian::frontB( HistoryElem& p_front)
+ {
+ 	if( m_backStack.size() == 0) return;
+ 	p_front = m_backStack.front();
+ }
+ 
+ bool CGMEDoc::Historian::isEmptyB() const
+ {
+ 	return m_backStack.size() == 0;
+ }
+ 
+ bool CGMEDoc::Historian::isEnabledBack() const
+ {
+ 	return m_backStack.size() > 1;
+ }
+ 
+ bool CGMEDoc::Historian::isEnabledFrwd() const
+ {
+ 	return m_frwdStack.size() > 0;
+ }
+ 
+ bool CGMEDoc::Historian::isEnabledHome() const
+ {
+ 	return !isEmptyB();
+ }
+ 
+ void CGMEDoc::Historian::totalBrainWash()
+ {
+ 	m_frwdStack.clear();
+ 	m_backStack.clear();
+ }
+ 
+ void CGMEDoc::Historian::frwdBrainWash()
+ {
+ 	m_frwdStack.clear();
+ }
+ 
+ void CGMEDoc::Historian::erasePrevOccurencesB( const HistoryElem& elem)
+ {
+ 	HISTLIST_ITER it;
+ 	
+ 	// backward stack
+ 	it = m_backStack.begin();
+ 	while( it != m_backStack.end())
+ 	{
+ 		if( *it == elem)
+ 			it = m_backStack.erase( it); // will progress it
+ 		else
+ 			++it;
+ 	}
+ 
+ 	const int MAX_LEN = -1;
+ 	while( MAX_LEN != -1 && m_backStack.size() > MAX_LEN)
+ 	{
+ 		m_backStack.pop_front();
+ 	}
+ }
+ 
+ void CGMEDoc::Historian::eraseOccurences( const std::string& p_id)
+ {
+ 	HISTLIST_ITER it;
+ 	
+ 	// backward stack
+ 	it = m_backStack.begin();
+ 	while( it != m_backStack.end())
+ 	{
+ 		if( it->id() == p_id)
+ 			it = m_backStack.erase( it); // will progress it
+ 		else
+ 			++it;
+ 	}
+ 
+ 	// forward stack
+ 	it = m_frwdStack.begin();
+ 	while( it != m_frwdStack.end())
+ 	{
+ 		if( it->id() == p_id)
+ 			it = m_frwdStack.erase( it); // will progress it
+ 		else
+ 			++it;
+ 	}
+ 
+ }
+ //**********************************************************************************************
+ //**********************************************************************************************
+ 
+ void CGMEDoc::OnBtnBack()
+ {
+ 	back();
+ }
+ 
+ void CGMEDoc::OnBtnFrwd()
+ {
+ 	forw();
+ }
+ 
+ void CGMEDoc::OnBtnHome()
+ {
+ 	home();
+ }
+ 
+ void CGMEDoc::OnUpdateBtnBack(CCmdUI* pCmdUI)
+ {
+ 	pCmdUI->Enable( theApp.isHistoryEnabled() && m_historian.isEnabledBack());
+ }
+ 
+ void CGMEDoc::OnUpdateBtnFrwd(CCmdUI* pCmdUI)
+ {
+ 	pCmdUI->Enable( theApp.isHistoryEnabled() && m_historian.isEnabledFrwd());
+ }
+ 
+ void CGMEDoc::OnUpdateBtnHome(CCmdUI* pCmdUI)
+ {
+ 	pCmdUI->Enable( theApp.isHistoryEnabled() && m_historian.isEnabledHome());
+ }
+ 
+ void CGMEDoc::OnBtnCloseActive()
+ {
+ 	closeActiveWnd();
+ }
+ 
+ void CGMEDoc::OnBtnCloseAll()
+ {
+ 	closeAllWnd();
+ }
+ 
+ void CGMEDoc::OnBtnCloseAllButOne()
+ {
+ 	closeAllButActiveWnd();
+ }
+ 
+ void CGMEDoc::OnBtnCycleAspect()
+ {
+ 	cycleAspect();
+ }
+ 
+ void CGMEDoc::OnBtnCycleAllAspects()
+ {
+ 	cycleAllAspects();
+ }
+ 
+ void CGMEDoc::OnBtnCycleViews()
+ {
+ 	cycleViews();
  }

Index: GMEDoc.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Gme/GMEDoc.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** GMEDoc.h	1 May 2006 17:20:11 -0000	1.15
--- GMEDoc.h	7 Mar 2007 22:41:26 -0000	1.16
***************
*** 14,17 ****
--- 14,19 ----
  #include "GMEOLEData.h"
  //#include "MGAUtil_i.h"
+ #include <list>
+ #include <string>
  
  class CGMEDoc : public CDocument
***************
*** 25,28 ****
--- 27,31 ----
  	static CGMEDoc *theInstance;
  	CToolBar modeBar;
+ 	CToolBar naviBar;
  	GMEModeCode editMode;
  
***************
*** 40,44 ****
  	void ViewModeChange();
  	CGMEView *FindView(CComPtr<IMgaModel> model);
! 	void SetNextToView(CComPtr<IMgaModel> &model,CString aspName, CComPtr<IMgaFCO> &centerObj)			{ nextToView = model; nextAspect = aspName; initialCenterObj = centerObj;}
  	void ShowObject(CComPtr<IUnknown> alienObject, BOOL inParent = FALSE);
  	void ShowObject(LPCTSTR objectID);
--- 43,127 ----
  	void ViewModeChange();
  	CGMEView *FindView(CComPtr<IMgaModel> model);
! 
! 	class Historian
! 	{
! 	public:
! 
! 		class HistoryElem 
! 		{
! 		public:
! 			HistoryElem()
! 			{
! 			}
! 
! 			HistoryElem( const std::string& p_id
! 			           , const std::string& p_aspect)
! 				: m_id( p_id)
! 				, m_an( p_aspect)
! 			{
! 			}
! 
! 			HistoryElem( const HistoryElem& peer)
! 				: m_id( peer.m_id)
! 				, m_an( peer.m_an)
! 			{
! 			}
! 
! 			const HistoryElem& operator=( const HistoryElem& peer)
! 			{
! 				if( this == &peer) return *this;
! 
! 				m_id = peer.m_id;
! 				m_an = peer.m_an;
! 
! 				return *this;
! 			}
! 			
! 			const std::string& id() const { return m_id; }
! 			const std::string& aspect() const { return m_an; }
! 
! 			bool operator==( const HistoryElem& peer) const
! 			{
! 				return id() == peer.id() && aspect() == peer.aspect();
! 			}
! 
! 			bool operator!=( const HistoryElem& peer) const
! 			{
! 				return !( *this == peer);
! 			}
! 
! 		private:
! 			std::string m_id;
! 			std::string m_an; // aspect name
! 		};
! 
! 	public:
! 		bool isEmptyB() const;
! 		bool isEnabledBack() const;
! 		bool isEnabledFrwd() const;
! 		bool isEnabledHome() const;
! 
! 		void totalBrainWash();
! 		void frwdBrainWash();
! 
! 		void pushB( const HistoryElem& e);
! 		void pushF( const HistoryElem& e);
! 
! 		void popB( HistoryElem& e, HistoryElem& c);
! 		void popF( HistoryElem& e);
! 		void frontB( HistoryElem& e);
! 
! 		void eraseOccurences( const std::string& p_id);
! 		void erasePrevOccurencesB( const HistoryElem& e);
! 
! 	private:
! 		typedef std::list< HistoryElem >   HISTLIST;
! 		typedef HISTLIST::iterator         HISTLIST_ITER;
! 		HISTLIST                           m_backStack;
! 		HISTLIST                           m_frwdStack;
! 
! 	} m_historian;
! 
! 	void SetNextToView(CComPtr<IMgaModel> &model,CString aspName, CComPtr<IMgaFCO> &centerObj)			{ nextToView = model; nextAspect = aspName; initialCenterObj = centerObj; }
  	void ShowObject(CComPtr<IUnknown> alienObject, BOOL inParent = FALSE);
  	void ShowObject(LPCTSTR objectID);
***************
*** 77,80 ****
--- 160,180 ----
  void SetMode(long mode);
  
+ 	// history related
+ 	void back();
+ 	void forw();
+ 	void home();
+ 	void clearTotalHistory();
+ 	void clearForwHistory();
+ 	void tellHistorian( CComPtr<IMgaModel>& model, CString asp);
+ 	void presentModel( LPCTSTR objectID, LPCTSTR aspectNM);
+ 	void eraseFromHistory( LPCTSTR p_id);
+ 
+ 	void closeActiveWnd();
+ 	void closeAllWnd();
+ 	void closeAllButActiveWnd();
+ 	void cycleAspect();
+ 	void cycleAllAspects();
+ 	void cycleViews();
+ 
  // Generated message map functions
  protected:
***************
*** 98,101 ****
--- 198,213 ----
  	afx_msg void OnUpdateFileClose(CCmdUI* pCmdUI);
  	afx_msg void OnViewRefresh();
+ 	afx_msg void OnBtnBack();
+ 	afx_msg void OnBtnFrwd();
+ 	afx_msg void OnBtnHome();
+ 	afx_msg void OnUpdateBtnFrwd(CCmdUI* pCmdUI);
+ 	afx_msg void OnUpdateBtnBack(CCmdUI* pCmdUI);
+ 	afx_msg void OnUpdateBtnHome(CCmdUI* pCmdUI);
+ 	afx_msg void OnBtnCloseActive();
+ 	afx_msg void OnBtnCloseAll();
+ 	afx_msg void OnBtnCloseAllButOne();
+ 	afx_msg void OnBtnCycleAspect();
+ 	afx_msg	void OnBtnCycleAllAspects();
+ 	afx_msg void OnBtnCycleViews();
  	//}}AFX_MSG
  	DECLARE_MESSAGE_MAP()



More information about the GME-commit mailing list