// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.Drawing; public partial class Fractals : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Spludlow.WebControls.DisableOnClick(this); if (this.IsPostBack == false) { this.TextBoxDestination.Text = Spludlow.Config.ProgramData; Spludlow.WebControls.AddItems(this.DropDownListPreviewHost, Spludlow.Config.Hosts(), 0); Spludlow.WebControls.SelectItem(this.DropDownListPreviewHost, Environment.MachineName); Spludlow.WebControls.AddItems(this.DropDownListResultHost, Spludlow.Config.Hosts(), 0); Spludlow.WebControls.SelectItem(this.DropDownListResultHost, Environment.MachineName); Spludlow.WebControls.AddItems(this.DropDownListZoom, new string[] { "0.125", "0.25", "0.5", "0.75", "1", "1.125", "1.25", "1.5", "1.75", "2", "3", "4" }, 9); Spludlow.WebControls.AddItems(this.DropDownListPreviewSize, new string[] { "128", "256", "320", "512", "640", "1024", "1280", "2048" }, 4); Spludlow.WebControls.AddItems(this.DropDownListRenderDpi, new string[] { "50", "72", "75", "150", "300", "450", "600", "900", "1200" }, 6); Spludlow.WebControls.AddItems(this.DropDownListPalleteFactor, new string[] { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0", "2", "3", "4", "5", "6", "7", "8", "9", "10", "15", "30", "45", "60", "90" }, 9); Spludlow.WebControls.AddItems(this.DropDownListIterations, new string[] { "2", "4", "8", "16", "32", "64", "128", "256", "512", "1000", "1500", "2000", "2500", "3000", "4000", "5000", "10000", "50000", "100000" }, 8); this.DropDownListPageSize.DataSource = Spludlow.Printing.PageSizes.PageSizeTable; this.DropDownListPageSize.DataValueField = "Name"; this.DropDownListPageSize.DataBind(); for (int index = 0; index < this.DropDownListPageSize.Items.Count; ++index) { ListItem item = this.DropDownListPageSize.Items[index]; if (item.Value == "A4") { this.DropDownListPageSize.SelectedIndex = index; break; } } this.GridViewHosts.DataSource = Spludlow.Drawing.Fractals.QueryHosts().Tables[0]; this.GridViewHosts.DataBind(); foreach (string fractalType in Spludlow.Drawing.Fractals.FractalTypes()) this.DropDownListFractalType.Items.Add(fractalType); this._UpdatePreviewCores(); this._Start(); } } protected void DropDownListFractalType_SelectedIndexChanged(object sender, EventArgs e) { this._Start(); } private void _Start() { Spludlow.Drawing.Fractals.FractalsInfo fractalInfo = new Spludlow.Drawing.Fractals.FractalsInfo(); fractalInfo.FractalType = this.DropDownListFractalType.SelectedValue; fractalInfo.Paramters = Spludlow.Drawing.Fractals.DefaultParameters(fractalInfo.FractalType); fractalInfo.Iterations = 256; fractalInfo.RandomSeed = 0; fractalInfo.PalleteFactor = 1; fractalInfo.Width = 4; int dpi = Int32.Parse(this.DropDownListRenderDpi.Text); this._SetSize(fractalInfo, dpi); this._WriteControls(fractalInfo); this.TextBoxFractalInfo.Text = Spludlow.Reflections.WriteTextFields(fractalInfo); this._Preview(); } private void _Preview() { Spludlow.Drawing.Fractals.FractalsInfo fractalInfo = new Spludlow.Drawing.Fractals.FractalsInfo(); Spludlow.Reflections.ReadTextFields(fractalInfo, this.TextBoxFractalInfo.Text); this._SetSize(fractalInfo, this._PreviewDpi()); string parameter = Spludlow.Reflections.WriteTextFields(fractalInfo); string previewHost = this.DropDownListPreviewHost.SelectedValue; StringBuilder url = new StringBuilder(); url.Append("Generic.aspx?H="); url.Append(previewHost); url.Append("&A=Spludlow&T=Spludlow.Drawing.Fractals&M=RenderHost&MIME=bytes&P="); url.Append(HttpUtility.UrlEncode(parameter)); this.ImageButtonPreview.ImageUrl = url.ToString(); } private int _PreviewDpi() { int thumbSize = Int32.Parse(this.DropDownListPreviewSize.SelectedValue); string pageSize = this.DropDownListPageSize.SelectedValue; bool landscape = this.CheckBoxLandscape.Checked; SizeF sizeMm = Spludlow.Printing.PageSizes.PageSizeMillimeters(pageSize, landscape); float longMm = Math.Max(sizeMm.Width, sizeMm.Height); int previewDpi = (int)((double)thumbSize / ((double)longMm / 25.4)); return previewDpi; } protected void ButtonRefresh_Click(object sender, EventArgs e) { Spludlow.Drawing.Fractals.FractalsInfo fractalInfo = new Spludlow.Drawing.Fractals.FractalsInfo(); Spludlow.Reflections.ReadTextFields(fractalInfo, this.TextBoxFractalInfo.Text); fractalInfo.Paramters = this.TextBoxParameters.Text; fractalInfo.Iterations = Int32.Parse(this.DropDownListIterations.SelectedValue); fractalInfo.PalleteFactor = Double.Parse(this.DropDownListPalleteFactor.SelectedValue); int dpi = Int32.Parse(this.DropDownListRenderDpi.Text); this._SetSize(fractalInfo, dpi); this.TextBoxFractalInfo.Text = Spludlow.Reflections.WriteTextFields(fractalInfo); this._Preview(); } protected void ImageButtonPreview_Click(object sender, ImageClickEventArgs e) { Spludlow.Drawing.Fractals.FractalsInfo fractalInfo = new Spludlow.Drawing.Fractals.FractalsInfo(); Spludlow.Reflections.ReadTextFields(fractalInfo, this.TextBoxFractalInfo.Text); this._SetSize(fractalInfo, this._PreviewDpi()); fractalInfo.X += ((fractalInfo.Width) / fractalInfo.PixelWidth) * (e.X - (fractalInfo.PixelWidth / 2)); fractalInfo.Y += ((fractalInfo.Height) / fractalInfo.PixelHeight) * (e.Y - (fractalInfo.PixelHeight / 2)); double zoom = Double.Parse(this.DropDownListZoom.SelectedValue); fractalInfo.Width /= zoom; fractalInfo.Height /= zoom; int dpi = Int32.Parse(this.DropDownListRenderDpi.Text); this._SetSize(fractalInfo, dpi); this.TextBoxFractalInfo.Text = Spludlow.Reflections.WriteTextFields(fractalInfo); this._Preview(); } protected void ButtonRender_Click(object sender, EventArgs e) { int renderDpi = Int32.Parse(this.DropDownListRenderDpi.SelectedValue); Spludlow.Drawing.Fractals.FractalsInfo fractalInfo = new Spludlow.Drawing.Fractals.FractalsInfo(); Spludlow.Reflections.ReadTextFields(fractalInfo, this.TextBoxFractalInfo.Text); this._SetSize(fractalInfo, renderDpi); // dont need? List hostCores = new List(); foreach (GridViewRow row in this.GridViewHosts.Rows) { string host = (string)this.GridViewHosts.DataKeys[row.RowIndex].Value; TextBox textBoxCores = (TextBox)row.FindControl("TextBoxUseCores"); int cores = Int32.Parse(textBoxCores.Text); if (cores > 0) hostCores.Add(host + "\t" + cores); } if (hostCores.Count == 0) throw new ApplicationException("No host cores"); string resultHost = this.DropDownListResultHost.SelectedValue; string directory = this.TextBoxDestination.Text.Trim(); if (Spludlow.RemoteIO.DirectoryExists(resultHost, directory) == false) throw new ApplicationException("Target Directory not there: " + resultHost + ", " + directory); Spludlow.Drawing.Fractals.Run(resultHost, hostCores.ToArray(), fractalInfo, directory); } private void _SetSize(Spludlow.Drawing.Fractals.FractalsInfo fractalInfo, int dpi) { double originalRatio = (double)fractalInfo.PixelHeight / (double)fractalInfo.PixelWidth; string pageSize = this.DropDownListPageSize.SelectedValue; bool landscape = this.CheckBoxLandscape.Checked; Size sizePixels = Spludlow.Printing.PageSizes.PageSizePixels(pageSize, landscape, dpi); fractalInfo.PixelWidth = sizePixels.Width; fractalInfo.PixelHeight = sizePixels.Height; fractalInfo.Dpi = dpi; double aspectRatio = (double)sizePixels.Height / (double)sizePixels.Width; if (originalRatio < 1 && aspectRatio > 1) fractalInfo.Width = fractalInfo.Height; fractalInfo.Height = fractalInfo.Width * aspectRatio; } protected void ButtonLoad_Click(object sender, EventArgs e) { Spludlow.Drawing.Fractals.FractalsInfo fractalInfo = new Spludlow.Drawing.Fractals.FractalsInfo(); Spludlow.Reflections.ReadTextFields(fractalInfo, this.TextBoxFractalInfo.Text); // need to read page size (calulate from pixels) this._WriteControls(fractalInfo); int dpi = Int32.Parse(this.DropDownListRenderDpi.Text); this._SetSize(fractalInfo, dpi); this.TextBoxFractalInfo.Text = Spludlow.Reflections.WriteTextFields(fractalInfo); this._Preview(); } private void _WriteControls(Spludlow.Drawing.Fractals.FractalsInfo fractalInfo) { this.TextBoxParameters.Text = fractalInfo.Paramters; bool landscape = false; if (fractalInfo.Width > fractalInfo.Height) landscape = true; this.CheckBoxLandscape.Checked = landscape; Spludlow.WebControls.SelectItem(this.DropDownListFractalType, fractalInfo.FractalType); Spludlow.WebControls.SelectItem(this.DropDownListRenderDpi, fractalInfo.Dpi.ToString()); Spludlow.WebControls.SelectItem(this.DropDownListIterations, fractalInfo.Iterations.ToString()); Spludlow.WebControls.SelectItem(this.DropDownListPalleteFactor, fractalInfo.PalleteFactor); this.TextBoxParameters.Text = fractalInfo.Paramters; } protected void DropDownListPreviewHost_SelectedIndexChanged(object sender, EventArgs e) { this._UpdatePreviewCores(); } private void _UpdatePreviewCores() { string previewHost = this.DropDownListPreviewHost.SelectedValue; int cores = (int)Spludlow.Call.Now(previewHost, "System", "System.Environment", "ProcessorCount"); this.TextBoxPreviewCores.Text = cores.ToString(); } }