Click here to Skip to main content
15,892,746 members
Articles / Multimedia / OpenGL

Universal Framework for Science and Engineering - Part 7: Virtual Reality at Once

Rate me:
Please Sign up or sign in to vote.
4.96/5 (105 votes)
19 Nov 2010CPOL25 min read 187.4K   14.4K   212  
An article on framework applications to virtual reality
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DiagramUI.Interfaces;

namespace DiagramUI
{
    /// <summary>
    /// The belongs to collection link
    /// </summary>
    [Serializable()]
    public class BelongsToCollection : CategoryArrow, ISerializable, IRemovableObject
    {
        #region Fields

        /// <summary>
        /// Source
        /// </summary>
        private IAddRemove source;

        /// <summary>
        /// Target
        /// </summary>
        private ICategoryObject target;

        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public BelongsToCollection()
        {
        }

        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        protected BelongsToCollection(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion

        #region ISerializable Members

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion

        #region Overriden Members

        /// <summary>
        /// Source
        /// </summary>
        public override ICategoryObject Source
        {
            get
            {
                return source as ICategoryObject;
            }
            set
            {
                source = value.GetObject<ObjectsCollection>();
            }
        }

        /// <summary>
        /// Target
        /// </summary>
        public override ICategoryObject Target
        {
            get
            {
                return target as ICategoryObject;
            }
            set
            {
                if (Check(value))
                {
                    return;
                }
                CategoryException.ThrowIllegalTargetException();
            }
        }

        #endregion

        #region IRemovableObject Members

        void IRemovableObject.RemoveObject()
        {
            if ((source != null) & (target != null))
            {
                source.Remove(target);
                source = null;
                target = null;
            }
        }

        #endregion

        #region Members

        private void Accept(ICategoryObject value)
        {
            target = value;
            source.Add(target);
        }

        private bool Check(ICategoryObject value)
        {
            Type t = value.GetType();
            Type to = source.Type;
            if (t.Equals(to) | t.IsSubclassOf(to))
            {
                Accept(value);
                return true;
            }
            Type[] types = t.GetInterfaces();
            foreach (Type tp in types)
            {
                if (tp.Equals(to))
                {
                    Accept(value);
                    return true;
                }
            }
            if (value is IChildrenObject)
            {
                IChildrenObject ch = value as IChildrenObject;
                IAssociatedObject[] ass = ch.Children;
                if (ass != null)
                {
                    foreach (object o in ass)
                    {
                        if (o is ICategoryObject)
                        {
                            ICategoryObject co = o as ICategoryObject;
                            if (Check(co))
                            {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions