コード例 #1
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
        // ------------------------------------------------------------------
        /// <summary>
        /// Removes all entities that are currently selected.
        /// </summary>
        /// <param name="entity">The entity.</param>
        // ------------------------------------------------------------------
        public void RemoveSelectedItems()
        {
            if (this.Selection.SelectedItems.Count < 1)
            {
                return;
            }

            int numberOfItems = this.Selection.SelectedItems.Count;

            for (int i = 0; i < numberOfItems - 1; i++)
            {
                IDiagramEntity entity = Selection.SelectedItems[0];
                foreach (IPage page in mPages)
                {
                    foreach (ILayer layer in page.Layers)
                    {
                        if (layer.Entities.Contains(entity))
                        {
                            layer.Entities.Remove(entity);
                            entity.Detached(DefaultPage.DefaultLayer);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
        /// <summary>
        /// Sends the entity up the z-order stack with the specified amount.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="zShift">The z shift.</param>
        public void SendForwards(IDiagramEntity entity, int zShift)
        {
            ILayer layer = CurrentPage.GetLayer(entity);

            if (layer != null)
            {
                int newpos = layer.Entities.IndexOf(entity) + zShift;
                //if this is the last in the row you cannot move it higher
                if (newpos < layer.Entities.Count)
                {
                    layer.Entities.Remove(entity);
                    layer.Entities.Insert(newpos, entity); //does it works when this is an addition at the top?
                    ReAssignSceneIndex(layer.Entities);
                    Rectangle rec = entity.Rectangle;
                    rec.Inflate(20, 20);
                    this.RaiseOnInvalidateRectangle(Rectangle);
                }
            }

            //if (Paintables.Contains(entity) && zShift>=1)
            //{
            //    int newpos = Paintables.IndexOf(entity) + zShift;
            //    //if this is the last in the row you cannot move it higher
            //    if (newpos < Paintables.Count)
            //    {
            //        Paintables.Remove(entity);
            //        Paintables.Insert(newpos, entity); //does it works when this is an addition at the top?
            //        ReAssignSceneIndex(Paintables);
            //        Rectangle rec = entity.Rectangle;
            //        rec.Inflate(20, 20);
            //        this.RaiseOnInvalidateRectangle(Rectangle);
            //    }
            //}
        }
コード例 #3
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
 // ------------------------------------------------------------------
 /// <summary>
 /// Sets the model (recursively) on the given entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 // ------------------------------------------------------------------
 public void SetModel(IDiagramEntity entity)
 {
     if (entity is IConnector)
     {
         (entity as IConnector).Model = this;
     }
     else if (entity is IConnection)
     {
         IConnection con = entity as IConnection;
         con.Model = this;
         Debug.Assert(con.From != null, "The 'From' connector is not set.");
         con.From.Model = this;
         Debug.Assert(con.From != null, "The 'To' connector is not set.");
         con.To.Model = this;
     }
     else if (entity is IShape)
     {
         IShape shape = entity as IShape;
         shape.Model = this;
         foreach (IConnector co in shape.Connectors)
         {
             co.Model = this;
         }
     }
     else if (entity is IGroup)
     {
         IGroup group = entity as IGroup;
         group.Model = this;
         foreach (IDiagramEntity child in group.Entities)
         {
             SetModel(child);
         }
     }
 }
コード例 #4
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
        /// <summary>
        /// Sends the entity down the z-order stack with the specified amount.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="zShift">The z shift.</param>
        public void SendBackwards(IDiagramEntity entity, int zShift)
        {
            ILayer layer = CurrentPage.GetLayer(entity);

            if (layer != null)
            {
                int newpos = layer.Entities.IndexOf(entity) - zShift;
                //if this is the first in the row you cannot move it lower
                if (newpos >= 0)
                {
                    layer.Entities.Remove(entity);
                    layer.Entities.Insert(newpos, entity);
                    ReAssignSceneIndex(layer.Entities);
                    Rectangle rec = entity.Rectangle;
                    rec.Inflate(20, 20);
                    this.RaiseOnInvalidateRectangle(Rectangle);
                }
            }

            //if (Paintables.Contains(entity))
            //{
            //    int newpos = Paintables.IndexOf(entity) - zShift;
            //    //if this is the first in the row you cannot move it lower
            //    if (newpos >= 0)
            //    {
            //        Paintables.Remove(entity);
            //        Paintables.Insert(newpos, entity);
            //        ReAssignSceneIndex(Paintables);
            //        Rectangle rec = entity.Rectangle;
            //        rec.Inflate(20, 20);
            //        this.RaiseOnInvalidateRectangle(Rectangle);
            //    }
            //}
        }
コード例 #5
0
 public void Remove(IDiagramEntity entity)
 {
     if (DefaultPage.DefaultLayer.Entities.Contains(entity))
     {
         DefaultPage.DefaultLayer.Entities.Remove(entity);
     }
 }
コード例 #6
0
        public void DiagramEntitySelected(IDiagramEntity obj)
        {
            if (EditModel == null)
            {
                return;
            }

            if (obj is DiagramShape)
            {
                var          shape = (DiagramShape)obj;
                IModelObject entity;
                if (ShapeLookup.TryGetValue(shape, out entity))
                {
                    EditModel.ShowObjectPropertyGrid(entity);
                    if (entity is ModelObject)
                    {
                        EditModel.SyncCurrentlySelectedObject(entity as ModelObject);
                    }
                }
            }
            else if (obj is Connection)
            {
                var          connection = (Connection)obj;
                IModelObject rel;
                if (ConnectionLookup.TryGetValue(connection, out rel))
                {
                    EditModel.ShowObjectPropertyGrid(rel);
                    if (rel is ModelObject)
                    {
                        EditModel.SyncCurrentlySelectedObject(rel as ModelObject);
                    }
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Unwraps an entity
 /// <list type="bullet">
 /// <term>Uid</term><description>Generates a new <see cref="IDiagramEntity.Uid"/> for the entity. </description>
 /// <tem>Model</tem><description>Assigns the Model property to the entity.</description>
 ///
 /// </list>
 /// </summary>
 public void Unwrap(IDiagramEntity entity)
 {
     //set a new unique identifier for this copied object
     entity.NewUid(true);
     //this assignment will be recursive if needed
     SetModel(entity);
     DefaultPage.DefaultLayer.Entities.Add(entity);
 }
コード例 #8
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
 // ------------------------------------------------------------------
 /// <summary>
 /// Removes the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 // ------------------------------------------------------------------
 public void Remove(IDiagramEntity entity)
 {
     if (CurrentPage.DefaultLayer.Entities.Contains(entity))
     {
         CurrentPage.DefaultLayer.Entities.Remove(entity);
         entity.Detached(CurrentPage.DefaultLayer);
     }
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EntityMenuEventArgs"/> class.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
 /// <param name="additionalItems">The additional items.</param>
 public EntityMenuEventArgs(
     IDiagramEntity entity,
     MouseEventArgs e,
     ref ToolStripItem[] additionalItems)
 {
     this.entity          = entity;
     this.e               = e;
     this.additionalItems = additionalItems;
 }
コード例 #10
0
 public EntityMouseEventArgs(IDiagramEntity entity, MouseEventArgs e)
     : base(e.Button, e.Clicks, e.X, e.Y, e.Delta)
 {
     if (e == null)
     {
         throw new ArgumentNullException("The argument object is 'null'");
     }
     this.mEntity = entity;
 }
コード例 #11
0
        public void MouseMove(MouseEventArgs e)
        {
            if (!IsSuspended && this.Enabled)
            {
                IHoverListener listener = null;

                CollectionBase<IDiagramEntity> paintables= this.Controller.Model.Paintables;
                IDiagramEntity entity;
                if(paintables.Count==0) return;
                //going from top to the bottom of the z-order
                for (int k=paintables.Count-1; k>=0; k--)
                {
                    entity = paintables[k];
                    if(entity.Rectangle.Contains(e.Location)) //we caught an entity
                    {
                        //unhover the previous, if any
                        if(previousHovered != null)
                            previousHovered.Hovered = false;
                        entity.Hovered = true; //tell the current one it's being hovered
                        //fetch the hovering service, if defined
                        listener = entity.GetService(typeof(IHoverListener)) as IHoverListener;
                        if(listener != null) //the caught entity does listen
                        {
                            if(currentListener == listener) //it's the same as the previous time
                                listener.MouseHover(e);
                            else //we moved from one entity to another listening entity
                            {
                                if(currentListener!=null) //tell the previous entity we are leaving
                                    currentListener.MouseLeave(e);
                                listener.MouseEnter(e); //tell the current one we enter
                                currentListener = listener;
                            }
                        }
                        else //the caught entity does not listen
                        {
                            if(currentListener != null)
                            {
                                currentListener.MouseLeave(e);
                                currentListener = null;
                            }
                        }
                        previousHovered = entity;//remember, for the next time
                        return; //if another entity is listening underneath this entity it will not receive the notification
                    }
                }
                if(currentListener != null)
                {
                    currentListener.MouseLeave(e);
                    currentListener = null;
                }
                //unhover the previous, if any
                if(previousHovered != null)
                    previousHovered.Hovered = false;

            }
        }
コード例 #12
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
 // ------------------------------------------------------------------
 /// <summary>
 /// Adds an entity to the diagram.  The magnification level for the
 /// entity is set to the current magnification level of the current
 /// page.
 /// </summary>
 /// <param name="entity">IDiagramEntity: The entity to add.</param>
 /// <returns>IDiagramEntity: The added entity.</returns>
 // ------------------------------------------------------------------
 public IDiagramEntity AddEntity(IDiagramEntity entity)
 {
     SetModel(entity);
     //By default the new entity is added to the default layer in the
     // current page.
     CurrentPage.DefaultLayer.Entities.Add(entity);
     entity.Attached(CurrentPage.DefaultLayer);
     entity.Magnification = CurrentPage.Magnification;
     return(entity);
 }
コード例 #13
0
 public void SendToFront(IDiagramEntity entity)
 {
     if (mPaintables.Contains(entity))
     {
         mPaintables.Remove(entity);
         mPaintables.Add(entity);
         Rectangle rec = entity.Rectangle;
         rec.Inflate(20, 20);
         this.RaiseOnInvalidateRectangle(Rectangle);
     }
 }
コード例 #14
0
 internal void RemoveFromPaintables(IDiagramEntity entity)
 {
     this.Model.Paintables.Remove(entity);
     if (entity is CollapsibleGroupShape && !(entity as CollapsibleGroupShape).Collapsed)
     {
         foreach (IDiagramEntity ent in (entity as CollapsibleGroupShape).Entities)
         {
             RemoveFromPaintables(ent);
         }
     }
 }
コード例 #15
0
 internal void AddToPaintables(IDiagramEntity entity)
 {
     this.Model.Paintables.Add(entity);
     if (entity is CollapsibleGroupShape && !(entity as CollapsibleGroupShape).Collapsed)
     {
         foreach (IDiagramEntity ent in (entity as CollapsibleGroupShape).Entities)
         {
             AddToPaintables(ent);
         }
     }
 }
コード例 #16
0
 // ------------------------------------------------------------------
 /// <summary>
 /// Gets the layer that has the entity specified.  If the entity
 /// specified could not be found, 'null' is returned.
 /// </summary>
 /// <param name="entity">IDiagramEntity</param>
 /// <returns>ILayer</returns>
 // ------------------------------------------------------------------
 public ILayer GetLayer(IDiagramEntity entity)
 {
     foreach (ILayer layer in mLayers)
     {
         if (layer.Entities.Contains(entity))
         {
             return(layer);
         }
     }
     return(null);
 }
コード例 #17
0
 /// <summary>
 /// Sends to entity to the bottom of the z-order stack.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public void SendToBack(IDiagramEntity entity)
 {
     if (mPaintables.Contains(entity))
     {
         mPaintables.Remove(entity);
         mPaintables.Insert(0, entity);
         ReAssignSceneIndex();
         Rectangle rec = entity.Rectangle;
         rec.Inflate(20, 20);
         this.RaiseOnInvalidateRectangle(Rectangle);
     }
 }
コード例 #18
0
 public void SendForwards(IDiagramEntity entity, int zShift)
 {
     if (mPaintables.Contains(entity) && zShift >= 1)
     {
         int newpos = mPaintables.IndexOf(entity) + zShift;
         //if this is the last in the row you cannot move it higher
         if (newpos < mPaintables.Count)
         {
             mPaintables.Remove(entity);
             mPaintables.Insert(newpos, entity); //does it works when this is an addition at the top?
             Rectangle rec = entity.Rectangle;
             rec.Inflate(20, 20);
             this.RaiseOnInvalidateRectangle(Rectangle);
         }
     }
 }
コード例 #19
0
 public void SendBackwards(IDiagramEntity entity, int zShift)
 {
     if (mPaintables.Contains(entity))
     {
         int newpos = mPaintables.IndexOf(entity) - zShift;
         //if this is the first in the row you cannot move it lower
         if (newpos >= 0)
         {
             mPaintables.Remove(entity);
             mPaintables.Insert(newpos, entity);
             Rectangle rec = entity.Rectangle;
             rec.Inflate(20, 20);
             this.RaiseOnInvalidateRectangle(Rectangle);
         }
     }
 }
コード例 #20
0
    // ------------------------------------------------------------------
    /// <summary>
    /// Aligns the center of all selected entities horizontally.  The 
    /// 'X' component of the center location of the first entity in the 
    /// selection is used for all other entities.
    /// </summary>
    // ------------------------------------------------------------------
    public override void Align(IDiagramEntity[] entities) {
      // The amount to offset the entities by.
      Point offset;

      for (int i = 1; i < entities.Length; i++) {
        IDiagramEntity entity = entities[i];

        // Keep the entities same y location but offset it's
        // x location.
        offset = new Point(
            this.centerOfFirstEntity.X - entity.Center.X,
            0);

        // Move the entity by this amount.
        entity.MoveBy(offset);
      }
    }
コード例 #21
0
 internal void SelectEntity(IDiagramEntity entity, Point surfacePoint)
 {
     // Groups are treated specially because we can drill-down
     // into the group.  The process of drilling is the first
     // mouse hit will select the group.  The second mouse hit
     // will select a child, if there's a child at that point.
     if (entity is IGroup)
     {
         if (entity.IsSelected == false)
         {
             entity.IsSelected = true;
             mSelection.Add(entity);
         }
         else
         {
             IGroup group = entity as IGroup;
             for (int j = group.Entities.Count - 1; j >= 0; j--)
             {
                 IDiagramEntity child = group.Entities[j];
                 if (child.Hit(surfacePoint))
                 {
                     // Repeat the process because what if this
                     // child is too a group!
                     SelectEntity(child, surfacePoint);
                     group.IsSelected = false;
                     if (mSelection.Contains(group))
                     {
                         mSelection.Remove(group);
                     }
                     break;
                 }
             }
         }
     }
     //else if (entity.Group != null)
     //{
     //    //entity.Group.IsSelected = true;
     //    //mSelection.Add(entity.Group);
     //}
     else
     {
         entity.IsSelected = true;
         mSelection.Add(entity);
     }
 }
コード例 #22
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Activates the tool.  First a check is performed to ensure there
        /// are at least two IDiagramEntities selected.  If so, then the
        /// x, y, top edge, bottom edge, and center of the first entity
        /// is stored in local, protected variables for all other alignment
        /// tools to use.
        /// </summary>
        // ------------------------------------------------------------------
        protected override void OnActivateTool()
        {
            base.OnActivateTool();

            // Make sure enough items were selected.
            if (this.Controller.Model.Selection.SelectedItems == null)
            {
                MessageBox.Show(
                    "Nothing is selected, you need to select at " +
                    "least two items to align.",
                    "Nothing selected.",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Hand);

                return;
            }

            if (this.Controller.Model.Selection.SelectedItems.Count <= 1)
            {
                MessageBox.Show(
                    "You need to select at least two items to align.",
                    "Nothing selected.",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Hand);

                return;
            }

            // Since there are enough items, peform the alignment.  But
            // first get all aspects about the location of the first
            // entity.
            this.firstEntity             = this.Controller.Model.Selection.SelectedItems[0];
            this.xLocationOfFirstEntity  = firstEntity.Rectangle.X;
            this.yLocationOfFirstEntity  = firstEntity.Rectangle.Y;
            this.topEdgeOfFirstEntity    = firstEntity.Rectangle.Top;
            this.bottomEdgeOfFirstEntity = firstEntity.Rectangle.Bottom;
            this.rightEdgeOfFirstEntity  = firstEntity.Rectangle.Right;
            this.centerOfFirstEntity     = firstEntity.Center;

            this.Align(this.Controller.Model.Selection.SelectedItems.ToArray());

            // Reset the Tracker.
            this.Controller.View.ShowTracker();
            DeactivateTool();
        }
コード例 #23
0
        void NetronEntityRemovedHandler(object sender, EntityEventArgs e)
        {
            IDiagramEntity entity = e.Entity;
            SignalShape    ss     = entity as SignalShape;

            if (ss != null)
            {
                if (!_bridge.Signals.ContainsValue(ss))
                {
                    return;
                }
                _bridge.Signals.Remove(ss.SignalReference.InstanceId);
                PostCommandRemoveSignal(ss.SignalReference, true);
                return;
            }
            BusShape bs = entity as BusShape;

            if (bs != null)
            {
                if (!_bridge.Buses.ContainsValue(bs))
                {
                    return;
                }
                _bridge.Buses.Remove(bs.BusReference.InstanceId);
                PostCommandRemoveBus(bs.BusReference);
                return;
            }
            PortShape ps = entity as PortShape;

            if (ps != null)
            {
                if (!_bridge.Ports.ContainsValue(ps))
                {
                    return;
                }
                _bridge.Ports.Remove(ps.PortReference.InstanceId);
                PostCommandRemovePort(ps.PortReference, true);
                return;
            }
            IConnection cn = entity as IConnection;

            if (cn != null)
            {
            }
        }
コード例 #24
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Aligns the center of all selected entities vertically.  The
        /// 'Y' component of the center location of the first entity in the
        /// selection is used for all other entities.
        /// </summary>
        // ------------------------------------------------------------------
        public override void Align(IDiagramEntity[] entities)
        {
            // The amount to offset the entities by.
            Point offset;

            for (int i = 1; i < entities.Length; i++)
            {
                IDiagramEntity entity = entities[i];

                // Keep the entities same x location but offset it's
                // y location.
                offset = new Point(
                    0,
                    this.centerOfFirstEntity.Y - entity.Center.Y);

                // Move the entity by this amount.
                entity.MoveBy(offset);
            }
        }
コード例 #25
0
    // ------------------------------------------------------------------
    /// <summary>
    /// Activates the tool.  First a check is performed to ensure there
    /// are at least two IDiagramEntities selected.  If so, then the
    /// x, y, top edge, bottom edge, and center of the first entity
    /// is stored in local, protected variables for all other alignment
    /// tools to use.
    /// </summary>
    // ------------------------------------------------------------------
    protected override void OnActivateTool() {
      base.OnActivateTool();

      // Make sure enough items were selected.
      if (this.Controller.Model.Selection.SelectedItems == null) {
        MessageBox.Show(
            "Nothing is selected, you need to select at " +
            "least two items to align.",
            "Nothing selected.",
            MessageBoxButtons.OK,
            MessageBoxIcon.Hand);

        return;
      }

      if (this.Controller.Model.Selection.SelectedItems.Count <= 1) {
        MessageBox.Show(
            "You need to select at least two items to align.",
            "Nothing selected.",
            MessageBoxButtons.OK,
            MessageBoxIcon.Hand);

        return;
      }

      // Since there are enough items, peform the alignment.  But
      // first get all aspects about the location of the first
      // entity.
      this.firstEntity = this.Controller.Model.Selection.SelectedItems[0];
      this.xLocationOfFirstEntity = firstEntity.Rectangle.X;
      this.yLocationOfFirstEntity = firstEntity.Rectangle.Y;
      this.topEdgeOfFirstEntity = firstEntity.Rectangle.Top;
      this.bottomEdgeOfFirstEntity = firstEntity.Rectangle.Bottom;
      this.rightEdgeOfFirstEntity = firstEntity.Rectangle.Right;
      this.centerOfFirstEntity = firstEntity.Center;

      this.Align(this.Controller.Model.Selection.SelectedItems.ToArray());

      // Reset the Tracker.
      this.Controller.View.ShowTracker();
      DeactivateTool();
    }
コード例 #26
0
    // ------------------------------------------------------------------
    /// <summary>
    /// Aligns the bottom edges of all selected entities.  The vertical
    /// location of the first entity in the selection is used for all 
    /// other entities vertical location.
    /// </summary>
    // ------------------------------------------------------------------
    public override void Align(IDiagramEntity[] entities) {
      // We want to align the bottom edges, so we need to set the
      // vertical location of each shape to one value.  We're
      // going use the first entity in the selection to determine
      // this setting.
      Point offset;

      for (int i = 1; i < entities.Length; i++) {
        IDiagramEntity entity = entities[i];

        // Keep the entities same y location but offset it's
        // x location.
        offset = new Point(
            0,
            this.bottomEdgeOfFirstEntity - entity.Rectangle.Bottom);

        // Move the entity by this amount.
        entity.MoveBy(offset);
      }
    }
コード例 #27
0
ファイル: DeleteTool.cs プロジェクト: thunder176/HeuristicLab
        protected override void OnActivateTool()
        {
            base.OnActivateTool();

            DeleteCommand cmd;

            if (this.Controller.Model.Selection.SelectedItems.Count > 0)
            {
                // If any one entity in the selction can't be deleted,
                // remove it from the selection.
                for (int i = 0; i < this.Controller.Model.Selection.SelectedItems.Count; i++)
                {
                    IDiagramEntity entity = this.Controller.Model.Selection.SelectedItems[i];
                    if (entity.AllowDelete == false)
                    {
                        this.Controller.Model.Selection.SelectedItems.Remove(entity);
                        i--;
                    }
                }
                cmd = new DeleteCommand(
                    this.Controller,
                    this.Controller.Model.Selection.SelectedItems.Copy());
                this.Controller.UndoManager.AddUndoCommand(cmd);

                // Alert each entity that they're about to be deleted.
                foreach (IDiagramEntity entity in this.Controller.Model.Selection.SelectedItems)
                {
                    entity.OnBeforeDelete(cmd);
                }

                cmd.Redo();

                // Alert each entity that they have been deleted.
                foreach (IDiagramEntity entity in this.Controller.Model.Selection.SelectedItems)
                {
                    entity.OnAfterDelete(cmd);
                }
            }

            DeactivateTool();
        }
コード例 #28
0
        // ------------------------------------------------------------------
        /// <summary>
        /// Aligns the bottom edges of all selected entities.  The vertical
        /// location of the first entity in the selection is used for all
        /// other entities vertical location.
        /// </summary>
        // ------------------------------------------------------------------
        public override void Align(IDiagramEntity[] entities)
        {
            // We want to align the bottom edges, so we need to set the
            // vertical location of each shape to one value.  We're
            // going use the first entity in the selection to determine
            // this setting.
            Point offset;

            for (int i = 1; i < entities.Length; i++)
            {
                IDiagramEntity entity = entities[i];

                // Keep the entities same y location but offset it's
                // x location.
                offset = new Point(
                    0,
                    this.bottomEdgeOfFirstEntity - entity.Rectangle.Bottom);

                // Move the entity by this amount.
                entity.MoveBy(offset);
            }
        }
コード例 #29
0
        /// <summary>
        /// Perform undo of this command.
        /// </summary>
        public override void Undo()
        {
            if (mGroup.CanUnGroup == false)
            {
                return;
            }

            //remove the group from the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup);

            // keep track of the entities removed.
            CollectionBase <IDiagramEntity> removedItems =
                new CollectionBase <IDiagramEntity>();

            int numberOfItems = mGroup.Entities.Count;

            //detach the entities from the group
            for (int i = 0; i < numberOfItems; numberOfItems--)
            {
                IDiagramEntity entity = mGroup.Entities[0];
                //this will be recursive if an entity is itself an IGroup
                entity.Group = null;
                mGroup.Entities.Remove(entity);
                Controller.Model.AddEntity(entity);
                entity.Invalidate();
                removedItems.Add(entity);
            }
            //change the visuals such that the entities in the group are selected
            this.Controller.Model.Selection.SelectedItems = removedItems;
            //mGroup.Entities.Clear();

            //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.
        }
コード例 #30
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
        /// <summary>
        /// Sends to entity to the bottom of the z-order stack.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public void SendToBack(IDiagramEntity entity)
        {
            ILayer layer = CurrentPage.GetLayer(entity);

            if (layer != null)
            {
                layer.Entities.Remove(entity);
                layer.Entities.Insert(0, entity);
                ReAssignSceneIndex(layer.Entities);
                Rectangle rec = entity.Rectangle;
                rec.Inflate(20, 20);
                this.RaiseOnInvalidateRectangle(Rectangle);
            }
            //if(Paintables.Contains(entity))
            //{
            //    Paintables.Remove(entity);
            //    Paintables.Insert(0, entity);
            //    ReAssignSceneIndex();
            //    Rectangle rec = entity.Rectangle;
            //    rec.Inflate(20, 20);
            //    this.RaiseOnInvalidateRectangle(Rectangle);
            //}
        }
コード例 #31
0
ファイル: Model.cs プロジェクト: Tom-Hoinacki/OO-CASE-Tool
 public void SendToFront(IDiagramEntity entity)
 {
     if(mPaintables.Contains(entity))
     {
         mPaintables.Remove(entity);
         mPaintables.Add(entity);
         Rectangle rec = entity.Rectangle;
         rec.Inflate(20, 20);
         this.RaiseOnInvalidateRectangle(Rectangle);
     }
 }
コード例 #32
0
 // ------------------------------------------------------------------
 /// <summary>
 /// Abstract method to be implemented by all alignment tools.
 /// </summary>
 /// <param name="entities">IDiagramEntity[]: All selected
 /// entities.</param>
 // ------------------------------------------------------------------
 public abstract void Align(IDiagramEntity[] entities);
コード例 #33
0
    internal void RemoveFromPaintables(IDiagramEntity entity) {
      this.Model.Paintables.Remove(entity);
      if (entity is CollapsibleGroupShape && !(entity as CollapsibleGroupShape).Collapsed) {
        foreach (IDiagramEntity ent in (entity as CollapsibleGroupShape).Entities) {
          RemoveFromPaintables(ent);
        }

      }
    }
コード例 #34
0
    internal void AddToPaintables(IDiagramEntity entity) {
      this.Model.Paintables.Add(entity);
      if (entity is CollapsibleGroupShape && !(entity as CollapsibleGroupShape).Collapsed) {
        foreach (IDiagramEntity ent in (entity as CollapsibleGroupShape).Entities) {
          AddToPaintables(ent);
        }

      }

    }
コード例 #35
0
 public EntityMouseEventArgs(IDiagramEntity entity, MouseButtons button, int clicks, int x, int y, int delta)
     : base(button, clicks, x, y, delta)
 {
     this.mEntity = entity;
 }
コード例 #36
0
 protected override bool ShouldHighlightObject(IDiagramEntity obj)
 {
     return obj is ConnectionPoint && CanConnect(obj as ConnectionPoint);
 }
コード例 #37
0
ファイル: DraggerBase.cs プロジェクト: uQr/Visual-NHibernate
 protected abstract bool ShouldHighlightObject(IDiagramEntity obj);
コード例 #38
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
    /// <summary>
    /// Sends the entity to the front of the z-order stack.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void SendToFront(IDiagramEntity entity) {
      ILayer layer = CurrentPage.GetLayer(entity);
      if (layer != null) {
        layer.Entities.Remove(entity);
        layer.Entities.Add(entity);
        ReAssignSceneIndex(layer.Entities);
        Rectangle rec = entity.Rectangle;
        rec.Inflate(20, 20);
        this.RaiseOnInvalidateRectangle(Rectangle);
      }

      //if(Paintables.Contains(entity))
      //{
      //    Paintables.Remove(entity);
      //    Paintables.Add(entity);
      //    ReAssignSceneIndex(Paintables);
      //    Rectangle rec = entity.Rectangle;
      //    rec.Inflate(20, 20);
      //    this.RaiseOnInvalidateRectangle(Rectangle);
      //}
    }
コード例 #39
0
ファイル: Page.cs プロジェクト: thunder176/HeuristicLab
 // ------------------------------------------------------------------
 /// <summary>
 /// Gets the layer that has the entity specified.  If the entity
 /// specified could not be found, 'null' is returned.
 /// </summary>
 /// <param name="entity">IDiagramEntity</param>
 /// <returns>ILayer</returns>
 // ------------------------------------------------------------------
 public ILayer GetLayer(IDiagramEntity entity) {
   foreach (ILayer layer in mLayers) {
     if (layer.Entities.Contains(entity)) {
       return layer;
     }
   }
   return null;
 }
コード例 #40
0
ファイル: Model.cs プロジェクト: Tom-Hoinacki/OO-CASE-Tool
 public void SendForwards(IDiagramEntity entity)
 {
     SendForwards(entity, 1);
 }
コード例 #41
0
ファイル: Model.cs プロジェクト: xuchuansheng/GenXSource
 /// <summary>
 /// Sends to entity to the bottom of the z-order stack.
 /// </summary>
 /// <param name="entity">The entity.</param>
 public void SendToBack(IDiagramEntity entity)
 {
     if(mPaintables.Contains(entity))
     {
         mPaintables.Remove(entity);
         mPaintables.Insert(0, entity);
         ReAssignSceneIndex();
         Rectangle rec = entity.Rectangle;
         rec.Inflate(20, 20);
         this.RaiseOnInvalidateRectangle(Rectangle);
     }
 }
コード例 #42
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
    /// <summary>
    /// Sends the entity down the z-order stack with the specified amount.
    /// </summary>
    /// <param name="entity">The entity.</param>
    /// <param name="zShift">The z shift.</param>
    public void SendBackwards(IDiagramEntity entity, int zShift) {
      ILayer layer = CurrentPage.GetLayer(entity);
      if (layer != null) {
        int newpos = layer.Entities.IndexOf(entity) - zShift;
        //if this is the first in the row you cannot move it lower
        if (newpos >= 0) {
          layer.Entities.Remove(entity);
          layer.Entities.Insert(newpos, entity);
          ReAssignSceneIndex(layer.Entities);
          Rectangle rec = entity.Rectangle;
          rec.Inflate(20, 20);
          this.RaiseOnInvalidateRectangle(Rectangle);
        }
      }

      //if (Paintables.Contains(entity))
      //{
      //    int newpos = Paintables.IndexOf(entity) - zShift;
      //    //if this is the first in the row you cannot move it lower
      //    if (newpos >= 0)
      //    {
      //        Paintables.Remove(entity);
      //        Paintables.Insert(newpos, entity);
      //        ReAssignSceneIndex(Paintables);
      //        Rectangle rec = entity.Rectangle;
      //        rec.Inflate(20, 20);
      //        this.RaiseOnInvalidateRectangle(Rectangle);
      //    }
      //}
    }
コード例 #43
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
 // ------------------------------------------------------------------
 /// <summary>
 /// Adds an entity to the diagram.  The magnification level for the
 /// entity is set to the current magnification level of the current 
 /// page.
 /// </summary>
 /// <param name="entity">IDiagramEntity: The entity to add.</param>
 /// <returns>IDiagramEntity: The added entity.</returns>
 // ------------------------------------------------------------------
 public IDiagramEntity AddEntity(IDiagramEntity entity) {
   SetModel(entity);
   //By default the new entity is added to the default layer in the 
   // current page.
   CurrentPage.DefaultLayer.Entities.Add(entity);
   entity.Attached(CurrentPage.DefaultLayer);
   entity.Magnification = CurrentPage.Magnification;
   return entity;
 }
コード例 #44
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();
        }
コード例 #45
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
    // ------------------------------------------------------------------
    /// <summary>
    /// Unwraps an entity
    /// <list type="bullet">
    /// <term>Uid</term><description>Generates a new <see cref="IDiagramEntity.Uid"/> for the entity. </description>
    /// <tem>Model</tem><description>Assigns the Model property to the entity.</description>
    /// 
    /// </list>
    /// </summary>
    // ------------------------------------------------------------------
    public void Unwrap(IDiagramEntity entity) {
      //set a new unique identifier for this copied object
      entity.NewUid(true);
      //this assignment will be recursive if needed
      SetModel(entity);
      CurrentPage.DefaultLayer.Entities.Add(entity);
      entity.Attached(CurrentPage.DefaultLayer);

    }
コード例 #46
0
 protected override bool ShouldHighlightObject(IDiagramEntity obj)
 {
     return false;
 }
コード例 #47
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
    /// <summary>
    /// Sends the entity up the z-order stack with the specified amount.
    /// </summary>
    /// <param name="entity">The entity.</param>
    /// <param name="zShift">The z shift.</param>
    public void SendForwards(IDiagramEntity entity, int zShift) {
      ILayer layer = CurrentPage.GetLayer(entity);
      if (layer != null) {
        int newpos = layer.Entities.IndexOf(entity) + zShift;
        //if this is the last in the row you cannot move it higher
        if (newpos < layer.Entities.Count) {
          layer.Entities.Remove(entity);
          layer.Entities.Insert(newpos, entity); //does it works when this is an addition at the top?
          ReAssignSceneIndex(layer.Entities);
          Rectangle rec = entity.Rectangle;
          rec.Inflate(20, 20);
          this.RaiseOnInvalidateRectangle(Rectangle);
        }
      }

      //if (Paintables.Contains(entity) && zShift>=1)
      //{
      //    int newpos = Paintables.IndexOf(entity) + zShift;
      //    //if this is the last in the row you cannot move it higher
      //    if (newpos < Paintables.Count)
      //    {
      //        Paintables.Remove(entity);
      //        Paintables.Insert(newpos, entity); //does it works when this is an addition at the top?
      //        ReAssignSceneIndex(Paintables);
      //        Rectangle rec = entity.Rectangle;
      //        rec.Inflate(20, 20);
      //        this.RaiseOnInvalidateRectangle(Rectangle);
      //    }
      //}
    }
コード例 #48
0
ファイル: Selection.cs プロジェクト: thunder176/HeuristicLab
 internal void SelectEntity(IDiagramEntity entity, Point surfacePoint) {
   // Groups are treated specially because we can drill-down
   // into the group.  The process of drilling is the first
   // mouse hit will select the group.  The second mouse hit
   // will select a child, if there's a child at that point.
   if (entity is IGroup) {
     if (entity.IsSelected == false) {
       entity.IsSelected = true;
       mSelection.Add(entity);
     } else {
       IGroup group = entity as IGroup;
       for (int j = group.Entities.Count - 1; j >= 0; j--) {
         IDiagramEntity child = group.Entities[j];
         if (child.Hit(surfacePoint)) {
           // Repeat the process because what if this
           // child is too a group!
           SelectEntity(child, surfacePoint);
           group.IsSelected = false;
           if (mSelection.Contains(group)) {
             mSelection.Remove(group);
           }
           break;
         }
       }
     }
   }
     //else if (entity.Group != null)
     //{
     //    //entity.Group.IsSelected = true;
     //    //mSelection.Add(entity.Group);
     //}
   else {
     entity.IsSelected = true;
     mSelection.Add(entity);
   }
 }
コード例 #49
0
ファイル: Model.cs プロジェクト: Tom-Hoinacki/OO-CASE-Tool
 public void Remove(IDiagramEntity entity)
 {
     if (DefaultPage.DefaultLayer.Entities.Contains(entity))
     {
         entity.OnRemove();
         DefaultPage.DefaultLayer.Entities.Remove(entity);
     }
 }
コード例 #50
0
ファイル: Model.cs プロジェクト: Tom-Hoinacki/OO-CASE-Tool
        public void SendBackwards(IDiagramEntity entity, int zShift)
        {
            if (mPaintables.Contains(entity))
            {
                int newpos = mPaintables.IndexOf(entity) - zShift;
                //if this is the first in the row you cannot move it lower
                if (newpos >= 0)
                {
                    mPaintables.Remove(entity);
                    mPaintables.Insert(newpos, entity);
                    Rectangle rec = entity.Rectangle;
                    rec.Inflate(20, 20);
                    this.RaiseOnInvalidateRectangle(Rectangle);
                }

            }
        }
コード例 #51
0
 public CancelableEntityEventArgs(IDiagramEntity entity)
 {
     this.Entity = entity;
 }
コード例 #52
0
ファイル: Model.cs プロジェクト: Tom-Hoinacki/OO-CASE-Tool
 public void SendForwards(IDiagramEntity entity, int zShift)
 {
     if (mPaintables.Contains(entity) && zShift>=1)
     {
         int newpos = mPaintables.IndexOf(entity) + zShift;
         //if this is the last in the row you cannot move it higher
         if (newpos < mPaintables.Count)
         {
             mPaintables.Remove(entity);
             mPaintables.Insert(newpos, entity); //does it works when this is an addition at the top?
             Rectangle rec = entity.Rectangle;
             rec.Inflate(20, 20);
             this.RaiseOnInvalidateRectangle(Rectangle);
         }
     }
 }
コード例 #53
0
ファイル: HoverTool.cs プロジェクト: radtek/HeuristicLabPlay
        // ------------------------------------------------------------------
        /// <summary>
        /// Handles the mouse move event
        /// </summary>
        /// <param name="e">The <see cref=
        /// "T:System.Windows.Forms.MouseEventArgs"/> instance containing
        /// the event data.</param>
        // ------------------------------------------------------------------
        public void MouseMove(MouseEventArgs e)
        {
            if (!IsSuspended && this.Enabled)
            {
                IHoverListener listener = null;

                CollectionBase <IDiagramEntity> paintables =
                    this.Controller.Model.Paintables;
                IDiagramEntity entity;
                if (paintables.Count == 0)
                {
                    return;
                }
                //going from top to the bottom of the z-order
                for (int k = paintables.Count - 1; k >= 0; k--)
                {
                    entity = paintables[k];
                    if (entity.Hit(e.Location)) //we caught an entity
                    {
                        //unhover the previous, if any
                        if (previousHovered != null)
                        {
                            previousHovered.Hovered = false;
                        }

                        //tell the current one it's being hovered
                        entity.Hovered = true;

                        //fetch the hovering service, if defined
                        listener = entity.GetService(
                            typeof(IHoverListener)) as IHoverListener;
                        if (listener != null)                //the caught entity does listen
                        {
                            if (currentListener == listener) //it's the same as the previous time
                            {
                                listener.MouseHover(e);
                            }
                            else //we moved from one entity to another listening entity
                            {
                                if (currentListener != null) //tell the previous entity we are leaving
                                {
                                    currentListener.MouseLeave(e);
                                }
                                listener.MouseEnter(e); //tell the current one we enter
                                currentListener = listener;
                            }
                        }
                        else //the caught entity does not listen
                        {
                            if (currentListener != null)
                            {
                                currentListener.MouseLeave(e);
                                currentListener = null;
                            }
                        }
                        previousHovered = entity; //remember, for the next time
                        return;                   //if another entity is listening underneath this entity it will not receive the notification
                    }
                }
                if (currentListener != null)
                {
                    currentListener.MouseLeave(e);
                    currentListener = null;
                }
                //unhover the previous, if any
                if (previousHovered != null)
                {
                    previousHovered.Hovered = false;
                }
            }
        }
コード例 #54
0
ファイル: Model.cs プロジェクト: Tom-Hoinacki/OO-CASE-Tool
 public void SetModel(IDiagramEntity entity)
 {
     if(entity is IConnector)
     {
         (entity as IConnector).Model = this;
     }
     else if(entity is IConnection)
     {
         IConnection con = entity as IConnection;
         con.Model = this;
         Debug.Assert(con.From != null, "The 'From' connector is not set.");
         con.From.Model = this;
         Debug.Assert(con.From != null, "The 'To' connector is not set.");
         con.To.Model = this;
     }
     else if(entity is IShape)
     {
         IShape shape = entity as IShape;
         shape.Model = this;
         foreach(IConnector co in shape.Connectors)
         {
             co.Model = this;
         }
     }
 }
コード例 #55
0
ファイル: Model.cs プロジェクト: thunder176/HeuristicLab
 // ------------------------------------------------------------------
 /// <summary>
 /// Removes the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 // ------------------------------------------------------------------
 public void Remove(IDiagramEntity entity) {
   if (CurrentPage.DefaultLayer.Entities.Contains(entity)) {
     CurrentPage.DefaultLayer.Entities.Remove(entity);
     entity.Detached(CurrentPage.DefaultLayer);
   }
 }