Beispiel #1
0
        public void LoadStockTypes(DataFeed dataFeed, List <int> stockTypeIds)
        {
            this.m_DataFeed     = dataFeed;
            this.m_StockTypeIds = stockTypeIds;

            WinFormSession sess = (WinFormSession)this.Project.Library.Session;

            this.m_FlowDiagramSheet = this.m_DataFeed.Scenario.GetDataSheet(Constants.DATASHEET_FLOW_PATHWAY_DIAGRAM_NAME);
            this.m_FlowDiagramData  = this.m_FlowDiagramSheet.GetData();

            this.m_FlowPathwaySheet = this.m_DataFeed.GetDataSheet(Constants.DATASHEET_FLOW_PATHWAY_NAME);
            this.m_FlowPathwayData  = this.m_FlowPathwaySheet.GetData();

            this.m_FlowPathwayView = (MultiRowDataFeedView)sess.CreateMultiRowDataFeedView(dataFeed.Scenario, dataFeed.Scenario);
            this.m_FlowPathwayView.LoadDataFeed(this.m_DataFeed, Constants.DATASHEET_FLOW_PATHWAY_NAME);

            this.m_FlowPathwayGrid = this.m_FlowPathwayView.GridControl;

            this.FilterFlowPathways();
            this.ConfigureContextMenus();
            this.InitializeColumnVisiblity();
            this.UpdateColumnVisibility();
            this.ConfigureColumnsReadOnly();

            this.PanelMain.Controls.Add(this.m_FlowPathwayView);
            this.m_FlowPathwayGrid.PaintGridBorders      = false;
            this.m_FlowPathwayView.ManageOptionalColumns = false;

            this.m_FlowPathwayGrid.CellBeginEdit += OnGridCellBeginEdit;
            this.m_FlowPathwayGrid.CellEndEdit   += OnGridCellEndEdit;
        }
Beispiel #2
0
        private void OpenSelectedStockTypes()
        {
            List <int>     lst   = new List <int>();
            string         title = this.CreateQuickViewTitle();
            string         tag   = this.CreateQuickViewTag();
            WinFormSession sess  = (WinFormSession)this.Project.Library.Session;

            if (sess.Application.GetView(tag) != null)
            {
                sess.Application.ActivateView(tag);
            }
            else
            {
                using (HourGlass h = new HourGlass())
                {
                    FlowPathwayDiagram d = this.GetFlowDiagram();

                    foreach (StockTypeShape s in d.SelectedShapes)
                    {
                        lst.Add(s.StockTypeId);
                    }

                    StockTypeQuickView v = (StockTypeQuickView)this.Session.CreateDataFeedView(
                        typeof(StockTypeQuickView), this.Library, this.Project, this.Scenario, null);

                    v.LoadStockTypes(this.DataFeed, lst);
                    sess.Application.HostView(v, title, tag);
                }
            }
        }
Beispiel #3
0
        private void CreateLibraryFromStrata(
            Library sourceLibrary,
            string targetFileName,
            List <int> keepStratumIds)
        {
            CreateTargetLibrary(sourceLibrary, targetFileName);

            WinFormSession      wfs = (WinFormSession)this.Session;
            string              KeepStratumIdString = CreateKeepStratumIdString(keepStratumIds);
            DataStoreConnection conn = new DataStoreConnection("SQLite", targetFileName);

            using (SyncroSimTransactionScope scope = Session.CreateTransactionScope())
            {
                using (DataStore store = Session.CreateDataStore(conn))
                {
                    DataTable AllTables = store.CreateDataTableFromQuery(
                        "SELECT name FROM sqlite_master WHERE type='table'",
                        "AllTables");

                    foreach (DataRow dr in AllTables.Rows)
                    {
                        string TableName = Convert.ToString(dr["name"]);

                        if (!ShouldProcessTable(TableName))
                        {
                            continue;
                        }

                        DataTable TableSchema = GetTableSchema(TableName, store);

                        if (TableSchema.Columns.Contains("StratumID"))
                        {
                            PurgeStratumIds(TableName, "StratumID", KeepStratumIdString, store);
                        }

                        if (TableSchema.Columns.Contains("StratumIDSource"))
                        {
                            PurgeStratumIds(TableName, "StratumIDSource", KeepStratumIdString, store);
                        }

                        if (TableSchema.Columns.Contains("StratumIDDest"))
                        {
                            PurgeStratumIds(TableName, "StratumIDDest", KeepStratumIdString, store);
                        }
                    }

                    string Title = Path.GetFileNameWithoutExtension(targetFileName);
                    string q     = string.Format(CultureInfo.InvariantCulture, "UPDATE core_Library SET Name='{0}'", Title);

                    store.ExecuteNonQuery(q);
                }

                scope.Complete();
            }
        }
Beispiel #4
0
        private void OnExecuteExportStrata(Command cmd)
        {
            ExportStrataForm f    = new ExportStrataForm();
            WinFormSession   wfs  = (WinFormSession)this.Session;
            Library          lib  = wfs.Application.GetSelectedLibrary();
            Project          Proj = GetProject(lib);

            if (Proj == null)
            {
                return;
            }

            f.Initialize(Proj);

            if (f.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                wfs.Application.BeginHourGlass();

                wfs.Application.SetStatusMessageWithEvents(
                    "Creating Library from selected strata...");

                //Create
                this.CreateLibraryFromStrata(
                    lib,
                    f.FileName,
                    f.GetSelectedStratumIds());

                //Compact
                this.Session.CompactLibrary(f.FileName);

                //Open
                wfs.Application.OpenLibrary(f.FileName);
            }
            catch (Exception ex)
            {
                string msg =
                    "Cannot create a Library.  More information:" +
                    Environment.NewLine +
                    Environment.NewLine +
                    ex.Message;

                Shared.ShowMessageBox(msg, MessageBoxButtons.OK);
            }

            finally
            {
                wfs.Application.SetStatusMessageWithEvents(null);
                wfs.Application.EndHourGlass();
            }
        }
Beispiel #5
0
        private void OnUpdateExportStrata(Command cmd)
        {
            cmd.IsEnabled = false;
            WinFormSession wfs = (WinFormSession)this.Session;
            Library        lib = wfs.Application.GetSelectedLibrary();

            if (lib != null)
            {
                string ptn = lib.GetPrimaryTransformerName();
                cmd.IsEnabled = (ptn == "landfirevegmodels_landfirevegmodels");
            }
        }
Beispiel #6
0
        public override void Configure()
        {
            base.Configure();

            Debug.Assert(
                this.Session.GetType() == typeof(Session) ||
                this.Session.GetType() == typeof(WinFormSession));

            if (typeof(WinFormSession).IsAssignableFrom(this.Session.GetType()))
            {
                WinFormSession wfs = (WinFormSession)this.Session;
                wfs.MainMenuLoaded += this.OnMainMenuLoaded;
            }
        }
Beispiel #7
0
        private void OnMainMenuLoaded(object sender, EventArgs e)
        {
            WinFormSession    wfs         = (WinFormSession)this.Session;
            CommandCollection cmds        = wfs.Application.GetMenuCommands();
            Command           EditCommand = Command.FindCommand("ssim_edit_menu", cmds);

            Debug.Assert(EditCommand != null);

            if (EditCommand != null)
            {
                EditCommand.Commands.Add(Command.CreateSeparatorCommand());

                Command LFVMExportStrataCmd = new Command(
                    "export-lfvm-strata",
                    "Export LFVM Strata",
                    OnExecuteExportStrata,
                    OnUpdateExportStrata);

                EditCommand.Commands.Add(LFVMExportStrataCmd);
            }
        }
Beispiel #8
0
        public override DataTable GetData(DataStore store, ChartDescriptor descriptor, DataSheet dataSheet)
        {
            if (ChartingUtilities.HasAgeClassUpdateTag(dataSheet.Project))
            {
                WinFormSession sess = (WinFormSession)dataSheet.Session;

                sess.SetStatusMessageWithEvents("Updating age related data...");
                dataSheet.Library.Save(store);
                sess.SetStatusMessageWithEvents(string.Empty);

                Debug.Assert(!ChartingUtilities.HasAgeClassUpdateTag(dataSheet.Project));
            }

            if (ChartingUtilities.HasTSTClassUpdateTag(dataSheet.Project))
            {
                WinFormSession sess = (WinFormSession)dataSheet.Session;

                sess.SetStatusMessageWithEvents("Updating TST related data...");
                dataSheet.Library.Save(store);
                sess.SetStatusMessageWithEvents(string.Empty);

                Debug.Assert(!ChartingUtilities.HasTSTClassUpdateTag(dataSheet.Project));
            }

            if (
                descriptor.DatasheetName == Strings.DATASHEET_OUTPUT_STRATUM_STATE_NAME ||
                descriptor.DatasheetName == Strings.DATASHEET_OUTPUT_STRATUM_TRANSITION_NAME)
            {
                if (descriptor.VariableName == Strings.STATE_CLASS_PROPORTION_VARIABLE_NAME)
                {
                    return(ChartingUtilities.CreateProportionChartData(
                               dataSheet.Scenario, descriptor, Strings.DATASHEET_OUTPUT_STRATUM_STATE_NAME, store));
                }
                else if (descriptor.VariableName == Strings.TRANSITION_PROPORTION_VARIABLE_NAME)
                {
                    return(ChartingUtilities.CreateProportionChartData(
                               dataSheet.Scenario, descriptor, Strings.DATASHEET_OUTPUT_STRATUM_TRANSITION_NAME, store));
                }
                else
                {
                    return(null);
                }
            }
            else if (
                descriptor.DatasheetName == Strings.DATASHEET_OUTPUT_STATE_ATTRIBUTE_NAME ||
                descriptor.DatasheetName == Strings.DATASHEET_OUTPUT_TRANSITION_ATTRIBUTE_NAME)
            {
                string[] s = descriptor.VariableName.Split('-');

                Debug.Assert(s.Count() == 2);
                Debug.Assert(s[0] == "stsim_AttrNormal" || s[0] == "stsim_AttrDensity");

                int    AttrId     = int.Parse(s[1], CultureInfo.InvariantCulture);
                bool   IsDensity  = (s[0] == "stsim_AttrDensity");
                string ColumnName = null;

                if (descriptor.DatasheetName == Strings.DATASHEET_OUTPUT_STATE_ATTRIBUTE_NAME)
                {
                    ColumnName = Strings.DATASHEET_STATE_ATTRIBUTE_TYPE_ID_COLUMN_NAME;
                }
                else
                {
                    ColumnName = Strings.DATASHEET_TRANSITION_ATTRIBUTE_TYPE_ID_COLUMN_NAME;
                }

                return(ChartingUtilities.CreateRawAttributeChartData(
                           dataSheet.Scenario, descriptor, dataSheet.Name, ColumnName, AttrId, IsDensity, store));
            }
            else if (descriptor.DatasheetName == Strings.OUTPUT_EXTERNAL_VARIABLE_VALUE_DATASHEET_NAME)
            {
                return(ChartingUtilities.CreateRawExternalVariableData(
                           dataSheet.Scenario, descriptor, store));
            }

            return(null);
        }