📄 maplayer.cpp
字号:
// Tidy up
if (pFile != NULL) fclose(pFile);
if (BDGetProgressBar() != NULL)
{
BDGetProgressBar()->SetPos(0);
};
AfxGetApp()->EndWaitCursor();
return bOK;
}
/////////////////////////////////////////////////////////////////////////////
void CMapLayer::Write(FILE* pFile)
{
// Output the attributes for the layer to file
fprintf(pFile,"begin\n");
fprintf(pFile,"name=\"%s\"\n",m_prop.m_sName);
fprintf(pFile,"textcolor=%i,%i,%i\n",GetRValue(m_prop.m_colorText),GetGValue(m_prop.m_colorText),GetBValue(m_prop.m_colorText));
fprintf(pFile,"symbol=%i,%lf\n",m_prop.m_nSymbol,m_prop.m_dSymSize);
fprintf(pFile,"colorline=%i\n", m_prop.m_crLine);
fprintf(pFile,"colorfill=%i\n", m_prop.m_crFill);
fprintf(pFile,"pattern=%i\n",m_prop.m_nPattern);
fprintf(pFile,"hatch=%i\n",m_prop.m_nHatch);
fprintf(pFile,"line=%i,%i\n",m_prop.m_nLineStyle,m_prop.m_nLineWidth);
fprintf(pFile,"text=%i,%i\n",m_prop.m_bOverlap, m_prop.m_nTextPos);
fprintf(pFile,"comment=\"%s\"\n",m_prop.m_sComment);
fprintf(pFile,"fitsym=%i\n", m_prop.m_bBestFitSym);
fprintf(pFile,"showlayername=%i\n", m_prop.m_bShowLayerName);
fprintf(pFile,"visible=%i\n", m_prop.m_bVisible);
fprintf(pFile,"sepcolor=%li\n",m_prop.m_nSepColour);
if (m_prop.m_nSepColour)
{
m_prop.m_aColourFeature.Write(pFile, m_prop.m_nSepColour);
}
fprintf(pFile,"rangecolor=%i\n", m_prop.m_bRangeColour);
if (m_prop.m_bRangeColour)
{
m_prop.m_aRangeColour.Write(pFile);
}
fprintf(pFile,"scalefont=%i\n",m_prop.m_bScaleFont);
fprintf(pFile,"autocolor=%i\n",m_prop.m_bAutoColour);
fprintf(pFile,"autosize=%i\n",m_prop.m_bAutoSize);
fprintf(pFile,"fillpolygon=%i\n",m_prop.m_bPolygon);
fprintf(pFile,"automin=%lf\n",m_prop.m_dAutoMin);
fprintf(pFile,"automax=%lf\n",m_prop.m_dAutoMax);
BDWrite(pFile,&m_prop.m_logfont, "logfont");
BDWrite(pFile,&m_prop.m_logfontC, "logfontC");
// Write name of filename for overlays and column
fprintf(pFile, "filename=%s\n", (LPCSTR)m_sFile);
fprintf(pFile, "column=%s\n", (LPCSTR)m_sColumn);
// Save the query
if (m_pQuery != NULL)
{
fprintf(pFile, "Query\n");
m_pQuery->Write(pFile);
} else
{
fprintf(pFile, "Standard\n");
if (m_sFile == "")
{
fprintf(pFile,"ftype=%li\n",m_lFType);
fprintf(pFile,"attr=");
for (int i = 0; i < m_aAttr.GetSize(); i++)
{
if (i != 0) fprintf(pFile,",");
fprintf(pFile,"%li",m_aAttr[i]);
};
fprintf(pFile,"\n");
// Output the map layer objects
fprintf(pFile,"features=");
for (i = 0; i < GetSize(); i++)
{
CMapLayerObj* pMapLayerObj = (CMapLayerObj*)GetAt(i);
if (i > 0) fprintf(pFile,",");
fprintf(pFile,"%li",pMapLayerObj->GetFeature());
}
fprintf(pFile,"\n");
};
};
fprintf(pFile,"end\n");
}
/////////////////////////////////////////////////////////////////////////////
int CMapLayer::Read(CMapLayerArray* pMapLayerArray, FILE* pFile)
{
BOOL bOK = TRUE;
CString s = BDNextItem(pFile);
if (s == "begin")
{
// Read the map layer attributes
// Backwards compatability
CString s = BDNextStr(pFile,"title");
if (s != "") pMapLayerArray->m_sTitle = s;
BDNext(pFile, &pMapLayerArray->m_logfontT, "logfontT");
BDNext(pFile, &pMapLayerArray->m_logfontL, "logfontL");
BOOL b = BDNextInt(pFile, "legend1Font", -1);
if (b!= -1) pMapLayerArray->m_bLegend1Font = b;
m_prop.m_sName = BDNextStr(pFile, "name");
BDNextRGB(pFile, "color"); //Backwards compatibility
m_prop.m_colorText = BDNextRGB(pFile, "textcolor");
m_prop.m_nSymbol = BDNextInt(pFile);
m_prop.m_dSymSize = BDNextDouble(pFile, FALSE);
m_prop.m_crLine = BDNextInt(pFile, "colorline");
m_prop.m_crFill = BDNextInt(pFile, "colorfill");
m_prop.m_nPattern = BDNextInt(pFile, "pattern");
m_prop.m_nHatch = BDNextInt(pFile, "hatch");
m_prop.m_nLineStyle = BDNextInt(pFile);
m_prop.m_nLineWidth = BDNextInt(pFile, FALSE);
m_prop.m_bOverlap = BDNextInt(pFile);
m_prop.m_nTextPos = BDNextInt(pFile, FALSE);
// Read comment, restore line feeds
m_prop.m_sComment = BDNextStr(pFile,"comment");
m_prop.m_bBestFitSym = BDNextInt(pFile,"fitsym");
m_prop.m_bShowLayerName = BDNextInt(pFile,"showlayername");
m_prop.m_bVisible = BDNextInt(pFile,"visible", TRUE);
m_prop.m_nSepColour = BDNextInt(pFile,"sepcolor");
if (m_prop.m_nSepColour)
{
m_prop.m_aColourFeature.Read(pFile, m_prop.m_nSepColour);
};
m_prop.m_bRangeColour = BDNextInt(pFile,"rangecolor");
if (m_prop.m_bRangeColour)
{
m_prop.m_aRangeColour.Read(pFile);
}
m_prop.m_bScaleFont = BDNextInt(pFile,"scalefont");
m_prop.m_bAutoColour = BDNextInt(pFile, TRUE);
m_prop.m_bAutoSize = BDNextInt(pFile, TRUE);
m_prop.m_bPolygon = BDNextInt(pFile, TRUE);
m_prop.m_dAutoMin = BDNextDouble(pFile);
m_prop.m_dAutoMax = BDNextDouble(pFile);
BDNext(pFile, &m_prop.m_logfont,"logfont");
BDNext(pFile, &m_prop.m_logfontC,"logfontC");
m_sFile = BDNextStr(pFile, "filename");
m_sColumn = BDNextStr(pFile, "column");
s = BDNextItem(pFile);
// Query
if (s == "Query")
{
ASSERT(m_pQuery == NULL);
m_pQuery = new CQuery;
bOK = m_pQuery->Read(pFile);
}
// Read the map layer objects
else
{
if (m_sFile == "")
{
m_lFType = BDNextInt(pFile);
BDNext(pFile, &m_aAttr, m_lFType);
m_alFeatures.RemoveAll();
BDNext(pFile, m_alFeatures);
};
};
s = BDNextItem(pFile);
if (s != "end") bOK = FALSE;
}
else
{
return -1;
}
return bOK;
}
/////////////////////////////////////////////////////////////////////////////
void CColourFeatureArray::Write(FILE* pFile, int nSepColour)
{
fprintf(pFile,"numcolor=%li\n",GetSize());
for (int i = 0; i < GetSize(); i++)
{
fprintf(pFile,"colorfeature=%li,\"%s\"",GetAt(i).m_lFeatureId, GetAt(i).m_sFeature);
if (nSepColour == CMapLayer::SepColourAttr || nSepColour == CMapLayer::LegendValues)
{
fprintf(pFile, ",\"%s\"", GetAt(i).m_sAttr);
}
fprintf(pFile, ",%li\n", GetAt(i).m_crFill);
fprintf(pFile, "mapstyle=%li", GetAt(i).m_crLine);
fprintf(pFile, ",%li", GetAt(i).m_nLineStyle);
fprintf(pFile, ",%li", GetAt(i).m_nLineWidth);
fprintf(pFile, ",%li", GetAt(i).m_nPattern);
fprintf(pFile, ",%li",GetAt(i).m_nHatch);
fprintf(pFile, ",%li",GetAt(i).m_nSymbol);
fprintf(pFile, ",%lf\n",GetAt(i).m_dSymSize);
}
}
/////////////////////////////////////////////////////////////////////////////
BOOL CColourFeatureArray::Read(FILE* pFile, int nSepColour)
{
BOOL bOK = TRUE;
RemoveAll();
int n = BDNextInt(pFile);
for (int i = 0; i < n; i++)
{
CColourFeature feature;
feature.m_lFeatureId = BDNextInt(pFile,TRUE);
feature.m_sFeature = BDNextStr(pFile,FALSE);
if (nSepColour == CMapLayer::SepColourAttr || nSepColour == CMapLayer::LegendValues)
{
feature.m_sAttr = BDNextStr(pFile,FALSE);
}
feature.m_crFill = BDNextInt(pFile,FALSE);
// Read addional attributes if available - NRDB Pro 2.0
int n = BDNextInt(pFile, "mapstyle", -1);
if (n != -1)
{
feature.m_crLine = n;
feature.m_nLineStyle = BDNextInt(pFile, FALSE);
feature.m_nLineWidth = BDNextInt(pFile, FALSE);
feature.m_nPattern = BDNextInt(pFile, FALSE);
feature.m_nHatch = BDNextInt(pFile, FALSE);
feature.m_nSymbol = BDNextInt(pFile, FALSE);
feature.m_dSymSize = BDNextDouble(pFile, FALSE);
}
Add(feature);
}
return bOK;
}
///////////////////////////////////////////////////////////////////////////////
CRangeColourArray& CRangeColourArray::operator=(CRangeColourArray &rSrc)
{
m_dRound = rSrc.m_dRound;
Copy(rSrc);
return *this;
}
///////////////////////////////////////////////////////////////////////////////
void CRangeColourArray::Write(FILE* pFile)
{
CString s;
fprintf(pFile,"numcolor=%li\n",GetSize());
for (int i = 0; i < GetSize(); i++)
{
fprintf(pFile,"colorfeature=%lf,%lf\n",GetAt(i).m_dMin, GetAt(i).m_dMax);
s = ((CMapStyle&)GetAt(i)).AsString();
fprintf(pFile, "mapstyle=%s\n", (LPCSTR)s);
}
fprintf(pFile, "round=%lf\n", m_dRound);
}
///////////////////////////////////////////////////////////////////////////////
BOOL CRangeColourArray::Read(FILE* pFile)
{
BOOL bOK = TRUE;
RemoveAll();
int n = BDNextInt(pFile);
for (int i = 0; i < n; i++)
{
CRangeColour rangecolor;
rangecolor.m_dMin = BDNextDouble(pFile, TRUE);
rangecolor.m_dMax = BDNextDouble(pFile, FALSE);
CString s = BDNextStr(pFile, FALSE);
if (s == "mapstyle") BDNext(pFile, (CMapStyle&)rangecolor);
else sscanf(s, "%d", &rangecolor.m_crFill);
Add(rangecolor);
}
m_dRound = BDNextDouble(pFile, "round", 1);
return bOK;
}
///////////////////////////////////////////////////////////////////////////////
//
// Returns the text description of the selected item, e.g. 0 <= n < 1
//
CString CRangeColourArray::GetDesc(int i)
{
CString s;
// Count number of decimal places
strstream sValue;
if (m_dRound != 0)
{
int nDP = 0;
CString sFormat;
sFormat.Format("%lf", m_dRound);
int k = sFormat.Find('.');
int j = sFormat.Find('1',k+1);
if (j > -1 && k > -1) nDP = j-k;
sValue.flags(ios::fixed);
sValue.precision(nDP);
};
// Zero condition
if (GetAt(i).m_dMin == GetAt(i).m_dMax)
{
sValue << GetAt(i).m_dMin << ends;
}
// Next to zero
else if (i > 0 && GetAt(i-1).m_dMin == GetAt(i-1).m_dMax)
{
sValue << GetAt(i).m_dMin << " < n < " << GetAt(i).m_dMax << ends;
}
// Other conditions
else
{
sValue << GetAt(i).m_dMin << " <= n < " << GetAt(i).m_dMax << ends;
};
s = sValue.str();
sValue.rdbuf()->freeze(0);
return s;
}
/////////////////////////////////////////////////////////////////////////////
BOOL CMapLayer::Initialise(CQuery* pQuery)
{
BOOL bOK = TRUE;
m_pQuery = pQuery;
m_lFType = m_pQuery->GetFType();
// Create the map objects based on the query results
if (m_prop.m_sName == "")
{
m_prop.m_sName = m_pQuery->GetQueryName();
};
CQueryResult queryresult;
if (queryresult.Initialise(pQuery))
{
// Copy the attributes from the query result
m_aAttr.RemoveAll();
for (int i = 0; i < queryresult.GetAttrArray().GetSize(); i++)
{
m_aAttr.Add(queryresult.GetAttrArray().GetAt(i));
};
// Retrieve map attributes
for (i = 0; i < queryresult.GetSize(); i++)
{
CMapLayerObj* pMapObj = new CMapLayerObj;
pMapObj->SetFeature(queryresult.GetAt(i)->m_lFeature);
if (AddAttribute(pMapObj, *queryresult[i]))
{
Add(pMapObj);
} else
{
delete pMapObj;
}
}
} else
{
bOK = FALSE;
}
return bOK;
}
///////////////////////////////////////////////////////////////////////////////
void CMapLayerArray::OnLoad(LPCSTR psFile)
{
CString sPathName;
// If no file specified then display file open dialog
if (psFile == NULL)
{
CFileDialog dlg(TRUE, "nrm", NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
BDString(IDS_NRDBFILE) + "|*.nrm||");
if (dlg.DoModal() == IDOK)
{
sPathName = dlg.GetPathName();
// If existing layers then ask whether to replace
if (GetSize() != 0)
{
if (AfxMessageBox(BDString(IDS_REPLACELAYERS), MB_YESNO+MB_DEFBUTTON2) == IDYES)
{
m_sTitle = "";
RemoveAll();
}
}
};
} else
{
sPathName = psFile;
}
// Redraw the screen
AfxGetMainWnd()->UpdateWindow();
AfxGetMainWnd()->RedrawWindow();
// Import the layers
if (sPathName != "")
{
CDlgProgress dlgProgress;
CMapLayerArray aMapLayers;
if (aMapLayers.Read(sPathName))
{
int nSets = aMapLayers.GetSize();
int nSet = 0;
for (int i = 0; i < aMapLayers.GetSize(); i++)
{
Add(aMapLayers[i]);
aMapLayers.RemoveAt(i--); // Don't delete pointers
};
// Copy maplayers properties
*this = aMapLayers;
}
else
{
if (m_sError == "") m_sError = BDString(IDS_CHANGEDATADICT);
AfxMessageBox(BDString(IDS_ERROROPEN) + ": " + sPathName + "\r\n" + m_sError);
m_sError = "";
}
};
}
///////////////////////////////////////////////////////////////////////////////
CColourFeature::CColourFeature()
{
m_lFeatureId = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -