<commit_before>//
// Name:		Projection2Dlg.cpp
//
// Copyright (c) 2002-2003 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

#ifdef __GNUG__
	#pragma implementation "Projection2Dlg.cpp"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "Projection2Dlg.h"
#include "StatePlaneDlg.h"
#include "vtui/wxString2.h"

//
// Must offset the values we use for Datum because a Choice
// control cannot handle "client data" values less than 0.
//
#define CHOICE_OFFSET 10

// WDR: class implementations

//---------------------------------------------------------------------------
// Projection2Dlg
//---------------------------------------------------------------------------

// WDR: event table for Projection2Dlg

BEGIN_EVENT_TABLE(Projection2Dlg,AutoDialog)
	EVT_CHOICE( ID_PROJ, Projection2Dlg::OnProjChoice )
	EVT_BUTTON( ID_STATEPLANE, Projection2Dlg::OnSetStatePlane )
	EVT_CHOICE( ID_ZONE, Projection2Dlg::OnZone )
	EVT_CHOICE( ID_HORUNITS, Projection2Dlg::OnHorizUnits )
	EVT_LIST_ITEM_RIGHT_CLICK( ID_PROJPARAM, Projection2Dlg::OnItemRightClick )
	EVT_CHOICE( ID_DATUM, Projection2Dlg::OnDatum )
    EVT_CHECKBOX( ID_SHOW_ALL_DATUMS, Projection2Dlg::OnShowAllDatums )
END_EVENT_TABLE()

Projection2Dlg::Projection2Dlg( wxWindow *parent, wxWindowID id, const wxString &title,
	const wxPoint &position, const wxSize& size, long style ) :
	AutoDialog( parent, id, title, position, size, style )
{
	m_bInitializedUI = false;
	m_bShowAllDatums = false;
	ProjectionDialog2Func( this, TRUE ); 
}

void Projection2Dlg::SetProjection(const vtProjection &proj)
{
	m_proj = proj;

	SetUIFromProjection();
}

void Projection2Dlg::OnInitDialog(wxInitDialogEvent& event)
{
	m_pParamCtrl = GetProjparam();
	m_pZoneCtrl = GetZonechoice();
	m_pHorizCtrl = GetHorizchoice();
	m_pDatumCtrl = GetDatumchoice();
	m_pProjCtrl = GetProjchoice();

	AddValidator(ID_PROJ, &m_iProj);
	AddValidator(ID_ZONE, &m_iZone);
	AddValidator(ID_SHOW_ALL_DATUMS, &m_bShowAllDatums);

	m_pProjCtrl->Append(_T("Geographic"));
	m_pProjCtrl->Append(_T("UTM"));
	m_pProjCtrl->Append(_T("Albers Equal Area Conic"));
	m_pProjCtrl->Append(_T("Lambert Conformal Conic"));
	m_pProjCtrl->Append(_T("Transverse Mercator"));
	m_pProjCtrl->Append(_T("Stereographic"));
	m_pProjCtrl->Append(_T("Oblique Stereographic"));
	m_pProjCtrl->Append(_T("Polar Stereographic"));

	// Fill in choices for Datum
	RefreshDatums();

	m_pParamCtrl->ClearAll();
	m_pParamCtrl->InsertColumn(0, _T("Attribute"));
	m_pParamCtrl->SetColumnWidth(0, 130);
	m_pParamCtrl->InsertColumn(1, _T("Value"));
	m_pParamCtrl->SetColumnWidth(1, 85);

	m_bInitializedUI = true;

	SetUIFromProjection();

	wxDialog::OnInitDialog(event);  // calls TransferDataToWindow()
}

void Projection2Dlg::RefreshDatums()
{
	m_pDatumCtrl->Clear();

	int i;
	wxString2 str;
	m_pDatumCtrl->Append(_T("Unknown"), (void *) (-1+CHOICE_OFFSET));
	for (i = 0; i < g_EPSGDatums.GetSize(); i++)
	{
		int code = g_EPSGDatums[i].iCode;
		str = g_EPSGDatums[i].szName;
		if (!m_bShowAllDatums)
		{
			if (!g_EPSGDatums[i].bCommon)
				continue;
		}
		m_pDatumCtrl->Append(str, (void *) (code+CHOICE_OFFSET));
	}
}


// Re-arrange the UI for a given projection
void Projection2Dlg::SetProjectionUI(ProjType type)
{
	m_eProj = type;
	m_iProj = m_eProj;

	if (m_bInitializedUI)
		UpdateControlStatus();
}

void Projection2Dlg::UpdateControlStatus()
{
	int i, pos = 0;
	int real_zone;
	wxString2 str;

	m_pZoneCtrl->Clear();
	switch (m_eProj)
	{
	case PT_GEO:
		m_pParamCtrl->Enable(false);
		m_pZoneCtrl->Enable(false);
		break;
	case PT_UTM:
		m_pParamCtrl->Enable(false);
		m_pZoneCtrl->Enable(true);
		real_zone = m_proj.GetUTMZone();
		for (i = -60; i <= -1; i++)
		{
			str.Printf(_T("Zone %d"), i);
			m_pZoneCtrl->Append(str, (void *) (i+100));
			if (i == real_zone)
				m_iZone = pos;
			pos++;
		}
		for (i = 1; i <= 60; i++)
		{
			str.Printf(_T("Zone %d"), i);
			m_pZoneCtrl->Append(str, (void *) (i+100));
			if (i == real_zone)
				m_iZone = pos;
			pos++;
		}
		break;
	case PT_ALBERS:
	case PT_LAMBERT:
	case PT_TM:
	case PT_STEREO:
	case PT_OS:
	case PT_PS:
		m_pParamCtrl->Enable(true);
		m_pZoneCtrl->Enable(false);
		break;
	}
	m_iDatum = m_proj.GetDatum();
	UpdateDatumStatus();

	// Do horizontal units ("linear units")
	m_pHorizCtrl->Clear();
	if (m_eProj == PT_GEO)
		m_pHorizCtrl->Append(_T("Degrees"), (void *) 0);
	if (m_eProj != PT_GEO)
		m_pHorizCtrl->Append(_T("Meters"), (void *) 1);
	if (m_eProj != PT_GEO && m_eProj != PT_UTM)
	{
		m_pHorizCtrl->Append(_T("Feet (International)"), (void *) 2);
		m_pHorizCtrl->Append(_T("Feet (U.S. Survey)"), (void *) 3);
	}
	// manually transfer value
	for (i = 0; i < m_pHorizCtrl->Number(); i++)
	{
		if ((int) m_pHorizCtrl->GetClientData(i) == m_proj.GetUnits())
			m_pHorizCtrl->SetSelection(i);
	}

	DisplayProjectionSpecificParams();

	TransferDataToWindow();
}

void Projection2Dlg::UpdateDatumStatus()
{
	int i;
	bool bIsCommon = false;
	for (i = 0; i < g_EPSGDatums.GetSize(); i++)
	{
		if (g_EPSGDatums[i].iCode == m_iDatum)
			bIsCommon = g_EPSGDatums[i].bCommon;
	}
	// If we've got a rare datum, but the UI is set to show the short list,
	//  change it to show the full list instead.
	if (!bIsCommon && !m_bShowAllDatums)
	{
		m_bShowAllDatums = true;
		RefreshDatums();
		TransferDataToWindow();
	}
	wxString2 str = DatumToString(m_iDatum);
	m_pDatumCtrl->SetStringSelection(str);
}

void Projection2Dlg::DisplayProjectionSpecificParams()
{
	m_pParamCtrl->DeleteAllItems();

	OGR_SRSNode *root = m_proj.GetRoot();
	OGR_SRSNode *node, *par1, *par2;
	const char *value;
	int children = root->GetChildCount();
	int i, item = 0;

	wxString2 str;
	for (i = 0; i < children; i++)
	{
		node = root->GetChild(i);
		value = node->GetValue();
		if (!strcmp(value, "PARAMETER"))
		{
			par1 = node->GetChild(0);
			value = par1->GetValue();
			str = value;
			item = m_pParamCtrl->InsertItem(item, str);

			par2 = node->GetChild(1);
			value = par2->GetValue();
			str = value;
			m_pParamCtrl->SetItem(item, 1, str);
			item++;
		}
	}<commit_msg>added safety check for bogus CS<commit_after>//
// Name:		Projection2Dlg.cpp
//
// Copyright (c) 2002-2003 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

#ifdef __GNUG__
	#pragma implementation "Projection2Dlg.cpp"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "Projection2Dlg.h"
#include "StatePlaneDlg.h"
#include "vtui/wxString2.h"

//
// Must offset the values we use for Datum because a Choice
// control cannot handle "client data" values less than 0.
//
#define CHOICE_OFFSET 10

// WDR: class implementations

//---------------------------------------------------------------------------
// Projection2Dlg
//---------------------------------------------------------------------------

// WDR: event table for Projection2Dlg

BEGIN_EVENT_TABLE(Projection2Dlg,AutoDialog)
	EVT_CHOICE( ID_PROJ, Projection2Dlg::OnProjChoice )
	EVT_BUTTON( ID_STATEPLANE, Projection2Dlg::OnSetStatePlane )
	EVT_CHOICE( ID_ZONE, Projection2Dlg::OnZone )
	EVT_CHOICE( ID_HORUNITS, Projection2Dlg::OnHorizUnits )
	EVT_LIST_ITEM_RIGHT_CLICK( ID_PROJPARAM, Projection2Dlg::OnItemRightClick )
	EVT_CHOICE( ID_DATUM, Projection2Dlg::OnDatum )
    EVT_CHECKBOX( ID_SHOW_ALL_DATUMS, Projection2Dlg::OnShowAllDatums )
END_EVENT_TABLE()

Projection2Dlg::Projection2Dlg( wxWindow *parent, wxWindowID id, const wxString &title,
	const wxPoint &position, const wxSize& size, long style ) :
	AutoDialog( parent, id, title, position, size, style )
{
	m_bInitializedUI = false;
	m_bShowAllDatums = false;
	ProjectionDialog2Func( this, TRUE ); 
}

void Projection2Dlg::SetProjection(const vtProjection &proj)
{
	m_proj = proj;

	SetUIFromProjection();
}

void Projection2Dlg::OnInitDialog(wxInitDialogEvent& event)
{
	m_pParamCtrl = GetProjparam();
	m_pZoneCtrl = GetZonechoice();
	m_pHorizCtrl = GetHorizchoice();
	m_pDatumCtrl = GetDatumchoice();
	m_pProjCtrl = GetProjchoice();

	AddValidator(ID_PROJ, &m_iProj);
	AddValidator(ID_ZONE, &m_iZone);
	AddValidator(ID_SHOW_ALL_DATUMS, &m_bShowAllDatums);

	m_pProjCtrl->Append(_T("Geographic"));
	m_pProjCtrl->Append(_T("UTM"));
	m_pProjCtrl->Append(_T("Albers Equal Area Conic"));
	m_pProjCtrl->Append(_T("Lambert Conformal Conic"));
	m_pProjCtrl->Append(_T("Transverse Mercator"));
	m_pProjCtrl->Append(_T("Stereographic"));
	m_pProjCtrl->Append(_T("Oblique Stereographic"));
	m_pProjCtrl->Append(_T("Polar Stereographic"));

	// Fill in choices for Datum
	RefreshDatums();

	m_pParamCtrl->ClearAll();
	m_pParamCtrl->InsertColumn(0, _T("Attribute"));
	m_pParamCtrl->SetColumnWidth(0, 130);
	m_pParamCtrl->InsertColumn(1, _T("Value"));
	m_pParamCtrl->SetColumnWidth(1, 85);

	m_bInitializedUI = true;

	SetUIFromProjection();

	wxDialog::OnInitDialog(event);  // calls TransferDataToWindow()
}

void Projection2Dlg::RefreshDatums()
{
	m_pDatumCtrl->Clear();

	int i;
	wxString2 str;
	m_pDatumCtrl->Append(_T("Unknown"), (void *) (-1+CHOICE_OFFSET));
	for (i = 0; i < g_EPSGDatums.GetSize(); i++)
	{
		int code = g_EPSGDatums[i].iCode;
		str = g_EPSGDatums[i].szName;
		if (!m_bShowAllDatums)
		{
			if (!g_EPSGDatums[i].bCommon)
				continue;
		}
		m_pDatumCtrl->Append(str, (void *) (code+CHOICE_OFFSET));
	}
}


// Re-arrange the UI for a given projection
void Projection2Dlg::SetProjectionUI(ProjType type)
{
	m_eProj = type;
	m_iProj = m_eProj;

	if (m_bInitializedUI)
		UpdateControlStatus();
}

void Projection2Dlg::UpdateControlStatus()
{
	int i, pos = 0;
	int real_zone;
	wxString2 str;

	m_pZoneCtrl->Clear();
	switch (m_eProj)
	{
	case PT_GEO:
		m_pParamCtrl->Enable(false);
		m_pZoneCtrl->Enable(false);
		break;
	case PT_UTM:
		m_pParamCtrl->Enable(false);
		m_pZoneCtrl->Enable(true);
		real_zone = m_proj.GetUTMZone();
		for (i = -60; i <= -1; i++)
		{
			str.Printf(_T("Zone %d"), i);
			m_pZoneCtrl->Append(str, (void *) (i+100));
			if (i == real_zone)
				m_iZone = pos;
			pos++;
		}
		for (i = 1; i <= 60; i++)
		{
			str.Printf(_T("Zone %d"), i);
			m_pZoneCtrl->Append(str, (void *) (i+100));
			if (i == real_zone)
				m_iZone = pos;
			pos++;
		}
		break;
	case PT_ALBERS:
	case PT_LAMBERT:
	case PT_TM:
	case PT_STEREO:
	case PT_OS:
	case PT_PS:
		m_pParamCtrl->Enable(true);
		m_pZoneCtrl->Enable(false);
		break;
	}
	m_iDatum = m_proj.GetDatum();
	UpdateDatumStatus();

	// Do horizontal units ("linear units")
	m_pHorizCtrl->Clear();
	if (m_eProj == PT_GEO)
		m_pHorizCtrl->Append(_T("Degrees"), (void *) 0);
	if (m_eProj != PT_GEO)
		m_pHorizCtrl->Append(_T("Meters"), (void *) 1);
	if (m_eProj != PT_GEO && m_eProj != PT_UTM)
	{
		m_pHorizCtrl->Append(_T("Feet (International)"), (void *) 2);
		m_pHorizCtrl->Append(_T("Feet (U.S. Survey)"), (void *) 3);
	}
	// manually transfer value
	for (i = 0; i < m_pHorizCtrl->Number(); i++)
	{
		if ((int) m_pHorizCtrl->GetClientData(i) == m_proj.GetUnits())
			m_pHorizCtrl->SetSelection(i);
	}

	DisplayProjectionSpecificParams();

	TransferDataToWindow();
}

void Projection2Dlg::UpdateDatumStatus()
{
	int i;
	bool bIsCommon = false;
	for (i = 0; i < g_EPSGDatums.GetSize(); i++)
	{
		if (g_EPSGDatums[i].iCode == m_iDatum)
			bIsCommon = g_EPSGDatums[i].bCommon;
	}
	// If we've got a rare datum, but the UI is set to show the short list,
	//  change it to show the full list instead.
	if (!bIsCommon && !m_bShowAllDatums)
	{
		m_bShowAllDatums = true;
		RefreshDatums();
		TransferDataToWindow();
	}
	wxString2 str = DatumToString(m_iDatum);
	m_pDatumCtrl->SetStringSelection(str);
}

void Projection2Dlg::DisplayProjectionSpecificParams()
{
	m_pParamCtrl->DeleteAllItems();

	OGR_SRSNode *root = m_proj.GetRoot();
	if (!root)
	{
		m_pParamCtrl->InsertItem(0, "(Invalid projection)");
		return;		// bogus projection
	}

	OGR_SRSNode *node, *par1, *par2;
	const char *value;
	int children = root->GetChildCount();
	int i, item = 0;

	wxString2 str;
	for (i = 0; i < children; i++)
	{
		node = root->GetChild(i);
		value = node->GetValue();
		if (!strcmp(value, "PARAMETER"))
		{
			par1 = node->GetChild(0);
			value = par1->GetValue();
			str = value;
			item = m_pParamCtrl->InsertItem(item, str);

			par2 = node->GetChild(1);
			value = par2->GetValue();
			str = value;
			m_pParamCtrl->SetItem(item, 1, str);
			item++;
		}
	}
{'fraction_non_alphanumeric': 0.16977358188655092, 'fraction_numerical': 0.012881030482438596, 'mean_word_length': 4.236698785085882, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3386260', 'n_tokens_mistral': 5241, 'n_tokens_neox': 4983, 'n_words': 967}