static void Main(string[] args) { string jsonString = ""; string s; while ((s = Console.ReadLine()) != null) { jsonString += s; } JToken o = JToken.Parse(jsonString); var selector = args[0]; var engine = new Engine(); object Eval(string script, object value) => engine.SetValue("$$", value) .Execute(script.Replace("@", "$$")) .GetCompletionValue() .ToObject(); var context = new JsonPathContext { ScriptEvaluator = new Func <string, object, string, object>((script, value, context) => Eval(script, value)), ValueSystem = new JsonNetValueSystem() }; try { var results = context.Select(o, selector); Console.WriteLine(JArray.FromObject(results).ToString()); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } }
public void SetActiveItem(IObject3D selectedItem) { this.item = selectedItem; editorPanel.CloseAllChildren(); // Allow caller to clean up with passing null for selectedItem if (item == null) { return; } var selectedItemType = selectedItem.GetType(); editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name; HashSet <IObject3DEditor> mappedEditors = ApplicationController.Instance.GetEditorsForType(selectedItemType); var undoBuffer = sceneContext.Scene.UndoBuffer; bool allowOperations = true; if (selectedItem is ComponentObject3D componentObject && componentObject.Finalized) { allowOperations = false; foreach (var selector in componentObject.SurfacedEditors) { // Get the named property via reflection // Selector example: '$.Children<CylinderObject3D>' var match = xpathLikeResolver.Select(componentObject, selector).ToList(); //// TODO: Create editor row for each property //// - Use the type of the property to find a matching editor (ideally all datatype -> editor functionality would resolve consistently) //// - Add editor row for each foreach (var instance in match) { if (instance is IObject3D object3D) { if (ApplicationController.Instance.GetEditorsForType(object3D.GetType())?.FirstOrDefault() is IObject3DEditor editor) { ShowObjectEditor((editor, object3D, object3D.Name), selectedItem, allowOperations: allowOperations); } } else if (JsonPath.JsonPathContext.ReflectionValueSystem.LastMemberValue is ReflectionTarget reflectionTarget) { var context = new PPEContext(); if (reflectionTarget.Source is IObject3D editedChild) { context.item = editedChild; } else { context.item = item; } var editableProperty = new EditableProperty(reflectionTarget.PropertyInfo, reflectionTarget.Source); var editor = PublicPropertyEditor.CreatePropertyEditor(editableProperty, undoBuffer, context, theme); if (editor != null) { editorPanel.AddChild(editor); } } } } // Enforce panel padding foreach (var sectionWidget in editorPanel.Descendants <SectionWidget>()) { sectionWidget.Margin = new BorderDouble(0, theme.DefaultContainerPadding / 2); } }
public void SetActiveItem(IObject3D selectedItem) { this.item = selectedItem; editorPanel.CloseAllChildren(); // Allow caller to clean up with passing null for selectedItem if (item == null) { return; } var selectedItemType = selectedItem.GetType(); editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name; HashSet <IObject3DEditor> mappedEditors = ApplicationController.Instance.GetEditorsForType(selectedItemType); var undoBuffer = sceneContext.Scene.UndoBuffer; bool allowOperations = true; // put in a color edit field var colorField = new ColorField(theme, selectedItem.Color); colorField.Initialize(0); colorField.ValueChanged += (s, e) => { if (selectedItem.Color != colorField.Color) { undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color)); } }; var colorRow = PublicPropertyEditor.CreateSettingsRow("Color".Localize()); colorRow.AddChild(colorField.Content); colorField.Content.MouseDown += (s, e) => { // make sure the render mode is set to shaded or outline if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Shaded && sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Outlines) { // make sure the render mode is set to material sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines; } }; editorPanel.AddChild(colorRow); // put in a material edit field var materialField = new MaterialIndexField(theme, selectedItem.MaterialIndex); materialField.Initialize(0); materialField.ValueChanged += (s, e) => { if (selectedItem.MaterialIndex != materialField.MaterialIndex) { undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex)); } }; var materialRow = PublicPropertyEditor.CreateSettingsRow("Material".Localize()); materialRow.AddChild(materialField.Content); materialField.Content.MouseDown += (s, e) => { if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials) { // make sure the render mode is set to material sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Materials; } }; editorPanel.AddChild(materialRow); // put in the normal editor if (selectedItem is ComponentObject3D componentObject && componentObject.Finalized) { allowOperations = false; foreach (var selector in componentObject.SurfacedEditors) { // Get the named property via reflection // Selector example: '$.Children<CylinderObject3D>' var match = pathResolver.Select(componentObject, selector).ToList(); //// TODO: Create editor row for each property //// - Use the type of the property to find a matching editor (ideally all datatype -> editor functionality would resolve consistently) //// - Add editor row for each foreach (var instance in match) { if (instance is IObject3D object3D) { if (ApplicationController.Instance.GetEditorsForType(object3D.GetType())?.FirstOrDefault() is IObject3DEditor editor) { ShowObjectEditor((editor, object3D, object3D.Name), selectedItem, allowOperations: allowOperations); } } else if (JsonPath.JsonPathContext.ReflectionValueSystem.LastMemberValue is ReflectionTarget reflectionTarget) { var context = new PPEContext(); if (reflectionTarget.Source is IObject3D editedChild) { context.item = editedChild; } else { context.item = item; } var editableProperty = new EditableProperty(reflectionTarget.PropertyInfo, reflectionTarget.Source); var editor = PublicPropertyEditor.CreatePropertyEditor(editableProperty, undoBuffer, context, theme); if (editor != null) { editorPanel.AddChild(editor); } } } } // Enforce panel padding foreach (var sectionWidget in editorPanel.Descendants <SectionWidget>()) { sectionWidget.Margin = new BorderDouble(0, theme.DefaultContainerPadding / 2); } }
public void SetActiveItem(ISceneContext sceneContext) { var selectedItem = sceneContext?.Scene?.SelectedItem; if (this.item == selectedItem) { return; } this.item = selectedItem; editorPanel.CloseChildren(); // Allow caller to clean up with passing null for selectedItem if (item == null) { editorSectionWidget.Text = editorTitle; return; } var selectedItemType = selectedItem.GetType(); primaryActionsPanel.RemoveChildren(); IEnumerable <SceneOperation> primaryActions; if ((primaryActions = SceneOperations.GetPrimaryOperations(selectedItemType)) == null) { primaryActions = new List <SceneOperation>(); } else { // Loop over primary actions creating a button for each foreach (var primaryAction in primaryActions) { // TODO: Run visible/enable rules on actions, conditionally add/enable as appropriate var button = new IconButton(primaryAction.Icon(theme.InvertIcons), theme) { // Name = namedAction.Title + " Button", ToolTipText = primaryAction.Title, Margin = theme.ButtonSpacing, BackgroundColor = theme.ToolbarButtonBackground, HoverColor = theme.ToolbarButtonHover, MouseDownColor = theme.ToolbarButtonDown, }; button.Click += (s, e) => { primaryAction.Action.Invoke(sceneContext); }; primaryActionsPanel.AddChild(button); } } if (primaryActionsPanel.Children.Any()) { // add in a separator from the apply and cancel buttons primaryActionsPanel.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin)); } editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name; HashSet <IObject3DEditor> mappedEditors = ApplicationController.Instance.Extensions.GetEditorsForType(selectedItemType); var undoBuffer = sceneContext.Scene.UndoBuffer; // put in a color edit field var colorField = new ColorField(theme, selectedItem.Color); colorField.Initialize(0); colorField.ValueChanged += (s, e) => { if (selectedItem.Color != colorField.Color) { undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color)); } }; colorField.Content.MouseDown += (s, e) => { // make sure the render mode is set to shaded or outline if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Shaded && sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Outlines) { // make sure the render mode is set to outline sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines; } }; // color row var row = new SettingsRow("Color".Localize(), null, colorField.Content, theme); // Special top border style for first item in editor row.Border = new BorderDouble(0, 1); editorPanel.AddChild(row); // put in a material edit field var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex); materialField.Initialize(0); materialField.ValueChanged += (s, e) => { if (selectedItem.MaterialIndex != materialField.MaterialIndex) { undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex)); } }; materialField.Content.MouseDown += (s, e) => { if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials) { // make sure the render mode is set to material sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Materials; } }; // material row editorPanel.AddChild( new SettingsRow("Material".Localize(), null, materialField.Content, theme)); // put in the normal editor if (selectedItem is ComponentObject3D componentObject && componentObject.Finalized) { PublicPropertyEditor.AddUnlockLinkIfRequired(selectedItem, editorPanel, theme); foreach (var selector in componentObject.SurfacedEditors) { // Get the named property via reflection // Selector example: '$.Children<CylinderObject3D>' var match = pathResolver.Select(componentObject, selector).ToList(); //// TODO: Create editor row for each property //// - Use the type of the property to find a matching editor (ideally all datatype -> editor functionality would resolve consistently) //// - Add editor row for each foreach (var instance in match) { if (instance is IObject3D object3D) { if (ApplicationController.Instance.Extensions.GetEditorsForType(object3D.GetType())?.FirstOrDefault() is IObject3DEditor editor) { ShowObjectEditor((editor, object3D, object3D.Name), selectedItem); } } else if (JsonPath.JsonPathContext.ReflectionValueSystem.LastMemberValue is ReflectionTarget reflectionTarget) { var context = new PPEContext(); if (reflectionTarget.Source is IObject3D editedChild) { context.item = editedChild; } else { context.item = item; } var editableProperty = new EditableProperty(reflectionTarget.PropertyInfo, reflectionTarget.Source); var editor = PublicPropertyEditor.CreatePropertyEditor(editableProperty, undoBuffer, context, theme); if (editor != null) { editorPanel.AddChild(editor); } } } } // Enforce panel padding foreach (var sectionWidget in editorPanel.Descendants <SectionWidget>()) { sectionWidget.Margin = 0; } }
public void SetActiveItem(ISceneContext sceneContext) { var selectedItem = sceneContext?.Scene?.SelectedItem; if (this.item == selectedItem) { return; } this.item = selectedItem; editorPanel.CloseChildren(); // Allow caller to clean up with passing null for selectedItem if (item == null) { editorSectionWidget.Text = editorTitle; return; } var selectedItemType = selectedItem.GetType(); primaryActionsPanel.RemoveChildren(); IEnumerable <SceneOperation> primaryActions; if ((primaryActions = SceneOperations.GetPrimaryOperations(selectedItemType)) == null) { primaryActions = new List <SceneOperation>(); } else { // Loop over primary actions creating a button for each foreach (var primaryAction in primaryActions) { // TODO: Run visible/enable rules on actions, conditionally add/enable as appropriate var button = new IconButton(primaryAction.Icon(theme), theme) { // Name = namedAction.Title + " Button", ToolTipText = primaryAction.Title, Margin = theme.ButtonSpacing, BackgroundColor = theme.ToolbarButtonBackground, HoverColor = theme.ToolbarButtonHover, MouseDownColor = theme.ToolbarButtonDown, }; button.Click += (s, e) => { primaryAction.Action.Invoke(sceneContext); }; primaryActionsPanel.AddChild(button); } } if (primaryActionsPanel.Children.Any()) { // add in a separator from the apply and cancel buttons primaryActionsPanel.AddChild(new ToolbarSeparator(theme.GetBorderColor(50), theme.SeparatorMargin)); } editorSectionWidget.Text = selectedItem.Name ?? selectedItemType.Name; HashSet <IObject3DEditor> mappedEditors = ApplicationController.Instance.Extensions.GetEditorsForType(selectedItemType); var undoBuffer = sceneContext.Scene.UndoBuffer; if (!(selectedItem.GetType().GetCustomAttributes(typeof(HideMeterialAndColor), true).FirstOrDefault() is HideMeterialAndColor)) { // put in a color edit field var colorField = new ColorField(theme, selectedItem.Color); colorField.Initialize(0); colorField.ValueChanged += (s, e) => { if (selectedItem.Color != colorField.Color) { undoBuffer.AddAndDo(new ChangeColor(selectedItem, colorField.Color)); } }; colorField.Content.MouseDown += (s, e) => { // make sure the render mode is set to shaded or outline if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Shaded && sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Outlines) { // make sure the render mode is set to outline sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Outlines; } }; // color row var row = new SettingsRow("Color".Localize(), null, colorField.Content, theme); // Special top border style for first item in editor row.Border = new BorderDouble(0, 1); editorPanel.AddChild(row); // put in a material edit field var materialField = new MaterialIndexField(sceneContext.Printer, theme, selectedItem.MaterialIndex); materialField.Initialize(0); materialField.ValueChanged += (s, e) => { if (selectedItem.MaterialIndex != materialField.MaterialIndex) { undoBuffer.AddAndDo(new ChangeMaterial(selectedItem, materialField.MaterialIndex)); } }; materialField.Content.MouseDown += (s, e) => { if (sceneContext.ViewState.RenderType != RenderOpenGl.RenderTypes.Materials) { // make sure the render mode is set to material sceneContext.ViewState.RenderType = RenderOpenGl.RenderTypes.Materials; } }; // material row editorPanel.AddChild( new SettingsRow("Material".Localize(), null, materialField.Content, theme)); } var rows = new SafeList <SettingsRow>(); // put in the normal editor if (selectedItem is ComponentObject3D componentObject && componentObject.Finalized) { var context = new PPEContext(); PublicPropertyEditor.AddUnlockLinkIfRequired(selectedItem, editorPanel, theme); foreach (var selector in componentObject.SurfacedEditors) { // if it is a reference to a sheet cell if (selector.StartsWith("!")) { var firtSheet = componentObject.Descendants <SheetObject3D>().FirstOrDefault(); if (firtSheet != null) { var cellId = selector.Substring(1); var cell = firtSheet.SheetData[cellId]; if (cell != null) { // add an editor for the cell var field = new DoubleField(theme); field.Initialize(0); double.TryParse(firtSheet.SheetData.EvaluateExpression(cellId), out double value); field.DoubleValue = value; field.ClearUndoHistory(); field.Content.Descendants <InternalNumberEdit>().First().MaxDecimalsPlaces = 3; field.ValueChanged += (s, e) => { cell.Expression = field.Value; firtSheet.SheetData.Recalculate(); }; var row = new SettingsRow(cell.Name == null ? cellId : cell.Name, null, field.Content, theme); editorPanel.AddChild(row); } } } else // parse it as a path to an object { // Get the named property via reflection // Selector example: '$.Children<CylinderObject3D>' var match = pathResolver.Select(componentObject, selector).ToList(); //// - Add editor row for each foreach (var instance in match) { if (instance is IObject3D object3D) { if (ApplicationController.Instance.Extensions.GetEditorsForType(object3D.GetType())?.FirstOrDefault() is IObject3DEditor editor) { ShowObjectEditor((editor, object3D, object3D.Name), selectedItem); } } else if (JsonPathContext.ReflectionValueSystem.LastMemberValue is ReflectionTarget reflectionTarget) { if (reflectionTarget.Source is IObject3D editedChild) { context.item = editedChild; } else { context.item = item; } var editableProperty = new EditableProperty(reflectionTarget.PropertyInfo, reflectionTarget.Source); var editor = PublicPropertyEditor.CreatePropertyEditor(rows, editableProperty, undoBuffer, context, theme); if (editor != null) { editorPanel.AddChild(editor); } // Init with custom 'UpdateControls' hooks (context.item as IPropertyGridModifier)?.UpdateControls(new PublicPropertyChange(context, "Update_Button")); } } } } // Enforce panel padding foreach (var sectionWidget in editorPanel.Descendants <SectionWidget>()) { sectionWidget.Margin = 0; } }