Esempio n. 1
0
 public NCProgramInfo()
 {
     sPath            = "";
     oNcOXY           = new WorkPlaneOrigin();
     oTools           = new List <NCProgramTool>();
     sToolRef         = "";
     sAttachWorkplane = "";
     sNCWorkplane     = "";
 }
Esempio n. 2
0
        /// <summary>
        /// Get coordinates of a workplanes
        /// </summary>
        /// <param name="token"></param>
        /// <param name="wp"></param>
        /// <param name="in_relation_to_active_wp"></param>
        /// <param name="err_msg"></param>
        /// <returns></returns>
        public static WorkPlaneOrigin GetWorkplaneCoords(string token, string wp, bool in_relation_to_active_wp, string err_msg)
        {
            WorkPlaneOrigin wpO = new WorkPlaneOrigin();

            if (wp.ToUpper() == "GLOBAL")
            {
                return(wpO);
            }

            if (!PowerMillHasWorkplane(wp))
            {
                if (err_msg != null)
                {
                    Messages.ShowError(err_msg);
                }
                return(wpO);
            }

            // Turn messages off, if necessary
            bool messages_displayed = PowerMILLAutomation.oPServices.RequestInformation("MessagesDisplayed") == "true";

            if (messages_displayed)
            {
                PowerMILLAutomation.oPServices.DoCommand(PowerMILLAutomation.oToken, "DIALOGS MESSAGE OFF");
            }

            // Print the workplane info
            object wp_info;

            PowerMILLAutomation.oPServices.DoCommandEx(token, "SIZE WORKPLANE '" + wp + "'", out wp_info);

            // Turn messages back on, if they were on originally
            if (messages_displayed)
            {
                PowerMILLAutomation.oPServices.DoCommand(token, "DIALOGS MESSAGE ON");
            }

            string wp_info_str = wp_info as string;

            if (wp_info_str == null)
            {
                Messages.ShowError(err_msg);
                if (messages_displayed)
                {
                    PowerMILLAutomation.oPServices.DoCommand("DIALOGS MESSAGE ON", token);
                }
                return(null);
            }

            // Convert into lines
            string[] lines = wp_info_str.Split('\n');

            // Parse the WP properties
            List <Point3D> coords = new List <Point3D>();

            try
            {
                // Look for lines containing three coordinates
                Regex r = new Regex(String.Format("{0} +{0} +{0}", "(-?[0-9]+\\" + System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator + "[0-9]+)"));
                foreach (string line in lines)
                {
                    Match m = r.Match(line);
                    if (m.Success)
                    {
                        double x = double.Parse(m.Groups[1].ToString());
                        double y = double.Parse(m.Groups[2].ToString());
                        double z = double.Parse(m.Groups[3].ToString());
                        coords.Add(new Point3D(x, y, z));
                    }
                }
            }
            catch (Exception)
            {
                Messages.ShowError(err_msg);
                if (messages_displayed)
                {
                    PowerMILLAutomation.oPServices.DoCommand("DIALOGS MESSAGE ON", token);
                }
                return(new WorkPlaneOrigin());
            }

            // We expect either 5 values or 10 values, depending on whether the workplane is active
            if (coords.Count != 5 && coords.Count != 10)
            {
                Messages.ShowError(err_msg);
                if (messages_displayed)
                {
                    PowerMILLAutomation.oPServices.DoCommand("DIALOGS MESSAGE ON", token);
                }
                return(new WorkPlaneOrigin());
            }

            // Build the output info
            StringBuilder sb = new StringBuilder();

            if (in_relation_to_active_wp && coords.Count == 10)
            {
                wpO = new WorkPlaneOrigin(coords[5].X, coords[5].Y, coords[5].Z,
                                          coords[6].X, coords[6].Y, coords[6].Z,
                                          coords[7].X, coords[7].Y, coords[7].Z,
                                          coords[8].X, coords[8].Y, coords[8].Z,
                                          coords[9].X, coords[9].Y, coords[9].Z);
            }
            if (!in_relation_to_active_wp)// && coords.Count == 5)
            {
                wpO = new WorkPlaneOrigin(coords[0].X, coords[0].Y, coords[0].Z,
                                          coords[1].X, coords[1].Y, coords[1].Z,
                                          coords[2].X, coords[2].Y, coords[2].Z,
                                          coords[3].X, coords[3].Y, coords[3].Z,
                                          coords[4].X, coords[4].Y, coords[4].Z);
            }

            return(wpO);
        }