Example #1
0
//---------------------------------------------------------
void CTable_Drop::On_Connection_Changed(CSG_Parameters *pParameters)
{
	CSG_Parameter	*pParameter	= pParameters->Get_Parameter("TABLES");

	pParameter->asChoice()->Set_Items(Get_Connection()->Get_Tables());
	pParameter->Set_Value(pParameter->asString());
}
Example #2
0
//---------------------------------------------------------
bool CWKSP_Project::_Compatibility_Data(TSG_Data_Type Type, CSG_Parameters *pParameters, const CSG_String &Version)
{
	if( !pParameters )
	{
		return( false );
	}

	if( !Version.Cmp(SAGA_VERSION) )
	{
		return( true );
	}

	//-----------------------------------------------------
	if( Version.is_Empty() )
	{
		CSG_Parameter	*pParameter;

		if( Type == SG_DATAOBJECT_TYPE_Grid )
		{
			if( (pParameter = pParameters->Get_Parameter("COLORS_TYPE")) != NULL )
			{
				if( pParameter->asInt() == 3 )
				{	// 0:Single >> 1:LUT >> 2:Discrete >> 3:Graduated >> 4:RGB Overlay >> 5:RGB Composite >> 6:Shade
					pParameter->Set_Value(5);	// RGB moved to position 5
				}
			}
		}
	}

	return( true );
}
//---------------------------------------------------------
void CParameters_Control::_Set_Parameter(const wxString &Identifier)
{
	wxPGProperty	*pProperty	= m_pPG->GetProperty(Identifier);

	if( pProperty )
	{
		CSG_Parameter	*pParameter	= m_pParameters->Get_Parameter(
			!pProperty->IsSubProperty() ? Identifier.wx_str() : Identifier.AfterLast(wxT('.')).wx_str()
		);

		if( pParameter )
		{
			switch( pParameter->Get_Type() )
			{
			default:
				break;

			case PARAMETER_TYPE_String:
			case PARAMETER_TYPE_FilePath:
				pParameter->Set_Value(m_pPG->GetPropertyValueAsString(pProperty).wx_str());
				break;

			case PARAMETER_TYPE_Bool:
				pParameter->Set_Value(m_pPG->GetPropertyValueAsBool		(pProperty));
				break;

			case PARAMETER_TYPE_Int:
				pParameter->Set_Value(m_pPG->GetPropertyValueAsInt		(pProperty));
				break;

			case PARAMETER_TYPE_Double:
				pParameter->Set_Value(m_pPG->GetPropertyValueAsDouble	(pProperty));
				break;

			case PARAMETER_TYPE_Color:
				pParameter->Set_Value(Get_Color_asInt(((wxColourProperty *)pProperty)->GetVal().m_colour));
				break;
			}

			m_bModified	= true;

			_Update_Parameters();
		}
	}
}
Example #4
0
//---------------------------------------------------------
bool		DLG_Table_Fields(const wxString &Caption, CSG_Parameter_Table_Fields *pFields)
{
	CSG_Table	*pTable	= pFields->Get_Table();

	if( pTable )
	{
		int				i;
		CSG_Parameters	P;

		for(i=0; i<pTable->Get_Field_Count(); i++)
		{
			P.Add_Value(NULL, SG_Get_String(i), pTable->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false);
		}

		for(i=0; i<pFields->Get_Count(); i++)
		{
			CSG_Parameter	*pParameter	= P(pFields->Get_Index(i));

			if( pParameter )
			{
				pParameter->Set_Value(true);
			}
		}

		if( DLG_Parameters(&P) )
		{
			CSG_String	s;

			for(i=0; i<pTable->Get_Field_Count(); i++)
			{
				if( P(i)->asBool() )
				{
					s	+= CSG_String::Format(s.Length() ? SG_T(",%d") : SG_T("%d"), i);
				}
			}

			pFields->Set_Value(s);

			return( true );
		}
	}

	return( false );
}
Example #5
0
//---------------------------------------------------------
bool CCMD_Module::_Get_Parameters(CSG_Parameters *pParameters)
{
    if( !pParameters || m_CMD.Parse(false) != 0 )
    {
        return( false );
    }

    //-----------------------------------------------------
    int		i;

    for(i=0; i<pParameters->Get_Count(); i++)
    {
        CSG_Parameter	*pParameter	= pParameters->Get_Parameter(i);

        if( pParameter->is_Input() )
        {
            // nop now, loading options first
        }

        else if( pParameter->is_Output() )
        {
            if( pParameter->is_DataObject() && pParameter->is_Optional() && !pParameter->asDataObject() && m_CMD.Found(_Get_ID(pParameter)) )
            {
                pParameter->Set_Value(DATAOBJECT_CREATE);
            }
        }

        else if( pParameter->is_Option() && !pParameter->is_Information() )
        {
            long		l;
            double		d;
            wxString	s;

            switch( pParameter->Get_Type() )
            {
            default:
                break;

            case PARAMETER_TYPE_Parameters:
                _Get_Parameters(pParameter->asParameters());
                break;

            case PARAMETER_TYPE_Bool:
                pParameter->Set_Value(m_CMD.Found(_Get_ID(pParameter)) ? 1 : 0);
                break;

            case PARAMETER_TYPE_Int:
                if( m_CMD.Found(_Get_ID(pParameter), &l) )
                {
                    pParameter->Set_Value((int)l);
                }
                break;

            case PARAMETER_TYPE_Choice:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    if( s.ToLong(&l) )
                    {
                        pParameter->Set_Value((int)l);
                    }
                    else
                    {
                        pParameter->Set_Value(CSG_String(&s));
                    }
                }
                break;

            case PARAMETER_TYPE_Double:
            case PARAMETER_TYPE_Degree:
                if( m_CMD.Found(_Get_ID(pParameter), &s) && s.ToDouble(&d) )
                {
                    pParameter->Set_Value(d);
                }
                break;

            case PARAMETER_TYPE_Range:
                if( m_CMD.Found(_Get_ID(pParameter, wxT("MIN")), &s) && s.ToDouble(&d) )
                {
                    pParameter->asRange()->Set_LoVal(d);
                }

                if( m_CMD.Found(_Get_ID(pParameter, wxT("MAX")), &s) && s.ToDouble(&d) )
                {
                    pParameter->asRange()->Set_HiVal(d);
                }
                break;

            case PARAMETER_TYPE_String:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    pParameter->Set_Value(CSG_String(&s));
                }
                break;

            case PARAMETER_TYPE_Text:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    CSG_File	Stream;

                    if( Stream.Open(CSG_String(&s)) )
                    {
                        CSG_String	t;

                        Stream.Read(t, Stream.Length());

                        pParameter->Set_Value(t.c_str());
                    }
                    else
                    {
                        pParameter->Set_Value(CSG_String(&s));
                    }
                }
                break;

            case PARAMETER_TYPE_FilePath:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    if( pParameter->asFilePath()->is_Multiple() )
                    {
                        s.Prepend(wxT("\""));
                        s.Replace(wxT(";"), wxT("\" \""));
                        s.Append (wxT("\""));
                    }

                    pParameter->Set_Value(CSG_String(&s));
                }
                break;

            case PARAMETER_TYPE_FixedTable:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    CSG_Table	Table(&s);
                    pParameter->asTable()->Assign_Values(&Table);
                }
                break;

            case PARAMETER_TYPE_Grid_System:
                if( pParameter->Get_Children_Count() == 0 )
                {
                    long	nx, ny;
                    double	d, x, y;

                    if(	!m_CMD.Found(_Get_ID(pParameter, wxT("NX")), &nx)
                            ||	!m_CMD.Found(_Get_ID(pParameter, wxT("NY")), &ny)
                            ||	!m_CMD.Found(_Get_ID(pParameter, wxT( "X")), &s) || !s.ToDouble(&x)
                            ||	!m_CMD.Found(_Get_ID(pParameter, wxT( "Y")), &s) || !s.ToDouble(&y)
                            ||	!m_CMD.Found(_Get_ID(pParameter, wxT( "D")), &s) || !s.ToDouble(&d) )
                    {
                        pParameter->asGrid_System()->Assign(-1, 0.0, 0.0, 0, 0);
                    }
                    else
                    {
                        pParameter->asGrid_System()->Assign(d, x, y, (int)nx, (int)ny);
                    }
                }
                break;
            }
        }
    }

    m_pModule->Update_Parameter_States();

    //-----------------------------------------------------
    for(i=0; i<pParameters->Get_Count(); i++)
    {
        CSG_Parameter	*pParameter	= pParameters->Get_Parameter(i);

        if( pParameter->is_Input() )
        {
            if( !_Load_Input(pParameters->Get_Parameter(i)) )
            {
                CMD_Print_Error(pParameters->Get_Parameter(i)->Get_Name());

                return( false );
            }
        }

        else if( pParameter->is_Option() && !pParameter->is_Information() )
        {
            long		l;
            wxString	s;

            switch( pParameter->Get_Type() )
            {
            case PARAMETER_TYPE_Table_Field:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    if( s.ToLong(&l) )
                    {
                        pParameter->Set_Value((int)l);
                    }
                    else
                    {
                        pParameter->Set_Value(CSG_String(&s));
                    }
                }
                break;

            case PARAMETER_TYPE_Table_Fields:
                if( m_CMD.Found(_Get_ID(pParameter), &s) )
                {
                    pParameter->Set_Value(CSG_String(&s));
                }
                break;
            }
        }
    }

    //-----------------------------------------------------
    return( true );
}
//---------------------------------------------------------
bool CWMS_Import::Get_Map(wxHTTP *pServer, const CSG_String &Directory, CWMS_Capabilities &Cap)
{
	bool	bResult	= false;

	int				i, n;
	CSG_Rect		r(Cap.m_Extent);
	CSG_Parameters	p;

	//-----------------------------------------------------
//	if( Cap.m_MaxWidth  > 2 && NX > Cap.m_MaxWidth  )	NX	= Cap.m_MaxWidth;
//	if( Cap.m_MaxHeight > 2 && NY > Cap.m_MaxHeight )	NY	= Cap.m_MaxHeight;

	p.Add_Range	(NULL	, "X_RANGE"	, _TL("X Range")	, _TL(""), r.Get_XMin(), r.Get_XMax(), r.Get_XMin(), r.Get_XRange() > 0.0, r.Get_XMax(), r.Get_XRange() > 0.0);
	p.Add_Range	(NULL	, "Y_RANGE"	, _TL("Y Range")	, _TL(""), r.Get_YMin(), r.Get_YMax(), r.Get_YMin(), r.Get_YRange() > 0.0, r.Get_YMax(), r.Get_YRange() > 0.0);

	p.Add_Value	(NULL	, "CELLSIZE", _TL("Cellsize")	, _TL(""), PARAMETER_TYPE_Double, r.Get_XRange() / 2001.0, 0.0, true);

	p.Add_Choice(NULL	, "FORMAT"	, _TL("Format")		, _TL(""), Cap.m_Formats);
	p.Add_Choice(NULL	, "PROJ"	, _TL("Projections"), _TL(""), Cap.m_Projections);

	CSG_Parameter	*pNode	= p("FORMAT");
	for(i=0; i<pNode->asChoice()->Get_Count(); i++)
	{
		CSG_String	s(pNode->asChoice()->Get_Item(i));
		if( !s.CmpNoCase(SG_T("image/png")) )
			pNode->Set_Value(i);
	}

	for(i=0; i<Cap.m_Layers_Name.Get_Count(); i++)
	{
		p.Add_Value(NULL, Cap.m_Layers_Name[i], Cap.m_Layers_Title[i], "", PARAMETER_TYPE_Bool, false);
	}

	//-----------------------------------------------------
	if( pServer && Dlg_Parameters(&p, _TL("WMS Import")) )
	{
		int			NX, NY;
		double		Cellsize;
		CSG_String	Layers, Format;

		//-------------------------------------------------
		r.Assign(
			p("X_RANGE")->asRange()->Get_LoVal(),
			p("Y_RANGE")->asRange()->Get_LoVal(),
			p("X_RANGE")->asRange()->Get_HiVal(),
			p("Y_RANGE")->asRange()->Get_HiVal()
		);

		Cellsize	= p("CELLSIZE")	->asDouble();

		NX			= 1 + (int)(r.Get_XRange() / Cellsize);
		NY			= 1 + (int)(r.Get_YRange() / Cellsize);

		//-------------------------------------------------
		Layers.Clear();

		for(i=0, n=0; i<Cap.m_Layers_Name.Get_Count(); i++)
		{
			if( p(Cap.m_Layers_Name[i])->asBool() )
			{
				if( n++ > 0 )	Layers	+= ",";

				Layers	+= Cap.m_Layers_Name[i];
			}
		}

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

		//-------------------------------------------------
		wxBitmapType	tFormat;

		Format	= p("FORMAT")->asString();

		if(      Format.Contains(SG_T("image/gif" )) )	tFormat	= wxBITMAP_TYPE_GIF ;
		else if( Format.Contains(SG_T("image/jpeg")) )	tFormat	= wxBITMAP_TYPE_JPEG;
		else if( Format.Contains(SG_T("image/png" )) )	tFormat	= wxBITMAP_TYPE_PNG ;
		else if( Format.Contains(SG_T("image/wbmp")) )	tFormat	= wxBITMAP_TYPE_BMP ;
		else if( Format.Contains(SG_T("image/bmp" )) )	tFormat	= wxBITMAP_TYPE_BMP ;
		else if( Format.Contains(SG_T("image/tiff")) )	tFormat	= wxBITMAP_TYPE_TIF ;
		else if( Format.Contains(SG_T("GIF"       )) )	tFormat	= wxBITMAP_TYPE_GIF ;
		else if( Format.Contains(SG_T("JPEG"      )) )	tFormat	= wxBITMAP_TYPE_JPEG;
		else if( Format.Contains(SG_T("PNG"       )) )	tFormat	= wxBITMAP_TYPE_PNG ;
		else
		{
			return( false );
		}

		//-------------------------------------------------
		CSG_String	sRequest(Directory);

		sRequest	+= SG_T("?SERVICE=WMS");
		sRequest	+= SG_T("&VERSION=")	+ Cap.m_Version;
		sRequest	+= SG_T("&REQUEST=GetMap");

		sRequest	+= SG_T("&LAYERS=")		+ Layers;

		if( Cap.m_Projections.Length() > 0 )
			sRequest	+= CSG_String(S_SRS(Cap.m_Version)) + p("PROJ")->asString();

		sRequest	+= SG_T("&FORMAT=")		+ Format;

		sRequest	+= CSG_String::Format(SG_T("&WIDTH=%d&HEIGHT=%d"), NX, NY);
		sRequest	+= CSG_String::Format(SG_T("&BBOX=%f,%f,%f,%f"), r.m_rect.xMin, r.m_rect.yMin, r.m_rect.xMax, r.m_rect.yMax);

		Message_Add(sRequest, true);

		//-------------------------------------------------
		wxInputStream	*pStream;

		if( (pStream = pServer->GetInputStream(sRequest.c_str())) == NULL )
		{
			Message_Add(_TL("could not open GetMap stream"));
		}
		else
		{
			wxImage	Image;

			if( Image.LoadFile(*pStream, tFormat) == false )
			{
				Message_Add(_TL("could not read image"));

				CSG_String	s	= SG_T("\n");

				pStream->SeekI(0, wxFromStart);

				while( !pStream->Eof() )
				{
					s	+= (char)pStream->GetC();
				}

				Message_Add(s);
			}
			else
			{
				CSG_Grid	*pGrid	= SG_Create_Grid(SG_DATATYPE_Int, Image.GetWidth(), Image.GetHeight(), Cellsize, r.m_rect.xMin, r.m_rect.yMin);

				for(int y=0, yy=pGrid->Get_NY()-1; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, yy--)
				{
					for(int x=0; x<pGrid->Get_NX(); x++)
					{
						pGrid->Set_Value(x, y, SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy)));
					}
				}

				//-----------------------------------------
				pGrid->Set_Name(Cap.m_Title);
				Parameters("MAP")->Set_Value(pGrid);
				DataObject_Set_Colors(pGrid, 100, SG_COLORS_BLACK_WHITE);

				CSG_Parameters	Parms;

				if( DataObject_Get_Parameters(pGrid, Parms) && Parms("COLORS_TYPE") )
				{
					Parms("COLORS_TYPE")->Set_Value(3);	// Color Classification Type: RGB

					DataObject_Set_Parameters(pGrid, Parms);
				}

				bResult	= true;
			}

			delete(pStream);
		}
	}

	return( bResult );
}
Example #7
0
//---------------------------------------------------------
bool CWKSP_Project::_Load_Data(CSG_MetaData &Entry, const wxString &ProjectDir, bool bLoad, const CSG_String &Version)
{
	if( !Entry.Cmp_Name("DATASET") || !Entry("FILE") || Entry["FILE"].Get_Content().is_Empty() )
	{
		return( false );
	}

	TSG_Data_Object_Type	Type	=
		Entry.Cmp_Property("type", "GRID"  ) ? SG_DATAOBJECT_TYPE_Grid
	:	Entry.Cmp_Property("type", "GRIDS" ) ? SG_DATAOBJECT_TYPE_Grids
	:	Entry.Cmp_Property("type", "TABLE" ) ? SG_DATAOBJECT_TYPE_Table
	:	Entry.Cmp_Property("type", "SHAPES") ? SG_DATAOBJECT_TYPE_Shapes
	:	Entry.Cmp_Property("type", "TIN"   ) ? SG_DATAOBJECT_TYPE_TIN
	:	Entry.Cmp_Property("type", "POINTS") ? SG_DATAOBJECT_TYPE_PointCloud
	:	SG_DATAOBJECT_TYPE_Undefined;

	if( Type == SG_DATAOBJECT_TYPE_Undefined )
	{
		return( false );
	}

	//-----------------------------------------------------
	wxString	File	= Entry("FILE")->Get_Content().c_str();

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

	//-----------------------------------------------------
	CWKSP_Base_Item	*pItem	= NULL;

	if( bLoad )
	{
		if( Type == SG_DATAOBJECT_TYPE_Grid && Entry("PARAMETERS"))
		{
			for(int i=0; i<Entry["PARAMETERS"].Get_Children_Count() && !pItem; i++)
			{
				if( Entry["PARAMETERS"][i].Cmp_Property("id", "FILE_CACHE") )
				{
					bool	bCached	= Entry["PARAMETERS"][i].Cmp_Content("TRUE", true);

					pItem	= g_pData->Add(SG_Create_Grid(&File, SG_DATATYPE_Undefined, bCached));
				}
			}
		}
	}

	if( !pItem )
	{
		pItem	= bLoad ? g_pData->Open(File, Type) : _Get_byFileName(File);
	}

	//-----------------------------------------------------
	if( !pItem || !pItem->Get_Parameters() || !Entry.Get_Child("PARAMETERS") )
	{
		if( bLoad )
		{
			MSG_Error_Add(wxString::Format("%s [%s]", _TL("failed to load data"), File.c_str()));
		}

		return( false );
	}

	//-----------------------------------------------------
	CSG_MetaData	*pEntry	= Entry("PARAMETERS");

	for(int i=0; i<pEntry->Get_Children_Count(); i++)
	{
		if( !pEntry->Get_Child(i)->Get_Name().CmpNoCase("DATA") && !pEntry->Get_Child(i)->Get_Content().is_Empty() && pEntry->Get_Child(i)->Get_Content().BeforeFirst(':').CmpNoCase("PGSQL") )
		{
			wxString	File(Get_FilePath_Absolute(ProjectDir, pEntry->Get_Child(i)->Get_Content().w_str()));

			pEntry->Get_Child(i)->Set_Content(&File);

		//	if( SG_Compare_SAGA_Version(Version) < 0 )
			{
				if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_1") )
				{
					pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_G");
				}

				if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_2") )
				{
					pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_B");
				}
			}
		}
	}

	pItem->Get_Parameters()->Serialize(*Entry.Get_Child("PARAMETERS"), false);

	//-----------------------------------------------------
	if( SG_Compare_Version(Version, "7.0.0") < 0 )	// inter-version-compatibility
	{
		CSG_Parameter	*pParameter	= pItem->Get_Parameter("COLORS_TYPE");

		if( pParameter && Type == SG_DATAOBJECT_TYPE_Grid )
		{
			if( pParameter->asInt() == 4 ) { pParameter->Set_Value(6); }	// Shade
			if( pParameter->asInt() == 5 ) { pParameter->Set_Value(4); }	// RGB Overlay
			if( pParameter->asInt() == 6 ) { pParameter->Set_Value(5); }	// RGB Composite
		}
	}

	//-----------------------------------------------------
	if( Type == SG_DATAOBJECT_TYPE_Grid )
	{
		pItem->Get_Parameter("FILE_CACHE")->Set_Value(((CWKSP_Grid *)pItem)->Get_Grid()->is_Cached());
	}

	pItem->Parameters_Changed();

	return( true );
}