Ejemplo n.º 1
0
 public void ProcessCommand(string command)
 {
     if (command.Contains("Add I"))
     {
         var form = new InstrumentForm();
         form.Show();
     }
 }
Ejemplo n.º 2
0
 public InstrumentFormDataChangedHandler(
     InstrumentType instrumentTYpe,
     InstrumentForm instrumentForm,
     IInstrumentFormSettingsWriter instrumentFormSettingsWriter = null
     )
 {
     _instrumentType = instrumentTYpe;
     _instrumentForm = instrumentForm;
     _instrumentFormSettingsWriter = instrumentFormSettingsWriter ?? new InstrumentFormSettingsWriter();
 }
        public InstrumentForm Create
        (
            InstrumentType instrumentType,
            IInstrumentRenderer renderer,
            Image initialImage = null
        )
        {
            var currentSettings = _instrumentFormSettingsReader.Read(instrumentType.ToString());

            if (!currentSettings.Enabled)
            {
                return(null);
            }
            Point location;
            Size  size;
            var   screen         = Util.FindScreen(currentSettings.OutputDisplay);
            var   instrumentForm = new InstrumentForm {
                Text = instrumentType.ToString(), ShowInTaskbar = false, ShowIcon = false, Settings = currentSettings
            };

            if (currentSettings.StretchToFit)
            {
                location = new Point(0, 0);
                size     = screen.Bounds.Size;
                instrumentForm.StretchToFill = true;
            }
            else
            {
                location = new Point(currentSettings.ULX, currentSettings.ULY);
                size     = new Size(currentSettings.LRX - currentSettings.ULX, currentSettings.LRY - currentSettings.ULY);
                instrumentForm.StretchToFill = false;
            }
            instrumentForm.AlwaysOnTop = currentSettings.AlwaysOnTop;
            instrumentForm.Monochrome  = currentSettings.Monochrome;
            instrumentForm.Rotation    = currentSettings.RotateFlipType;
            instrumentForm.WindowState = FormWindowState.Normal;
            Util.OpenFormOnSpecificMonitor(instrumentForm, screen, location, size, true, true);
            instrumentForm.DataChanged += new InstrumentFormDataChangedHandler(instrumentType, instrumentForm).HandleDataChangedEvent;

            if (initialImage == null)
            {
                return(instrumentForm);
            }
            using (var graphics = (Graphics)instrumentForm.CreateGraphics())
            {
                graphics.DrawImageFast(initialImage, instrumentForm.ClientRectangle);
            }
            return(instrumentForm);
        }
Ejemplo n.º 4
0
        /*
         * Handler for the Add Button click event
         */
        private void lvInstruments_OnAdd()
        {
            var form = new InstrumentForm();
            var instrumentDescription = new InstrumentDescription();

            form.InstrumentDescription = instrumentDescription;
            if (DialogResult.OK == form.ShowDialog())
            {
                instrumentDescription = form.InstrumentDescription;
                var document = new Document();
                SaveInstrumentDescriptionDocument(instrumentDescription, document, BASEBean.eDataState.DS_ADD);
                AddDocumentToInstrumentList(document);
                LoadInstrumentPreview();
            }
        }
Ejemplo n.º 5
0
 /*
  * Handler for the Edit Button click event
  */
 private void lvInstruments_OnEdit()
 {
     if (lvInstruments.HasSelected)
     {
         var document = lvInstruments.SelectedObject as Document;
         var form     = new InstrumentForm();
         InstrumentDescription instrumentDescription =
             InstrumentDescription.Deserialize(Encoding.UTF8.GetString(document.DocumentContent));
         form.InstrumentDescription = instrumentDescription;
         if (DialogResult.OK == form.ShowDialog())
         {
             instrumentDescription = form.InstrumentDescription;
             SaveInstrumentDescriptionDocument(instrumentDescription, document, BASEBean.eDataState.DS_EDIT);
             UpdateExistingDocumentInList(document, instrumentDescription.uuid);
             LoadInstrumentPreview();
         }
     }
 }
        private void btnEditObject_Click(object sender, EventArgs e)
        {
            TestStationDescriptionInstrument tsi =
                testStationDescriptionInstrumentControl1.TestStationDescriptionInstrument;

            if (tsi != null && tsi.Item != null)
            {
                var docRef = tsi.Item as DocumentReference;
                if (docRef != null)
                {
                    Document document = DocumentManager.GetDocument(docRef.uuid);
                    if (document == null)
                    {
                        MessageBox.Show(string.Format("Test Station Instrument \"{0}\" does not exist in the document database.", docRef.uuid));
                    }
                    else
                    {
                        InstrumentDescription instrument =
                            InstrumentDescription.Deserialize(Encoding.UTF8.GetString(document.DocumentContent));
                        var form = new InstrumentForm();
                        form.InstrumentDescription = instrument;
                        //form.TopMost = true;
                        Visible      = false;
                        form.Closed += delegate
                        {
                            if (DialogResult.OK == form.DialogResult)
                            {
                                instrument = form.InstrumentDescription;
                                document.DocumentContent = Encoding.UTF8.GetBytes(instrument.Serialize());
                                PersistanceController.Save(document);
                            }
                            Visible = true;
                        };
                        form.Show(this);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private Bitmap ObtainRenderSurface(InstrumentForm targetForm)
        {
            if (!_renderSurfaces.ContainsKey(targetForm) ||
                (
                    (
                        targetForm.Rotation.ToString().Contains("90") || targetForm.Rotation.ToString().Contains("270")
                    )
                    &&
                    (_renderSurfaces[targetForm].Width != targetForm.ClientRectangle.Height
                     ||
                     _renderSurfaces[targetForm].Height != targetForm.ClientRectangle.Width
                    )
                )
                ||
                (
                    (
                        !targetForm.Rotation.ToString().Contains("90") && !targetForm.Rotation.ToString().Contains("270")
                    )
                    &&
                    (_renderSurfaces[targetForm].Width != targetForm.ClientRectangle.Width
                     ||
                     _renderSurfaces[targetForm].Height != targetForm.ClientRectangle.Height
                    )
                )
                ||
                (
                    !_formRotations.ContainsKey(targetForm) || targetForm.Rotation != _formRotations[targetForm]
                )
                )

            {
                _renderSurfaces[targetForm] = CreateRenderSurface(targetForm);

                _formRotations[targetForm] = targetForm.Rotation;
            }
            return(_renderSurfaces[targetForm]);
        }
Ejemplo n.º 8
0
        private void newInstrumentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InstrumentForm frm = new InstrumentForm(new Instrument(), this);

            frm.ShowDialog();
        }
Ejemplo n.º 9
0
        private void lbtAddnew_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            InstrumentForm frm = new InstrumentForm(new Instrument(), MdiParentForm);

            frm.ShowDialog();
        }
Ejemplo n.º 10
0
        public override void EditSelectedItem()
        {
            InstrumentForm frm = new InstrumentForm(GetSelectedInstrument(), MdiParentForm);

            frm.ShowDialog();
        }
Ejemplo n.º 11
0
        public void Render(
            IInstrumentRenderer renderer,
            InstrumentForm targetForm,
            RotateFlipType rotation,
            bool monochrome,
            bool highlightBorder,
            bool nightVisionMode)
        {
            try
            {
                if (!targetForm.Visible || targetForm.IsDisposed)
                {
                    return;
                }
                var renderSurface = ObtainRenderSurface(targetForm);

                using (var destinationGraphics = Graphics.FromImage(renderSurface))
                {
                    try
                    {
                        renderer.Render(destinationGraphics,
                                        new Rectangle(0, 0, renderSurface.Width, renderSurface.Height));
                        targetForm.LastRenderedOn = DateTime.UtcNow;
                        if (highlightBorder)
                        {
                            HighlightBorder(destinationGraphics, renderSurface);
                        }
                    }
                    catch (ThreadAbortException)
                    {
                    }
                    catch (ThreadInterruptedException)
                    {
                    }
                    catch (Exception ex)
                    {
                        var rendererName = renderer != null?renderer.GetType().FullName : "unknown";

                        _log.Error($"An error occurred while rendering {rendererName}", ex);
                    }
                }
                if (rotation != RotateFlipType.RotateNoneFlipNone)
                {
                    renderSurface.RotateFlip(rotation);
                }
                using (var graphics = targetForm.CreateGraphics())
                {
                    if (nightVisionMode)
                    {
                        RenderWithNightVisionEffect(targetForm, graphics, renderSurface);
                    }
                    else if (monochrome)
                    {
                        RenderWithMonochromeEffect(targetForm, graphics, renderSurface);
                    }
                    else
                    {
                        RenderWithStandardEffect(graphics, renderSurface);
                    }
                }
            }
            catch (ExternalException)
            {
                //GDI+ error message we don't care about
            }
            catch (ObjectDisposedException)
            {
                //GDI+ error message thrown on operations on disposed images -- can happen when one thread disposes while shutting-down thread tries to render
            }
            catch (ArgumentException)
            {
                //GDI+ error message we don't care about
            }
            catch (OutOfMemoryException)
            {
                //bullshit OOM messages from GDI+
            }
            catch (InvalidOperationException)
            {
                //GDI+ error message we don't care about
            }
        }
Ejemplo n.º 12
0
 private static Bitmap CreateRenderSurface(InstrumentForm targetForm)
 {
     return(targetForm.Rotation.ToString().Contains("90") || targetForm.Rotation.ToString().Contains("270")
         ? new Bitmap(targetForm.ClientRectangle.Height, targetForm.ClientRectangle.Width, PixelFormat.Format32bppArgb)
         : new Bitmap(targetForm.ClientRectangle.Width, targetForm.ClientRectangle.Height, PixelFormat.Format32bppArgb));
 }
Ejemplo n.º 13
0
 private static bool HighlightingBorderShouldBeDisplayedOnTargetForm(InstrumentForm targetForm)
 {
     return(targetForm != null && targetForm.SizingOrMovingCursorsAreDisplayed && Settings.Default.HighlightOutputWindows);
 }
        public bool CaptureInstrumentStateSnapshotAndCheckIfStale(IInstrumentRenderer renderer, InstrumentForm instrumentForm)
        {
            if (renderer == null)
            {
                return(false);
            }
            var storedState         = _instrumentStates.ContainsKey(renderer) ? _instrumentStates[renderer] : InstrumentStateSnapshot.Default;
            var latestState         = CaptureStateSnapshot(renderer);
            var newStateIsDifferent = (storedState.HashCode != latestState.HashCode);

            if (newStateIsDifferent)
            {
                _instrumentStates.AddOrUpdate(renderer, latestState, (x, y) => latestState);
            }
            else
            {
                latestState = storedState;
            }
            var timeSinceLastRendered = instrumentForm != null?
                                        DateTime.UtcNow.Subtract(instrumentForm.LastRenderedOn).TotalMilliseconds
                                        : 0;

            var isStale = instrumentForm != null && (newStateIsDifferent || instrumentForm.LastRenderedOn <latestState.DateTime || timeSinceLastRendered> StaleDataTimeoutMilliseconds);

            return(isStale);
        }