home *** CD-ROM | disk | FTP | other *** search
-
- //lRegen_FileHeading
- //lRegen_FileHeading
-
- /********************************************************************
- *
- * Source File: distance.cpp
- * Author: RC
- * Module: Dialog implementation for travel
- * Program Desc:
- * Date: Mon Feb 12 15:33:35 1996
- * Language: MFC C++ 3.0
- *
- ********************************************************************/
-
- #include ".\travel.h"
- //Regen_Cdistance_Top
-
- #include <stdlib.h> // for atoi support
-
- //Regen_Cdistance_Top
-
- IMPLEMENT_DYNCREATE(CdistanceDlg, CDialog)
-
- BEGIN_MESSAGE_MAP(CdistanceDlg, CDialog)
-
- //{{AFX_MSG_MAP(CdistanceDlg)
- ON_BN_CLICKED(IDOK, OnOK)
- ON_WM_CLOSE()
- ON_WM_DESTROY()
- ON_WM_SHOWWINDOW()
- ON_CBN_SELCHANGE(IDC_SOURCE, Oncbn_selchangeidc_source)
- ON_CBN_SELCHANGE(IDC_DEST, Oncbn_selchangeidc_dest)
- //}}AFX_MSG_MAP
-
- //Regen_Map
- //Regen_Map
-
- END_MESSAGE_MAP()
-
- // ------------ Define CdistanceDlg constructor -----------
- CdistanceDlg::CdistanceDlg(UINT nIDTemplate, CWnd* pParentWnd)
- : CDialog((nIDTemplate) ? nIDTemplate : distance, pParentWnd)
- {
-
- //Regen_distance_VarConstructor
- //Regen_distance_VarConstructor
- //lRegen_distance_Constructor
- //lRegen_distance_Constructor
-
- //{{AFX_DATA_INIT(CdistanceDlg)
- //}}AFX_DATA_INIT
- }
-
- // Define CdistanceDlg destructor
- CdistanceDlg::~CdistanceDlg()
- {
- //Regen_distance_Destructor
- //Regen_distance_Destructor
- }
-
- //lRegen_Class_Member_Functions
- //lRegen_Class_Member_Functions
-
- BOOL CdistanceDlg::OnInitDialog()
- {
- //Regen_Cdistance_BeginInitDlg
- //Regen_Cdistance_BeginInitDlg
- CDialog::OnInitDialog();
- //Regen_Cdistance_InitDialog
- CEntity entity;
-
- if(m_pIDO)
- {
- if(m_pIDO->IterateEntityFirst())
- while(m_pIDO->IterateEntityNext(&entity)) // extract the user names of all the entities
- {
- SendDlgItemMessage(IDC_SOURCE, CB_ADDSTRING, 0, (LPARAM)(LPSTR)entity.m_entity.name);
- SendDlgItemMessage(IDC_DEST, CB_ADDSTRING, 0, (LPARAM)(LPSTR)entity.m_entity.name);
- }
-
- SendDlgItemMessage(IDC_SOURCE, CB_SETCURSEL, 0, 0L);
- SendDlgItemMessage(IDC_DEST, CB_SETCURSEL, 0, 0L);
- }
-
- ClearAllItems();
-
- Stack.Init(this);
-
- //Regen_Cdistance_InitDialog
- return TRUE;
- }
-
- CdistanceDlg::CdistanceDlg() //Default Constructor for DYNCREATE
- {
- //Regen_DefConstructor
- //Regen_DefConstructor
- }
-
- void CdistanceDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //lRegen_distance_DDX
- //lRegen_distance_DDX
- //{{AFX_DATA_MAP(CdistanceDlg)
- //}}AFX_DATA_MAP
- }
-
- // ----------- OnClose for Termination of the Dialog --------
- void CdistanceDlg::OnClose()
- {
- //Regen_distance_PreClose
- //Regen_distance_PreClose
-
- EndDialog(IDCANCEL);
-
- //Regen_distance_PostClose
- //Regen_distance_PostClose
- }
-
- void CdistanceDlg::OnDestroy()
- {
- //Regen_CdistanceDlg_wm_destroy
- RemoveUserData();
- //Regen_CdistanceDlg_wm_destroy
- CDialog::OnDestroy();
- }
-
- void CdistanceDlg::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- //Regen_CdistanceDlg_wm_showwindow
- //Regen_CdistanceDlg_wm_showwindow
- CDialog::OnShowWindow(bShow, nStatus);
- }
-
- void CdistanceDlg::Oncbn_selchangeidc_source()
- {
- //Regen_CdistanceDlg_idc_source_cbn_selchange
-
- CalculateDistance();
-
- //Regen_CdistanceDlg_idc_source_cbn_selchange
- }
-
- void CdistanceDlg::Oncbn_selchangeidc_dest()
- {
- //Regen_CdistanceDlg_idc_dest_cbn_selchange
-
- CalculateDistance();
-
- //Regen_CdistanceDlg_idc_dest_cbn_selchange
- }
-
- void CdistanceDlg::OnOK()
- {
- //lRegen_CdistanceDlg_OK_Var
- //lRegen_CdistanceDlg_OK_Var
- EndDialog(IDOK);
- //Regen_distance_OK_End
- //Regen_distance_OK_End
- }
-
- void CdistanceDlg::Ondistanceidc_short()
- {
- //lRegen_CdistanceDlg_distanceidc_short_Var
- //lRegen_CdistanceDlg_distanceidc_short_Var
- //Regen_distance_distanceidc_short_End
- //Regen_distance_distanceidc_short_End
- }
-
- void CdistanceDlg::Ondistanceidc_list()
- {
- //lRegen_CdistanceDlg_distanceidc_list_Var
- //lRegen_CdistanceDlg_distanceidc_list_Var
- //Regen_distance_distanceidc_list_End
- //Regen_distance_distanceidc_list_End
- }
-
-
- //Regen_Code
-
- // ------------ Define CdistanceDlg constructor -----------
- CdistanceDlg::CdistanceDlg(UINT nIDTemplate, CWnd* pParentWnd, CIDO *pIDO)
- : CDialog((nIDTemplate) ? nIDTemplate : distance, pParentWnd)
- {
- m_pIDO = pIDO;
- }
-
- void CdistanceDlg::ClearAllItems()
- {
- LPUSERDATA lpData;
- CRelation * relation;
- CEntity * entity;
- long count;
-
-
- if(m_pIDO)
- {
- if(m_pIDO->IterateEntityFirst())
- while(entity = m_pIDO->IterateEntityNext())
- {
- // if the object does not have a user data object, create one and store it
- lpData = (LPUSERDATA)entity->GetUserData();
- if(lpData == NULL)
- lpData = (LPUSERDATA)calloc(1, sizeof(USERDATA));
-
- lpData->lDistance = -1;
- lstrcpy(lpData->szNamePrevious, "");
-
- entity->SetUserData(lpData);
- entity->SetTextColor(RGB(0,0,0));
-
- // if the object has arrows pointing away, iterate through them
- // to reset their colors
- count = entity->GetRelationOutCount();
- if(count)
- {
- // iterate all the away arrows
- entity->IterateRelationOutFirst();
- while(relation = entity->IterateRelationOutNext())
- relation->SetTextColor(RGB(0,0,0));
- }
- }
-
- m_pIDO->InvalidateRect(NULL, TRUE);
- m_pIDO->UpdateWindow();
- }
- }
-
-
- void CdistanceDlg::CalculateDistance()
- {
- char szEntityName[100+1];
- LPUSERDATA lpData;
- CEntity entity;
- UINT index;
-
-
- ClearAllItems();
-
- index = (UINT)SendDlgItemMessage(IDC_SOURCE, CB_GETCURSEL, 0, 0L);
- SendDlgItemMessage(IDC_SOURCE, CB_GETLBTEXT, (WPARAM)index, (LPARAM)(LPSTR)szEntityName);
- SendDlgItemMessage(IDC_SHORT, LB_RESETCONTENT, 0, 0L);
-
- m_pIDO->GetEntity(0, szEntityName, &entity);
- lpData = (LPUSERDATA)entity.GetUserData();
- if(lpData != NULL)
- lpData->lDistance = 0;
-
- Stack.EmptyStack();
- Stack.Push(szEntityName); // push entity name from the SOURCE combobox
-
- while(SendDlgItemMessage(IDC_LIST, LB_GETCOUNT, 0, 0L)) // while the stack is not empty
- {
- Stack.Pop(szEntityName);
- CalcDist(szEntityName);
- }
-
- WalkList();
- }
-
-
- // pass the name of the previous item here
- void CdistanceDlg::CalcDist(LPSTR lpName)
- {
- LPUSERDATA lpData;
- CRelation relation;
- CEntity this_entity;
- CEntity next_entity;
- long count, Distance, CurrDist;
- char szText[50+1];
-
-
- m_pIDO->GetEntity(0, lpName, &this_entity);
- lpData = (LPUSERDATA)this_entity.GetUserData();
- if(lpData != NULL)
- CurrDist = lpData->lDistance; // save the current distance.
-
-
- // if the object has arrows pointing away, iterate through them
- count = this_entity.GetRelationOutCount();
- if(count)
- {
- // iterate all the away arrows
- this_entity.IterateRelationOutFirst();
- while(this_entity.IterateRelationOutNext(&relation))
- {
- lstrcpy(szText, relation.GetText()); // get the line text
- Distance = (long)atoi(szText); // do a get prop for this
-
- relation.DestinationEntity(&next_entity);
- lpData = (LPUSERDATA)next_entity.GetUserData();
- if(lpData != NULL)
- {
- // if the distance to the prev item is less, do this
- if( (lpData->lDistance == -1) || (lpData->lDistance > Distance + CurrDist) )
- {
- lstrcpy(lpData->szNamePrevious, lpName);
- lstrcpy(lpData->szNamePreviousLine, (LPSTR)relation.m_relation.name);
- lpData->lDistance = Distance + CurrDist;
- Stack.Push((LPSTR)next_entity.m_entity.name);
- }
- }
- } // end WHILE
- }
-
- count = this_entity.GetRelationInCount();
- if(count)
- {
- //iterate all the arrows pointing to this entity
- this_entity.IterateRelationInFirst();
- while(this_entity.IterateRelationInNext(&relation))
-
- {
- lstrcpy(szText, relation.GetText()); // get the line text
- Distance = (long)atoi(szText); // do a get prop for this;
-
- relation.SourceEntity(&next_entity);
- lpData = (LPUSERDATA)next_entity.GetUserData();
- if(lpData != NULL)
- {
- // if the distance to the prev item is less, do this
- if( (lpData->lDistance == -1) || (lpData->lDistance > Distance + CurrDist) )
- {
- lstrcpy(lpData->szNamePrevious, lpName);
- lstrcpy(lpData->szNamePreviousLine, relation.m_relation.name);
- lpData->lDistance = Distance + CurrDist;
- Stack.Push((LPSTR)next_entity.m_entity.name);
- }
- }
-
- } // end WHILE
- } // end count
-
- }
-
-
- void CdistanceDlg::WalkList()
- {
- char szEntityName[100+1];
- char szSrc[99+1];
- char szText[199+1];
- long lDist;
- long total;
- UINT index;
- LPUSERDATA lpData;
- CRelation relation;
- CEntity entity;
-
-
- total = 0; lDist = 0;
-
- // what is the destination name?
- index = (UINT)SendDlgItemMessage(IDC_DEST, CB_GETCURSEL, 0, 0L);
- SendDlgItemMessage(IDC_DEST, CB_GETLBTEXT, (WPARAM)index, (LPARAM)(LPSTR)szEntityName);
-
- // what is the source name?
- index = (UINT)SendDlgItemMessage(IDC_SOURCE, CB_GETCURSEL, 0, 0L);
- SendDlgItemMessage(IDC_SOURCE, CB_GETLBTEXT, (WPARAM)index, (LPARAM)(LPSTR)szSrc);
-
- while(TRUE)
- {
- m_pIDO->GetEntity(0, szEntityName, &entity);
-
- entity.SetTextColor(RGB(255,0,0));
-
- wsprintf(szText,"%s - %li %li", (LPSTR)szEntityName, lDist, total);
- SendDlgItemMessage(IDC_SHORT, LB_INSERTSTRING, (WPARAM)0, (LPARAM)(LPSTR)szText);
-
- if(lstrcmp(szEntityName, szSrc)==0) // we are at the source entity
- break;
-
- lpData = (LPUSERDATA)entity.GetUserData();
- if(lpData == NULL)
- break;
-
- m_pIDO->GetRelation(0, (LPSTR)lpData->szNamePreviousLine, &relation);
- relation.SetTextColor(RGB(255,0,0));
- lDist = lpData->lDistance;
- total += lDist;
-
- lstrcpy(szEntityName, lpData->szNamePrevious);
- }
-
- m_pIDO->InvalidateRect(NULL, TRUE);
- m_pIDO->UpdateWindow();
- }
-
-
- void CdistanceDlg::RemoveUserData()
- {
- LPUSERDATA lpData;
- CRelation relation;
- CEntity entity;
- long count;
-
-
- if(m_pIDO)
- {
- if(m_pIDO->IterateEntityFirst())
- while(m_pIDO->IterateEntityNext(&entity))
- {
- lpData = NULL;
- lpData = (LPUSERDATA)entity.GetUserData();
- if(lpData != NULL)
- free(lpData);
-
- entity.SetTextColor(RGB(0,0,0));
-
- // if the object has arrows pointing away, iterate through them
- // to reset their colors
- count = entity.GetRelationOutCount();
- if(count)
- {
- // iterate all the away arrows
- entity.IterateRelationOutFirst();
- while(entity.IterateRelationOutNext(&relation))
- relation.SetTextColor(RGB(0,0,0));
- }
- } // end WHILE
-
- m_pIDO->InvalidateRect(NULL, TRUE);
- m_pIDO->UpdateWindow();
- } // if pIDO
- }
-
-
- pvStack::pvStack()
- {
- ;
- }
-
- pvStack::~pvStack()
- {
- ;
- }
-
- void pvStack::Init(CWnd * hWnd)
- {
- m_pList = hWnd;
- }
-
- void pvStack::EmptyStack()
- {
- m_pList->SendDlgItemMessage(IDC_LIST, LB_RESETCONTENT, 0, 0L);
- }
-
- void pvStack::Push(LPCSTR lpName)
- {
- m_pList->SendDlgItemMessage(IDC_LIST, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)(LPSTR)lpName);
- }
-
- void pvStack::Pop(LPCSTR lpName)
- {
- m_pList->SendDlgItemMessage(IDC_LIST, LB_GETTEXT, (WPARAM)0, (LPARAM)(LPSTR)lpName);
- m_pList->SendDlgItemMessage(IDC_LIST, LB_DELETESTRING, (WPARAM)0, 0L);
- }
-
- //Regen_Code
-
-
-
-