Beispiel #1
0
        private void HighlightNode(List <int> nodeNumbers)
        {
            using (Graphics g = Graphics.FromImage(_imgHighlight)) {
                g.Clear(Color.Transparent);

                _highlightedNodes = nodeNumbers;

                foreach (int nn in nodeNumbers)
                {
                    if (nn < 0)
                    {
                        //Draw transistor
                        using (Brush brush = new SolidBrush(Color.FromArgb(180, 255, 255, 255))) {
                            List <int> bb = _chipDef.Transistors[-nn + 1].bb;
                            DrawSegment(g, brush, new List <int> {
                                bb[0], bb[2], bb[1], bb[2], bb[1], bb[3], bb[0], bb[3]
                            }, false);
                        }
                    }
                    else if (_chipDef.Nodes[nn].segs.Count > 0)
                    {
                        //Draw node
                        Color color = CoreWrapper.isNodeHigh(nn) ? Color.FromArgb(180, 255, 0, 0) : Color.FromArgb(180, 255, 255, 255);
                        using (Brush brush = new SolidBrush(color)) {
                            foreach (List <int> segments in _chipDef.Nodes[nn].segs)
                            {
                                DrawSegment(g, brush, segments, false);
                            }
                        }
                    }
                }
            }
            _viewPortChanged = true;
        }
Beispiel #2
0
        public void RefreshState(bool async = false)
        {
            if (!_refreshingState && _showState)
            {
                Action updateState = () => {
                    _refreshingState = true;
                    lock (_imgHighNodes) {
                        using (Graphics g = Graphics.FromImage(_imgHighNodes)) {
                            g.Clear(Color.Transparent);
                            using (Brush brush = new SolidBrush(Color.FromArgb(100, 255, 0, 64))) {
                                foreach (node node in _chipDef.Nodes)
                                {
                                    if (node != null)
                                    {
                                        if (node.num != 1 && CoreWrapper.isNodeHigh(node.num))
                                        {
                                            foreach (List <int> segments in node.segs)
                                            {
                                                DrawSegment(g, brush, segments, false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    _needRefresh     = true;
                    _refreshingState = false;
                };

                if (async)
                {
                    Task.Run(updateState);
                }
                else
                {
                    updateState();
                }
            }
        }
Beispiel #3
0
        public void HighlightNode(List <int> nodeNumbers, bool focusOnSelection = false)
        {
            List <List <int> > segmentList = new List <List <int> >();

            using (Graphics g = Graphics.FromImage(_imgHighlight)) {
                g.Clear(Color.Transparent);

                foreach (int nn in nodeNumbers)
                {
                    if (nn < 0)
                    {
                        segmentList.Add(_chipDef.Transistors[-nn + 1].bb);

                        //Draw transistor
                        using (Brush brush = new SolidBrush(Color.FromArgb(180, 255, 255, 255))) {
                            List <int> bb = _chipDef.Transistors[-nn + 1].bb;
                            DrawSegment(g, brush, new List <int> {
                                bb[0], bb[2], bb[1], bb[2], bb[1], bb[3], bb[0], bb[3]
                            }, false);
                        }
                    }
                    else if (_chipDef.Nodes[nn].segs.Count > 0)
                    {
                        segmentList.AddRange(_chipDef.Nodes[nn].segs);

                        //Draw node
                        Color color = CoreWrapper.isNodeHigh(nn) ? Color.FromArgb(180, 255, 255, 255) : Color.FromArgb(180, 255, 255, 255);
                        using (Brush brush = new SolidBrush(color)) {
                            foreach (List <int> segments in _chipDef.Nodes[nn].segs)
                            {
                                DrawSegment(g, brush, segments, false);
                            }
                        }
                    }
                }
            }

            if (focusOnSelection && segmentList.Count > 0)
            {
                var xmin = segmentList[0][0];
                var xmax = segmentList[0][0];
                var ymin = segmentList[0][1];
                var ymax = segmentList[0][1];
                foreach (List <int> segments in segmentList)
                {
                    for (var i = 0; i < segments.Count; i += 2)
                    {
                        if (segments[i] < xmin)
                        {
                            xmin = segments[i];
                        }
                        if (segments[i] > xmax)
                        {
                            xmax = segments[i];
                        }
                        if (segments[i + 1] < ymin)
                        {
                            ymin = segments[i + 1];
                        }
                        if (segments[i + 1] > ymax)
                        {
                            ymax = segments[i + 1];
                        }
                    }
                }

                ZoomToBox(xmin, xmax, ymin, ymax);
            }

            _viewPortChanged = true;
        }