public Flowsheet(NewProcessSettings newProcessSettings, FlowsheetPreferences flowsheetPrefs, ApplicationPreferences appPrefs) { // // Required for Windows Form Designer support // InitializeComponent(); this.flowsheetPrefs = flowsheetPrefs; this.appPrefs = appPrefs; 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); this.connectionManager = new ConnectionManager(this); this.customEditor = new ProsimoUI.CustomEditor.CustomEditor(this); Init(); }
public Flowsheet UnpersistFlowsheet(NewProcessSettings newProcessSettings, ApplicationPreferences appPrefs, string fileName) { Flowsheet flowsheet = null; Stream stream = null; try { stream = new FileStream(fileName, FileMode.Open); SoapFormatter serializer = new SoapFormatter(); serializer.AssemblyFormat = FormatterAssemblyStyle.Simple; ArrayList items = (ArrayList)serializer.Deserialize(stream); string flowsheetName = Path.GetFileNameWithoutExtension(fileName); flowsheet = this.SetFlowsheetContent(newProcessSettings, appPrefs, items, flowsheetName); 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); }
private static void SetDefaultPrefs(MainForm mainForm) { NewProcessSettings newProcessSettings = new NewProcessSettings(); mainForm.NewProcessSettings = newProcessSettings; ApplicationPreferences appPrefs = new ApplicationPreferences(); mainForm.ApplicationPrefs = appPrefs; }
//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; }
//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 = (NewProcessSettings)RecallStorableObject("NewProcessSettings", typeof(NewProcessSettings)); this.flowsheetPrefs = (FlowsheetPreferences)RecallStorableObject("FlowsheetPreferences", typeof(FlowsheetPreferences)); }
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; }
public NewProcessSettingsForm(MainForm mainForm, NewProcessSettings newProcessSettings) { // // Required for Windows Form Designer support // InitializeComponent(); this.mainForm = mainForm; this.newProcessSettings = newProcessSettings; this.dryingGasesControl.ListViewGases.MultiSelect = false; this.dryingMaterialsControl.ListViewMaterials.MultiSelect = false; this.dryingGasesControl.SelectDryingGas(this.newProcessSettings.DryingGasName); this.dryingMaterialsControl.SelectDryingMaterial(this.newProcessSettings.DryingMaterialName); this.textBoxDryingGas.Text = this.newProcessSettings.DryingGasName; this.textBoxDryingMaterial.Text = this.newProcessSettings.DryingMaterialName; this.ResizeEnd += new EventHandler(NewProcessSettingsForm_ResizeEnd); }
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); }
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(); } } }