[GME-commit] GMESRC/Tools/GMETableEditor TableEditorParser.h,NONE,1.1 TableEditorParser.cpp,NONE,1.1 GridDlg.cpp,1.8,1.9 resource.h,1.3,1.4 component.rc,1.3,1.4 Component.dsp,1.4,1.5

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Thu Apr 8 12:13:46 CDT 2004


Update of /var/lib/gme/GMESRC/Tools/GMETableEditor
In directory braindrain:/tmp/cvs-serv25922/Tools/GMETableEditor

Modified Files:
	GridDlg.cpp resource.h component.rc Component.dsp 
Added Files:
	TableEditorParser.h TableEditorParser.cpp 
Log Message:
Added first version of import of Excel XML for the table Editor

CVS User: brianw

--- NEW FILE: TableEditorParser.h ---
// TableEditorParser.h: interface for the CTableEditorParser class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TABLEEDITORPARSER_H__1CB08981_9ED5_4AFF_862A_71AD347CCEF9__INCLUDED_)
#define AFX_TABLEEDITORPARSER_H__1CB08981_9ED5_4AFF_862A_71AD347CCEF9__INCLUDED_

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

#include "GMECOM.h"
#include <sax/HandlerBase.hpp>

class CTableEditorParser : public HandlerBase  
{
public:
	CTableEditorParser(IMgaProject* theProject);
	virtual ~CTableEditorParser();

	//Handler Base
public:
	//virtual InputSource *resolveEntity (const XMLCh* const publicId, const XMLCh* const systemId);

    virtual void startDocument();
    virtual void endDocument();

    virtual void startElement(const XMLCh* const name, AttributeList& attributes);
    virtual void endElement(const XMLCh* const name);

	virtual void characters(const XMLCh* const chars, const unsigned int length);

    virtual void error(const SAXParseException& exception);
    virtual void fatalError(const SAXParseException& exception);

	virtual void setDocumentLocator(const Locator *const locator);
 
	IMgaFCOs* ParseExcelXML(IMgaProject *p, CString filename); //must be for current project open, and all FCOs must previously exist

private:
	CComPtr<IMgaFCO> currentFCO;
	CComPtr<IMgaProject> currentProject;
	CComPtr<IMgaFCOs> importedFCOs;
	int currentColNum; //state of parser info
	int currentRowNum; //state of parser info
	int firstAttrColNum; //the start of Attribute/Value pairs of columns
	int objIDColNum;
	int objNameColNum;
	CString currentFCOname;
	CString currentAttrDName;
	BOOL inData; //only interested in CDATA in the <Data> tag

	BOOL SetAttr(CString DisplayedName, CString Value);

};

#endif // !defined(AFX_TABLEEDITORPARSER_H__1CB08981_9ED5_4AFF_862A_71AD347CCEF9__INCLUDED_)

--- NEW FILE: TableEditorParser.cpp ---
// TableEditorParser.cpp: implementation of the CTableEditorParser class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TableEditorParser.h"
#include <parsers/SAXParser.hpp>
#include <util/PlatformUtils.hpp>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTableEditorParser::CTableEditorParser(IMgaProject* theProject):HandlerBase()
{
	currentProject = theProject;
	importedFCOs = NULL;

}

CTableEditorParser::~CTableEditorParser()
{

}

//initiate parsing
IMgaFCOs* CTableEditorParser::ParseExcelXML(IMgaProject *p, CString filename)
{
	try //catch moved up into GridDlg.cpp
	{
		XMLPlatformUtils::Initialize();

		SAXParser parser;
		//parser.setDoValidation(true);
		parser.setDocumentHandler(this);
		parser.setErrorHandler(this);
		parser.setEntityResolver(this);

		parser.parse(filename);

		//XMLPlatformUtils::Terminate(); 
	}
	catch(const XMLException &e)
	{
		CString desc(e.getMessage());
		AfxMessageBox(desc);
		return NULL;
	}

	return importedFCOs;

}

//XML Doc Handler stuff

void CTableEditorParser::startDocument()
{
	currentRowNum = 0;
	currentColNum = 0;
	firstAttrColNum = -1;
	objIDColNum = -1;
	objNameColNum = -1;
	inData = FALSE;

	COMTHROW(importedFCOs.CoCreateInstance(L"Mga.MgaFCOs"));
}

void CTableEditorParser::endDocument()
{
	//AfxMessageBox("EndDoc");
}

void CTableEditorParser::startElement(const XMLCh* const name, AttributeList& attributes)
{
	CString elementName(name);

	//if(elementName.Compare("Table")==0)
	if(elementName.Compare("Row")==0)
	{
		currentColNum = 0;
	}
	if(elementName.Compare("Data")==0)
	{
		inData = TRUE;
	}
	if(elementName.Compare("Cell")==0)
	{
		int len = attributes.getLength();
		for(int index = 0; index < len; index++)
		{
			CString name = attributes.getName(index);
			CString value = attributes.getValue(index);
			if(name.Compare("ss:Index")==0)//excel will not make <Cell> tags for empty cells
			{                              //including ss:Index means that some cells have been skipped over
				if(currentColNum>firstAttrColNum)//skipped some columns, so there was an empty attribute.
				{	
					SetAttr(currentAttrDName,"");
				}
				
				currentColNum=atoi(value)-1;//this code is 0-based, the ss:Index is 1-based
			}
		}
	}

}

void CTableEditorParser::endElement(const XMLCh* const name)
{
	CString elementName(name);

	if(elementName.Compare("Row")==0)//end of row, advance to next row, set col to 0
	{
		++currentRowNum;
		currentColNum = 0;
	}
	if(elementName.Compare("Cell")==0)
	{
		++currentColNum;
	}
	if(elementName.Compare("Data")==0)
	{
		inData = FALSE;
	}
}

void CTableEditorParser::characters(const XMLCh* const chars, const unsigned int length)
{

	CString cdata(chars);

	if(currentColNum == objNameColNum && inData)
	{
		currentFCOname = cdata;
	}

	if(currentColNum == objIDColNum && inData)
	{
		CComBSTR ID(cdata);
		COMTHROW(currentProject->GetFCOByID(ID,&currentFCO));
		CComBSTR name(currentFCOname);
		COMTHROW(currentFCO->put_Name(name));

		COMTHROW(importedFCOs->Append(currentFCO));
	}


	if(currentRowNum==0) //special stuff for first row, need to find what col ID, Name and First attr are in
	{
		if(cdata.Compare("Object Name")==0)
			objNameColNum = currentColNum;
		if(cdata.Compare("Object ID")==0)
			objIDColNum = currentColNum;
		if(cdata.Compare("Attribute")==0 && firstAttrColNum == -1)
			firstAttrColNum = currentColNum;
	}

	//finally, the attributes
	if(currentRowNum > 0 && currentColNum >= firstAttrColNum && inData)
	{
		if((currentColNum-firstAttrColNum)%2==0)//Attribute Column
		{
			currentAttrDName = cdata;
		}
		else //Value Column
		{
			SetAttr(currentAttrDName,cdata);
		}
	}

}

void CTableEditorParser::error(const SAXParseException& exception)
{
	CString desc(exception.getMessage());
	AfxMessageBox(desc);
}

void CTableEditorParser::fatalError(const SAXParseException& exception)
{
	CString desc(exception.getMessage());
	AfxMessageBox(desc);
}

void CTableEditorParser::setDocumentLocator(const Locator *const locator)
{
}

BOOL CTableEditorParser::SetAttr(CString DisplayedName, CString Value)
{

	CComPtr<IMgaAttributes> attrs; //we only know the displayed name, so have to check through the meta on each attr
	COMTHROW(currentFCO->get_Attributes(&attrs));


	MGACOLL_ITERATE(IMgaAttribute,attrs)
	{

		CComPtr<IMgaAttribute> attr = MGACOLL_ITER;
		CComPtr<IMgaMetaAttribute> metaAttr;
		COMTHROW(attr->get_Meta(&metaAttr));

		CComBSTR metaDisplayedName;
		COMTHROW(metaAttr->get_DisplayedName(&metaDisplayedName));

		if(DisplayedName.Compare(CString(metaDisplayedName))==0)
		{
			attval_enum AttrType;
			COMTHROW(metaAttr->get_ValueType(&AttrType));

			CComBSTR StringVal = Value;
			CComBSTR prevStringVal;
			long IntVal = atoi(Value);
			long prevIntVal;
			double DoubleVal = atof(Value);
			double prevDoubleVal;
			VARIANT_BOOL BoolVal = (atoi(Value)==1);
			VARIANT_BOOL prevBoolVal;
			switch(AttrType)
			{
				case ATTVAL_NULL:
					break;
				case ATTVAL_STRING:
					COMTHROW(attr->get_StringValue(&prevStringVal));
					if(CString(prevStringVal).Compare(CString(StringVal))!=0)//only put if there's a change
						COMTHROW(attr->put_StringValue(StringVal));
					break;
				case ATTVAL_INTEGER:
					COMTHROW(attr->get_IntValue(&prevIntVal));
					if(prevIntVal != IntVal)
						COMTHROW(attr->put_IntValue(IntVal));
					break;
				case ATTVAL_DOUBLE:
					COMTHROW(attr->get_FloatValue(&prevDoubleVal));
					if(prevDoubleVal != DoubleVal)
						COMTHROW(attr->put_FloatValue(DoubleVal));
					break;
				case ATTVAL_BOOLEAN:
					COMTHROW(attr->get_BoolValue(&prevBoolVal));
					if(((prevBoolVal == 0) != (BoolVal == 0))) //Variant_bools are 0 for false, nonzero for true, 
						COMTHROW(attr->put_BoolValue(BoolVal)); //I want this to evaluate if prevBoolVal and BoolVal are different (true and false)
					break;
				case ATTVAL_REFERENCE:
					break;
				case ATTVAL_ENUM:
					COMTHROW(attr->get_StringValue(&prevStringVal));
					if(CString(prevStringVal).Compare(CString(StringVal))!=0)
						COMTHROW(attr->put_StringValue(StringVal));
					break;
				case ATTVAL_DYNAMIC:
					break;
			}
			return TRUE;
		}

	}MGACOLL_ITERATE_END

	return FALSE;
}
Index: GridDlg.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/Tools/GMETableEditor/GridDlg.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** GridDlg.cpp	19 Jan 2004 20:24:22 -0000	1.8
--- GridDlg.cpp	8 Apr 2004 16:13:42 -0000	1.9
***************
*** 11,14 ****
--- 11,15 ----
  #include "NewCellTypes/GridCellMultiLine.h"
  #include "NewCellTypes/GridCellAttrName.h"
+ #include "TableEditorParser.h"
  
  #ifdef _DEBUG
***************
*** 132,137 ****
  {                             //separate out code into subfunctions
  
! 	if(m_FCOs == NULL)//if nothing was selected for the table editor invocation.
! 		return;
  
  	CRect rect;
--- 133,137 ----
  {                             //separate out code into subfunctions
  
! 	
  
  	CRect rect;
***************
*** 145,148 ****
--- 145,151 ----
  	m_Grid.SetColumnCount(0);
  
+ 	if(m_FCOs == NULL)//if nothing was selected for the table editor invocation.
+ 		return;
+ 
  
  
***************
*** 531,534 ****
--- 534,538 ----
  	CDialog::DoDataExchange(pDX);
  	//{{AFX_DATA_MAP(CGridDlg)
+ 	DDX_Control(pDX, IDC_BTNIMPORT, m_btnImport);
  	DDX_Control(pDX, IDC_STATIC_FILTERS, m_stcFilters);
  	DDX_Control(pDX, IDC_STATIC_SELECTION, m_stcSelect);
***************
*** 572,575 ****
--- 576,580 ----
  	ON_BN_CLICKED(IDC_CHKREF, OnChkRef)
  	ON_BN_CLICKED(IDC_CHKSET, OnChkSet)
+ 	ON_BN_CLICKED(IDC_BTNIMPORT, OnBtnImport)
  	//}}AFX_MSG_MAP
      ON_NOTIFY(NM_DBLCLK, IDC_GRID, OnGridDblClick)
***************
*** 845,848 ****
--- 850,855 ----
  void CGridDlg::OnSize(UINT nType, int cx, int cy) 
  {
+ 	if(!(::IsWindow(m_hWnd)))
+ 		return;
  	CDialog::OnSize(nType, cx, cy);
  	
***************
*** 904,907 ****
--- 911,916 ----
  	MoveWndDown(&m_stcFilters, Translate.cy);
  
+ 	MoveWndDown(&m_btnImport, Translate.cy);
+ 
  	Invalidate();
  
***************
*** 967,970 ****
--- 976,1001 ----
  }
  
+ void CGridDlg::OnBtnImport() 
+ {
+ 	CFileDialog FileSelector(TRUE,"xml",NULL, NULL,"EXCEL Exported XML (*.xml)|*.xml||");
+ 	if(FileSelector.DoModal() == IDOK)
+ 	{
+ 		try
+ 		{
+ 			CTableEditorParser parser(m_Project);
+ 			m_FCOs =  parser.ParseExcelXML(m_Project,FileSelector.GetPathName());
+ 			InitGrid();
+ 		}
+ 		catch(HRESULT hr)
+ 		{
+ 			//need better error handling
+ 			AfxMessageBox("A GME COM error occurred on import. Does this file match the current project?");
+ 			CDialog::OnCancel();
+ 		}
+ 	
+ 	}
+ 	
+ }
+ 
  
  	
***************
*** 1122,1124 ****
--- 1153,1156 ----
  	
  }
+ 
  

Index: resource.h
===================================================================
RCS file: /var/lib/gme/GMESRC/Tools/GMETableEditor/resource.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** resource.h	14 Nov 2003 00:40:49 -0000	1.3
--- resource.h	8 Apr 2004 16:13:42 -0000	1.4
***************
*** 22,25 ****
--- 22,26 ----
  #define IDC_STATIC_SELECTION            224
  #define IDC_STATIC_FILTERS              225
+ #define IDC_BTNIMPORT                   226
  
  // Next default values for new objects

Index: component.rc
===================================================================
RCS file: /var/lib/gme/GMESRC/Tools/GMETableEditor/component.rc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** component.rc	14 Nov 2003 00:43:11 -0000	1.3
--- component.rc	8 Apr 2004 16:13:42 -0000	1.4
***************
*** 111,118 ****
  FONT 8, "MS Sans Serif"
  BEGIN
!     DEFPUSHBUTTON   "OK",IDOK,27,324,50,14
!     PUSHBUTTON      "Cancel",IDCANCEL,163,324,50,14
      CONTROL         "Custom1",IDC_GRID,"MFCGridCtrl",WS_TABSTOP,7,7,420,265
!     PUSHBUTTON      "Export...",IDC_BTNEXPORT,93,324,48,14
      CONTROL         "Display All Types",IDC_CHKALLTYPES,"Button",
                      BS_AUTOCHECKBOX | WS_TABSTOP,64,295,69,10
--- 111,118 ----
  FONT 8, "MS Sans Serif"
  BEGIN
!     DEFPUSHBUTTON   "OK",IDOK,14,324,50,14
!     PUSHBUTTON      "Cancel",IDCANCEL,69,324,50,14
      CONTROL         "Custom1",IDC_GRID,"MFCGridCtrl",WS_TABSTOP,7,7,420,265
!     PUSHBUTTON      "Export...",IDC_BTNEXPORT,125,324,48,14
      CONTROL         "Display All Types",IDC_CHKALLTYPES,"Button",
                      BS_AUTOCHECKBOX | WS_TABSTOP,64,295,69,10
***************
*** 140,143 ****
--- 140,144 ----
                      IDC_STATIC_SELECTION,7,276,257,8
      LTEXT           "Filters:",IDC_STATIC_FILTERS,12,286,54,8
+     PUSHBUTTON      "Import...",IDC_BTNIMPORT,179,324,48,14
  END
  

Index: Component.dsp
===================================================================
RCS file: /var/lib/gme/GMESRC/Tools/GMETableEditor/Component.dsp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Component.dsp	19 Jan 2004 20:23:29 -0000	1.4
--- Component.dsp	8 Apr 2004 16:13:42 -0000	1.5
***************
*** 44,48 ****
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
! # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".\\" /I "../../SDK/BON/" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /FR /Yu"stdafx.h" /FD /GZ /c
  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
--- 44,48 ----
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
! # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".\\" /I "../../SDK/BON/" /I "../../GME/Include/xerces" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /FR /Yu"stdafx.h" /FD /GZ /c
  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
***************
*** 53,57 ****
  LINK32=link.exe
  # ADD BASE LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
! # ADD LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug/GMETableEditor.dll" /pdbtype:sept
  # Begin Custom Build - Performing registration
  OutDir=.\Debug
--- 53,57 ----
  LINK32=link.exe
  # ADD BASE LINK32 /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
! # ADD LINK32 ../../GME/Lib/xerces-c_1.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug/GMETableEditor.dll" /pdbtype:sept
  # Begin Custom Build - Performing registration
  OutDir=.\Debug
***************
*** 81,85 ****
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MD /W3 /GX /O1 /I ".\\" /I "../../SDK/BON/" /D "NDEBUG" /D "_ATL_STATIC_REGISTRY" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c
! # ADD CPP /nologo /MD /W3 /GX /O1 /I ".\\" /I "../../SDK/BON/" /D "NDEBUG" /D "_ATL_STATIC_REGISTRY" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c
  # ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
  # ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
--- 81,85 ----
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MD /W3 /GX /O1 /I ".\\" /I "../../SDK/BON/" /D "NDEBUG" /D "_ATL_STATIC_REGISTRY" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c
! # ADD CPP /nologo /MD /W3 /GX /O1 /I ".\\" /I "../../SDK/BON/" /I "../../GME/Include/xerces" /D "NDEBUG" /D "_ATL_STATIC_REGISTRY" /D "WIN32" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /Yu"stdafx.h" /FD /c
  # ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
  # ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
***************
*** 89,93 ****
  LINK32=link.exe
  # ADD BASE LINK32 /nologo /subsystem:windows /dll /machine:I386 /out:"ReleaseMinDependency/GMETableEditor.dll"
! # ADD LINK32 /nologo /subsystem:windows /dll /machine:I386 /out:"Release/GMETableEditor.dll"
  # Begin Custom Build - Performing registration
  OutDir=.\Release
--- 89,93 ----
  LINK32=link.exe
  # ADD BASE LINK32 /nologo /subsystem:windows /dll /machine:I386 /out:"ReleaseMinDependency/GMETableEditor.dll"
! # ADD LINK32 ../../GME/Lib/xerces-c_1.lib /nologo /subsystem:windows /dll /machine:I386 /out:"Release/GMETableEditor.dll"
  # Begin Custom Build - Performing registration
  OutDir=.\Release
***************
*** 262,265 ****
--- 262,269 ----
  # ADD CPP /Yc"stdafx.h"
  # End Source File
+ # Begin Source File
+ 
+ SOURCE=.\TableEditorParser.cpp
+ # End Source File
  # End Group
  # Begin Group "Header Files"
***************
*** 377,380 ****
--- 381,388 ----
  
  SOURCE=.\StdAfx.h
+ # End Source File
+ # Begin Source File
+ 
+ SOURCE=.\TableEditorParser.h
  # End Source File
  # End Group



More information about the GME-commit mailing list