Beispiel #1
0
        public static string BrowseFile(string title, string currentDir, string filter = "all (*.*)|*.*")
        {
            var dialog = new OpenFileDialog();

            if (!string.IsNullOrEmpty(title))
            {
                dialog.Title = title;
            }
            if (!string.IsNullOrEmpty(currentDir))
            {
                dialog.InitialDirectory = currentDir;
            }
            else
            {
                dialog.InitialDirectory = CommandCanvas.GetSamplePath();
            }
            if (!string.IsNullOrEmpty(filter))
            {
                dialog.Filter = filter;
            }
            if (dialog.ShowDialog() == true)
            {
                return(dialog.FileName);
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// アセットコードでノードを作成します。
        /// </summary>
        /// <param name="assetCode">アセットコード</param>
        /// <returns>ノード</returns>
        public static MultiRootConnector CreateFunction(CommandCanvas OwnerCommandCanvas, string assetCode)
        {
            var ret = new MultiRootConnector(nameof(MultiRootConnector));

            ret.AssetFuncType      = assetCode;
            ret.AssetType          = FunctionType.FuncType;
            ret.OwnerCommandCanvas = OwnerCommandCanvas;
            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// 指定されたアセットコードに対して変数の型を選択しノードを作成します。
        /// </summary>
        /// <param name="assetCode">アセットコード</param>
        /// <param name="cbType">選択された型の格納先</param>
        /// <param name="ignoreTypes">選択除外の型を指定</param>
        /// <param name="forcedListTypeSelect">リスト型を選択するか?</param>
        /// <returns>ノード</returns>
        public static MultiRootConnector CreateFreeTypeVariableFunction(
            CommandCanvas OwnerCommandCanvas,
            string assetCode,
            List <TypeRequest> typeRequests,
            bool forcedListTypeSelect = false)
        {
            MultiRootConnector multiRootConnector = null;
            StackNode          stackNode          = null;

            return(_CreateFreeTypeVariableFunction(OwnerCommandCanvas, assetCode, typeRequests, multiRootConnector, stackNode, forcedListTypeSelect));
        }
 /// <summary>
 /// スクリプト作業領域を削除するボタンの処理です。
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DeleteButton_Click(object sender, RoutedEventArgs e)
 {
     CurrentScriptCanvas.ClearWorkCanvas();
     CanvasData.Remove(CurrentScriptCanvas);
     CurrentScriptCanvas.Dispose();
     Tab.Items.Remove(CurrentTabItem);
     if (Tab.Items.Count == 0)
     {
         CurrentScriptCanvas = null;
         RequestSetTitle();
     }
     UpdateButtonEnable();
 }
Beispiel #5
0
        private bool disposedValue = false; // 重複する呼び出しを検出するには

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    LinkConnectorControl.Dispose();
                    AssetXML?.Dispose();
                    AssetXML           = null;
                    OwnerCommandCanvas = null;
                }
                disposedValue = true;
            }
        }
Beispiel #6
0
        public static void Create(CommandCanvas OwnerCommandCanvas, string msg, IEnumerable <PlotInfo> plotInfos, double baseLine = 0)
        {
            var lines = new List <double>()
            {
                baseLine
            };

            if (OwnerCommandCanvas.PlotWindowHoldAction.Enabled)
            {
                // スクリプト実行後に一括で行う

                OwnerCommandCanvas.PlotWindowHoldAction.Add(() => Create(msg, plotInfos, lines));
                return;
            }
            Create(msg, plotInfos, lines);
        }
Beispiel #7
0
        /// <summary>
        /// グループにアセットを登録する
        /// </summary>
        /// <param name="group">登録するグループ</param>
        /// <param name="funcAssetDef">アセット</param>
        protected static void CreateAssetMenu(CommandCanvas OwnerCommandCanvas, TreeMenuNode group, IFuncCreateAssetDef funcAssetDef)
        {
            AddAsset(funcAssetDef);
            string title = TreeViewCommand.MakeGroup(ref group, funcAssetDef.MenuTitle);
            var    menu  = new TreeMenuNode(title, funcAssetDef.HelpText);

            group.AddChild(menu);
            menu.LeftClickCommand = OwnerCommandCanvas.CreateEventCanvasCommand(
                menu.Path,
                () => {
                var result = CbScript.CreateFunction(OwnerCommandCanvas, funcAssetDef.AssetCode);
                if (funcAssetDef.MenuTitle.Contains(CbSTUtils.MENU_OLD_SPECIFICATION))
                {
                    result.OldSpecification = true;
                }
                return(result);
            }
                );
        }
Beispiel #8
0
        /// <summary>
        /// グループにアセットを登録する
        /// </summary>
        /// <param name="group">登録するグループ</param>
        /// <param name="funcAssetDef">アセット</param>
        public static void CreateAssetMenu(CommandCanvas OwnerCommandCanvas, TreeMenuNode group, IFuncAssetLiteralDef funcAssetDef)
        {
            //AddAsset(funcAssetDef); 不要
            string title = TreeViewCommand.MakeGroup(ref group, funcAssetDef.MenuTitle);
            var    menu  = new TreeMenuNode(title, funcAssetDef.HelpText);

            group.AddChild(menu);
            menu.LeftClickCommand = OwnerCommandCanvas.CreateEventCanvasCommand(
                menu.Path,
                () => {
                var result = CbScript.SelectVariableType(OwnerCommandCanvas, funcAssetDef.typeRequests);
                if (funcAssetDef.MenuTitle.Contains(CbSTUtils.MENU_OLD_SPECIFICATION))
                {
                    result.OldSpecification = true;
                }
                return(result);
            }
                );
        }
Beispiel #9
0
        /// <summary>
        /// 引数の型を選択しノードを作成します。
        /// </summary>
        /// <param name="cbType">選択された型の格納先</param>
        /// <param name="ignoreTypes">選択除外の型を指定</param>
        /// <returns>ノード</returns>
        public static MultiRootConnector SelectVariableType(
            CommandCanvas OwnerCommandCanvas,
            List <TypeRequest> typeRequests = null)
        {
            var ret = new MultiRootConnector(nameof(CbScript));

            ret.OwnerCommandCanvas = OwnerCommandCanvas;
            if (typeRequests != null)
            {
                List <string> typeNames = OwnerCommandCanvas.RequestTypeName(typeRequests);
                if (typeNames is null)
                {
                    return(null);
                }
                ret.SelectedVariableTypes = typeNames.ToArray();
            }
            ret.AssetType = FunctionType.LiteralType;
            return(ret);
        }
        /// <summary>
        /// 新規スクリプト作業領域を作成します。
        /// </summary>
        private void AddNewContents()
        {
            string newName = $"New{newNumbering++}";

            CurrentScriptCanvas = CreateCanvas();
            Tab.Items.Add(
                new TabItem()
            {
                Header  = newName,
                Content = CurrentScriptCanvas
            }
                );
            if (CurrentTabIndex == -1)
            {
                CurrentTabIndex = 0;
            }
            SetupScriptCommandRecent(CurrentScriptCanvas);
            Dispatcher.BeginInvoke(new Action(() =>
            {
                // アイドル状態になって反映する

                Tab.SelectedIndex = Tab.Items.Count - 1;
            }), DispatcherPriority.ApplicationIdle);
        }
        public static StackNode Create(
            CommandCanvas OwnerCommandCanvas,
            string caption,
            ObservableCollection <StackGroup> stackList,
            bool forcedListTypeSelect,
            Point?pos = null)
        {
            ListSelectWindow selectWindow = new ListSelectWindow();

            selectWindow.Caption = caption;
            selectWindow.Owner   = CommandCanvasList.OwnerWindow;
            ControlTools.SetWindowPos(selectWindow, pos);

            if (DefaultValue != null)
            {
                selectWindow.Add("[ New ]");
            }
            List <string> teble = new List <string>();

            foreach (var node in stackList)
            {
                teble.Add(node.stackNode.ValueData.Name);

                if (DefaultValue != null)
                {
                    if (DefaultValue.TypeName != node.stackNode.ValueData.TypeName)
                    {
                        continue;
                    }
                }

                if (forcedListTypeSelect)
                {
                    if (!node.stackNode.ValueData.IsList)
                    {
                        continue;
                    }
                }

                selectWindow.Add(node.stackNode.ValueData.Name);
            }
            selectWindow.ShowDialog();
            if (selectWindow.SelectedIndex == -1)
            {
                return(null);
            }

            if (selectWindow.SelectedName == "[ New ]")
            {
                if (DefaultValue is null)
                {
                    return(null);
                }

                // 新規作成する
                DefaultValue.Name = "variable" + (OwnerCommandCanvas.ScriptWorkStack.StackData.Count + 1);
                var ret = OwnerCommandCanvas.ScriptWorkStack.Append(DefaultValue).stackNode;
                DefaultValue = null;
                return(ret);
            }
            DefaultValue = null;

            // 選ばれたアイテムの名前からインデックスを求める
            int index = teble.FindIndex((x) => x == selectWindow.SelectedName);

            return(stackList[index].stackNode);
        }
 /// <summary>
 /// カレントのスクリプト作業領域を切り替えます。
 /// </summary>
 /// <param name="index">スクリプト作業領域のインデックス番号</param>
 private void SetCurrentScriptCanvas(int index)
 {
     CurrentScriptCanvas = CanvasData[index];
     CurrentScriptCanvas.SetupTitle();
     UpdateButtonEnable();
 }
 private static void SetTargetWorkCanvasBB(CommandCanvas canvas, string path, Stretch stretch = Stretch.UniformToFill)
 {
     canvas.ScriptWorkCanvas.BGImage.Stretch = stretch;
     canvas.ScriptWorkCanvas.BGImage.Source  = new BitmapImage(new Uri(path));
 }
Beispiel #14
0
        /// <summary>
        /// 指定されたアセットコードに対してウインドウを表示して変数の型を選択しノードを作成します。
        /// </summary>
        /// <param name="assetCode">アセットコード</param>
        /// <param name="multiRootConnector">対象のMultiRootConnector</param>
        /// <param name="stackNode">変数の登録領域</param>
        /// <param name="forcedListTypeSelect">リスト型を選択するか?</param>
        /// <returns>ノード</returns>
        private static MultiRootConnector _CreateFreeTypeVariableFunction(
            CommandCanvas OwnerCommandCanvas,
            string assetCode,
            List <TypeRequest> typeRequests,
            MultiRootConnector multiRootConnector,
            StackNode stackNode,
            bool forcedListTypeSelect)
        {
            if (multiRootConnector is null)
            {
                List <string> typeNames;
                if (typeRequests == null)
                {
                    if (OwnerCommandCanvas.ScriptWorkStack.StackData.Count != 0)
                    {
                        // 既存の変数から選択する

                        stackNode = ListSelectWindow.Create(
                            OwnerCommandCanvas,
                            "Variable",
                            OwnerCommandCanvas.ScriptWorkStack.StackData,
                            forcedListTypeSelect,
                            new Point(Mouse.GetPosition(null).X, Mouse.GetPosition(null).Y));

                        if (stackNode is null)
                        {
                            return(null);
                        }

                        typeNames = new List <string>();
                        typeNames.Add(stackNode.ValueData.OriginalType.FullName);
                    }
                    else
                    {
                        // 既存の変数が存在しない

                        return(null);
                    }
                }
                else
                {
                    // 変数を新規作成する

                    typeNames = OwnerCommandCanvas.RequestTypeName(typeRequests);

                    if (typeNames is null)
                    {
                        return(null);
                    }

                    int    nameIndex = 1;
                    string name;
                    do
                    {
                        name = "variable" + nameIndex++;
                    }while (OwnerCommandCanvas.ScriptWorkStack.NameContains(name));

                    ListSelectWindow.DefaultValue = CbST.CbCreate(CbST.GetTypeEx(typeNames[0]), name);
                    stackNode = OwnerCommandCanvas.ScriptWorkStack.Append(ListSelectWindow.DefaultValue).stackNode;
                    ListSelectWindow.DefaultValue = null;
                }

                multiRootConnector = new MultiRootConnector(nameof(CbScript));
                multiRootConnector.OwnerCommandCanvas    = OwnerCommandCanvas;
                multiRootConnector.SelectedVariableTypes = typeNames.ToArray();

                multiRootConnector.AssetFuncType = assetCode;
            }

            multiRootConnector.AttachParam = new MultiRootConnector.AttachVariableId(stackNode.Id);
            multiRootConnector.AssetType   = FunctionType.FuncType;

            return(multiRootConnector);
        }
Beispiel #15
0
        /// <summary>
        /// 指定されたアセットコードに対して引数の型を選択しノードを作成します。
        /// </summary>
        /// <param name="assetCode">アセットコード</param>
        /// <param name="cbType">選択された型の格納先</param>
        /// <param name="ignoreTypes">選択除外の型を指定</param>
        /// <returns>ノード</returns>
        public static MultiRootConnector CreateFreeTypeFunction(
            CommandCanvas OwnerCommandCanvas,
            string assetCode,
            List <TypeRequest> typeRequests = null)
        {
            var ret = new MultiRootConnector(nameof(CbScript));

            ret.OwnerCommandCanvas = OwnerCommandCanvas;
            if (typeRequests != null)
            {
                // 型選択要求用のタイトルを作成する

                string methodName = assetCode;
                int    pos        = methodName.LastIndexOf(".");
                if (pos != -1 && ret.OwnerCommandCanvas.IsEqualRootConnectorValueType(methodName.Substring(0, pos)))
                {
                    // RootConnector の型と選ばれたメソッドの型が一致するなら RootConnector の型リクエスト情報をコピーする

                    ret.SelectedVariableTypes = ret.OwnerCommandCanvas.SetRootConnectorValueType(ret);
                }
                else
                {
                    string className = null;
                    if (methodName.Contains("`"))
                    {
                        className = methodName.Substring(0, methodName.IndexOf("`"));
                    }
                    if (methodName.Contains(".."))
                    {
                        methodName = methodName.Substring(methodName.LastIndexOf("..") + 1);
                    }
                    else
                    {
                        methodName = methodName.Substring(methodName.LastIndexOf(".") + 1);
                    }
                    if (methodName.Contains("#"))
                    {
                        methodName = methodName.Substring(0, methodName.IndexOf('#'));
                        string args = null;
                        foreach (var typeRequest in typeRequests)
                        {
                            if (args is null)
                            {
                                args = "<" + typeRequest.Name;
                            }
                            else
                            {
                                args += "," + typeRequest.Name;
                            }
                        }
                        methodName += args + ">";
                    }
                    else
                    {
                        methodName += "<>";  // 本来ジェネリックメソッドには引数がある筈だが、システムの提供するメソッドでそうでない場合がある
                    }
                    if (className != null)
                    {
                        methodName = className + "." + methodName;
                    }
                    List <string> typeNames = OwnerCommandCanvas.RequestTypeName(typeRequests, $"[{methodName}] ");
                    if (typeNames is null)
                    {
                        return(null);
                    }
                    ret.SelectedVariableTypes = typeNames.ToArray();
                }
            }
            ret.AssetFuncType = assetCode;
            ret.AssetType     = FunctionType.FuncType;
            return(ret);
        }