diff --git a/OpenNest/Controls/DrawingListBox.cs b/OpenNest/Controls/DrawingListBox.cs index 916ed00..027958e 100644 --- a/OpenNest/Controls/DrawingListBox.cs +++ b/OpenNest/Controls/DrawingListBox.cs @@ -28,6 +28,8 @@ namespace OpenNest.Controls public bool HideDepletedParts { get; set; } + public bool HideQuantity { get; set; } + protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index >= Items.Count || e.Index <= -1) @@ -38,8 +40,15 @@ namespace OpenNest.Controls if (dwg == null) return; - var isComplete = dwg.Quantity.Nested > 0 && dwg.Quantity.Remaining == 0; - var bgBrush = isComplete ? SystemBrushes.Info : Brushes.White; + var isSelected = (e.State & DrawItemState.Selected) != 0; + Brush bgBrush; + + if (isSelected) + bgBrush = SystemBrushes.Highlight; + else if (!HideQuantity && dwg.Quantity.Nested > 0 && dwg.Quantity.Remaining == 0) + bgBrush = SystemBrushes.Info; + else + bgBrush = Brushes.White; e.Graphics.FillRectangle(bgBrush, e.Bounds); @@ -57,19 +66,32 @@ namespace OpenNest.Controls pt.X += imageSize.Width + 10; - e.Graphics.DrawString(dwg.Name, nameFont, Brushes.Black, pt); + var textBrush = isSelected ? SystemBrushes.HighlightText : Brushes.Black; + var detailBrush = isSelected ? SystemBrushes.HighlightText : Brushes.Gray; + + e.Graphics.DrawString(dwg.Name, nameFont, textBrush, pt); var bounds = dwg.Program.BoundingBox(); - var text1 = string.Format("{0} of {1} nested", dwg.Quantity.Nested, dwg.Quantity.Required); var text2 = bounds.Size.ToString(4); var text3 = string.Format("{0} sq/{1}", System.Math.Round(dwg.Area, 4), UnitsHelper.GetShortString(Units)); - pt.Y += 22; - e.Graphics.DrawString(text1, Font, Brushes.Gray, pt); - pt.Y += 18; - e.Graphics.DrawString(text2, Font, Brushes.Gray, pt); - pt.Y += 18; - e.Graphics.DrawString(text3, Font, Brushes.Gray, pt); + if (HideQuantity) + { + pt.Y += 22; + e.Graphics.DrawString(text2, Font, detailBrush, pt); + pt.Y += 18; + e.Graphics.DrawString(text3, Font, detailBrush, pt); + } + else + { + var text1 = string.Format("{0} of {1} nested", dwg.Quantity.Nested, dwg.Quantity.Required); + pt.Y += 22; + e.Graphics.DrawString(text1, Font, detailBrush, pt); + pt.Y += 18; + e.Graphics.DrawString(text2, Font, detailBrush, pt); + pt.Y += 18; + e.Graphics.DrawString(text3, Font, detailBrush, pt); + } } protected override void OnMouseMove(MouseEventArgs e) diff --git a/OpenNest/Forms/BestFitViewerForm.Designer.cs b/OpenNest/Forms/BestFitViewerForm.Designer.cs index ed23f65..5e78b8f 100644 --- a/OpenNest/Forms/BestFitViewerForm.Designer.cs +++ b/OpenNest/Forms/BestFitViewerForm.Designer.cs @@ -13,134 +13,157 @@ namespace OpenNest.Forms private void InitializeComponent() { - this.gridPanel = new System.Windows.Forms.TableLayoutPanel(); - this.toolbarPanel = new System.Windows.Forms.Panel(); - this.lblDrawing = new System.Windows.Forms.Label(); - this.cboDrawing = new System.Windows.Forms.ComboBox(); - this.navPanel = new System.Windows.Forms.Panel(); - this.btnPrev = new System.Windows.Forms.Button(); - this.btnNext = new System.Windows.Forms.Button(); - this.txtPage = new System.Windows.Forms.TextBox(); - this.lblPageCount = new System.Windows.Forms.Label(); - this.toolbarPanel.SuspendLayout(); - this.navPanel.SuspendLayout(); - this.SuspendLayout(); - // + splitContainer = new System.Windows.Forms.SplitContainer(); + drawingListBox = new OpenNest.Controls.DrawingListBox(); + gridPanel = new System.Windows.Forms.TableLayoutPanel(); + navPanel = new System.Windows.Forms.Panel(); + btnPrev = new System.Windows.Forms.Button(); + txtPage = new System.Windows.Forms.TextBox(); + lblPageCount = new System.Windows.Forms.Label(); + btnNext = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit(); + splitContainer.Panel1.SuspendLayout(); + splitContainer.Panel2.SuspendLayout(); + splitContainer.SuspendLayout(); + navPanel.SuspendLayout(); + SuspendLayout(); + // + // splitContainer + // + splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; + splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + splitContainer.Location = new System.Drawing.Point(0, 0); + splitContainer.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + splitContainer.Name = "splitContainer"; + // + // splitContainer.Panel1 + // + splitContainer.Panel1.Controls.Add(drawingListBox); + splitContainer.Panel1MinSize = 180; + // + // splitContainer.Panel2 + // + splitContainer.Panel2.Controls.Add(gridPanel); + splitContainer.Panel2.Controls.Add(navPanel); + splitContainer.Size = new System.Drawing.Size(792, 486); + splitContainer.SplitterDistance = 280; + splitContainer.SplitterWidth = 6; + splitContainer.TabIndex = 0; + // + // drawingListBox + // + drawingListBox.BorderStyle = System.Windows.Forms.BorderStyle.None; + drawingListBox.Dock = System.Windows.Forms.DockStyle.Fill; + drawingListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + drawingListBox.FormattingEnabled = true; + drawingListBox.HideDepletedParts = false; + drawingListBox.ItemHeight = 85; + drawingListBox.Location = new System.Drawing.Point(0, 0); + drawingListBox.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + drawingListBox.Name = "drawingListBox"; + drawingListBox.Size = new System.Drawing.Size(280, 486); + drawingListBox.TabIndex = 0; + drawingListBox.Units = Units.Inches; + // // gridPanel - // - this.gridPanel.ColumnCount = 5; - this.gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.gridPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.gridPanel.Location = new System.Drawing.Point(0, 32); - this.gridPanel.Name = "gridPanel"; - this.gridPanel.RowCount = 3; - this.gridPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33F)); - this.gridPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.34F)); - this.gridPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33F)); - this.gridPanel.Size = new System.Drawing.Size(1200, 732); - this.gridPanel.TabIndex = 0; - // - // toolbarPanel - // - this.toolbarPanel.Controls.Add(this.lblDrawing); - this.toolbarPanel.Controls.Add(this.cboDrawing); - this.toolbarPanel.Dock = System.Windows.Forms.DockStyle.Top; - this.toolbarPanel.Location = new System.Drawing.Point(0, 0); - this.toolbarPanel.Name = "toolbarPanel"; - this.toolbarPanel.Size = new System.Drawing.Size(1200, 32); - this.toolbarPanel.TabIndex = 2; - // - // lblDrawing - // - this.lblDrawing.Location = new System.Drawing.Point(6, 0); - this.lblDrawing.Name = "lblDrawing"; - this.lblDrawing.Size = new System.Drawing.Size(55, 32); - this.lblDrawing.TabIndex = 0; - this.lblDrawing.Text = "Drawing:"; - this.lblDrawing.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // cboDrawing - // - this.cboDrawing.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cboDrawing.Location = new System.Drawing.Point(64, 5); - this.cboDrawing.Name = "cboDrawing"; - this.cboDrawing.Size = new System.Drawing.Size(250, 21); - this.cboDrawing.TabIndex = 1; - // + // + gridPanel.ColumnCount = 5; + gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + gridPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + gridPanel.Dock = System.Windows.Forms.DockStyle.Fill; + gridPanel.Location = new System.Drawing.Point(0, 0); + gridPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + gridPanel.Name = "gridPanel"; + gridPanel.RowCount = 3; + gridPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33F)); + gridPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.34F)); + gridPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33F)); + gridPanel.Size = new System.Drawing.Size(506, 444); + gridPanel.TabIndex = 0; + // // navPanel - // - this.navPanel.Controls.Add(this.btnPrev); - this.navPanel.Controls.Add(this.txtPage); - this.navPanel.Controls.Add(this.lblPageCount); - this.navPanel.Controls.Add(this.btnNext); - this.navPanel.Dock = System.Windows.Forms.DockStyle.Bottom; - this.navPanel.Location = new System.Drawing.Point(0, 764); - this.navPanel.Name = "navPanel"; - this.navPanel.Size = new System.Drawing.Size(1200, 36); - this.navPanel.TabIndex = 1; - // + // + navPanel.Controls.Add(btnPrev); + navPanel.Controls.Add(txtPage); + navPanel.Controls.Add(lblPageCount); + navPanel.Controls.Add(btnNext); + navPanel.Dock = System.Windows.Forms.DockStyle.Bottom; + navPanel.Location = new System.Drawing.Point(0, 444); + navPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + navPanel.Name = "navPanel"; + navPanel.Size = new System.Drawing.Size(506, 42); + navPanel.TabIndex = 1; + // // btnPrev - // - this.btnPrev.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnPrev.Name = "btnPrev"; - this.btnPrev.Size = new System.Drawing.Size(80, 28); - this.btnPrev.TabIndex = 0; - this.btnPrev.Text = "< Prev"; - this.btnPrev.Click += new System.EventHandler(this.btnPrev_Click); - // + // + btnPrev.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + btnPrev.Location = new System.Drawing.Point(0, 0); + btnPrev.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnPrev.Name = "btnPrev"; + btnPrev.Size = new System.Drawing.Size(93, 32); + btnPrev.TabIndex = 0; + btnPrev.Text = "< Prev"; + btnPrev.Click += btnPrev_Click; + // // txtPage - // - this.txtPage.Name = "txtPage"; - this.txtPage.Size = new System.Drawing.Size(40, 20); - this.txtPage.TabIndex = 1; - this.txtPage.Text = "1"; - this.txtPage.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.txtPage.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPage_KeyDown); - // + // + txtPage.Location = new System.Drawing.Point(0, 0); + txtPage.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + txtPage.Name = "txtPage"; + txtPage.Size = new System.Drawing.Size(46, 23); + txtPage.TabIndex = 1; + txtPage.Text = "1"; + txtPage.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + txtPage.KeyDown += txtPage_KeyDown; + // // lblPageCount - // - this.lblPageCount.Name = "lblPageCount"; - this.lblPageCount.Size = new System.Drawing.Size(50, 28); - this.lblPageCount.TabIndex = 2; - this.lblPageCount.Text = "/ 1"; - this.lblPageCount.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // + // + lblPageCount.Location = new System.Drawing.Point(0, 0); + lblPageCount.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + lblPageCount.Name = "lblPageCount"; + lblPageCount.Size = new System.Drawing.Size(58, 32); + lblPageCount.TabIndex = 2; + lblPageCount.Text = "/ 1"; + lblPageCount.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // btnNext - // - this.btnNext.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnNext.Name = "btnNext"; - this.btnNext.Size = new System.Drawing.Size(80, 28); - this.btnNext.TabIndex = 3; - this.btnNext.Text = "Next >"; - this.btnNext.Click += new System.EventHandler(this.btnNext_Click); - // + // + btnNext.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + btnNext.Location = new System.Drawing.Point(0, 0); + btnNext.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + btnNext.Name = "btnNext"; + btnNext.Size = new System.Drawing.Size(93, 32); + btnNext.TabIndex = 3; + btnNext.Text = "Next >"; + btnNext.Click += btnNext_Click; + // // BestFitViewerForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1200, 800); - this.Controls.Add(this.gridPanel); - this.Controls.Add(this.toolbarPanel); - this.Controls.Add(this.navPanel); - this.KeyPreview = true; - this.Name = "BestFitViewerForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Best-Fit Viewer"; - this.WindowState = System.Windows.Forms.FormWindowState.Maximized; - this.toolbarPanel.ResumeLayout(false); - this.navPanel.ResumeLayout(false); - this.navPanel.PerformLayout(); - this.ResumeLayout(false); + // + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + ClientSize = new System.Drawing.Size(792, 486); + Controls.Add(splitContainer); + KeyPreview = true; + Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + Name = "BestFitViewerForm"; + StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + Text = "Best-Fit Viewer"; + WindowState = System.Windows.Forms.FormWindowState.Maximized; + splitContainer.Panel1.ResumeLayout(false); + splitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)splitContainer).EndInit(); + splitContainer.ResumeLayout(false); + navPanel.ResumeLayout(false); + navPanel.PerformLayout(); + ResumeLayout(false); } + private System.Windows.Forms.SplitContainer splitContainer; + private Controls.DrawingListBox drawingListBox; private System.Windows.Forms.TableLayoutPanel gridPanel; - private System.Windows.Forms.Panel toolbarPanel; - private System.Windows.Forms.Label lblDrawing; - private System.Windows.Forms.ComboBox cboDrawing; private System.Windows.Forms.Panel navPanel; private System.Windows.Forms.Button btnPrev; private System.Windows.Forms.Button btnNext; diff --git a/OpenNest/Forms/BestFitViewerForm.cs b/OpenNest/Forms/BestFitViewerForm.cs index f483a16..3599b98 100644 --- a/OpenNest/Forms/BestFitViewerForm.cs +++ b/OpenNest/Forms/BestFitViewerForm.cs @@ -41,11 +41,12 @@ namespace OpenNest.Forms private int currentPage; private int pageCount; private CancellationTokenSource computeCts; + private Label lblLoading; public BestFitResult SelectedResult { get; private set; } public Drawing SelectedDrawing => activeDrawing; - public BestFitViewerForm(DrawingCollection drawings, Plate plate) + public BestFitViewerForm(DrawingCollection drawings, Plate plate, Units units = Units.Inches) { this.drawings = drawings.ToList(); this.plate = plate; @@ -53,10 +54,12 @@ namespace OpenNest.Forms DoubleBuffered = true; InitializeComponent(); + drawingListBox.Units = units; + drawingListBox.HideQuantity = true; foreach (var d in drawings) - cboDrawing.Items.Add(d.Name); - cboDrawing.SelectedIndex = 0; - cboDrawing.SelectedIndexChanged += cboDrawing_SelectedIndexChanged; + drawingListBox.Items.Add(d); + drawingListBox.SelectedIndex = 0; + drawingListBox.SelectedIndexChanged += drawingListBox_SelectedIndexChanged; navPanel.SizeChanged += (s, ev) => CenterNavControls(); Shown += BestFitViewerForm_Shown; @@ -93,13 +96,13 @@ namespace OpenNest.Forms return base.ProcessCmdKey(ref msg, keyData); } - private void cboDrawing_SelectedIndexChanged(object sender, EventArgs e) + private void drawingListBox_SelectedIndexChanged(object sender, EventArgs e) { - var index = cboDrawing.SelectedIndex; - if (index < 0 || index >= drawings.Count) + var drawing = drawingListBox.SelectedItem as Drawing; + if (drawing == null) return; - activeDrawing = drawings[index]; + activeDrawing = drawing; LoadResultsAsync(); } @@ -145,7 +148,6 @@ namespace OpenNest.Forms private void SetLoading(bool loading) { Cursor = loading ? Cursors.WaitCursor : Cursors.Default; - cboDrawing.Enabled = !loading; btnPrev.Enabled = !loading; btnNext.Enabled = !loading; txtPage.Enabled = !loading; @@ -155,8 +157,34 @@ namespace OpenNest.Forms Text = "Best-Fit Viewer — Computing..."; gridPanel.SuspendLayout(); gridPanel.Controls.Clear(); + lblLoading = null; + EnsureLoadingLabel(); + lblLoading.Text = string.Format("Computing best fits for {0}...", activeDrawing.Name); gridPanel.ResumeLayout(true); } + else + { + if (lblLoading != null) + lblLoading.Visible = false; + } + } + + private void EnsureLoadingLabel() + { + if (lblLoading != null) + return; + + lblLoading = new Label + { + AutoSize = false, + TextAlign = ContentAlignment.MiddleCenter, + ForeColor = Color.Gray, + Font = new Font(Font.FontFamily, 14f), + Dock = DockStyle.Fill + }; + gridPanel.Controls.Add(lblLoading, 0, 0); + gridPanel.SetColumnSpan(lblLoading, Columns); + gridPanel.SetRowSpan(lblLoading, Rows); } private static ComputeResult ComputeResults(Drawing drawing, double length, double width, double spacing) diff --git a/OpenNest/Forms/BestFitViewerForm.resx b/OpenNest/Forms/BestFitViewerForm.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/OpenNest/Forms/BestFitViewerForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OpenNest/Forms/MainForm.cs b/OpenNest/Forms/MainForm.cs index 36642d3..e4eb0d1 100644 --- a/OpenNest/Forms/MainForm.cs +++ b/OpenNest/Forms/MainForm.cs @@ -626,7 +626,7 @@ namespace OpenNest.Forms return; } - using (var form = new BestFitViewerForm(drawings, plate)) + using (var form = new BestFitViewerForm(drawings, plate, activeForm.Nest.Units)) { if (form.ShowDialog(this) == DialogResult.OK && form.SelectedResult != null) {