Ejemplo n.º 1
0
        private void ParseDrawings(XmlReader r, PointF scale)
        {
            // Note:
            // We do not do a metadata.AddDrawing at this point, only add the drawing internally to the keyframe without side-effects.
            // We wait for the complete keyframe to be parsed and ready, and then merge-insert it into the existing collection.
            // The drawing post-initialization will only be done at that point.
            // This prevents doing post-initializations too early when the keyframe is not yet added to the metadata collection.

            bool isEmpty = r.IsEmptyElement;

            r.ReadStartElement();

            if (isEmpty)
            {
                return;
            }

            while (r.NodeType == XmlNodeType.Element)
            {
                AbstractDrawing drawing = DrawingSerializer.Deserialize(r, scale, TimeHelper.IdentityTimestampMapper, metadata);
                if (drawing == null || !drawing.IsValid)
                {
                    continue;
                }

                AddDrawing(drawing);
                drawing.InfosFading.ReferenceTimestamp        = this.Position;
                drawing.InfosFading.AverageTimeStampsPerFrame = metadata.AverageTimeStampsPerFrame;
            }

            r.ReadEndElement();
        }
Ejemplo n.º 2
0
        public override AbstractDrawing GetNewDrawing(PointF origin, long timestamp, long averageTimeStampsPerFrame, IImageToViewportTransformer transformer)
        {
            // Drawings constructors must conforms to one of two predefined prototypes:
            // (PointF origin, long timestamp, long averageTimeStampsPerFrame, DrawingStyle preset = null, IImageToViewportTransformer transformer = null).
            // (PointF origin, long timestamp, long averageTimeStampsPerFrame, DrawingStyle stylePreset).
            // Exemple for 1: DrawingAngle.
            // Exemple for 2: DrawingText.

            ConstructorInfo ci = drawingType.GetConstructor(new[] { typeof(PointF), typeof(long), typeof(long), typeof(DrawingStyle), typeof(IImageToViewportTransformer) });

            if (ci != null)
            {
                object[]        parameters = new object[] { origin, timestamp, averageTimeStampsPerFrame, currentStyle, transformer };
                AbstractDrawing drawing    = (AbstractDrawing)Activator.CreateInstance(drawingType, parameters);
                return(drawing);
            }

            ci = drawingType.GetConstructor(new[] { typeof(PointF), typeof(long), typeof(long), typeof(DrawingStyle) });
            if (ci != null)
            {
                object[]        parameters = new object[] { origin, timestamp, averageTimeStampsPerFrame, currentStyle };
                AbstractDrawing drawing    = (AbstractDrawing)Activator.CreateInstance(drawingType, parameters);
                return(drawing);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// General method to add a drawing on a manager (keyframe-attched, chrono, track).
        /// </summary>
        public void AddDrawing(Guid managerId, AbstractDrawing drawing)
        {
            if (drawing == null)
            {
                return;
            }

            Keyframe keyframe = GetKeyframe(managerId);

            if (keyframe != null)
            {
                AddDrawing(keyframe, drawing);
                return;
            }

            if (chronoManager.Id == managerId && drawing is DrawingChrono)
            {
                AddChrono(drawing as DrawingChrono);
                return;
            }

            if (trackManager.Id == managerId && drawing is DrawingTrack)
            {
                AddTrack(drawing as DrawingTrack);
                return;
            }
        }
Ejemplo n.º 4
0
        public void ConfigureDrawing(AbstractDrawing drawing, Action refresh)
        {
            Keyframe   keyframe  = metadata.HitKeyframe;
            IDecorable decorable = drawing as IDecorable;

            if (keyframe == null || drawing == null || decorable == null)
            {
                return;
            }

            HistoryMementoModifyDrawing memento = new HistoryMementoModifyDrawing(metadata, keyframe.Id, drawing.Id, drawing.Name, SerializationFilter.Style);

            FormConfigureDrawing2 fcd = new FormConfigureDrawing2(decorable, refresh);

            FormsHelper.Locate(fcd);
            fcd.ShowDialog();

            if (fcd.DialogResult == DialogResult.OK)
            {
                memento.UpdateCommandName(drawing.Name);
                metadata.HistoryStack.PushNewCommand(memento);
            }

            fcd.Dispose();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the id of the keyframe the drawing is attached to.
        /// </summary>
        public Guid FindAttachmentKeyframeId(AbstractDrawing drawing)
        {
            Keyframe foundKeyframe = null;

            foreach (Keyframe k in keyframes)
            {
                foreach (AbstractDrawing d in k.Drawings)
                {
                    if (d.Id != drawing.Id)
                    {
                        continue;
                    }

                    foundKeyframe = k;
                    break;
                }

                if (foundKeyframe != null)
                {
                    break;
                }
            }

            return(foundKeyframe == null ? Guid.Empty : foundKeyframe.Id);
        }
Ejemplo n.º 6
0
        private void AfterDrawingCreation(AbstractDrawing drawing)
        {
            // When passing here, it is possible that the drawing has already been initialized.
            // (for example, for undo of delete, paste or reload from KVA).

            if (string.IsNullOrEmpty(drawing.Name))
            {
                SetDrawingName(drawing);
            }

            if (drawing is IScalable)
            {
                ((IScalable)drawing).Scale(this.ImageSize);
            }

            if (drawing is ITrackable && AddTrackableDrawingCommand != null)
            {
                AddTrackableDrawingCommand.Execute(drawing as ITrackable);
            }

            if (drawing is IMeasurable)
            {
                IMeasurable measurableDrawing = drawing as IMeasurable;
                measurableDrawing.CalibrationHelper = calibrationHelper;

                measurableDrawing.InitializeMeasurableData(trackExtraData);
                measurableDrawing.ShowMeasurableInfoChanged += MeasurableDrawing_ShowMeasurableInfoChanged;
            }

            if (drawing is DrawingDistortionGrid)
            {
                DrawingDistortionGrid d = drawing as DrawingDistortionGrid;
                d.LensCalibrationAsked += LensCalibrationAsked;
            }
        }
Ejemplo n.º 7
0
        public AbstractDrawing IsOnExtraDrawing(PointF point, long timestamp)
        {
            // Check if the mouse is on one of the drawings not attached to any key image.
            // Returns the drawing on which we stand (or null if none), and select it on the way.
            // the caller will then check its type and decide which action to perform.

            AbstractDrawing result = null;

            foreach (DrawingChrono chrono in chronoManager.Drawings)
            {
                int hit = chrono.HitTest(point, timestamp, calibrationHelper.DistortionHelper, imageTransform, imageTransform.Zooming);
                if (hit < 0)
                {
                    continue;
                }

                result     = chrono;
                hitDrawing = chrono;
                break;
            }

            if (result != null)
            {
                return(result);
            }

            foreach (DrawingTrack track in trackManager.Drawings)
            {
                int hit = track.HitTest(point, timestamp, calibrationHelper.DistortionHelper, imageTransform, imageTransform.Zooming);
                if (hit < 0)
                {
                    continue;
                }

                result     = track;
                hitDrawing = track;
                break;
            }

            if (result != null)
            {
                return(result);
            }

            for (int i = extraDrawings.Count - 1; i >= 0; i--)
            {
                AbstractDrawing candidate = extraDrawings[i];
                int             hitRes    = candidate.HitTest(point, timestamp, calibrationHelper.DistortionHelper, imageTransform, imageTransform.Zooming);
                if (hitRes < 0)
                {
                    continue;
                }

                result     = candidate;
                hitDrawing = candidate;
                break;
            }

            return(result);
        }
Ejemplo n.º 8
0
        public override void AddImageDrawing(string filename, bool isSvg)
        {
            if (!File.Exists(filename))
            {
                return;
            }

            view.BeforeAddImageDrawing();

            if (frameServer.Metadata.HitKeyframe == null)
            {
                return;
            }

            AbstractDrawing drawing = null;

            if (isSvg)
            {
                drawing = new DrawingSVG(frameServer.VideoReader.Current.Timestamp, frameServer.VideoReader.Info.AverageTimeStampsPerFrame, filename);
            }
            else
            {
                drawing = new DrawingBitmap(frameServer.VideoReader.Current.Timestamp, frameServer.VideoReader.Info.AverageTimeStampsPerFrame, filename);
            }

            if (drawing != null)
            {
                AddDrawingWithMemento(frameServer.Metadata.HitKeyframe.Id, drawing);
            }
        }
Ejemplo n.º 9
0
        private void PrepareContextMenuDrawing(AbstractDrawing drawing)
        {
            // Add menus depending on drawing capabilities and its own menus.
            if (drawing == null)
            {
                return;
            }

            if ((drawing.Caps & DrawingCapabilities.ConfigureColor) == DrawingCapabilities.ConfigureColor ||
                (drawing.Caps & DrawingCapabilities.ConfigureColorSize) == DrawingCapabilities.ConfigureColorSize)
            {
                mnuConfigureDrawing.Text = ScreenManagerLang.Generic_ConfigurationElipsis;
                popMenu.Items.Add(mnuConfigureDrawing);
            }

            if ((drawing.Caps & DrawingCapabilities.Opacity) == DrawingCapabilities.Opacity)
            {
                popMenu.Items.Add(mnuConfigureOpacity);
            }

            popMenu.Items.Add(new ToolStripSeparator());

            bool hasExtraMenus = AddDrawingCustomMenus(drawing, popMenu.Items);

            if (hasExtraMenus)
            {
                popMenu.Items.Add(new ToolStripSeparator());
            }

            // TODO: Add copy and paste menu here.

            popMenu.Items.Add(mnuDeleteDrawing);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a new track drawing.
        /// </summary>
        public void AddTrack(DrawingTrack track)
        {
            trackManager.AddDrawing(track);

            track.ParentMetadata = this;

            if (lastUsedTrackerParameters != null)
            {
                track.TrackerParameters = lastUsedTrackerParameters;
            }

            track.TrackerParametersChanged += Track_TrackerParametersChanged;

            hitDrawing = track;

            AfterDrawingCreation(track);

            // The following is necessary for the "undo of deletion" case.
            track.UpdateKinematics();
            track.IntegrateKeyframes();

            if (DrawingAdded != null)
            {
                DrawingAdded(this, new DrawingEventArgs(track, trackManager.Id));
            }
        }
Ejemplo n.º 11
0
        public override void AddDrawing(AbstractDrawing drawing)
        {
            if (!(drawing is DrawingChrono))
            {
                return;
            }

            drawings.Add(drawing);
        }
Ejemplo n.º 12
0
        public FormConfigureVisibility(AbstractDrawing drawing, Control screen)
        {
            this.drawing       = drawing;
            this.surfaceScreen = screen;
            this.memoFading    = drawing.InfosFading.Clone();

            InitializeComponent();
            Populate();
        }
Ejemplo n.º 13
0
        private InfosFading m_MemoInfosFading;     // Memo to fallback to on cancel.
        #endregion

        #region Construction & Initialization
        public formConfigureOpacity(AbstractDrawing _drawing, PictureBox _SurfaceScreen)
        {
            m_SurfaceScreen   = _SurfaceScreen;
            m_Drawing         = _drawing;
            m_MemoInfosFading = _drawing.InfosFading.Clone();

            InitializeComponent();
            ConfigureForm();
            LocalizeForm();
        }
Ejemplo n.º 14
0
        private void AddDrawingWithMemento(Guid managerId, AbstractDrawing drawing)
        {
            // Temporary function.
            // Once the player screen ui uses the viewport, this event handler should be removed.
            // The code here should also be in the metadata manipulator until this function is removed.
            HistoryMemento memento = new HistoryMementoAddDrawing(frameServer.Metadata, managerId, drawing.Id, drawing.ToolDisplayName);

            frameServer.Metadata.AddDrawing(managerId, drawing);
            historyStack.PushNewCommand(memento);
        }
        public override HistoryMemento PerformUndo()
        {
            HistoryMemento redoMemento = new HistoryMementoAddDrawing(metadata, managerId, drawingId, drawingName);

            redoMemento.CommandName = commandName;

            AbstractDrawing drawing = DrawingSerializer.DeserializeMemento(data, metadata);

            metadata.AddDrawing(managerId, drawing);
            return(redoMemento);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Get the precision cursor to use while manipulating the object.
        /// </summary>
        public Cursor GetManipulationCursor(AbstractDrawing drawing)
        {
            IDecorable decorable = drawing as IDecorable;

            if (decorable == null)
            {
                return(GetCursorPrecision(null, false));
            }

            return(GetCursorPrecision(decorable.DrawingStyle, false));
        }
Ejemplo n.º 17
0
        public formConfigureDrawing(AbstractDrawing _drawing, PictureBox _SurfaceScreen)
        {
            // This constructor is called when we will be updating a specific drawing.
            m_bPreConfigure = false;
            m_SurfaceScreen = _SurfaceScreen;
            m_Drawing       = _drawing;
            m_ToolType      = m_Drawing.ToolType;
            m_Drawing.MemorizeDecoration();

            SetupForm();
        }
Ejemplo n.º 18
0
 public override void AddDrawing(AbstractDrawing drawing)
 {
     // insert to the top of z-order except for grids.
     if (drawing is DrawingPlane)
     {
         drawings.Add(drawing);
     }
     else
     {
         drawings.Insert(0, drawing);
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Adds a new chronometer drawing.
        /// </summary>
        public void AddChrono(DrawingChrono chrono)
        {
            chronoManager.AddDrawing(chrono);
            chrono.ParentMetadata = this;

            hitDrawing = chrono;

            AfterDrawingCreation(chrono);

            if (DrawingAdded != null)
            {
                DrawingAdded(this, new DrawingEventArgs(chrono, chronoManager.Id));
            }
        }
Ejemplo n.º 20
0
        private void ParseTracks(XmlReader r, PointF scale)
        {
            // TODO: catch empty tag <Tracks/>.

            r.ReadStartElement();

            while (r.NodeType == XmlNodeType.Element)
            {
                AbstractDrawing drawing = DrawingSerializer.Deserialize(r, scale, RemapTimestamp, metadata);
                metadata.AddDrawing(metadata.TrackManager.Id, drawing);
            }

            r.ReadEndElement();
        }
Ejemplo n.º 21
0
        private void ParseChronos(XmlReader r, PointF scale)
        {
            // TODO: catch empty tag <Chronos/>.

            r.ReadStartElement();

            while (r.NodeType == XmlNodeType.Element)
            {
                AbstractDrawing drawing = DrawingSerializer.Deserialize(r, scale, TimeHelper.IdentityTimestampMapper, metadata);
                metadata.AddDrawing(metadata.ChronoManager.Id, drawing);
            }

            r.ReadEndElement();
        }
Ejemplo n.º 22
0
        public CommandDeleteDrawing(Action _invalidate, Metadata _Metadata, long _iFramePosition, int _iDrawingIndex)
        {
            m_DoScreenInvalidate = _invalidate;
            m_iFramePosition     = _iFramePosition;
            m_Metadata           = _Metadata;
            m_iDrawingIndex      = _iDrawingIndex;

            int iIndex = GetKeyframeIndex();

            if (iIndex >= 0)
            {
                m_Drawing = m_Metadata[iIndex].Drawings[m_iDrawingIndex];
            }
        }
        public static AbstractDrawing Deserialize(XmlReader r, PointF scaling, TimestampMapper timestampMapper, Metadata metadata)
        {
            AbstractDrawing drawing = null;

            if (r.IsEmptyElement)
            {
                r.ReadStartElement();
                return(null);
            }

            // Find the right class to instanciate.
            // The class must derive from AbstractDrawing and have the corresponding [XmlType] C# attribute.
            bool     drawingRead = false;
            Assembly a           = Assembly.GetExecutingAssembly();

            foreach (Type t in a.GetTypes())
            {
                if (t.BaseType != typeof(AbstractDrawing))
                {
                    continue;
                }

                object[] attributes = t.GetCustomAttributes(typeof(XmlTypeAttribute), false);
                if (attributes.Length <= 0 || ((XmlTypeAttribute)attributes[0]).TypeName != r.Name)
                {
                    continue;
                }

                ConstructorInfo ci = t.GetConstructor(new[] { typeof(XmlReader), typeof(PointF), typeof(TimestampMapper), typeof(Metadata) });
                if (ci == null)
                {
                    break;
                }

                object[] parameters = new object[] { r, scaling, timestampMapper, metadata };
                drawing     = (AbstractDrawing)Activator.CreateInstance(t, parameters);
                drawingRead = drawing != null;

                break;
            }

            if (!drawingRead)
            {
                string unparsed = r.ReadOuterXml();
                log.DebugFormat("Unparsed content in KVA XML: {0}", unparsed);
            }

            return(drawing);
        }
Ejemplo n.º 24
0
        public void DeleteHitDrawing()
        {
            Keyframe        keyframe = metadata.HitKeyframe;
            AbstractDrawing drawing  = metadata.HitDrawing;

            if (keyframe == null || drawing == null)
            {
                return;
            }

            HistoryMemento memento = new HistoryMementoDeleteDrawing(metadata, keyframe.Id, drawing.Id, drawing.ToolDisplayName);

            metadata.DeleteDrawing(keyframe.Id, drawing.Id);
            metadata.HistoryStack.PushNewCommand(memento);
        }
Ejemplo n.º 25
0
        public CommandAddDrawing(DelegateScreenInvalidate _invalidate, DelegateDrawingUndrawn _undrawn, Metadata _Metadata, long _iFramePosition)
        {
            m_DoInvalidate = _invalidate;
            m_DoUndrawn    = _undrawn;

            m_iFramePosition = _iFramePosition;
            m_Metadata       = _Metadata;

            int iIndex = GetKeyframeIndex();

            if (iIndex >= 0)
            {
                m_iTotalDrawings = m_Metadata[iIndex].Drawings.Count;
                m_Drawing        = m_Metadata[iIndex].Drawings[0];
            }
        }
Ejemplo n.º 26
0
        public void ModifiedDrawing(Guid managerId, Guid drawingId)
        {
            AbstractDrawing drawing = GetDrawing(managerId, drawingId);
            DrawingTrack    track   = drawing as DrawingTrack;

            if (track != null)
            {
                track.UpdateKinematics();
                track.IntegrateKeyframes();
            }

            if (DrawingModified != null)
            {
                DrawingModified(this, new DrawingEventArgs(drawing, managerId));
            }
        }
Ejemplo n.º 27
0
 public void ShowDataAnalysis(AbstractDrawing drawing)
 {
     /*if (drawing is DrawingCrossMark)
      * {
      *  FormPointsAnalysis fpa = new FormPointsAnalysis(frameServer.Metadata);
      *  FormsHelper.Locate(fpa);
      *  fpa.ShowDialog();
      *  fpa.Dispose();
      * }
      * else if (drawing is DrawingTrack)
      * {
      *  FormTrackAnalysis fta = new FormTrackAnalysis(frameServer.Metadata, drawing as DrawingTrack);
      *  FormsHelper.Locate(fta);
      *  fta.ShowDialog();
      *  fta.Dispose();
      * }*/
 }
Ejemplo n.º 28
0
        public void DeleteDrawing(Guid managerId, Guid drawingId)
        {
            // Remove event handlers from the drawing as well as all associated data like tracking data,
            // and finally remove the drawing itself.

            AbstractDrawingManager manager = null;

            if (managerId == chronoManager.Id)
            {
                manager = chronoManager;
            }
            else if (managerId == trackManager.Id)
            {
                manager = trackManager;
            }
            else
            {
                manager = GetKeyframe(managerId);
            }

            if (manager == null)
            {
                return;
            }

            AbstractDrawing drawing = manager.GetDrawing(drawingId);

            if (drawing == null)
            {
                return;
            }

            BeforeDrawingDeletion(drawing);

            manager.RemoveDrawing(drawingId);
            UnselectAll();

            if (DrawingDeleted != null)
            {
                DrawingDeleted(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 29
0
        private void SetDrawingName(AbstractDrawing drawing)
        {
            // Use a unique name based on drawing type.
            string toolDisplayName = drawing.ToolDisplayName;
            int    index           = 1;
            bool   done            = false;
            string name            = "";

            while (!done)
            {
                name = string.Format("{0} {1}", toolDisplayName, index);
                if (!IsNameTaken(name))
                {
                    break;
                }

                index++;
            }

            drawing.Name = name;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Adds a drawing to the specified keyframe.
        /// </summary>
        public void AddDrawing(Keyframe keyframe, AbstractDrawing drawing)
        {
            if (keyframe == null || drawing == null || !drawing.IsValid)
            {
                return;
            }

            keyframe.AddDrawing(drawing);
            drawing.InfosFading.ReferenceTimestamp        = keyframe.Position;
            drawing.InfosFading.AverageTimeStampsPerFrame = averageTimeStampsPerFrame;

            SelectKeyframe(keyframe);
            SelectDrawing(drawing);

            AfterDrawingCreation(drawing);

            if (DrawingAdded != null)
            {
                DrawingAdded(this, new DrawingEventArgs(drawing, keyframe.Id));
            }
        }