Exemple #1
0
        public void KojtoCAD_3D_Get_Glass_Conturs_Centroid()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Matrix3d old = ed.CurrentUserCoordinateSystem;

            ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

            try
            {
                PromptKeywordOptions pop = new PromptKeywordOptions("");
                pop.AppendKeywordsToMessage = true;
                pop.AllowNone = false;
                pop.Keywords.Add("Run");
                pop.Keywords.Add("Help");
                pop.Keywords.Default = "Run";
                PromptResult res = ed.GetKeywords(pop);
                //_AcAp.Application.ShowAlertDialog(res.ToString());
                if (res.Status == PromptStatus.OK)
                {
                    switch (res.StringResult)
                    {
                    case "Run":
                        if ((container != null) && (container.Bends.Count > 0) && (container.Nodes.Count > 0) && (container.Triangles.Count > 0))
                        {
                            double     area = 0.0;
                            quaternion cen  = new quaternion();
                            foreach (WorkClasses.Triangle TR in container.Triangles)
                            {
                                Triplet <quaternion, quaternion, quaternion> pr = container.GetInnererTriangle(TR.Numer, true);

                                double ar = Math.Abs(GlobalFunctions.GetArea(pr));

                                area += ar;
                                quaternion centroid = new quaternion();
                                centroid  = (pr.First + pr.Second) / 2.0;
                                centroid  = centroid - pr.Third;
                                centroid *= (2.0 / 3.0);
                                centroid  = pr.Third + centroid;
                                centroid *= ar;
                                cen      += centroid;
                            }
                            if (area > 0.0)
                            {
                                cen /= area;
                                string title = "\nTeoretical Mesh Glass Conturs center of gravity\n------------------\n\n";
                                string mess  = string.Format("{0} total area: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, area,
                                                             cen.GetX(), cen.GetY(), cen.GetZ());
                                ed.WriteMessage(mess);

                                MessageBox.Show(mess, "Glass Conturs - teoretical mesh center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;

                    case "Help":
                        GlobalFunctions.OpenHelpHTML("http://3dsoft.blob.core.windows.net/kojtocad/html/SPOTS_CENTROID.htm");
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Application.ShowAlertDialog(
                    string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
            }
            finally { ed.CurrentUserCoordinateSystem = old; }
        }