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

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

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

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#include <wx/colordlg.h>
#include "BuildingDlg.h"
#include "HeightDlg.h"
#include "vtui/Helper.h"

// WDR: class implementations

//----------------------------------------------------------------------------
// BuildingDlg
//----------------------------------------------------------------------------

// Statics
wxColourData BuildingDlg::s_ColorData;


// WDR: event table for BuildingDlg

BEGIN_EVENT_TABLE(BuildingDlg, AutoDialog)
	EVT_INIT_DIALOG (BuildingDlg::OnInitDialog)
	EVT_BUTTON( wxID_OK, BuildingDlg::OnOK )
	EVT_BUTTON( ID_SET_COLOR, BuildingDlg::OnColor1 )
	EVT_LISTBOX( ID_LEVEL, BuildingDlg::OnLevel )
	EVT_LISTBOX( ID_EDGE, BuildingDlg::OnEdge )
	EVT_BUTTON( ID_SET_ROOF_TYPE, BuildingDlg::OnSetRoofType )
	EVT_BUTTON( ID_SET_EDGE_SLOPES, BuildingDlg::OnSetEdgeSlopes )
	EVT_BUTTON( ID_SET_MATERIAL, BuildingDlg::OnSetMaterial )
	EVT_SPINCTRL( ID_STORIES, BuildingDlg::OnSpinStories )
	EVT_TEXT( ID_STORY_HEIGHT, BuildingDlg::OnStoryHeight )
	EVT_BUTTON( ID_LEVEL_COPY, BuildingDlg::OnLevelCopy )
	EVT_BUTTON( ID_LEVEL_UP, BuildingDlg::OnLevelUp )
	EVT_BUTTON( ID_LEVEL_DEL, BuildingDlg::OnLevelDelete )
	EVT_BUTTON( ID_LEVEL_DOWN, BuildingDlg::OnLevelDown )
	EVT_BUTTON( ID_EDGES, BuildingDlg::OnEdges )
	EVT_TEXT( ID_EDGE_SLOPE, BuildingDlg::OnEdgeSlope )
	EVT_BUTTON( ID_FEAT_CLEAR, BuildingDlg::OnFeatClear )
	EVT_BUTTON( ID_FEAT_WALL, BuildingDlg::OnFeatWall )
	EVT_BUTTON( ID_FEAT_WINDOW, BuildingDlg::OnFeatWindow )
	EVT_BUTTON( ID_FEAT_DOOR, BuildingDlg::OnFeatDoor )
	EVT_CLOSE(BuildingDlg::OnCloseWindow)
	EVT_CHAR_HOOK(BuildingDlg::OnCharHook)
	EVT_TEXT_ENTER( ID_FACADE, BuildingDlg::OnFacadeEnter )
	EVT_BUTTON( ID_EDITHEIGHTS, BuildingDlg::OnEditHeights )
	EVT_BUTTON( ID_MODIFY_FACADE, BuildingDlg::OnModifyFacade )
END_EVENT_TABLE()

BuildingDlg::BuildingDlg( wxWindow *parent, wxWindowID id, const wxString &title,
	const wxPoint &position, const wxSize& size, long style ) :
	AutoDialog( parent, id, title, position, size, style )
{
	m_pHeightField = NULL;
	m_bSetting = false;
	m_bEdges = false;

	BuildingDialogFunc( this, TRUE );
	SetupValidators();
}

void BuildingDlg::SetupValidators()
{
	AddValidator(ID_STORIES, &m_iStories);
	AddNumValidator(ID_STORY_HEIGHT, &m_fStoryHeight);

	if (m_bEdges)
	{
		AddValidator(ID_MATERIAL2, &m_strMaterial);
		AddNumValidator(ID_EDGE_SLOPE, &m_iEdgeSlope);
		AddValidator(ID_FEATURES, &m_strFeatures);
		AddValidator(ID_FACADE, &m_strFacade);
	}
	else
	{
		AddValidator(ID_MATERIAL1, &m_strMaterial);
		AddValidator(ID_EDGE_SLOPES, &m_strEdgeSlopes);
	}
}

void BuildingDlg::Setup(vtStructureArray *pSA, vtBuilding *bld, vtHeightField *pHeightField)
{
	m_pSA = pSA;
	m_pBuilding = bld;
	m_pHeightField = pHeightField;
}

void BuildingDlg::EditColor()
{
	s_ColorData.SetChooseFull(true);

	// Set the existing color to the dialog
	RGBi rgb;
	if (m_bEdges)
		rgb = m_pEdge->m_Color;
	else
	{
		if (!m_pLevel->GetOverallEdgeColor(rgb))
			rgb = m_pLevel->GetEdge(0)->m_Color;
	}
	m_Color.Set(rgb.r, rgb.g, rgb.b);
	s_ColorData.SetColour(m_Color);

	EnableRendering(false);
	wxColourDialog dlg(this, &s_ColorData);
	if (dlg.ShowModal() == wxID_OK)
	{
		// Get the color from the dialog
		s_ColorData = dlg.GetColourData();
		m_Color = s_ColorData.GetColour();
		RGBi result(m_Color.Red(), m_Color.Green(), m_Color.Blue());

		// and apply it to the appropriate feature
		if (m_bEdges)
			m_pEdge->m_Color = result;
		else
			m_pLevel->SetEdgeColor(result);

		UpdateColorControl();
	}
	EnableRendering(true);
}

void BuildingDlg::HighlightSelectedLevel()
{
	m_pLevelListBox->SetSelection(m_iLevel);
}

void BuildingDlg::HighlightSelectedEdge()
{
	m_pEdgeListBox->SetSelection(m_iEdge);
}

// WDR: handler implementations for BuildingDlg

void BuildingDlg::OnModifyFacade( wxCommandEvent &event )
{
	wxFileDialog SelectFile(this, _("Choose facade texture"),
							_T(""),
							_T(""),
							_T("Jpeg files (*.jpg)|*.jpg|PNG files(*.png)|*.png|Bitmap files (*.bmp)|*.bmp|All files(*.*)|*.*"),
							wxOPEN);

	if (SelectFile.ShowModal() != wxID_OK)
		return;

	m_strFacade = SelectFile.GetFilename();
	UpdateFacade();
	SetEdgeFacade();
}

void BuildingDlg::OnEditHeights( wxCommandEvent &event )
{
	if (!m_pHeightField)
		return;

	CHeightDialog HeightDialog(this, -1, _("Baseline Editor"));
	HeightDialog.Setup(m_pBuilding, m_pHeightField);
	HeightDialog.ShowModal();
}

void BuildingDlg::OnFacadeEnter( wxCommandEvent &event )
{
	TransferDataFromWindow();
	SetEdgeFacade();
}

void BuildingDlg::OnFeatDoor( wxCommandEvent &event )
{
	vtEdgeFeature f;
	f.m_code = WFC_DOOR;
	f.m_width = -1.0f;
	f.m_vf1 = 0.0f;
	f.m_vf2 = 0.8f;
	m_pEdge->m_Features.push_back(f);
	UpdateFeatures();
	Modified();
}

void BuildingDlg::OnFeatWindow( wxCommandEvent &event )
{<commit_msg>disabled HeightDialog<commit_after>//
// Name: BuildingDlg.cpp
//
// Copyright (c) 2001-2004 Virtual Terrain Project
// Free for all uses, see license.txt for details.
//

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

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

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#include <wx/colordlg.h>
#include "BuildingDlg.h"
//#include "HeightDlg.h"
#include "vtui/Helper.h"

// WDR: class implementations

//----------------------------------------------------------------------------
// BuildingDlg
//----------------------------------------------------------------------------

// Statics
wxColourData BuildingDlg::s_ColorData;


// WDR: event table for BuildingDlg

BEGIN_EVENT_TABLE(BuildingDlg, AutoDialog)
	EVT_INIT_DIALOG (BuildingDlg::OnInitDialog)
	EVT_BUTTON( wxID_OK, BuildingDlg::OnOK )
	EVT_BUTTON( ID_SET_COLOR, BuildingDlg::OnColor1 )
	EVT_LISTBOX( ID_LEVEL, BuildingDlg::OnLevel )
	EVT_LISTBOX( ID_EDGE, BuildingDlg::OnEdge )
	EVT_BUTTON( ID_SET_ROOF_TYPE, BuildingDlg::OnSetRoofType )
	EVT_BUTTON( ID_SET_EDGE_SLOPES, BuildingDlg::OnSetEdgeSlopes )
	EVT_BUTTON( ID_SET_MATERIAL, BuildingDlg::OnSetMaterial )
	EVT_SPINCTRL( ID_STORIES, BuildingDlg::OnSpinStories )
	EVT_TEXT( ID_STORY_HEIGHT, BuildingDlg::OnStoryHeight )
	EVT_BUTTON( ID_LEVEL_COPY, BuildingDlg::OnLevelCopy )
	EVT_BUTTON( ID_LEVEL_UP, BuildingDlg::OnLevelUp )
	EVT_BUTTON( ID_LEVEL_DEL, BuildingDlg::OnLevelDelete )
	EVT_BUTTON( ID_LEVEL_DOWN, BuildingDlg::OnLevelDown )
	EVT_BUTTON( ID_EDGES, BuildingDlg::OnEdges )
	EVT_TEXT( ID_EDGE_SLOPE, BuildingDlg::OnEdgeSlope )
	EVT_BUTTON( ID_FEAT_CLEAR, BuildingDlg::OnFeatClear )
	EVT_BUTTON( ID_FEAT_WALL, BuildingDlg::OnFeatWall )
	EVT_BUTTON( ID_FEAT_WINDOW, BuildingDlg::OnFeatWindow )
	EVT_BUTTON( ID_FEAT_DOOR, BuildingDlg::OnFeatDoor )
	EVT_CLOSE(BuildingDlg::OnCloseWindow)
	EVT_CHAR_HOOK(BuildingDlg::OnCharHook)
	EVT_TEXT_ENTER( ID_FACADE, BuildingDlg::OnFacadeEnter )
	EVT_BUTTON( ID_EDITHEIGHTS, BuildingDlg::OnEditHeights )
	EVT_BUTTON( ID_MODIFY_FACADE, BuildingDlg::OnModifyFacade )
END_EVENT_TABLE()

BuildingDlg::BuildingDlg( wxWindow *parent, wxWindowID id, const wxString &title,
	const wxPoint &position, const wxSize& size, long style ) :
	AutoDialog( parent, id, title, position, size, style )
{
	m_pHeightField = NULL;
	m_bSetting = false;
	m_bEdges = false;

	BuildingDialogFunc( this, TRUE );
	SetupValidators();
}

void BuildingDlg::SetupValidators()
{
	AddValidator(ID_STORIES, &m_iStories);
	AddNumValidator(ID_STORY_HEIGHT, &m_fStoryHeight);

	if (m_bEdges)
	{
		AddValidator(ID_MATERIAL2, &m_strMaterial);
		AddNumValidator(ID_EDGE_SLOPE, &m_iEdgeSlope);
		AddValidator(ID_FEATURES, &m_strFeatures);
		AddValidator(ID_FACADE, &m_strFacade);
	}
	else
	{
		AddValidator(ID_MATERIAL1, &m_strMaterial);
		AddValidator(ID_EDGE_SLOPES, &m_strEdgeSlopes);
	}
}

void BuildingDlg::Setup(vtStructureArray *pSA, vtBuilding *bld, vtHeightField *pHeightField)
{
	m_pSA = pSA;
	m_pBuilding = bld;
	m_pHeightField = pHeightField;
}

void BuildingDlg::EditColor()
{
	s_ColorData.SetChooseFull(true);

	// Set the existing color to the dialog
	RGBi rgb;
	if (m_bEdges)
		rgb = m_pEdge->m_Color;
	else
	{
		if (!m_pLevel->GetOverallEdgeColor(rgb))
			rgb = m_pLevel->GetEdge(0)->m_Color;
	}
	m_Color.Set(rgb.r, rgb.g, rgb.b);
	s_ColorData.SetColour(m_Color);

	EnableRendering(false);
	wxColourDialog dlg(this, &s_ColorData);
	if (dlg.ShowModal() == wxID_OK)
	{
		// Get the color from the dialog
		s_ColorData = dlg.GetColourData();
		m_Color = s_ColorData.GetColour();
		RGBi result(m_Color.Red(), m_Color.Green(), m_Color.Blue());

		// and apply it to the appropriate feature
		if (m_bEdges)
			m_pEdge->m_Color = result;
		else
			m_pLevel->SetEdgeColor(result);

		UpdateColorControl();
	}
	EnableRendering(true);
}

void BuildingDlg::HighlightSelectedLevel()
{
	m_pLevelListBox->SetSelection(m_iLevel);
}

void BuildingDlg::HighlightSelectedEdge()
{
	m_pEdgeListBox->SetSelection(m_iEdge);
}

// WDR: handler implementations for BuildingDlg

void BuildingDlg::OnModifyFacade( wxCommandEvent &event )
{
	wxFileDialog SelectFile(this, _("Choose facade texture"),
							_T(""),
							_T(""),
							_T("Jpeg files (*.jpg)|*.jpg|PNG files(*.png)|*.png|Bitmap files (*.bmp)|*.bmp|All files(*.*)|*.*"),
							wxOPEN);

	if (SelectFile.ShowModal() != wxID_OK)
		return;

	m_strFacade = SelectFile.GetFilename();
	UpdateFacade();
	SetEdgeFacade();
}

void BuildingDlg::OnEditHeights( wxCommandEvent &event )
{
	if (!m_pHeightField)
		return;

	//CHeightDialog HeightDialog(this, -1, _("Baseline Editor"));
	//HeightDialog.Setup(m_pBuilding, m_pHeightField);
	//HeightDialog.ShowModal();
}

void BuildingDlg::OnFacadeEnter( wxCommandEvent &event )
{
	TransferDataFromWindow();
	SetEdgeFacade();
}

void BuildingDlg::OnFeatDoor( wxCommandEvent &event )
{
	vtEdgeFeature f;
	f.m_code = WFC_DOOR;
	f.m_width = -1.0f;
	f.m_vf1 = 0.0f;
	f.m_vf2 = 0.8f;
	m_pEdge->m_Features.push_back(f);
	UpdateFeatures();
	Modified();
}

void BuildingDlg::OnFeatWindow( wxCommandEvent &event )
{
{'fraction_non_alphanumeric': 0.15189624680683828, 'fraction_numerical': 0.0041265474552957355, 'mean_word_length': 4.883815028901734, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3286259', 'n_tokens_mistral': 4032, 'n_tokens_neox': 3944, 'n_words': 675}