private void PrintLength(ConductorMaterial material, double length)
        {
            if (length <= 0)
            {
                return;
            }

            string measurementUnit        = "мм";
            Int64  measurementCoefficient = 1;
            string stringFormat           = "n3";

            const int mInLength  = 1000;           //мм^2
            const int cmInLength = 10;             //мм^2

            if (length >= mInLength)
            {
                measurementUnit        = "м";
                measurementCoefficient = mInLength;
                stringFormat           = "n3";
            }
            else if (length >= cmInLength)
            {
                measurementUnit        = "см";
                measurementCoefficient = cmInLength;
                stringFormat           = "n3";
            }
            textBoxLengths.Text += material.Name + ": "
                                   + (length / measurementCoefficient).ToString(stringFormat)
                                   + " " + measurementUnit
                                   + Environment.NewLine;
        }
        private void PrintSquare(ConductorMaterial material, double square)
        {
            if (square <= 0)
            {
                return;
            }

            string measurementUnit        = "мм^2";
            Int64  measurementCoefficient = 1;
            string stringFormat           = "n2";

            const int mInSquare  = 1000000;         //мм^2
            const int cmInSquare = 100;             //мм^2

            if (square >= mInSquare)
            {
                measurementUnit        = "м^2";
                measurementCoefficient = mInSquare;
                stringFormat           = "n3";
            }
            else if (square >= cmInSquare)
            {
                measurementUnit        = "см^2";
                measurementCoefficient = cmInSquare;
                stringFormat           = "n3";
            }
            textBoxSquares.Text += material.Name + ": "
                                   + (square / measurementCoefficient).ToString(stringFormat)
                                   + " " + measurementUnit
                                   + Environment.NewLine;
        }
        public double CalculateLength(ConductorMaterial material)
        {
            double pixelsInLineCount = 0;

            for (int iWidth = 0; iWidth < bitmapReal.Width; iWidth++)
            {
                for (int jHeight = 0; jHeight < bitmapReal.Height; jHeight++)
                {
                    Color currentPixel = bitmapReal.GetPixel(iWidth, jHeight);
                    if (IsAvailableColor(currentPixel))
                    {
                        //TODO: Разобраться с предикатами и заменить это на materials.Find()
                        if (material.PixelColor.ToArgb() == currentPixel.ToArgb())
                        {
                            pixelsInLineCount++;
                            break;
                        }
                    }
                }
            }

            double length = pixelsInLineCount / (Math.Sqrt(PixelsInCellCount) / Math.Sqrt(CellSquare));

            return(length);
        }
        public double ChangeSideSquare(ConductorMaterial material, double frontSquare)
        {
            double newSquare           = 0;
            int    frontLineDifference = maxHeight - minHeight;

            int lineCount = 0;

            for (int iWidth = 0; iWidth < bitmapReal.Width; iWidth++)
            {
                int currentLineDiff = 0;
                for (int jHeight = 0; jHeight < bitmapReal.Height; jHeight++)
                {
                    Color currentPixel = bitmapReal.GetPixel(iWidth, jHeight);
                    if (IsAvailableColor(currentPixel))
                    {
                        //TODO: Разобраться с предикатами и заменить это на materials.Find()
                        if (material.PixelColor.ToArgb() == currentPixel.ToArgb())
                        {
                            currentLineDiff++;
                        }
                    }
                }
                if (currentLineDiff != 0)
                {
                    lineCount++;
                    double ratio         = (double)currentLineDiff / frontLineDifference;
                    double currentSquare = frontSquare * ratio;
                    newSquare += currentSquare;
                }
            }
            newSquare = newSquare / lineCount;
            return(newSquare);
        }
        public double CalculateSquare(ConductorMaterial currentMaterial)
        {
            currentMaterial.PixelCount = CalculatePixelCount(currentMaterial);
            double square = (currentMaterial.PixelCount / ((double)PixelsInCellCount / (double)CellSquare));             //Количество пикселей/количество пикселей в 1 мм^2

            return(square);
        }
Beispiel #6
0
        private void buttonAccept_Click(object sender, EventArgs e)
        {
            if (IsNameAvailable(textBoxName.Text))
            {
                if (IsColorAvailable(colorDialog.Color))
                {
                    ConductorMaterial newConductorMaterial = new ConductorMaterial(
                        textBoxName.Text,
                        panelColor.BackColor,
                        Convert.ToDouble(numericUpDownResistivity.Value)
                        );

                    if (currentMaterial != null)
                    {
                        windowMain.DeleteMaterial(currentMaterial.Name);
                        windowMain.AddNewMaterial(newConductorMaterial);
                    }
                    else
                    {
                        windowMain.AddNewMaterial(newConductorMaterial);
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Нельзя создать материал с таким цветом");
                }
            }
            else
            {
                MessageBox.Show("Нельзя создать материал с таким именем");
            }
        }
        public void PrintPixelCount(ConductorMaterial material, TextBox textBoxToPrint)
        {
            if (material.PixelCount <= 0)
            {
                return;
            }

            textBoxToPrint.Text += material.Name + ": " + material.PixelCount.ToString() + Environment.NewLine;
        }
 private void OpenWindowMaterialSettings(ConductorMaterial materialForChanging)
 {
     if (!isMaterialSettingsOpened)
     {
         WindowMaterialSettings windowMaterialSettings = new WindowMaterialSettings(materialForChanging);
         windowMaterialSettings.Owner = this;
         windowMaterialSettings.Show();
         isMaterialSettingsOpened = true;
     }
 }
Beispiel #9
0
        public WindowMaterialSettings(ConductorMaterial materialForChanging)
        {
            InitializeComponent();

            this.currentMaterial = materialForChanging;
            if (materialForChanging != null)
            {
                textBoxName.Text = materialForChanging.Name;
                numericUpDownResistivity.Value = Convert.ToDecimal(materialForChanging.Resistivity);
                panelColor.BackColor           = materialForChanging.PixelColor;
            }
        }
        public int CalculatePixelCount(ConductorMaterial material)
        {
            int pixelsCount = 0;

            for (int iWidth = 0; iWidth < bitmapReal.Width; iWidth++)
            {
                for (int jHeight = 0; jHeight < bitmapReal.Height; jHeight++)
                {
                    Color currentPixel = bitmapReal.GetPixel(iWidth, jHeight);
                    if (IsAvailableColor(currentPixel))
                    {
                        //TODO: Разобраться с предикатами и заменить это на materials.Find()
                        if (material.PixelColor.ToArgb() == currentPixel.ToArgb())
                        {
                            pixelsCount++;
                        }
                    }
                }
            }
            return(pixelsCount);
        }
 public void AddNewMaterial(ConductorMaterial newMaterial)
 {
     materials.Add(newMaterial);
     ComboBoxRefresh();
 }