//---------------------------------------------------------
bool CWKSP_Project::_Compatibility_Load_Map(CSG_File &Stream, const wxString &ProjectDir)
{
	TSG_Rect		r;
	CSG_String		sLine, sName;
	CWKSP_Base_Item	*pItem;
	CWKSP_Map		*pMap;

	while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRY_BEGIN) && sLine.Cmp(MAP_ENTRIES_END) );

	if( !sLine.Cmp(MAP_ENTRY_BEGIN) && Stream.Read_Line(sLine) )
	{
		if(	SG_SSCANF(sLine, SG_T("%lf %lf %lf %lf"), &r.xMin, &r.xMax, &r.yMin, &r.yMax) == 4 )
		{
			pMap	= NULL;

			while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRY_END) )
			{
				if( !sLine.Cmp(MAP_ENTRY_NAME) )
				{
					Stream.Read_Line(sName);
				}
				else
				{
					sLine	= Get_FilePath_Absolute(ProjectDir, sLine.w_str()).wc_str();

					if(	(pItem = _Get_byFileName(sLine.c_str())) != NULL
					&&	(	pItem->Get_Type()	== WKSP_ITEM_Grid
						||	pItem->Get_Type()	== WKSP_ITEM_Grids
						||	pItem->Get_Type()	== WKSP_ITEM_TIN
						||	pItem->Get_Type()	== WKSP_ITEM_PointCloud
						||	pItem->Get_Type()	== WKSP_ITEM_Shapes) )
					{
						if( pMap == NULL )
						{
							pMap	= new CWKSP_Map;
						}

						g_pMaps->Add((CWKSP_Layer *)pItem, pMap);
					}
				}
			}

			if( pMap )
			{
				if( sName.Length() > 0 )
				{
					pMap->Get_Parameter("NAME")->Set_Value(sName);
					pMap->Parameters_Changed();
				}

				pMap->Set_Extent(r, true);
				pMap->View_Show(true);
			}
		}

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
void CWKSP_Map_Control::On_Drag_Begin(wxTreeEvent &event)
{
	CWKSP_Base_Item	*pItem	= (CWKSP_Base_Item *)GetItemData(event.GetItem());

	if( pItem
	&& (pItem->Get_Type() == WKSP_ITEM_Map_Layer
	 || pItem->Get_Type() == WKSP_ITEM_Map_Graticule
	 || pItem->Get_Type() == WKSP_ITEM_Map_BaseMap) )
	{
		m_draggedItem	= event.GetItem();

		event.Allow();
	}
}
//---------------------------------------------------------
bool CWKSP_Module_Manager::On_Command(int Cmd_ID)
{
	switch( Cmd_ID )
	{
	default:
		return( CWKSP_Base_Manager::On_Command(Cmd_ID) );

	case ID_CMD_MODULES_OPEN:
		Open();
		break;

	case ID_CMD_MODULES_SEARCH:
		{
			CWKSP_Base_Item	*pItem	= g_pModule_Ctrl->Search_Item(_TL("Run Tool"), WKSP_ITEM_Module);

			if( pItem && pItem->GetId().IsOk() && pItem->Get_Type() == WKSP_ITEM_Module )
			{
				((CWKSP_Module *)pItem)->Execute(true);
			}
		}
		break;

	case ID_CMD_MODULES_SAVE_DOCS:
		{
			wxString	Path;

			if( DLG_Directory(Path, _TL("Create Tool Description Files")) )
			{
				MSG_General_Add(wxString::Format(SG_T("%s..."), _TL("Create Tool Description Files")), true, true);

				SG_Get_Module_Library_Manager().Get_Summary(&Path);

				MSG_General_Add(_TL("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS);
			}
		}
		break;
	}

	return( true );
}
//---------------------------------------------------------
bool CWKSP_Project::_Load_Map(CSG_MetaData &Entry, const wxString &ProjectDir)
{
	TSG_Rect	Extent;

	if( !Entry.Cmp_Name("MAP")
	||	!Entry.Get_Child("XMIN") || !Entry.Get_Child("XMIN")->Get_Content().asDouble(Extent.xMin)
	||	!Entry.Get_Child("XMAX") || !Entry.Get_Child("XMAX")->Get_Content().asDouble(Extent.xMax)
	||	!Entry.Get_Child("YMIN") || !Entry.Get_Child("YMIN")->Get_Content().asDouble(Extent.yMin)
	||	!Entry.Get_Child("YMAX") || !Entry.Get_Child("YMAX")->Get_Content().asDouble(Extent.yMax) )
	{
		return( false );
	}

	//-----------------------------------------------------
	CSG_MetaData	*pNode	= Entry.Get_Child("LAYERS");

	if( pNode == NULL || pNode->Get_Children_Count() <= 0 )
	{
		return( false );
	}

	//-----------------------------------------------------
	int		i, n;

	for(i=0, n=0; i<pNode->Get_Children_Count(); i++)
	{
		if( pNode->Get_Child(i)->Cmp_Name("FILE") )
		{
			wxString	FileName(pNode->Get_Child(i)->Get_Content().w_str());

			if( FileName.Find("PGSQL") != 0 )
			{
				FileName	= Get_FilePath_Absolute(ProjectDir, FileName);
			}

			CWKSP_Base_Item	*pItem	= _Get_byFileName(FileName);

			if(	pItem &&
			(   pItem->Get_Type() == WKSP_ITEM_Grid
			||  pItem->Get_Type() == WKSP_ITEM_Grids
			||  pItem->Get_Type() == WKSP_ITEM_TIN
			||  pItem->Get_Type() == WKSP_ITEM_PointCloud
			||  pItem->Get_Type() == WKSP_ITEM_Shapes) )
			{
				n++;
			}
		}
	}

	if( n == 0 )
	{
		return( false );
	}

	//-----------------------------------------------------
	CWKSP_Map	*pMap	= new CWKSP_Map;

	pMap->Get_Parameter("CRS_CHECK")->Set_Value(false);

	for(int i=0; i<pNode->Get_Children_Count(); i++)
	{
		if( pNode->Get_Child(i)->Cmp_Name("FILE") )
		{
			wxString	FileName(pNode->Get_Child(i)->Get_Content().w_str());

			if( FileName.Find("PGSQL") != 0 )
			{
				FileName	= Get_FilePath_Absolute(ProjectDir, FileName);
			}

			CWKSP_Base_Item	*pItem	= _Get_byFileName(FileName);

			if(	pItem &&
			(   pItem->Get_Type() == WKSP_ITEM_Grid
			||  pItem->Get_Type() == WKSP_ITEM_Grids
			||  pItem->Get_Type() == WKSP_ITEM_TIN
			||  pItem->Get_Type() == WKSP_ITEM_PointCloud
			||  pItem->Get_Type() == WKSP_ITEM_Shapes) )
			{
				g_pMaps->Add((CWKSP_Layer *)pItem, pMap);
			}
		}
		else if( pNode->Get_Child(i)->Cmp_Name("PARAMETERS") )
		{
			if( pNode->Get_Child(i)->Cmp_Property("name", "GRATICULE") )
			{
				pMap->Add_Graticule(pNode->Get_Child(i));
			}

			if( pNode->Get_Child(i)->Cmp_Property("name", "BASEMAP") )
			{
				pMap->Add_BaseMap  (pNode->Get_Child(i));
			}
		}
	}

	pMap->Get_Parameter("CRS_CHECK")->Set_Value(true);

	//-----------------------------------------------------
	if( Entry.Get_Child("PARAMETERS") && pMap->Get_Parameters()->Serialize(*Entry.Get_Child("PARAMETERS"), false) )
	{
		pMap->Parameters_Changed();
	}

	pMap->Set_Extent(Extent, true);
	pMap->View_Show(true);

	return( true );
}