Ejemplo n.º 1
0
        /// <summary>
        /// This method draws a rectangular grid with gridFactor divided length.
        /// </summary>
        private void DrawRectangularGrid()
        {
            int widthData  = Document.ActiveDocument.ExperimentSettings.WidthStimulusScreen;
            int heightData = Document.ActiveDocument.ExperimentSettings.HeightStimulusScreen;

            float xDistance = (widthData - 2) / (float)this.gridFactor;
            float yDistance = (heightData - 2) / (float)this.gridFactor;

            // For each row
            for (int i = 0; i < this.gridFactor; i++)
            {
                // For each column
                for (int j = 0; j < this.gridFactor; j++)
                {
                    // Create a rectangle with a new string index
                    RectangleF  bounds = new RectangleF(j * xDistance, i * yDistance, xDistance, yDistance);
                    VGRectangle rect   = new VGRectangle(
                        ShapeDrawAction.NameAndEdge,
                        new Pen(Color.Gray, 1.0f),
                        new Font(VGRectangle.DefaultFont.FontFamily, 14.0f),
                        Color.Gray,
                        bounds,
                        VGStyleGroup.SCA_GRID_RECTANGLE,
                        currentIdentifierList[i * this.gridFactor + j],
                        string.Empty);

                    this.Elements.Add(rect);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method creates a rectangular grid of AOI named from
        ///   A-Z or Aa to Zz depending on grid size.
        ///   The given <see cref="DataGridView"/> supplies the names
        ///   and the number of rows and columns.
        /// </summary>
        /// <param name="dataGridView">
        /// A <see cref="DataGridView"/>
        ///   with the named rows and columns for the new rectangular AOI grid.
        /// </param>
        public void CreateAOIGrid(DataGridView dataGridView)
        {
            try
            {
                // Calculate grid sizes
                var numRows    = dataGridView.Rows.Count;
                var numColumns = dataGridView.Columns.Count;
                var cellHeight = (float)Document.ActiveDocument.PresentationSize.Height / numRows;
                var cellWidth  = (float)Document.ActiveDocument.PresentationSize.Width / numColumns;

                // Iterate through data grid view and creat for each cell a rectangular AOI
                for (var i = 0; i < numRows; i++)
                {
                    for (var j = 0; j < numColumns; j++)
                    {
                        // Calculate grid cell bounds.
                        var boundingRect = new RectangleF();
                        boundingRect.Y      = i * cellHeight;
                        boundingRect.X      = j * cellWidth;
                        boundingRect.Width  = cellWidth;
                        boundingRect.Height = cellHeight;

                        // Create Rect with default stroke
                        var newRect = new VGRectangle(
                            this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                            this.DefaultPen,
                            this.DefaultFonts,
                            this.DefaultFontColor,
                            boundingRect,
                            VGStyleGroup.AOI_NORMAL,
                            dataGridView.Rows[i].Cells[j].Value.ToString(),
                            string.Empty);
                        newRect.TextAlignment = this.DefaultTextAlignment;
                        this.AoiCollection.Add(newRect);

                        // Raise event
                        base.OnShapeAdded(new ShapeEventArgs(newRect));
                    }
                }

                this.DrawForeground(true);
            }
            catch (Exception ex)
            {
                ExceptionMethods.HandleException(ex);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This static method calculates the bounding rectangle for the thumb of
        /// the list view item and creates a <see cref="BufferedGraphics"/> for the drawing.
        /// </summary>
        /// <param name="g">Ref. The <see cref="Graphics"/> to be drawn to.</param>
        /// <param name="r">The <see cref="Rectangle"/> with the bounds of the list view item.</param>
        /// <param name="buffered">Out. <see cref="BufferedGraphics"/> to be used for drawing.</param>
        /// <returns>The bounding <see cref="Rectangle"/> for the thumb of
        /// the list view item</returns>
        protected Rectangle GetThumbRect(ref Graphics g, Rectangle r, out BufferedGraphics buffered)
        {
            Rectangle boundsWithoutPadding = r;

            boundsWithoutPadding.Inflate(2, 2);

            // Use buffered graphics to kill flickers
            buffered = BufferedGraphicsManager.Current.Allocate(g, boundsWithoutPadding);
            g        = buffered.Graphics;
            g.Clear(this.ListView.BackColor);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Rectangle bounds = r;

            // Allow a border around the item
            bounds.Inflate(-2, -2);

            // Draw background
            if (this.IsItemSelected)
            {
                Pen          focusPen         = new Pen(Color.Red, 2.0f);
                GraphicsPath roundedRectangle = VGRectangle.GetRoundedRect(bounds, 5f);
                g.FillPath(new SolidBrush(Color.FromArgb(125, Color.Gray)), roundedRectangle);
                g.DrawPath(focusPen, roundedRectangle);
            }

            // Draw the Image
            Size thumbsSize = this.ListView.TileSize;

            thumbsSize.Width  -= 15;
            thumbsSize.Height -= 40;
            Rectangle thumbRect = new Rectangle(
                new Point(bounds.X + bounds.Width / 2 - thumbsSize.Width / 2, bounds.Y + SPACING),
                thumbsSize);

            return(thumbRect);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the shapes that are listed in the given database table
        ///   and creates corresponding graphic elements.
        /// </summary>
        /// <param name="areaOfInterestTableRows">
        /// Areas of interest table as
        ///   a <see cref="DataGridViewRowCollection"/>
        /// </param>
        public void LoadShapesFromDataGridView(DataGridViewRowCollection areaOfInterestTableRows)
        {
            try
            {
                // Create aoi elements from data view
                this.AoiCollection = new VGElementCollection();

                foreach (DataGridViewRow row in areaOfInterestTableRows)
                {
                    if (!row.IsNewRow)
                    {
                        // retrieve shape parameters from cell values.
                        var          shapeName = row.Cells["colShapeName"].Value.ToString();
                        var          strPtList = row.Cells["colShapePts"].Value.ToString();
                        Pen          usedPen;
                        Font         usedFont;
                        Color        usedFontColor;
                        VGAlignment  usedAlignment;
                        VGStyleGroup usedStyleGroup;
                        var          pointList        = ObjectStringConverter.StringToPointFList(strPtList);
                        var          usedElementGroup = row.Cells["colShapeGroup"].Value.ToString();
                        switch (usedElementGroup)
                        {
                        case "Target":
                            usedPen        = this.TargetPen;
                            usedFont       = this.TargetFont;
                            usedFontColor  = this.TargetFontColor;
                            usedStyleGroup = VGStyleGroup.AOI_TARGET;
                            usedAlignment  = this.TargetTextAlignment;
                            break;

                        case "SearchRect":
                            usedPen        = this.SearchRectPen;
                            usedFont       = this.SearchRectFont;
                            usedFontColor  = this.SearchRectFontColor;
                            usedStyleGroup = VGStyleGroup.AOI_SEARCHRECT;
                            usedAlignment  = this.SearchRectTextAlignment;
                            break;

                        default:
                            usedPen        = this.DefaultPen;
                            usedFont       = this.DefaultFonts;
                            usedFontColor  = this.DefaultFontColor;
                            usedStyleGroup = VGStyleGroup.AOI_NORMAL;
                            usedAlignment  = this.DefaultTextAlignment;
                            break;
                        }

                        // Create the shape depending on ShapeType
                        var boundingRect = new RectangleF();
                        switch (row.Cells["colShapeType"].Value.ToString())
                        {
                        case "Rectangle":
                            boundingRect.Location = pointList[0];
                            boundingRect.Width    = pointList[2].X - pointList[0].X;
                            boundingRect.Height   = pointList[2].Y - pointList[0].Y;

                            // Create Rect with defined stroke
                            var newRect =
                                new VGRectangle(
                                    this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                                    usedPen,
                                    usedFont,
                                    usedFontColor,
                                    boundingRect,
                                    usedStyleGroup,
                                    shapeName,
                                    usedElementGroup);
                            newRect.TextAlignment = usedAlignment;
                            this.AoiCollection.Add(newRect);
                            break;

                        case "Ellipse":
                            boundingRect.Location = pointList[0];
                            boundingRect.Width    = pointList[2].X - pointList[0].X;
                            boundingRect.Height   = pointList[2].Y - pointList[0].Y;

                            // Create Rect with defined stroke
                            var newEllipse =
                                new VGEllipse(
                                    this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                                    usedPen,
                                    usedFont,
                                    usedFontColor,
                                    boundingRect,
                                    usedStyleGroup,
                                    shapeName,
                                    usedElementGroup);
                            newEllipse.TextAlignment = usedAlignment;
                            this.AoiCollection.Add(newEllipse);
                            break;

                        case "Polyline":

                            // Create Polyline with defined stroke
                            var newPolyline =
                                new VGPolyline(
                                    this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                                    usedPen,
                                    usedFont,
                                    usedFontColor,
                                    usedStyleGroup,
                                    shapeName,
                                    usedElementGroup);
                            newPolyline.TextAlignment = usedAlignment;
                            foreach (var point in pointList)
                            {
                                newPolyline.AddPt(point);
                            }

                            newPolyline.ClosePolyline();
                            this.AoiCollection.Add(newPolyline);
                            break;
                        }
                    }
                }

                // Reset Elements (deselect and clear all)
                this.ResetPicture();

                this.Elements.AddRange(this.AoiCollection);

                // If there were a selected element before updating, try
                // to select it again.
                if (this.SelectedElement != null)
                {
                    foreach (VGElement element in this.Elements)
                    {
                        if (VGPolyline.Distance(element.Location, this.SelectedElement.Location) < 1)
                        {
                            this.SelectedElement = element;
                            element.IsInEditMode = true;
                        }
                    }
                }

                this.DrawForeground(true);
            }
            catch (Exception ex)
            {
                ExceptionMethods.HandleException(ex);
            }
        }
Ejemplo n.º 5
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Methods and Eventhandling for Background tasks                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region BACKGROUNDWORKER
        #endregion //BACKGROUNDWORKER

        ///////////////////////////////////////////////////////////////////////////////
        // Inherited methods                                                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region OVERRIDES
        #endregion //OVERRIDES

        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region METHODS

        /// <summary>
        /// This method creates the shape that is defined in this dialog to be added to a slide.
        /// </summary>
        /// <returns>The ready to use <see cref="VGElement"/>.</returns>
        private VGElement GenerateNewShape()
        {
            VGElement element = null;

            if (this.rdbRectangle.Checked)
            {
                element = new VGRectangle(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewBrush,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    new RectangleF(0, 0, 100, 100),
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbEllipse.Checked)
            {
                element = new VGEllipse(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewBrush,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    new RectangleF(0, 0, 100, 100),
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbPolyline.Checked)
            {
                element = new VGPolyline(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewBrush,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbSharp.Checked)
            {
                element = new VGSharp(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    new RectangleF(0, 0, 100, 100),
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbLine.Checked)
            {
                element = new VGLine(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }

            element.Sound = this.audioControl.Sound;

            return(element);
        }