[GME-commit] GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp NameSpecDlg.cpp,NONE,1.1 NameSpecDlg.h,NONE,1.1 NameSpecTbl.cpp,NONE,1.1 NameSpecTbl.h,NONE,1.1 AspectSpecDlg.cpp,1.6,1.7

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Thu Jul 29 20:10:25 CDT 2004


Update of /var/lib/gme/GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp
In directory braindrain:/tmp/cvs-serv19299/Asp

Modified Files:
	AspectSpecDlg.cpp 
Added Files:
	NameSpecDlg.cpp NameSpecDlg.h NameSpecTbl.cpp NameSpecTbl.h 
Log Message:
Name selector dialog box for chosing the preferred name in case of equivalent objects.
Errors dumped to console window.


CVS User: zolmol

--- NEW FILE: NameSpecDlg.cpp ---
// AspectSpecDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NameSpecDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// NameSpecDlg

//IMPLEMENT_DYNAMIC(NameSpecDlg, CPropertySheet)

NameSpecDlg::NameSpecDlg(CWnd* pParent /*=NULL*/)
	: CDialog( NameSpecDlg::IDD, pParent)
	, m_lastID( 0)
{
	//{{AFX_DATA_INIT(NameSpecDlg)
	//}}AFX_DATA_INIT
}

NameSpecDlg::~NameSpecDlg()
{
}


BEGIN_MESSAGE_MAP(NameSpecDlg, CDialog)
	//{{AFX_MSG_MAP(NameSpecDlg)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// NameSpecDlg message handlers



void NameSpecDlg::GetEntry(int rowID, CString& name, CString& kind, const void * &ptr)
{
	m_nmlist.GetRow(rowID, name, kind);
}


void NameSpecDlg::GetNames( int num, CString& curr, CStringList& names)
{
	LARGE_MAP::iterator it = m_map.begin();
	for( int k = 0; k != num && it != m_map.end(); ++it, ++k);

	names.AddHead( curr);
	if( it != m_map.end()) // found
	{
		std::set< BON::FCO>::iterator jt = it->second.begin();
		for( ; jt != it->second.end(); ++jt)
		{
			CString onelem = (*jt)->getName().c_str();
			if( onelem != curr) names.AddTail( onelem);
		}
	}
}


BOOL NameSpecDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CRect loc;
	this->GetClientRect(&loc);
	loc.DeflateRect(10, 3*10, 10, 4*10);
	m_nmlist.Create(WS_CHILD|WS_VISIBLE|WS_BORDER/*|LVS_EDITLABELS*/|LVS_REPORT|LVS_SINGLESEL, loc, this, 1);
	
	DEFNAMES_MAP::iterator it = m_dn.begin();
	for( ; it != m_dn.end(); ++it)
	{
		BON::FCO ff( it->first);
		CString defname = it->second.c_str();
		CString kind = ff->getObjectMeta().name().c_str();

		//t
		//kind = CString(ff->getName().c_str()) + ":" + kind;
		//et

		m_nmlist.AddRow( m_lastID++, defname, kind);
	}

	return TRUE;
}


void NameSpecDlg::OnOK() 
{
	DEFNAMES_MAP::iterator it = m_dn.begin();
	for( int k = 0; k < m_lastID && it != m_dn.end(); ++k, ++it)
	{
		CString name, kind; void * ptr;
		GetEntry( k, name, kind, ptr);
		BON::FCO fco = it->first;
		std::string newsel_name = (LPCTSTR) name;
		m_result[ fco] = newsel_name;

#ifdef _DEBUG
		//check
		std::set< BON::FCO>::iterator jt = m_map[ fco].begin();
		for( ; jt != m_map[ fco].end() && (*jt)->getName() != newsel_name; ++jt);

		if( jt == m_map[ fco].end() && newsel_name != m_dn[ fco])
			ASSERT(0); // if not found among equivs and is not the default name
#endif
	}

	CDialog::OnOK();
}

--- NEW FILE: NameSpecDlg.h ---
#if !defined(AFX_ASPECTSPECDLG_H__A771B477_7ECF_41F9_8FCD_1557C770B87C__INCLUDED_)
#define AFX_ASPECTSPECDLG_H__A771B477_7ECF_41F9_8FCD_1557C770B87C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
#include <AFXDLGS.H>
#include "resource.h"
#include "NameSpecTbl.h"
#include "map"
#include "string"
#include "BONImpl.h"
#include "BON.h"

// AspectSpecDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// NameSpecDlg

//class NameSpecDlg : public CPropertySheet
class NameSpecDlg : public CDialog
{
	//DECLARE_DYNAMIC(NameSpecDlg)

// Dialog Data
	//{{AFX_DATA(NameSpecDlg)
	enum { IDD = IDD_EQUIVDIALOG };
	//}}AFX_DATA

// Construction
public:
	NameSpecDlg( CWnd* pParent = NULL);   // standard constructor

// Attributes
public:

	NameSpecTbl	m_nmlist;
	int	m_lastID;
	typedef std::map< BON::FCO, std::set< BON::FCO> > LARGE_MAP;
	typedef std::map< BON::FCO, std::string> DEFNAMES_MAP;

	LARGE_MAP m_map;
	DEFNAMES_MAP m_dn;
	DEFNAMES_MAP m_result;

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(NameSpecDlg)
	public:
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	//}}AFX_VIRTUAL

// Implementation
public:
	void GetEntry(int entryNum, CString& name, CString& kind, const void * &ptr);

	void GetNames(int num, CString& curname, CStringList& names);

	virtual ~NameSpecDlg();

	// Generated message map functions
protected:
	//{{AFX_MSG(NameSpecDlg)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ASPECTSPECDLG_H__A771B477_7ECF_41F9_8FCD_1557C770B87C__INCLUDED_)

--- NEW FILE: NameSpecTbl.cpp ---
// AspectSpecTbl.cpp : implementation file
//

#include "stdafx.h"
#include "inplaceedit.h"
#include "inplacelist.h"
#include "NameSpecTbl.h"
#include "NameSpecDlg.h"
extern NameSpecDlg * dlg;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// NameSpecTbl

NameSpecTbl::NameSpecTbl()
{
}

NameSpecTbl::~NameSpecTbl()
{
}


BEGIN_MESSAGE_MAP(NameSpecTbl, CListCtrl)
	//{{AFX_MSG_MAP(NameSpecTbl)
	ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, OnEndlabeledit)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_WM_LBUTTONDOWN()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// NameSpecTbl message handlers

void NameSpecTbl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	// TODO: Add your control notification handler code here

	LV_ITEM	*plvItem = &pDispInfo->item;

	if (plvItem->pszText != NULL)
	{
		SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText);
	}

	*pResult = TRUE;
}





// HitTestEx	- Determine the row index and column index for a point
// Returns	- the row index or -1 if point is not over a row
// point	- point to be tested.
// col		- to hold the column index
int NameSpecTbl::HitTestEx(CPoint &point, int *col) const
{
	int colnum = 0;
	int row = HitTest( point, NULL );
	
	if( col ) *col = 0;

	// Make sure that the ListView is in LVS_REPORT
	if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
		return row;

	// Get the top and bottom row visible
	row = GetTopIndex();
	int bottom = row + GetCountPerPage();
	if( bottom > GetItemCount() )
		bottom = GetItemCount();
	
	// Get the number of columns
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();

	// Loop through the visible rows
	for( ;row <=bottom;row++)
	{
		// Get bounding rect of item and check whether point falls in it.
		CRect rect;
		GetItemRect( row, &rect, LVIR_BOUNDS );
		if( rect.PtInRect(point) )
		{
			// Now find the column
			for( colnum = 0; colnum < nColumnCount; colnum++ )
			{
				int colwidth = GetColumnWidth(colnum);
				if( point.x >= rect.left 
					&& point.x <= (rect.left + colwidth ) )
				{
					if( col ) *col = colnum;
					return row;
				}
				rect.left += colwidth;
			}
		}
	}
	return -1;
}


// ShowInPlaceList		- Creates an in-place drop down list for any 
//				- cell in the list view control
// Returns			- A temporary pointer to the combo-box control
// nItem			- The row index of the cell
// nCol				- The column index of the cell
// lstItems			- A list of strings to populate the control with
// nSel				- Index of the initial selection in the drop down list
CComboBox* NameSpecTbl::ShowInPlaceList( int nItem, int nCol, 
					CStringList &lstItems, int nSel )
{
	// The returned pointer should not be saved

	// Make sure that the item is visible
	if( !EnsureVisible( nItem, TRUE ) ) return NULL;

	// Make sure that nCol is valid 
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();
	if( nCol >= nColumnCount || GetColumnWidth(nCol) < 10 ) 
		return NULL;

	// Get the column offset
	int offset = 0;
	for( int i = 0; i < nCol; i++ )
		offset += GetColumnWidth( i );

	CRect rect;
	GetItemRect( nItem, &rect, LVIR_BOUNDS );

	// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect( &rcClient );
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll( size );
		rect.left -= size.cx;
	}

	rect.left += offset+4;
	rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
	int height = rect.bottom-rect.top;
	rect.bottom += (lstItems.GetCount()+1)*height;
	if( rect.right > rcClient.right) rect.right = rcClient.right;

	DWORD dwStyle = WS_BORDER|WS_CHILD|WS_VISIBLE
					|CBS_DROPDOWNLIST|CBS_DISABLENOSCROLL;
	CComboBox *pList = new CInPlaceList(nItem, nCol, &lstItems, nSel);
	pList->Create( dwStyle, rect, this, IDC_IPEDIT );
	pList->SetItemHeight( -1, height);
	pList->SetHorizontalExtent( GetColumnWidth( nCol ));

	
	return pList;
}



// EditSubLabel		- Start edit of a sub item label
// Returns		- Temporary pointer to the new edit control
// nItem		- The row index of the item to edit
// nCol			- The column of the sub item.
CEdit* NameSpecTbl::EditSubLabel( int nItem, int nCol )
{
	// The returned pointer should not be saved

	// Make sure that the item is visible
	if( !EnsureVisible( nItem, TRUE ) ) return NULL;

	// Make sure that nCol is valid
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();
	if( nCol >= nColumnCount || GetColumnWidth(nCol) < 5 )
		return NULL;

	// Get the column offset
	int offset = 0;
	for( int i = 0; i < nCol; i++ )
		offset += GetColumnWidth( i );

	CRect rect;
	GetItemRect( nItem, &rect, LVIR_BOUNDS );

	// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect( &rcClient );
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll( size );
		rect.left -= size.cx;
	}

	// Get Column alignment
	LV_COLUMN lvcol;
	lvcol.mask = LVCF_FMT;
	GetColumn( nCol, &lvcol );
	DWORD dwStyle ;
	if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
		dwStyle = ES_LEFT;
	else if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
		dwStyle = ES_RIGHT;
	else dwStyle = ES_CENTER;

	rect.left += offset+4;
	rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
	if( rect.right > rcClient.right) rect.right = rcClient.right;

	dwStyle |= WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL;
	CEdit *pEdit = new CInPlaceEdit(nItem, nCol, GetItemText( nItem, nCol ));
	pEdit->Create( dwStyle, rect, this, IDC_IPEDIT );


	return pEdit;
}

void NameSpecTbl::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	if( GetFocus() != this ) SetFocus();
	CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
}



void NameSpecTbl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	if( GetFocus() != this ) SetFocus();	
	CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}


/*
void NameSpecTbl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CListCtrl::OnLButtonDown(nFlags, point);

	int index;
	int colnum;
	if( ( index = HitTestEx( point, &colnum )) != -1 )
	{
		UINT flag = LVIS_FOCUSED;
		if( (GetItemState( index, flag ) & flag) == flag && colnum > 0)
		{
			// Add check for LVS_EDITLABELS
			if( GetWindowLong(m_hWnd, GWL_STYLE) & LVS_EDITLABELS )
				EditSubLabel( index, colnum );
		}
		else
			SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED ,
				    	LVIS_SELECTED | LVIS_FOCUSED); 
	}

}
*/
void NameSpecTbl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	int index;
	CListCtrl::OnLButtonDown(nFlags, point);

	int colnum;
	if( ( index = HitTestEx( point, &colnum )) != -1 )
	{
		UINT flag = LVIS_FOCUSED;
		if( (GetItemState( index, flag ) & flag) == flag )
		{
			// Add check for LVS_EDITLABELS
			/*if( GetWindowLong(m_hWnd, GWL_STYLE) & LVS_EDITLABELS )*/
			if(colnum==0)
			{
				char buff[128];
				LVITEM item;
				item.mask = LVIF_TEXT;
				item.iItem = index;
				item.iSubItem = 0;
				item.pszText = buff;
				item.cchTextMax = 127;
				if (GetItem(&item) && CString(item.pszText) != "N/A") {
					CStringList lstItems;
					int rowID = GetItemData( index);
					//dlg->GetAspects(lstItems);
					//dlg->GetNames( rowID, lstItems);
					dlg->GetNames( rowID, CString(item.pszText), lstItems);
					ShowInPlaceList( index, colnum, lstItems, 0 );
				}
			}
		}
		else
			SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED , 
					LVIS_SELECTED | LVIS_FOCUSED);
	}
}



void NameSpecTbl::AddRow(int rowID, CString& name, CString& kind)
{
	LV_ITEM lvItem;
	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = GetItemCount();
	lvItem.iSubItem = 0;
	lvItem.pszText = name.GetBuffer( name.GetLength());
	int index = InsertItem(&lvItem);
	

	lvItem.iSubItem = 1;
	lvItem.pszText = kind.GetBuffer( kind.GetLength());
	SetItem(&lvItem);

	SetItemData(index, rowID);
}

int NameSpecTbl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;

	int col1size = 3*GetStringWidth("TipicalLongTipicalLongName")/2;
	int col2size = 3*GetStringWidth("KindName")/2;

	InsertColumn(0, _T("Name"), LVCFMT_LEFT,  col1size, -1);
	InsertColumn(1, _T("Kind"), LVCFMT_LEFT, col2size, -1);

	return 0;
}

bool NameSpecTbl::GetRow(int rowID, CString& name, CString& kind)
{
	LVFINDINFO lvFind;
	lvFind.flags = LVFI_PARAM;
	lvFind.lParam = rowID;
	int idx = FindItem(&lvFind);

	if (idx == -1)
		return false;


	LV_ITEM lvItem;
	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = idx;
	lvItem.pszText = name.GetBuffer(255);
	lvItem.cchTextMax = 254;
	lvItem.iSubItem = 0;
	GetItem(&lvItem);
	
	

	lvItem.iSubItem = 1;
	lvItem.pszText = kind.GetBuffer(255);
	lvItem.cchTextMax = 254;
	GetItem(&lvItem);

	return true;
}


--- NEW FILE: NameSpecTbl.h ---
#if !defined(AFX_ASPECTSPECTBL_H__62A172B9_B4D4_497D_B466_B7BB7BF98B7F__INCLUDED_)
#define AFX_ASPECTSPECTBL_H__62A172B9_B4D4_497D_B466_B7BB7BF98B7F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <AFXCMN.H>

// MyListCtrl.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMyListCtrl window

class NameSpecTbl : public CListCtrl
{
// Construction
public:
	NameSpecTbl();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(NameSpecTbl)
	//}}AFX_VIRTUAL

// Implementation
public:
	CImageList m_checkImages;
	bool GetRow( int rowID, CString& name, CString& kind);
	void AddRow( int rowID, CString& name, CString& kind);
	virtual ~NameSpecTbl();
	int HitTestEx(CPoint &point, int *col) const;
	CEdit* EditSubLabel( int nItem, int nCol );
	CComboBox* ShowInPlaceList( int nItem, int nCol, CStringList &lstItems, int nSel );

	// Generated message map functions
protected:
	//{{AFX_MSG(NameSpecTbl)
	afx_msg void OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ASPECTSPECTBL_H__62A172B9_B4D4_497D_B466_B7BB7BF98B7F__INCLUDED_)

Index: AspectSpecDlg.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/Paradigms/MetaGME/MetaInterpreter2004/Asp/AspectSpecDlg.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** AspectSpecDlg.cpp	11 Mar 2004 15:39:38 -0000	1.6
--- AspectSpecDlg.cpp	30 Jul 2004 00:10:23 -0000	1.7
***************
*** 108,112 ****
  	GetEntry( rowID, role_name, kind_asp, is_prim, ptr);
  	if ( role_name == "N/A") 
! 		global_vars.err << "Internal error: GetEntry failed. Empty rolename\n";
  	const FCO * fco_ptr = static_cast<const FCO*>( ptr);
  	if ( fco_ptr)
--- 108,112 ----
  	GetEntry( rowID, role_name, kind_asp, is_prim, ptr);
  	if ( role_name == "N/A") 
! 		global_vars.err << MSG_ERROR << "Internal error: GetEntry failed. Empty rolename\n";
  	const FCO * fco_ptr = static_cast<const FCO*>( ptr);
  	if ( fco_ptr)
***************
*** 127,133 ****
  			}
  		}
! 		else global_vars.err << "Internal error: why other type than Model and Ref has Kindaspect?\n";
  	}
! 	else global_vars.err << "Internal error: zero pointer\n";
  }
  
--- 127,133 ----
  			}
  		}
! 		else global_vars.err << MSG_ERROR << "Internal error: why other type than Model and Ref has Kindaspect?\n";
  	}
! 	else global_vars.err << MSG_ERROR << "Internal error: zero pointer\n";
  }
  



More information about the GME-commit mailing list