📄 wksp_shapes_edit.cpp
字号:
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Shape(void)
{
return( m_Edit_pShape ? _Edit_Shape_Stop() : _Edit_Shape_Start() );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Shape_Start(void)
{
if( m_Edit_pShape == NULL && m_pShapes->Get_Selection(0) != NULL )
{
m_Edit_pShape = m_Edit_Shapes.Add_Shape();
m_Edit_pShape->Assign(m_pShapes->Get_Selection(0), false);
m_Edit_iPart = -1;
m_Edit_iPoint = -1;
Update_Views(true);
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Shape_Stop(void)
{
return( _Edit_Shape_Stop(DLG_Message_Confirm(LNG("[DLG] Save changes?"), LNG("[CAP] Edit Shapes"))) );
}
bool CWKSP_Shapes::_Edit_Shape_Stop(bool bSave)
{
if( m_Edit_pShape != NULL )
{
if( bSave )
{
if( m_pShapes->Get_Selection(0) != NULL )
{
m_pShapes->Get_Selection(0)->Assign(m_Edit_pShape, false);
}
else
{
m_pShapes->Add_Shape()->Assign(m_Edit_pShape, false);
}
}
m_Edit_Shapes.Del_Shape(m_Edit_pShape);
m_Edit_pShape = NULL;
Update_Views(false);
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Shape_Add(void)
{
if( !m_Edit_pShape )
{
if( m_pShapes->Get_Selection_Count() > 0 )
{
m_pShapes->Select();
}
m_Edit_pShape = m_Edit_Shapes.Add_Shape();
return( _Edit_Part_Add() );
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Part_Add(void)
{
if( m_Edit_pShape )
{
m_Edit_iPart = m_Edit_pShape->Get_Part_Count();
m_Edit_iPoint = -1;
Update_Views(true);
return( true );
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Shape_Del(void)
{
if( DLG_Message_Confirm(LNG("[DLG] Delete selected shape(s)."), LNG("[CAP] Edit Shapes")) )
{
if( m_pShapes->Get_Selection_Count() > 0 )
{
if( m_Edit_pShape )
{
_Edit_Shape_Stop(false);
m_pShapes->Del_Shape(m_pShapes->Get_Selection(0));
}
else
{
m_pShapes->Del_Selection();
}
Update_Views(false);
return( true );
}
return( _Edit_Shape_Stop(false) );
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Part_Del(void)
{
if( m_Edit_pShape && m_Edit_iPart >= 0 )
{
if( m_Edit_pShape->Get_Part_Count() > 1 )
{
m_Edit_pShape->Del_Part(m_Edit_iPart);
m_Edit_iPart = -1;
m_Edit_iPoint = -1;
Update_Views(true);
return( true );
}
else
{
return( _Edit_Shape_Del() );
}
}
return( false );
}
//---------------------------------------------------------
bool CWKSP_Shapes::_Edit_Point_Del(void)
{
if( m_Edit_pShape && m_Edit_iPart >= 0 && m_Edit_iPoint >= 0 )
{
if( m_Edit_pShape->Get_Point_Count(m_Edit_iPart) > 1 )
{
m_Edit_pShape->Del_Point(m_Edit_iPoint, m_Edit_iPart);
if( m_Edit_iPoint >= m_Edit_pShape->Get_Point_Count(m_Edit_iPart) )
{
m_Edit_iPoint = m_Edit_pShape->Get_Point_Count(m_Edit_iPart) - 1;
}
if( m_Edit_pShape->Get_Point_Count(m_Edit_iPart) <= 1 )
{
if( m_pShapes->Get_Type() == SHAPE_TYPE_Line || m_pShapes->Get_Type() == SHAPE_TYPE_Polygon )
{
m_Edit_iPoint = -1;
}
}
Update_Views(true);
return( true );
}
else
{
return( _Edit_Part_Del() );
}
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Shape_Draw_Point(wxDC &dc, TSG_Point_Int Point, bool bSelected)
{
_Edit_Shape_Draw_Point(dc, Point.x, Point.y, bSelected);
}
void CWKSP_Shapes::_Edit_Shape_Draw_Point(wxDC &dc, int x, int y, bool bSelected)
{
dc.SetPen (*wxBLACK_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawCircle(x, y, 2);
Draw_Edge(dc, EDGE_STYLE_SIMPLE,
x - EDIT_TICKMARK_SIZE - 1,
y - EDIT_TICKMARK_SIZE - 1,
x + EDIT_TICKMARK_SIZE,
y + EDIT_TICKMARK_SIZE
);
if( bSelected )
{
dc.SetPen(*wxRED_PEN);
Draw_Edge(dc, EDGE_STYLE_SIMPLE,
x - EDIT_TICKMARK_SIZE - 2,
y - EDIT_TICKMARK_SIZE - 2,
x + EDIT_TICKMARK_SIZE + 1,
y + EDIT_TICKMARK_SIZE + 1
);
}
}
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Shape_Draw_Move(wxDC &dc, CSG_Rect rWorld, double ClientToWorld, wxPoint Point)
{
_Edit_Shape_Draw_Point(dc, Point.x, Point.y, false);
}
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Shape_Draw(CWKSP_Map_DC &dc_Map)
{
int iPart, iPoint;
if( m_Edit_pShape )
{
for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
{
for(iPoint=0; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
{
_Edit_Shape_Draw_Point(dc_Map.dc, dc_Map.World2DC(m_Edit_pShape->Get_Point(iPoint, iPart)), false);
}
}
if( m_Edit_iPart >= 0 && m_Edit_iPoint >= 0 )
{
_Edit_Shape_Draw_Point(dc_Map.dc, dc_Map.World2DC(m_Edit_pShape->Get_Point(m_Edit_iPoint, m_Edit_iPart)), true);
}
if( m_Parameters("EDIT_SNAP_LIST")->asShapesList()->Get_Count() > 0 )
{
iPoint = m_Parameters("EDIT_SNAP_DIST")->asInt();
dc_Map.dc.DrawCircle(1 + iPoint, 1 + iPoint, iPoint);
}
}
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Snap_Point(CSG_Point &Point, double ClientToWorld)
{
if( m_Edit_pShape )
{
CSG_Parameter_Shapes_List *pList = m_Parameters("EDIT_SNAP_LIST")->asShapesList();
if( pList->Get_Count() > 0 )
{
int i;
double snap_Dist, max_Dist;
CSG_Point snap_Point;
max_Dist = m_Parameters("EDIT_SNAP_DIST")->asDouble() * ClientToWorld;
snap_Dist = max_Dist + 1.0;
for(i=0; i<pList->Get_Count(); i++)
{
_Edit_Snap_Point(Point, snap_Point, snap_Dist, pList->asShapes(i), false);
}
if( snap_Dist <= max_Dist )
{
Point = snap_Point;
}
else if( m_pShapes->Get_Type() == SHAPE_TYPE_Line || m_pShapes->Get_Type() == SHAPE_TYPE_Polygon )
{
for(i=0; i<pList->Get_Count(); i++)
{
_Edit_Snap_Point(Point, snap_Point, snap_Dist, pList->asShapes(i), true);
}
if( snap_Dist <= max_Dist )
{
Point = snap_Point;
}
}
}
}
}
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Snap_Point(CSG_Point Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shapes *pShapes, bool bLine)
{
CSG_Shape *pSelected = pShapes->Get_Selection();
if( pShapes->Select(CSG_Rect(Point.Get_X() - snap_Dist, Point.Get_Y() - snap_Dist, Point.Get_X() + snap_Dist, Point.Get_Y() + snap_Dist)) )
{
for(int i=0; i<pShapes->Get_Selection_Count(); i++)
{
if( pShapes != m_pShapes || pSelected != pShapes->Get_Selection(i) )
{
if( bLine )
{
_Edit_Snap_Point_ToLine(Point, snap_Point, snap_Dist, pShapes->Get_Selection(i));
}
else
{
_Edit_Snap_Point (Point, snap_Point, snap_Dist, pShapes->Get_Selection(i));
}
}
}
}
pShapes->Select(pSelected);
}
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Snap_Point(CSG_Point pos_Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape)
{
int iPart, iPoint;
double d, dx, dy;
TSG_Point Point;
for(iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
{
for(iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
{
Point = pShape->Get_Point(iPoint, iPart);
dx = pos_Point.Get_X() - Point.x;
dy = pos_Point.Get_Y() - Point.y;
d = sqrt(dx*dx + dy*dy);
if( d < snap_Dist )
{
snap_Dist = d;
snap_Point = Point;
}
}
}
}
//---------------------------------------------------------
void CWKSP_Shapes::_Edit_Snap_Point_ToLine(CSG_Point pos_Point, CSG_Point &snap_Point, double &snap_Dist, CSG_Shape *pShape)
{
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
int CWKSP_Shapes::_Edit_Shape_HitTest(CSG_Point pos_Point, double max_Dist, int &pos_iPart, int &pos_iPoint)
{
int Result, iPart, iPoint;
double d, dx, dy;
TSG_Point Point;
Result = 0;
pos_iPoint = -1;
pos_iPart = -1;
if( m_Edit_pShape )
{
for(iPart=0; iPart<m_Edit_pShape->Get_Part_Count(); iPart++)
{
for(iPoint=0; iPoint<m_Edit_pShape->Get_Point_Count(iPart); iPoint++)
{
Point = m_Edit_pShape->Get_Point(iPoint, iPart);
dx = pos_Point.Get_X() - Point.x;
dy = pos_Point.Get_Y() - Point.y;
d = sqrt(dx*dx + dy*dy);
if( 0.0 > max_Dist || d < max_Dist )
{
Result = 1;
max_Dist = d;
pos_iPoint = iPoint;
pos_iPart = iPart;
}
}
}
}
return( Result );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -