📄 wksp_shapes.cpp
字号:
wxString::Format(wxT("%s|"), LNG("[VAL] [default]")), 0
);
return( pParameter );
}
//---------------------------------------------------------
void CWKSP_Shapes::_AttributeList_Set(CSG_Parameter *pFields, bool bAddNoField)
{
if( pFields && pFields->Get_Type() == PARAMETER_TYPE_Choice )
{
wxString s;
for(int i=0; i<m_pShapes->Get_Table().Get_Field_Count(); i++)
{
s.Append(wxString::Format(wxT("%s|"), m_pShapes->Get_Table().Get_Field_Name(i)));
}
if( bAddNoField )
{
s.Append(wxString::Format(wxT("%s|"), LNG("[VAL] [none]")));
}
pFields->asChoice()->Set_Items(s);
if( bAddNoField )
{
pFields->Set_Value(m_pShapes->Get_Table().Get_Field_Count());
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CSG_Parameter * CWKSP_Shapes::_BrushList_Add(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description)
{
CSG_Parameter *pParameter;
pParameter = m_Parameters.Add_Choice(
pNode, Identifier, Name, Description,
wxString::Format(wxT("%s|%s|%s|%s|%s|%s|%s|%s|"),
LNG("[VAL] Opaque"),
LNG("[VAL] Transparent"),
LNG("[VAL] Backward Diagonal"),
LNG("[VAL] Cross Diagonal"),
LNG("[VAL] Forward Diagonal"),
LNG("[VAL] Cross"),
LNG("[VAL] Horizontal"),
LNG("[VAL] Vertical")
), 0
);
return( pParameter );
}
//---------------------------------------------------------
int CWKSP_Shapes::_BrushList_Get_Style(int Index)
{
switch( Index )
{
default:
case 0: return( wxSOLID );
case 1: return( wxTRANSPARENT );
case 2: return( wxBDIAGONAL_HATCH );
case 3: return( wxCROSSDIAG_HATCH );
case 4: return( wxFDIAGONAL_HATCH );
case 5: return( wxCROSS_HATCH );
case 6: return( wxHORIZONTAL_HATCH );
case 7: return( wxVERTICAL_HATCH );
}
}
//---------------------------------------------------------
CSG_Parameter * CWKSP_Shapes::_PenList_Add(CSG_Parameter *pNode, const char *Identifier, const wxChar *Name, const wxChar *Description)
{
CSG_Parameter *pParameter;
pParameter = m_Parameters.Add_Choice(
pNode, Identifier, Name, Description,
wxString::Format(wxT("%s|%s|%s|%s|%s|"),
LNG("[VAL] Solid"),
LNG("[VAL] Dotted"),
LNG("[VAL] Long Dashed"),
LNG("[VAL] Short Dashed"),
LNG("[VAL] Dot And Dash")
), 0
);
return( pParameter );
}
//---------------------------------------------------------
int CWKSP_Shapes::_PenList_Get_Style(int Index)
{
switch( Index )
{
default:
case 0: return( wxSOLID );
case 1: return( wxDOT );
case 2: return( wxLONG_DASH );
case 3: return( wxSHORT_DASH );
case 4: return( wxDOT_DASH );
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CWKSP_Shapes::_Chart_Set_Options(void)
{
CSG_Parameters *pChart = m_Parameters("DISPLAY_CHART")->asParameters();
pChart->Destroy();
m_Chart.Clear();
if( 1 )
{
int i, n;
CSG_Colors Colors;
CSG_String sFields;
CSG_Parameter *pFields, *pColors;
CSG_Table *pTable = &m_pShapes->Get_Table();
for(i=0, n=0; i<pTable->Get_Field_Count(); i++)
{
if( pTable->Get_Field_Type(i) != TABLE_FIELDTYPE_String )
n++;
}
if( n > 0 )
{
pChart->Create(NULL, LNG("[CAP] Chart Properties"), LNG(""));
pChart->Add_Choice(
NULL, "TYPE" , LNG("Chart Type"),
LNG(""),
CSG_String::Format(wxT("%s|%s|%s|%s|"),
LNG("bar"),
LNG("bar (not outlined)"),
LNG("pie"),
LNG("pie (not outlined)")
), 0
);
pChart->Add_Choice(
NULL, "SIZE_FIELD" , LNG("[CAP] Attribute (Size)"),
LNG(""),
CSG_String::Format(wxT("%s|"), LNG("[VAL] [not set]")), 0
);
pChart->Add_Choice(
NULL, "SIZE_TYPE" , LNG("[CAP] Size relates to..."),
LNG(""),
wxString::Format(wxT("%s|%s|"),
LNG("[VAL] Screen"),
LNG("[VAL] Map Units")
), 0
);
pChart->Add_Value(
NULL, "SIZE_DEFAULT" , LNG("[CAP] Default Size"),
LNG(""),
PARAMETER_TYPE_Double, 15, 0, true
);
pChart->Add_Range(
NULL, "SIZE_RANGE" , LNG("[CAP] Size Range"),
LNG(""),
5, 25, 0, true
);
pFields = pChart->Add_Node(NULL, "NODE_FIELDS" , LNG("Fields") , LNG(""));
pColors = pChart->Add_Node(NULL, "NODE_COLORS" , LNG("Field Colors") , LNG(""));
Colors.Set_Count(n);
for(i=0, n=0; i<pTable->Get_Field_Count(); i++)
{
if( pTable->Get_Field_Type(i) != TABLE_FIELDTYPE_String )
{
sFields.Append(CSG_String::Format(wxT("%s|"), pTable->Get_Field_Name(i)));
pChart->Add_Value(
pFields , wxString::Format(wxT("FIELD_%d"), i), pTable->Get_Field_Name(i),
LNG(""),
PARAMETER_TYPE_Bool , false
);
pChart->Add_Value(
pColors , wxString::Format(wxT("COLOR_%d"), i), pTable->Get_Field_Name(i),
LNG(""),
PARAMETER_TYPE_Color, Colors.Get_Color(n++)
);
}
}
sFields.Append(CSG_String::Format(wxT("%s|"), LNG("[VAL] [none]")));
pFields = pChart->Get_Parameter("SIZE_FIELD");
pFields->asChoice()->Set_Items(sFields);
pFields->Set_Value(m_pShapes->Get_Table().Get_Field_Count());
return( true );
}
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Chart_Get_Options(void)
{
CSG_Parameters *pChart = m_Parameters("DISPLAY_CHART")->asParameters();
CSG_Parameter *p;
m_Chart.Clear();
m_Chart_sField=-1;
if( pChart->Get_Parameter("NODE_FIELDS") )
{
for(int i=0, n=0; i<m_pShapes->Get_Table().Get_Field_Count(); i++)
{
if( (p = pChart->Get_Parameter(wxString::Format(wxT("FIELD_%d"), i))) != NULL )
{
if( pChart->Get_Parameter("SIZE_FIELD")->asInt() == n++ )
m_Chart_sField = i;
if( p->asBool() && (p = pChart->Get_Parameter(wxString::Format(wxT("COLOR_%d"), i))) != NULL )
m_Chart.Add(i, p->asColor());
}
}
m_Chart_Type = pChart->Get_Parameter("TYPE") ->asInt();
m_Chart_sType = pChart->Get_Parameter("SIZE_TYPE") ->asInt();
m_Chart_sSize = m_Chart_sField < 0
? pChart->Get_Parameter("SIZE_DEFAULT") ->asDouble()
: pChart->Get_Parameter("SIZE_RANGE") ->asRange()->Get_LoVal();
m_Chart_sRange = pChart->Get_Parameter("SIZE_RANGE") ->asRange()->Get_HiVal() - m_Chart_sSize;
return( true );
}
return( false );
}
//---------------------------------------------------------
void CWKSP_Shapes::_Draw_Chart(CWKSP_Map_DC &dc_Map, CSG_Shape *pShape)
{
if( _Chart_is_Valid() )
{
int s;
double dSize = m_Chart_sSize;
TSG_Point_Int p;
if( m_Chart_sField >= 0 )
{
double range, min = m_pShapes->Get_Table().Get_MinValue(m_Chart_sField);
if( (range = (m_pShapes->Get_Table().Get_MaxValue(m_Chart_sField) - min)) > 0.0 )
dSize += m_Chart_sRange * ((pShape->Get_Record()->asDouble(m_Chart_sField) - min) / range);
}
s = (int)(dSize * (m_Chart_sType == 1 ? dc_Map.m_World2DC : dc_Map.m_Scale));
switch( pShape->Get_Type() )
{
default: p = dc_Map.World2DC(pShape->Get_Extent().Get_Center()); break;
case SHAPE_TYPE_Polygon: p = dc_Map.World2DC(((CSG_Shape_Polygon *)pShape)->Get_Centroid()); break;
}
dc_Map.dc.SetPen(*wxBLACK_PEN);
switch( m_Chart_Type )
{
case 0: _Draw_Chart_Bar(dc_Map, pShape->Get_Record(), true, p.x, p.y, (int)(0.8 * s), s); break; // bar outlined
case 1: _Draw_Chart_Bar(dc_Map, pShape->Get_Record(), false, p.x, p.y, (int)(0.8 * s), s); break; // bar
case 2: _Draw_Chart_Pie(dc_Map, pShape->Get_Record(), true, p.x, p.y, (int)(1.0 * s)); break; // pie outlined
case 3: _Draw_Chart_Pie(dc_Map, pShape->Get_Record(), false, p.x, p.y, (int)(1.0 * s)); break; // pie
}
}
}
//---------------------------------------------------------
void CWKSP_Shapes::_Draw_Chart_Pie(CWKSP_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int size)
{
int i, ix, iy, jx, jy;
double d, sum;
for(i=0, sum=0.0; i<m_Chart.Get_Count(); i++)
{
sum += fabs(pRecord->asDouble(m_Chart[i].x));
}
if( sum > 0.0 )
{
sum = M_PI_360 / sum;
for(i=0, jx=x, jy=y-size, d=0.0; i<m_Chart.Get_Count(); i++)
{
if( !bOutline )
dc_Map.dc.SetPen (wxPen (Get_Color_asWX(m_Chart[i].y)));
dc_Map.dc.SetBrush (wxBrush(Get_Color_asWX(m_Chart[i].y)));
d += sum * fabs(pRecord->asDouble(m_Chart[i].x));
ix = jx;
iy = jy;
jx = x - (int)(size * sin(-d));
jy = y - (int)(size * cos(-d));
dc_Map.dc.DrawArc(jx, jy, ix, iy, x, y);
}
}
}
//---------------------------------------------------------
void CWKSP_Shapes::_Draw_Chart_Bar(CWKSP_Map_DC &dc_Map, CSG_Table_Record *pRecord, bool bOutline, int x, int y, int sx, int sy)
{
int i;
double d, dx, dy, max, ix;
for(i=1, max=fabs(pRecord->asDouble(m_Chart[0].x)); i<m_Chart.Get_Count(); i++)
{
if( (d = fabs(pRecord->asDouble(m_Chart[i].x))) > max )
max = d;
}
if( max != 0.0 )
{
max = sy / max;
dx = sx / (double)m_Chart.Get_Count();
for(i=0, ix=x-sx/2.0; i<m_Chart.Get_Count(); i++, ix+=dx)
{
if( !bOutline )
dc_Map.dc.SetPen (wxPen (Get_Color_asWX(m_Chart[i].y)));
dc_Map.dc.SetBrush (wxBrush(Get_Color_asWX(m_Chart[i].y)));
dy = -pRecord->asDouble(m_Chart[i].x) * max;
dc_Map.dc.DrawRectangle((int)ix, y, (int)dx, (int)dy);
}
if( !bOutline )
{
dc_Map.dc.SetPen(*wxBLACK_PEN);
dc_Map.dc.DrawLine(x - sx / 2, y, x + sx / 2, y);
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -