private void cmbFunction_SelectedIndexChanged(object sender, EventArgs e)
        {
            IronPython.Runtime.PythonFunction pf =
                (IronPython.Runtime.PythonFunction)AppGlobals.PyGetVar(cmbFunction.SelectedItem.ToString());
            lstInputs.Items.Clear();
            if (pf.__doc__ != null)
            {
                lblDesc.Text = "Description: \n" + pf.__doc__.ToString();
            }
            else
            {
                lblDesc.Text = "Description: N/A";
            }
            int var_count = 0;

            foreach (var item in pf.func_code.co_varnames)
            {
                lstInputs.Items.Add(item.ToString());
                var_count++;
                if (var_count >= pf.func_code.co_argcount)
                {
                    break;
                }
            }
        }
Example #2
0
        void tentry_Click(object sender, EventArgs e)
        {
            ModelDesignerWindow mdlWin = new ModelDesignerWindow();

            mdlWin.OpenFileByPath(System.IO.Path.Combine("./core/samples/", ((ToolStripItem)sender).Text), true);
            AppGlobals.ShowWin(mdlWin, WeifenLuo.WinFormsUI.Docking.DockState.Document);
        }
Example #3
0
 public override void Execute(EventDescription token)
 {
     if (this.LastEvent != token)
     {
         OutputNodes[0].Object = AppGlobals.PyExecuteExpr(Code);
     }
 }
Example #4
0
 private void mainForm_Load(object sender, EventArgs e)
 {
     if (System.IO.Directory.Exists("./core/samples"))
     {
         string[] files = System.IO.Directory.GetFiles("./core/samples", "*.emdl", System.IO.SearchOption.AllDirectories);
         foreach (var file in files)
         {
             System.IO.FileInfo fi = new System.IO.FileInfo(file);
             var tentry            = samplesToolStripMenuItem.DropDownItems.Add(fi.Name);
             tentry.Click += tentry_Click;
         }
     }
     if (AppGlobals.args.Count() > 0)
     {
         for (int i = 0; i < AppGlobals.args.Count(); i++)
         {
             string arg = AppGlobals.args[i];
             if (System.IO.File.Exists(arg))
             {
                 ModelDesignerWindow designerWin = new ModelDesignerWindow();
                 designerWin.Show(masterDockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document);
                 designerWin.OpenFileByPath(arg);
             }
         }
     }
     AppGlobals.ShowGenericResults();
 }
Example #5
0
        private void selectWord()
        {
            try
            {
                int cursorPosition = this.SelectionStart - 1;
                if (cursorPosition >= 0)
                {
                    int    nextSpace      = this.Text.IndexOf(' ', cursorPosition);
                    int    selectionStart = 0;
                    string trimmedString  = string.Empty;
                    if (nextSpace != -1)
                    {
                        trimmedString = this.Text.Substring(0, nextSpace);
                    }
                    else
                    {
                        trimmedString = this.Text;//.Substring(cursorPosition);
                    }


                    if (trimmedString.LastIndexOf(' ') != -1)
                    {
                        selectionStart = 1 + trimmedString.LastIndexOf(' ');
                        trimmedString  = trimmedString.Substring(1 + trimmedString.LastIndexOf(' '));
                    }
                    _selWord = trimmedString;
                }
            } catch (Exception ex)
            {
                Logger.D(AppGlobals.PyGetTraceback(ex));
            }
        }
Example #6
0
        public static String GetOrbImagePathFromType(AppGlobals.Types orbType)
        {
            if (orbType == null)
            {
                return "";
            }

            var type = orbType.ToString();
            return "Assets/Orbs/" + type + "Orb.png";
        }
Example #7
0
        public static String GetProfileBorderImagePathFromType(AppGlobals.Types profileType)
        {
            if (profileType == null)
            {
                return "";
            }

            var type = profileType.ToString();
            return "Assets/ProfileBorders/" + type + ".png";
        }
Example #8
0
        public static void Main()
        {
            // Enable nice styles in XP/Vista/7.
            Application.EnableVisualStyles();

            // Store title which can be shown in all message boxes etc.
            AppGlobals.AppName = $"{Application.ProductName} {AppGlobals.AppVersion()}";

            // Test for existence of database.
            bool   databaseExists = false;
            string databasePath   = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\RoadMusic\\RoadMusic.db";

            // Set database connection string across whole app.
            DatabaseSettings.DatabasePath     = databasePath;
            DatabaseSettings.ConnectionString = $"Data Source={databasePath}";

            // If database not found...
            if (!File.Exists(databasePath))
            {
                // Try to create a blank database.
                try
                {
                    DbCreate.CreateDatabase(databasePath);

                    // Database now exists.
                    databaseExists = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}  The program cannot start.", AppGlobals.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                // Database already exists.
                databaseExists = true;
            }

            // Only start the app if the database exists...
            if (databaseExists)
            {
                // Set where registry access happens across whole app.
                RegistryAccess.SetSoftwareKey($"Software\\{Application.ProductName}");

                // Show the main form.
                try
                {
                    Application.Run(new MainForm());
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Sorry, a fatal error occurred : {ex.Message}", AppGlobals.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #9
0
        public override void Execute(EventDescription e)
        {
            var obj = InputNodes[0].Object;

            if (obj == null)
            {
                obj = "null";
            }
            string outp = this.ID + "<Sink> Received: " + obj.ToString();

            Logger.D(outp);
            AppGlobals.WriteResults(outp);
        }
Example #10
0
 public static object Parse(string expr, string hint)
 {
     try
     {
         object result = AppGlobals.PyExecuteExpr(expr);
         return(result);
     } catch (Exception ex)
     {
         string    msg = "Error while evaluating `" + hint + "` (" + ex.Message + ")";
         Exception tmp = (Exception)Activator.CreateInstance(ex.GetType(), msg);
         throw tmp;
     }
 }
Example #11
0
 public override void Execute(Blocks.EventDescription e)
 {
     if (InputNodes[0].ConnectingNode != null)
     {
         var obj = InputNodes[0].Object;
         if (Utils.IsArrayOf <OpenSignalLib.ComplexTypes.Complex>(obj))
         {
             OpenSignalLib.ComplexTypes.Complex[] fft = (OpenSignalLib.ComplexTypes.Complex[])obj;
             var vals = OpenSignalLib.Transforms.Fourier.iFFT(fft,
                                                              int.Parse(AppGlobals.PyExecuteExpr(N).ToString()));
             OutputNodes[0].Object = Utils.GetAbsolute(vals);
         }
     }
 }
Example #12
0
 public override void Execute(Blocks.EventDescription e)
 {
     IronPython.Runtime.PythonFunction fun = (IronPython.Runtime.PythonFunction)AppGlobals.PyVarGetFunc(pf);
     if (fun != null)
     {
         object[] args = new object[InputNodes.Count];
         for (int i = 0; i < InputNodes.Count; i++)
         {
             args[i] = InputNodes[i].Object;
         }
         object result = AppGlobals.InvokeFunction(fun, args);
         OutputNodes[0].Object = result;
     }
 }
        public PythonFunctionAsBlockConfigWindow()
        {
            InitializeComponent();
            var names = AppGlobals.PyGetVarNames();

            foreach (var name in names)
            {
                if (AppGlobals.IsFunction(name))
                {
                    cmbFunction.Items.Add(name);
                }
            }
            cmbFunction.SelectedIndex = 0;
        }
Example #14
0
        public override void Execute(EventDescription token)
        {
            if (code == "")
            {
                code = "None";
            }
            for (int i = 0; i < input_count; i++)
            {
                AppGlobals.PySetVar("in" + (i + 1).ToString(), InputNodes[i].Object);
            }
            object result = null;

            AppGlobals.PyExecute(code, Microsoft.Scripting.SourceCodeKind.Statements);
            for (int i = 0; i < output_count; i++)
            {
                var name = "out" + (i + 1).ToString();
                if (AppGlobals.PyVarExists(name))
                {
                    result = AppGlobals.PyGetVar(name);
                    if (result.GetType() == typeof(IronPython.Runtime.List))
                    {
                        IronPython.Runtime.List lst = (IronPython.Runtime.List)result;
                        //var tmp = new List<object>();
                        //foreach (var item in lst)
                        //{
                        //    tmp.Add(item);
                        //}
                        result = lst;// tmp.ToArray();
                    }
                    var tmp = PyToNET(result);
                    if (tmp != null)
                    {
                        OutputNodes[i].Object = (double[])tmp;
                    }
                    else
                    {
                        OutputNodes[i].Object = result;
                    }
                }
                AppGlobals.PyRemVar(name);
            }
            for (int i = 0; i < input_count; i++)
            {
                AppGlobals.PyRemVar("in" + (i + 1).ToString());
            }
        }
Example #15
0
        //TODO: I think these Repository methods should be static
        public virtual IQueryable <T> FindAll(bool returnsIQueryable)
        {
            try
            {
                var query =
                    from u in SessionProxy.Query <T>()
                    select u;

                return(query);
            }
            catch (Exception ex)
            {
                DiscardCurrentSession();
                string errorMessage = BuildErrorMessage(ex);
                AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace);
                return(null);
            }
        }
Example #16
0
        //TODO: I think these Repository methods should be static
        public virtual int CountOfElements()
        {
            try
            {
                var count =
                    (from u in SessionProxy.Query <T>()
                     select u).Count();

                return(count);
            }
            catch (Exception ex)
            {
                DiscardCurrentSession();
                string errorMessage = BuildErrorMessage(ex);
                AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace);
                return(-1);
            }
        }
Example #17
0
 public override void Execute(Blocks.EventDescription e)
 {
     if (InputNodes[0].ConnectingNode != null)
     {
         double[] x, y;
         var      obj = InputNodes[0].Object;
         if (Utils.IsSignal(obj))
         {
             OpenSignalLib.Sources.Signal s = Utils.AsSignal(obj);
             Logger.D(s.SamplingRate.ToString());
             int n        = int.Parse(AppGlobals.PyExecuteExpr(N).ToString());
             var spectrum = OpenSignalLib.Transforms.Fourier.fspectrum(s, n);
             x = spectrum.Keys.ToArray();
             y = spectrum.Values.ToArray();
         }
         else
         {
             throw new Exception("invalid input type : " + obj.GetType().Name);
         }
         if (!Hold || (plotControl.Window == null || plotControl.Window.IsDisposed))
         {
             _createPlot(x, y);
         }
         if (Hold)
         {
             plotControl.Curve.Clear();
             for (int i = 0; i < x.Length; i++)
             {
                 if (Scale == Scales.dB_Scale)
                 {
                     plotControl.Curve.AddPoint(x[i], 10 * Math.Log10(y[i]));
                 }
                 else
                 {
                     plotControl.Curve.AddPoint(x[i], y[i]);
                 }
             }
             plotControl.Control.AxisChange();
             plotControl.Control.Invalidate();
         }
     }
 }
Example #18
0
 public virtual bool Delete(T theEntity)
 {
     using (var transaction = sessionProxy.BeginTransaction())
     {
         try
         {
             sessionProxy.Delete(theEntity);
             transaction.Commit();
             return(true);
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             DiscardCurrentSession();
             string errorMessage = BuildErrorMessage(ex);
             AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace);
             return(false);
         }
     }
 }
Example #19
0
        private void mainForm_MdiChildActivate(object sender, EventArgs e)
        {
            var child = this.ActiveMdiChild;

            if (child != null)
            {
                if (child.GetType() == typeof(ModelDesignerWindow))
                {
                    AppGlobals.CurrentDesigner = (ModelDesignerWindow)child;
                    AppGlobals.ShowBlocksetBrowser();
                    undoToolStripMenuItem.Enabled = true;
                    redoToolStripMenuItem.Enabled = true;
                }
                else
                {
                    undoToolStripMenuItem.Enabled = false;
                    redoToolStripMenuItem.Enabled = false;
                }
            }
        }
Example #20
0
 protected virtual void DiscardCurrentSession()
 {
     if (sessionProxy != null)
     {
         //Try flushing the session
         try
         {
             sessionProxy.Flush();
         }
         catch (Exception ex)
         {
             string errorMessage = BuildErrorMessage(ex);
             AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace);
         }
         finally
         {
             sessionProxy.Close();
             sessionProxy = null;
         }
     }
 }
Example #21
0
 static void Main(string[] args)
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     try
     {
         SplashScreen.SplashScreen.ShowSplashScreen();
         Application.DoEvents();
         SplashScreen.SplashScreen.SetStatus("loading python modules...");
         AppGlobals.PyInit();
         AppGlobals.args = args;
         SplashScreen.SplashScreen.SetStatus("loading blockset...");
         string dir = (new System.IO.FileInfo(Application.ExecutablePath).Directory.FullName);
         AppGlobals.LoadBlockset(dir);
         AppGlobals.LoadBlockset();
     } catch (Exception ex)
     {
         MessageBox.Show("Critical error occured (Err: " + ex.Message + ")");
     }
     Application.Run(new mainForm());
 }
Example #22
0
 public override void Execute(Blocks.EventDescription e)
 {
     if (InputNodes[0].ConnectingNode != null)
     {
         double[] values = new double[0];
         if (Utils.IsSignal(InputNodes[0].Object))
         {
             values = Utils.AsSignal(InputNodes[0].Object).Samples;
         }
         var vals = OpenSignalLib.Transforms.Fourier.FFT(values,
                                                         int.Parse(AppGlobals.PyExecuteExpr(N).ToString()));
         if (OutputAbsoluteValues)
         {
             double[] vec = Utils.GetAbsolute(vals);
             OutputNodes[0].Object = vec;
         }
         else
         {
             OutputNodes[0].Object = vals;
         }
     }
 }
Example #23
0
        public Hero(string heroName, 
                    int hitPointsPerLevel, 
                    int healingPerLevel,
                    int attackDamagePerLevel, 
                    AppGlobals.Types type,
                    int baseExpPerLevel,
                    int maxLevel)
        {
            CurrentExp = 0;
            Id = Guid.NewGuid();
            Name = heroName;
            Type = type;

            MaxLevel = maxLevel;
            BaseExpPerLevel = baseExpPerLevel;
            _levelCalculator = new HeroLevelCalculator();
            _hitPointsPerLevel = hitPointsPerLevel;
            _attackDamagePerLevel = attackDamagePerLevel;
            _healingPerLevel = healingPerLevel;

            FullImagePath = AppGlobals.HeroImagePathPrefix + heroName + "/" + heroName + "Full.png";
            ProfileImagePath = AppGlobals.HeroImagePathPrefix + heroName + "/" + heroName + "Profile.png";
        }
Example #24
0
        public override void OnClick(SourceGrid.CellContext sender, EventArgs e)
        {
            base.OnClick(sender, e);

            // 顯示目前焦點所在的儲存格屬於第幾頁。
            SourceGrid.Grid grid = (SourceGrid.Grid)sender.Grid;
            int             row  = sender.Position.Row;

            if (row < 1)
            {
                return;
            }

            int  lineIdx      = m_Form.GetBrailleLineIndex(row);
            int  linesPerPage = AppGlobals.Config.Braille.LinesPerPage;
            bool needPageFoot = AppGlobals.Config.Printing.PrintPageFoot;
            int  currPage     = AppGlobals.CalcCurrentPage(lineIdx, linesPerPage, needPageFoot) + 1;
            int  totalPages   = AppGlobals.CalcTotalPages(m_Form.BrailleDoc.Lines.Count, linesPerPage, needPageFoot);

            m_Form.PageNumberText = currPage.ToString() + "/" + totalPages.ToString();


            //if (m_Form.DebugMode)
            //{
            //    SourceGrid.Grid grid = (SourceGrid.Grid)sender.Grid;
            //    int row = sender.Position.Row;
            //    int col = sender.Position.Column;

            //    BrailleWord brWord = (BrailleWord)grid[row, col].Tag;
            //    string brScreenText = brWord.CellList.ToString();
            //    string brPrinterText = BrailleGlobals.FontConvert.ToString(brWord);

            //    m_Form.StatusBar.Items[0].Text = brWord.Text +
            //        "(" + brScreenText + ") " + // 顯示時的點字 16 進位字串
            //        "[" + brPrinterText + "]";  // 列印時的點字 16 進位字串
            //}
        }
        /// <summary>
        /// 在執行列印前必須進行的初始化參數工作。明眼字及點字於列印之前都必須呼叫此方法。
        /// </summary>
        private void InitializePrintParameters()
        {
            m_TotalPages = AppGlobals.CalcTotalPages(m_BrDoc.Lines.Count, m_PrintOptions.LinesPerPage, m_PrintOptions.PrintPageFoot);

            if (m_PrintOptions.AllPages)    // 列印全部?
            {
                m_PrintOptions.FromPage = 1;
                m_PrintOptions.ToPage   = m_TotalPages;
                m_PageNum = 0;
            }
            else
            {
                // 只列印特定頁次範圍
                m_PageNum = m_PrintOptions.FromPage - 1;

                // 修正終止頁次
                if (m_PrintOptions.ToPage > m_TotalPages)
                {
                    m_PrintOptions.ToPage = m_TotalPages;
                }
            }

            // 起始頁碼
            if (m_PrintOptions.ReassignStartPageNumber)
            {
                m_DisplayedPageNum = m_PrintOptions.StartPageNumber;
            }
            else
            {
                m_DisplayedPageNum = m_PageNum + 1;
            }

            m_BeginOrgPageNumber = -1; // -1 表示沒有指定原書頁碼。
            m_EndOrgPageNumber   = -1; // -1 表示沒有指定原書頁碼。

            m_PrintedPageCount = 0;
        }
Example #26
0
        public static PlotControl Plot(string title, double[] x, double[] y, bool ShowPlot = true, bool useDockableWindow = true)
        {
            System.Windows.Forms.Form win = new System.Windows.Forms.Form();
            if (useDockableWindow)
            {
                win = new PlotterWindowDockable();
            }
            win.Text = title;
            ZedGraph.ZedGraphControl zed = new ZedGraph.ZedGraphControl();
            zed.Dock = System.Windows.Forms.DockStyle.Fill;
            win.Controls.Add(zed);
            GraphPane     cPane = zed.GraphPane;
            PointPairList lst   = new PointPairList(x, y);
            LineItem      curve = cPane.AddCurve(title, lst, Color.Blue);

            cPane.Title.Text  = title;
            curve.Symbol.Type = SymbolType.None;
            if (ShowPlot)
            {
                if (useDockableWindow)
                {
                    var w = (PlotterWindowDockable)win;
                    AppGlobals.ShowWin(w, WeifenLuo.WinFormsUI.Docking.DockState.Float);
                }
                else
                {
                    win.Show();
                }
            }
            PlotControl p = new PlotControl();

            p.Curve   = curve;
            p.Control = zed;
            p.Window  = win;
            p.Points  = lst;
            return(p);
        }
Example #27
0
        //TODO: I think these Repository methods should be static
        public virtual IList <T> FindAll()
        {
            try
            {
                //OMM: I use this dirty hack to generate DDL statement then comment out the two lines of code
                //Risky Affair: If you forget to comment them out you will overwrite the database.
                //ISession session = DigitizingDataDomain.Helpers.NHibernateHelper.OpenSessionForDdl();
                //session = null;

                var query =
                    from u in SessionProxy.Query <T>()
                    select u;

                return(query.ToList());
            }
            catch (Exception ex)
            {
                DiscardCurrentSession();
                string errorMessage = BuildErrorMessage(ex);
                AppGlobals.LogToFileServer(AppGlobals.LOG_FOLDER_SERVER, errorMessage + Environment.NewLine + ex.StackTrace);

                return(new List <T>());
            }
        }
 /// <summary>
 /// Form load.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AboutForm_Load(object sender, EventArgs e)
 {
     Icon            = AppGlobals.ImgLib.GetIcon(AppGlobals.ImgLib.GetImageIndex(AppIcons.Music));
     lblVersion.Text = $"Version: {AppGlobals.AppVersion()}";
 }
 private BitmapImage GetOrbImageFromType(AppGlobals.Types type)
 {
     var imagePath = ImageUtils.GetOrbImagePathFromType(type);
     return ImageUtils.GetImageSourceFromPath("/" + imagePath);
 }
Example #30
0
 protected override void OnStartup(StartupEventArgs e)
 {
     AppGlobals.Init();
     base.OnStartup(e);
 }
 private int GetDamage(List<Hero> team, AppGlobals.Types type)
 {
     var heroesOfType = team.Where(h => h.Type == type);
     return heroesOfType.Sum(h => h.AttackDamage);
 }
 private string GetDamageMessage(List<Hero> team, AppGlobals.Types type)
 {
     return "Will deal " + GetDamage(team, type) + " damage";
 }
Example #33
0
 public OrbMatch(AppGlobals.Types type, int count, bool hasHorizontalMatch)
 {
     Type = type;
     Count = count;
     HasHorizontalMatch = hasHorizontalMatch;
 }
Example #34
0
 private void resultsWindowToolStripMenuItem_Click(object sender, EventArgs e)
 {
     AppGlobals.ShowGenericResults();
 }
Example #35
0
 private void propertyInspectorToolStripMenuItem_Click(object sender, EventArgs e)
 {
     AppGlobals.ShowProperties(null);
 }
Example #36
0
 private void blocksetWindowToolStripMenuItem_Click(object sender, EventArgs e)
 {
     AppGlobals.ShowBlocksetBrowser();
 }
Example #37
0
 public override void Execute(Blocks.EventDescription e)
 {
     OutputNodes[0].Object = AppGlobals.PyExecuteExpr(Value);
 }