📄 dlgeditattributes.cpp
字号:
//////////////////////////////////////////////////////
//
// NRDB Pro - Spatial database and mapping application
//
// Copyright (c) 1989-2004 Richard D. Alexander
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// NRDB Pro is part of the Natural Resources Database Project
//
// Homepage: http://www.nrdb.co.uk/
// Users' Forum: http://nrdb.mypalawan.info/
//
#include "stdafx.h"
#include <io.h>
#include "nrdb.h"
#include "DlgEditAttributes.h"
#include "importmaplines.h"
#include "dlgftypeattr.h"
#include "projctns.h"
#include "bdattribute.h"
#include "dlgeditfeature.h"
#include "fileobj.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
#define COL_FEATURE 1
#define COL_FEATUREID 2
#define COL_DATE 3
#define ROW_HEADER 0
#define BD_GRAY RGB(128,128,128)
#define BD_WHITE RGB(255,255,255)
#define BD_BLUE RGB(0,0,200)
#define WM_CHANGECELL WM_USER+100
/////////////////////////////////////////////////////////////////////////////
// CDlgEditAttributes dialog
CDlgEditAttributes::CDlgEditAttributes(long lFeature, long lFType, LPCSTR sFeature, CWnd* pParent /*=NULL*/)
: CDialog(CDlgEditAttributes::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgEditAttributes)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_lFType = lFType;
m_alFeatures.Add(lFeature);
m_sFeature = sFeature;
m_sFeature.TrimRight();
m_pMapLayerObj = NULL;
}
/////////////////////////////////////////////////////////////////////////////
//
// Multi-edit constructor
//
CDlgEditAttributes::CDlgEditAttributes(CLongArray& alFeature, long lFType, CWnd* pParent) :
CDialog(IDD, pParent)
{
m_alFeatures.Copy(alFeature);
m_lFType = lFType;
m_pMapLayerObj = NULL;
}
///////////////////////////////////////////////////////////////////////////////
CDlgEditAttributes::CDlgEditAttributes(long lFType, long lFeature, CMapLayerObj* pMapLayerObj, CWnd* pParent) :
CDialog(IDD, pParent)
{
m_lFType = lFType;
m_alFeatures.Add(lFeature);
m_pMapLayerObj = pMapLayerObj;
}
///////////////////////////////////////////////////////////////////////////////
CDlgEditAttributes::~CDlgEditAttributes()
{
BDSetProgressBar(NULL);
}
///////////////////////////////////////////////////////////////////////////////
void CDlgEditAttributes::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgEditAttributes)
DDX_Control(pDX, IDC_PROGRESS, m_ctlProgress);
//}}AFX_DATA_MAP
}
BEGIN_EVENTSINK_MAP(CDlgEditAttributes, CDialog)
//{{AFX_EVENTSINK_MAP(CDlgEditAttributes)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
BEGIN_MESSAGE_MAP(CDlgEditAttributes, CDialog)
//{{AFX_MSG_MAP(CDlgEditAttributes)
ON_BN_CLICKED(IDC_IMPORT, OnImport)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_WM_SIZE()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_EXPORT, OnExport)
ON_BN_CLICKED(IDC_INSERT, OnInsert)
ON_MESSAGE(SSM_LEAVECELL, OnLeaveCell)
ON_MESSAGE(WM_CHANGECELL, OnChangeCell)
ON_MESSAGE(SSM_DATACHANGE, OnDataChange)
ON_MESSAGE(SSM_COMBOSELCHANGE, OnComboSelChange)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
ON_MESSAGE(BDRESETPROGRESS, OnResetProgress)
ON_MESSAGE(BDUPDATEPROGESS, OnUpdateProgress)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgEditAttributes message handlers
BOOL CDlgEditAttributes::OnInitDialog()
{
CDialog::OnInitDialog();
BDSetProgressBar(&m_ctlProgress);
BDSetActiveWnd(GetSafeHwnd());
CFeatureType ftype;
ftype.m_lId = m_lFType;
BDFeatureType(BDHandle(), &ftype, BDSELECT);
SetWindowText(BDString(IDS_EDIT) + " " + ftype.m_sDesc);
// Initialise the grid properties
CreateGrid();
// Initialise the columns
InitialiseCols();
// Retrieve all attribute values for the feature
int iRow = ROW_HEADER+1;
for (int i = 0; i < m_alFeatures.GetSize(); i++)
{
LoadData(m_alFeatures[i], iRow);
}
// If initialising a map attribute
if (m_pMapLayerObj != NULL)
{
InitMapObject();
}
// Display type of selected cell
OnChangeCell(0,0);
// Display insert button for professional version
GetDlgItem(IDC_INSERT)->ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
///////////////////////////////////////////////////////////////////////////////
BOOL CDlgEditAttributes::GetRowDateTime(long lRow, CDateTime& rDateTime)
{
BOOL bOK = TRUE;
CString sDate;
sDate = m_Grid.GetValue(COL_DATE, lRow);
return rDateTime.StringAsDateTime(sDate, "");
}
///////////////////////////////////////////////////////////////////////////////
void CDlgEditAttributes::OnImport()
{
CDateTime datetime;
long lRow, lCol;
long lDataType, lData;
CLongLines* pMapLines = NULL;
m_Grid.GetActiveCell(&lCol, &lRow);
// Import the data
m_Grid.GetColUserData(lCol, &lDataType);
if (lDataType == BDMAPLINES)
{
if (GetRowDateTime(lRow, datetime))
{
m_Grid.GetInteger(lCol, lRow, &lData);
CLongLines* pMapLinesOld = (CLongLines*)(LONG)lData;
pMapLines = new CLongLines;
if (pMapLines != NULL)
{
if (ImportMapLines(*pMapLines))
{
m_Grid.SetInteger(lCol, lRow, (LONG)(LPCSTR)pMapLines);
if (pMapLinesOld != NULL) delete pMapLinesOld;
} else
{
delete pMapLines;
}
m_Grid.GetInteger(lCol, lRow, &lData);
if (lData != NULL) m_Grid.SetColor(lCol, lRow, BD_BLUE, BD_BLUE);
else m_Grid.SetColor(lCol, lRow, BD_WHITE, BD_WHITE);
};
};
}
// Image
// Support for JPG and PNG Images (georeferenced)
else if (lDataType == BDIMAGE)
{
if (GetRowDateTime(lRow, datetime))
{
m_Grid.GetInteger(lCol, lRow, &lData);
CImageFile* pImageFileOld = (CImageFile*)(LONG)lData;
CImageFile* pImageFile = new CImageFile;
if (pImageFile != NULL)
{
// Import the image and delete any previous image
CString sFilter = BDString(IDS_JPGFILE) + "|*.jpg|" +
BDString(IDS_PNGFILE) + "|*.png||";
CFileDialog dlg(TRUE, NULL, "*.jpg", OFN_FILEMUSTEXIST, sFilter);
if (dlg.DoModal() == IDOK && pImageFile->Open(dlg.GetPathName(), CImageFile::GeoRef, GetSafeHwnd()))
{
m_Grid.SetInteger(lCol, lRow, (LONG)(LPCSTR)pImageFile);
if (pImageFileOld != NULL) delete pImageFileOld;
} else
{
delete pImageFile;
}
// Set the color to indicate if data was imported
m_Grid.GetInteger(lCol, lRow, &lData);
if (lData != NULL) m_Grid.SetColor(lCol, lRow, BD_BLUE, BD_BLUE);
else m_Grid.SetColor(lCol, lRow, BD_WHITE, BD_WHITE);
};
};
}
// Support for files embedded in the database
else if (lDataType == BDFILE)
{
CString s = BDString(IDS_ALLFILES) + " (*.*)|(*.*)||";
CFileDialog dlg(TRUE, NULL, "*.*", OFN_FILEMUSTEXIST, s);
if (dlg.DoModal() == IDOK)
{
m_Grid.GetInteger(lCol, lRow, &lData);
CFileObj* pFileObjOld = (CFileObj*)(LONG)lData;
CFileObj* pFileObj = new CFileObj;
if (pFileObj != NULL && pFileObj->Open(dlg.GetPathName()))
{
m_Grid.SetInteger(lCol, lRow, (LONG)(LPCSTR)pFileObj);
if (pFileObjOld != NULL) delete pFileObjOld;
} else
{
delete pFileObj;
AfxMessageBox(BDString(IDS_ERRORREAD) + " " + dlg.GetPathName());
}
}
}
// Hotlink
else if (lDataType == BDHOTLINK)
{
CString s = BDString(IDS_ALLFILES) + " (*.*)|(*.*)||";
CFileDialog dlg(TRUE, NULL, "*.*", OFN_FILEMUSTEXIST, s);
if (dlg.DoModal() == IDOK)
{
m_Grid.SetValue(lCol, lRow, dlg.GetPathName());
}
}
}
///////////////////////////////////////////////////////////////////////////////
void CDlgEditAttributes::OnExport()
{
CDateTime datetime;
long lRow, lCol;
long lDataType;
long lValue;
CLongLines* pMapLines = NULL;
m_Grid.GetActiveCell(&lCol, &lRow);
// Export the data
m_Grid.GetColUserData(lCol, &lDataType);
if (lDataType == BDMAPLINES)
{
if (GetRowDateTime(lRow, datetime))
{
m_Grid.GetInteger(lCol, lRow, &lValue);
pMapLines = (CLongLines*)lValue;
if (pMapLines != NULL)
{
if (!ExportMapLines(pMapLines))
{
AfxMessageBox(BDString(IDS_ERROREXPORT));
}
};
};
}
}
///////////////////////////////////////////////////////////////////////////////
//
// Create the grid control
//
BOOL CDlgEditAttributes::CreateGrid()
{
CRect rect;
GetDlgItem(IDC_GRID)->GetClientRect(&rect);
BOOL bOK = m_Grid.Create(WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, rect,
this, IDC_GRID1);
if (bOK)
{
m_Grid.SetUserResize(SS_USERRESIZE_COL);
m_Grid.SetBool(SSB_PROCESSTAB, TRUE);
m_Grid.SetEditEnterAction(SS_ENTERACTION_NEXT);
m_Grid.SetBool(SSB_EDITMODEREPLACE, TRUE);
}
PostMessage(WM_SIZE, SIZE_RESTORED, 0);
return bOK;
}
///////////////////////////////////////////////////////////////////////////////
BOOL CDlgEditAttributes::LoadData(long lFeature, int& iRow)
{
CAttrArray aAttr;
CString sDate;
CDateTime datetime;
BOOL bOK = TRUE;
int iCol = COL_DATE;
BeginWaitCursor();
// Determine feature name
CFeature feature;
feature.m_lFeatureTypeId = m_lFType;
feature.m_lId = lFeature;
BDFeature(BDHandle(), &feature, BDSELECT);
BDEnd(BDHandle());
// Output the column values and retrieve all subsequent readings
aAttr.m_lFType = m_lFType;
aAttr.m_lFeature = lFeature;
BOOL bFound = BDAttribute(BDHandle(), &aAttr, BDSELECT3);
do
{
m_Grid.SetMaxRows(iRow);
CString s;
s.Format("%i", feature.m_lId);
m_Grid.SetValue(COL_FEATURE, iRow, feature.m_sName);
m_Grid.SetValue(COL_FEATUREID, iRow, s);
if (!bFound) iRow++;
if (bFound)
{
iCol = COL_DATE;
datetime = CDateTime(aAttr.m_lDate, 0);
datetime.DateAsString(sDate);
m_Grid.SetValue(iCol++, iRow, sDate);
for (int i = 0; i < aAttr.GetSize(); i++)
{
CBDAttribute* pAttr = (CBDAttribute*)aAttr.GetAt(i);
// Predefined coordinates for creating from map
m_Grid.SetValue(iCol, iRow, pAttr->AsString());
// For links find the matching value in the combo box
if (pAttr->GetDataType() == BDLINK)
{
for (int i = 0; i < m_aFTypeLink[iCol].GetSize(); i++)
{
if (m_aFTypeLink[iCol][i] == (DWORD)*pAttr->GetLink())
{
m_Grid.ComboBoxSendMessage(iCol, iRow, CB_SETCURSEL,i,0);
break;
}
}
}
// For map line data store a pointer to the map line object
if (pAttr->GetDataType() == BDMAPLINES)
{
CLongLines* pMapLines = NULL;
if (pAttr->GetLongBinary()->m_hData != NULL)
{
pMapLines = new CLongLines(*pAttr->GetLongBinary());
// Check that the long binary contains valid map lines
if (pMapLines->GetSize() == 0)
{
delete pMapLines;
pMapLines = 0;
} else
{
m_Grid.SetColor(iCol, iRow, BD_BLUE, BD_BLUE);
};
}
m_Grid.SetInteger(iCol, iRow, (LONG)(LPCSTR)pMapLines);
}
// For image files, store a pointer to the image object
CImageFile* pImageFile = NULL;
if (pAttr->GetDataType() == BDIMAGE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -