BigLitho/Large.Lito.Database/Make3_Treko3D/ChildForms/frmChildProject.cs

582 lines
22 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Projects;
using ControlLibrary;
using Frames;
using Data;
using ClassLibrary;
namespace ChildForms
{
public partial class frmChildProject : Form
{
#region Local Data
Project _projectObj;
Layer _layerObj;
ProjectControl _projectControl;
string _technologyName;
string _sourceFilePath;
private struct Selection
{
public int Top;
public int Left;
public int Height;
public int Width;
}
private bool wEdge;
private bool eEdge;
private bool nEdge;
private bool sEdge;
private bool Sizing;
private const int EdgeSize = 6;
private Point StartCoord;
private Point OldCoord;
private Point NewCoord;
private Selection Rect;
private bool MovePic;
private bool MoveMain;
private bool SizePic;
private List<LayerPictureBox> _layers = new List<LayerPictureBox>();
//internal LayerPictureBox layerPicBox1;
//internal LayerPictureBox layerPicBox2;
private LayerPictureBox layerPicBox3;
//private LayerPictureBox layerPicBox4;
int _mmToPixelsCoeffPreview = 1;
#endregion
#region Get-Set
public Project ProjectObj
{
get { return _projectObj; }
set { _projectObj = value; }
}
public Layer LayerObj
{
get { return _layerObj; }
set { _layerObj = value; }
}
public ProjectControl ProjectControl
{
get { return _projectControl; }
set { _projectControl = value; }
}
#endregion
public frmChildProject()
{
InitializeComponent();
//InitializeExt();
}
private void InitializeExt()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LayerControl));
//RefreshLayersPicBoxes();
//this.layerPicBox4 = new LayerPictureBox();
this.layerPicBox3 = new LayerPictureBox();
//this.layerPicBox2 = new LayerPictureBox();
//this.layerPicBox1 = new LayerPictureBox();
//layerPicBox2.Parent = pictureBox1;
//layerPicBox2.SizeMode = PictureBoxSizeMode.StretchImage;
layerPicBox3.Parent = pictureBox1;
layerPicBox3.SizeMode = PictureBoxSizeMode.StretchImage;
//layerPicBox4.Parent = pictureBox1;
//layerPicBox4.SizeMode = PictureBoxSizeMode.StretchImage;
//layerPicBox3.Image = global::TestLayers.Properties.Resources.test1;
//layerPicBox3.Location = new System.Drawing.Point(27, 19);
//layerPicBox3.Name = "pictureBox3";
//layerPicBox3.Size = new System.Drawing.Size(139, 48);
this.layerPicBox3.BackColor = System.Drawing.Color.Transparent;
this.layerPicBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictThumbnail.Image"))); ;
this.layerPicBox3.Location = new System.Drawing.Point(10, 10);
this.layerPicBox3.Name = "pictureBox3";
this.layerPicBox3.Size = new System.Drawing.Size(48, 48);
//this.layerPicBox3.TabIndex = 7;
//this.layerPicBox3.TabStop = false;
//this.layerPicBox3.BringToFront();
//hScrollBar1.Parent = this;
//vScrollBar1.Parent = this;
//pictureBox2.Controls.Add(layerPicBox2);
}
public void Draw_HologramBorder(decimal nx, decimal ny)
{
pictureBox1.Image = new Bitmap(2000, 2000);
Bitmap bmp = (Bitmap)pictureBox1.Image;
Graphics g = Graphics.FromImage(bmp);
ClearImage(g);
Color col = Color.FromArgb(255, 255, 0, 0);
var Pn = new Pen(col, 3);
g.DrawRectangle(Pn, 0, 0, (float)_projectObj.HologramWidth * _mmToPixelsCoeffPreview, (float)_projectObj.HologramHeight * _mmToPixelsCoeffPreview);
Color col1 = Color.FromArgb(255, 255, 255, 0);
var Pn1 = new Pen(col1, 1);
g.DrawRectangle(Pn1, 0, 0, (float)0.2 * _mmToPixelsCoeffPreview, (float)0.15 * _mmToPixelsCoeffPreview);
Color col2 = Color.FromArgb(255, 0, 255, 0);
var Pn2 = new Pen(col2, 1);
g.DrawRectangle(Pn2, 0, 0, (float)0.2 * _mmToPixelsCoeffPreview * Convert.ToInt32(nx), (float)0.15 * _mmToPixelsCoeffPreview * Convert.ToInt32(ny));
g.Dispose();
}
public void ClearImage(Graphics g)
{
g.Clear(Color.Black);
}
public void RefreshLayersPicBoxes()
{
LayerPictureBox lpb;
LayerPictureBox lpbFace = null;
LayerPictureBox lpbDotrix = null;
LayerPictureBox lpbTeapot = null;
if (_projectObj != null)
{
ProjectControl.LoadProject(_projectObj.ProjectId);
_projectObj = ProjectControl.Project;
int i = 0;
if (_projectObj != null && _projectObj.Layers != null && _projectObj.Layers.Count > 0)
{
foreach (Layer layer in _projectObj.Layers)
{
lpb = new LayerPictureBox();
if (i == 2)
lpbFace = lpb;
if (i == 0)
lpbDotrix = lpb;
if (i == 1)
lpbTeapot = lpb;
lpb.SizeMode = PictureBoxSizeMode.StretchImage;
lpb.BackColor = System.Drawing.Color.Transparent;
//lpb.Image = global::TestLayers.Properties.Resources.broculo; //((System.Drawing.Image)(resources.GetObject("pictThumbnail.Image"))); ;
lpb.Location = new System.Drawing.Point(Convert.ToInt32(layer.LayerLeft) * 2, Convert.ToInt32(layer.LayerTop) * 2);
lpb.Name = layer.LayerName;
lpb.Size = new System.Drawing.Size(Convert.ToInt32(layer.LayerWidth)*2, Convert.ToInt32(layer.LayerHeight)*2);
//pgb.LayerService = layerService;
//pgb.LayerModel = layerModel;
lpb.Padding = new Padding(5);
_technologyName = layer.TechnologyName;
_sourceFilePath = layer.SourceFilePath;
if (_technologyName == "Treko3D")
{
string[] _rakurseFiles = Helper.LoadRakurseFiles(_sourceFilePath);
string filePath = _rakurseFiles[0];
try
{
lpb.Image = new Bitmap(filePath);
}
catch (Exception e)
{
}
} else if (_technologyName == "Treko")
{
//string[] _rakurseFiles = Helper.LoadRakurseFiles(_sourceFilePath);
string filePath = _sourceFilePath;
try
{
lpb.Image = new Bitmap(filePath);
}
catch (Exception e)
{
}
}
//lpb.LayerName = layer.LayerName;
//lpb.LayerObj = layer;
//lpb.StatusBarColor = 0;
//pgb.Size = s;
//pgb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
//pgb.OnArrowUpClicked += LayerControl_ArrowUpClicked;
//pgb.OnArrowDownClicked += LayerControl_ArrowDownClicked;
//pgb.OnDoubleClicked += LayerControl_DoubleClicked;
//pgb.OnCancelClicked += LayerControl_CancelClicked;
this._layers.Add(lpb);
i++;
//this.flowLayoutPanel1.Controls.Add(pgb);
}
lpbDotrix.Parent = lpbFace;
lpbTeapot.Parent = lpbFace;
lpbFace.Parent = pictureBox1;
//Draw_HologramBorder(numFrameGroupWidth.Value, numFrameGroupHeight.Value);
Draw_HologramBorder(10, 10);
}
}
}
private void ScrollAdjust()
{
//if (pictureBox2.Width < pictureBox1.Width)
//{
// pictureBox2.Left = (pictureBox1.Width - pictureBox2.Width) / 2;
// hScrollBar1.Enabled = false;
//}
//else
//{
// if (pictureBox2.Left > 0)
// pictureBox2.Left = 0;
// hScrollBar1.Minimum = 0;
// hScrollBar1.Maximum = pictureBox2.Width - pictureBox1.Width;
// hScrollBar1.SmallChange = 1;
// hScrollBar1.LargeChange = 10;
// hScrollBar1.Enabled = true;
//}
//if (pictureBox2.Height < pictureBox1.Height)
//{
// pictureBox2.Top = (pictureBox1.Height - pictureBox2.Height) / 2;
// vScrollBar1.Enabled = false;
//}
//else
//{
// if (pictureBox2.Top > 0)
// pictureBox2.Top = 0;
// vScrollBar1.Minimum = 0;
// vScrollBar1.Maximum = pictureBox2.Height - pictureBox1.Height;
// vScrollBar1.SmallChange = 1;
// vScrollBar1.LargeChange = 10;
// vScrollBar1.Enabled = true;
//}
}
private void Form1_Resize(object sender, EventArgs e)
{
ScrollAdjust();
}
//private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
//{
// if (e.Button == MouseButtons.Middle)
// MoveMain = true;
// StartCoord = e.Location;
//}
//private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
//{
// MoveMain = false;
//}
//private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
//{
// if (MoveMain)
// {
// if (vScrollBar1.Enabled)
// {
// NewCoord.Y = pictureBox2.Top - (StartCoord.Y - e.Location.Y);
// if (NewCoord.Y > 0)
// NewCoord.Y = 0;
// if (NewCoord.Y < -vScrollBar1.Maximum)
// NewCoord.Y = -vScrollBar1.Maximum;
// pictureBox2.Top = NewCoord.Y;
// vScrollBar1.Value = -NewCoord.Y;
// }
// if (hScrollBar1.Enabled)
// {
// NewCoord.X = pictureBox2.Left - (StartCoord.X - e.Location.X);
// if (NewCoord.X > 0)
// NewCoord.X = 0;
// if (NewCoord.X < -hScrollBar1.Maximum)
// NewCoord.X = -hScrollBar1.Maximum;
// pictureBox2.Left = NewCoord.X;
// hScrollBar1.Value = -NewCoord.X;
// }
// }
//}
private void pictureBox3_MouseDown(object sender, MouseEventArgs ee)
{
// Click on Sizable Image Region - NB. Child picturebox
if (ee.Button == MouseButtons.Left)
{
OldCoord = ee.Location;
StartCoord = ee.Location;
if (Sizing)
SizePic = true;
else
MovePic = true;
}
if (ee.Button == MouseButtons.Middle)
{
MoveMain = true;
StartCoord = ee.Location;
}
}
private void pictureBox3_MouseUp(object sender, MouseEventArgs e)
{
// Release Click in Sizable Image Region - NB. Child picturebox
SizePic = false;
MovePic = false;
MoveMain = false;
}
//private void pictureBox3_MouseMove(object sender, MouseEventArgs ee)
//{
// //Mouse move inside Image Region... - NB. Child Picturebox
// if (ee.Button == MouseButtons.None)
// {
// if (ee.Location.X < EdgeSize && ee.Location.X > 0)
// wEdge = true;
// else
// wEdge = false;
// if (ee.Location.X > pictureBox3.Size.Width - EdgeSize && ee.Location.X < pictureBox3.Size.Width)
// eEdge = true;
// else
// eEdge = false;
// if (ee.Location.Y < EdgeSize && ee.Location.Y > 0)
// nEdge = true;
// else
// nEdge = false;
// if (ee.Location.Y > pictureBox3.Size.Height - EdgeSize && ee.Location.Y < pictureBox3.Size.Height)
// sEdge = true;
// else
// sEdge = false;
// Sizing = true;
// }
// else if (ee.Button == MouseButtons.Left)
// {
// if (MovePic)
// {
// pictureBox3.Top = pictureBox3.Top + (ee.Location.Y - StartCoord.Y);
// pictureBox3.Left = pictureBox3.Left + (ee.Location.X - StartCoord.X);
// }
// // The code following works when used with a child Picturebox...
// // NB. Alternate code will apply if working on a rect region selection.....
// if (SizePic)
// {
// Rect.Top = pictureBox3.Top;
// Rect.Height = pictureBox3.Height;
// Rect.Left = pictureBox3.Left;
// Rect.Width = pictureBox3.Width;
// if (eEdge)
// Rect.Width = ee.Location.X;
// if (sEdge)
// Rect.Height = ee.Location.Y;
// if (wEdge)
// {
// Rect.Left = Rect.Left - (StartCoord.X - ee.Location.X);
// Rect.Width = Rect.Width + (StartCoord.X - ee.Location.X);
// }
// if (nEdge)
// {
// Rect.Top = Rect.Top - (StartCoord.Y - ee.Location.Y);
// Rect.Height = Rect.Height + (StartCoord.Y - ee.Location.Y);
// }
// if (Rect.Height < 0)
// {
// Rect.Top = Rect.Top + Rect.Height;
// Rect.Height = Math.Abs(Rect.Height);
// nEdge = !nEdge;
// sEdge = !sEdge;
// StartCoord.Y = 0;
// }
// if (Rect.Width < 0)
// {
// Rect.Left = Rect.Left + Rect.Width;
// Rect.Width = Math.Abs(Rect.Width);
// eEdge = !eEdge;
// wEdge = !wEdge;
// StartCoord.X = 0;
// }
// pictureBox3.Top = Rect.Top;
// pictureBox3.Height = Rect.Height;
// pictureBox3.Left = Rect.Left;
// pictureBox3.Width = Rect.Width;
// }
// }
// if ((nEdge || sEdge) && !(wEdge || eEdge))
// pictureBox3.Cursor = Cursors.SizeNS;
// else if ((wEdge || eEdge) && !(nEdge || sEdge))
// pictureBox3.Cursor = Cursors.SizeWE;
// else if ((nEdge && eEdge) || (sEdge && wEdge))
// pictureBox3.Cursor = Cursors.SizeNESW;
// else if ((nEdge && wEdge) || (sEdge && eEdge))
// pictureBox3.Cursor = Cursors.SizeNWSE;
// else
// {
// pictureBox3.Cursor = Cursors.Default;
// Sizing = false;
// }
// OldCoord = ee.Location;
// if (MoveMain)
// pictureBox2_MouseMove(sender, ee);
//}
private void VScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
//pictureBox2.Top = -vScrollBar1.Value;
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
//pictureBox2.Left = -hScrollBar1.Value;
}
private void frmChildProject_Resize(object sender, EventArgs e)
{
ScrollAdjust();
}
//private void pictureBox4_MouseDown(object sender, MouseEventArgs e)
//{
// // Click on Sizable Image Region - NB. Child picturebox
// if (e.Button == MouseButtons.Left)
// {
// OldCoord = e.Location;
// StartCoord = e.Location;
// if (Sizing)
// SizePic = true;
// else
// MovePic = true;
// }
// if (e.Button == MouseButtons.Middle)
// {
// MoveMain = true;
// StartCoord = e.Location;
// }
//}
//private void pictureBox4_MouseUp(object sender, MouseEventArgs e)
//{
// // Release Click in Sizable Image Region - NB. Child picturebox
// SizePic = false;
// MovePic = false;
// MoveMain = false;
//}
//private void pictureBox4_MouseMove(object sender, MouseEventArgs e)
//{
// //Mouse move inside Image Region... - NB. Child Picturebox
// if (e.Button == MouseButtons.None)
// {
// if (e.Location.X < EdgeSize && e.Location.X > 0)
// wEdge = true;
// else
// wEdge = false;
// if (e.Location.X > pictureBox4.Size.Width - EdgeSize && e.Location.X < pictureBox4.Size.Width)
// eEdge = true;
// else
// eEdge = false;
// if (e.Location.Y < EdgeSize && e.Location.Y > 0)
// nEdge = true;
// else
// nEdge = false;
// if (e.Location.Y > pictureBox4.Size.Height - EdgeSize && e.Location.Y < pictureBox4.Size.Height)
// sEdge = true;
// else
// sEdge = false;
// Sizing = true;
// }
// else if (e.Button == MouseButtons.Left)
// {
// if (MovePic)
// {
// pictureBox4.Top = pictureBox4.Top + (e.Location.Y - StartCoord.Y);
// pictureBox4.Left = pictureBox4.Left + (e.Location.X - StartCoord.X);
// }
// // The code following works when used with a child Picturebox...
// // NB. Alternate code will apply if working on a rect region selection.....
// if (SizePic)
// {
// Rect.Top = pictureBox4.Top;
// Rect.Height = pictureBox4.Height;
// Rect.Left = pictureBox4.Left;
// Rect.Width = pictureBox4.Width;
// if (eEdge)
// Rect.Width = e.Location.X;
// if (sEdge)
// Rect.Height = e.Location.Y;
// if (wEdge)
// {
// Rect.Left = Rect.Left - (StartCoord.X - e.Location.X);
// Rect.Width = Rect.Width + (StartCoord.X - e.Location.X);
// }
// if (nEdge)
// {
// Rect.Top = Rect.Top - (StartCoord.Y - e.Location.Y);
// Rect.Height = Rect.Height + (StartCoord.Y - e.Location.Y);
// }
// if (Rect.Height < 0)
// {
// Rect.Top = Rect.Top + Rect.Height;
// Rect.Height = Math.Abs(Rect.Height);
// nEdge = !nEdge;
// sEdge = !sEdge;
// StartCoord.Y = 0;
// }
// if (Rect.Width < 0)
// {
// Rect.Left = Rect.Left + Rect.Width;
// Rect.Width = Math.Abs(Rect.Width);
// eEdge = !eEdge;
// wEdge = !wEdge;
// StartCoord.X = 0;
// }
// pictureBox4.Top = Rect.Top;
// pictureBox4.Height = Rect.Height;
// pictureBox4.Left = Rect.Left;
// pictureBox4.Width = Rect.Width;
// }
// }
// if ((nEdge || sEdge) && !(wEdge || eEdge))
// pictureBox4.Cursor = Cursors.SizeNS;
// else if ((wEdge || eEdge) && !(nEdge || sEdge))
// pictureBox4.Cursor = Cursors.SizeWE;
// else if ((nEdge && eEdge) || (sEdge && wEdge))
// pictureBox4.Cursor = Cursors.SizeNESW;
// else if ((nEdge && wEdge) || (sEdge && eEdge))
// pictureBox4.Cursor = Cursors.SizeNWSE;
// else
// {
// pictureBox4.Cursor = Cursors.Default;
// Sizing = false;
// }
// OldCoord = e.Location;
// if (MoveMain)
// pictureBox2_MouseMove(sender, e);
//}
}
}