Пример #1
0
        /// <summary>
        /// Evento que se lanza al entrar el puntero del mouse en una celda del grid
        /// </summary>
        private void grid_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {
            // Evita lanzar eventos durante la representación del panel
            if (_drawing)
            {
                return;
            }

            if (_mode == PanelModes.Operation)
            {
                try
                {
                    if (SelectedSchema.IsUsedCell(e.ColumnIndex, e.RowIndex))
                    {
                        OTCPanelBlock block = SelectedSchema.GetBlock(e.ColumnIndex, e.RowIndex);
                        if (block.LibraryBlock.Type != OTCLibraryBlock.BlockTypes.Static)
                        {
                            SelectedGrid.Cursor = Cursors.Hand;
                        }
                    }
                }
                catch
                {
                    // Descarta cualquier error
                }
            }
            else if (_mode == PanelModes.Design && _currentDesignAction == DesignActions.Add)
            {
                try
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(global::otc.Properties.Resources.CUR_ADD);
                    SelectedGrid.Cursor = new Cursor(ms);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Genera un archivo PDF que contiene el esquema como gráfico.
        /// </summary>
        /// <param name="filename">Nombre y path del archivo a generar.</param>
        /// <param name="ShowBlockInfo">Indica si el esquema debe mostrar información en los accesorios.</param>
        /// <param name="landscape">Indica si se debe generar el documento usando páginas apaisadas.</param>
        /// <remarks>
        /// Usa iTextSharp para generar el PDF: http://itextsharp.sourceforge.net/
        /// </remarks>
        public void PrintToPDF(string filename, bool ShowBlockInfo, bool landscape)
        {
            try
            {
                // Genera un nuevo documento apaisado
                Document document = new Document(PageSize.A4);

                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));

                // Genera tipos de letra necesarios
                BaseFont             bfvalue = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font fhead   = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.NORMAL);
                iTextSharp.text.Font fheadb  = FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD);

                // Establece las propiedades del documento
                if (landscape)
                {
                    document.SetPageSize(PageSize.A4.Rotate());
                }
                document.AddAuthor(Application.ProductName);
                document.AddCreationDate();
                document.AddCreator(Application.CompanyName + " - " + Application.ProductName);
                document.AddTitle(SelectedSchema.Name);
                document.AddSubject(Application.CompanyName);

                // Abre el nuevo documento
                document.Open();

                // Genera la plantilla del documento
                PdfContentByte cb = writer.DirectContent;
                cb.SetLineWidth(01f);

                cb.Rectangle(document.LeftMargin,
                             document.BottomMargin,
                             document.PageSize.Width - (document.RightMargin + document.LeftMargin),
                             document.PageSize.Height - (document.TopMargin + document.BottomMargin));
                cb.Stroke();

                cb.Rectangle(document.PageSize.Width - 250 - document.RightMargin,
                             document.BottomMargin,
                             250,
                             50);
                cb.Stroke();

                cb.MoveTo(document.PageSize.Width - 250 - document.RightMargin, document.BottomMargin + 25);
                cb.LineTo(document.PageSize.Width - document.RightMargin, document.BottomMargin + 25);
                cb.Stroke();

                cb.MoveTo(document.PageSize.Width - 125 - document.RightMargin, document.BottomMargin);
                cb.LineTo(document.PageSize.Width - 125 - document.RightMargin, document.BottomMargin + 25);
                cb.Stroke();

                cb.SetLineWidth(0.2f);

                cb.MoveTo(document.PageSize.Width - 250 - document.RightMargin, document.BottomMargin + (25 / 2));
                cb.LineTo(document.PageSize.Width - 125 - document.RightMargin, document.BottomMargin + (25 / 2));
                cb.Stroke();

                cb.MoveTo(document.PageSize.Width - 221 - document.RightMargin, document.BottomMargin);
                cb.LineTo(document.PageSize.Width - 221 - document.RightMargin, document.BottomMargin + 25);
                cb.Stroke();

                cb.MoveTo(document.PageSize.Width - 30 - document.RightMargin, document.BottomMargin + 50);
                cb.LineTo(document.PageSize.Width - 30 - document.RightMargin, document.BottomMargin + 25);
                cb.Stroke();

                cb.MoveTo(document.PageSize.Width - 30 - document.RightMargin, document.BottomMargin + 25 + (25 / 2));
                cb.LineTo(document.PageSize.Width - document.RightMargin, document.BottomMargin + 25 + (25 / 2));
                cb.Stroke();

                BaseFont bflabel = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                cb.BeginText();

                cb.SetFontAndSize(bflabel, 7);
                cb.SetTextMatrix(document.PageSize.Width - 250 - document.RightMargin + 3, document.BottomMargin + 50 - 8);
                cb.ShowText(_panel.Name);

                cb.SetFontAndSize(bfvalue, 12);
                cb.SetTextMatrix(document.PageSize.Width - 250 - document.RightMargin + 3, document.BottomMargin + 50 - 20);
                cb.ShowText(SelectedSchema.Name);

                cb.SetFontAndSize(bflabel, 6);
                cb.SetTextMatrix(document.PageSize.Width - 250 - document.RightMargin + 3, document.BottomMargin + 25 - 9);
                cb.ShowText("Fecha");

                cb.SetFontAndSize(bflabel, 7);
                cb.SetTextMatrix(document.PageSize.Width - 221 - document.RightMargin + 3, document.BottomMargin + 25 - 9);
                cb.ShowText(DateTime.Now.ToString("dd/MM/yyyy"));

                cb.SetFontAndSize(bflabel, 6);
                cb.SetTextMatrix(document.PageSize.Width - 250 - document.RightMargin + 3, document.BottomMargin + 25 - 21);
                cb.ShowText("Autor");

                cb.SetFontAndSize(bflabel, 7);
                cb.SetTextMatrix(document.PageSize.Width - 221 - document.RightMargin + 3, document.BottomMargin + 25 - 21);
                cb.ShowText(_panel.Author);

                cb.SetFontAndSize(bflabel, 6);
                cb.SetTextMatrix(document.PageSize.Width - 30 - document.RightMargin + 3, document.BottomMargin + 50 - 9);
                cb.ShowText("Versión");

                cb.SetFontAndSize(bflabel, 7);
                cb.SetTextMatrix(document.PageSize.Width - 30 - document.RightMargin + 3, document.BottomMargin + 50 - 21);
                cb.ShowText(_panel.Version);

                cb.SetFontAndSize(bflabel, 6);
                cb.SetTextMatrix(document.PageSize.Width - 125 - document.RightMargin + 3, document.BottomMargin + 25 - 14);
                cb.ShowText(Application.ProductName);

                cb.SetFontAndSize(bflabel, 6);
                cb.SetTextMatrix(document.PageSize.Width - 125 - document.RightMargin + 3, document.BottomMargin + 25 - 21);
                cb.ShowText(Application.CompanyName);

                cb.EndText();

                // Agrega una pequeña separación en el inicio del documento
                Phrase sep = new Phrase(" ");
                sep.Font = new iTextSharp.text.Font(bflabel, 4);
                document.Add(sep);

                // Genera la tabla que debe contener el panel de control
                PdfPTable table = new iTextSharp.text.pdf.PdfPTable(SelectedSchema.Columns);
                table.FooterRows                   = 0;
                table.HeaderRows                   = 0;
                table.WidthPercentage              = 98;
                table.DefaultCell.Padding          = 0;
                table.DefaultCell.UseBorderPadding = false;

                // Genera una imagen para usar en las celdas en blanco
                Bitmap blankbmp = new Bitmap(_library.BlockWidth, _library.BlockHeight);
                for (int i = 0; i < _library.BlockWidth; i++)
                {
                    for (int j = 0; j < _library.BlockHeight; j++)
                    {
                        blankbmp.SetPixel(i, j, _library.BgColor);
                    }
                }

                for (int y = 0; y < SelectedSchema.Rows; y++)
                {
                    for (int x = 0; x < SelectedSchema.Columns; x++)
                    {
                        try
                        {
                            // Obtiene el bloque de la celda actual
                            OTCPanelBlock block = SelectedSchema.GetBlock(x, y);

                            // Obtiene la imagen asociada
                            Bitmap bmp = _library.GetBlockImage(block.LibraryBlock.Id, OTCLibrary.ImageTypes.Bitmap, block.Rotation, OTCBlockStatus.None);

                            // Si es un bloque con dirección, la representa
                            if (ShowBlockInfo && block.LibraryBlock.Type != OTCLibraryBlock.BlockTypes.Static)
                            {
                                string text = "";

                                if (String.IsNullOrEmpty(block.Name))
                                {
                                    text = "ND";
                                }
                                else
                                {
                                    text = block.Name;
                                }

                                if (block.DigitalAddress > 0)
                                {
                                    text += " (" + block.DigitalAddress.ToString() + ")";
                                }

                                Bitmap   ibmp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                                Graphics ig   = Graphics.FromImage(ibmp);
                                ig.DrawImage((System.Drawing.Image)bmp, new Point(0, 0));

                                bmp.Dispose();

                                StringFormat strFormat = new StringFormat();
                                strFormat.Alignment     = StringAlignment.Center;
                                strFormat.LineAlignment = StringAlignment.Center;

                                ig.FillRectangle(Brushes.White, 2, ibmp.Height / 4, ibmp.Width - 4, ibmp.Height / 2);

                                ig.DrawString(text,
                                              new System.Drawing.Font("Tahoma", 8),
                                              Brushes.Black,
                                              new RectangleF(0, 0, ibmp.Width, ibmp.Height),
                                              strFormat);

                                bmp = ibmp;
                            }

                            // Agrega la celda
                            table.AddCell(iTextSharp.text.Image.GetInstance((System.Drawing.Image)bmp, iTextSharp.text.Color.WHITE));
                        }
                        catch (OTCBlockNotFoundException)
                        {
                            // Deja la celda vacía
                            table.AddCell(iTextSharp.text.Image.GetInstance((System.Drawing.Image)blankbmp, iTextSharp.text.Color.WHITE));
                        }
                    }
                }
                document.Add(table);

                // Cierra y genera el documento PDF
                document.Close();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
        /// <summary>
        /// Realiza la acción oportuna cuando el usuario hace un clic sobre el grid.
        /// </summary>
        private void grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // Evita lanzar eventos durante la representación del panel
            if (_drawing)
            {
                return;
            }

            if (_mode == PanelModes.Design)
            {
                if (!_routeEditing)
                {
                    switch (_currentDesignAction)
                    {
                    case DesignActions.Add:

                        if (String.IsNullOrEmpty(_addBlockType))
                        {
                            MessageBox.Show(this, "No se ha seleccionado el tipo de bloque a agregar.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        // Agrega un elemento al panel
                        int x = SelectedGrid.SelectedCells[0].ColumnIndex;
                        int y = SelectedGrid.SelectedCells[0].RowIndex;
                        SelectedSchema.AddBlock(x, y, _addBlockType);
                        break;

                    case DesignActions.Delete:

                        // Elimina un elemento del panel
                        if ((SelectedGrid.SelectedCells[0].Tag == null) || (SelectedGrid.SelectedCells[0].Tag.ToString().Equals("")))
                        {
                            _currentBlock = null;
                            return;
                        }
                        SelectedSchema.DeleteBlock(int.Parse(SelectedGrid.SelectedCells[0].Tag.ToString()), SelectedGrid);
                        break;

                    case DesignActions.Rotate:

                        // Gira un elemento del panel
                        if ((SelectedGrid.SelectedCells[0].Tag == null) || (SelectedGrid.SelectedCells[0].Tag.ToString().Equals("")))
                        {
                            _currentBlock = null;
                            return;
                        }
                        SelectedSchema.SetBlockRotation(int.Parse(SelectedGrid.SelectedCells[0].Tag.ToString()));
                        break;

                    case DesignActions.Pointer:

                        if (SelectedGrid.SelectedCells.Count == 0)
                        {
                            return;
                        }
                        if (_blockproperties == null)
                        {
                            return;
                        }

                        // Selecciona y muestra las propiedades de un elemento del panel
                        if ((SelectedGrid.SelectedCells[0].Tag == null) || (SelectedGrid.SelectedCells[0].Tag.ToString().Equals("")))
                        {
                            _blockproperties.Panel = null;
                            _blockproperties.Block = null;
                            return;
                        }

                        // Obtiene el bloque seleccionado
                        _blockproperties.Panel = _panel;
                        _blockproperties.Block = SelectedSchema.GetBlock(int.Parse(SelectedGrid.SelectedCells[0].Tag.ToString()));

                        break;
                    }
                }
                else
                {
                    // Edición de rutas activada

                    if (SelectedGrid.SelectedCells.Count == 0)
                    {
                        return;
                    }
                    if (_blockproperties == null)
                    {
                        return;
                    }

                    if ((SelectedGrid.SelectedCells[0].Tag == null) || (SelectedGrid.SelectedCells[0].Tag.ToString().Equals("")))
                    {
                        // Obtiene las direcciones posibles del elemento
                        // int directions = _panel.Library
                        MessageBox.Show("");

                        // Busca en la ruta que se está editando si existe el bloque seleccionado

                        // Si no existe, lo añade con el estado inicial

                        // Si existe, cambia el estado del elemento

                        // Muestra el bloque

                        return;
                    }
                }
            }
            else if (_mode == PanelModes.Operation)
            {
                // Cambia el estado de un elemento del panel
                if ((SelectedGrid.SelectedCells[0].Tag == null) || (SelectedGrid.SelectedCells[0].Tag.ToString().Equals("")))
                {
                    _currentBlock = null;
                    return;
                }

                // Obtiene el bloque
                OTCPanelBlock block = SelectedSchema.GetBlock(int.Parse(SelectedGrid.SelectedCells[0].Tag.ToString()));

                try
                {
                    // Establece el estado en el panel
                    SelectedSchema.SetBlockStatus(block.Id);
                }
                catch (Exception ex)
                {
                    OnError(new OTCInformationEventArgs(ex.Message), ex);
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Se produce cuando el usuario actualiza las propiedades de un bloque.
 /// </summary>
 private void BlockEditor_OnBlockUpdated(OTCSchemaEventArgs args)
 {
     SelectedSchema.Blocks[SelectedSchema.GetBlockIndex(args.Block.Id)] = args.Block;
 }