Exemple #1
0
    public void PlayRandomOneShot()
    {
        int trackNo = Random.Range(0, Clips.Count);

        CurrentSource.PlayOneShot(Clips[trackNo]);
        NextSource();
    }
Exemple #2
0
        private void DataRemove()
        {
            if (CurrentData is DirectoryResourceData)
            {
                //DialogResult r = MessageBox.Show("Do you want to delete just this ResourceData for the directory, or the directory and all of its members?", "Anolis Resourcer", MessageBoxButtons.);
                // TODO: How do you do a messagebox with custom button labels?

                var r = MessageBox.Show("You are attempting to delete an Icon or Cursor directory resource. This will also delete all associated Icon or Cursor member images. Are you sure you want to continue?", "Anolis Resourcer", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (r != DialogResult.OK)
                {
                    return;
                }
            }

            if (CurrentData is IconCursorImageResourceData)
            {
                var r = MessageBox.Show("You are attempting to delete an Icon or Cursor member image. This will render the state of the parent Icon or Cursor Directory invalid and will cause errors in any applications attempting to read the icon. Are you sure you want to continue?", "Anolis Resourcer", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (r != DialogResult.OK)
                {
                    return;
                }
            }

            CurrentSource.Remove(CurrentData.Lang);

            ToolbarUpdate(false, true, false);
            TreeRefresh(CurrentData.Lang);
        }
Exemple #3
0
    // private VoltageSource AddVoltageSource(Circuit ckt)
    // {
    //     VoltageSource source = new VoltageSource("PS", "PSPOS", "0", 0);


    //     for (int i = 0; i < _powerSupply.transform.childCount; i++)
    //     {
    //         var child = _powerSupply.transform.GetChild(i);
    //         if (child.CompareTag("BBSlot"))
    //         {
    //             if (child.GetComponent<Slot>().itemPlaced != null && !child.GetComponent<Slot>().slotChecked)
    //             {
    //                 AttachPowerSupply(child, ckt);
    //             }
    //         }
    //     }
    //     return source;
    // }

    private void AddPowerSupplyConnection(string pos, string neg, Circuit ckt)
    {
        bool isGroundConnected = false;

        if (Globals.PSConnections.TryGetValue(Globals.PowerSupplyInput.ground, out Globals.BananaPlugs groundConnection))
        {
            if (!groundConnection.Equals(Globals.BananaPlugs.noConnection))
            {
                isGroundConnected = true;
            }
        }

        if (pos == Globals.PowerSupplyInput.ground.ToString())
        {
            pos = "0";
        }
        else if (pos == Globals.PowerSupplyInput.voltageSource.ToString() && isGroundConnected)
        {
            Debug.Log("Adding PS Voltage Source: " + pos + "PS" + " " + pos + " " + "0" + " " + _powerSupplyMachine.GetComponent <PSSelect>().voltage);
            VoltageSource voltSource = new VoltageSource(pos + "PS", pos, "0", _powerSupplyMachine.GetComponent <PSSelect>().voltage);
            voltageSource = voltSource;
            ckt.Add(voltSource);
        }
        else if (pos == Globals.PowerSupplyInput.currentSource.ToString() && isGroundConnected)
        {
            Debug.Log("Adding PS Current Source: " + pos + "PS" + " " + pos + " " + "0" + " " + _powerSupplyMachine.GetComponent <PSSelect>().current);
            CurrentSource currSource = new CurrentSource(pos + "PS", pos, "0", _powerSupplyMachine.GetComponent <PSSelect>().current);
            currentSource = currSource;
            ckt.Add(currSource);
        }

        Debug.Log("Adding Wire: " + pos + " " + pos + " " + neg + " " + 0);
        ckt.Add(new Resistor(pos, pos, neg, 0));
    }
Exemple #4
0
            public bool MoveNext()
            {
_MoveNextRow:

                // Is this the start of a new row?
                if (InitializeRow)
                {
                    // Are we out of rows?
                    if (!NameEnumerator.MoveNext())
                    {
                        return(false);
                    }

                    // Get the new row.
                    RowIndex++;
                    ColumnIndex      = -1;
                    ObjectEnumerator = CurrentSource.GetEnumerator();
                    InitializeRow    = false;
                }

                // Is this the last column?
                if (!ObjectEnumerator.MoveNext())
                {
                    // Attempt to get the next row.
                    InitializeRow = true;
                    goto _MoveNextRow;
                }

                Current = ObjectEnumerator.Current;
                ColumnIndex++;
                return(true);
            }
Exemple #5
0
        private void DataImport(String dataFilename)
        {
            var form = new AddResourceForm();

            if (dataFilename != null)
            {
                form.LoadFile(dataFilename);
            }

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                var data = form.ResourceData;

                var typeId = form.ResourceTypeIdentifier;
                var nameId = form.ResourceNameIdentifier;
                var langId = form.ResourceLangId;

                var lang = CurrentSource.Add(typeId, nameId, langId, data);

                TreeAdd(lang);

                //TreeRefresh( lang );
                MainFormRefresh();
            }
        }
Exemple #6
0
        private void registerButton(Grid grid)
        {
            grid.MouseEnter += (sender, args) =>
            {
                // if(grid != selectedGrid) grid.Children.OfType<Canvas>().FirstOrDefault().Background = new SolidColorBrush(Color.FromArgb(255, 111, 235, 254));
            };
            grid.MouseLeave += (sender, args) =>
            {
                //if (grid != selectedGrid) grid.Children.OfType<Canvas>().FirstOrDefault().Background = new SolidColorBrush(Color.FromArgb(255, 140, 240, 255));
            };
            grid.MouseDown += (sender, args) =>
            {
                selectedGrid.Children.OfType <Image>().FirstOrDefault().Visibility = Visibility.Hidden;
                selectedGrid = grid;
                selectedGrid.Children.OfType <Image>().FirstOrDefault().Visibility = Visibility.Visible;

                Uri uri = GetPage();
                CurrentSource.Source = uri;
                if (grid == Menu_2)
                {
                    CurrentSource.Navigate(Share_Page.getInstance());
                }
                else
                {
                    CurrentSource.NavigationService.Navigate(uri);
                }
            };
        }
        public void When_CurrentSourceCloned_Expect_Reference()
        {
            // Let's check cloning of entities here.
            var isrc = new CurrentSource("I1", "A", "B", 1.0);

            isrc.SetParameter("waveform", new Pulse(0.0, 1.0, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5));
            isrc.SetParameter("ac", new double[] { 1.0, 2.0 });

            // Clone the entity
            var clone = (CurrentSource)isrc.Clone();

            // Change some stuff (should not be reflected in the clone)
            isrc.GetParameter <Waveform>("waveform").SetParameter("v2", 2.0);

            // Check
            Assert.AreEqual(isrc.Name, clone.Name);
            Assert.AreEqual(isrc.GetNode(0), clone.GetNode(0));
            Assert.AreEqual(isrc.GetNode(1), clone.GetNode(1));
            var waveform = (Pulse)clone.GetParameter <Waveform>("waveform");

            Assert.AreEqual(0.0, waveform.InitialValue.Value, 1e-12);
            Assert.AreEqual(1.0, waveform.PulsedValue.Value, 1e-12);
            Assert.AreEqual(2.0, isrc.GetParameter <Waveform>("waveform").GetParameter <double>("v2"));
            Assert.AreEqual(1e-5, waveform.GetParameter <double>("per"), 1e-12);
        }
        private void LogEntry(LogEntry entry)
        {
            // Here, we throw an exception because it is an applicative error,
            // not a logging failure.
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            // Do we have a source? If yes ask-it to pre process the entry.
            if (CurrentSource != null)
            {
                entry = CurrentSource.ProcessLogEntry(entry);
            }
            if (entry == null)
            {
                return;                // The current source decided this entry should not be logged.
            }
            // if trace level is Off, just log to the Visual Studio output window.
            if (entry.Level <= LogLevel.Off)
            {
                Debug.WriteLine(string.Format("DEBUG: {0}", entry));
            }

            // Eventlog logging
            try
            {
                if (entry.Level <= configuration.EventLogLevel)
                {
                    LogToEventLog(entry);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("ERROR: Logging error.\r\nLogged entry:\r\n{0}\r\nException:{1}", entry, ex));
                //throw ex; // Remark: logging shouldn't trhow exceptions if it can't log...
            }

            // File logging
            try
            {
                if (entry.Level <= configuration.TracingLogLevel)
                {
                    LogToTraceFile(entry);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("ERROR: Logging error.\r\nLogged entry:\r\n{0}\r\nException:{1}", entry, ex));
                //throw ex; // Remark: logging shouldn't trhow exceptions if it can't log...
            }

            // Console logging: whatever log level was set, we also log to Console.Out.
            try { LogToWriter(Console.Out, entry); }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("ERROR: Logging error.\r\nLogged entry:\r\n{0}\r\nException:{1}", entry, ex));
                //throw ex; // Remark: logging shouldn't trhow exceptions if it can't log...
            }
        }
Exemple #9
0
        /// <summary>Prompts the user to save the CurrentSource or to cancel the operation. If the source is to be uploaded it's Disposes it. Returns False if operation was cancelled.</summary>
        private Boolean SourceUnload()
        {
            if (CurrentSource == null)
            {
                return(true);
            }

            var retval = false;

            if (CurrentSource.HasUnsavedChanges)
            {
                var nofChanges = 0;
                foreach (var change in CurrentSource.AllActiveLangs)
                {
                    nofChanges++;
                }

                var message = String.Format(Cult.CurrentCulture, "Save {0} change{1} to \"{2}\" before closing?", nofChanges, nofChanges == 1 ? "" : "s", CurrentSource.Name);

                var r = MessageBox.Show(this, message, "Anolis Resourcer", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                switch (r)
                {
                case DialogResult.Yes:

                    SourceSave();
                    retval = true;
                    break;

                case DialogResult.No:
                    retval = true;
                    break;

                case DialogResult.Cancel:
                default:
                    retval = false;
                    break;
                }
            }
            else
            {
                retval = true;
            }

            if (retval)
            {
                NavigateClear();
                CurrentSource.Dispose();
                CurrentSource = null;
            }

            ToolbarUpdate(true, true, false);
            StatusbarUpdate();
            TreePopulate();
            ListHide();

            return(retval);
        }
Exemple #10
0
        private void SourceRevert()
        {
            if (CurrentSource == null)
            {
                return;
            }

            CurrentSource.Reload();
        }
Exemple #11
0
 public void Play(int trackNo = 0, bool loop = false)
 {
     if (trackNo >= Clips.Count)
     {
         return;
     }
     CurrentSource.clip = Clips[trackNo];
     CurrentSource.loop = loop;
     CurrentSource.Play();
     currentTrackNo = trackNo;
 }
Exemple #12
0
        private void OnNavigate(object obj)
        {
            int page = Convert.ToInt32(obj);
            int r    = row * page - row + 1;

            CurrentSource.Clear();
            for (int i = r; i < r + row && i < count; i++)
            {
                CurrentSource.Add(i - 1);
            }
        }
Exemple #13
0
        private void SourceSave()
        {
            if (CurrentSource == null || !CurrentSource.HasUnsavedChanges || CurrentSource.IsReadOnly)
            {
                return;
            }

            CurrentSource.CommitChanges();

            MainFormRefresh();
        }
Exemple #14
0
        private void DataCancel()
        {
            if (CurrentData == null)
            {
                throw new InvalidOperationException("There is no current ResourceData.");
            }

            CurrentSource.Cancel(CurrentData.Lang);

            ToolbarUpdate(false, true, false);

            TreeRefresh(CurrentData.Lang);
        }
Exemple #15
0
 public void Pool()
 {
     if (!inPool)
     {
         foreach (var CurrentSource in CurrentSources)
         {
             CurrentSource.Pool();
         }
         CurrentSources.Clear();
         ElectricalPool.PooledVIRCurrent.Add(this);
         inPool = true;
     }
 }
Exemple #16
0
        private void HandleXferReturnCode(ReturnCode rc)
        {
            switch (rc)
            {
            case ReturnCode.Success:
            case ReturnCode.XferDone:
            case ReturnCode.Cancel:
                // ok to keep going
                break;

            default:
                var status = CurrentSource.GetStatus();
                OnTransferError(new TransferErrorEventArgs(rc, status));
                break;
            }
        }
Exemple #17
0
        /// <summary>
        /// Logs the specified log entry.
        /// </summary>
        /// <param name="entry">The entry to log.</param>
        public override void Log(LogEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            // Do we have a source? If yes ask-it to pre process the entry.
            if (CurrentSource != null)
            {
                entry = CurrentSource.ProcessLogEntry(entry);
            }
            if (entry == null)
            {
                return;                // The current source decided this entry should not be logged.
            }
            CurrentLog.Logger.Log(
                thisServiceType,
                Helper.LogLevelToLog4NetLevel(entry.Level),
                entry.Message,
                entry.Exception);
        }
Exemple #18
0
    protected void DeleteS3Orphans()
    {
        Response.Clear();
        Response.Write(String.Format("<html><head><link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" /></head><body><p>", VirtualPathUtility.ToAbsolute("~/Public/stylesheet.css")));

        // Get a list of all of the images in the DB for this category:
        UpdateProgress(1, 0, String.Format("Getting images for {0} from S3", CurrentSource.ToString()));

        bool fIsLiveSite = Branding.CurrentBrand.MatchesHost(Request.Url.Host);
        bool fIsPreview  = !String.IsNullOrEmpty(Request["preview"]);

        AWSImageManagerAdmin.ADMINDeleteS3Orphans(CurrentSource,
                                                  (cFiles, cBytesTotal, cOrphans, cBytesToFree) =>
                                                  { UpdateProgress(4, 100, String.Format("{0} orphaned files ({1:#,##0} bytes) found out of {2} files ({3:#,##0} bytes).", cOrphans, cBytesToFree, cFiles, cBytesTotal)); },
                                                  () => { UpdateProgress(2, 0, "S3 Enumeration done, getting files from DB"); },
                                                  (szKey, percent) =>
        {
            UpdateProgress(3, percent, String.Format("{0}: {1}", fIsPreview ? "PREVIEW" : (fIsLiveSite ? "ACTUAL" : "NOT LIVE SITE"), szKey));
            return(!fIsPreview && fIsLiveSite);
        });

        Response.Write("</p></body></html>");
        Response.End();
    }
Exemple #19
0
        protected void SyncImages(List <DirKey> lstDk)
        {
            if (lstDk == null)
            {
                throw new ArgumentNullException(nameof(lstDk));
            }

            Response.Clear();
            Response.Write(String.Format(CultureInfo.InvariantCulture, "<html><head><link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" /></head><body><p>", VirtualPathUtility.ToAbsolute("~/Public/stylesheet.css")));

            DateTime            dtStart              = DateTime.Now;
            int                 cNewImages           = 0;
            int                 cChangedImages       = 0;
            int                 cDeletedImages       = 0;
            int                 cImagesExamined      = 0;
            List <MFBImageInfo> lstMfbiiNewOrChanged = new List <MFBImageInfo>();

            try
            {
                // Get a list of all of the images in the DB for this category:
                UpdateProgress(1, 0, String.Format(CultureInfo.CurrentCulture, "Getting images for {0} from DB", CurrentSource.ToString()));
                Dictionary <string, MFBImageInfo> dictDBResults = MFBImageInfo.AllImagesForClass(CurrentSource);

                int cDBEntriesToStart = dictDBResults.Count;

                // Get a list of all of the images in this category:
                int cDirectories          = lstDk.Count;
                int cDirectoriesProcessed = 0;
                int c5Percent             = Math.Max(1, cDirectories / 20);

                UpdateProgress(2, 0, String.Format(CultureInfo.CurrentCulture, "Getting images for {0} ({1} folders)...", CurrentSource.ToString(), cDirectories));
                ImageList il = new ImageList
                {
                    Class = CurrentSource
                };
                foreach (DirKey dk in lstDk)
                {
                    il.Key = dk.Key;
                    il.Refresh(true);
                    foreach (MFBImageInfo mfbii in il.ImageArray)
                    {
                        MFBImageInfo mfbiiMatch = dictDBResults.ContainsKey(mfbii.PrimaryKey) ? dictDBResults[mfbii.PrimaryKey] : null;
                        if (mfbiiMatch == null)
                        {
                            // If no match was found, it's a new image
                            lstMfbiiNewOrChanged.Add(mfbii);
                            cNewImages++;
                        }
                        else
                        {
                            bool fCommentChanged = String.Compare(mfbii.Comment, mfbiiMatch.Comment, StringComparison.CurrentCultureIgnoreCase) != 0;
                            bool fLocChanged     = !MyFlightbook.Geography.LatLong.AreEqual(mfbii.Location, mfbiiMatch.Location);

                            // if it's changed, we need to update it.
                            if (fCommentChanged || fLocChanged)
                            {
                                if (mfbii.Location != null && !mfbii.Location.IsValid)
                                {
                                    mfbii.Location = null;
                                }

                                UpdateProgress(2, (100 * cDirectoriesProcessed) / cDirectories, String.Format(CultureInfo.CurrentCulture, "Changed {0}:{1}{2}",
                                                                                                              mfbii.PrimaryKey,
                                                                                                              fCommentChanged ? String.Format(CultureInfo.CurrentCulture, "<br />&nbsp;Comment: {0} => {1}", mfbiiMatch.Comment, mfbii.Comment) : string.Empty,
                                                                                                              fLocChanged ? String.Format(CultureInfo.CurrentCulture, "<br />&nbsp;Location: {0} => {1}", (mfbiiMatch.Location == null ? "null" : mfbiiMatch.Location.ToString()), (mfbii.Location == null ? "null" : mfbii.Location.ToString())) : string.Empty));

                                lstMfbiiNewOrChanged.Add(mfbii);
                                cChangedImages++;
                            }

                            // Now remove it from the list of DB images.
                            dictDBResults.Remove(mfbii.PrimaryKey);
                            mfbiiMatch.UnCache();
                            mfbiiMatch = null;  // save some memory?
                        }
                        mfbii.UnCache();

                        cImagesExamined++;
                    }

                    il.Clear();

                    if (++cDirectoriesProcessed % c5Percent == 0)
                    {
                        GC.Collect();
                        UpdateProgress(2, (100 * cDirectoriesProcessed) / cDirectories, String.Format(CultureInfo.CurrentCulture, "{0} Folders processed, {1} images found", cDirectoriesProcessed, cImagesExamined));
                    }
                }

                UpdateProgress(3, 100, String.Format(CultureInfo.CurrentCulture, "Elapsed Time: {0} seconds", DateTime.Now.Subtract(dtStart).TotalSeconds));

                UpdateProgress(4, 0, String.Format(CultureInfo.CurrentCulture, "{0} image files found, {1} images in DB", cImagesExamined, cDBEntriesToStart));

                // Now see if anything got deleted but not from the DB
                int cImagesToDelete = dictDBResults.Values.Count;
                if (String.IsNullOrEmpty(Request["preview"]))
                {
                    UpdateProgress(5, 0, String.Format(CultureInfo.CurrentCulture, "{0} images found in DB that weren't found as files; deleting these.", cImagesToDelete));
                    foreach (MFBImageInfo mfbii in dictDBResults.Values)
                    {
                        mfbii.DeleteFromDB();
                        cDeletedImages++;

                        if (cDeletedImages % 100 == 0)
                        {
                            UpdateProgress(5, (100 * cDeletedImages) / cImagesToDelete, String.Format(CultureInfo.CurrentCulture, "Deleted {0} images from DB", cDeletedImages));
                        }
                    }

                    // And finally add new images back
                    UpdateProgress(6, 0, String.Format(CultureInfo.CurrentCulture, "{0} new and {1} changed images (total of {2}) to be added to/updated in the DB", cNewImages, cChangedImages, lstMfbiiNewOrChanged.Count));
                    lstMfbiiNewOrChanged.ForEach((mfbii) =>
                    {
                        try
                        {
                            mfbii.ToDB();
                        }
                        catch (Exception ex) when(ex is MyFlightbookException)
                        {
                            Response.Write(String.Format(CultureInfo.InvariantCulture, "<p class=\"error\">Exception sync'ing DB: {0}</p>", ex.Message));
                        }
                    });
                }
                else
                {
                    UpdateProgress(5, 0, String.Format(CultureInfo.CurrentCulture, "{0} images found in DB that weren't found as files; these are:", cImagesToDelete));
                    foreach (MFBImageInfo mfbii in dictDBResults.Values)
                    {
                        UpdateProgress(5, 0, mfbii.PathThumbnail);
                    }
                    UpdateProgress(6, 0, String.Format(CultureInfo.CurrentCulture, "{0} images found that are new or changed that weren't in DB; these are:", cNewImages + cChangedImages));
                    lstMfbiiNewOrChanged.ForEach((mfbii) => { UpdateProgress(6, 0, mfbii.PathThumbnail); });
                }

                UpdateProgress(6, 100, "Finished!");
            }
            catch (Exception ex) when(!(ex is OutOfMemoryException))
            {
                Response.Write(String.Format(CultureInfo.InvariantCulture, "<p class=\"error\">Exception sync'ing DB: {0}</p>", ex.Message));
            }

            Response.Write("</p></body></html>");
            Response.End();
        }
Exemple #20
0
        private void SourceChangeLeftArrowControl_Click(object sender, RoutedEventArgs e)
        {
            var prevAsm = CurrentSource.GetPreviousAsm();

            OnSourceChanged(prevAsm);
        }
Exemple #21
0
        private void SourceChangeRightArrowControl_Click(object sender, RoutedEventArgs e)
        {
            var nextAsm = CurrentSource.GetNextAsm();

            OnSourceChanged(nextAsm);
        }
Exemple #22
0
 public static IParsingSource GetCurrentSource()
 {
     return(CurrentSource?.FreezedPosition());
 }
Exemple #23
0
    public void SpiceSharpCalculation()
    {
        Debug.Log("*********************");
        Debug.Log("Starting calculation ");
        ClearAllSlots();

        voltageSource = new VoltageSource("a");
        currentSource = new CurrentSource("b");
        var ckt = new Circuit();


        foreach (KeyValuePair <Globals.AgilentInput, Globals.BananaPlugs> entry in Globals.AgilentConnections)
        {
            if (entry.Value != Globals.BananaPlugs.noConnection)
            {
                ActivateBananaSlot(entry.Value.ToString());
            }
        }

        foreach (KeyValuePair <Globals.FlukeInput, Globals.BananaPlugs> entry in Globals.FlukeConnections)
        {
            if (entry.Value != Globals.BananaPlugs.noConnection)
            {
                ActivateBananaSlot(entry.Value.ToString());
            }
        }

        foreach (KeyValuePair <Globals.PowerSupplyInput, Globals.BananaPlugs> entry in Globals.PSConnections)
        {
            if (entry.Value != Globals.BananaPlugs.noConnection)
            {
                AddPowerSupplyConnection(entry.Key.ToString(), entry.Value.ToString(), ckt);
                ActivateBananaSlot(entry.Value.ToString());
            }
        }

        //Handle Self BananaPlug Connections
        for (int i = 0; i < 5; i++)
        {
            if (bananaPlugActive[i])
            {
                HandleSelfBananaConnections(i, ckt);
            }
        }

        //INSERT POTENTIOMETER VAL HERE


        if (bananaPlugActive[4])
        {
            if (_potentioMeterTextBox.text.Length == 0)
            {
                ckt.Add(new Resistor("PotentioMeterBanana", "B4", "PotentioMeter", 0));
                Debug.Log("Adding Wire: PotentioMeterBanana B4 PotentioMeter 0");
            }
            else
            {
                ckt.Add(new Resistor("PotentioMeterBanana", "B4", "PotentioMeter", int.Parse(_potentioMeterTextBox.text)));
                Debug.Log("Adding Wire: PotentioMeterBanana B4 PotentioMeter " + _potentioMeterTextBox.text);
            }

            ckt.Add(new Resistor("PotentioMeterBlack", "PotentioMeter", "C67", 0));
            ckt.Add(new Resistor("PotentioMeterBlue", "PotentioMeter", "C70", 0));
            ckt.Add(new Resistor("PotentioMeterRed", "PotentioMeter", "C72", 0));
            Debug.Log("Adding Wire: PotentioMeterBlack PotentioMeter C67 0");
            Debug.Log("Adding Wire: PotentioMeterBlue PotentioMeter C70 0");
            Debug.Log("Adding Wire: PotentioMeterRed PotentioMeter C82 0");
        }
        if (bananaPlugActive[2] || bananaPlugActive[4])
        {
            ckt.Add(new Inductor("B2B4Inductor", "B2", "B4", 0.020f));
            Debug.Log("Adding Inductor: PotentioMeterInductor B2 B4 0.020H");
        }
        // ckt.Add(new Resistor("PotentioMeterBanana", "B4", "PotentioMeter", 500));
        // ckt.Add(new Resistor("PotentioMeterBlack", "PotentioMeter", "C17", 0));
        // ckt.Add(new Resistor("PotentioMeterBlue", "PotentioMeter", "C18", 0));
        // ckt.Add(new Resistor("PotentioMeterRed", "PotentioMeter", "C19", 0));
        // ckt.Add(new Resistor("ShortCircuitInductor", "B2", "B4", 0));
        // ckt.Add(new Inductor("ShortCircuitInductor","B2", "B4",0.020f));

        //handle permanent connections
        for (int i = 0; i < _bananaPlugs.transform.childCount; i++)
        {
            if (bananaPlugActive[i])
            {
                var child = _bananaPlugs.transform.GetChild(i);
                if (child.CompareTag("BBSlot"))
                {
                    AddElectricalElement(child.GetComponent <Slot>(), ckt);
                    child.GetComponent <Slot>().slotChecked = true;
                    child.GetComponent <Slot>().slotPair.GetComponent <Slot>().slotChecked = true;
                }
            }
        }
        for (int i = 0; i < _breadboardUI.transform.childCount; i++)
        {
            var child = _breadboardUI.transform.GetChild(i);
            if (child.CompareTag("BBSlot"))
            {
                if (child.GetComponent <Slot>().itemPlaced != null && !child.GetComponent <Slot>().slotChecked&& !child.GetComponent <Slot>().ignoreThisSlot)
                {
                    if (child.GetComponent <Slot>().slotPair.GetComponent <Slot>().slotType == Globals.SlotType.defaultSlot)
                    {
                        AddElectricalElement(child.GetComponent <Slot>(), ckt);
                        child.GetComponent <Slot>().slotChecked = true;
                        child.GetComponent <Slot>().slotPair.GetComponent <Slot>().slotChecked = true;
                    }
                }
            }
            // if (breadboardSlots[i].GetComponent<Slot>().itemPlaced != null && !breadboardSlots[i].GetComponent<Slot>().slotChecked)
            // {
            //     if (breadboardSlots[i].GetComponent<Slot>().slotPair.GetComponent<Slot>().slotType == Globals.SlotType.defaultSlot)
            //     {

            //         AddElectricalElement(breadboardSlots[i].GetComponent<Slot>(), ckt);
            //         breadboardSlots[i].GetComponent<Slot>().slotChecked = true;
            //         breadboardSlots[i].GetComponent<Slot>().slotPair.GetComponent<Slot>().slotChecked = true;
            //     }
            // }
        }

        // VoltageSource powerSupply = AddVoltageSource(ckt);
        // ckt.Add(powerSupply);


        // Create a DC sweep and register to the event for exporting simulation data
        //var dc = new DC("dc", "voltageSourcePS", _powerSupply.GetComponent<PowerSupply>().powerReading, _powerSupply.GetComponent<PowerSupply>().powerReading, 1);
        //var dc = new DC("dc", "voltageSourcePS", _powerSupplyMachine.GetComponent<PSSelect>().voltage, _powerSupplyMachine.GetComponent<PSSelect>().voltage, 1);

        var dc = new DC("dc");

        if (voltageSource.Name != "a" && currentSource.Name != "b")
        {
            dc = new DC("dc", new[] {
                new ParameterSweep(voltageSource.Name, new LinearSweep(_powerSupplyMachine.GetComponent <PSSelect>().voltage, _powerSupplyMachine.GetComponent <PSSelect>().voltage, 1)),
                new ParameterSweep(currentSource.Name, new LinearSweep(_powerSupplyMachine.GetComponent <PSSelect>().current, _powerSupplyMachine.GetComponent <PSSelect>().current, 1))
            });
        }
        else if (voltageSource.Name != "a")
        {
            dc = new DC("dc", new[] {
                new ParameterSweep(voltageSource.Name, new LinearSweep(_powerSupplyMachine.GetComponent <PSSelect>().voltage, _powerSupplyMachine.GetComponent <PSSelect>().voltage, 1))
            });
        }
        else if (currentSource.Name != "b")
        {
            dc = new DC("dc", new[] {
                new ParameterSweep(currentSource.Name, new LinearSweep(_powerSupplyMachine.GetComponent <PSSelect>().current, _powerSupplyMachine.GetComponent <PSSelect>().current, 1))
            });
        }


        //GetCircuitToolsReading(dc);
        ManageAgilentReadingsConnections(dc);
        ManageFlukeReadingsConnections(dc);
        // Run the simulation
        try
        {
            dc.Run(ckt);
        }
        catch (ValidationFailedException e)
        {
            Debug.Log("Error is: " + e.ToString());
        }
    }
Exemple #24
0
        /// <summary>
        /// Forces the stepping down of an opened source when things gets out of control.
        /// Used when session state and source state become out of sync.
        /// </summary>
        /// <param name="targetState">State of the target.</param>
        public void ForceStepDown(int targetState)
        {
            PlatformInfo.Current.Log.Debug("Thread {0}: ForceStepDown.", Thread.CurrentThread.ManagedThreadId);

            bool origFlag = EnforceState;

            EnforceState = false;

            // From the twain spec
            // Stepping Back Down the States
            // DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER → state 7 to 6
            // DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET → state 6 to 5
            // DG_CONTROL / DAT_USERINTERFACE / MSG_DISABLEDS → state 5 to 4
            // DG_CONTROL / DAT_IDENTITY / MSG_CLOSEDS → state 4 to 3
            // Ignore the status returns from the calls prior to the one yielding the desired state. For instance, if a
            // call during scanning returns TWCC_SEQERROR and the desire is to return to state 5, then use the
            // following commands.
            // DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER → state 7 to 6
            // DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET → state 6 to 5
            // Being sure to confirm that DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET returned
            // success, the return status from DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER may
            // be ignored.

            _msgLoopHook?.Invoke(() =>
            {
                if (targetState < 7 && CurrentSource != null)
                {
                    // not sure if really necessary but can't hurt to pin it
                    var pending = new TWPendingXfers();
                    var handle  = GCHandle.Alloc(pending, GCHandleType.Pinned);
                    try
                    {
                        ((ITwainSessionInternal)this).DGControl.PendingXfers.EndXfer(pending);
                    }
                    finally
                    {
                        handle.Free();
                    }
                }
                if (targetState < 6 && CurrentSource != null)
                {
                    var pending = new TWPendingXfers();
                    var handle  = GCHandle.Alloc(pending, GCHandleType.Pinned);
                    try
                    {
                        ((ITwainSessionInternal)this).DGControl.PendingXfers.Reset(pending);
                    }
                    finally
                    {
                        handle.Free();
                    }
                }
                if (targetState < 5 && CurrentSource != null)
                {
                    ((ITwainSessionInternal)this).DisableSource();
                }
                if (targetState < 4 && CurrentSource != null)
                {
                    CurrentSource.Close();
                }
                if (targetState < 3)
                {
                    Close();
                }
            });
            EnforceState = origFlag;
        }