コード例 #1
0
ファイル: PropertyPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The model to connect to</param>
        /// <param name="view">The view to connect to</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            // if the model is Testable, run the test method.
            ITestable testModel = model as ITestable;
            if (testModel != null)
                testModel.Test(false, true);

            string[] split;
            this.grid = view as IGridView;
            this.model = model as Model;
            this.explorerPresenter = explorerPresenter;

            this.FindAllProperties(this.model);
            if (this.grid.DataSource == null)
            {
                this.PopulateGrid(this.model);
            }
            else
            {
                this.grid.ResizeControls();
                FormatTestGrid();
            }

            this.grid.CellsChanged += this.OnCellValueChanged;
            this.grid.ButtonClick += OnFileBrowseClick;
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
            if (model != null)
            {
                split = this.model.GetType().ToString().Split('.');
                this.grid.ModelName = split[split.Length - 1];
                this.grid.LoadImage();
            }
        }
コード例 #2
0
ファイル: XYPairsPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attach the view to the model.
        /// </summary>
        /// <param name="model">The initial water model</param>
        /// <param name="view">The initial water view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.xyPairs = model as XYPairs;
            this.xyPairsView = view as XYPairsView;
            this.explorerPresenter = explorerPresenter as ExplorerPresenter;

            // Create a list of profile (array) properties. PpoulateView wil create a table from them and
            // hand the table to the variables grid.
            this.FindAllProperties(this.xyPairs);

            this.PopulateView();

            this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;

            // Populate the graph.
            this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph");
            this.xyPairs.Children.Add(this.graph);
            this.graph.Parent = this.xyPairs;
            (this.graph.Series[0] as Series).XFieldName = Apsim.FullPath(graph.Parent) + ".X";
            (this.graph.Series[0] as Series).YFieldName = Apsim.FullPath(graph.Parent) + ".Y";
            this.graphPresenter = new GraphPresenter();
            this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter);
            string xAxisTitle = LookForXAxisTitle();
            if (xAxisTitle != null)
                xyPairsView.Graph.FormatAxis(Axis.AxisType.Bottom, xAxisTitle, false, double.NaN, double.NaN, double.NaN);

            string yAxisTitle = LookForYAxisTitle();
            if (yAxisTitle != null)
                xyPairsView.Graph.FormatAxis(Axis.AxisType.Left, yAxisTitle, false, double.NaN, double.NaN, double.NaN);

            xyPairsView.Graph.FormatTitle(xyPairs.Parent.Name);
        }
コード例 #3
0
ファイル: SummaryPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>Attach the model to the view.</summary>
        /// <param name="model">The model to work with</param>
        /// <param name="view">The view to attach to</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.summary = model as Summary;
            this.view = view as ISummaryView;
            this.explorerPresenter = explorerPresenter;

            // populate the simulation names in the view.
            Simulation simulation = Apsim.Parent(this.summary, typeof(Simulation)) as Simulation;
            if (simulation != null)
            {
                if (simulation.Parent is Experiment)
                {
                    Experiment experiment = simulation.Parent as Experiment;
                    string[] simulationNames = experiment.Names();
                    this.view.SimulationNames = simulationNames;
                    if (simulationNames.Length > 0)
                        this.view.SimulationName = simulationNames[0];
                }
                else
                {
                    this.view.SimulationNames = new string[] { simulation.Name };
                    this.view.SimulationName = simulation.Name;
                }

                // create a data store - we'll need it later
                dataStore = new DataStore(simulation, false);

                // populate the view
                this.SetHtmlInView();

                // subscribe to the simulation name changed event.
                this.view.SimulationNameChanged += OnSimulationNameChanged;
            }
        }
コード例 #4
0
ファイル: ReportPresenter.cs プロジェクト: ykhorzon/ApsimX
        /// <summary>Attach the model (report) and the view (IReportView)</summary>
        public void Attach(object Model, object View, ExplorerPresenter explorerPresenter)
        {
            this.report = Model as Report;
            this.explorerPresenter = explorerPresenter;
            this.view = View as IReportView;

            this.view.VariableList.Lines = report.VariableNames;
            this.view.EventList.Lines = report.EventNames;
            this.view.VariableList.ContextItemsNeeded += OnNeedVariableNames;
            this.view.EventList.ContextItemsNeeded += OnNeedEventNames;
            this.view.VariableList.TextHasChangedByUser += OnVariableNamesChanged;
            this.view.EventList.TextHasChangedByUser += OnEventNamesChanged;
            this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;

            Simulations simulations = Apsim.Parent(report, typeof(Simulations)) as Simulations;
            dataStore = Apsim.Child(simulations, typeof(DataStore)) as DataStore;
            this.view.VariableList.SetSyntaxHighlighter("Report");

            dataStorePresenter = new DataStorePresenter();
            dataStorePresenter.Attach(dataStore, this.view.DataStoreView, explorerPresenter);
            this.view.DataStoreView.TableList.SelectedValue = this.report.Name;

            Simulation simulation = Apsim.Parent(report, typeof(Simulation)) as Simulation;
            if (simulation != null)
            {
                if (simulation.Parent is Experiment)
                    dataStorePresenter.ExperimentFilter = simulation.Parent as Experiment;
                else
                    dataStorePresenter.SimulationFilter = simulation;
                dataStorePresenter.PopulateGrid();
            }
        }
コード例 #5
0
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            ForestryModel = model as StaticForestrySystem;
            ForestryViewer = view as StaticForestrySystemView;

            AttachData();
            ForestryViewer.OnCellEndEdit += OnCellEndEdit;
        }
コード例 #6
0
ファイル: MemoPresenter.cs プロジェクト: hol353/ApsimX
 /// <summary>
 /// Attach the 'Model' and the 'View' to this presenter.
 /// </summary>
 /// <param name="model">The model to use</param>
 /// <param name="view">The view object</param>
 /// <param name="explorerPresenter">The explorer presenter used</param>
 public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
 {
     this.memoModel = model as Memo;
     this.memoViewer = view as HTMLView;
     this.explorerPresenter = explorerPresenter;
     this.memoViewer.ImagePath = Path.GetDirectoryName(explorerPresenter.ApsimXFile.FileName);
     this.memoViewer.SetContents(this.memoModel.MemoText, true);
 }
コード例 #7
0
ファイル: MetDataPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>Attaches the specified model.</summary>
        /// <param name="model">The model.</param>
        /// <param name="view">The view.</param>
        /// <param name="explorerPresenter">The explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.explorerPresenter = explorerPresenter;
            this.weatherData = (model as Weather);
            this.weatherDataView = (view as IMetDataView);

            this.weatherDataView.BrowseClicked += this.OnBrowse;
            this.WriteTableAndSummary(this.weatherData.FullFileName);
        }
コード例 #8
0
ファイル: ExperimentPresenter.cs プロジェクト: hut104/ApsimX
        public void Attach(object Model, object View, ExplorerPresenter explorerPresenter)
        {
            Experiment = Model as Experiment;
            ListView = View as IMemoView;
            ExplorerPresenter = explorerPresenter;

            ListView.MemoLines = Experiment.Names();
            ListView.LabelText = "Listed below are names of the " + ListView.MemoLines.Length.ToString() + " simulations that this experiment will create";
            ListView.ReadOnly = true;
            ListView.AddContextAction("Run APSIM", OnRunApsimClick);
        }
コード例 #9
0
ファイル: TreeProxyPresenter.cs プロジェクト: hol353/ApsimX
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            ForestryModel = model as TreeProxy;
            ForestryViewer = view as TreeProxyView;

            AttachData();
            ForestryViewer.OnCellEndEdit += OnCellEndEdit;
            ForestryViewer.SetReadOnly();
            this.propertyPresenter = new PropertyPresenter();
            this.propertyPresenter.Attach(ForestryModel, ForestryViewer.ConstantsGrid, explorerPresenter);
        }
コード例 #10
0
ファイル: SupplementPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the model and view to this presenter.
        /// </summary>
        /// <param name="model">The initial supplement model</param>
        /// <param name="view">The supplement view to work with</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explrPresenter)
        {
            supplement = model as Supplement;
            supplementView = view as SupplementView;
            explorerPresenter = explrPresenter;

            ConnectViewEvents();
            PopulateView();

            explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;
        }
コード例 #11
0
ファイル: OperationsPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach model to view.
        /// </summary>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            Operations = model as Operations;
            View = view as EditorView;
            ExplorerPresenter = explorerPresenter;

            PopulateEditorView();
            View.ContextItemsNeeded += OnContextItemsNeeded;
            View.TextHasChangedByUser += OnTextHasChangedByUser;
            ExplorerPresenter.CommandHistory.ModelChanged += OnModelChanged;
        }
コード例 #12
0
ファイル: InputPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attaches an Input model to an Input View.
        /// </summary>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            Input = model as Models.PostSimulationTools.Input;
            View = view as IInputView;
            ExplorerPresenter = explorerPresenter;
            View.BrowseButtonClicked += OnBrowseButtonClicked;

            OnModelChanged(model);  // Updates the view

            ExplorerPresenter.CommandHistory.ModelChanged += OnModelChanged;
        }
コード例 #13
0
ファイル: FactorPresenter.cs プロジェクト: hut104/ApsimX
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            Factor = model as Factor;
            FactorView = view as IEditorView;
            ExplorerPresenter = explorerPresenter;

            FactorView.Lines = Factor.Specifications.ToArray();

            FactorView.TextHasChangedByUser += OnTextHasChangedByUser;
            FactorView.ContextItemsNeeded += OnContextItemsNeeded;
            ExplorerPresenter.CommandHistory.ModelChanged += OnModelChanged;
        }
コード例 #14
0
ファイル: CultivarPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>Attach the cultivar model to the cultivar view</summary>
        /// <param name="model">The mode</param>
        /// <param name="view">The view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.cultivar = model as Cultivar;
            this.view = view as IEditorView;
            this.explorerPresenter = explorerPresenter;

            this.view.Lines = this.cultivar.Commands;

            this.view.LeaveEditor += this.OnCommandsChanged;
            this.view.ContextItemsNeeded += this.OnContextItemsNeeded;
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
コード例 #15
0
ファイル: MetDataPresenter.cs プロジェクト: ykhorzon/ApsimX
        /// <summary>Attaches the specified model.</summary>
        /// <param name="model">The model.</param>
        /// <param name="view">The view.</param>
        /// <param name="explorerPresenter">The explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.explorerPresenter = explorerPresenter;
            this.weatherData = (model as Weather);
            this.weatherDataView = (view as IMetDataView);

            this.weatherDataView.BrowseClicked += this.OnBrowse;
            this.weatherDataView.GraphRefreshClicked += this.GraphRefreshValueChanged;
            this.weatherDataView.ExcelSheetChangeClicked += this.ExcelSheetValueChanged;

            this.WriteTableAndSummary(this.weatherData.FullFileName, this.weatherData.ExcelWorkSheetName);
        }
コード例 #16
0
ファイル: ManagerPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attach the Manager model and ManagerView to this presenter.
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="view">The view to attach</param>
        /// <param name="explorerPresenter">The explorer presenter being used</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.manager = model as Manager;
            this.managerView = view as IManagerView;
            this.explorerPresenter = explorerPresenter;

            this.propertyPresenter.Attach(this.manager.Script, this.managerView.GridView, this.explorerPresenter);

            this.managerView.Editor.Text = this.manager.Code;
            this.managerView.Editor.ContextItemsNeeded += this.OnNeedVariableNames;
            this.managerView.Editor.LeaveEditor += this.OnEditorLeave;
        }
コード例 #17
0
ファイル: MapPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attach the specified Model and View.
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="view">The view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.map = model as Map;
            this.view = view as MapView;
            this.explorerPresenter = explorerPresenter;

            // Tell the view to populate the axis.
            this.PopulateView();
            this.view.Zoom = map.Zoom;
            this.view.Center = map.Center;
            this.view.ZoomChanged += OnZoomChanged;
            this.view.PositionChanged += OnPositionChanged;
        }
コード例 #18
0
ファイル: AddFunctionPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>Attach the specified Model and View.</summary>
        /// <param name="model">The axis model</param>
        /// <param name="view">The axis view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.model = model as IModel;
            this.view = view as IListButtonView;
            this.explorerPresenter = explorerPresenter;

            allowableChildFunctions = Apsim.GetAllowableChildFunctions(this.model);

            this.view.List.Values = allowableChildFunctions.Select(m => m.Name).ToArray();
            this.view.AddButton("Add", null, this.OnAddButtonClicked);

            // Trap events from the view.
            this.view.List.DoubleClicked += this.OnAddButtonClicked;
        }
コード例 #19
0
ファイル: TestPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The model object</param>
        /// <param name="view">The view used</param>
        /// <param name="explorerPresenter">The explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.view = view as ITestView;
            this.tests = model as Tests;
            this.explorerPresenter = explorerPresenter;

            this.dataStore = Apsim.Find(this.tests, typeof(DataStore)) as DataStore;
            this.view.Editor.IntelliSenseChars = " :";
            this.view.Editor.ContextItemsNeeded += this.OnContextItemsNeeded;
            this.view.TableNameChanged += this.OnTableNameChanged;

            this.PopulateView();
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
コード例 #20
0
ファイル: GraphPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>Attach the model to the view.</summary>
        /// <param name="model">The model.</param>
        /// <param name="view">The view.</param>
        /// <param name="explorerPresenter">The explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.graph = model as Graph;
            this.graphView = view as GraphView;
            this.explorerPresenter = explorerPresenter;

            graphView.OnAxisClick += OnAxisClick;
            graphView.OnLegendClick += OnLegendClick;
            graphView.OnCaptionClick += OnCaptionClick;
            graphView.OnHoverOverPoint += OnHoverOverPoint;
            explorerPresenter.CommandHistory.ModelChanged += OnGraphModelChanged;
            this.graphView.AddContextAction("Copy graph to clipboard", false, CopyGraphToClipboard);
            this.graphView.AddContextAction("Include in auto-documentation?", graph.IncludeInDocumentation, IncludeInDocumentationClicked);
            DrawGraph();
        }
コード例 #21
0
ファイル: TitlePresenter.cs プロジェクト: hut104/ApsimX
        /// <summary>
        /// Attach the specified Model and View.
        /// </summary>
        /// <param name="model">The model to use</param>
        /// <param name="view">The view for this presenter</param>
        /// <param name="explorerPresenter">The explorer presenter used</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.graph = model as Graph;
            this.view = view as ITitleView;
            this.explorerPresenter = explorerPresenter;

            // Trap change event from the model.
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;

            // Trap events from the view.
            this.view.OnTitleChanged += this.OnTitleChanged;

            // Tell the view to populate the axis.
            this.PopulateView();
        }
コード例 #22
0
ファイル: LegendPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attach the specified Model and View.
        /// </summary>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            Graph = model as Graph;
            View = view as ILegendView;
            ExplorerPresenter = explorerPresenter;

            // Trap change event from the model.
            ExplorerPresenter.CommandHistory.ModelChanged += OnModelChanged;

            // Trap events from the view.
            View.OnPositionChanged += OnTitleChanged;

            // Tell the view to populate the axis.
            PopulateView();
        }
コード例 #23
0
ファイル: FolderPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the specified Model and View.
        /// </summary>
        /// <param name="model">The axis model</param>
        /// <param name="view">The axis view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            IModel folder = model as IModel;

            List<UserControl> views = new List<UserControl>();

            foreach (Graph graph in Apsim.Children(folder, typeof(Graph)))
            {
                GraphView graphView = new GraphView();
                GraphPresenter presenter = new GraphPresenter();
                presenter.Attach(graph, graphView, explorerPresenter);
                views.Add(graphView);
            }

            if (views.Count > 0)
                (view as IFolderView).SetContols(views);
        }
コード例 #24
0
ファイル: SeriesPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the model and view to this presenter.
        /// </summary>
        /// <param name="model">The graph model to work with</param>
        /// <param name="view">The series view to work with</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.series = model as Series;
            this.seriesView = view as SeriesView;
            this.explorerPresenter = explorerPresenter;

            Graph parentGraph = Apsim.Parent(series, typeof(Graph)) as Graph;
            if (parentGraph != null)
            {
                graphPresenter = new GraphPresenter();
                graphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter);
            }

            PopulateView();

            ConnectViewEvents();
        }
コード例 #25
0
ファイル: DataStorePresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the model and view to this presenter and populate the view.
        /// </summary>
        /// <param name="model">The data store model to work with.</param>
        /// <param name="view">Data store view to work with.</param>
        /// <param name="explorerPresenter">Parent explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.dataStore = model as DataStore;
            this.dataStoreView = view as IDataStoreView;
            this.explorerPresenter = explorerPresenter;

            this.dataStoreView.AutoExport = dataStore.AutoExport;

            this.dataStoreView.OnTableSelected += this.OnTableSelected;
            this.dataStoreView.AutoExportClicked += OnAutoExportClicked;

            this.dataStoreView.Grid.ReadOnly = true;

            this.dataStoreView.Grid.NumericFormat = "N3";
            this.dataStoreView.TableNames = this.GetTableNames();

            this.dataStoreView.Grid.ResizeControls();
        }
コード例 #26
0
ファイル: DataStorePresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>Attach the model and view to this presenter and populate the view.</summary>
        /// <param name="model">The data store model to work with.</param>
        /// <param name="view">Data store view to work with.</param>
        /// <param name="explorerPresenter">Parent explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            dataStore = model as DataStore;
            this.view = view as IDataStoreView;
            this.explorerPresenter = explorerPresenter;

            this.view.TableList.IsEditable = false;
            this.view.Grid.ReadOnly = true;
            this.view.Grid.NumericFormat = "N3";
            this.view.TableList.Values = this.GetTableNames();
            if (dataStore != null && dataStore.MaximumResultsPerPage > 0)
                this.view.MaximumNumberRecords.Value = dataStore.MaximumResultsPerPage.ToString();

            this.view.Grid.ResizeControls();
            this.view.TableList.Changed += this.OnTableSelected;
            this.view.ColumnFilter.Changed += OnColumnFilterChanged;
            this.view.MaximumNumberRecords.Changed += OnMaximumNumberRecordsChanged;
            PopulateGrid();
        }
コード例 #27
0
        /// <summary>
        /// Attach the view to the model.
        /// </summary>
        /// <param name="model">The initial water model</param>
        /// <param name="view">The initial water view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.initialWater = model as InitialWater;
            this.initialWaterView = view as IInitialWaterView;
            this.explorerPresenter = explorerPresenter as ExplorerPresenter;

            this.initialWaterView.RelativeToCrops = this.initialWater.RelativeToCrops;
            this.ConnectViewEvents();
            this.PopulateView();

            this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;

            // Populate the graph.
            this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph");
            this.initialWater.Parent.Children.Add(this.graph);
            this.graph.Parent = this.initialWater.Parent;
            this.graphPresenter = new GraphPresenter();
            this.graphPresenter.Attach(this.graph, this.initialWaterView.Graph, this.explorerPresenter);
        }
コード例 #28
0
ファイル: AxisPresenter.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Attach the specified Model and View.
        /// </summary>
        /// <param name="model">The axis model</param>
        /// <param name="view">The axis view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.axis = model as Axis;
            this.view = view as AxisView;
            this.explorerPresenter = explorerPresenter;

            // Trap change event from the model.
            explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;

            // Trap events from the view.
            this.view.TitleChanged += this.OnTitleChanged;
            this.view.InvertedChanged += this.OnInvertedChanged;
            this.view.MinimumChanged += this.OnMinimumChanged;
            this.view.MaximumChanged += this.OnMaximumChanged;
            this.view.IntervalChanged += this.OnIntervalChanged;

            // Tell the view to populate the axis.
            this.PopulateView();
        }
コード例 #29
0
ファイル: PropertyPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The model to connect to</param>
        /// <param name="view">The view to connect to</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            string[] split;
            this.grid = view as IGridView;
            this.model = model as Model;
            this.explorerPresenter = explorerPresenter;

            this.FindAllProperties();
            this.PopulateGrid(this.model);
            this.grid.CellsChanged += this.OnCellValueChanged;
            this.grid.ButtonClick += OnFileBrowseClick;
            this.grid.ResizeControls();
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
            if (model != null)
            {
                split = this.model.GetType().ToString().Split('.');
                this.grid.ModelName = split[split.Length - 1];
                this.grid.LoadImage();
            }
        }
コード例 #30
0
ファイル: XYPairsPresenter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Attach the view to the model.
        /// </summary>
        /// <param name="model">The initial water model</param>
        /// <param name="view">The initial water view</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.xyPairs = model as XYPairs;
            this.xyPairsView = view as XYPairsView;
            this.explorerPresenter = explorerPresenter as ExplorerPresenter;

            // Create a list of profile (array) properties. PpoulateView wil create a table from them and
            // hand the table to the variables grid.
            this.FindAllProperties(this.xyPairs);

            this.PopulateView();

            this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;

            // Populate the graph.
            this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph");
            this.xyPairs.Children.Add(this.graph);
            this.graph.Parent = this.xyPairs;
            this.graphPresenter = new GraphPresenter();
            this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter);
        }
コード例 #31
0
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.ApsimXFile        = model as Simulations;
            this.explorerPresenter = explorerPresenter;
            this.view = view as IModelDetailsWrapperView;

            if (model != null)
            {
                ViewNameAttribute      viewName      = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;

                this.view.ModelTypeText = model.GetType().ToString().Substring("Models.".Length);
                DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (descAtt != null)
                {
                    this.view.ModelDescriptionText = descAtt.ToString();
                }
                else
                {
                    this.view.ModelDescriptionText = "";
                }

                // Set CLEM specific colours for title
                if (this.view.ModelTypeText.Contains(".Resources."))
                {
                    this.view.ModelTypeTextColour = "996633";
                    this.view.ModelTypeTextStyle  = "resource";
                }
                else if (this.view.ModelTypeText.Contains(".Activities.LabourRequirement"))
                {
                    this.view.ModelTypeTextColour = "cc33cc";
                    this.view.ModelTypeTextStyle  = "labourrequirement";
                }
                else if (this.view.ModelTypeText.Contains(".Activities."))
                {
                    this.view.ModelTypeTextColour = "009999";
                    this.view.ModelTypeTextStyle  = "activity";
                }
                else if (this.view.ModelTypeText.Contains(".Groupings."))
                {
                    this.view.ModelTypeTextColour = "cc33cc";
                    this.view.ModelTypeTextStyle  = "grouping";
                }
                else if (this.view.ModelTypeText.Contains(".File"))
                {
                    this.view.ModelTypeTextColour = "008000";
                    this.view.ModelTypeTextStyle  = "file";
                }
                else if (this.view.ModelTypeText.Contains(".Market"))
                {
                    this.view.ModelTypeTextColour = "1785FF";
                    this.view.ModelTypeTextStyle  = "market";
                }

                HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute;
                this.view.ModelHelpURL = "";
                if (helpAtt != null)
                {
                    this.view.ModelHelpURL = helpAtt.ToString();
                }

                var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false);
                if (vs.Count() > 0)
                {
                    VersionAttribute verAtt = vs.ToList <Attribute>().Cast <VersionAttribute>().OrderBy(a => a.ToString()).Last() as VersionAttribute;
                    if (verAtt != null)
                    {
                        string v = "Version ";
                        v += verAtt.ToString();
                        this.view.ModelVersionText = v;
                    }
                    else
                    {
                        this.view.ModelVersionText = "";
                    }
                }

                if (viewName != null && presenterName != null)
                {
                    // if model CLEMModel
                    if (model.GetType().IsSubclassOf(typeof(CLEMModel)) | model is ZoneCLEM | model is Market | model is RandomNumberGenerator | model is ReportResourceLedger)
                    {
                        // all CLEMModels will handle this presenter
                        ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter");
                    }
                    else if (typeof(ICLEMPresenter).IsAssignableFrom(Assembly.GetExecutingAssembly().GetType(presenterName.ToString())))
                    {
                        // apply this if the presenter has ICLEMPresenter interface and is ready to create presenters
                        ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter");
                    }
                    else
                    {
                        ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString());
                    }
                }
            }
        }
コード例 #32
0
 /// <summary>
 /// Attach the view
 /// </summary>
 /// <param name="model">The model</param>
 /// <param name="view">The view to attach</param>
 /// <param name="explorerPresenter">The explorer</param>
 public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
 {
     this.model       = model as Model;
     this.genericView = view as IMarkdownView;
 }
コード例 #33
0
        /// <summary>
        /// Attach the view
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="view">The view to attach</param>
        /// <param name="explorerPresenter">The explorer</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.clemModel         = model as ICLEMUI;
            this.explorerPresenter = explorerPresenter;

            this.view = view as ICLEMView;
            if (model != null)
            {
                //Messages
                try
                {
                    if (model is ZoneCLEM)
                    {
                        object newView = new HTMLView(this.view as ViewBase);
                        messagePresenter = new MessagePresenter();
                        if (newView != null && messagePresenter != null)
                        {
                            this.view.AddTabView("Messages", newView);
                            messagePresenter.Attach(model, newView, this.explorerPresenter);
                        }
                    }
                }
                catch (Exception err)
                {
                    this.explorerPresenter.MainPresenter.ShowError(err);
                }
                //HTML Summary
                try
                {
                    object newView = new HTMLView(this.view as ViewBase);
                    summaryPresenter = new CLEMSummaryPresenter();
                    if (newView != null && summaryPresenter != null)
                    {
                        this.view.AddTabView("Summary", newView);
                        summaryPresenter.Attach(model, newView, this.explorerPresenter);
                    }
                }
                catch (Exception err)
                {
                    this.explorerPresenter.MainPresenter.ShowError(err);
                }
                //Versions
                try
                {
                    var versions = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false);
                    if (versions.Count() > 0)
                    {
                        object newView = new HTMLView(this.view as ViewBase);
                        versionPresenter = new VersionsPresenter();
                        if (newView != null && versionPresenter != null)
                        {
                            this.view.AddTabView("Version", newView);
                            versionPresenter.Attach(model, newView, this.explorerPresenter);
                        }
                    }
                }
                catch (Exception err)
                {
                    this.explorerPresenter.MainPresenter.ShowError(err);
                }
                //Properties
                try
                {
                    PresenterNameAttribute presenterName    = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;
                    string[] childDisplayInParentPresenters = { "PropertyTablePresenter", "PropertyTreeTablePresenter" };
                    bool     isTablePresenter = childDisplayInParentPresenters.Contains(presenterName.ToString().Split('.').Last());

                    // check if it has properties
                    if (isTablePresenter ||
                        (model.GetType().GetProperties(
                             BindingFlags.Public |
                             BindingFlags.NonPublic |
                             BindingFlags.Instance
                             ).Where(prop => prop.IsDefined(typeof(DescriptionAttribute), false)).Count() > 0))
                    {
                        ViewNameAttribute viewName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                        object            newView  = Assembly.GetExecutingAssembly().CreateInstance(viewName.ToString(), false, BindingFlags.Default, null, new object[] { this.view }, null, null);
                        propertyPresenter = Assembly.GetExecutingAssembly().CreateInstance(presenterName.ToString()) as IPresenter;
                        if (newView != null && propertyPresenter != null)
                        {
                            this.view.AddTabView("Properties", newView);
                            propertyPresenter.Attach(model, newView, this.explorerPresenter);
                        }
                    }
                }
                catch (Exception err)
                {
                    this.explorerPresenter.MainPresenter.ShowError(err);
                }

                if (clemModel != null)
                {
                    this.view.SelectTabView(clemModel.SelectedTab);
                }
                this.view.TabSelected += OnTabSelected;
            }
        }
コード例 #34
0
 public GraphTab(string simulationName, ExplorerPresenter presenter)
 {
     Graphs         = new List <PanelGraph>();
     SimulationName = simulationName;
     Presenter      = presenter;
 }
コード例 #35
0
 /// <summary>
 /// Attach the view to this presenter.
 /// </summary>
 /// <param name="model"></param>
 /// <param name="view"></param>
 /// <param name="explorerPresenter"></param>
 public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
 {
     this.view           = (CloudJobDisplayView)view;
     this.view.Presenter = this;
     GetCredentials();
 }
コード例 #36
0
ファイル: ProfilePresenter.cs プロジェクト: nastaranch/ApsimX
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The underlying model we are to use</param>
        /// <param name="view">The underlying view we are to attach to</param>
        /// <param name="explorerPresenter">Our parent explorerPresenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.model = model as Model;
            this.view  = view as IProfileView;
            this.view.ProfileGrid.FormatColumns += (sender, e) =>
            {
                FormatGrid((view as IProfileView).ProfileGrid.DataSource);
            };

            this.explorerPresenter = explorerPresenter;

            this.view.ShowView(false);

            // Setup the property presenter and view. Hide the view if there are no properties to show.
            this.propertyPresenter = new PropertyPresenter();
            this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter);

            // Create a list of profile (array) properties. Create a table from them and
            // hand the table to the profile grid.
            this.FindAllProperties(this.model);

            // Populate the grid
            this.PopulateGrid();

            // Populate the graph.
            this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph");

            if (this.graph == null)
            {
                this.view.ShowGraph(false);
            }
            else
            {
                this.parentForGraph = this.model.Parent as IModel;
                if (this.parentForGraph != null)
                {
                    this.parentForGraph.Children.Add(this.graph);
                    this.graph.Parent = this.parentForGraph;
                    this.view.ShowGraph(true);
                    int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2;
                    this.view.Graph.LeftRightPadding = padding;
                    this.graphPresenter = new GraphPresenter();
                    for (int col = 0; col < this.propertiesInGrid.Count; col++)
                    {
                        VariableProperty property   = this.propertiesInGrid[col];
                        string           columnName = property.Description;

                        // crop colours
                        if (property.CropName != null && columnName.Contains("LL"))
                        {
                            Series cropLLSeries = new Series();
                            cropLLSeries.Name         = columnName;
                            cropLLSeries.Colour       = ColourUtilities.ChooseColour(this.graph.Children.Count);
                            cropLLSeries.Line         = LineType.Solid;
                            cropLLSeries.Marker       = MarkerType.None;
                            cropLLSeries.Type         = SeriesType.Scatter;
                            cropLLSeries.ShowInLegend = true;
                            cropLLSeries.XAxis        = Axis.AxisType.Top;
                            cropLLSeries.YAxis        = Axis.AxisType.Left;
                            cropLLSeries.YFieldName   = "[Soil].DepthMidPoints";
                            cropLLSeries.XFieldName   = "[" + (property.Object as Model).Name + "]." + property.Name;
                            cropLLSeries.Parent       = this.graph;

                            this.graph.Children.Add(cropLLSeries);
                        }
                    }

                    this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter);
                }
            }

            // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that
            // we can save the contents.
            this.view.ProfileGrid.CellsChanged += this.OnProfileGridCellValueChanged;

            // Trap the right click on column header so that we can potentially put
            // units on the context menu.
            this.view.ProfileGrid.ColumnHeaderClicked += this.OnColumnHeaderClicked;

            // Trap the model changed event so that we can handle undo.
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;

            this.view.ProfileGrid.ResizeControls();
            this.view.PropertyGrid.ResizeControls();
            this.view.ShowView(true);
        }
コード例 #37
0
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The underlying model we are to use</param>
        /// <param name="view">The underlying view we are to attach to</param>
        /// <param name="explorerPresenter">Our parent explorerPresenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.model = model as Model;
            this.view  = view as IProfileView;
            profileGrid.Attach(model, this.view.ProfileGrid, explorerPresenter);
            this.explorerPresenter = explorerPresenter;

            this.view.ShowView(false);

            // Setup the property presenter and view. Hide the view if there are no properties to show.
            this.propertyPresenter = new PropertyPresenter();
            this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter);

            // Create a list of profile (array) properties. Create a table from them and
            // hand the table to the profile grid.
            this.FindAllProperties(this.model);

            // Populate the grid
            this.PopulateGrid();

            // Populate the graph.
            this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph");

            if (this.graph == null)
            {
                this.view.ShowGraph(false);
            }
            else
            {
                // The graph's series contain many variables such as [Soil].LL. We now replace
                // these relative paths with absolute paths.
                foreach (Series series in Apsim.Children(graph, typeof(Series)))
                {
                    series.XFieldName  = series.XFieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                    series.X2FieldName = series.X2FieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                    series.YFieldName  = series.YFieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                    series.Y2FieldName = series.Y2FieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                }

                this.parentForGraph = this.model.Parent as IModel;
                if (this.parentForGraph != null)
                {
                    this.parentForGraph.Children.Add(this.graph);
                    this.graph.Parent = this.parentForGraph;
                    this.view.ShowGraph(true);
                    int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2;
                    this.view.Graph.LeftRightPadding = padding;
                    this.graphPresenter = new GraphPresenter();
                    for (int col = 0; col < this.propertiesInGrid.Count; col++)
                    {
                        string columnName = propertiesInGrid[col].ColumnName;

                        if (columnName.Contains("\r\n"))
                        {
                            StringUtilities.SplitOffAfterDelimiter(ref columnName, "\r\n");
                        }

                        // crop colours
                        if (columnName.Contains("LL"))
                        {
                            Series cropLLSeries = new Series();
                            cropLLSeries.Name         = columnName;
                            cropLLSeries.Colour       = ColourUtilities.ChooseColour(this.graph.Children.Count);
                            cropLLSeries.Line         = LineType.Solid;
                            cropLLSeries.Marker       = MarkerType.None;
                            cropLLSeries.Type         = SeriesType.Scatter;
                            cropLLSeries.ShowInLegend = true;
                            cropLLSeries.XAxis        = Axis.AxisType.Top;
                            cropLLSeries.YAxis        = Axis.AxisType.Left;
                            cropLLSeries.YFieldName   = (parentForGraph is Soil ? Apsim.FullPath(parentForGraph) : "[Soil]") + ".DepthMidPoints";
                            cropLLSeries.XFieldName   = Apsim.FullPath((propertiesInGrid[col].ObjectWithProperty as Model)) + "." + propertiesInGrid[col].PropertyName;
                            //cropLLSeries.XFieldName = Apsim.FullPath(property.Object as Model) + "." + property.Name;
                            cropLLSeries.Parent = this.graph;

                            this.graph.Children.Add(cropLLSeries);
                        }
                    }

                    explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter);
                }
            }

            // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that
            // we can save the contents.
            this.view.ProfileGrid.CellsHaveChanged += this.OnProfileGridCellValueChanged;

            // Trap the right click on column header so that we can potentially put
            // units on the context menu.
            this.view.ProfileGrid.ColumnMenuClicked += this.OnColumnMenuItemClicked;

            // Trap the model changed event so that we can handle undo.
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;

            this.view.ShowView(true);
        }
コード例 #38
0
 /// <summary>
 /// Attach the model and view to the presenter
 /// </summary>
 /// <param name="model">The model to attach</param>
 /// <param name="view">The view to attach</param>
 /// <param name="explorerPresenter">The presenter to attach to</param>
 public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
 {
     // This code is not reached, the usual functionality is performed in
     // the CLEMPresenter.AttachExtraPresenters() method
 }
コード例 #39
0
ファイル: GraphPresenter.cs プロジェクト: ver078/ApsimX
 /// <summary>Attach the model to the view.</summary>
 /// <param name="model">The model.</param>
 /// <param name="view">The view.</param>
 /// <param name="explorerPresenter">The explorer presenter.</param>
 public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
 {
     Attach(model, view, explorerPresenter, null);
 }
コード例 #40
0
ファイル: MainMenu.cs プロジェクト: markje153/ApsimX-1
 /// <summary>
 /// Initializes a new instance of the <see cref="MainMenu" /> class.
 /// </summary>
 /// <param name="explorerPresenter">The explorer presenter to work with</param>
 public MainMenu(ExplorerPresenter explorerPresenter)
 {
     this.explorerPresenter = explorerPresenter;
 }
コード例 #41
0
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The underlying model we are to use</param>
        /// <param name="view">The underlying view we are to attach to</param>
        /// <param name="explorerPresenter">Our parent explorerPresenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.model = model as Model;
            this.view  = view as IProfileView;
            profileGrid.Attach(model, this.view.ProfileGrid, explorerPresenter);
            this.explorerPresenter = explorerPresenter;

            this.view.ShowView(false);

            // Setup the property presenter and view. Hide the view if there are no properties to show.
            this.propertyPresenter = new PropertyPresenter();
            this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter);
            propertyPresenter.ScalarsOnly = true;
            // Populate the grid
            this.PopulateGrid();

            // Populate the graph.
            this.graph = Utility.Graph.CreateGraphFromResource("WaterGraph");
            graph.Name = "";
            if (this.graph == null)
            {
                this.view.ShowGraph(false);
            }
            else
            {
                // The graph's series contain many variables such as [Soil].LL. We now replace
                // these relative paths with absolute paths.
                foreach (Series series in Apsim.Children(graph, typeof(Series)))
                {
                    series.XFieldName  = series.XFieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                    series.X2FieldName = series.X2FieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                    series.YFieldName  = series.YFieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                    series.Y2FieldName = series.Y2FieldName?.Replace("[Soil]", Apsim.FullPath(this.model.Parent));
                }

                this.parentForGraph = this.model.Parent as IModel;
                if (this.parentForGraph != null)
                {
                    // Don't add the graph as a child of the soil. This causes problems
                    // (see bug #4622), and adding the soil as a parent is sufficient.
                    this.graph.Parent = this.parentForGraph;
                    this.view.ShowGraph(true);
                    int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2;
                    this.view.Graph.LeftRightPadding = padding;
                    this.graphPresenter = new GraphPresenter();
                    for (int i = 0; i < this.profileGrid.Properties.Length; i++)
                    {
                        string columnName = profileGrid.Properties[i].Name;

                        if (columnName.Contains("\r\n"))
                        {
                            StringUtilities.SplitOffAfterDelimiter(ref columnName, "\r\n");
                        }

                        // crop colours
                        if (columnName.Contains("LL"))
                        {
                            if (profileGrid.Properties[i].Object is SoilCrop)
                            {
                                string soilCropName = (profileGrid.Properties[i].Object as SoilCrop).Name;
                                string cropName     = soilCropName.Replace("Soil", "");
                                columnName = cropName + " " + columnName;
                            }

                            Series cropLLSeries = new Series();
                            cropLLSeries.Name         = columnName;
                            cropLLSeries.Colour       = ColourUtilities.ChooseColour(this.graph.Children.Count);
                            cropLLSeries.Line         = LineType.Solid;
                            cropLLSeries.Marker       = MarkerType.None;
                            cropLLSeries.Type         = SeriesType.Scatter;
                            cropLLSeries.ShowInLegend = true;
                            cropLLSeries.XAxis        = Axis.AxisType.Top;
                            cropLLSeries.YAxis        = Axis.AxisType.Left;
                            cropLLSeries.YFieldName   = (parentForGraph is Soil ? Apsim.FullPath(parentForGraph) : "[Soil]") + ".DepthMidPoints";
                            cropLLSeries.XFieldName   = Apsim.FullPath((profileGrid.Properties[i].Object as IModel)) + "." + profileGrid.Properties[i].Name;
                            //cropLLSeries.XFieldName = Apsim.FullPath(property.Object as Model) + "." + property.Name;
                            cropLLSeries.Parent = this.graph;

                            this.graph.Children.Add(cropLLSeries);
                        }
                    }

                    this.graph.LegendPosition = Graph.LegendPositionType.RightTop;
                    explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter);
                    graphPresenter.LegendInsideGraph = false;
                }
            }

            // Trap the model changed event so that we can handle undo.
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;

            this.view.ShowView(true);
        }
コード例 #42
0
        /// <summary>
        /// Attach the view
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="view">The view to attach</param>
        /// <param name="explorerPresenter">The explorer</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.model             = model as Model;
            this.genericView       = view as IHTMLView;
            this.explorerPresenter = explorerPresenter;

            string htmlString = "<!DOCTYPE html>\n" +
                                "<html>\n<head>\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n<style>\n" +
                                "body {color: [FontColor]; max-width:1000px; font-size:10pt;}" +
                                "th,td {padding:5px;}" +
                                "th,td {border: 1px dotted [GridColor]; }" +
                                "table {border: 0px none #009999; border-collapse: collapse;}" +
                                "table.main {[TableBackground] }" +
                                "table.main tr td.disabled {color: [DisabledColour]; }" +
                                ".dot { margin:auto; display:block; height:20px; width:20px; line-height:20px; background-color:black; -moz-border-radius: 10px; border-radius: 10px; }" +
                                ".dot1 { background-color:lightgreen; }" +
                                ".dot2 { background-color:lightskyblue; }" +
                                ".dot4 { background-color:coral; }" +
                                ".dot3 { background-color:lightpink; }" +
                                ".warningbanner {background-color:orange; border-radius:5px 5px 0px 0px; color:white; padding:5px; font-weight:bold }" +
                                ".warningcontent {background-color:[WarningBackground]; margin-bottom:20px; border-radius:0px 0px 5px 5px; border-color:orange; border-width:1px; border-style:none solid solid solid; padding:10px;}" +
                                ".messagebanner {background-color:CornflowerBlue; border-radius:5px 5px 0px 0px; color:white; padding:5px; font-weight:bold }" +
                                ".messagecontent {background-color:[MessageBackground]; margin-bottom:20px; border-radius:0px 0px 5px 5px; border-color:CornflowerBlue; border-width:1px; border-style:none solid solid solid; padding:10px;}" +
                                "li {margin-bottom:10px;}" +
                                "table.blank td {border: 0px none [GridColor]; }" +
                                "table.blank {border: 0px none #009999; border-collapse: collapse; }" +
                                "table th:first-child {text-align:left; }" +
                                "table th:nth-child(n+2) { /* Safari */ - webkit - transform: rotate(-90deg); /* Firefox */ -moz - transform: rotate(-90deg); /* IE */ -ms - transform: rotate(-90deg); /* Opera */ -o - transform: rotate(-90deg); /* Internet Explorer */ filter: progid: DXImageTransform.Microsoft.BasicImage(rotation = 3);  }" +
                                "table td:nth-child(n+2) { text-align:center; }" +
                                ".holdermain {margin: 20px 0px 20px 0px}" +
                                "\n</style>\n</head>\n<body>";

            // Start building table

            // apply theme based settings
            if (!Utility.Configuration.Settings.DarkTheme)
            {
                // light theme
                htmlString = htmlString.Replace("[FontColor]", "#000000");
                htmlString = htmlString.Replace("[GridColor]", "Black");
                htmlString = htmlString.Replace("[WarningBackground]", "#FFFFFA");
                htmlString = htmlString.Replace("[MessageBackground]", "#FAFAFF");
                htmlString = htmlString.Replace("[DisabledColour]", "#cccccc");
                htmlString = htmlString.Replace("[TableBackground]", "background-color: white;");
            }
            else
            {
                // dark theme
                htmlString = htmlString.Replace("[FontColor]", "#E5E5E5");
                htmlString = htmlString.Replace("[GridColor]", "#888");
                htmlString = htmlString.Replace("[WarningBackground]", "rgba(255, 102, 0, 0.4)");
                htmlString = htmlString.Replace("[MessageBackground]", "rgba(100, 149, 237, 0.4)");
                htmlString = htmlString.Replace("[DisabledColour]", "#666666");
                htmlString = htmlString.Replace("[TableBackground]", "background-color: rgba(50, 50, 50, 0.5);");
            }

            // get CLEM Zone
            IModel clem = model as IModel;

            while (!(clem is ZoneCLEM))
            {
                clem = clem.Parent;
            }

            // Get Labour resources
            labour = Apsim.ChildrenRecursively(clem, typeof(Labour)).FirstOrDefault() as Labour;
            if (labour == null)
            {
                htmlString += "No Labour supplied in resources";
                EndHTML(htmlString);
            }

            numberLabourTypes = Apsim.Children(labour, typeof(LabourType)).Count();
            if (numberLabourTypes == 0)
            {
                htmlString += "No Labour types supplied in Labour resource";
                EndHTML(htmlString);
            }

            // create labour list
            foreach (LabourType lt in Apsim.Children(labour, typeof(LabourType)))
            {
                labourList.Add(new LabourType()
                {
                    Parent      = labour,
                    Name        = lt.Name,
                    AgeInMonths = lt.InitialAge * 12,
                    Gender      = lt.Gender
                }
                               );
            }

            // get all parents of LabourRequirement
            validpAtt.AddRange(ReflectionUtilities.GetAttributes(typeof(LabourRequirement), typeof(ValidParentAttribute), false).Cast <ValidParentAttribute>().ToList());
            validpAtt.AddRange(ReflectionUtilities.GetAttributes(typeof(LabourRequirementNoUnitSize), typeof(ValidParentAttribute), false).Cast <ValidParentAttribute>().ToList());
            validpAtt.AddRange(ReflectionUtilities.GetAttributes(typeof(LabourRequirementSimple), typeof(ValidParentAttribute), false).Cast <ValidParentAttribute>().ToList());
            if (validpAtt.Count() == 0)
            {
                htmlString += "No components allow Labour Requirements to be added";
                EndHTML(htmlString);
            }

            // walk through all activities
            // check if LabourRequirement can be added
            ActivitiesHolder activities = Apsim.ChildrenRecursively(clem, typeof(ActivitiesHolder)).FirstOrDefault() as ActivitiesHolder;

            if (activities == null)
            {
                htmlString += "Could not find an Activities Holder";
                EndHTML(htmlString);
            }

            string tableHtml = "";

            tableHtml += "<table class=\"main\">";
            tableHtml += "<tr><th>Activity</th>";
            foreach (LabourType lt in Apsim.Children(labour, typeof(LabourType)))
            {
                tableHtml += "<th>" + lt.Name + "</th>";
            }
            tableHtml += "</tr>";
            tableHtml += TableRow(activities);
            tableHtml += "</table>";

            htmlString += tableHtml;

            // add notes
            htmlString += "\n<div class=\"holdermain\">";
            htmlString += "\n<div class=\"clearfix messagebanner\">";
            htmlString += "<div class=\"typediv\">" + "Notes" + "</div>";
            htmlString += "</div>";
            htmlString += "\n<div class=\"messagecontent\">";
            htmlString += "\n<ul>";
            htmlString += "\n<li>Only activities capable of including a labour requirement are displayed.</li>";
            htmlString += "\n<li>Activities with no labour requirement provided are displayed with grey text.</li>";
            htmlString += "\n<li>Multiple rows of icons (circles) for a given activity show where more than one individual is required.</li>";
            htmlString += "\n<li>The preferential allocation of labour is displayed in the following order:" +
                          "<table class=\"blank\">" +
                          "<tr><td><span class=\"dot dot1 \">" + "</span></td><td>1st preference</td></tr>" +
                          "<tr><td><span class=\"dot dot2 \">" + "</span></td><td>2nd preference</td></tr>" +
                          "<tr><td><span class=\"dot dot3 \">" + "</span></td><td>3rd preference</td></tr>" +
                          "<tr><td><span class=\"dot dot4 \">" + "</span></td><td>4th+ preference</td></tr>" +
                          "</table></li>";
            htmlString += "\n</ul>";
            htmlString += "\n</div>";

            // aging note
            if (labour.AllowAging)
            {
                htmlString += "\n<div class=\"holdermain\">";
                htmlString += "\n<div class=\"clearfix warningbanner\">";
                htmlString += "<div class=\"typediv\">" + "Warning" + "</div>";
                htmlString += "</div>";
                htmlString += "\n<div class=\"warningcontent\">";
                htmlString += "\n<div class=\"activityentry\">As this simulation allows aging of individuals (see Labour) these allocations may change over the duration of the simulation. ";
                htmlString += "\n</div>";
                htmlString += "\n</div>";
            }

            EndHTML(htmlString);
        }
コード例 #43
0
        /// <summary>
        /// Attach the view
        /// </summary>
        /// <param name="model">The model</param>
        /// <param name="view">The view to attach</param>
        /// <param name="explorerPresenter">The explorer</param>
        public virtual void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.Model             = model as IModel;
            this.ClemModel         = model as ICLEMUI;
            this.ExplorerPresenter = explorerPresenter;

            this.View = view as ICLEMView;

            PresenterNameAttribute presenterName = null;

            if (model != null)
            {
                //Messages
                try
                {
                    if (model is ZoneCLEM)
                    {
                        object     newView          = new MarkdownView(this.View as ViewBase);
                        IPresenter messagePresenter = new MessagePresenter();
                        if (newView != null && messagePresenter != null)
                        {
                            this.View.AddTabView("Messages", newView);
                            messagePresenter.Attach(model, newView, this.ExplorerPresenter);
                            PresenterList.Add("Messages", messagePresenter);
                        }
                    }
                }
                catch (Exception err)
                {
                    this.ExplorerPresenter.MainPresenter.ShowError(err);
                }
                //Properties
                try
                {
                    // user can set view to state it must be multiview so do not override value
                    presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;
                    string            propPresenterName = presenterName.ToString();
                    ViewNameAttribute viewAttribute     = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                    string            viewName          = viewAttribute.ToString();
                    if (propPresenterName == "UserInterface.Presenters.PropertyPresenter" | !propPresenterName.Contains("Property"))
                    {
                        propPresenterName = "UserInterface.Presenters.PropertyPresenter";
                        if (viewName != "UserInterface.Views.PropertyMultiModelView")
                        {
                            viewName = "UserInterface.Views.PropertyView";
                        }
                    }

                    var props = model.GetType().GetProperties(
                        BindingFlags.Public |
                        BindingFlags.NonPublic |
                        BindingFlags.Instance
                        );

                    // check if any category attribtes other than "*" fould and if so make this a PropertyCategoryPresenter
                    bool categoryAttributeFound = props.Where(prop => prop.IsDefined(typeof(CategoryAttribute), false) && (prop.GetCustomAttribute(typeof(CategoryAttribute)) as CategoryAttribute).Category != "*").Any();
                    if (categoryAttributeFound)
                    {
                        propPresenterName = "UserInterface.Presenters.PropertyCategorisedPresenter";
                        viewName          = "UserInterface.Views.PropertyCategorisedView";
                    }

                    // check if it has properties
                    if ((viewName.Contains("PropertyMultiModelView") | propPresenterName.Contains("MultiModel")) ||
                        (props.Where(prop => prop.IsDefined(typeof(DescriptionAttribute), false)).Count() > 0))
                    {
                        object     newView           = Assembly.GetExecutingAssembly().CreateInstance(viewName, false, BindingFlags.Default, null, new object[] { this.View }, null, null);
                        IPresenter propertyPresenter = Assembly.GetExecutingAssembly().CreateInstance(propPresenterName) as IPresenter;
                        if (newView != null && propertyPresenter != null)
                        {
                            this.View.AddTabView("Properties", newView);
                            propertyPresenter.Attach(model, newView, this.ExplorerPresenter);
                            PresenterList.Add("Properties", propertyPresenter);
                        }
                    }
                }
                catch (Exception err)
                {
                    this.ExplorerPresenter.MainPresenter.ShowError(err);
                }

                // if presenter is ICLEMPresenter then add the extra presenters if specified
                if (presenterName != null && typeof(ICLEMPresenter).IsAssignableFrom(Assembly.GetExecutingAssembly().GetType(presenterName.ToString())))
                {
                    (Assembly.GetExecutingAssembly().CreateInstance(presenterName.ToString()) as ICLEMPresenter).AttachExtraPresenters(this);
                }

                //HTML Summary
                try
                {
                    object     newView          = new MarkdownView(this.View as ViewBase);
                    IPresenter summaryPresenter = new CLEMSummaryPresenter();
                    if (newView != null && summaryPresenter != null)
                    {
                        this.View.AddTabView("Summary", newView);
                        summaryPresenter.Attach(model, newView, this.ExplorerPresenter);
                        PresenterList.Add("Summary", summaryPresenter);
                    }
                }
                catch (Exception err)
                {
                    this.ExplorerPresenter.MainPresenter.ShowError(err);
                }
                //Versions
                try
                {
                    var versions = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false);
                    if (versions.Count() > 0)
                    {
                        object     newView          = new MarkdownView(this.View as ViewBase);
                        IPresenter versionPresenter = new VersionsPresenter();
                        if (newView != null && versionPresenter != null)
                        {
                            this.View.AddTabView("Version", newView);
                            versionPresenter.Attach(model, newView, this.ExplorerPresenter);
                            PresenterList.Add("Version", versionPresenter);
                        }
                    }
                }
                catch (Exception err)
                {
                    this.ExplorerPresenter.MainPresenter.ShowError(err);
                }

                this.View.TabSelected += OnTabSelected;

                if (ClemModel != null)
                {
                    this.View.SelectTabView(ClemModel.SelectedTab);
                    if (ClemModel.SelectedTab == "Summary")
                    {
                        PresenterList.TryGetValue("Summary", out IPresenter selectedPresenter);
                        (selectedPresenter as CLEMSummaryPresenter).Refresh();
                    }
                }

                if (ClemModel != null && ClemModel.SelectedTab is null && PresenterList.Count > 0)
                {
                    if (PresenterList.FirstOrDefault().Value is IRefreshPresenter)
                    {
                        (PresenterList.FirstOrDefault().Value as IRefreshPresenter).Refresh();
                    }
                }
            }
        }
コード例 #44
0
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.ApsimXFile        = model as Simulations;
            this.explorerPresenter = explorerPresenter;
            this.view = view as IModelDetailsWrapperView;

            if (model != null)
            {
                ViewNameAttribute      viewName      = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;

                this.view.ModelTypeText = model.GetType().ToString().Substring("Models.".Length);
                DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (descAtt != null)
                {
                    this.view.ModelDescriptionText = descAtt.ToString();
                }
                else
                {
                    this.view.ModelDescriptionText = "";
                }
                // Set CLEM specific colours for title
                if (this.view.ModelTypeText.Contains(".Resources."))
                {
                    this.view.ModelTypeTextColour = "996633";
                }
                else if (this.view.ModelTypeText.Contains(".Activities.LabourRequirement"))
                {
                    this.view.ModelTypeTextColour = "cc33cc";
                }
                else if (this.view.ModelTypeText.Contains(".Activities."))
                {
                    this.view.ModelTypeTextColour = "009999";
                }
                else if (this.view.ModelTypeText.Contains(".Groupings."))
                {
                    this.view.ModelTypeTextColour = "cc33cc";
                }
                else if (this.view.ModelTypeText.Contains(".File"))
                {
                    this.view.ModelTypeTextColour = "008000";
                }

                HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute;
                this.view.ModelHelpURL = "";
                if (helpAtt != null)
                {
                    this.view.ModelHelpURL = helpAtt.ToString();
                }

                var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false);
                if (vs.Count() > 0)
                {
                    VersionAttribute verAtt = vs.ToList <Attribute>().Cast <VersionAttribute>().OrderBy(a => a.ToString()).Last() as VersionAttribute;
                    if (verAtt != null)
                    {
                        string v = "Version ";
                        v += verAtt.ToString();
                        this.view.ModelVersionText = v;
                    }
                    else
                    {
                        this.view.ModelVersionText = "";
                    }
                }

                if (viewName != null && presenterName != null)
                {
                    // if model CLEMModel
                    if (model.GetType().IsSubclassOf(typeof(CLEMModel)) || model is ZoneCLEM)
                    {
                        ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter");
                    }
                    else
                    {
                        ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString());
                    }
                }
            }
        }
コード例 #45
0
ファイル: ContextMenu.cs プロジェクト: ver078/ApsimX
 /// <summary>
 /// Initializes a new instance of the <see cref="ContextMenu" /> class.
 /// </summary>
 /// <param name="explorerPresenter">The explorer presenter to work with</param>
 public ContextMenu(ExplorerPresenter explorerPresenter)
 {
     this.explorerPresenter = explorerPresenter;
 }