예제 #1
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();
 }
예제 #2
0
파일: AMElm.cs 프로젝트: mctr909/CircuitSim
        void drawWaveform(CustomGraphics g, Point center)
        {
            g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
            int xc = center.X;
            int yc = center.Y;

            g.DrawCircle(center, SIZE / 2);
            adjustBbox(xc - SIZE, yc - SIZE, xc + SIZE, yc + SIZE);
        }
예제 #3
0
 public override void Draw(CustomGraphics g)
 {
     drawPosts();
     draw2Leads();
     g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
     g.DrawPolygon(gatePoly);
     g.DrawPolygon(symbolPoly);
     g.DrawCircle(pcircle, 3);
     mCurCount = updateDotCount(mCurrent, mCurCount);
     drawDots(mLead2, mPoint2, mCurCount);
 }
예제 #4
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);
            }
        }
예제 #5
0
        public override void Draw(CustomGraphics g)
        {
            draw2Leads();

            g.DrawCircle(mCenter, BODY_LEN / 2);
            drawLead(mAshaft1, mAshaft2);
            g.FillPolygon(NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor, mArrow);

            setBbox(mPoint1, mPoint2, BODY_LEN);
            doDots();
            if (ControlPanel.ChkShowValues.Checked)
            {
                string s = Utils.UnitText(mCurrentValue, "A");
                g.DrawRightText(s, mTextPos.X, mTextPos.Y);
            }
            drawPosts();
        }
예제 #6
0
 public override void Draw(CustomGraphics g)
 {
     drawPosts();
     draw2Leads();
     g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
     if (GateElm.useAnsiGates())
     {
         g.DrawPolygon(mGatePolyAnsi);
     }
     else
     {
         g.DrawPolygon(mGatePolyEuro);
         drawCenteredLText("1", mCenter, true);
     }
     g.DrawCircle(mPcircle, 3);
     mCurCount = updateDotCount(mCurrent, mCurCount);
     drawDots(mLead2, mPoint2, mCurCount);
 }
예제 #7
0
 public override void Draw(CustomGraphics g)
 {
     for (int i = 0; i != mInputCount; i++)
     {
         drawLead(mInPosts[i], mInGates[i]);
     }
     drawLead(mLead2, mPoint2);
     g.LineColor = NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor;
     if (useAnsiGates())
     {
         g.DrawPolygon(mGatePolyAnsi);
     }
     else
     {
         g.DrawPolygon(mGatePolyEuro);
         var center = new Point();
         interpPoint(ref center, 0.5);
         drawCenteredLText(getGateText(), center, true);
     }
     if (hasSchmittInputs())
     {
         g.LineColor = CustomGraphics.WhiteColor;
         g.DrawPolygon(mSchmittPoly);
     }
     if (mLinePoints != null && useAnsiGates())
     {
         for (int i = 0; i != mLinePoints.Length - 1; i++)
         {
             drawLead(mLinePoints[i], mLinePoints[i + 1]);
         }
     }
     if (isInverting())
     {
         g.DrawCircle(mCirclePos, CIRCLE_SIZE);
     }
     mCurCount = updateDotCount(mCurrent, mCurCount);
     drawDots(mLead2, mPoint2, mCurCount);
     drawPosts();
 }
예제 #8
0
        public override void Draw(CustomGraphics g)
        {
            if (NeedsHighlight || this == CirSim.Sim.DragElm)
            {
                base.Draw(g);
                return;
            }

            drawLead(mPoint1, mLedLead1);
            drawLead(mLedLead2, mPoint2);

            g.LineColor = CustomGraphics.GrayColor;
            g.DrawCircle(mLedCenter, CR);

            double w = mCurrent / mMaxBrightnessCurrent;

            if (0 < w)
            {
                w = 255 * (1 + .2 * Math.Log(w));
            }
            if (255 < w)
            {
                w = 255;
            }
            if (w < 0)
            {
                w = 0;
            }

            g.LineColor = Color.FromArgb((int)(mColorR * w), (int)(mColorG * w), (int)(mColorB * w));
            g.FillCircle(mLedCenter.X, mLedCenter.Y, CR_INNER);

            setBbox(mPoint1, mPoint2, CR_INNER);
            updateDotCount();
            drawDots(mPoint1, mLedLead1, mCurCount);
            drawDots(mPoint2, mLedLead2, -mCurCount);
            drawPosts();
        }
예제 #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
        public override void Draw(CustomGraphics g)
        {
            /* pick up global flags changes */
            if ((mFlags & FLAGS_GLOBAL) != mGlobalFlags)
            {
                SetPoints();
            }

            setBbox(mPoint1, mPoint2, HS);

            /* draw source/drain terminals */
            drawLead(mSrc[0], mSrc[1]);
            drawLead(mDrn[0], mDrn[1]);

            /* draw line connecting source and drain */
            bool enhancement = mVt > 0 && ShowBulk;

            for (int i = 0; i != SEGMENTS; i++)
            {
                if ((i == 1 || i == 4) && enhancement)
                {
                    continue;
                }
                double v = Volts[V_S] + (Volts[V_D] - Volts[V_S]) * i / SEGMENTS;
                drawLead(mPs1[i], mPs2[i]);
            }

            /* draw little extensions of that line */
            drawLead(mSrc[1], mSrc[2]);
            drawLead(mDrn[1], mDrn[2]);

            /* draw bulk connection */
            if (ShowBulk)
            {
                drawLead(mPnp == -1 ? mDrn[0] : mSrc[0], mBody[0]);
                drawLead(mBody[0], mBody[1]);
            }

            /* draw arrow */
            if (!DrawDigital)
            {
                g.FillPolygon(NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor, mArrowPoly);
            }

            /* draw gate */
            drawLead(mPoint1, mGate[1]);
            drawLead(mGate[0], mGate[2]);
            if (DrawDigital && mPnp == -1)
            {
                g.DrawCircle(mPcircle, mPcircler);
            }

            if ((mFlags & FLAG_SHOWVT) != 0)
            {
                string s = "" + (mVt * mPnp);
                drawCenteredLText(s, P2, false);
            }
            mCurCount = updateDotCount(-mIds, mCurCount);
            drawDots(mSrc[0], mSrc[1], mCurCount);
            drawDots(mDrn[1], mDrn[0], mCurCount);
            drawDots(mSrc[1], mDrn[1], mCurCount);

            if (ShowBulk)
            {
                mCurcountBody1 = updateDotCount(mDiodeCurrent1, mCurcountBody1);
                mCurcountBody2 = updateDotCount(mDiodeCurrent2, mCurcountBody2);
                drawDots(mSrc[0], mBody[0], -mCurcountBody1);
                drawDots(mBody[0], mDrn[0], mCurcountBody2);
            }

            drawPosts();

            if (ControlPanel.ChkShowName.Checked)
            {
                if (mNameV)
                {
                    g.DrawCenteredVText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
                else
                {
                    g.DrawLeftText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
            }
        }
예제 #11
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);
            }
        }