Example #1
0
        private IEnumerable <XElement> ExecutePlugin(IDspPlugin1 p, IEnumerable <XElement> selectedsignals, double time_cursor, string parameter)
        {
            IEnumerable <XElement> retsigs = null;

            foreach (XElement xe in selectedsignals)
            {
                RendererManager.CloseRenderer(xe);
            }

            try
            {
                string path = Environment.CurrentDirectory + "\\" + "unisens.xml";
                retsigs = p.Main(UnisensXmlFileManager.CurrentUnisensInstance.Xdocument, selectedsignals, path, time_cursor, signalviewercontrol.SelectionStart, signalviewercontrol.SelectionEnd, parameter);
            }
            catch (Exception ex)
            {
                retsigs = null;
                MessageBox.Show("Exception im Plugin: " + ex.Message);
            }

            foreach (XElement xe in selectedsignals)
            {
                try
                {
                    RendererManager.ReOpenRenderer(xe);
                }
                catch
                {
                    RendererManager.KillRenderer(xe);
                }
            }

            if (retsigs != null)
            {
                foreach (XElement xe in retsigs)
                {
                    if (StackerControl.IsSignalEventValueEntry(xe))
                    {
                        signalviewercontrol.stackercontrol.DropSignalEventValueEntry(xe, null);
                    }
                }
            }

            signalviewercontrol.Deselect();
            if (RendererManager.TimeMax < RendererManager.Time)
            {
                RendererManager.Scroll(0.0);
            }
            else
            {
                RendererManager.Render();
            }

            // Save Unisens file after Plugin execution
            Executed_Save(null, null);

            return(retsigs);
        }
Example #2
0
        private static bool cropSelection(double time_start, double time_end, XDocument unisensxml, IEnumerable <XElement> selectedsignals)
        {
            // If you want to delete more than 10 % of the signal, an extra warning is given.
            double length = Crop.GetSignalLength(unisensxml, selectedsignals);

            if (time_end - time_start < length * 0.9)
            {
                if (MessageBox.Show("Sind Sie Sich sicher, dass Sie mehr als 10% der Daten löschen wollen?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) == MessageBoxResult.No)
                {
                    return(false);
                }
            }

            // Renderer schließen
            foreach (XElement xe in selectedsignals)
            {
                RendererManager.CloseRenderer(xe);
            }

            foreach (XElement xe in selectedsignals)
            {
                switch (xe.Name.LocalName)
                {
                case "signalEntry":
                case "eventEntry":
                case "valuesEntry":

                    switch (MeasurementEntry.GetFileFormat(xe))
                    {
                    case FileFormat.Bin:
                        CropBinary(xe, time_start, time_end);
                        break;

                    case FileFormat.Csv:
                        CropCsv(xe, time_start, time_end);
                        break;
                    }

                    break;
                }
            }

            // Renderer aktivieren
            foreach (XElement xe in selectedsignals)
            {
                try
                {
                    RendererManager.ReOpenRenderer(xe);
                }
                catch
                {
                    RendererManager.KillRenderer(xe);
                }
            }

            // If duration attribute is known: Recalculate duration attribute
            ResetDuration(unisensxml, time_end - time_start);
            ResetTimestampStart(unisensxml, time_start);
            RendererManager.UpdateTimeMax();

            return(true);
        }
Example #3
0
        public static IEnumerable <XElement> setArtifact(double time_start, double time_end, string artifactSymbol_Start, string artifactSymbol_End)
        {
            XDocument unisensxml = UnisensXmlFileManager.CurrentUnisensInstance.Xdocument;
            IEnumerable <XElement> selectedsignals = from XElement xe in unisensxml.Root.Elements()
                                                     where xe.Name.LocalName == "signalEntry" || xe.Name.LocalName == "eventEntry" || xe.Name.LocalName == "valuesEntry"
                                                     select xe;
            XElement        evententry = FindArtifactsEntry(selectedsignals);
            List <XElement> ret        = null;

            if (evententry == null)
            { // kein EventEntry vorhanden, erstelle eine neue EventEntry
                MessageBox.Show("Es wird ein neues Artefakt-Entry mit der ID '" + Properties.Settings.Default.ArtifactEntryId + "' erstellt. ");
                evententry = CreateArtifactsEntry(unisensxml, GetMaxSampleRate(selectedsignals));
                ret        = new List <XElement>();
                ret.Add(evententry);
            }

            // Renderer schließen
            foreach (XElement xe in selectedsignals)
            {
                RendererManager.CloseRenderer(xe);
            }
            string comment       = null;
            string artifactsfile = evententry.Attribute("id").Value;
            double samplespersec = EventEntry.GetSampleRate(evententry);

            delim = EventEntry.GetCsvFileFormatSeparator(evententry);
            int sample_start = (int)(time_start * samplespersec);
            int sample_end   = (int)(time_end * samplespersec);

            // Artefakt-Kommentare sind erstmal deaktiviert
            //DialogsArtifacts dialogsArtifact = new DialogsArtifacts();
            //dialogsArtifact.Topmost = true;

            //if (dialogsArtifact.ShowDialog() != (DialogsArtifacts.artifact))
            //{
            //    comment = DialogsArtifacts.artifact_comment;
            //}

            string artifactStart = delim + artifactSymbol_Start + ";" + comment;
            string artifactEnd   = delim + artifactSymbol_End + ";" + comment;

            StreamWriter csv_out = null;
            StreamReader csv_in  = null;

            try
            {
                // Temporäre Datei erzeugen, um Marker an entsprechender Stelle einfügen zu können.
                csv_in  = new StreamReader(artifactsfile);
                csv_out = new StreamWriter(artifactsfile + ".tmp");
            }
            catch
            {
                return(null);
            }

            string s1 = csv_in.ReadLine();
            string s2 = csv_in.ReadLine();

            // implements for reading and writting the data
            bool aldready = false;

            while (s1 != null && s2 != null)
            {
                int a = s1.IndexOf(delim);
                int b = s2.IndexOf(delim);
                if (a == -1 || b == -1)
                {
                    break;
                }

                int x1 = int.Parse(s1.Substring(0, a), CultureInfo.InvariantCulture.NumberFormat);
                int x2 = int.Parse(s2.Substring(0, b), CultureInfo.InvariantCulture.NumberFormat);

                if (sample_end < x1)
                {
                    if (aldready == false)
                    {
                        csv_out.WriteLine(sample_start + artifactStart);
                        csv_out.WriteLine(sample_end + artifactEnd);
                        aldready = true;
                    }
                }
                else if ((x1 < sample_start && sample_start < x2) || (x1 < sample_end && sample_end < x2) || (sample_start < x1 && x2 < sample_end))
                {
                    MessageBox.Show("Der ausgewählte Bereich hat eine Überlappung. Bitte wählen Sie einen anderen Bereich!");
                    aldready = true;
                }

                csv_out.WriteLine(s1);
                csv_out.WriteLine(s2);
                s1 = csv_in.ReadLine();
                s2 = csv_in.ReadLine();
            }

            if (aldready == false) // SAMPLESTAMP_START;(artifact; noch nicht abgelegt
            {
                csv_out.WriteLine(sample_start + artifactStart);
                csv_out.WriteLine(sample_end + artifactEnd);
                aldready = true;
            }

            //while ((line = csv_in.ReadLine()) != null)
            //{
            //    int a = line.IndexOf(delim);
            //    if (a == -1)
            //    {
            //        break;
            //    }

            //    int timeStamp = int.Parse(line.Substring(0, a), CultureInfo.InvariantCulture.NumberFormat);
            //    if (timeStamp < sample_start)
            //    {
            //        csv_out.WriteLine(line);
            //    }
            //    else
            //    {
            //        if (start == false)
            //        {
            //            csv_out.WriteLine(sample_start + artifactStart);
            //            start = true; // write SAMPLESTAMP_START;(artifact already
            //        }

            //        if (timeStamp < sample_end)
            //        {
            //            csv_out.WriteLine(line);
            //        }
            //        else
            //        {
            //            if (end == false)
            //            {
            //                csv_out.WriteLine(sample_end + artifactEnd);
            //                end = true;
            //            }
            //            csv_out.WriteLine(line);
            //        }
            //    }
            //}

            //if (start == false) // SAMPLESTAMP_START;(artifact; noch nicht abgelegt
            //{
            //    csv_out.WriteLine(sample_start + artifactStart);
            //    start = true;
            //}
            //if (end == false)
            //{
            //    csv_out.WriteLine(sample_end + artifactEnd);
            //    end = true;
            //}

            csv_in.Close();
            csv_in.Dispose();
            csv_in = null;
            File.Delete(artifactsfile);

            // Die ursprüngliche Marker-Datei (oben schon gelöscht) durch temporäre Datei ersetzen.
            csv_out.Close();
            csv_out.Dispose();
            csv_out = null;
            File.Move(artifactsfile + ".tmp", artifactsfile);

            // Rendere wieder aktivieren
            foreach (XElement xe in selectedsignals)
            {
                try
                {
                    RendererManager.ReOpenRenderer(xe);
                }
                catch
                {
                    RendererManager.KillRenderer(xe);
                }
            }

            // UnisensViewer das neue eventEntry (falls eins erzeugt wurde) zum Stapel hinzufügen lassen
            return(ret);
        }
Example #4
0
        /// - Hotkey muss mit SelectedSignals="StackFiles" konfiguriert sein!
        ///    => selectedsignals enthält alle Signale im Stapel
        /// - parameter == "truncate" für truncate-Funktion
        /// <summary>
        /// Main function for plug-ins, called by UnisensViewer.
        /// </summary>
        /// <param name="unisensxml">unisens.xml file.</param>
        /// <param name="selectedsignals">All information from unisens.xml of the selected signals.</param>
        /// <param name="path">Path of the current unisens.xml file.</param>
        /// <param name="time_cursor">Time in seconds of current cursor position. Is 0, if the plug-in is called via plug-in menu.</param>
        /// <param name="time_start">Time in seconds of start of the current selection. Is 0, when no selection exists.</param>
        /// <param name="time_end">Time in seconds of end of the current selection. Is 0, when no selection exists.</param>
        /// <param name="parameter">Additional parameter of the key bindings.</param>
        /// <returns>
        /// Returned signals have to be described by the corresponding Unisens XML element (e.g. signalEntry or eventEntry). UnisensViewer displays the returned signals directly.
        /// </returns>
        private static IEnumerable <XElement> main(IEnumerable <XElement> selectedsignals, double time_cursor, double time_start, double time_end, string markerSymbol, MarkerOperation operation)
        {
            XDocument unisensxml = UnisensXmlFileManager.CurrentUnisensInstance.Xdocument;

            //// Marker-Datei im Signal-Stapel suchen.
            //// Falls keine vorhanden:
            ////  - eindeutigen Dateinamen für Marker-Datei generieren
            ////  - in Unisens-Metadatei einen neuen eventEntry mit Marker-Dateinamen erzeugen
            XElement        evententry = FindMarkerEntry(selectedsignals);
            List <XElement> ret        = null;

            if (evententry == null)
            {
                if (operation == MarkerOperation.Truncate || operation == MarkerOperation.Delete)
                {
                    return(null);
                }

                evententry = CreateMarkerEntry(unisensxml, GetMaxSampleRate(selectedsignals));

                if (evententry == null)
                {
                    return(null);
                }

                ret = new List <XElement>();
                ret.Add(evententry);
            }

            // kein Auswahl
            if (time_start == 0 & time_end == 0)
            {
                time_start = time_end = time_cursor;
            }

            string markerfile    = evententry.Attribute("id").Value;
            double samplespersec = EventEntry.GetSampleRate(evententry);

            delim = EventEntry.GetCsvFileFormatSeparator(evententry);
            int sample_cursor = (int)(time_cursor * samplespersec);
            int sample_start  = (int)(time_start * samplespersec);
            int sample_end    = (int)(time_end * samplespersec);

            string mark = delim + markerSymbol;

            if (!File.Exists(markerfile))
            {
                FileStream fs = File.Create(markerfile);
                fs.Close();
            }

            StreamReader csv_in  = new StreamReader(markerfile);
            StreamWriter csv_out = new StreamWriter(markerfile + ".tmp");

            Boolean success = false;

            switch (operation)
            {
            case MarkerOperation.Set:
                success = Set(csv_in, csv_out, sample_cursor, mark);
                break;

            case MarkerOperation.Delete:
                success = Delete(csv_in, csv_out, sample_start, sample_end);
                break;

            case MarkerOperation.Truncate:
                success = Truncate(csv_in, csv_out, sample_cursor);
                break;
            }

            csv_in.Close();
            csv_in.Dispose();
            csv_out.Close();
            csv_out.Dispose();

            if (success)
            {
                // Die ursprüngliche Marker-Datei durch temporäre Datei ersetzen.
                File.Delete(markerfile);
                File.Move(markerfile + ".tmp", markerfile);
            }
            else
            {
                // Die temporäre Marker-Datei löschen
                File.Delete(markerfile + ".tmp");
            }

            // Rendere wieder aktivieren
            foreach (XElement xe in selectedsignals)
            {
                try
                {
                    RendererManager.ReOpenRenderer(xe);
                }
                catch
                {
                    RendererManager.KillRenderer(xe);
                }
            }

            // UnisensViewer den neuen eventEntry (falls einer erzeugt wurde) zum Stapel hinzufügen lassen
            return(ret);
        }