📄 maplayer.cpp
字号:
m_aLayout.Add(layoutobj);
layoutobj.m_nType = legend;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = title;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = arrow;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = source;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = scalebar;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = box;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = projection;
m_aLayout.Add(layoutobj);
layoutobj.m_nType = location;
m_aLayout.Add(layoutobj);
m_bDefault = FALSE;
}
CMapLayout& CMapLayout::operator=(CMapLayout& rSrc)
{
m_sName = rSrc.m_sName;
m_bDefault = rSrc.m_bDefault;
m_aLayout.Copy(rSrc.m_aLayout);
return *this;
}
CMapLayout::CMapLayout(CMapLayout& rSrc)
{
*this = rSrc;
}
CMapLayoutObj CMapLayout::GetLayoutObj(int nType)
{
for (int i = 0; i < m_aLayout.GetSize(); i++)
{
if (m_aLayout[i].m_nType == nType) return m_aLayout[i];
}
return CMapLayoutObj();
}
CMapLayoutObj* CMapLayout::GetLayoutObjPtr(int nType)
{
for (int i = 0; i < m_aLayout.GetSize(); i++)
{
if (m_aLayout[i].m_nType == nType) return &m_aLayout[i];
}
return NULL;
}
/////////////////////////////////////////////////////////////////////////////
void CMapLayoutObj::AsXML(CXMLObj* pXML)
{
pXML->m_sName = "layoutobj";
// Rectangle
CXMLObj *pXMLObj = new CXMLObj;
pXMLObj->m_sName = "rect";
pXMLObj->m_sValue.Format("%d,%d,%d,%d", m_rect.left, m_rect.top, m_rect.right, m_rect.bottom);
pXML->AddChild(pXMLObj);
// style
pXMLObj = new CXMLObj;
pXMLObj->m_sName = "style";
m_style.AsXML(pXMLObj);
pXML->AddChild(pXMLObj);
// logfont
pXMLObj = new CXMLObj;
pXMLObj->m_sName = "logfont";
pXMLObj->m_sValue = AsString(&m_logfont);
pXML->AddChild(pXMLObj);
// Type
pXMLObj = new CXMLObj;
pXMLObj->m_sName = "type";
pXMLObj->m_sValue.Format("%d", m_nType);
pXML->AddChild(pXMLObj);
// Imagefile
pXMLObj = new CXMLObj;
pXMLObj->m_sName = "imagefile";
pXMLObj->m_sValue = m_sImageFile;
pXML->AddChild(pXMLObj);
// Text
pXMLObj = new CXMLObj;
pXMLObj->m_sName = "text";
pXMLObj->m_sValue = m_sText;
pXML->AddChild(pXMLObj);
}
/////////////////////////////////////////////////////////////////////////////
BOOL CMapLayoutObj::XMLAs(CXMLObj* pXMLObj)
{
BOOL bOK = TRUE;
// Get rectangle
bOK = sscanf(pXMLObj->GetString("layoutobj", "rect"), "%d,%d,%d,%d",
&m_rect.left, &m_rect.top, &m_rect.right, &m_rect.bottom) == 4;
// Get style
bOK &= m_style.XMLAs(pXMLObj->GetXMLObj("layoutobj", "style"));
// Get font
bOK &= StringAs(pXMLObj->GetString("layoutobj", "logfont"), &m_logfont);
// Get type
m_nType = pXMLObj->GetInteger("layoutobj", "type");
// Get image file
m_sImageFile = pXMLObj->GetString("layoutobj", "imagefile");
// Get text
m_sText = pXMLObj->GetString("layoutobj", "text");
// If type box and layout version < 2.01 then set style to transparent
if (m_nType == CMapLayout::box && CMapLayoutArray::m_dLayoutVersion < 2.01)
{
m_style.m_nPattern = BS_NULL;
}
return bOK;
}
/////////////////////////////////////////////////////////////////////////////
void CMapLayout::SetLayoutObj(int nType, CMapLayoutObj layoutobj)
{
for (int i = 0; i < m_aLayout.GetSize(); i++)
{
if (m_aLayout[i].m_nType == nType)
{
m_aLayout[i] = layoutobj;
break;
};
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Returns a rectangle containing the percentage of the second rectangle of the
// first
//
CRect CMapLayout::RectAsPercent(CRect rectT, CRect rect)
{
CRect rectP;
rectP.left = int(((rect.left-rectT.left)*1000) / (double)rectT.Width() + 0.5);
rectP.right = int(((rect.right-rectT.left)*1000) / (double)rectT.Width() + 0.5);
rectP.top = int(((rect.top-rectT.top)*1000) / (double)rectT.Height() + 0.5);
rectP.bottom = int(((rect.bottom-rectT.top)*1000) / (double)rectT.Height() + 0.5);
return rectP;
}
///////////////////////////////////////////////////////////////////////////////
//
// Returns a rectangle given the percentage of the the first rectangle in the
// second
//
CRect CMapLayout::RectFromPercent(CRect rectT, CRect rectP)
{
CRect rect;
rect.left = int(rectT.left + (rectT.Width() * rectP.left)/1000.0 + 0.5);
rect.right = int(rectT.left + (rectT.Width() * rectP.right)/1000.0 + 0.5);
rect.top = int(rectT.top + (rectT.Height() * rectP.top)/1000.0 + 0.5);
rect.bottom = int(rectT.top + (rectT.Height() * rectP.bottom)/1000.0 + 0.5);
return rect;
}
/////////////////////////////////////////////////////////////////////////////
void CMapLayout::AsXML(CXMLObj* pXML)
{
pXML->m_sName = "layout";
// Add name of layout
CXMLAttr attr;
attr.m_sName = "name";
attr.m_sValue = m_sName;
pXML->m_aAttr.Add(attr);
attr.m_sName = "default";
attr.m_sValue.Format("%d", m_bDefault);
pXML->m_aAttr.Add(attr);
// Add array of objects
for (int i = 0; i < m_aLayout.GetSize(); i++)
{
CXMLObj *pXMLObj = new CXMLObj;
m_aLayout[i].AsXML(pXMLObj);
pXML->AddChild(pXMLObj);
}
}
/////////////////////////////////////////////////////////////////////////////
BOOL CMapLayout::XMLAs(CXMLObj* pXMLObj)
{
BOOL bOK = TRUE;
m_aLayout.RemoveAll();
// Retrieve the attributes
m_sName = pXMLObj->GetAttr("name");
sscanf(pXMLObj->GetAttr("default"), "%d", &m_bDefault);
CXMLObj *pXMLChild = NULL;
while (bOK && pXMLObj->GetChild("layoutobj", pXMLChild))
{
CMapLayoutObj layoutobj;
bOK = layoutobj.XMLAs(pXMLChild);
m_aLayout.Add(layoutobj);
};
return bOK;
}
/////////////////////////////////////////////////////////////////////////////
void CMapLayoutArray::AsXML(CXMLObj* pXML)
{
pXML->m_sName = "layoutarray";
CXMLAttr attr;
attr.m_sName = "version";
attr.m_sValue = "2.01";
pXML->m_aAttr.Add(attr);
for (int i = 0; i < GetSize(); i++)
{
CXMLObj *pXMLObj = new CXMLObj;
GetAt(i).AsXML(pXMLObj);
pXML->AddChild(pXMLObj);
}
}
///////////////////////////////////////////////////////////////////////////////
BOOL CMapLayoutArray::XMLAs(CXMLObj* pXML)
{
BOOL bOK = TRUE;
RemoveAll();
m_dLayoutVersion = 0;
sscanf(pXML->GetAttr("version"), "%lf", &m_dLayoutVersion);
// Read through layouts
CXMLObj *pXMLObj = NULL; // Must be null
while (bOK && pXML->GetChild("layout", pXMLObj))
{
CMapLayout layout;
bOK = layout.XMLAs(pXMLObj);
// Add to array
Add(layout);
}
return bOK;
}
/////////////////////////////////////////////////////////////////////////////
//
// Return the default map layout
//
CMapLayout CMapLayoutArray::GetDefault()
{
for (int i = 0; i < GetSize(); i++)
{
if (GetAt(i).m_bDefault) return GetAt(i);
}
if (GetSize() > 0)
{
// Set this as default
CMapLayout layout = GetAt(0);
layout.m_bDefault = TRUE;
SetAt(0, layout);
return GetAt(0);
}
else return CMapLayout();
}
/////////////////////////////////////////////////////////////////////////////
BOOL CMapLayer::Initialise(long lFType, CLongArray& alFeatures, CFTypeAttrArray& aAttr, COLORREF color)
{
BOOL bOK = TRUE;
m_lFType = lFType;
for (int i = 0; i < aAttr.GetSize(); i++)
{
CQueryAttrSel attrsel;
attrsel.m_lAttr = aAttr[i].m_lAttrId;
attrsel.m_lFType = aAttr[i].m_lFType;
attrsel.m_lDataType = 0;
m_aAttr.Add(attrsel);
};
// Create the map layer objects
m_alFeatures.Copy(alFeatures);
// Load the data
if (bOK)
{
bOK = LoadData();
};
// Copy the selected items into the object. This is done after the
// data is loaded so that it is known whether the layer contains polylines
// or polygons
if (m_prop.m_bPolygon) m_prop.m_crFill = color;
else m_prop.m_crLine = color;
m_prop.m_colorText = RGB(0,0,0);
return bOK;
}
/////////////////////////////////////////////////////////////////////////////
void CMapLayer::RemoveAll()
{
for (int i = 0; i < GetSize(); i++)
{
CMapLayerObj* pMapLayerObj = (CMapLayerObj*)GetAt(i);
if (pMapLayerObj != NULL) delete pMapLayerObj;
SetAt(i, NULL);
}
CArray <CMapLayerObj*, CMapLayerObj*>::RemoveAll();
}
/////////////////////////////////////////////////////////////////////////////
CMapLayer::~CMapLayer()
{
if (m_pQuery != NULL)
{
delete m_pQuery;
m_pQuery = NULL;
}
RemoveAll();
}
///////////////////////////////////////////////////////////////////////////////
CMapLayerArray::CMapLayerArray()
{
m_iDefault = 0;
Reset();
// Initialise static variables
memset(&m_logfontT,0,sizeof(LOGFONT));
m_logfontT.lfHeight = -16;
m_logfontT.lfPitchAndFamily = 18;
m_logfontT.lfCharSet = NRDB_CHARSET;
m_logfontT.lfWeight = 700;
memset(&m_logfontL,0,sizeof(LOGFONT));
m_logfontL.lfHeight = -10;
m_logfontL.lfPitchAndFamily = 18;
m_logfontL.lfCharSet = NRDB_CHARSET;
m_logfontL.lfWeight = 700;
m_bLegend1Font = FALSE;
// Don't initialise report wizard object as program loads
if (afxCurrentResourceHandle == NULL) return;
strcpy(m_logfontL .lfFaceName, BDString(IDS_DEFAULTFONT));
strcpy(m_logfontT.lfFaceName, BDString(IDS_DEFAULTFONT));
m_sTitle = BDGetSettings().m_Organization;
}
/////////////////////////////////////////////////////////////////////////////
CMapLayerArray::Reset()
{
m_layout = CMapLayout();
}
/////////////////////////////////////////////////////////////////////////////
CMapLayerArray::~CMapLayerArray()
{
RemoveAll();
}
///////////////////////////////////////////////////////////////////////////////
//
// Copy attributes but not array contents
//
CMapLayerArray& CMapLayerArray::operator=(CMapLayerArray& rSrc)
{
m_layout = rSrc.m_layout;
m_sTitle = rSrc.m_sTitle;
m_logfontT = rSrc.m_logfontT;
m_logfontL = rSrc.m_logfontL;
m_bLegend1Font = rSrc.m_bLegend1Font;
m_mapgrid = rSrc.m_mapgrid;
return *this;
}
///////////////////////////////////////////////////////////////////////////////
void CMapLayerArray::RemoveAll()
{
for (int i = 0; i < GetSize(); i++)
{
delete (CMapLayer*)GetAt(i);
}
CArray <CMapLayer*, CMapLayer*>::RemoveAll();
}
///////////////////////////////////////////////////////////////////////////////
BOOL CMapLayer::AddAttribute(CMapLayerObj* pMapLayerObj, CAttrArray& aAttr)
{
BOOL bOK = TRUE;
CString sAttrName;
double dValue = AFX_RFX_DOUBLE_PSEUDO_NULL;
BOOL bFound = FALSE;
// Determine name / attributes
if (m_pQuery != NULL)
{
sAttrName = m_aAttr.GetAttrDesc(aAttr);
}
// Determine the value of the attribute
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -