void ShowCachedEntry(CachedEntry entry) { if (entry.status == CachedEntryStatus.Ignored) { return; } else if (entry.status != CachedEntryStatus.Folder) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(entry.label); if (entry.hasBuildButton && GUILayout.Button(entry.buildLabel, GUILayout.Width(BUTTON_WIDTH))) { // build this msg, srv, or action file switch (entry.status) { case CachedEntryStatus.BuiltMsgFile: case CachedEntryStatus.UnbuiltMsgFile: MessageAutoGen.GenerateSingleMessage(entry.path, MessageGenBrowserSettings.Get().outputPath); break; case CachedEntryStatus.BuiltSrvFile: case CachedEntryStatus.UnbuiltSrvFile: ServiceAutoGen.GenerateSingleService(entry.path, MessageGenBrowserSettings.Get().outputPath); break; case CachedEntryStatus.BuiltActionFile: case CachedEntryStatus.UnbuiltActionFile: ActionAutoGen.GenerateSingleAction(entry.path, MessageGenBrowserSettings.Get().outputPath); break; } AssetDatabase.Refresh(); m_IsCacheDirty = true; } EditorGUILayout.EndHorizontal(); } else { bool isFoldedOut = m_FoldedOutHash.Contains(entry.path); EditorGUILayout.BeginHorizontal(); bool shouldBeFoldedOut = EditorGUILayout.Foldout(isFoldedOut, entry.label, true, EditorStyles.foldout); if (entry.hasBuildButton && GUILayout.Button(entry.buildLabel, GUILayout.Width(BUTTON_WIDTH))) { // build this directory MessageAutoGen.GenerateDirectoryMessages(entry.path, MessageGenBrowserSettings.Get().outputPath); ServiceAutoGen.GenerateDirectoryServices(entry.path, MessageGenBrowserSettings.Get().outputPath); ActionAutoGen.GenerateDirectoryActions(entry.path, MessageGenBrowserSettings.Get().outputPath); AssetDatabase.Refresh(); m_IsCacheDirty = true; } EditorGUILayout.EndHorizontal(); if (isFoldedOut) { EditorGUI.indentLevel++; foreach (CachedEntry subEntry in entry.contents) { ShowCachedEntry(subEntry); } EditorGUI.indentLevel--; } if (shouldBeFoldedOut != isFoldedOut) { m_IsCacheDirty = true; if (shouldBeFoldedOut) { m_FoldedOutHash.Add(entry.path); } else { m_FoldedOutHash.Remove(entry.path); } } } }
public static void Main(string[] args) { // Arguments string inputPath = ""; bool verbose = false; bool service = false; bool action = false; bool recursive = false; bool package = false; string rosPackageName = ""; string outputPath = defaultOutputDirectory; // Parse Arguments if (args.Length == 0) { Console.WriteLine("No argument: Display usage"); Console.WriteLine(usage); return; } if (args[0].Equals("--help") || args[0].Equals("-h")) { Console.WriteLine("Help: Displays usage"); Console.WriteLine(usage); return; } for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg.Equals("-s") || arg.Equals("--service")) { if (action) { Console.Error.WriteLine("Option '--service' conflict with '--action'."); if (verbose) { Console.Error.WriteLine("Make up your mind!"); } return; } service = true; if (verbose) { Console.WriteLine("'--service' flag seen. Expecting *.srv input"); } continue; } if (arg.Equals("-a") || arg.Equals("--action")) { if (service) { Console.Error.WriteLine("Option '--action' conflict with '--service'."); if (verbose) { Console.Error.WriteLine("Make up your mind!"); } return; } action = true; if (verbose) { Console.WriteLine("'--action' flag seen. Expecting *.action input"); } continue; } if (arg.Equals("-r") || arg.Equals("--recursive")) { if (package) { Console.Error.WriteLine("Option '--recursive' conflict with '--package'."); if (verbose) { Console.Error.WriteLine("Make up your mind!"); } return; } if (recursive) { Console.WriteLine("Duplicate flag '--recursive'."); if (verbose) { Console.Error.WriteLine("I got it already!"); } } if (!rosPackageName.Equals("")) { Console.WriteLine("'--recursive' option enabled, ignoring ROS package name"); } recursive = true; continue; } if (arg.Equals("-p") || arg.Equals("--package")) { if (recursive) { Console.Error.WriteLine("Option '--package' conflict with '--recursive'."); if (verbose) { Console.Error.WriteLine("Make up your mind!"); } return; } if (package) { Console.WriteLine("Duplicate flag '--package'."); if (verbose) { Console.Error.WriteLine("I got it already!"); } } package = true; continue; } if (arg.Equals("-n") || arg.Equals("--ros-package-name")) { if (i == args.Length - 1) { Console.Error.WriteLine("Missing ROS package name. Will get name from path"); } else if (validOptions.Contains(args[i + 1])) { Console.Error.WriteLine("Missing ROS package name. Will get name from path"); } else if (recursive) { Console.WriteLine("'--recursive' option enabled, ignoring ROS package name"); } else { rosPackageName = args[i + 1]; i++; } continue; } if (arg.Equals("-o") || arg.Equals("--output")) { if (i == args.Length - 1) { Console.Error.WriteLine("Missing output path. Using default output path."); } else if (validOptions.Contains(args[i + 1])) { Console.Error.WriteLine("Missing output path. Using default output path."); } else { outputPath = args[i + 1]; outputPath = Path.Combine(outputPath, "RosSharpMessages"); i++; } continue; } if (arg.Equals("-v") || arg.Equals("--verbose")) { Console.WriteLine("Verbose flag detected. Warning: A huge wave of text incoming!"); verbose = true; continue; } if (inputPath.Equals("")) { inputPath = arg; } else { Console.Error.WriteLine("Ignored invalid argument: " + arg); if (verbose) { Console.Error.WriteLine("Mumble mumble. Run 'RosMsgGen.exe -h' or 'RosMsgGen.exe --help' to see usage"); } } } // Do work // Parse Individual Messages if (!package && !recursive) { if (inputPath.Equals("")) { Console.Error.WriteLine("Please specify input file"); if (verbose) { Console.Error.WriteLine("Bricks without straw"); } return; } if (!IsValidPath(inputPath, false)) { if (IsValidPath(inputPath, true)) { Console.Error.WriteLine("Input path is a directory. Please use --package or --recursive option"); } else { Console.Error.WriteLine("Invalid input path"); } return; } List <string> warnings; if (service) { warnings = ServiceAutoGen.GenerateSingleService(inputPath, outputPath, rosPackageName, verbose); } else if (action) { warnings = ActionAutoGen.GenerateSingleAction(inputPath, outputPath, rosPackageName, verbose); } else { warnings = MessageAutoGen.GenerateSingleMessage(inputPath, outputPath, rosPackageName, verbose); } PrintWarnings(warnings); return; } // Parse Package Messages if (package) { if (inputPath.Equals("")) { Console.Error.WriteLine("Please specify input package"); if (verbose) { Console.Error.WriteLine("Bricks without straw"); } return; } if (!IsValidPath(inputPath, true)) { if (IsValidPath(inputPath, false)) { Console.Error.WriteLine("Input path is a file. Please drop --package option"); } else { Console.Error.WriteLine("Invalid input path"); } return; } try { Console.WriteLine("Working..."); List <string> warnings; if (service) { warnings = ServiceAutoGen.GeneratePackageServices(inputPath, outputPath, rosPackageName, verbose); } else if (action) { warnings = ActionAutoGen.GeneratePackageActions(inputPath, outputPath, rosPackageName, verbose); } else { warnings = MessageAutoGen.GeneratePackageMessages(inputPath, outputPath, rosPackageName, verbose); } PrintWarnings(warnings); } catch (DirectoryNotFoundException) { if (service) { Console.Error.WriteLine("Didn't find service folder in given package"); } else { Console.Error.WriteLine("Didn't find message folder in given package"); } if (verbose) { Console.Error.WriteLine("Bricks without straw"); } } return; } // Parse Directory Message if (recursive) { if (inputPath.Equals("")) { Console.Error.WriteLine("Please specify input directory"); if (verbose) { Console.Error.WriteLine("Bricks without straw"); } return; } if (!IsValidPath(inputPath, true)) { if (IsValidPath(inputPath, false)) { Console.Error.WriteLine("Input path is a file. Consider as base case"); // Parse Single Message List <string> singleMsgWarnings; if (service) { singleMsgWarnings = ServiceAutoGen.GenerateSingleService(inputPath, outputPath, rosPackageName, verbose); } else if (action) { singleMsgWarnings = ActionAutoGen.GenerateSingleAction(inputPath, outputPath, rosPackageName, verbose); } else { singleMsgWarnings = MessageAutoGen.GenerateSingleMessage(inputPath, outputPath, rosPackageName, verbose); } PrintWarnings(singleMsgWarnings); } else { Console.Error.WriteLine("Invalid input path"); } return; } Console.WriteLine("Working...Checkout xkcd.com/303"); List <string> warnings; if (service) { warnings = ServiceAutoGen.GenerateDirectoryServices(inputPath, outputPath, verbose); } else if (action) { warnings = ActionAutoGen.GenerateDirectoryActions(inputPath, outputPath, verbose); } else { warnings = MessageAutoGen.GenerateDirectoryMessages(inputPath, outputPath, verbose); } PrintWarnings(warnings); return; } // Otherwise I don't know... Console.Error.WriteLine("Unrecognized combination of arguments."); if (verbose) { Console.WriteLine("Mumble Mumble. Run 'RosMsgGen.exe -h' or 'RosMsgGen.exe --help' to see usage"); } }