Beispiel #1
0
        public Flowsheet(FlowsheetSettings newFlowsheetSettings, FlowsheetPreferences flowsheetPrefs, ApplicationPreferences appPrefs)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.flowsheetPrefs = flowsheetPrefs;
            this.appPrefs       = appPrefs;

            DryingGas dg = DryingGasCatalog.Instance.GetDryingGas(newFlowsheetSettings.DryingGasName);

            if (dg == null)
            {
                //string message = "You need to set a drying gas in Materials / New Process Settings first!";
                //MessageBox.Show(message, "New Flowsheet Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dg = DryingGasCatalog.Instance.GetDryingGas("Air");
            }

            DryingMaterial dm = DryingMaterialCatalog.Instance.GetDryingMaterial(newFlowsheetSettings.DryingMaterialName);

            if (dm == null)
            {
                string message = "You need to choose a drying material for the new flowsheet to be created first! (go to Materials / Set Default Flowsheet Settings)";
                MessageBox.Show(message, "New Flowsheet Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.evapAndDryingSystem = new EvaporationAndDryingSystem(UI.NEW_SYSTEM, dm, dg);

            this.connectionManager = new ConnectionManager(this);
            this.customEditor      = new ProsimoUI.CustomEditor.CustomEditor(this);

            Init();
        }
Beispiel #2
0
        //public Flowsheet UnpersistFlowsheet(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, string fileName) {
        public Flowsheet UnpersistFlowsheet(string fileName, ApplicationPreferences appPrefs)
        {
            Flowsheet flowsheet = null;
            Stream    stream    = null;

            try {
                stream = new FileStream(fileName, FileMode.Open);
                SoapFormatter serializer = new SoapFormatter();
                //BinaryFormatter serializer = new BinaryFormatter();
                serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;
                ArrayList persistedItems = (ArrayList)serializer.Deserialize(stream);
                string    flowsheetName  = Path.GetFileNameWithoutExtension(fileName);
                //flowsheet = this.SetFlowsheetContent(newProcessSettings, appPrefs, items, flowsheetName);
                flowsheet = this.SetFlowsheetContent(persistedItems, flowsheetName, appPrefs);
                if (flowsheet != null)
                {
                    flowsheet.Text = fileName;
                }
            }
            catch (Exception e) {
                string message = e.ToString();
                MessageBox.Show(message, "Open Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally {
                stream.Close();
            }
            return(flowsheet);
        }
Beispiel #3
0
        private static void SetDefaultPrefs(MainForm mainForm)
        {
            FlowsheetSettings newProcessSettings = new FlowsheetSettings();

            mainForm.NewProcessSettings = newProcessSettings;
            ApplicationPreferences appPrefs = new ApplicationPreferences();

            mainForm.ApplicationPrefs = appPrefs;
        }
Beispiel #4
0
 //public UIPreferences(Point mainFormLocation, Size mainFormSize, FormWindowState mainFormWindowState, bool toolboxVisible, Point toolboxLocation) {
 public UIPreferences(MainForm mainForm)
 {
     this.mainFormLocation    = mainForm.Location;
     this.mainFormSize        = mainForm.Size;
     this.mainFormWindowState = mainForm.WindowState;
     this.toolboxVisible      = mainForm.ToolboxVisible;
     //this.toolboxLocation = toolboxLocation;
     this.newProcessSettings = mainForm.NewProcessSettings;
     this.appPrefs           = mainForm.ApplicationPrefs;
     this.flowsheetPrefs     = mainForm.FlowsheetPrefs;
 }
Beispiel #5
0
        //public virtual void SetObjectData(SerializationInfo info, StreamingContext context) {
        public override void SetObjectData()
        {
            int persistedClassVersion = info.GetInt32("ClassPersistenceVersionUIPreferences");

            this.mainFormLocation    = (Point)info.GetValue("MainFormLocation", typeof(Point));
            this.mainFormSize        = (Size)info.GetValue("MainFormSize", typeof(Size));
            this.mainFormWindowState = (FormWindowState)info.GetValue("MainFormWindowState", typeof(FormWindowState));
            this.toolboxVisible      = info.GetBoolean("ToolboxVisible");
            //this.ToolboxLocation = (Point)info.GetValue("ToolboxLocation", typeof(Point));
            this.appPrefs           = (ApplicationPreferences)RecallStorableObject("ApplicationPreferences", typeof(ApplicationPreferences));
            this.newProcessSettings = (FlowsheetSettings)RecallStorableObject("NewProcessSettings", typeof(FlowsheetSettings));
            this.flowsheetPrefs     = (FlowsheetPreferences)RecallStorableObject("FlowsheetPreferences", typeof(FlowsheetPreferences));
        }
Beispiel #6
0
        public ApplicationPreferencesForm(MainForm mainForm, ApplicationPreferences appPrefs, AppPrefsTab tab)
        {
            InitializeComponent();

            this.mainForm = mainForm;
            this.appPrefs = appPrefs;

            //
            unitSystemsCtrl = new UnitSystemsControl();
            this.tabPageUnits.Controls.Add(unitSystemsCtrl);
            unitSystemsCtrl.Location = new Point(0, 0);

            UnitSystem unitSystem = unitSystemsCtrl.GetSelectedUnitSystem();
            int        selIdx     = unitSystemsCtrl.GetSelectedIndex();

            this.buttonCurrentUnitSys.Enabled = false;
            if (selIdx >= 0)
            {
                if (unitSystem != null)
                {
                    this.buttonCurrentUnitSys.Enabled = true;
                }
            }

            UnitSystem currentUnitSystem = UnitSystemService.GetInstance().CurrentUnitSystem;

            this.labelCurrent.Text = this.CURRENT_UNIT_SYS + currentUnitSystem.Name;
            unitSystemsCtrl.SelectedUnitSystemChanged += new SelectedUnitSystemChangedEventHandler(unitSystemsCtrl_SelectedUnitSystemChanged);

            //
            this.domainUpDownDecPlaces.SelectedItem = this.appPrefs.DecimalPlaces;
            if (this.appPrefs.NumericFormat.Equals(NumericFormat.FixedPoint))
            {
                this.radioButtonFixedPoint.Checked = true;
            }
            else if (this.appPrefs.NumericFormat.Equals(NumericFormat.Scientific))
            {
                this.radioButtonScientific.Checked = true;
            }

            this.ResizeEnd += new EventHandler(ApplicationPreferencesForm_ResizeEnd);

            if (tab == AppPrefsTab.NumericFormat)
            {
                this.tabControlPrefs.SelectTab(tabPageNumberFormat);
            }
            else if (tab == AppPrefsTab.UnitSystems)
            {
                this.tabControlPrefs.SelectTab(tabPageUnits);
            }
        }
Beispiel #7
0
        public Flowsheet(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, EvaporationAndDryingSystem system)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.newProcessSettings = newProcessSettings;
            this.appPrefs           = appPrefs;

            this.MultipleSelection = false;
            SetFlowsheetActivity(FlowsheetActivity.Default);

            if (system == null)
            {
                DryingGas dg = DryingGasCatalog.GetInstance().GetDryingGas(newProcessSettings.DryingGasName);
                if (dg == null)
                {
                    //               string message = "You need to set a drying gas in Materials / New Process Settings first!";
                    //               MessageBox.Show(message, "New Flowsheet Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dg = DryingGasCatalog.GetInstance().GetDryingGas("Air");
                }

                DryingMaterial dm = DryingMaterialCatalog.GetInstance().GetDryingMaterial(newProcessSettings.DryingMaterialName);
                if (dm == null)
                {
                    string message = "You need to choose a drying material for the new flowsheet to be created first! (go to Materials / New Flowsheet Settings)";
                    MessageBox.Show(message, "New Flowsheet Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.evapAndDryingSystem = new EvaporationAndDryingSystem(UI.NEW_SYSTEM, dm, dg);
            }
            else
            {
                this.evapAndDryingSystem = system;
            }

            this.evapAndDryingSystem.SystemChanged      += new SystemChangedEventHandler(evapAndDryingSystem_SystemChanged);
            this.evapAndDryingSystem.CalculationStarted += new CalculationStartedEventHandler(evapAndDryingSystem_CalculationStarted);
            this.evapAndDryingSystem.CalculationEnded   += new CalculationEndedEventHandler(evapAndDryingSystem_CalculationEnded);
            this.evapAndDryingSystem.NameChanged        += new NameChangedEventHandler(evapAndDryingSystem_NameChanged);

            this.connectionManager = new ConnectionManager(this);
            this.customEditor      = new ProsimoUI.CustomEditor.CustomEditor(this);
            this.streamManager     = new StreamManager(this);
            this.unitOpManager     = new UnitOpManager(this);
            this.BackColor         = Color.White;
            this.Version           = new FlowsheetVersion();

            this.IsDirty = false;
        }
Beispiel #8
0
        public Flowsheet(EvaporationAndDryingSystem system, ApplicationPreferences appPrefs)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.evapAndDryingSystem = system;
            this.appPrefs            = appPrefs;

            this.connectionManager = new ConnectionManager(this);
            this.customEditor      = new ProsimoUI.CustomEditor.CustomEditor(this);

            Init();
        }
Beispiel #9
0
        //public Flowsheet UnpersistFlowsheet(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, string fileName) {
        public Flowsheet UnpersistFlowsheet(string fileName, ApplicationPreferences appPrefs)
        {
            Flowsheet flowsheet = null;

            try {
                ArrayList persistedItems = (ArrayList)UnpersistFile(fileName);
                //ArrayList persistedItems = (ArrayList)Recall(fileName);
                string flowsheetName = Path.GetFileNameWithoutExtension(fileName);
                flowsheet = this.SetFlowsheetContent(persistedItems, flowsheetName, appPrefs);
                if (flowsheet != null)
                {
                    flowsheet.Text = fileName;
                }
            }
            catch (Exception e) {
                string message = e.ToString();
                MessageBox.Show(message, "Open Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(flowsheet);
        }
Beispiel #10
0
        //private static Flowsheet UnpersistFlowsheet1_01(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, ArrayList persistedItems, string flowsheetName) {
        private static Flowsheet UnpersistFlowsheet1_01(ArrayList persistedItems, string flowsheetName, ApplicationPreferences appPrefs)
        {
            Flowsheet flowsheet = null;

            foreach (object obj in persistedItems)
            {
                if (obj is EvaporationAndDryingSystem)
                {
                    EvaporationAndDryingSystem persisted = (EvaporationAndDryingSystem)obj;
                    persisted.SetSystemFileName(flowsheetName); // call this before SetObjectData()
                    persisted.SetObjectData();
                    //flowsheet = new Flowsheet(newProcessSettings, appPrefs, persisted);
                    flowsheet = new Flowsheet(persisted, appPrefs);
                }
                else if (obj is SolvableControl)
                {
                    SolvableControl persistedCtrl = (SolvableControl)obj;

                    persistedCtrl.Flowsheet = flowsheet;
                    persistedCtrl.SetObjectData();

                    //string solvableName = (string)persistedCtrl.NameControl.Text;
                    //Solvable solvable = flowsheet.EvaporationAndDryingSystem.GetSolvable(solvableName);
                    //persistedCtrl.Solvable = solvable;
                    flowsheet.Controls.Add(persistedCtrl);
                }
                else if (obj is SolvableConnection)
                {
                    SolvableConnection persistedDc = (SolvableConnection)obj;
                    persistedDc.Flowsheet = flowsheet;
                    persistedDc.SetObjectData();
                    persistedDc.UpdateConnection();
                    flowsheet.ConnectionManager.AddConnection(persistedDc);
                }
                else if (obj is FlowsheetPreferences)
                {
                    FlowsheetPreferences flowsheetPrefs = obj as FlowsheetPreferences;
                    flowsheetPrefs.SetObjectData();
                    flowsheet.BackColor = flowsheetPrefs.BackColor;
                }
                else if (obj is ProsimoUI.CustomEditor.CustomEditor)
                {
                    ProsimoUI.CustomEditor.CustomEditor persistedEditor = (ProsimoUI.CustomEditor.CustomEditor)obj;
                    persistedEditor.Flowsheet = flowsheet;
                    persistedEditor.SetObjectData();
                }
            }
            return(flowsheet);
        }
Beispiel #11
0
        //private Flowsheet SetFlowsheetContent(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, ArrayList persistedItems, string flowsheetName) {
        private Flowsheet SetFlowsheetContent(ArrayList persistedItems, string flowsheetName, ApplicationPreferences appPrefs)
        {
            Flowsheet        flowsheet        = null;
            FlowsheetVersion flowsheetVersion = GetFlowSheetVersion(persistedItems);

            if (flowsheetVersion.Major > 1 || (flowsheetVersion.Major == 1 && flowsheetVersion.Minor > 0))
            {
                foreach (object obj in persistedItems)
                {
                    if (obj is Flowsheet)
                    {
                        flowsheet = obj as Flowsheet;
                        flowsheet.ApplicationPrefs = appPrefs;
                        //flowsheet.NewProcessSettings = newProcessSettings;
                        flowsheet.SetObjectData();
                    }
                }
            }
            else if (flowsheetVersion.Major == 1 && flowsheetVersion.Minor == 0)
            {
                //flowsheet = UnpersistFlowsheet1_01(newProcessSettings, appPrefs, persistedItems, flowsheetName);
                flowsheet = UnpersistFlowsheet1_01(persistedItems, flowsheetName, appPrefs);
            }

            FlowsheetVersionStatus flowsheetVersionStatus = CheckFlowsheetVersion(flowsheet);

            if (flowsheetVersionStatus == FlowsheetVersionStatus.Ok)
            {
                flowsheet.IsDirty = false;
            }
            else if (flowsheetVersionStatus == FlowsheetVersionStatus.Upgraded)
            {
                flowsheet.IsDirty = true;
            }
            else if (flowsheetVersionStatus == FlowsheetVersionStatus.NotOk)
            {
                flowsheet = null;
            }

            flowsheet.Version = new FlowsheetVersion();
            //if (flowsheetVersion != null) {
            //   flowsheet.Version = flowsheetVersion;
            //}

            return(flowsheet);
        }
Beispiel #12
0
        private Flowsheet SetFlowsheetContent(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, ArrayList items, string flowsheetName)
        {
            Flowsheet   flowsheet = null;
            IEnumerator e         = items.GetEnumerator();

            while (e.MoveNext())
            {
                object obj = e.Current;

                if (obj is EvaporationAndDryingSystem)
                {
                    EvaporationAndDryingSystem persisted = (EvaporationAndDryingSystem)obj;
                    persisted.SetSystemFileName(flowsheetName); // call this before SetObjectData()
                    persisted.SetObjectData();
                    flowsheet = new Flowsheet(newProcessSettings, appPrefs, persisted);
                }

                else if (obj is GasStreamControl)
                {
                    GasStreamControl persistedCtrl = (GasStreamControl)obj;
                    string           solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    DryingGasStream  stream        = flowsheet.EvaporationAndDryingSystem.GetGasStream(solvableName);
                    GasStreamControl newCtrl       = new GasStreamControl(flowsheet, new Point(0, 0), stream);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is MaterialStreamControl)
                {
                    MaterialStreamControl persistedCtrl = (MaterialStreamControl)obj;
                    string solvableName           = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    DryingMaterialStream  stream  = flowsheet.EvaporationAndDryingSystem.GetMaterialStream(solvableName);
                    MaterialStreamControl newCtrl = new MaterialStreamControl(flowsheet, new Point(0, 0), stream);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is DryerControl)
                {
                    DryerControl persistedCtrl = (DryerControl)obj;
                    string       solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Dryer        uo            = flowsheet.EvaporationAndDryingSystem.GetDryer(solvableName);
                    DryerControl newCtrl       = new DryerControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is HeatExchangerControl)
                {
                    HeatExchangerControl persistedCtrl = (HeatExchangerControl)obj;
                    string               solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    HeatExchanger        uo            = flowsheet.EvaporationAndDryingSystem.GetHeatExchanger(solvableName);
                    HeatExchangerControl newCtrl       = new HeatExchangerControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is CycloneControl)
                {
                    CycloneControl persistedCtrl = (CycloneControl)obj;
                    string         solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Cyclone        uo            = flowsheet.EvaporationAndDryingSystem.GetCyclone(solvableName);
                    CycloneControl newCtrl       = new CycloneControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is EjectorControl)
                {
                    EjectorControl persistedCtrl = (EjectorControl)obj;
                    string         solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Ejector        uo            = flowsheet.EvaporationAndDryingSystem.GetEjector(solvableName);
                    EjectorControl newCtrl       = new EjectorControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is WetScrubberControl)
                {
                    WetScrubberControl persistedCtrl = (WetScrubberControl)obj;
                    string             solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    WetScrubber        uo            = flowsheet.EvaporationAndDryingSystem.GetWetScrubber(solvableName);
                    WetScrubberControl newCtrl       = new WetScrubberControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is ScrubberCondenserControl)
                {
                    ScrubberCondenserControl persistedCtrl = (ScrubberCondenserControl)obj;
                    string                   solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    ScrubberCondenser        uo            = flowsheet.EvaporationAndDryingSystem.GetScrubberCondenser(solvableName);
                    ScrubberCondenserControl newCtrl       = new ScrubberCondenserControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is MixerControl)
                {
                    MixerControl persistedCtrl = (MixerControl)obj;
                    string       solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Mixer        uo            = flowsheet.EvaporationAndDryingSystem.GetMixer(solvableName);
                    MixerControl newCtrl       = new MixerControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is TeeControl)
                {
                    TeeControl persistedCtrl = (TeeControl)obj;
                    string     solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Tee        uo            = flowsheet.EvaporationAndDryingSystem.GetTee(solvableName);
                    TeeControl newCtrl       = new TeeControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is FlashTankControl)
                {
                    FlashTankControl persistedCtrl = (FlashTankControl)obj;
                    string           solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    FlashTank        uo            = flowsheet.EvaporationAndDryingSystem.GetFlashTank(solvableName);
                    FlashTankControl newCtrl       = new FlashTankControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is FanControl)
                {
                    FanControl persistedCtrl = (FanControl)obj;
                    string     solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Fan        uo            = flowsheet.EvaporationAndDryingSystem.GetFan(solvableName);
                    FanControl newCtrl       = new FanControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is ValveControl)
                {
                    ValveControl persistedCtrl = (ValveControl)obj;
                    string       solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Valve        uo            = flowsheet.EvaporationAndDryingSystem.GetValve(solvableName);
                    ValveControl newCtrl       = new ValveControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is BagFilterControl)
                {
                    BagFilterControl persistedCtrl = (BagFilterControl)obj;
                    string           solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    BagFilter        uo            = flowsheet.EvaporationAndDryingSystem.GetBagFilter(solvableName);
                    BagFilterControl newCtrl       = new BagFilterControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is AirFilterControl)
                {
                    AirFilterControl persistedCtrl = (AirFilterControl)obj;
                    string           solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    AirFilter        uo            = flowsheet.EvaporationAndDryingSystem.GetAirFilter(solvableName);
                    AirFilterControl newCtrl       = new AirFilterControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is CompressorControl)
                {
                    CompressorControl persistedCtrl = (CompressorControl)obj;
                    string            solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Compressor        uo            = flowsheet.EvaporationAndDryingSystem.GetCompressor(solvableName);
                    CompressorControl newCtrl       = new CompressorControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is HeaterControl)
                {
                    HeaterControl persistedCtrl = (HeaterControl)obj;
                    string        solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Heater        uo            = flowsheet.EvaporationAndDryingSystem.GetHeater(solvableName);
                    HeaterControl newCtrl       = new HeaterControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is CoolerControl)
                {
                    CoolerControl persistedCtrl = (CoolerControl)obj;
                    string        solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Cooler        uo            = flowsheet.EvaporationAndDryingSystem.GetCooler(solvableName);
                    CoolerControl newCtrl       = new CoolerControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is ElectrostaticPrecipitatorControl)
                {
                    ElectrostaticPrecipitatorControl persistedCtrl = (ElectrostaticPrecipitatorControl)obj;
                    string solvableName = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    ElectrostaticPrecipitator        uo      = flowsheet.EvaporationAndDryingSystem.GetElectrostaticPrecipitator(solvableName);
                    ElectrostaticPrecipitatorControl newCtrl = new ElectrostaticPrecipitatorControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is PumpControl)
                {
                    PumpControl persistedCtrl = (PumpControl)obj;
                    string      solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Pump        uo            = flowsheet.EvaporationAndDryingSystem.GetPump(solvableName);
                    PumpControl newCtrl       = new PumpControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is RecycleControl)
                {
                    RecycleControl persistedCtrl = (RecycleControl)obj;
                    string         solvableName  = (string)persistedCtrl.SerializationInfo.GetValue("SolvableName", typeof(string));
                    Recycle        uo            = flowsheet.EvaporationAndDryingSystem.GetRecycle(solvableName);
                    RecycleControl newCtrl       = new RecycleControl(flowsheet, new Point(0, 0), uo);
                    newCtrl.SetObjectData(persistedCtrl.SerializationInfo, persistedCtrl.StreamingContext);
                    flowsheet.Controls.Add(newCtrl);
                }
                else if (obj is SolvableConnection)
                {
                    SolvableConnection persistedDc = (SolvableConnection)obj;
                    SolvableConnection dc          = new SolvableConnection(flowsheet);
                    dc.SetObjectData(persistedDc.SerializationInfo, persistedDc.StreamingContext);
                    flowsheet.ConnectionManager.Connections.Add(dc);
                }
                else if (obj is FlowsheetPreferences)
                {
                    FlowsheetPreferences flowsheetPrefs = obj as FlowsheetPreferences;
                    flowsheetPrefs.SetObjectData(flowsheetPrefs.SerializationInfo, flowsheetPrefs.StreamingContext);
                    flowsheet.BackColor = flowsheetPrefs.BackColor;
                }
                else if (obj is ProsimoUI.CustomEditor.CustomEditor)
                {
                    ProsimoUI.CustomEditor.CustomEditor persistedEditor = (ProsimoUI.CustomEditor.CustomEditor)obj;
                    flowsheet.CustomEditor.SetObjectData(persistedEditor.SerializationInfo, persistedEditor.StreamingContext);
                }
            }

            if (this.CheckFlowsheetVersion(items, flowsheet))
            {
                flowsheet.IsDirty = false;
            }
            else
            {
                flowsheet = null;
            }

            return(flowsheet);
        }
Beispiel #13
0
        public void UnpersistAppPreferences(MainForm mainForm)
        {
            string fileName = mainForm.ExePathName + MainForm.APP_PREFS;
            Stream stream   = null;

            try
            {
                stream = new FileStream(fileName, FileMode.Open);
                SoapFormatter serializer = new SoapFormatter();
                serializer.AssemblyFormat = FormatterAssemblyStyle.Simple;
                ArrayList items = (ArrayList)serializer.Deserialize(stream);

                IEnumerator e = items.GetEnumerator();
                while (e.MoveNext())
                {
                    object obj = e.Current;

                    if (obj is UIPreferences)
                    {
                        UIPreferences uiPrefs = (UIPreferences)obj;
                        uiPrefs.SetObjectData(uiPrefs.SerializationInfo, uiPrefs.StreamingContext);
                        mainForm.Location        = uiPrefs.MainFormLocation;
                        mainForm.Size            = uiPrefs.MainFormSize;
                        mainForm.WindowState     = uiPrefs.MainFormWindowState;
                        mainForm.ToolboxVisible  = uiPrefs.ToolboxVisible;
                        mainForm.ToolboxLocation = uiPrefs.ToolboxLocation;
                    }
                    else if (obj is NewProcessSettings)
                    {
                        NewProcessSettings newProcessSettings = (NewProcessSettings)obj;
                        newProcessSettings.SetObjectData(newProcessSettings.SerializationInfo, newProcessSettings.StreamingContext);
                        if (!DryingGasCatalog.GetInstance().IsInCatalog(newProcessSettings.DryingGasName))
                        {
                            newProcessSettings.DryingGasName = DryingGasCatalog.GetInstance().GetDefaultDryingGas().Name;
                        }
                        if (!DryingMaterialCatalog.GetInstance().IsInCatalog(newProcessSettings.DryingMaterialName))
                        {
                            newProcessSettings.DryingMaterialName = DryingMaterialCatalog.GetInstance().GetDefaultDryingMaterial().Name;
                        }

                        //
                        if (newProcessSettings.DryingGasName == null || newProcessSettings.DryingGasName.Trim().Equals(""))
                        {
                            newProcessSettings.DryingGasName = "Air";
                        }
                        mainForm.NewProcessSettings = newProcessSettings;
                    }
                    else if (obj is ApplicationPreferences)
                    {
                        ApplicationPreferences appPrefs = (ApplicationPreferences)obj;
                        appPrefs.SetObjectData(appPrefs.SerializationInfo, appPrefs.StreamingContext);
                        appPrefs.InitializeCurrentUnitSystem();
                        mainForm.ApplicationPrefs = appPrefs;
                    }
                }
            }
            catch (Exception)
            {
                NewProcessSettings newProcessSettings = new NewProcessSettings();
                mainForm.NewProcessSettings = newProcessSettings;
                ApplicationPreferences appPrefs = new ApplicationPreferences();
                mainForm.ApplicationPrefs = appPrefs;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }