Esempio n. 1
0
 void mDefaultPage_OnEntityAdded(object sender, EntityEventArgs e)
 {
     //don't add it if it's already there or if it's a group (unless you want to deploy something special to emphasize a group shape).
     if (!mPaintables.Contains(e.Entity) && !(e.Entity is IGroup))
     {
         //set the new entity on top of the stack
         e.Entity.SceneIndex = mPaintables.Count;
         mPaintables.Add(e.Entity);
     }
     RaiseOnEntityAdded(e);
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        public void AddTool(ITool tool)
        {
            //add the tool to the collection even if it doesn't attach to anything (yet)
            registeredTools.Add(tool);

            IMouseListener mouseTool = null;

            if ((mouseTool = tool as IMouseListener) != null)
            {
                mouseListeners.Add(mouseTool);
            }

            IKeyboardListener keyboardTool = null;

            if ((keyboardTool = tool as IKeyboardListener) != null)
            {
                keyboardListeners.Add(keyboardTool);
            }

            IDragDropListener dragdropTool = null;

            if ((dragdropTool = tool as IDragDropListener) != null)
            {
                dragdropListeners.Add(dragdropTool);
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        public Page(string name)
        {
            mLayers = new CollectionBase <ILayer>();


            //the one and only and indestructible layer
            mDefaultLayer = new Layer("Default Layer");
            mDefaultLayer.OnEntityAdded   += new EventHandler <EntityEventArgs>(defaultLayer_OnEntityAdded);
            mDefaultLayer.OnEntityRemoved += new EventHandler <EntityEventArgs>(mDefaultLayer_OnEntityRemoved);
            mDefaultLayer.OnClear         += new EventHandler(mDefaultLayer_OnClear);
            mLayers.Add(mDefaultLayer);

            mName = name;
        }
Esempio n. 6
0
 public void AttachConnector(IConnector connector)
 {
     if (connector == null)
     {
         return;
     }
     //only attach'm if not already present and not the parent
     if (!attachedConnectors.Contains(connector) && connector != attachedTo)
     {
         connector.DetachFromParent();
         attachedConnectors.Add(connector);
         //make sure the attached connector is centered at this connector
         connector.Point      = this.point;
         connector.AttachedTo = this;
     }
 }
Esempio n. 7
0
        public Bundle(CollectionBase <IDiagramEntity> collection)
        {
            mEntities = new CollectionBase <IDiagramEntity>();
            //we could assign it directly but let's make sure the collection does not
            //contain unwanted elements
            foreach (IDiagramEntity entity in collection)
            {
                if ((entity is IShape) || (entity is IConnection) || (entity is IGroup))
                {
                    mEntities.Add(entity);
                }
            }

            //the following line would give problem. The event handler attached to the Selection would be triggered when
            //the mEntities collection is changed!
            //mEntities = collection;
        }
Esempio n. 8
0
        public Model()
        {
            mAmbience = new Ambience(this);
            //listen to events
            AttachToAmbience(mAmbience);

            //here I'll have to work on the scene graph
            this.mShapes = new ShapeCollection();

            //the page collection
            mPages = new CollectionBase <IPage>();

            //the default page
            mDefaultPage = new Page("Default Page");
            mDefaultPage.OnEntityAdded   += new EventHandler <EntityEventArgs>(mDefaultPage_OnEntityAdded);
            mDefaultPage.OnEntityRemoved += new EventHandler <EntityEventArgs>(mDefaultPage_OnEntityRemoved);
            mDefaultPage.OnClear         += new EventHandler(mDefaultPage_OnClear);
            mPages.Add(mDefaultPage);
            //initially the current page is the one and only default page
            mCurrentPage = mDefaultPage;

            //the paintables
            mPaintables = new CollectionBase <IDiagramEntity>();
        }
Esempio n. 9
0
        public static void CollectEntitiesAt(Point surfacePoint)
        {
            if (surfacePoint == Point.Empty)
            {
                return;
            }
            if (Selection.mController == null)
            {
                return;
            }

            //only change the current selection if the mouse did not hit an already selected element
            if (mSelection.Count > 0)
            {
                foreach (IDiagramEntity entity in mSelection)
                {
                    if (entity.Rectangle.Contains(surfacePoint))
                    {
                        return;
                    }
                }
            }

            //here the scene-graph will play a role in the future,
            //for now we'll keep is simple
            Selection.Clear();

            IConnection con;
            IShape      sh;

            //we use the paintables here rather than traversing the scene-graph because only
            //visible things can be collected
            //We traverse the paintables from top to bottom since the highest z-order
            //is at the top of the stack.

            for (int k = Model.Paintables.Count - 1; k >= 0; k--)
            {
                IDiagramEntity entity = Model.Paintables[k];

                #region we give priority to the connector selection
                if (typeof(IConnection).IsInstanceOfType(entity))
                {
                    con = entity as IConnection;
                    if (con.From.Hit(surfacePoint))
                    {
                        connector            = con.From;
                        connector.IsSelected = true;
                        Invalidate();
                        return;
                    }
                    if (con.To.Hit(surfacePoint))
                    {
                        connector            = con.To;
                        connector.IsSelected = true;
                        Invalidate();
                        return;
                    }
                }
                else
                if (typeof(IShape).IsInstanceOfType(entity))
                {
                    sh = entity as IShape;
                    foreach (IConnector cn in sh.Connectors)
                    {
                        //if there are connectors attached to the shape connector, the attached ones should be picked up and not the one of the shape
                        if (cn.Hit(surfacePoint) && cn.AttachedConnectors.Count == 0)
                        {
                            connector            = cn;
                            connector.IsSelected = true;
                            Invalidate(); //this will invalidate only the selected connector
                            return;       //we hit a connector and quit the selection. If the user intended to select the entity it had to be away from the connector!
                        }
                    }
                }

                #endregion

                #region no connector was hit, maybe the entity itself
                if (entity.Hit(surfacePoint))
                {
                    //if the entity is part of an IGroup, the IGroup should be selected
                    //rather than the entity itself
                    //Note that the Group property returns the top group parent and not
                    //just the immediate parent of an entity
                    if (entity.Group != null)
                    {
                        entity.Group.IsSelected = true;
                        mSelection.Add(entity.Group);
                    }
                    else
                    {
                        entity.IsSelected = true;
                        mSelection.Add(entity);
                    }


                    break;
                }
                #endregion
            }
            RaiseOnNewSelection();
            Invalidate();

            //Using a full invalidate is rather expensive, so we'll only refresh the current selection
            //Controller.View.Invalidate();
        }