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

RepairJoints() public static method

Detects inconsistencies in the model and repairs them. If a line is connected to a joint outside the model, it's added (if ID is free) or changed (if a joint with same ID exists).
public static RepairJoints ( Canguro model ) : void
model Canguro
return void
        public static void RepairJoints(Canguro.Model.Model model)
        {
            foreach (LineElement line in model.LineList)
            {
                if (line != null && line.I != null && line.J != null)
                {
                    Joint j = line.I;
                    if (model.JointList[j.Id] == null)
                        model.JointList.Add(j);
                    else if (model.JointList[j.Id] != j)
                        line.I = model.JointList[j.Id];

                    j = line.J;
                    if (model.JointList[j.Id] == null)
                        model.JointList.Add(j);
                    else if (model.JointList[j.Id] != j)
                        line.J = model.JointList[j.Id];
                }
            }

            foreach (AreaElement area in model.AreaList)
            {
                if (area != null && area.J1 != null && area.J2 != null && area.J3 != null)
                {
                    for (int i = 0; i < ((area.J4 != null) ? 4 : 3); i++)
                    {
                        Joint j = area[i];
                        if (model.JointList[j.Id] == null)
                            model.JointList.Add(j);
                        else if (model.JointList[j.Id] != j)
                            area[i] = model.JointList[j.Id];
                    }
                }
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Executes the command.
        /// Opens the AnalysisOptionsDialog, creates the export file, sends it to the Server and waits for it to have results.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            gettingResults = false;
            System.Windows.Forms.DialogResult result = services.ShowDialog(new Canguro.Commands.Model.AnalysisOptionsDialog(services));
            string message = "";

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                services.Model.Undo.Rollback();
            }
            else if (result == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    System.Windows.Forms.Cursor cursor = System.Windows.Forms.Cursor.Current;
                    bool isConnected;
                    bool canAnalyze = false;
                    JoinCmd.RepairJoints(services.Model);
                    new Canguro.Commands.Model.UnselectCmd().Run(services);
                    if (!(canAnalyze = AnalysisUtils.CanAnalyze(services.Model, ref message, out isConnected)))
                    {
                        if (!isConnected)
                        {
                            if (System.Windows.Forms.MessageBox.Show(message, Culture.Get("error"),
                                                                     System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error) ==
                                System.Windows.Forms.DialogResult.Yes)
                            {
                                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                                new JoinCmd().Run(services);
                                canAnalyze = AnalysisUtils.CanAnalyze(services.Model, ref message, out isConnected);

                                System.Windows.Forms.Cursor.Current = cursor;
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    if (canAnalyze)
                    {
                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                        string modelPath = System.IO.Path.GetTempFileName();
                        System.Diagnostics.Debug.WriteLine(modelPath);
                        FixPDelta(services.Model.AbstractCases);

                        Stream stream = File.Create(modelPath);
                        new Canguro.Model.Serializer.Serializer(services.Model).Serialize(stream, false);
                        stream.Close();

                        System.Windows.Forms.Cursor.Current = cursor;

                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                        // TODO: ANALYZE STRUCTURE!!!
                        //analysisID = ws.Analyze(userNameURL, passwordURL, host, serial, file, analysisOptions, modelSize, quotation);

                        System.Windows.Forms.Cursor.Current = cursor;

                        services.Model.Results = new Canguro.Model.Results.Results(0);

                        // TODO: GET RESULTS
                        services.ReportProgress(5);
                    }
                    else // Can't analyze
                    {
                        if (!isConnected)
                        {
                            message = Culture.Get("structureIsDisconnectedWrn");
                        }

                        System.Windows.Forms.MessageBox.Show(message, Culture.Get("error"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                }
                catch (Exception)
                {
                    System.Windows.Forms.MessageBox.Show(Culture.Get("ErrorAnalyzing"), Culture.Get("error"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
        }