Exemplo n.º 1
0
        string getLastExcepText(MTParser parser)
        {
            string            msg = "";
            MTExcepData       e   = new MTExcepData();
            MTParserLocalizer loc = new MTParserLocalizer();

            do
            {
                parser.getLastExcep(e);
                if (e.getID() != "ok")
                {
                    string desc = "";
                    try
                    {
                        desc = loc.getExcep(e);
                    }
                    catch (Exception)
                    {
                        // No localized description available, so take the default text
                        desc = e.getDescription();
                    }

                    msg = msg + desc;
                    msg = msg + Environment.NewLine;
                }
            } while(e.getID() != "ok");

            return(msg);
        }
Exemplo n.º 2
0
        void form_load(Object _sender, EventArgs _e1)
        {
            string            str       = String.Empty;
            sMTOperator       opInfo    = new sMTOperator();
            sMTFunction       funcInfo  = new sMTFunction();
            sMTConstant       constInfo = new sMTConstant();
            int               nbOps     = 0;
            int               t         = 0;
            int               nbFuncs   = 0;
            int               nbConsts  = 0;
            MTParserLocalizer loc       = new MTParserLocalizer();
            sMTSyntax         syntax    = m_parser.getSyntax();

            nbOps = m_parser.getNbDefinedOps();
            for (t = 0; t <= nbOps - 1; t += 1)
            {
                opInfo = m_parser.getOp(t);
                try
                {
                    opInfo = loc.getOpInfo(opInfo.ID);
                }
                catch (Exception) {}

                str = opInfo.symbol + (char)(9) + opInfo.helpString + (char)(9) + opInfo.description;
                Operators.Items.Add(str);
            }
            nbFuncs = m_parser.getNbDefinedFuncs();
            for (t = 0; t <= nbFuncs - 1; t += 1)
            {
                funcInfo = m_parser.getFunc(t);
                try
                {
                    funcInfo = loc.getFuncInfo(funcInfo.ID, ref syntax);
                }
                catch (Exception) {}

                str = funcInfo.symbol + (char)(9) + funcInfo.helpString + (char)(9) + funcInfo.description;
                Functions.Items.Add(str);
            }
            nbConsts = m_parser.getNbDefinedConsts();
            for (t = 0; t <= nbConsts - 1; t += 1)
            {
                constInfo = m_parser.getConst(t);
                str       = constInfo.name + (char)(9) + constInfo.value;
                Constants.Items.Add(str);
            }
        }
Exemplo n.º 3
0
        void form_load(Object _sender, EventArgs _e1)
        {
            try
            {
                _macroDefinition.SetParser(m_parser);

                // Define the variables and keep the keys to speed up value assignations
                m_parser.defineVar(m_x as IMTVariable);
                m_parser.defineVar(m_y as IMTVariable);
                m_parser.defineVar(m_z as IMTVariable);

                // Define a shared double variable for test purpose
                MTDouble v = new MTDouble();

                v.create("v", 1.0);
                m_parser.defineVar(v as IMTVariable);
                double r = 0;

                r = m_parser.evaluate("v");

                // Change the variable's value
                v.value = 10.0;

                r = m_parser.evaluate("v");
                Console.Out.WriteLine("r = {0}", r);

                // Create another parser and copy the existing parser configuration
                MTParser p2 = new MTParser();
                p2.copy(m_parser);

                r = p2.evaluate("v");

                // the shared variable has been copied
                // Changing the shared variable's value updates all parsers using this variable
                v.value = 3.0;
                r       = p2.evaluate("v");
                r       = m_parser.evaluate("v");

                // define a constant
                m_parser.defineConst("pi", 3.14159);

                // define  a user-defined function
                m_parser.defineFunc(new MySumFunction());

                // Load localized information
                string            dir       = System.AppDomain.CurrentDomain.BaseDirectory;
                MTParserLocalizer localizer = new MTParserLocalizer();
                localizer.locale = "en";
                localizer.registerAllLibraries(dir, "*.xml");


                sMTSyntax syntax = m_parser.getSyntax();
                syntax.decimalPoint      = '.';
                syntax.argumentSeparator = ',';
                m_parser.setSyntax(ref syntax);

                // Load plug-ins
                m_parser.loadAllPlugins(dir, "*.xml");
            }
            catch (Exception)
            {
                MessageBox.Show("Error: " + getLastExcepText(m_parser), "Project1");
            }
        }
		string getLastExcepText(MTParser parser) 
		{			
			string msg = "";
			MTExcepData e = new MTExcepData();
			MTParserLocalizer loc = new MTParserLocalizer();
			
			do
			{
				parser.getLastExcep(e);
				if (e.getID() != "ok")
				{
					string desc = "";
					try
					{
						desc = loc.getExcep(e);
					}
					catch( Exception )
					{
						// No localized description available, so take the default text
						desc = e.getDescription();
					}

					msg = msg + desc;
					msg = msg + Environment.NewLine ;
				}
			} while(e.getID() != "ok");			
			
			return msg;
		}
		void form_load(Object _sender, EventArgs _e1) 
		{			
			try
			{				
				_macroDefinition.SetParser( m_parser ) ;

				// Define the variables and keep the keys to speed up value assignations
				m_parser.defineVar(m_x as IMTVariable);
				m_parser.defineVar(m_y as IMTVariable);
				m_parser.defineVar(m_z as IMTVariable);
				
				// Define a shared double variable for test purpose
				MTDouble v = new MTDouble();				

				v.create("v", 1.0);
				m_parser.defineVar(v as IMTVariable);
				double r = 0;
								
				r = m_parser.evaluate("v");
				
				// Change the variable's value
				v.value = 10.0;				

				r = m_parser.evaluate("v");
				Console.Out.WriteLine( "r = {0}", r ) ;

				// Create another parser and copy the existing parser configuration
				MTParser p2 = new MTParser();
				p2.copy(m_parser);

				r = p2.evaluate("v");				

				// the shared variable has been copied
				// Changing the shared variable's value updates all parsers using this variable
				v.value = 3.0;
				r = p2.evaluate("v");
				r = m_parser.evaluate("v");

				// define a constant
				m_parser.defineConst("pi", 3.14159);

                // define  a user-defined function
                m_parser.defineFunc(new MySumFunction());
				
				// Load localized information
				string dir = System.AppDomain.CurrentDomain.BaseDirectory;				
				MTParserLocalizer localizer = new MTParserLocalizer();
				localizer.locale = "en";				
				localizer.registerAllLibraries( dir, "*.xml");								
				

				sMTSyntax syntax = m_parser.getSyntax();				
				syntax.decimalPoint = '.';
				syntax.argumentSeparator = ',';
				m_parser.setSyntax(ref syntax);
				
				// Load plug-ins				
				m_parser.loadAllPlugins( dir, "*.xml");

              
                
				
				
			}
			catch ( Exception )
			{
				MessageBox.Show("Error: " + getLastExcepText(m_parser), "Project1");
			}
		}
		void form_load(Object _sender, EventArgs _e1) 
		{
			string str = String.Empty;
			sMTOperator opInfo = new sMTOperator();
			sMTFunction funcInfo = new sMTFunction();
			sMTConstant constInfo = new sMTConstant();
			int nbOps = 0;
			int t = 0;
			int nbFuncs = 0;
			int nbConsts = 0;
			MTParserLocalizer loc = new MTParserLocalizer();
			sMTSyntax syntax = m_parser.getSyntax();			
			
			nbOps = m_parser.getNbDefinedOps();
			for(t = 0; t <= nbOps - 1; t += 1)
			{
				opInfo = m_parser.getOp(t);
				try
				{
					opInfo = loc.getOpInfo(opInfo.ID);
				}
				catch( Exception ){}

				str = opInfo.symbol + (char)(9) + opInfo.helpString + (char)(9) + opInfo.description;
					Operators.Items.Add(str);
			}
			nbFuncs = m_parser.getNbDefinedFuncs();
			for(t = 0; t <= nbFuncs - 1; t += 1)
			{
				funcInfo = m_parser.getFunc(t);
				try
				{
					funcInfo = loc.getFuncInfo(funcInfo.ID, ref syntax);
				}
				catch( Exception ){}

				str = funcInfo.symbol + (char)(9) + funcInfo.helpString + (char)(9) + funcInfo.description;
					Functions.Items.Add(str);
			}
			nbConsts = m_parser.getNbDefinedConsts();
			for(t = 0; t <= nbConsts - 1; t += 1)
			{
				constInfo = m_parser.getConst(t);				
				str = constInfo.name + (char)(9) + constInfo.value;
					Constants.Items.Add(str);
			}
		}