From 938fa96b9f5377ef330171232262b4d8aaca0918 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 24 Oct 2012 01:33:21 +0100 Subject: minor: Move co-ordinate related help to object commands to common ConsoleUtil.CoordHelp --- OpenSim/Framework/Console/ConsoleUtil.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs index a7cf0c0..027753d 100644 --- a/OpenSim/Framework/Console/ConsoleUtil.cs +++ b/OpenSim/Framework/Console/ConsoleUtil.cs @@ -36,6 +36,23 @@ public class ConsoleUtil { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// + /// Used by modules to display stock co-ordinate help, though possibly this should be under some general section + /// rather than in each help summary. + /// + public const string CoordHelp += @"Each component of the coord is comma separated. There must be no spaces between the commas. +If you don't care about the z component you can simply omit it. +If you don't care about the x or y components then you can leave them blank (though a comma is still required) +If you want to specify the maxmimum value of a component then you can use ~ instead of a number +If you want to specify the minimum value of a component then you can use -~ instead of a number +e.g. +delete object pos 20,20,20 to 40,40,40 +delete object pos 20,20 to 40,40 +delete object pos ,20,20 to ,40,40 +delete object pos ,,30 to ,,~ +delete object pos ,,-~ to ,,30"; + public const string MinRawConsoleVectorValue = "-~"; public const string MaxRawConsoleVectorValue = "~"; -- cgit v1.1 From 73db057fa1dbda7d6dff7de770cef8670b234f84 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 24 Oct 2012 02:05:28 +0100 Subject: Add "dump object uuid" console command. This allows any object in the scene to be serialized and dumped to XML for debug purposes. --- OpenSim/Framework/Console/ConsoleUtil.cs | 206 +++++++++++++++++-------------- 1 file changed, 115 insertions(+), 91 deletions(-) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs index 027753d..5c25ccb 100644 --- a/OpenSim/Framework/Console/ConsoleUtil.cs +++ b/OpenSim/Framework/Console/ConsoleUtil.cs @@ -32,100 +32,124 @@ using System.Reflection; using log4net; using OpenMetaverse; -public class ConsoleUtil +namespace OpenSim.Framework.Console { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - /// - /// Used by modules to display stock co-ordinate help, though possibly this should be under some general section - /// rather than in each help summary. - /// - public const string CoordHelp -= @"Each component of the coord is comma separated. There must be no spaces between the commas. -If you don't care about the z component you can simply omit it. -If you don't care about the x or y components then you can leave them blank (though a comma is still required) -If you want to specify the maxmimum value of a component then you can use ~ instead of a number -If you want to specify the minimum value of a component then you can use -~ instead of a number -e.g. -delete object pos 20,20,20 to 40,40,40 -delete object pos 20,20 to 40,40 -delete object pos ,20,20 to ,40,40 -delete object pos ,,30 to ,,~ -delete object pos ,,-~ to ,,30"; - - public const string MinRawConsoleVectorValue = "-~"; - public const string MaxRawConsoleVectorValue = "~"; - - public const string VectorSeparator = ","; - public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray(); - - /// - /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3 - /// - /// /param> - /// - /// - public static bool TryParseConsoleMinVector(string rawConsoleVector, out Vector3 vector) + public class ConsoleUtil { - return TryParseConsoleVector(rawConsoleVector, c => float.MinValue.ToString(), out vector); - } - - /// - /// Convert a maximum vector input from the console to an OpenMetaverse.Vector3 - /// - /// /param> - /// - /// - public static bool TryParseConsoleMaxVector(string rawConsoleVector, out Vector3 vector) - { - return TryParseConsoleVector(rawConsoleVector, c => float.MaxValue.ToString(), out vector); - } - - /// - /// Convert a vector input from the console to an OpenMetaverse.Vector3 - /// - /// - /// A string in the form ,, where there is no space between values. - /// Any component can be missing (e.g. ,,40). blankComponentFunc is invoked to replace the blank with a suitable value - /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40,30 or 40) - /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue - /// Other than that, component values must be numeric. - /// - /// - /// - /// - public static bool TryParseConsoleVector( - string rawConsoleVector, Func blankComponentFunc, out Vector3 vector) - { - List components = rawConsoleVector.Split(VectorSeparatorChars).ToList(); - - if (components.Count < 1 || components.Count > 3) + // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + /// + /// Used by modules to display stock co-ordinate help, though possibly this should be under some general section + /// rather than in each help summary. + /// + public const string CoordHelp + = @"Each component of the coord is comma separated. There must be no spaces between the commas. + If you don't care about the z component you can simply omit it. + If you don't care about the x or y components then you can leave them blank (though a comma is still required) + If you want to specify the maxmimum value of a component then you can use ~ instead of a number + If you want to specify the minimum value of a component then you can use -~ instead of a number + e.g. + delete object pos 20,20,20 to 40,40,40 + delete object pos 20,20 to 40,40 + delete object pos ,20,20 to ,40,40 + delete object pos ,,30 to ,,~ + delete object pos ,,-~ to ,,30"; + + public const string MinRawConsoleVectorValue = "-~"; + public const string MaxRawConsoleVectorValue = "~"; + + public const string VectorSeparator = ","; + public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray(); + + /// + /// Try to parse a console UUID from the console. + /// + /// + /// Will complain to the console if parsing fails. + /// + /// + /// + /// + /// + public static bool TryParseConsoleUuid(ICommandConsole console, string rawUuid, out UUID uuid) { - vector = Vector3.Zero; - return false; + if (!UUID.TryParse(rawUuid, out uuid)) + { + console.OutputFormat("{0} is not a valid uuid", rawUuid); + return false; + } + + return true; + } + + /// + /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3 + /// + /// /param> + /// + /// + public static bool TryParseConsoleMinVector(string rawConsoleVector, out Vector3 vector) + { + return TryParseConsoleVector(rawConsoleVector, c => float.MinValue.ToString(), out vector); + } + + /// + /// Convert a maximum vector input from the console to an OpenMetaverse.Vector3 + /// + /// /param> + /// + /// + public static bool TryParseConsoleMaxVector(string rawConsoleVector, out Vector3 vector) + { + return TryParseConsoleVector(rawConsoleVector, c => float.MaxValue.ToString(), out vector); + } + + /// + /// Convert a vector input from the console to an OpenMetaverse.Vector3 + /// + /// + /// A string in the form ,, where there is no space between values. + /// Any component can be missing (e.g. ,,40). blankComponentFunc is invoked to replace the blank with a suitable value + /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40,30 or 40) + /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue + /// Other than that, component values must be numeric. + /// + /// + /// + /// + public static bool TryParseConsoleVector( + string rawConsoleVector, Func blankComponentFunc, out Vector3 vector) + { + List components = rawConsoleVector.Split(VectorSeparatorChars).ToList(); + + if (components.Count < 1 || components.Count > 3) + { + vector = Vector3.Zero; + return false; + } + + for (int i = components.Count; i < 3; i++) + components.Add(""); + + List semiDigestedComponents + = components.ConvertAll( + c => + { + if (c == "") + return blankComponentFunc.Invoke(c); + else if (c == MaxRawConsoleVectorValue) + return float.MaxValue.ToString(); + else if (c == MinRawConsoleVectorValue) + return float.MinValue.ToString(); + else + return c; + }); + + string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray()); + + // m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector); + + return Vector3.TryParse(semiDigestedConsoleVector, out vector); } - - for (int i = components.Count; i < 3; i++) - components.Add(""); - - List semiDigestedComponents - = components.ConvertAll( - c => - { - if (c == "") - return blankComponentFunc.Invoke(c); - else if (c == MaxRawConsoleVectorValue) - return float.MaxValue.ToString(); - else if (c == MinRawConsoleVectorValue) - return float.MinValue.ToString(); - else - return c; - }); - - string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray()); - -// m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector); - - return Vector3.TryParse(semiDigestedConsoleVector, out vector); } } \ No newline at end of file -- cgit v1.1 From f76dceb90b5a76a7b6a5243c9032996c007c0cf5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 24 Oct 2012 03:08:58 +0100 Subject: Get "save oar" and "save iar" to tell you in a more friendly manner if the filename to save already exists, rather than exception throwing. Also changes ConsoleUtil.CheckFileExists to CheckFileDoesNotExist() since this is more meaningful in the context, even though it does result in double negatives. --- OpenSim/Framework/Console/ConsoleUtil.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs index 5c25ccb..3ebfdf8 100644 --- a/OpenSim/Framework/Console/ConsoleUtil.cs +++ b/OpenSim/Framework/Console/ConsoleUtil.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using log4net; @@ -60,6 +61,24 @@ namespace OpenSim.Framework.Console public const string VectorSeparator = ","; public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray(); + + /// + /// Check if the given file path exists. + /// + /// If not, warning is printed to the given console. + /// true if the file does not exist, false otherwise. + /// + /// + public static bool CheckFileDoesNotExist(ICommandConsole console, string path) + { + if (File.Exists(path)) + { + console.OutputFormat("File {0} already exists. Please move or remove it.", path); + return false; + } + + return true; + } /// /// Try to parse a console UUID from the console. -- cgit v1.1 From 81aeecc90723658187668baa49bd168b7b333afb Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 24 Oct 2012 04:10:22 +0100 Subject: Allow "show object", "show part", "dump object" and "delete object" to accept a local ID as well as a UUID. This means that the sub-commands are now id rather than uuid, e.g. show object id --- OpenSim/Framework/Console/ConsoleUtil.cs | 58 ++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs index 3ebfdf8..16a63e0 100644 --- a/OpenSim/Framework/Console/ConsoleUtil.cs +++ b/OpenSim/Framework/Console/ConsoleUtil.cs @@ -38,6 +38,8 @@ namespace OpenSim.Framework.Console public class ConsoleUtil { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public const int LocalIdNotFound = 0; /// /// Used by modules to display stock co-ordinate help, though possibly this should be under some general section @@ -87,19 +89,71 @@ namespace OpenSim.Framework.Console /// Will complain to the console if parsing fails. /// /// - /// + /// If null then no complaint is printed. /// /// public static bool TryParseConsoleUuid(ICommandConsole console, string rawUuid, out UUID uuid) { if (!UUID.TryParse(rawUuid, out uuid)) { - console.OutputFormat("{0} is not a valid uuid", rawUuid); + if (console != null) + console.OutputFormat("{0} is not a valid uuid", rawUuid); + return false; } return true; } + + public static bool TryParseConsoleLocalId(ICommandConsole console, string rawLocalId, out uint localId) + { + if (!uint.TryParse(rawLocalId, out localId)) + { + if (console != null) + console.OutputFormat("{0} is not a valid local id", localId); + + return false; + } + + if (localId == 0) + { + if (console != null) + console.OutputFormat("{0} is not a valid local id - it must be greater than 0", localId); + + return false; + } + + return true; + } + + /// + /// Tries to parse the input as either a UUID or a local ID. + /// + /// true if parsing succeeded, false otherwise. + /// + /// + /// + /// + /// Will be set to ConsoleUtil.LocalIdNotFound if parsing result was a UUID or no parse succeeded. + /// + public static bool TryParseConsoleId(ICommandConsole console, string rawId, out UUID uuid, out uint localId) + { + if (TryParseConsoleUuid(null, rawId, out uuid)) + { + localId = LocalIdNotFound; + return true; + } + + if (TryParseConsoleLocalId(null, rawId, out localId)) + { + return true; + } + + if (console != null) + console.OutputFormat("{0} is not a valid UUID or local id", rawId); + + return false; + } /// /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3 -- cgit v1.1