Commit bf16d6ae authored by qwe's avatar qwe
Browse files

init

parents
################################################################################
# Данный GITIGNORE-файл был автоматически создан Microsoft(R) Visual Studio.
################################################################################
/.vs/MDRCUBE/v16
/bin
/obj
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BF3A6F28-26CB-4B8C-94A1-C5D67799AF64}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>mdr32cube</RootNamespace>
<AssemblyName>MDR32CUBE</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Pinout.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Pinout.Designer.cs">
<DependentUpon>Pinout.cs</DependentUpon>
</Compile>
<Compile Include="PinoutPix.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="PinoutPix.Designer.cs">
<DependentUpon>PinoutPix.cs</DependentUpon>
</Compile>
<Compile Include="MdrCubeForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MdrCubeForm.Designer.cs">
<DependentUpon>MdrCubeForm.cs</DependentUpon>
</Compile>
<Compile Include="Pin.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MdrCubeForm.resx">
<DependentUpon>MdrCubeForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="PinoutPix.resx">
<DependentUpon>PinoutPix.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\filesave.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\FileOpen.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDRCUBE", "MDRCUBE.csproj", "{BF3A6F28-26CB-4B8C-94A1-C5D67799AF64}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BF3A6F28-26CB-4B8C-94A1-C5D67799AF64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF3A6F28-26CB-4B8C-94A1-C5D67799AF64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF3A6F28-26CB-4B8C-94A1-C5D67799AF64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF3A6F28-26CB-4B8C-94A1-C5D67799AF64}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E3DDDF2-AF73-483B-B1D5-2E1C74B6985D}
EndGlobalSection
EndGlobal

namespace mdr32cube
{
partial class MdrCubeForm
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором форм Windows
/// <summary>
/// Требуемый метод для поддержки конструктора не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.ToolStrip tlstrip;
this.btnOpen = new System.Windows.Forms.ToolStripButton();
this.btnSave = new System.Windows.Forms.ToolStripButton();
this.lblCurrentFile = new System.Windows.Forms.ToolStripLabel();
this.lstPeriph = new System.Windows.Forms.ListBox();
this.pix = new System.Windows.Forms.Panel();
this.lstFunc = new System.Windows.Forms.ListBox();
this.lblHint = new System.Windows.Forms.Label();
this.dlgOpen = new System.Windows.Forms.OpenFileDialog();
this.dlgSave = new System.Windows.Forms.SaveFileDialog();
this.pinoutPix1 = new mdr32cube.PinoutPix();
this.pinout = new mdr32cube.Pinout(this.components);
tlstrip = new System.Windows.Forms.ToolStrip();
tlstrip.SuspendLayout();
this.pix.SuspendLayout();
this.SuspendLayout();
//
// tlstrip
//
tlstrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
tlstrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btnOpen,
this.btnSave,
this.lblCurrentFile});
tlstrip.Location = new System.Drawing.Point(154, 0);
tlstrip.Name = "tlstrip";
tlstrip.Size = new System.Drawing.Size(761, 25);
tlstrip.TabIndex = 5;
//
// btnOpen
//
this.btnOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnOpen.Image = global::mdr32cube.Properties.Resources.FileOpen;
this.btnOpen.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(23, 22);
this.btnOpen.Text = "Open";
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// btnSave
//
this.btnSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.btnSave.Image = global::mdr32cube.Properties.Resources.FileSave;
this.btnSave.ImageTransparentColor = System.Drawing.Color.Magenta;
this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(23, 22);
this.btnSave.Text = "toolStripButton2";
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
//
// lblCurrentFile
//
this.lblCurrentFile.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
this.lblCurrentFile.Name = "lblCurrentFile";
this.lblCurrentFile.Size = new System.Drawing.Size(42, 22);
this.lblCurrentFile.Text = "No file";
this.lblCurrentFile.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lstPeriph
//
this.lstPeriph.Dock = System.Windows.Forms.DockStyle.Left;
this.lstPeriph.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
this.lstPeriph.FormattingEnabled = true;
this.lstPeriph.Location = new System.Drawing.Point(0, 0);
this.lstPeriph.Name = "lstPeriph";
this.lstPeriph.Size = new System.Drawing.Size(154, 542);
this.lstPeriph.Sorted = true;
this.lstPeriph.TabIndex = 2;
this.lstPeriph.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lstPeriph_DrawItem);
this.lstPeriph.SelectedIndexChanged += new System.EventHandler(this.lstPeriph_SelectedIndexChanged);
//
// pix
//
this.pix.BackColor = System.Drawing.SystemColors.ControlLight;
this.pix.Controls.Add(this.pinoutPix1);
this.pix.Controls.Add(this.lstFunc);
this.pix.Controls.Add(this.lblHint);
this.pix.Dock = System.Windows.Forms.DockStyle.Fill;
this.pix.Location = new System.Drawing.Point(154, 25);
this.pix.Name = "pix";
this.pix.Size = new System.Drawing.Size(761, 517);
this.pix.TabIndex = 4;
this.pix.Paint += new System.Windows.Forms.PaintEventHandler(this.pix_Paint);
this.pix.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pix_MouseDown);
this.pix.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pix_MouseMove);
this.pix.Resize += new System.EventHandler(this.pix_Resize);
//
// lstFunc
//
this.lstFunc.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lstFunc.FormattingEnabled = true;
this.lstFunc.Location = new System.Drawing.Point(0, 18);
this.lstFunc.Name = "lstFunc";
this.lstFunc.Size = new System.Drawing.Size(51, 41);
this.lstFunc.TabIndex = 4;
this.lstFunc.Visible = false;
this.lstFunc.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstFunc_MouseDown);
this.lstFunc.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lstFunc_MouseMove);
//
// lblHint
//
this.lblHint.AutoSize = true;
this.lblHint.BackColor = System.Drawing.SystemColors.Control;
this.lblHint.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.lblHint.Location = new System.Drawing.Point(0, 0);
this.lblHint.Margin = new System.Windows.Forms.Padding(0);
this.lblHint.Name = "lblHint";
this.lblHint.Size = new System.Drawing.Size(26, 15);
this.lblHint.TabIndex = 3;
this.lblHint.Text = "hint";
this.lblHint.VisibleChanged += new System.EventHandler(this.lblHint_VisibleChanged);
//
// dlgOpen
//
this.dlgOpen.DefaultExt = "csv";
this.dlgOpen.Filter = "CSV (*.csv)|*.csv|All files (*.*)|*.*";
this.dlgOpen.RestoreDirectory = true;
//
// dlgSave
//
this.dlgSave.DefaultExt = "csv";
this.dlgSave.FileName = "MDR";
this.dlgSave.Filter = "CSV (*.csv)|*.csv|All files (*.*)|*.*";
//
// pinoutPix1
//
this.pinoutPix1.BackColor = System.Drawing.SystemColors.ControlLight;
this.pinoutPix1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pinoutPix1.Location = new System.Drawing.Point(0, 0);
this.pinoutPix1.Name = "pinoutPix1";
this.pinoutPix1.pinout = this.pinout;
this.pinoutPix1.Size = new System.Drawing.Size(761, 517);
this.pinoutPix1.TabIndex = 5;
//
// MdrCubeForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(915, 542);
this.Controls.Add(this.pix);
this.Controls.Add(tlstrip);
this.Controls.Add(this.lstPeriph);
this.DoubleBuffered = true;
this.Name = "MdrCubeForm";
this.Text = "MdrCube";
tlstrip.ResumeLayout(false);
tlstrip.PerformLayout();
this.pix.ResumeLayout(false);
this.pix.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox lstPeriph;
private System.Windows.Forms.Panel pix;
private System.Windows.Forms.Label lblHint;
private System.Windows.Forms.ListBox lstFunc;
private System.Windows.Forms.ToolStripButton btnOpen;
private System.Windows.Forms.ToolStripButton btnSave;
private System.Windows.Forms.OpenFileDialog dlgOpen;
private System.Windows.Forms.SaveFileDialog dlgSave;
private System.Windows.Forms.ToolStripLabel lblCurrentFile;
private PinoutPix pinoutPix1;
private Pinout pinout;
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace mdr32cube
{
public partial class MdrCubeForm : Form
{
public MdrCubeForm()
{
InitializeComponent();
/*Is setting protected properties via reflection ugly?
* Yes.
* Is sub-classing a control you want to use in the GUI designer even uglier?
* Also yes.
* (c) Lily Finley @ https://stackoverflow.com/questions/818415/how-do-i-double-buffer-a-panel */
typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty
| BindingFlags.Instance | BindingFlags.NonPublic, null,
pix, new object[] { true });
}
private int pinPerSide = 36;
List<Pin> pins = new List<Pin>();
private void pix_Paint(object sender, PaintEventArgs e)
{
Point pixMouse = pix.PointToClient(Cursor.Position);
Graphics g = e.Graphics;
g.TranslateTransform(pix.Width / 2, pix.Height / 2);
int half = 9 * Math.Min(pix.Height, pix.Width) / 20;
g.DrawRectangle(Pens.Black, -half, -half, 2 * half, 2 * half);
g.ResetTransform();
pins.ForEach(pin => DrawPin(g, pin, pixMouse));
}
private void DrawPin(Graphics g, Pin pin, Point pixMouse)
{
int pinSide = (pin.pin - 1) / pinPerSide;
int pinPos = (pin.pin - 1) % pinPerSide;
int sz = 18 * Math.Min(pix.Height, pix.Width) / 20;
int pinL = sz / 6 / 4;
int pinW = sz / 6 / 8;
int pinShift = sz * (pinPos + 2) / 40;
g.ResetTransform();
g.TranslateTransform(pix.Width / 2, pix.Height / 2);
GraphicsState gState;
SizeF fsz = g.MeasureString($"{pin.pin}", Font);
float sc = Math.Min(1, Math.Min(pinL / fsz.Width, pinW / fsz.Height));
float sideRot, textRot;
PointF textOrigin;
switch (pinSide)
{
case 0:
sideRot = 0;
textRot = 0;
textOrigin = new PointF(-fsz.Width, 0);
break;
case 1:
sideRot = -90;
textRot = 0;
textOrigin = new PointF(-fsz.Width, 0);
break;
case 2:
sideRot = -180;
textRot = 180;
textOrigin = new PointF(0, -fsz.Height);
break;
case 3:
sideRot = -270;
textRot = 180;
textOrigin = new PointF(0, -fsz.Height);
break;
default:
sideRot = textRot = 0;
textOrigin = PointF.Empty;
break;
}
g.RotateTransform(sideRot);
g.TranslateTransform(-sz / 2, -sz / 2);
g.TranslateTransform(0, pinShift);
Rectangle rect = new Rectangle(-pinL, 0, pinL, pinW);
Point[] pts = new Point[] { pixMouse, rect.Location };
using (Matrix matrix = g.Transform.Clone())
{
matrix.Invert();
matrix.TransformPoints(pts);
}
bool mouseHover = rect.Contains(pts[0]);
bool periphSelected = pin.func.Exists(pf => pf.periph.Equals(lstPeriph.SelectedItem?.ToString()));
if (mouseHover)
g.FillRectangle(Brushes.Gray, rect);
else if (periphSelected)
{
g.FillRectangle(GetBrush(lstPeriph.SelectedItem.ToString()), rect);
g.DrawRectangle(new Pen(Color.Black, 2), rect);
}
else if (pin.sel > -1)
{
g.FillRectangle(GetBrush(pin.func[pin.sel].periph), rect);
}
g.DrawRectangle(Pens.Black, rect);
gState = g.Save();
g.ScaleTransform(sc, sc);
g.RotateTransform(textRot);
g.DrawString($"{pin.pin}", base.Font, Brushes.Black, textOrigin);
if (pin.sel > -1)
{
SizeF funcSz = g.MeasureString($"{pin.func[pin.sel].func}", base.Font);
g.DrawString($"{pin.func[pin.sel].func}", base.Font, Brushes.Black,
new PointF(pinSide < 2 ? rect.Right + 5 : -funcSz.Width - 5, textOrigin.Y));
}
g.Restore(gState);
}
private static SolidBrush GetBrush(string periph)
{
return new SolidBrush(Color.FromArgb((int)($"{periph.GetHashCode()}".GetHashCode() | 0xFF808080)));
}
private Rectangle GetPinRectangle(int pin)
{
int pinSide = (pin - 1) / pinPerSide;
int pinPos = (pin - 1) % pinPerSide;
Rectangle rect = new Rectangle(pix.Width / 2, pix.Height / 2, 0, 0);
int sz = 18 * Math.Min(pix.Height, pix.Width) / 20;
int pinL = sz / 6 / 4;
int pinW = sz / 6 / 8;
int pinShift = sz * (pinPos + 2) / 40;
switch (pinSide)
{
case 0:
rect.Offset(-sz / 2, -sz / 2);
rect.Offset(0, pinShift);
rect.Offset(-pinL, 0);
rect.Width = pinL;
rect.Height = pinW;
break;
case 1:
rect.Offset(-sz / 2, sz / 2);
rect.Offset(pinShift, 0);
rect.Offset(0, 0);
rect.Width = pinW;
rect.Height = pinL;
break;
case 2:
rect.Offset(sz / 2, sz / 2);
rect.Offset(0, -pinShift);
rect.Offset(0, -pinW);
rect.Width = pinL;
rect.Height = pinW;
break;
case 3:
rect.Offset(sz / 2, -sz / 2);
rect.Offset(-pinShift, 0);
rect.Offset(-pinW, -pinL);
rect.Width = pinW;
rect.Height = pinL;
break;
default:
rect = Rectangle.Empty;
break;
}
return rect;
}
private void pix_Resize(object sender, EventArgs e) => pix.Refresh();
private void pix_MouseMove(object sender, MouseEventArgs e)
{
Pin p = pins.Find(pin => GetPinRectangle(pin.pin).Contains(e.Location));
if (p != null && !lstFunc.Visible)
{
pix.Refresh();
lblHint.Text =
$"Pin {p.pin}{Environment.NewLine}" +
string.Join(Environment.NewLine, p.func.Select(pf => $"{pf.periph} {pf.func}"));
lblHint.Left = Math.Min(e.X + 16, pix.Width - lblHint.Width);
lblHint.Top = Math.Min(e.Y + 16, pix.Height - lblHint.Height);
lblHint.Show();
}
else
{
lblHint.Hide();
}
}
private void lstPeriph_SelectedIndexChanged(object sender, EventArgs e)
{
pix.Refresh();
lstPeriph.Refresh();
}
private void lstPeriph_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
return;
string periph = lstPeriph.Items[e.Index].ToString();
SolidBrush periphBrush = GetBrush(periph);
e.Graphics.FillRectangle(periphBrush, e.Bounds);
e.Graphics.DrawString(