Exemplo n.º 1
0
 // ------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ConnectorBase"/>
 /// class.
 /// </summary>
 /// <param name="p">Point: The location of the conector.</param>
 // ------------------------------------------------------------------
 protected ConnectorBase(Point p)
     : base()
 {
     mAttachedConnectors = new CollectionBase <IConnector>();
     this.mPoint         = p;
     this.InitializeConnector();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Inits this instance.
 /// </summary>
 protected override void Initialize()
 {
     base.Initialize();
     mConnectors              = new CollectionBase <IConnector>();
     mConnectors.OnItemAdded += new EventHandler <CollectionEventArgs <IConnector> >(mConnectors_OnItemAdded);
     mRectangle = new Rectangle(0, 0, 100, 70);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Perform redo of this command.
        /// </summary>
        public override void Redo()
        {
            //create a new group; use the standard GroupShape or the CollapsibleGroupShape for a painted group with collapse/expand features.
            //GroupShape group = new GroupShape(this.Controller.Model);
            CollapsibleGroupShape group = new CollapsibleGroupShape(this.controller.Model);

            //asign the entities to the group
            group.Entities.Clear();

            foreach (IDiagramEntity entity in bundle.Entities)
            {
                //this will be recursive if an entity is itself an IGroup
                entity.Group = group;
                group.Entities.Add(entity);
            }
            //add the new group to the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group);

            mGroup = group;

            //select the newly created group
            CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>();

            col.Add(mGroup);
            Selection.SelectedItems = col;
            mGroup.Invalidate();
        }
Exemplo n.º 4
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Unwraps the specified collection.
        /// </summary>
        /// <param name="collection">The collection.</param>
        // ------------------------------------------------------------------
        public void Unwrap(CollectionBase <IDiagramEntity> collection)
        {
            if (collection == null)
            {
                return;
            }
            foreach (IDiagramEntity entity in collection)
            {
                Unwrap(entity);
            }
            //reconnect the connectors, just like the deserialization of a filed diagram
            Dictionary <Guid, Anchor> .Enumerator enumer = Anchors.GetEnumerator();
            System.Collections.Generic.KeyValuePair <Guid, Anchor> pair;
            Anchor anchor;

            while (enumer.MoveNext())
            {
                pair   = enumer.Current;
                anchor = pair.Value;
                if (anchor.Parent != Guid.Empty) //there's a parent connector
                {
                    if (Anchors.ContainsKey(anchor.Parent))
                    {
                        Anchors.GetAnchor(anchor.Parent).Instance.AttachConnector(anchor.Instance);
                    }
                }
            }
            //clean up the anchoring matrix
            Anchors.Clear();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Depth-first traversal of an <see cref="IGroup"/>
        /// </summary>
        /// <param name="group"></param>
        /// <param name="collection"></param>
        public static void TraverseCollect(IGroup group, ref CollectionBase <IDiagramEntity> collection)
        {
            #region Checks
            if (group == null)
            {
                throw new InconsistencyException("Cannot collect entities of a 'null' IGroup");
            }
            if (collection == null)
            {
                throw new InconsistencyException("You need to instantiate a collection before using this method.");
            }
            #endregion

            foreach (IDiagramEntity entity in group.Entities)
            {
                if (entity is IGroup)
                {
                    TraverseCollect(entity as IGroup, ref collection);
                }
                else
                {
                    collection.Add(entity);
                }
            }
        }
Exemplo n.º 6
0
        ///<summary>
        ///Default constructor
        ///</summary>
        public FolderMaterial(string title)
            : base()
        {
            myTextStyle = new TextStyle(
                Color.Black,
                new Font("Arial", 10),
                StringAlignment.Near,
                StringAlignment.Near);
            mEntries              = new CollectionBase <IShapeMaterial>();
            mEntries.OnItemAdded +=
                new EventHandler <CollectionEventArgs <IShapeMaterial> >(
                    mEntries_OnItemAdded);

            Gliding   = false;
            Resizable = true;

            plusminus           = new SwitchIconMaterial(SwitchIconType.PlusMinus);
            plusminus.TextStyle = myTextStyle;
            plusminus.Transform(new Rectangle(0, 0, 16, 16));
            plusminus.Visible     = true;
            plusminus.Gliding     = false;
            plusminus.OnExpand   += new EventHandler(plusminus_OnExpand);
            plusminus.OnCollapse += new EventHandler(plusminus_OnCollapse);


            header           = new ClickableLabelMaterial();
            header.TextStyle = myTextStyle;
            header.Transform(new Rectangle(0, 0, 100, HeaderHeight));
            header.Text      = title;
            header.Gliding   = false;
            header.Visible   = true;
            header.Resizable = true;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Unwraps the given bundle to the diagram.
        /// </summary>
        /// <param name="collection">CollectionBase<IDiagramEntity></param>
        void UnwrapBundle(CollectionBase <IDiagramEntity> collection)
        {
            if (collection != null)
            {
                #region Unwrap the bundle
                this.Controller.Model.Unwrap(collection);

                Rectangle rec = Utils.BoundingRectangle(collection);

                // The InsertionPoint specifies where the pasted
                // entities should be.  So, shift each entity in the
                // collection to the InsertionPoint.
                Point delta = new Point(
                    InsertionPoint.X - rec.Location.X,
                    InsertionPoint.Y - rec.Location.Y);
                //delta.Offset(rec.Location);

                foreach (IDiagramEntity entity in collection)
                {
                    entity.MoveBy(delta);
                }

                // Recalculate the bounding rectangle and invalidate
                // that area on the canvas.
                rec = Utils.BoundingRectangle(collection);
                rec.Inflate(30, 30);
                this.Controller.View.Invalidate(rec);
                #endregion
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DeleteCommand"/> class.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="bundle">The bundle.</param>
 public DeleteCommand(IController controller, CollectionBase <IDiagramEntity> bundle)
     : base(controller)
 {
     this.Text       = "Delete";
     this.controller = controller;
     this.bundle     = bundle;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Re-sets the scene-index of the paintables
 /// </summary>
 private void ReAssignSceneIndex(CollectionBase <IDiagramEntity> entities)
 {
     for (int i = 0; i < entities.Count; i++)
     {
         entities[i].SceneIndex = i;
     }
 }
Exemplo n.º 10
0
 ///<summary>
 ///Default constructor
 ///</summary>
 public GroupShape(IModel model) : base(model)
 {
     this.mEntities                = new CollectionBase <IDiagramEntity>();
     this.mEntities.OnItemAdded   += new EventHandler <CollectionEventArgs <IDiagramEntity> >(mEntities_OnItemAdded);
     this.mEntities.OnClear       += new EventHandler(mEntities_OnClear);
     this.mEntities.OnItemRemoved += new EventHandler <CollectionEventArgs <IDiagramEntity> >(mEntities_OnItemRemoved);
 }
Exemplo n.º 11
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Sets the current page.
        /// </summary>
        /// <param name="page">The page.</param>
        // ------------------------------------------------------------------
        public void SetCurrentPage(IPage page)
        {
            mCurrentPage = page;
            RaiseOnAmbienceChanged(new AmbienceEventArgs(page.Ambience));
            RaiseOnCurrentPageChanged(new PageEventArgs(page));

            //change the paintables as well
            //Paintables = new CollectionBase<IDiagramEntity>();

            #region Reload of the z-order, usually only necessary after deserialization

            CollectionBase <IDiagramEntity> collected = new CollectionBase <IDiagramEntity>();
            //pick up the non-group entities
            foreach (IDiagramEntity entity in Paintables)
            {
                if (!typeof(IGroup).IsInstanceOfType(entity))
                {
                    collected.Add(entity);
                }
            }

            if (collected.Count > 0)
            {
                Algorithms.SortInPlace <IDiagramEntity>(collected, new SceneIndexComparer <IDiagramEntity>());
                //Paintables.AddRange(collected);
            }
            #endregion
        }
Exemplo n.º 12
0
 // ------------------------------------------------------------------
 /// <summary>
 /// Constructs a connector, passing its location
 /// </summary>
 /// <param name="p">Point: The location of the conector.</param>
 /// <param name="model">IModel: The model.</param>
 // ------------------------------------------------------------------
 protected ConnectorBase(Point p, IModel model)
     : base(model)
 {
     mAttachedConnectors = new CollectionBase <IConnector>();
     mPoint = p;
     this.InitializeConnector();
 }
Exemplo n.º 13
0
        /// <summary>
        /// Perform undo of this command.
        /// </summary>
        public override void Undo()
        {
            //create a new group
            GroupShape group = new GroupShape(this.Controller.Model);

            //asign the entities to the group
            group.Entities = bundle.Entities;

            foreach (IDiagramEntity entity in group.Entities)
            {
                //this will be recursive if an entity is itself an IGroup
                entity.Group = group;
            }
            //add the new group to the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group);

            mGroup = group;

            //select the newly created group
            CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>();

            col.Add(mGroup);
            Selection.SelectedItems = col;
            mGroup.Invalidate();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Perform redo of this command.
        /// </summary>
        public override void Redo()
        {
            //remove the group from the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup);
            //detach the entities from the group
            foreach (IDiagramEntity entity in mGroup.Entities)
            {
                //this will be recursive if an entity is itself an IGroup
                entity.Group = null;
                bundle.Entities.Add(entity);
                //mGroup.Entities.Remove(entity);
            }
            //change the visuals such that the entities in the group are selected

            CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>();

            col.AddRange(mGroup.Entities);

            Selection.SelectedItems = col;

            mGroup.Invalidate();
            mGroup = null;

            //note that the entities have never been disconnected from the layer
            //so they don't have to be re-attached to the anything.
            //The insertion of the Group simply got pushed in the scene-graph.
        }
Exemplo n.º 15
0
        // -------------------------------------------------------------------
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="context">The context.</param>
        // -------------------------------------------------------------------
        protected ShapeBase(
            SerializationInfo info,
            StreamingContext context)
            : base(info, context)
        {
            if (Tracing.BinaryDeserializationSwitch.Enabled)
            {
                Trace.WriteLine("Deserializing the fields of 'ShapeBase'.");
            }

            double version = info.GetDouble("ShapeBaseVersion");

            mConnectors = new CollectionBase <IConnector>();

            //transform to the new bounding rectangle
            Transform(
                (Rectangle)info.GetValue("Rectangle", typeof(Rectangle))
                );

            this.mConnectors = info.GetValue(
                "Connectors",
                typeof(CollectionBase <IConnector>)) as
                               CollectionBase <IConnector>;

            mShowConnectors = info.GetBoolean("ShowConnectors");
            mIsFixed        = info.GetBoolean("IsFixed");
        }
Exemplo n.º 16
0
 /// <summary>
 /// Adds a collection of entities to the diagram
 /// </summary>
 /// <param name="collection">The collection.</param>
 public void AddEntities(CollectionBase <IDiagramEntity> collection)
 {
     foreach (IDiagramEntity entity in collection)
     {
         SetModel(entity);
         DefaultPage.DefaultLayer.Entities.Add(entity);
     }
 }
Exemplo n.º 17
0
 // ------------------------------------------------------------------
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 // ------------------------------------------------------------------
 protected override void Initialize()
 {
     base.Initialize();
     mChildren              = new CollectionBase <IShapeMaterial>();
     mChildren.OnItemAdded +=
         new EventHandler <CollectionEventArgs <IShapeMaterial> >
             (mChildren_OnItemAdded);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:FillStyleCommand"/> class.
 /// </summary>
 /// <param name="controller">The controller.</param>
 /// <param name="bundle">The bundle.</param>
 /// <param name="paintStyle">The paint style.</param>
 public FillStyleCommand(IController controller, CollectionBase <IDiagramEntity> bundle, IPaintStyle paintStyle)
     : base(controller)
 {
     this.Text       = "Fill style";
     this.controller = controller;
     this.bundle     = bundle;//the bundle should contain only IShape and IConnection entities!
     this.newStyle   = paintStyle;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Inits this instance.
        /// </summary>
        private void Init()
        {
            mConnectors              = new CollectionBase <IConnector>();
            mConnectors.OnItemAdded += new EventHandler <CollectionEventArgs <IConnector> >(mConnectors_OnItemAdded);
            mRectangle = new Rectangle(0, 0, 100, 70);

            PaintStyle = ArtPallet.GetDefaultPaintStyle();
            PenStyle   = ArtPallet.GetDefaultPenStyle();
        }
Exemplo n.º 20
0
        /// <summary>
        /// Returns a copy of this instance.
        /// </summary>
        /// <returns></returns>
        public CollectionBase <T> Copy()
        {
            CollectionBase <T> copy = new CollectionBase <T>();

            foreach (T item in this.innerList)
            {
                copy.Add(item);
            }
            return(copy);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 private void Init()
 {
     mChildren              = new CollectionBase <IShapeMaterial>();
     mChildren.OnItemAdded += new EventHandler <CollectionEventArgs <IShapeMaterial> >(mChildren_OnItemAdded);
     mServices              = new Dictionary <Type, IInteraction>();
     //mChildren.Clear();
     //mServices.Clear();
     mServices[typeof(IMouseListener)] = this;
     mServices[typeof(IHoverListener)] = this;
 }
Exemplo n.º 22
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public Model()
        {
            //here I'll have to work on the scene graph
            //this.mShapes = new CollectionBase<IShape>();
            //the default page

            //the page collection
            mPages = new CollectionBase <IPage>();
            mPages.Add(new Page("Default Page", this));

            Init();
        }
Exemplo n.º 23
0
 /// <summary>
 /// Adds a collection range to this collection.
 /// </summary>
 /// <param name="items">The items.</param>
 public virtual void AddRange(CollectionBase <T> items)
 {
     if (mReadOnly)
     {
         throw new InconsistencyException("The collection is read only");
     }
     this.innerList.AddRange(items);
     foreach (T item in items)
     {
         RaiseOnItemAdded(item);
     }
 }
Exemplo n.º 24
0
        ///<summary>
        ///Default constructor
        ///</summary>
        public Page(string name, IModel model)
        {
            this.mModel = model;

            mName     = name;
            mAmbience = new Ambience(this);

            //the one and only and indestructible layer
            mLayers = new CollectionBase <ILayer>();
            mLayers.Add(new Layer("Default Layer"));

            Init();
        }
Exemplo n.º 25
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Hooks-up the required events to monitor the collection of entities
        /// specified.
        /// </summary>
        /// <param name="entities">CollectionBase<IDiagramEntity></param>
        // ------------------------------------------------------------------
        protected virtual void AttachEventsToEnityCollection(
            CollectionBase <IDiagramEntity> entities)
        {
            this.mEntities.OnItemAdded +=
                new EventHandler <CollectionEventArgs <IDiagramEntity> >(
                    OnEntityAdded);

            this.mEntities.OnClear += new EventHandler(OnClearEntities);

            this.mEntities.OnItemRemoved +=
                new EventHandler <CollectionEventArgs <IDiagramEntity> >(
                    OnEntityRemoved);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Sets the items.
        /// </summary>
        /// <param name="editValue">The edit value.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        protected override object SetItems(object editValue, object[] value)
        {
            CollectionBase <IShapeMaterial> entries = editValue as CollectionBase <IShapeMaterial>;

            entries.Clear();
            for (int k = 0; k < value.Length; k++)
            {
                entries.Add(value[k] as IShapeMaterial);
            }
            object retValue = base.SetItems(entries, value);

            return(retValue);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="context">The context.</param>
        protected ConnectorBase(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            if (Tracing.BinaryDeserializationSwitch.Enabled)
            {
                Trace.WriteLine("Deserializing the fields of 'ConnectorBase'.");
            }
            this.mPoint        = (Point)info.GetValue("Point", typeof(Point));
            attachedConnectors = new CollectionBase <IConnector>();

            #region Preparation of the anchoring process
            Guid tuid = new Guid(info.GetString("AttachedTo"));
            Anchors.Add(this.Uid, new Anchor(tuid, this));
            #endregion
        }
Exemplo n.º 28
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public Model()
        {
            //here I'll have to work on the scene graph
            //this.mShapes = new CollectionBase<IShape>();
            //the default page

            //the page collection
            mPages = new CollectionBase <IPage>();
            mPages.Add(new Page("Default Page", this));

            mConnectorHolders = new Dictionary <IConnector, IDiagramEntity>();

            Init();
        }
        /// <summary>
        /// Moves the connectors of the children to the central group connector location.
        /// </summary>
        internal void MoveConnectors(CollectionBase <IDiagramEntity> entities, Point point)
        {
            IConnection cnn;

            foreach (IDiagramEntity entity in entities)
            {
                if (entity is IGroup)
                {
                    continue; //since we use a flattened collection (the Leafs) we don't care about the groups here
                    //the inclusion of the subgroups in the Leafs is however important to make the subgroups
                    //(in)visible when collapsed/expanded.
                }
                if (entity is IShape)
                {
                    foreach (IConnector cn in (entity as IShape).Connectors)
                    {
                        if (cn.AttachedConnectors.Count > 0)
                        {
                            foreach (IConnector cn2 in cn.AttachedConnectors)
                            {
                                if (cn2.Parent is IConnection)
                                {
                                    cnn = cn2.Parent as IConnection;
                                    //the ends have to be connected
                                    if (cnn.From.AttachedTo.Parent is IShape && cnn.To.AttachedTo.Parent is IShape)
                                    {
                                        if (entities.Contains(cnn.From.AttachedTo.Parent as IShape) && entities.Contains(cnn.To.AttachedTo.Parent as IShape))
                                        {
                                            continue;//both endconnectors are internal
                                        }
                                        else//one of the connectors is external
                                        {
                                            if (entities.Contains(cnn.From.AttachedTo.Parent as IShape)) //the From is internal
                                            {
                                                MoveConnector(cnn.From, point);
                                            }
                                            else //the To is internal
                                            {
                                                MoveConnector(cnn.To, point);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Default constructor
        /// </summary>
        // ------------------------------------------------------------------
        public Model()
        {
            //here I'll have to work on the scene graph
            //this.mShapes = new CollectionBase<IShape>();
            //the default page

            //the page collection
            mPages = new CollectionBase <IPage>();
            Page p = new Page("Default Page", this);

            p.Ambience.PageColor = ArtPalette.DefaultPageColor;
            mPages.Add(p);

            Init();
        }