/// <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); } } } } } } } } } }
/// <summary> /// Attaches the given connector to this connector. /// <remarks>The method will remove a previous binding, if any, before creating the attachment. This method prohibits mutliple identical connections; /// you can attach a connector only once. /// </remarks> /// </summary> /// <param name="connector"></param> public void AttachConnector(IConnector connector) { if (connector == null || !Enabled) { 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.mPoint; connector.AttachedTo = this; } }
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); } }
/// <summary> /// Handles the OnEntityRemoved event of the DefaultPage. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:Netron.Diagramming.Core.EntityEventArgs"/> instance containing the event data.</param> void mDefaultPage_OnEntityRemoved(object sender, EntityEventArgs e) { if (mPaintables.Contains(e.Entity)) { //shift the entities above the one to be removed int index = e.Entity.SceneIndex; foreach (IDiagramEntity entity in mPaintables) { if (entity.SceneIndex > index) { entity.SceneIndex--; } } mPaintables.Remove(e.Entity); } //if the selection contains the shape we have to remove it from the selection if (Selection.SelectedItems.Contains(e.Entity)) { Selection.SelectedItems.Remove(e.Entity); } RaiseOnEntityRemoved(e); }
/// <summary> /// Handles the OnEntityRemoved event of the DefaultPage. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:Netron.Diagramming.Core.EntityEventArgs"/> instance containing the event data.</param> void mDefaultPage_OnEntityRemoved(object sender, EntityEventArgs e) { //IShape sp = e.Entity as IShape; //if(sp != null) //{ // foreach(IConnector cr in sp.Connectors) // mConnectorHolders.Remove(cr); //} if (mPaintables.Contains(e.Entity)) { //shift the entities above the one to be removed int index = e.Entity.SceneIndex; foreach (IDiagramEntity entity in mPaintables) { if (entity.SceneIndex > index) { entity.SceneIndex--; } } mPaintables.Remove(e.Entity); } //if the selection contains the shape we have to remove it from the selection if (Selection.SelectedItems.Contains(e.Entity)) { Selection.SelectedItems.Remove(e.Entity); } RaiseOnEntityRemoved(e); IConnection cn = e.Entity as IConnection; if (cn != null) { mConnectorHolders.Remove(cn.From); mConnectorHolders.Remove(cn.To); } }
/// <summary> /// Collects the entities inside the given rectangle. /// </summary> /// <param name="surfaceRectangle">The surface rectangle.</param> public static void CollectEntitiesInside(Rectangle surfaceRectangle) { if (surfaceRectangle == Rectangle.Empty) { return; } Selection.Clear(); foreach (IDiagramEntity entity in Selection.Controller.Model.Paintables) { //if the entity is part of a group we have to look at the bigger picture if (mSelectionType == SelectionTypes.Inclusion) { if (entity.Group != null) { //the rectangle must contain the whole group if (surfaceRectangle.Contains(entity.Group.Rectangle)) { //add the group if not already present via another group member if (!mSelection.Contains(entity.Group)) { mSelection.Add(entity.Group); } continue; } } else { if (surfaceRectangle.Contains(entity.Rectangle)) { mSelection.Add(entity); entity.IsSelected = true; } } } else //the selection requires only partial overlap with the rectangle { if (entity.Group != null) { if (surfaceRectangle.IntersectsWith(entity.Group.Rectangle)) { if (!mSelection.Contains(entity.Group)) { mSelection.Add(entity.Group); } continue; } } else { if (surfaceRectangle.IntersectsWith(entity.Rectangle)) { if (!mSelection.Contains(entity))//it could be a group which got already selected by one of its children { mSelection.Add(entity); entity.IsSelected = true; } } } } } RaiseOnNewSelection(); }