Canguro.Commands.Model.JoinCmd.Join C# (CSharp) Method

Join() public static method

Finds repeated Joints and Line Elements and deletes them. Deletes only Items in the parameters and keeps the Item with the smallest ID.
public static Join ( Canguro model, IList joints, IList lines, IList areas ) : void
model Canguro The Model object
joints IList List of Joints to check
lines IList List of Line Elements to check
areas IList List of Area Elements to check
return void
        public static void Join(Canguro.Model.Model model, IList<Joint> joints, IList<LineElement> lines, IList<AreaElement> areas)
        {
            System.Windows.Forms.Cursor cursor = System.Windows.Forms.Cursor.Current;
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
            try
            {
                Dictionary<uint, uint> deleteJoints = new Dictionary<uint, uint>();
                ItemList<Joint> jList = model.JointList;
                ItemList<LineElement> lList = model.LineList;
                ItemList<AreaElement> aList = model.AreaList;
                bool[] usedJoints = new bool[jList.Count];

                // Find repeated joints
                for (uint ii = 0; ii < joints.Count; ii++)
                {
                    Joint j = joints[(int)ii];
                    if (j != null)
                    {
                        for (uint jj = 0; jj < j.Id; jj++)
                        {
                            Joint mj = jList[jj];
                            if (mj != null && equals(j, mj)
                                && !deleteJoints.ContainsKey(j.Id))
                            {
                                deleteJoints.Add(j.Id, jj);
                                break;
                            }
                        }
                    }
                    System.Windows.Forms.Application.DoEvents();
                }

                // Move lines to current joints.
                foreach (LineElement l in lines)
                {
                    if (l != null && l.I != null && deleteJoints.ContainsKey(l.I.Id))
                        l.I = jList[deleteJoints[l.I.Id]];
                    if (l != null && l.J != null && deleteJoints.ContainsKey(l.J.Id))
                        l.J = jList[deleteJoints[l.J.Id]];
                }

                // Delete repeated and Zero-lenght lines.
                for (int i = 0; i < lines.Count; i++)
                {
                    LineElement l = lines[i];
                    if (l != null)
                    {
                        if (l.I.Id == l.J.Id || l.Length < 0.0001F)
                            lList.RemoveAt((int)l.Id);
                        else
                            for (int j = 0; j < (int)l.Id; j++)
                            {
                                LineElement ml = lList[j];
                                if (ml != null && (ml.Id < l.Id && equals(l, ml)))
                                {
                                    lList.RemoveAt((int)l.Id);
                                    ml.IsVisible = true;
                                    break;
                                }
                            }
                    }
                }

                // Move areas to current joints.
                foreach (AreaElement a in areas)
                {
                    if (a != null && a.J1 != null && deleteJoints.ContainsKey(a.J1.Id))
                        a.J1 = jList[deleteJoints[a.J1.Id]];
                    if (a != null && a.J2 != null && deleteJoints.ContainsKey(a.J2.Id))
                        a.J2 = jList[deleteJoints[a.J2.Id]];
                    if (a != null && a.J3 != null && deleteJoints.ContainsKey(a.J3.Id))
                        a.J3 = jList[deleteJoints[a.J3.Id]];
                    if (a != null && a.J4 != null && deleteJoints.ContainsKey(a.J4.Id))
                        a.J4 = jList[deleteJoints[a.J4.Id]];
                }

                // Delete repeated and Zero-area Areas.
                for (int i = 0; i < areas.Count; i++)
                {
                    AreaElement a = areas[i];
                    if (a != null)
                    {
                        if ((a.J4 != null && (a.J1.Id == a.J2.Id || a.J1.Id == a.J3.Id || a.J1.Id == a.J4.Id || a.J2.Id == a.J3.Id || a.J2.Id == a.J4.Id || a.J3.Id == a.J4.Id)) ||
                            (a.J1.Id == a.J2.Id || a.J1.Id == a.J3.Id || a.J2.Id == a.J3.Id) || a.Area < 0.0001F)
                            aList.RemoveAt((int)a.Id);
                        else
                            for (int j = 0; j < (int)a.Id; j++)
                            {
                                AreaElement ml = aList[j];
                                if (ml != null && (ml.Id < a.Id && equals(a, ml)))
                                {
                                    aList.RemoveAt((int)a.Id);
                                    ml.IsVisible = true;
                                    break;
                                }
                            }
                    }
                }

                // Delete repeated joints.
                foreach (int id in deleteJoints.Keys)
                    jList.RemoveAt(id);

                // Delete unused joints only if lines or areas are used.
                if (lines.Count > 0 || areas.Count > 0)
                {
                    foreach (LineElement l in lList)
                        if (l != null)
                        {
                            usedJoints[l.I.Id] = true;
                            usedJoints[l.J.Id] = true;
                        }
                    foreach (AreaElement a in aList)
                        if (a != null)
                        {
                            usedJoints[a.J1.Id] = true;
                            usedJoints[a.J2.Id] = true;
                            usedJoints[a.J3.Id] = true;
                            usedJoints[a.J4.Id] = true;
                        }
                    for (int i = 0; i < joints.Count; i++)
                    {
                        Joint j = joints[i];
                        if (j != null && !usedJoints[j.Id] && jList[j.Id] == j)
                            jList.RemoveAt((int)j.Id);
                    }
                }
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = cursor;
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Executes the command.
        /// Adds a set of Line Elements. Opens a properties window and asks the user for two points or Joints for each one.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            LineElement        line;
            Joint              joint1, joint2;
            LineProps          props    = new StraightFrameProps();
            List <LineElement> newLines = new List <LineElement>();
            List <AreaElement> newAreas = new List <AreaElement>();

            services.GetProperties(Culture.Get("addLineProps"), props);


            try
            {
                while ((joint1 = services.GetJoint(newLines)) != null)
                {
                    services.TrackingService = LineTrackingService.Instance;
                    services.TrackingService.SetPoint(joint1.Position);

                    while ((joint2 = services.GetJoint(newLines)) == joint1)
                    {
                        ;
                    }

                    if (joint2 == null)
                    {
                        services.Model.JointList.Remove(joint1);
                        break;
                    }
                    services.TrackingService = null;

                    services.Model.LineList.Add(line = new LineElement(props, joint1, joint2));
                    newLines.Add(line);

                    // Para que se refleje el cambio inmediatamente
                    services.Model.ChangeModel();
                }
            }
            catch (Canguro.Controller.CancelCommandException) { }
            JoinCmd.Join(services.Model, new List <Joint>(), newLines, newAreas);
        }
All Usage Examples Of Canguro.Commands.Model.JoinCmd::Join