public ThermodynamicSystemEditorViewModel(IEventAggregator aggregator, ThermodynamicSystemEntity source, IThermodynamicSystemImporter importer, IChartViewModelFactory chartFactory)
        {
            _aggregator   = aggregator;
            _source       = source;
            _importer     = importer;
            _chartFactory = chartFactory;
            _aggregator.Subscribe(this);
            ScriptDocument = new TextDocument(_source.SourceCode);

            var types = Enum.GetValues(typeof(EvaluatedProperties));

            foreach (var type in types.OfType <EvaluatedProperties>())
            {
                AvailableFunctionTypes.Add(type);
            }
            ParseInputFile();
        }
        public ThermodynamicSystemEditorViewModel(IEventAggregator aggregator, ThermodynamicSystem source, IThermodynamicSystemImporter importer, IChartViewModelFactory chartFactory)
        {
            _aggregator = aggregator;
            //  _source = new ThermodynamicSystemEntity(source.Name);
            CurrentSystem = source;
            _importer     = importer;
            _chartFactory = chartFactory;
            _aggregator.Subscribe(this);
            //ScriptDocument = new TextDocument(_source.SourceCode);

            var types = Enum.GetValues(typeof(EvaluatedProperties));

            foreach (var type in types.OfType <EvaluatedProperties>())
            {
                AvailableFunctionTypes.Add(type);
            }
            // ParseInputFile();
            ComponentsForPureAnalysis = CurrentSystem.Components.Select(c => new CheckableComponent()
            {
                Data = c
            }).ToList();
        }
Esempio n. 3
0
        public PythonEnvironmentModule(IEventAggregator aggregator, IEntityManagerViewModel entityManager,
                                       IThermodynamicSystemImporter importer,
                                       IChartViewModelFactory chartFactory,
                                       IFlowsheetEntityEditorFactory flowsheetFactory,
                                       IPureComponentPropertyDatabase pureDB,
                                       IThermodynamicSystemViewModelFactory thermoEditorFactory
                                       )
        {
            _aggregator          = aggregator;
            _entityManager       = entityManager;
            _importer            = importer;
            _chartFactory        = chartFactory;
            _flowsheetFactory    = flowsheetFactory;
            _pyEngine            = Python.CreateEngine();
            _pyScope             = _pyEngine.CreateScope();
            _pureComponentDB     = pureDB;
            _thermoEditorFactory = thermoEditorFactory;

            _pyScope.SetVariable("_host", this);
            _pyScope.SetVariable("Items", _entityManager);
            _pyEngine.SetSearchPaths(new List <string> {
                Environment.CurrentDirectory
            });
            var pc    = HostingHelpers.GetLanguageContext(_pyEngine) as PythonContext;
            var hooks = pc.SystemState.Get__dict__()["path_hooks"] as List;

            hooks.Clear();
            Run("import sys");
            Run("import clr");
            Run("clr.AddReferenceToFile(\"OpenFMSL.Core.dll\")");
            Run("clr.AddReferenceToFile(\"OpenFMSL.Contracts.dll\")");

            Run("from OpenFMSL.Core.Expressions import *");
            Run("from OpenFMSL.Core.Flowsheeting import *");
            Run("from OpenFMSL.Core.Flowsheeting.Documentation import *");
            Run("from OpenFMSL.Core.Numerics import *");
            Run("from OpenFMSL.Core.Numerics.Solvers import *");
            Run("from OpenFMSL.Core.UnitsOfMeasure import *");
            Run("from OpenFMSL.Core.ModelLibrary import *");
            Run("from OpenFMSL.Core.Thermodynamics import *");

            Run("from OpenFMSL.Contracts.Entities import *");
            Run("from OpenFMSL.Contracts.Infrastructure.Reporting import *");

            Run("from System import Math");
            Run("sys.stdout=_host");
            Run("runFile= _host.RunFile");
            Run("run= _host.RunEntity");
            Run("pause= _host.WaitThread");
            Run("CreateThermo= _host.LoadThermodynamicSystem");

            _pureComponentDB.SetLogCallback(Write);

            ipopt       = new IpoptSolver();
            ipopt.OnLog = (x) => Write("    " + x + Environment.NewLine);
            _pyScope.SetVariable("_ipopt", ipopt);
            _pyScope.SetVariable("Database", _pureComponentDB);

            newton              = new Newton();
            newton.OnLog        = (x) => Write("    " + x + Environment.NewLine);
            newton.OnLogDebug   = (x) => Write(x + Environment.NewLine);
            newton.OnLogError   = (x) => Write("!!! " + x + Environment.NewLine);
            newton.OnLogSuccess = (x) => Write("+++ " + x + Environment.NewLine);
            newton.OnLogWarning = (x) => Write("*** " + x + Environment.NewLine);
            newton.OnLogInfo    = (x) => Write("--- " + x + Environment.NewLine);
            _pyScope.SetVariable("_newton", newton);

            var flash = new FlashRoutines(newton);

            _pyScope.SetVariable("_flash", flash);

            decomp              = new Decomposer();
            decomp.OnLog        = (x) => Write("    " + x + Environment.NewLine);
            decomp.OnLogDebug   = (x) => Write(x + Environment.NewLine);
            decomp.OnLogError   = (x) => Write("!!! " + x + Environment.NewLine);
            decomp.OnLogSuccess = (x) => Write("+++ " + x + Environment.NewLine);
            decomp.OnLogWarning = (x) => Write("*** " + x + Environment.NewLine);
            decomp.OnLogInfo    = (x) => Write("--- " + x + Environment.NewLine);

            _pyScope.SetVariable("_decomp", decomp);

            Run("solve= _host.Solve");
            Run("decomp= _host.Decompose");
            Run("report= _host.Report");

            Run("show= _host.Show");
            Run("check= _host.Check");

            Run("info= _host.SendLogMessage");
            Run("warn= _host.SendWarningMessage");
            Run("error= _host.SendErrorMessage");

            Run("FlashPT= _flash.CalculateTP");
            Run("FlashPZ= _flash.CalculateZP");



            Run("status= _host.SendStatusTextChangeMessage");

            Run("print 'Python console running...");
        }
 public ThermodynamicSystemEditorViewModelFactory(IEventAggregator aggregator, IThermodynamicSystemImporter importer, IChartViewModelFactory chartFactory)
 {
     _aggregator   = aggregator;
     _importer     = importer;
     _chartFactory = chartFactory;
 }