⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wksp_map.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{
		if( pLayer == Get_Layer(i)->Get_Layer() )
		{
			return( Get_Layer(i) );
		}
	}

	return( NULL );
}

//---------------------------------------------------------
int CWKSP_Map::Get_Layer(CWKSP_Layer *pLayer)
{
	for(int i=0; i<Get_Count(); i++)
	{
		if( pLayer == Get_Layer(i)->Get_Layer() )
		{
			return( i );
		}
	}

	return( -1 );
}

//---------------------------------------------------------
CWKSP_Map_Layer * CWKSP_Map::Add_Layer(CWKSP_Layer *pLayer)
{
	CWKSP_Map_Layer	*pItem;

	if( Get_Layer(pLayer) < 0 )
	{
		if( Get_Count() == 0 )
		{
			m_Extent	= pLayer->Get_Extent();
		}

		if( Get_Count() == 0 || m_Parameters("GOTO_NEWLAYER")->asBool() )
		{
			Set_Extent(pLayer->Get_Extent());
		}

		Add_Item(pItem = new CWKSP_Map_Layer(pLayer));

		Move_Top(pItem);

		return( pItem );
	}

	return( NULL );
}

//---------------------------------------------------------
bool CWKSP_Map::Update(CWKSP_Layer *pLayer, bool bMapOnly)
{
	int		iLayer;
	
	if( (iLayer = Get_Layer(pLayer)) >= 0 )
	{
		if( !bMapOnly )
		{
			Get_Layer(iLayer)->Parameters_Changed();
		}

		if( m_pView )
		{
			View_Refresh(bMapOnly);
		}

		_Img_Save_On_Change();

		return( true );
	}

	return( false );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CWKSP_Map::Set_Extent(TSG_Rect Extent)
{
	if( Extent.xMax - Extent.xMin == 0.0 )
	{
		Extent.xMin	-= 0.01 * m_Extent.Get_XRange();
		Extent.xMax	+= 0.01 * m_Extent.Get_XRange();
	}

	if( Extent.yMax - Extent.yMin == 0.0 )
	{
		Extent.yMin	-= 0.01 * m_Extent.Get_YRange();
		Extent.yMax	+= 0.01 * m_Extent.Get_YRange();
	}

	if( !(m_Extent == Extent) )
	{
		m_Extent_Last	= m_Extent;
		m_Extent		= Extent;

		View_Refresh(true);

		if( m_bSynchronise )
		{
			_Synchronise_Extents();
		}
	}
}

//---------------------------------------------------------
void CWKSP_Map::Set_Extent(void)
{
	CSG_Parameters	p;

	p.Create(NULL, LNG("[CAP] Map Extent"), LNG(""));
	p.Add_Range(NULL, "X", LNG("West-East")		, LNG(""), m_Extent.Get_XMin(), m_Extent.Get_XMax());
	p.Add_Range(NULL, "Y", LNG("South-North")	, LNG(""), m_Extent.Get_YMin(), m_Extent.Get_YMax());

	if( DLG_Parameters(&p) )
	{
		CSG_Rect	Extent(	p("X")->asRange()->Get_LoVal(),
							p("Y")->asRange()->Get_LoVal(),
							p("X")->asRange()->Get_HiVal(),
							p("Y")->asRange()->Get_HiVal()	);

		Set_Extent(Extent);
	}
}

//---------------------------------------------------------
void CWKSP_Map::Set_Extent_Last(void)
{
	Set_Extent(m_Extent_Last);
}

//---------------------------------------------------------
void CWKSP_Map::Set_Extent_Full(void)
{
	if( Get_Count() > 0 )
	{
		CSG_Rect	Extent(Get_Layer(0)->Get_Layer()->Get_Extent());

		for(int i=1; i<Get_Count(); i++)
		{
			Extent.Union(Get_Layer(i)->Get_Layer()->Get_Extent());
		}

		Set_Extent(Extent);
	}
}

//---------------------------------------------------------
void CWKSP_Map::Set_Extent_Active(void)
{
	if( Get_Active_Layer() )
	{
		Set_Extent(Get_Active_Layer()->Get_Extent());
	}
}

//---------------------------------------------------------
void CWKSP_Map::Set_Extent_Selection(void)
{
	if( Get_Active_Layer() )
	{
		Set_Extent(Get_Active_Layer()->Edit_Get_Extent());
	}
}

//---------------------------------------------------------
void CWKSP_Map::_Synchronise_Extents(void)
{
	for(int i=0; i<Get_Manager()->Get_Count(); i++)
	{
		if( Get_Manager()->Get_Item(i) != this )
		{
			((CWKSP_Map_Manager *)Get_Manager())->Get_Map(i)->Set_Extent(m_Extent);
		}
	}
}

//---------------------------------------------------------
void CWKSP_Map::Set_Synchronising(bool bOn)
{
	m_bSynchronise	= bOn;

	if( m_bSynchronise )
	{
		_Synchronise_Extents();
	}
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CWKSP_Map::On_Delete(CWKSP_Map_Layer *pLayer)
{
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
void CWKSP_Map::View_Closes(wxMDIChildFrame *pView)
{
	if( wxDynamicCast(pView, CVIEW_Map) != NULL )
	{
		m_pView		= NULL;
	}

	if( wxDynamicCast(pView, CVIEW_Map_3D) != NULL )
	{
		m_pView_3D	= NULL;
	}

	if( wxDynamicCast(pView, CVIEW_Layout) != NULL )
	{
		m_pLayout	= NULL;
	}
}

//---------------------------------------------------------
void CWKSP_Map::View_Refresh(bool bMapOnly)
{
	if( !bMapOnly && g_pACTIVE && g_pACTIVE->Get_Legend() )
	{
		g_pACTIVE->Get_Legend()->Refresh(true);
	}

	if( m_pView )
	{
		m_pView->Refresh_Map();
	}

	if( m_pView_3D )
	{
		m_pView_3D->On_Source_Changed();
	}

	if( m_pLayout )
	{
		m_pLayout->Refresh_Layout();
	}
}

//---------------------------------------------------------
void CWKSP_Map::View_Show(bool bShow)
{
	if( bShow )
	{
		if( !m_pView )
		{
			m_pView	= new CVIEW_Map(this, Get_Frame_Width());
		}
		else
		{
			View_Refresh(false);
			m_pView->Activate();
		}
	}
	else if( m_pView )
	{
		m_pView->Destroy();
		delete(m_pView);
	}
}

//---------------------------------------------------------
void CWKSP_Map::View_Toggle(void)
{
	View_Show( m_pView == NULL );
}

//---------------------------------------------------------
void CWKSP_Map::View_3D_Show(bool bShow)
{
	if( bShow && !m_pView_3D )
	{
		m_pView_3D	= new CVIEW_Map_3D(this);
	}
	else if( !bShow && m_pView_3D )
	{
		m_pView_3D->Destroy();
		delete(m_pView_3D);
	}
}

//---------------------------------------------------------
void CWKSP_Map::View_3D_Toggle(void)
{
	View_3D_Show( m_pView_3D == NULL );
}

//---------------------------------------------------------
void CWKSP_Map::View_Layout_Show(bool bShow)
{
	if( bShow && !m_pLayout )
	{
		m_pLayout	= new CVIEW_Layout(m_pLayout_Info);
	}
	else if( !bShow && m_pLayout )
	{
		m_pLayout->Destroy();
		delete(m_pLayout);
	}
}

//---------------------------------------------------------
void CWKSP_Map::View_Layout_Toggle(void)
{
	View_Layout_Show( m_pLayout == NULL );
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
CSG_Rect CWKSP_Map::Get_World(wxRect rClient)
{
	double		d, dWorld, dClient;
	TSG_Rect	Extent;

	Extent	= m_Extent.m_rect;

	dClient	= (double)rClient.GetHeight()	/ (double)rClient.GetWidth();
	dWorld	= m_Extent.Get_YRange()			/ m_Extent.Get_XRange();

	if( dWorld > dClient )
	{
		d			= (m_Extent.Get_XRange() - m_Extent.Get_YRange() / dClient) / 2.0;
		Extent.xMin	+= d;
		Extent.xMax	-= d;
	}
	else
	{
		d			= (m_Extent.Get_YRange() - m_Extent.Get_XRange() * dClient) / 2.0;
		Extent.yMin	+= d;
		Extent.yMax	-= d;
	}

	return( CSG_Rect(Extent) );
}

//---------------------------------------------------------
CSG_Point CWKSP_Map::Get_World(wxRect rClient, wxPoint ptClient)
{
	double		d;
	CSG_Rect	rWorld(Get_World(rClient));

	ptClient.y	= rClient.GetHeight() - ptClient.y;
	d			= rWorld.Get_XRange() / (double)rClient.GetWidth();

	return( CSG_Point(
		rWorld.Get_XMin() + ptClient.x * d,
		rWorld.Get_YMin() + ptClient.y * d)
	);
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#define MASK_R	255
#define MASK_G	0
#define MASK_B	255

//---------------------------------------------------------
bool CWKSP_Map::Get_Image(wxImage &Image, CSG_Rect &rWorld)
{
	if( Image.GetWidth() > 0 && Image.GetHeight() > 0 )
	{
		wxBitmap	BMP(Image);
		wxMemoryDC	dc;

		dc.SelectObject(BMP);
		Draw_Map(dc, 1.0, wxRect(0, 0, Image.GetWidth(), Image.GetHeight()), false, SG_GET_RGB(MASK_R, MASK_G, MASK_B));
		dc.SelectObject(wxNullBitmap);

		rWorld	= Get_World(wxRect(0, 0, Image.GetWidth(), Image.GetHeight()));
		Image	= BMP.ConvertToImage();
		Image.SetMaskColour(MASK_R, MASK_G, MASK_B);

		return( true );
	}

	return( false );
}

//---------------------------------------------------------
void CWKSP_Map::SaveAs_Image(void)
{
	//-----------------------------------------------------
	if( DLG_Image_Save(m_Img_File, m_Img_Type) && DLG_Parameters(&m_Img_Parms) )
	{
		_Img_Save(m_Img_File, m_Img_Type);
	}
}

//---------------------------------------------------------
void CWKSP_Map::SaveAs_Image_On_Change(void)
{
	if( m_Img_bSave )
	{
		m_Img_bSave	= false;
	}
	else if( DLG_Image_Save(m_Img_File, m_Img_Type) && DLG_Parameters(&m_Img_Parms) )
	{
		m_Img_bSave	= true;
		m_Img_Count	= 0;
	}
}

//---------------------------------------------------------
void CWKSP_Map::_Img_Save_On_Change(void)
{
	if( m_Img_bSave )
	{
		wxFileName	fn(m_Img_File), file(m_Img_File);

		file.SetName(wxString::Format(wxT("%s_%03d"), fn.GetName().c_str(), m_Img_Count++));

		_Img_Save(file.GetFullPath(), m_Img_Type);
	}
}

//---------------------------------------------------------
void CWKSP_Map::_Img_Save(wxString file, int type)
{
	int			nx, ny, Frame;
	wxSize		s;
	wxRect		r;
	wxBitmap	BMP;
	wxMemoryDC	dc;

	Set_Buisy_Cursor(true);

	nx		= m_Img_Parms("NX")->asInt();
	ny		= m_Img_Parms("NY")->asInt();
	Frame	= m_Img_Parms("FR")->asInt();	if( Frame < 5 )	Frame	= 0;
	r		= wxRect(0, 0, nx + 2 * Frame, ny + 2 * Frame);

	BMP.Create(r.GetWidth(), r.GetHeight());
	r.Deflate(Frame);
	dc.SelectObject(BMP);
	dc.SetBackground(*wxWHITE_BRUSH);
	dc.Clear();

	Draw_Map(dc, 1.0, r, false);
	Draw_Frame(dc, r, Frame);

	dc.SelectObject(wxNullBitmap);
	BMP.SaveFile(file, (wxBitmapType)type);

	if( m_Img_Parms("REF")->asBool() )
	{
		CSG_File	Stream;
		wxFileName	fn(file);
		fn.SetExt(wxT("world"));

		if( Stream.Open(fn.GetFullPath().c_str(), SG_FILE_W, false) )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -