!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Hier ist wahrscheinlich nicht alles auf dem neuesten Stand, aber für einen Überblick nicht verkehrt.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!





-------------------------------------------------------------------
Adding an object such as grid, tin, shape or table to the SAGA workspace
-------------------------------------------------------------------
- Adding a simple feature object to the workspace

	- function CWKSP_Data_Manager::Add(CSG_Data_Object *pObject)
	  Depending on the object type different functions are called,
	  if a new data type is introduced, a corresponding 'Add'-function
	  in CWKSP_object-type_Manager must be implemented.
	
	- CWKSP_SimpleFeature_Manager
	  I'm not sure  if I should implement this class, or wheter I modify CWKSP_Shape_Manager 
	  

GET_STATION_DATA	
gewurstet in: wksp_data_manager.h, WKSP_Shapes.cpp/h, wksp_shapes_point.cpp/h, wdsp_layer.h

SELECTION OF SHAPES
wksp_shapes_edit.cpp::On_Edit_On_Mouse_Up
shapes_selection.cpp::Select(TSG_Rect Extent, bool bInvert)      
CWKSP_Layer?: m_Def_Color

*************************************************
MODIFIED FILES
*************************************************


	parameters.cpp
	parameter_data.cpp


-----------------------------
table.h
-----------------------------
	friend class CSG_SimpleFeature;



-----------------------------
res_commands.cpp
res_commands.h
-----------------------------
Added code:	
	ID_CMD_SIMPLEFEATURE_GET_STATION was included in res_commands.h/cpp
	!!! NOTE !!!
	In saga_frame.cpp in: BEGIN_EVENT_TABLE(CSAGA_Frame, wxMDIParentFrame)
	EVT_MENU_RANGEs are defined! If a new ID_CMD is added, it must be included in res_commands.cpp
	on the appropriate position.
	

-----------------------------
saga_api.h
-----------------------------	
Added code:
	#include "simplefeature_api.h"

-----------------------------
parameters.h
-----------------------------	
Added code:
	#include "simplefeature_api.h"
	
	PARAMETER_TYPE_SimpleFeature, in: typedef enum ESG_Parameter_Type
	
-----------------------------
dataobject.h
-----------------------------
Definition of a new DATAOBJECT_TYPE
Added code:
	DATAOBJECT_TYPE_SimpleFeature,
	in typedef enum ESG_Data_Object_Type
	
	#define HISTORY_EXT_SIMPLEFEATURE	"hsf"
	

-----------------------------
dataobject.cpp
-----------------------------
Added code:
	Function: const char *	SG_Get_DataObject_Name(TSG_Data_Object_Type Type)
	case DATAOBJECT_TYPE_SimpleFeature: return( LNG("[DAT] SimpleFeature") );
	
	
-----------------------------
shapes.h
-----------------------------
Added code:
	public section:
	CSG_Shapes	(CSG_SimpleFeature &SimpleFeature, TSG_Shape_Type type);
	bool	Create	(const CSG_SimpleFeature &SimpleFeature);
	bool	Assign	(CSG_Data_Object *pObject, bool sf);

	int	Get_Vector_Type();
	
	protected section:
	int	m_Vector_Type;

-----------------------------
shapes.cpp
-----------------------------
Added code:
	#include "simplefeature_api.h"
	
	CSG_Shapes::CSG_Shapes(const CSG_SimpleFeature &SimpleFeature)
		: CSG_Data_Object()
	{
		//_On_Construction();

		//Create(Shapes);
	}
	
	bool CSG_Shapes::Create(const CSG_SimpleFeature &SimpleFeature)
	{
		return( Assign((CSG_Data_Object *)&SimpleFeature) );
	}
	
	int CSG_Shapes::Get_Vector_Type()
	{
		return(m_Vector_Type);
	}


	bool CSG_Shapes::Assign(CSG_Data_Object *pObject, bool sf)
	{
		int		iShape;
		CSG_Shape	*pShape;
		CSG_SimpleFeature *pSimpleFeature;

		//-----------------------------------------------------
		// !!!!!!!!!!!!!!!!!!
		// the following condition is not working with SimpleFeatures
		//if(	pObject && pObject->is_Valid() && pObject->Get_ObjectType() == Get_ObjectType() )
		{
			pSimpleFeature	= (CSG_SimpleFeature *)pObject;

			for(iShape=0; iShape<pSimpleFeature->Get_Count() && SG_UI_Process_Set_Progress(iShape, pSimpleFeature->Get_Count()); iShape++)
			{
				pShape	= Add_Shape();
				pShape->Assign(pSimpleFeature->Get_Shape(iShape));
			}

			SG_UI_Process_Set_Ready();

			_Extent_Update();

			Get_History().Assign(pObject->Get_History());

			return( true );
		}

		return( false );
	}	
	
	void CSG_Shapes::_On_Construction(void)
	{
		m_Type				= SHAPE_TYPE_Undefined;

		m_Shapes			= NULL;
		m_nShapes			= 0;

		m_bUpdate			= true;

		m_Table.m_pOwner	= this;

		//----------stliersch----------
		m_Vector_Type = 0;
		//----------stliersch----------

	}	
	
-----------------------------
wksp_data_manager.cpp (gewurstet)
-----------------------------	
Added code:
	Function: _Get_Manager(int DataType)
	case DATAOBJECT_TYPE_SimpleFeature:
		if( !m_pShapes )
		{
			Add_Item(m_pShapes = new CWKSP_Shapes_Manager);
		}
		return( m_pShapes != NULL );
		
	Function: Add(		
	case DATAOBJECT_TYPE_SimpleFeature:
		return( (CWKSP_Base_Item *)m_pShapes->Add((CSG_SimpleFeature*)pObject) );

	Function: Exists(CSG_Data_Object *pObject, int Type)
	case DATAOBJECT_TYPE_SimpleFeature:
		return( m_pShapes && m_pShapes->Exists((CSG_SimpleFeature *)pObject) );		


-----------------------------			
wksp_shapes_manager.cpp
-----------------------------
Added code:
	New Function:
	CWKSP_Shapes * CWKSP_Shapes_Manager::Add(CSG_SimpleFeature *pSF)
	{
		//if( pSF && pSF->is_Valid() && !Exists(pSF) )
		//{
			return( _Get_Shapes_Type(pSF->Get_Type())->Add(pSF) );
		//}

		return( NULL );
	}


-----------------------------
wksp_shapes_type.cpp
-----------------------------
Added code:
	New Function:
	CWKSP_Shapes * CWKSP_Shapes_Type::Add(CSG_SimpleFeature *pSimpleFeature)
	{
		CWKSP_Shapes	*pItem;

	//	if( pSimpleFeature && pSimpleFeature->Get_Type() == m_Shapes_Type && !Exists(pSimpleFeature) )
	//	{
			switch( pSimpleFeature->Get_Type() )
			{
			default:
				return( false );

			case SHAPE_TYPE_Point:
				pItem	= new CWKSP_Shapes_Point	(pSimpleFeature);
				break;

			case SHAPE_TYPE_Points:
				pItem	= new CWKSP_Shapes_Points	(pSimpleFeature);
				break;

			case SHAPE_TYPE_Line:
				pItem	= new CWKSP_Shapes_Line		(pSimpleFeature);
				break;

			case SHAPE_TYPE_Polygon:
				pItem	= new CWKSP_Shapes_Polygon	(pSimpleFeature);
				break;
			}

			if( Add_Item(pItem) )
			{
				return( pItem );
			}
		//}

		return( NULL );
	}
-----------------------------
wksp_shapes_line.cpp
-----------------------------
Added Code:
	CWKSP_Shapes_Line::CWKSP_Shapes_Line(CSG_SimpleFeature *pSimpleFeature)
		: CWKSP_Shapes(pSimpleFeature)
	{
		Create_Parameters();
	}

-----------------------------
wksp_shapes_line.cpp
-----------------------------
see above

-----------------------------
wksp_layer.cpp
-----------------------------
Added code:	
	case DATAOBJECT_TYPE_SimpleFeature:
		return( ((CSG_SimpleFeature *)m_pObject)->Get_Extent() );


-----------------------------
wksp_shapes.cpp
-----------------------------
Added code:

	Function: wxMenu * CWKSP_Shapes::Get_Menu(void)
	if (m_pShapes->Get_Vector_Type() == 0)
		pMenu	= new wxMenu(m_pShapes->Get_Name());
	else
		pMenu	= new wxMenu("SimpleFeature");

	Function: bool CWKSP_Shapes::On_Command(int Cmd_ID)
	case ID_CMD_SIMPLEFEATURE_GET_STATION:
		Get_Station_Data();
		break;
		
	Function: bool CWKSP_Shapes::On_Command_UI(wxUpdateUIEvent &event)		
	case ID_CMD_SIMPLEFEATURE_GET_STATION:
		event.Enable( (m_pShapes->Get_Type() == SHAPE_TYPE_Points ||
			       m_pShapes->Get_Type() == SHAPE_TYPE_Point) &&
			       m_pShapes->Get_Selection_Count() > 0 );		
			       
			       
-----------------------------
view_map_control.cpp
-----------------------------
MOUSE EVENTS are catched here
	
	
-----------------------------
wksp_shapes_point.h
-----------------------------
Added code:
	New constructor: 	CWKSP_Shapes_Point(CSG_SimpleFeature *pSimpleFeature);

	New function in protected section
	wxMenu*	On_Edit_Get_Menu_SF(wxMenu* pMenu);
	Function definition in 'wksp_simplefeature_point.cpp'

-----------------------------
wksp_shapes_point.cpp
-----------------------------
Added code:
	New constructor:
	CWKSP_Shapes_Point::CWKSP_Shapes_Point(CSG_SimpleFeature *pSimpleFeature)
		: CWKSP_Shapes(pSimpleFeature)
	{
		Create_Parameters();
	}
	
	In order to add entries to the PopupMenu on a Point Feature following function was modified
	
	Function: On_Edit_Get_Menu(void)
	if (m_pShapes->Get_Vector_Type() == 1) // 1 = SimpleFeature
	{
		On_Edit_Get_Menu_SF(pMenu);
	}
	
	NOTE: !!!!!!!!!
	In saga_frame.cpp in: BEGIN_EVENT_TABLE(CSAGA_Frame, wxMDIParentFrame)
	EVT_MENU_RANGEs are defined! If a new ID_CMD is added, it must be included in res_commands.cpp
	on the appropriate position.
	ID_CMD_SIMPLEFEATURE_GET_STATION was included in res_commands.h/cpp
	
	
		
		
		
*************************************************
NEW FILES:
*************************************************

-----------------------------
simplefeature_api.h
-----------------------------
	#ifndef HEADER_INCLUDED__SAGA_API__simplefeature_api_H
	#define HEADER_INCLUDED__SAGA_API__simplefeature_api_H

	#include "shapes.h"

	class SF_GeoAttributes
	{
	public:
		int SRID;
		int GeometryColumn;
		int GeometryDimension;
	};

	class SAGA_API_DLL_EXPORT CSG_SimpleFeature : public CSG_Shapes
	{
	public:
		CSG_SimpleFeature(void);
		CSG_SimpleFeature(const CSG_Shapes &pShapes);
		//CSG_SimpleFeature(const CSG_SimpleFeature &pSimpleFeature);
		CSG_SimpleFeature(CSG_SimpleFeature &pSimpleFeature);


		virtual TSG_Data_Object_Type	Get_ObjectType		(void)	
										const { return(DATAOBJECT_TYPE_SimpleFeature); }

		// override virtual function is_Valid() declared in 'Shapes.h'
		//bool							is_Valid(void)	const		{	return( m_Type != SHAPE_TYPE_Undefined && m_nShapes >= 0 );				}

	private:

		SF_GeoAttributes	geometryAttributes;

	};

	//---------------------------------------------------------
	/** Safe shapes construction */
	SAGA_API_DLL_EXPORT CSG_SimpleFeature*	SG_Create_SimpleFeature(void);

	SAGA_API_DLL_EXPORT CSG_SimpleFeature*	SG_Create_SimpleFeature(const CSG_Shapes &Shapes);

	SAGA_API_DLL_EXPORT CSG_SimpleFeature*	SG_Create_SimpleFeature(const CSG_SimpleFeature &SimpleFeature);

	//---------------------------------------------------------
	#endif // #ifndef HEADER_INCLUDED__SAGA_API__simplefeature_api_H


-----------------------------
simplefeature_api.cpp
-----------------------------
	#include "simplefeature_api.h"

	CSG_SimpleFeature* SG_Create_SimpleFeature()
	{
		return(new CSG_SimpleFeature());
	}

	CSG_SimpleFeature* SG_Create_SimpleFeature(const CSG_Shapes &Shapes)
	{
		return(new CSG_SimpleFeature(Shapes));
	}

	CSG_SimpleFeature* SG_Create_SimpleFeature(const CSG_SimpleFeature &SimpleFeature)
	{
		return(new CSG_SimpleFeature(SimpleFeature));
	}


	CSG_SimpleFeature::CSG_SimpleFeature(void)
	: CSG_Shapes()
	{
	}

	CSG_SimpleFeature::CSG_SimpleFeature(const CSG_Shapes &pShapes)
	: CSG_Shapes(pShapes)
	{
	}

	//CSG_SimpleFeature::CSG_SimpleFeature(const CSG_SimpleFeature &pSimpleFeature)
	CSG_SimpleFeature::CSG_SimpleFeature(CSG_SimpleFeature &pSimpleFeature)
	: CSG_Shapes(pSimpleFeature, pSimpleFeature.Get_Type())
	{
	}




-----------------------------
wksp_simplefeature_point.cpp
-----------------------------
#include "wksp_shapes_point.h"
#include "res_commands.h"

wxMenu * CWKSP_Shapes_Point::On_Edit_Get_Menu_SF(wxMenu *pMenu)
{
	pMenu->AppendSeparator();
	CMD_Menu_Add_Item(pMenu, false, ID_CMD_SIMPLEFEATURE_GET_STATION);

	return(pMenu);
}



-----------------------------
wksp_simplefeature_tools.cpp
-----------------------------

///////////////////////////////////////////////////////////
// Author:			Stefan Liersch
// Contact:			stliersch@freenet.de,
//					stefan.liersch@ufz.de
//
// Date:			2007-05-03
// last modified:	2007-05-03
//
//---------------------------------------------------------
// Mouse Right Click events for SimpleFeatures
//
// FUNCTIONS declared in: 'wksp_shapes.h'
///////////////////////////////////////////////////////////

#include "wx/arrstr.h"

#include "wksp_shapes.h"
//#include "wksp_shapes_point.h"

#include "saga_gui/saga_frame.h"
#include "saga_gui/res_dialogs.h"		// using DLG_Parameters
#include "PGSQL/pgdatabase.h"
#include "PGSQL/sqltable.h"
#include "PGSQL/menu_db.h"
#include "saga_gui/wksp_data_manager.h" // adding items to SAGA Workspace *g_pData

#include "saga_gui/view_base.h"

#include "saga_gui/helper.h"			// using function MSG_General_Add()
#define MSG_ADD(s)	MSG_General_Add(s, true, true);

//---------------------------------------------------------

bool CWKSP_Shapes::Get_Station_Data()
{
	wxString		PK_ColumnName;	// Column name of the SimpleFeature's primary key column
	int				PK_ColumnNumber;// Column number of the SimpleFeature's primary key
	wxArrayString	aPK_Value_str;	// Primary key value as wxString
	wxArrayString	aStationName;	// Name of the corresponding gauging station

	// Get LookUp table name as well as SimpleFeature's primary key column number and name
	wxString LUT_Name = Select_LU_Table(PK_ColumnNumber, PK_ColumnName);
		
	if (LUT_Name != "")
	{
		for (int i = 0; i < m_pShapes->Get_Selection_Count(); i++)
		{
			// Get selected primary key value (representing station id) as wxString
			aPK_Value_str.Add(m_pShapes->Get_Selection(i)->Get_Record()->asString(PK_ColumnNumber));
			// Get station name(s) corresponding to selected station(s)
			aStationName.Add(_Get_Station_TableName(aPK_Value_str[i], LUT_Name, PK_ColumnName));
			// Import Table(s) StationName from database
			_ImportTable(aStationName[i]);
		}
	}

	return(true);
}
//---------------------------------------------------------

wxString CWKSP_Shapes::Select_LU_Table(int &PK_ColumnNumber, wxString &PK_ColumnName)
{
	// returns the name of the corresponding LookUp table
	// as well as the name and column number of the SimpleFeature's primary key column
	//-----------------------------------------------------
	// DIALOG
	//-----------------------------------------------------
	CSG_Parameters	P;

	P.Set_Name(LNG("Select LookUp Table"));

	P.Add_Choice(
		NULL	, "TABLE"	, LNG("Select LookUp Table"),
		"",
		_Get_LU_Tables_Only().c_str()
	);

	P.Add_Choice(
		NULL	, "PK_Col"	, LNG("Select Primary Key Column"),
		"",
		_Get_Column_Names().c_str()
	);

	if( DLG_Parameters(&P) )
	{
		PK_ColumnName	= P("PK_Col")->asString();
		PK_ColumnNumber = P("PK_Col")->asInt();
		return(P("TABLE")->asString());
	} else {
		return("");
	}
}
//---------------------------------------------------------

wxString CWKSP_Shapes::_Get_LU_Tables_Only()
{
	// returns a wxString containing
	// only LookUp table names (names starting with 'lu_')
	wxArrayString All_Tables = g_pSAGA_Frame->db->GetDBTablesArray();
	wxString LU_Tables;

	for (unsigned int i = 0; i < All_Tables.size(); i++)
	{
		if (   All_Tables[i].compare(0,2,"lu_",0,2) == 0
			|| All_Tables[i].compare(0,2,"LU_",0,2) == 0)
		{
			LU_Tables.Append(All_Tables[i]);
			LU_Tables.Append("|");
		}
	}
	return(LU_Tables);
}
//---------------------------------------------------------

wxString CWKSP_Shapes::_Get_Column_Names()
{
	// returns the column names of the current SimpleFeature
	wxString ColNames;
	for (int i = 0; i < m_pShapes->Get_Table().Get_Field_Count(); i++)
	{
		ColNames.Append(m_pShapes->Get_Table().Get_Field_Name(i));
		ColNames.Append("|");
	}
	return(ColNames);
}
//---------------------------------------------------------

wxString CWKSP_Shapes::_Get_Station_TableName(wxString PK_Value_str, wxString LU_TableName, wxString PK_ColumnName)
{
	Csqltable	*sqltable = new Csqltable();
	wxString	StationName = "";
	wxString	sql = "SELECT * FROM ";

	// Create query
	sql.Append(LU_TableName);
	sql.Append(" WHERE ");
	sql.Append(PK_ColumnName);
	sql.Append(" = ");
	sql.Append(PK_Value_str);

	// send query
	if (g_pSAGA_Frame->db->GetSelection(sqltable, sql))
	{
		if (sqltable->Get_nrows() > 0)
			StationName.Append(sqltable->GetValue(1,0).c_str());
	}
	delete sqltable;

	return(StationName);
}
//---------------------------------------------------------

void CWKSP_Shapes::_ImportTable(wxString tablename)
{
	Cmenu_db		menu;
	CSG_Table		*pTable;
	Csqltable		*psqltable;
	psqltable = new Csqltable(tablename.c_str(),
							  g_pSAGA_Frame->db->GetNumberCols(tablename.c_str()),
							  g_pSAGA_Frame->db->GetNumberRows(tablename.c_str()));

	if (g_pSAGA_Frame->db->ReadTable(psqltable))
	{
		MSG_ADD(wxString::Format("%s%s%s", "Read Table '", tablename.c_str(), "' successfull"));
		//-----------------------------------------------------
		// create SAGA Table from database table
		pTable = SG_Create_Table();
		menu.CreateSAGATable(psqltable, pTable);
				
		// add table to SAGA Workspace
		pTable->Set_Name(tablename.c_str());
		g_pData->Add(pTable);

		delete psqltable;

	} else {
		MSG_ADD("Read Table not successfull");
	}
}