using System; using System.IO; using Deltares.Geometry; using Deltares.Geotechnics; using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; using Deltares.MStab.IO.Classic; using Deltares.Stability; using Deltares.Stability.IO.WTI; using Deltares.Standard; using Deltares.Standard.EventPublisher; using Deltares.Standard.IO.Xml; namespace Deltares.MStab { public class MStabApplication { public bool isApplicationCreated = true; private ClassFactory classFactory = null; private MStabProject mStabProject = null; private ClassicMstabConvertor mstabProjectConverter = null; private IMStabReportManager mstabReportManager = null; private ProgramSettings programSettings = null; public Action ReloadModels; public MStabApplication() { classFactory = new ClassFactory(); programSettings = new ProgramSettings(); XmlHandler.RegisterHandler(new MStabXmlHandler()); XmlHandler.RegisterHandler(new StabilityXmlHandler()); } public IMStabReportManager MstabReportManager { get { return mstabReportManager; } set { mstabReportManager = value; } } public MStabProject MStabProjects { get { return mStabProject; } set { if (mStabProject != null && !ReferenceEquals(mStabProject, value)) { mStabProject.Dispose(); } mStabProject = value; Soil.SoilPropertyManager = mStabProject.Stability; } } public ClassFactory ClassFactory { get { return classFactory; } set { classFactory = value; } } public ClassicMstabConvertor MStabProjectConverter { get { return mstabProjectConverter; } set { mstabProjectConverter = value; } } public ProgramSettings ProgramSettings { get { return programSettings; } } ///// ///// updates the license information to the license manager from Flexlm ///// //public void UpdateLicenseManager() //{ // // License info is to be provided by Flexlm but for now custom info is provided // LicenseManager.Instance.ClearLicenseInfo(); // LicenseManager.Instance.ProvideLicense(LicenseProduct.MStab, LicenseStabilityModule.MStab, license.Full, new Version("10.0.0")); // LicenseManager.Instance.ProvideLicense(LicenseProduct.MStab, LicenseStabilityModule.SpencerModule, license.Full, new Version("10.0.0")); // LicenseManager.Instance.ProvideLicense(LicenseProduct.MStab, LicenseStabilityModule.UpliftVanModule, license.Full, new Version("10.0.0")); // LicenseManager.Instance.ProvideLicense(LicenseProduct.MStab, LicenseStabilityModule.ProbabilisticRandomFieldModule, license.Full, new Version("10.0.0")); // LicenseManager.Instance.ProvideLicense(LicenseProduct.MStab, LicenseStabilityModule.ReliabiltyAnalysesModule, license.Full, new Version("10.0.0")); // LicenseManager.Instance.ProvideLicense(LicenseProduct.MStab, LicenseStabilityModule.EvaluationMode, license.Full, new Version("10.0.0")); //} public object NewProject() { DataEventPublisher.InvokeWithoutPublishingEvents(() => { mStabProject = new MStabProject(); mStabProject.CreateDefaultLibraryData(); MStabProjects = mStabProject; DataEventPublisher.SelectionChanged(null); // TODO: Does this make sense? }); ReloadModels(); return mStabProject; } public void SaveStabProject(string aFileName, object project) { DataEventPublisher.InvokeWithoutPublishingEvents(() => { TransformerManager.UseTransformer = false; var xmlSerializer = new XmlSerializer(); var l = new FileInfo(aFileName); if (l.Extension.ToLower() == ".dsx") { xmlSerializer.Serialize(project, aFileName, AppDomain.CurrentDomain.BaseDirectory + "Mstab.xsl"); } else if (l.Extension.ToLower() == ".locx") { StabilityDikeLocationInfo dikeLocationInfo = GetStabilityDikeLocationInfo(MStabProjects.Stability); xmlSerializer.Serialize(dikeLocationInfo, aFileName); } else if (l.Extension.ToLower() == ".wti") { File.WriteAllText(aFileName, WTISerializer.Serialize(MStabProjects.Stability, true)); } TransformerManager.UseTransformer = true; }); } public object OpenStabProject(string aFileName) { //IMstabViewSettings previousMstabViewSettings = this.MStabProjects.MStabViewSettings; DataEventPublisher.InvokeWithoutPublishingEvents(() => { try { var l = new FileInfo(aFileName); if (l.Extension == ".sti") { MStabProjects = new MStabProject(); MStabProjects.SetStabilityModel((StabilityModel)mstabProjectConverter.ConvertProject(aFileName)); } else if (l.Extension == ".dsx") { var xmlDeserializer = new XmlDeserializer(); MStabProjects = (MStabProject)xmlDeserializer.XmlDeserialize(aFileName, typeof(MStabProject), classFactory); } else if (l.Extension == ".locx") { var xmlDeserializer = new XmlDeserializer(); StabilityDikeLocationInfo deserialized = (StabilityDikeLocationInfo)xmlDeserializer.XmlDeserialize(aFileName, typeof(StabilityDikeLocationInfo), classFactory); MStabProjects = new MStabProject(); StabilityModel model = deserialized.StabilityModel; if (deserialized.SoilSurfaceProfile2D != null) { model.SoilProfile = deserialized.SoilSurfaceProfile2D.SoilProfile2D; } MStabProjects.SetStabilityModel(model); } else if (l.Extension == ".wti") { StabilityModel model = WTIDeserializer.Deserialize(File.ReadAllText(aFileName), true); model.CalculationModel = CalculationModel.WBI; MStabProjects = new MStabProject(); MStabProjects.SetStabilityModel(model); } else { throw new InvalidDataException("File not supported"); } ReloadModels(); UpdateModelObjects(); } catch { //TODO } }); return MStabProjects; } public StabilityDikeLocationInfo GetStabilityDikeLocationInfo(StabilityModel stabilityModel) { StabilityDikeLocationInfo dikeLocationInfo = new StabilityDikeLocationInfo(); dikeLocationInfo.StabilityModel = stabilityModel; dikeLocationInfo.SchematizedSurfaceLine = stabilityModel.SurfaceLine2; dikeLocationInfo.SurfaceLine = stabilityModel.SurfaceLine2.Geometry; dikeLocationInfo.SoilProfile2D = stabilityModel.SoilProfile; dikeLocationInfo.PiezometricHeads = stabilityModel.Location.PiezometricHeads; dikeLocationInfo.Settings.CreateZones = stabilityModel.SlipPlaneConstraints.CreateZones; dikeLocationInfo.Settings.MaximumSlideWidth = stabilityModel.MaximumSliceWidth; dikeLocationInfo.Settings.MinimalPlaneDepth = stabilityModel.SlipPlaneConstraints.SlipPlaneMinDepth; dikeLocationInfo.Settings.MinimalCircleLength = stabilityModel.SlipPlaneConstraints.SlipPlaneMinLength; dikeLocationInfo.Settings.MaxAllowedAngleBetweenSlices = stabilityModel.MaxAllowedAngleBetweenSlices; dikeLocationInfo.Settings.RequiredForcePointsInSlices = stabilityModel.RequiredForcePointsInSlices; dikeLocationInfo.Settings.PreconsolidationStressFactor = stabilityModel.PreconsolidationStressModelFactor; dikeLocationInfo.Settings.ModelUncertaintyParameterStochast.Assign(stabilityModel.ModelUncertaintyParameterStochast); return dikeLocationInfo; } public void UpdateModelObjects() { //Populating the Soil groups mStabProject.Geometry.SetupCurveSurfaceAssociations(); DataEventPublisher.IsDataEventPublishStopped = false; mStabProject.UpdateCounters(); DataEventPublisher.SelectionChanged(null); } #region IGeometryPresenter Members public GeometryData Geometry { get { return MStabProjects.Geometry; } } #endregion } }