Ejemplo n.º 1
0
            private void tracePath(int from, int to, List <VectorLine> lines, List <VectorPath> vp, VectorPath start, List <int> startl)
            {
                if (from == to)
                {
                    // On the final line
                    VectorPath ep = new VectorPath(start);
                    ep.addPoint(lines[to].B);
                    vp.Add(ep);
                    return;
                }

                // Check for intersections
                for (int i = 0; i < lines.Count; i++)
                {
                    if ((i != from) && (startl.IndexOf(i) < 0))
                    {
                        Vector ip = Vector.Zero;
                        if (VectorLine.intersect(lines[from], lines[i], ref ip))
                        {
                            // Lines intersect!
                            bool isavalidline = true;
                            if (isavalidline && (startl.Count > 1) && _VA.nonZero && _VA.inside(ip))
                            {
                                isavalidline = false;
                            }
                            if (isavalidline && _VB.nonZero && _VB.inside(ip))
                            {
                                isavalidline = false;
                            }
                            VectorLine nl = new VectorLine(start.list.Last(), ip, VectorLine.LineType.AB);
                            if (isavalidline && (startl.Count > 1) && _VA.nonZero && _VA.Intersects(nl))
                            {
                                isavalidline = false;
                            }
                            if (isavalidline && _VB.nonZero && _VB.Intersects(nl))
                            {
                                isavalidline = false;
                            }
                            if (isavalidline)
                            {
                                VectorPath ep      = new VectorPath(start);
                                List <int> startlx = new List <int>(startl);
                                startlx.Add(i);
                                ep.addPoint(ip);
                                tracePath(i, to, lines, vp, ep, startlx);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 2
0
 public bool inside(VectorRect vr)
 {
     if ((list == null) || (list.Count < 1))
     {
         return(false);
     }
     foreach (Vector v in list)
     {
         if (!vr.inside(v))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
 public void selectOnHit(Vector hv, APSelection sel)
 {
     if (_isNamed)
     {
         bool selected = false;
         foreach (RTIO io in connectedIOs)
         {
             if (!selected)
             {
                 Vector pstart, pstop, textpos, textdir;
                 getNamedPoints(io, out pstart, out pstop, out textpos, out textdir);
                 Vector vv = textpos +
                             Vector.V(textdir.y, -textdir.x) * owner.Font.Height * owner.scale;
                 VectorRect vx = VectorRect.containingThreePoints(pstart, pstop, vv);
                 if (vx.inside(owner.toScreen(hv)))
                 {
                     selected = true;
                 }
             }
         }
         if (selected)
         {
             foreach (ProcessingConnection pc in connections)
             {
                 pc.selected = true;
             }
             sel.select(this);
         }
     }
     else
     {
         updateConnections();
         Vector ps = owner.toScreen(hv);
         for (int i = 0; i < connections.Count; i++)
         {
             if (connections[i].bc.linedist(ps) < 10)
             {
                 sel.select(this, i);
             }
         }
     }
 }
Ejemplo n.º 4
0
        public void selectOnContained(VectorRect vr, APSelection sel)
        {
            VectorRect  rf;
            SystemPanel p = owner;

            if (p == null)
            {
                return;
            }
            if (_shrinked)
            {
                Vector dimS = Vector.V(_shrinkSize.Width, _shrinkSize.Height);
                rf = VectorRect.FromCenterSize(center, dimS);
            }
            else
            {
                rf = VectorRect.FromCenterSize(center, dim);
            }
            if (vr.inside(rf))
            {
                sel.select(this);
            }
        }
Ejemplo n.º 5
0
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            base.OnMouseWheel(e);

            GraphicsUtil.TextPosition titlePos = new GraphicsUtil.TextPosition();
            GraphicsUtil.TextPosition valuePos = new GraphicsUtil.TextPosition();
            VectorRect bar    = new VectorRect();
            VectorRect handle = new VectorRect();
            Vector     vlow   = Vector.Zero;
            Vector     vhigh  = Vector.Zero;

            getPositions(ref titlePos, ref valuePos, ref bar, ref handle, ref vlow, ref vhigh);

            VectorRect vr = VectorRect.containingRects(bar, handle);

            if (vr.inside(e.X, e.Y))
            {
                ((HandledMouseEventArgs)e).Handled = true;
                if (_logScale)
                {
                    if ((_minVal <= 0) || (_maxVal <= 0) || (_maxVal == _minVal))
                    {
                        return;
                    }
                    if (_val <= 0)
                    {
                        return;
                    }
                    double v = Math.Log(_val) + (double)e.Delta / 2000 * (Math.Log(_maxVal) - Math.Log(_minVal));
                    if (v < Math.Log(_minVal))
                    {
                        v = Math.Log(_minVal);
                    }
                    if (v > Math.Log(_maxVal))
                    {
                        v = Math.Log(_maxVal);
                    }
                    _val = Math.Exp(v);
                    Invalidate();
                    newValue();
                }
                else
                {
                    if (_minVal >= _maxVal)
                    {
                        return;
                    }
                    double v = _val + (double)e.Delta / 2000 * (_maxVal - _minVal);
                    if (v < _minVal)
                    {
                        v = _minVal;
                    }
                    if (v > _maxVal)
                    {
                        v = _maxVal;
                    }
                    _val = v;
                    Invalidate();
                    newValue();
                }
            }
            else
            {
                forwardOnMouseWheel(e);
            }
        }
Ejemplo n.º 6
0
        // private static double sqr(double s) { return s * s; }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            double scl = scale;

            if ((e.X < 0) || (e.X >= Width) || (e.Y < 0) || (e.Y >= Height))
            {
                return;
            }

            if (_showValue && e.Y >= Height - 1 - valueFont.Height * scale)
            {
                // Hit in Value
                // Show Value Selector Window
                NumericInputWin dw = new NumericInputWin(this,
                                                         ((_title != null) && (_title.Length > 0)) ? _title : null,
                                                         ((_unit != null) && (_unit.Length > 0)) ? _unit : null,
                                                         getFormat(), true, _minVal, _val, _maxVal, _logScale);
                dw.StartPosition = FormStartPosition.Manual;
                dw.Location      = PointToScreen(e.Location);
                dw.ShowDialog();
                _val = dw.value;
                newValue();
                Invalidate();
                return;
            }

            GraphicsUtil.TextPosition titlePos = new GraphicsUtil.TextPosition();
            GraphicsUtil.TextPosition valuePos = new GraphicsUtil.TextPosition();
            VectorRect bar    = new VectorRect();
            VectorRect handle = new VectorRect();
            Vector     vlow   = Vector.Zero;
            Vector     vhigh  = Vector.Zero;

            getPositions(ref titlePos, ref valuePos, ref bar, ref handle, ref vlow, ref vhigh);


            VectorRect vr = VectorRect.containingRects(bar, handle);

            if (vr.inside(e.X, e.Y))
            {
                // Hit in Dial Region
                double n = 0;
                if (_slideDirection == SlideDirection.Horizontal)
                {
                    n = (e.X - vlow.x) / (vhigh.x - vlow.x);
                }
                else
                {
                    n = (e.Y - vlow.y) / (vhigh.y - vlow.y);
                }
                if (n < 0)
                {
                    n = 0;
                }
                if (n > 1.0)
                {
                    n = 1;
                }

                if (logScale)
                {
                    if ((_minVal <= 0) || (_maxVal <= 0) || (_minVal == _maxVal))
                    {
                        _val = _minVal;
                    }
                    else
                    {
                        _val = Math.Exp(n * (Math.Log(_maxVal) - Math.Log(_minVal)) + Math.Log(_minVal));
                    }
                }
                else
                {
                    _val = n * (_maxVal - _minVal) + _minVal;
                }
                newValue();
                Invalidate();
                dragMode  = DragMode.Dial;
                dragStart = e.Location;
            }
            else
            {
                forwardOnMouseDown(e);
            }
        }