Exemplo n.º 1
0
        /**************************************************************************************************/
        public PedigreeControl()
        {
            InitializeComponent();

            FHxQueue = new Queue<RiskApps3.Model.PatientRecord.FHx.FamilyHistory>();

            this.DoubleBuffered = true;

            ModelConvergedDelegate = ModelConverged;

            at.SpawnAnimationThread
            (
                delegate()
                {
                    if (model != null && controller != null)
                    {
                        controller.IncrementLayout();
                        if (controller.LayoutComplete)
                        {
                            if (CloseFormCallback != null)
                            {
                                CloseFormCallback.Invoke();
                            }
                        }
                    }

                    this.Refresh();

                    return continueAnimation;
                }
            );

            /**************************************************************************************************/
            MouseDown += new MouseEventHandler(delegate(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    RightClickTimer.Enabled = true;
                }

                //PushPositionHistory();

                if (model != null)
                {
                    model.io.mouseX = e.X;
                    model.io.mouseY = e.Y;
                    model.io.mouseDown = true;
                    model.io.button = e.Button;
                }

                //PointWithVelocity pointUnderCursor = GetPointUnderCursor(model, e.X, e.Y);
                PedigreeIndividual underCursor = PedigreeUtils.GetIndividualUnderPoint(model, e.X, e.Y);

                if (underCursor != null)
                {
                    if (model.Selected.Count > 1)
                    {
                        foreach (PedigreeIndividual pi in model.Selected)
                        {
                            model.pointsBeingDragged.Add(pi.point);
                        }
                        if (!(model.pointsBeingDragged.Contains(underCursor.point)))
                        {
                            model.pointsBeingDragged.Clear();
                        }
                    }
                    else
                    {
                        if (underCursor.Group == null)
                        {
                            model.pointsBeingDragged.Add(underCursor.point);
                        }
                        else
                        {
                            foreach (PedigreeIndividual gm in underCursor.Group)
                            {
                                model.pointsBeingDragged.Add(gm.point);
                            }
                        }
                    }
                }

            });

            /**************************************************************************************************/
            MouseClick += new MouseEventHandler(delegate(object sender, MouseEventArgs e)
            {

            });

            /**************************************************************************************************/
            MouseUp += new MouseEventHandler(delegate(object sender, MouseEventArgs e)
            {

                if (model.SelectionLasso.Count > 0)
                {
                    Polygon poly = new Polygon(model.SelectionLasso.ToArray());

                    model.Selected.Clear();
                    foreach (PedigreeIndividual pi in model.individuals)
                    {
                        if (!model.parameters.hideNonBloodRelatives || pi.bloodRelative)
                        {
                            System.Drawing.Point scaled = new System.Drawing.Point((int)pi.point.x, (int)pi.point.y);

                            scaled.X += model.parameters.hOffset;
                            scaled.Y += model.parameters.vOffset;

                            scaled.X = (int)(model.parameters.scale * (double)scaled.X);
                            scaled.Y = (int)(model.parameters.scale * (double)scaled.Y);

                            if (poly.Contains(scaled))
                            {
                                pi.Selected = true;
                                if (model.Selected.Contains(pi) == false)
                                {
                                    model.Selected.Add(pi);
                                    model.pointsBeingDragged.Add(pi.point);
                                }
                            }
                            else
                            {
                                pi.Selected = false;
                            }
                        }
                    }
                }
                else
                {

                    PedigreeIndividual individual = PedigreeUtils.GetIndividualUnderPoint(model, (e.X), (e.Y));
                    if (individual != null)
                    {
                        if (individual.Selected == false)
                        {
                            foreach (PedigreeIndividual pi in model.Selected)
                            {
                                pi.Selected = false;
                            }
                            model.Selected.Clear();

                            if (individual.Group == null)
                            {
                                if (SelectedIndividualCallback != null)
                                {
                                    SelectedIndividualCallback.Invoke(individual.HraPerson);
                                }
                                individual.Selected = true;
                                if (model.Selected.Contains(individual) == false)
                                    model.Selected.Add(individual);
                            }
                            else
                            {
                                if (SelectedIndividualCallback != null)
                                {
                                    SelectedIndividualCallback.Invoke(null);
                                }
                                foreach (PedigreeIndividual gm in individual.Group)
                                {
                                    gm.Selected = true;
                                    if (model.Selected.Contains(gm) == false)
                                        model.Selected.Add(gm);
                                }
                            }
                        }
                    }
                    else
                    {
                        //if (currentPrefs != null)
                        //{
                        //    currentPrefs.GUIPreference_xOffset = model.parameters.hOffset;
                        //    currentPrefs.GUIPreference_yOffset = model.parameters.vOffset;
                        //}
                        if (SelectedIndividualCallback != null)
                        {
                            SelectedIndividualCallback.Invoke(null);
                        }
                        foreach (PedigreeIndividual pi in model.Selected)
                        {
                            pi.Selected = false;
                        }
                        model.Selected.Clear();
                    }
                }

                if (e.Button == MouseButtons.Right)
                {
                    if (RightClickTimer.Enabled)
                    {
                        RightClickTimer.Enabled = false;
                        ShowContextMenu(e);

                        if (model.Selected.Count == 1)
                        {
                            if (model.Selected[0].HraPerson.PMH.Observations.Count > 0)
                            {
                                removeToolStripMenuItem.Enabled = true;
                                foreach (ClincalObservation co in model.Selected[0].HraPerson.PMH.Observations)
                                {
                                    ToolStripMenuItem tsmi = new ToolStripMenuItem();
                                    tsmi.Text = co.disease;
                                    if (string.IsNullOrEmpty(co.ageDiagnosis) == false)
                                    {
                                        tsmi.Text += " @ " + co.ageDiagnosis;
                                    }
                                    removeToolStripMenuItem.DropDownItems.Add(tsmi);
                                    tsmi.Tag = co;
                                    tsmi.Click += new System.EventHandler(RemoveCoClick);
                                }
                            }
                            else
                            {
                                removeToolStripMenuItem.Enabled = false;
                            }
                        }
                        else
                        {
                            removeToolStripMenuItem.Enabled = false;
                        }
                    }
                    else
                    {
                        //removeToolStripMenuItem.Enabled = false;
                    }
                }

                if (model != null)
                {
                    model.io.mouseX = e.X;
                    model.io.mouseY = e.Y;
                    model.io.mouseDown = false;
                    model.io.button = e.Button;
                }

                if (model.pointsBeingDragged.Count > 0)
                {
                    PushPositionHistory();

                    foreach (PedigreeIndividual p in model.individuals)
                    {
                        if (model.pointsBeingDragged.Contains(p.point))
                        {
                            bool changed = false;

                            double tempXpos = 800 / (p.point.x - ((model.displayXMax - 800) / 2));
                            double tempYpos = 600 / (p.point.y - ((model.displayYMax - 600) / 2));
                            int tempXnorm = (int)(p.point.x - (model.displayXMax / 2));
                            int tempYnorm = (int)(p.point.y - (model.displayYMax / 2));

                            if (tempXpos != p.HraPerson.x_position)
                            {
                                p.HraPerson.x_position = tempXpos;
                                changed = true;
                            }
                            if (tempYpos != p.HraPerson.y_position)
                            {
                                p.HraPerson.y_position = tempYpos;
                                changed = true;
                            }
                            if (tempXnorm != p.HraPerson.x_norm)
                            {
                                p.HraPerson.x_norm = tempXnorm;
                                changed = true;
                            }
                            if (tempYnorm != p.HraPerson.y_norm)
                            {
                                p.HraPerson.y_norm = tempYnorm;
                                changed = true;
                            }
                            if (changed)
                            {
                                HraModelChangedEventArgs args = new RiskApps3.Model.HraModelChangedEventArgs((HraView)(this.Parent));
                                if (p.HraPerson.x_position > float.MinValue && p.HraPerson.x_position < float.MaxValue)
                                {
                                    foreach (MemberInfo mi in p.HraPerson.GetType().GetMember("x_*"))
                                    {
                                        args.updatedMembers.Add(mi);
                                    }
                                }
                                if (p.HraPerson.y_position > float.MinValue && p.HraPerson.y_position < float.MaxValue)
                                {
                                    foreach (MemberInfo mi in p.HraPerson.GetType().GetMember("y_*"))
                                    {
                                        args.updatedMembers.Add(mi);
                                    }
                                }
                                p.HraPerson.SignalModelChanged(args);
                            }
                        }
                    }
                }

                if (model.RelativesToLink.Count > 0)
                {
                    LinkToSelected();

                    model.RelativesToLink.Clear();
                    PushPositionHistory();
                    SavePositions(true);
                    SetPedigreeFromFHx(model.familyHistory);
                }

                model.pointsBeingDragged.Clear();

                model.SelectionLasso.Clear();

            });

            /**************************************************************************************************/
            MouseMove += new MouseEventHandler(delegate(object sender, MouseEventArgs e)
            {
                if (model != null)
                {
                    if (model.io.mouseDown)
                    {
                        if (!(model.pointsBeingDragged.Count > 0))
                        {
                            if (model.parameters.multiSelect)
                            {
                                model.SelectionLasso.Add(e.Location);
                            }
                            else
                            {
                                model.parameters.hOffset += (int)((System.Convert.ToDouble(e.X) - (model.io.mouseX)) / model.parameters.scale);
                                model.parameters.vOffset += (int)((System.Convert.ToDouble(e.Y) - (model.io.mouseY)) / model.parameters.scale);
                            }
                        }
                        else
                        {
                            foreach (PointWithVelocity point in model.pointsBeingDragged)
                            {
                                point.x += ((e.X - model.io.mouseX) / model.parameters.scale);
                                point.y += ((e.Y - model.io.mouseY) / model.parameters.scale);
                            }
                        }
                    }
                    model.io.mouseX = e.X;
                    model.io.mouseY = e.Y;
                }
            });
        }
Exemplo n.º 2
0
Arquivo: Pan.cs Projeto: mahitosh/HRA4
        public Pan(PedigreeModel model)
        {
            step = delegate()
            {

                //if the mouse was pressed and there were no couples being dragged,
                //drag the one under the mouse point.
                if (model.io.mousePressed)
                {
                    double x = model.io.mouseX;
                    double y = model.io.mouseY;
                    PointWithVelocity pointUnderCursor = GetPointUnderCursor(model, x, y);
                    if (pointUnderCursor == null)
                    {
                        x1 = x; y1 = y;
                        hOffset1 = model.parameters.hOffset;
                        vOffset1 = model.parameters.vOffset;
                        panInProgress = true;
                        //model.parameters.multiSelect = true;
                    }
                }
                else if (model.io.mouseReleased)
                {
                    if (model.SelectionLasso.Count > 3)
                    {
                        model.Selected.Clear();
                        Polygon p = new Polygon(model.SelectionLasso.ToArray());
                        foreach (PedigreeIndividual pi in model.individuals)
                        {
                            System.Drawing.Point scaled = new System.Drawing.Point((int)pi.point.x, (int)pi.point.y);

                            scaled.X += model.parameters.hOffset;
                            scaled.Y += model.parameters.vOffset;

                            scaled.X = (int)(model.parameters.scale * (double)scaled.X);
                            scaled.Y = (int)(model.parameters.scale * (double)scaled.Y);

                            pi.Selected = false;
                            if (p.Contains(scaled))
                            {
                                pi.Selected = true;
                                if(model.Selected.Contains(pi) == false)
                                    model.Selected.Add(pi);
                            }
                        }
                    }
                    else
                    {
                        //PedigreeIndividual s = PedigreeUtils.GetIndividualUnderPoint(model, x1, y1);
                        //if (s != null)
                        //{
                        //    s.Selected = true;
                        //    if(model.Selected.Contains(s) == false)
                        //            model.Selected.Add(s);
                        //}
                    }
                    model.parameters.multiSelect = false;
                    panInProgress = false;
                    model.SelectionLasso.Clear();

                }
                else if (panInProgress)
                {
                    double x2 = model.io.mouseX;
                    double y2 = model.io.mouseY;

                    if (model.parameters.multiSelect)
                    {
                        model.SelectionLasso.Add(new System.Drawing.Point((int)x2, (int)y2));
                    }
                    else
                    {
                        model.parameters.hOffset = (int)(hOffset1 + x2 - x1);
                        model.parameters.vOffset = (int)(vOffset1 + y2 - y1);
                    }
                }
            };
        }