コード例 #1
0
        public ContextMenuStrip Show(int px, int py, CircuitElm mouseElm)
        {
            mScope.Enabled      = mouseElm.CanViewInScope;
            mFloatScope.Enabled = mouseElm.CanViewInScope;
            mEdit.Enabled       = mouseElm.GetElementInfo(0) != null;
            mFlip.Enabled       = 2 == mouseElm.PostCount;
            mSplit.Enabled      = canSplit(mouseElm);
            mSlider.Enabled     = sliderItemEnabled(mouseElm);

            var popupMenu = new ContextMenuStrip();

            popupMenu.Items.AddRange(mMenuItems.ToArray());
            popupMenu.Show();
            popupMenu.Location = new Point(px, py);
            return(popupMenu);
        }
コード例 #2
0
 bool sliderItemEnabled(CircuitElm elm)
 {
     if (elm is PotElm)
     {
         return(false);
     }
     for (int i = 0; ; i++)
     {
         var ei = elm.GetElementInfo(i);
         if (ei == null)
         {
             return(false);
         }
         if (ei.CanCreateAdjustable())
         {
             return(true);
         }
     }
 }
コード例 #3
0
ファイル: SliderDialog.cs プロジェクト: mctr909/CircuitSim
        void buildDialog()
        {
            int i;
            int idx;

            vp.SuspendLayout();
            for (i = 0; ; i++)
            {
                einfos[i] = elm.GetElementInfo(i);
                if (einfos[i] == null)
                {
                    break;
                }
                var ei = einfos[i];
                if (!ei.CanCreateAdjustable())
                {
                    continue;
                }
                var    adj  = findAdjustable(i);
                string name = ei.Name;
                idx = vp.Controls.IndexOf(hp);

                /* remove HTML */
                var rg = new Regex("<[^>]*>");
                name        = rg.Replace(name, "");
                ei.CheckBox = new CheckBox()
                {
                    AutoSize = true,
                    Text     = name,
                    Checked  = adj != null
                };
                ctrlInsert(vp, ei.CheckBox, idx++);
                ei.CheckBox.CheckedChanged += new EventHandler((sender, e) => { itemStateChanged(sender); });
                if (adj != null)
                {
                    ctrlInsert(vp, new Label()
                    {
                        TextAlign = ContentAlignment.BottomLeft, Text = "Min Value"
                    }, idx++);
                    ei.MinBox = new TextBox()
                    {
                        Text = ElementInfoDialog.UnitString(ei, adj.MinValue)
                    };
                    ctrlInsert(vp, ei.MinBox, idx++);
                    ctrlInsert(vp, new Label()
                    {
                        TextAlign = ContentAlignment.BottomLeft, Text = "Max Value"
                    }, idx++);
                    ei.MaxBox = new TextBox()
                    {
                        Text = ElementInfoDialog.UnitString(ei, adj.MaxValue)
                    };
                    ctrlInsert(vp, ei.MaxBox, idx++);
                    ctrlInsert(vp, new Label()
                    {
                        TextAlign = ContentAlignment.BottomLeft, Text = "Label"
                    }, idx++);
                    ei.LabelBox = new TextBox()
                    {
                        Text = adj.SliderText
                    };
                    ctrlInsert(vp, ei.LabelBox, idx++);
                }
            }
            vp.ResumeLayout(false);
            einfocount = i;
        }
コード例 #4
0
        void setupValues()
        {
            if (mMyElm is ResistorElm)
            {
                mMinPow = 0;
                mMaxPow = 6;
                mUnit   = "Ω";
            }
            if (mMyElm is CapacitorElm)
            {
                mMinPow = -11;
                mMaxPow = -3;
                mUnit   = "F";
            }
            if (mMyElm is InductorElm)
            {
                mMinPow = -6;
                mMaxPow = 0;
                mUnit   = "H";
            }
            mValues = new double[2 + (mMaxPow - mMinPow) * 24];
            int ptr = 0;

            for (int i = mMinPow; i <= mMaxPow; i++)
            {
                for (int j = 0; j < ((i != mMaxPow) ? 24 : 1); j++, ptr++)
                {
                    mValues[ptr] = Math.Pow(10.0, i) * E24[j];
                }
            }
            mNValues          = ptr;
            mValues[mNValues] = 1E99;
            mInfo             = mMyElm.GetElementInfo(0);
            double currentvalue = mInfo.Value;

            for (int i = 0; i < mNValues + 1; i++)
            {
                if (Utils.UnitText(currentvalue, "") == Utils.UnitText(mValues[i], "")) /* match to an existing value */
                {
                    mValues[i]  = currentvalue;                                         /* Just in case it isn't 100% identical */
                    mCurrentIdx = i;
                    break;
                }
                if (currentvalue < mValues[i])   /* overshot - need to insert value */
                {
                    mCurrentIdx = i;
                    for (int j = mNValues - 1; j >= i; j--)
                    {
                        mValues[j + 1] = mValues[j];
                    }
                    mValues[i] = currentvalue;
                    mNValues++;
                    break;
                }
            }
            mName    = mInfo.Name;
            mLastIdx = mCurrentIdx;

            /*for (int i = 0; i < nvalues; i++) {
             *  Console.WriteLine("i=" + i + " values=" + values[i] + " current? " + (i == currentidx));
             * }*/
        }
コード例 #5
0
        public void CreateSlider()
        {
            double value = Elm.GetElementInfo(EditItem).Value;

            CreateSlider(value);
        }