예제 #1
0
        public override void Draw(CustomGraphics g)
        {
            drawLead(mPoint1, mLead1);
            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.WhiteColor;
            var str      = Text;
            var lineOver = false;

            if (str.StartsWith("/"))
            {
                lineOver = true;
                str      = str.Substring(1);
            }
            drawCenteredText(str, P2, true);
            if (lineOver)
            {
                int asc = (int)CustomGraphics.FontText.Size;
                if (lineOver)
                {
                    int ya = P2.Y - asc;
                    int sw = (int)g.GetTextSize(str).Width;
                    g.DrawLine(P2.X - sw / 2, ya, P2.X + sw / 2, ya);
                }
            }
            mCurCount = updateDotCount(mCurrent, mCurCount);
            drawDots(mPoint1, mLead1, mCurCount);
            interpPoint(ref mPos, 1 + 11.0 / mLen);
            setBbox(mPoint1, mPos, CircleSize);
            drawPosts();
        }
예제 #2
0
        public override void Draw(CustomGraphics g)
        {
            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
            g.DrawPolygon(mRectPoints);

            /* draw stubs */
            for (int i = 0; i != 4; i++)
            {
                var a = posts[i];
                var b = mStubs[i];
                drawLead(a, b);
                mCurCounts[i] = updateDotCount(-GetCurrentIntoNode(i), mCurCounts[i]);
                drawDots(a, b, mCurCounts[i]);
            }

            mDiode.Draw(g);
            mTransistor.Draw(g);

            drawPosts();

            /* draw little arrows */
            var c = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;

            g.FillPolygon(c, mArrow1);
            g.FillPolygon(c, mArrow2);
            g.LineColor = c;
            int sx = mStubs[0].X + 2;
            int sy = (mStubs[0].Y + mStubs[1].Y) / 2;

            for (int i = 0; i != 2; i++)
            {
                int y = sy + i * 10 - 5;
                g.DrawLine(sx + 10, y, sx + 15, y);
            }
        }
예제 #3
0
        public override void Draw(CustomGraphics g)
        {
            drawLead(mPtEnds[0], mPtCoil[0]);
            drawLead(mPtEnds[1], mPtCoil[1]);
            drawLead(mPtEnds[2], mPtCoil[2]);
            drawLead(mPtEnds[3], mPtCoil[3]);

            drawCoil(mPtCoil[0], mPtCoil[2], Volts[PRI_T], Volts[PRI_B], 90 * mDsign);
            drawCoil(mPtCoil[1], mPtCoil[3], Volts[SEC_T], Volts[SEC_B], -90 * mDsign * mPolarity);

            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
            g.DrawLine(mPtCore[0], mPtCore[2]);
            g.DrawLine(mPtCore[1], mPtCore[3]);
            if (mDots != null)
            {
                g.DrawCircle(mDots[0], 2.5f);
                g.DrawCircle(mDots[1], 2.5f);
            }

            mCurCounts[0] = updateDotCount(mCurrents[0], mCurCounts[0]);
            mCurCounts[1] = updateDotCount(mCurrents[1], mCurCounts[1]);
            for (int i = 0; i != 2; i++)
            {
                drawDots(mPtEnds[i], mPtCoil[i], mCurCounts[i]);
                drawDots(mPtCoil[i], mPtCoil[i + 2], mCurCounts[i]);
                drawDots(mPtEnds[i + 2], mPtCoil[i + 2], -mCurCounts[i]);
            }

            drawPosts();
            setBbox(mPtEnds[0], mPtEnds[mPolarity == 1 ? 3 : 1], 0);

            if (ControlPanel.ChkShowName.Checked)
            {
                g.DrawLeftText(ReferenceName, mNamePos.X, mNamePos.Y);
            }
        }
예제 #4
0
 public void drawChip(CustomGraphics g)
 {
     for (int i = 0; i != PostCount; i++)
     {
         var p = pins[i];
         var a = p.post;
         var b = p.stub;
         drawLead(a, b);
         p.curcount = updateDotCount(p.current, p.curcount);
         drawDots(b, a, p.curcount);
         if (p.bubble)
         {
             g.LineColor = Color.White;
             g.DrawCircle(p.bubblePos, 1);
             g.LineColor = CustomGraphics.GrayColor;
             g.DrawCircle(p.bubblePos, 3);
         }
         g.LineColor = p.selected ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
         int fsz  = 12 * csize;
         var font = CustomGraphics.FontText;
         while (true)
         {
             int sw = (int)g.GetTextSize(p.text, font).Width;
             /* scale font down if it's too big */
             if (sw > 12 * csize)
             {
                 fsz--;
                 font = new Font(CustomGraphics.FontText.Name, fsz);
                 continue;
             }
             g.DrawCenteredText(p.text, p.textloc.X, p.textloc.Y, font);
             if (p.lineOver)
             {
                 int ya = p.textloc.Y;
                 g.DrawLine(p.textloc.X - sw / 2, ya, p.textloc.X + sw / 2, ya);
             }
             break;
         }
     }
     g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
     g.DrawPolygon(rectPoints);
     if (clockPoints != null)
     {
         g.DrawPolygon(clockPoints);
     }
     drawPosts();
 }
예제 #5
0
        public override void Draw(CustomGraphics g)
        {
            int hs1 = (Position == 1) ? 0 : 2;
            int hs2 = (Position == 1) ? OPEN_HS : 2;

            setBbox(mPoint1, mPoint2, OPEN_HS);
            draw2Leads();
            if (Position == 0)
            {
                doDots();
            }
            interpLead(ref mP1, 0, hs1);
            interpLead(ref mP2, 1, hs2);
            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.WhiteColor;
            g.DrawLine(mP1, mP2);
            drawPosts();
        }
예제 #6
0
        public override void Draw(CustomGraphics g)
        {
            int hs = mIsOpen ? OPEN_HS : 0;

            setBbox(mPoint1, mPoint2, OPEN_HS);

            draw2Leads();

            interpLead(ref mPs, 1, hs);
            g.LineColor = CustomGraphics.WhiteColor;
            g.DrawLine(mLead1, mPs);

            drawLead(mPoint3, mLead3);

            if (!mIsOpen)
            {
                doDots();
            }
            drawPosts();
        }
예제 #7
0
        public override void Draw(CustomGraphics g)
        {
            setBbox(mPoint1, mPoint2, OPEN_HS);
            adjustBbox(mSwPosts[0], mSwPosts[mThrowCount - 1]);

            /* draw first lead */
            drawLead(mPoint1, mLead1);
            /* draw other leads */
            for (int i = 0; i < mThrowCount; i++)
            {
                drawLead(mSwPoles[i], mSwPosts[i]);
            }
            /* draw switch */
            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.WhiteColor;
            g.DrawLine(mLead1, mSwPoles[Position]);

            updateDotCount();
            drawDots(mPoint1, mLead1, mCurCount);
            if (Position != 2)
            {
                drawDots(mSwPoles[Position], mSwPosts[Position], mCurCount);
            }
            drawPosts();
        }
예제 #8
0
 protected void drawLead(Point a, Point b)
 {
     Context.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
     Context.DrawLine(a, b);
 }
예제 #9
0
        public override void Draw(CustomGraphics g)
        {
            setBbox(mPoint1, mPoint2, SIZE);

            drawLead(mPoint1, mLead1);

            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;

            int xc = mPoint2.X;
            int yc = mPoint2.Y;

            g.DrawCircle(mPoint2, SIZE / 2);

            adjustBbox(
                xc - SIZE, yc - SIZE,
                xc + SIZE, yc + SIZE
                );

            int  wl = 7;
            int  xl = 10;
            long tm = DateTime.Now.ToFileTimeUtc();

            tm %= 2000;
            if (tm > 1000)
            {
                tm = 2000 - tm;
            }
            double w = 1 + tm * 0.002;

            if (CirSim.Sim.IsRunning)
            {
                w = 1 + 3 * (mFrequency - mMinF) / (mMaxF - mMinF);
            }

            int x0 = 0;
            int y0 = 0;

            g.LineColor = CustomGraphics.GrayColor;
            for (int i = -xl; i <= xl; i++)
            {
                var yy = yc + (int)(0.95 * Math.Sin(i * Math.PI * w / xl) * wl);
                if (i == -xl)
                {
                    x0 = xc + i;
                    y0 = yy;
                }
                else
                {
                    g.DrawLine(x0, y0, xc + i, yy);
                    x0 = xc + i;
                    y0 = yy;
                }
            }

            if (ControlPanel.ChkShowValues.Checked)
            {
                string s = Utils.UnitText(mFrequency, "Hz");
                drawValues(s, 20, -15);
            }

            drawPosts();
            mCurCount = updateDotCount(-mCurrent, mCurCount);
            if (CirSim.Sim.DragElm != this)
            {
                drawDots(mPoint1, mLead1, mCurCount);
            }
        }
예제 #10
0
        protected void drawWaveform(CustomGraphics g, Point center)
        {
            var x = center.X;
            var y = center.Y;

            if (waveform != WAVEFORM.NOISE)
            {
                g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
                g.DrawCircle(center, BODY_LEN / 2);
            }

            adjustBbox(
                x - BODY_LEN, y - BODY_LEN,
                x + BODY_LEN, y + BODY_LEN
                );

            var h  = 7;
            var xd = (int)(h * 2 * mDutyCycle - h + x);

            xd = Math.Max(x - h + 1, Math.Min(x + h - 1, xd));

            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;

            switch (waveform)
            {
            case WAVEFORM.DC: {
                break;
            }

            case WAVEFORM.SQUARE:
                if (mMaxVoltage < 0)
                {
                    g.DrawLine(x - h, y + h, x - h, y);
                    g.DrawLine(x - h, y + h, xd, y + h);
                    g.DrawLine(xd, y + h, xd, y - h);
                    g.DrawLine(x + h, y - h, xd, y - h);
                    g.DrawLine(x + h, y, x + h, y - h);
                }
                else
                {
                    g.DrawLine(x - h, y - h, x - h, y);
                    g.DrawLine(x - h, y - h, xd, y - h);
                    g.DrawLine(xd, y - h, xd, y + h);
                    g.DrawLine(x + h, y + h, xd, y + h);
                    g.DrawLine(x + h, y, x + h, y + h);
                }
                break;

            case WAVEFORM.PULSE:
                if (mMaxVoltage < 0)
                {
                    g.DrawLine(x + h, y, x + h, y);
                    g.DrawLine(x + h, y, xd, y);
                    g.DrawLine(xd, y + h, xd, y);
                    g.DrawLine(x - h, y + h, xd, y + h);
                    g.DrawLine(x - h, y + h, x - h, y);
                }
                else
                {
                    g.DrawLine(x - h, y - h, x - h, y);
                    g.DrawLine(x - h, y - h, xd, y - h);
                    g.DrawLine(xd, y - h, xd, y);
                    g.DrawLine(x + h, y, xd, y);
                    g.DrawLine(x + h, y, x + h, y);
                }
                break;

            case WAVEFORM.SAWTOOTH:
                g.DrawLine(x, y - h, x - h, y);
                g.DrawLine(x, y - h, x, y + h);
                g.DrawLine(x, y + h, x + h, y);
                break;

            case WAVEFORM.TRIANGLE: {
                int xl = 5;
                g.DrawLine(x - xl * 2, y, x - xl, y - h);
                g.DrawLine(x - xl, y - h, x, y);
                g.DrawLine(x, y, x + xl, y + h);
                g.DrawLine(x + xl, y + h, x + xl * 2, y);
                break;
            }

            case WAVEFORM.NOISE: {
                drawCenteredText("Noise", center, true);
                break;
            }

            case WAVEFORM.AC: {
                var xl = 10;
                var x0 = 0;
                var y0 = 0;
                for (var i = -xl; i <= xl; i++)
                {
                    var yy = y + (int)(.95 * Math.Sin(i * Math.PI / xl) * h);
                    if (i != -xl)
                    {
                        g.DrawLine(x0, y0, x + i, yy);
                    }
                    x0 = x + i;
                    y0 = yy;
                }
                break;
            }
            }

            if (ControlPanel.ChkShowValues.Checked && waveform != WAVEFORM.NOISE)
            {
                var s = Utils.UnitText(mMaxVoltage, "V\r\n");
                s += Utils.UnitText(mFrequency, "Hz\r\n");
                s += Utils.UnitText(mPhaseShift * 180 / Math.PI, "°");
                drawValues(s, 0, 5);
            }
        }