Exemple #1
0
        private string LookupName(ParameterModel reference, ModelSystemStructureModel current)
        {
            var param = current.Parameters;

            if (param != null && param.Parameters != null)
            {
                int index = param.Parameters.IndexOf(reference);
                if (index >= 0)
                {
                    return(current.Parameters.Parameters[index].Name);
                }
            }
            var childrenList = current.Children;

            if (childrenList != null)
            {
                for (int i = 0; i < childrenList.Count; i++)
                {
                    var res = LookupName(reference, childrenList[i]);
                    if (res != null)
                    {
                        // make sure to use an escape character before the . to avoid making the mistake of reading it as another index
                        return(string.Concat(current.IsCollection ? i.ToString()
                            : childrenList[i].ParentFieldName.Replace(".", "\\."), '.', res));
                    }
                }
            }
            return(null);
        }
Exemple #2
0
 /// <summary>
 /// Create a model system model for a previous run.
 /// </summary>
 /// <param name="modelSystemEditingSession">The session to use</param>
 /// <param name="project">The project the previous run is in.</param>
 /// <param name="runFile">The path to the run file.</param>
 public ModelSystemModel(XTMFRuntime runtime, ModelSystemEditingSession modelSystemEditingSession, Project project, string runFile)
 {
     Project = project;
     ModelSystemIndex = -1;
     Name = Path.GetFileName(runFile);
     _Description = "Previous run";
     Root = new ModelSystemStructureModel(modelSystemEditingSession, runtime.ModelSystemController.LoadFromRunFile(runFile));
 }
Exemple #3
0
 public ModelSystemModel(ModelSystemEditingSession session, ModelSystem modelSystem)
 {
     ModelSystem      = modelSystem;
     Name             = modelSystem.Name;
     _Description     = modelSystem.Description;
     Root             = new ModelSystemStructureModel(session, modelSystem.CreateEditingClone(out List <ILinkedParameter> editingLinkedParameters) as ModelSystemStructure);
     LinkedParameters = new LinkedParametersModel(session, this, editingLinkedParameters);
 }
Exemple #4
0
 public bool Remove(ModelSystemStructureModel selected, ref string error)
 {
     if (selected.IsCollection)
     {
         return(selected.RemoveAllCollectionMembers(ref error));
     }
     return(Remove(Root, null, selected, ref error));
 }
Exemple #5
0
 /// <summary>
 /// Create a model system model for a previous run.
 /// </summary>
 /// <param name="modelSystemEditingSession">The session to use</param>
 /// <param name="project">The project the previous run is in.</param>
 /// <param name="runFile">The path to the run file.</param>
 public ModelSystemModel(XTMFRuntime runtime, ModelSystemEditingSession modelSystemEditingSession, Project project, string runFile)
 {
     Project          = project;
     ModelSystemIndex = -1;
     Name             = Path.GetFileName(runFile);
     _Description     = "Previous run";
     Root             = new ModelSystemStructureModel(modelSystemEditingSession, runtime.ModelSystemController.LoadFromRunFile(runFile));
     LinkedParameters = new LinkedParametersModel(modelSystemEditingSession, this, new List <ILinkedParameter>());
 }
Exemple #6
0
 public ModelSystemModel(ModelSystemEditingSession session, ModelSystem modelSystem)
 {
     ModelSystem = modelSystem;
     Name = modelSystem.Name;
     _Description = modelSystem.Description;
     List<ILinkedParameter> editingLinkedParameters;
     Root = new ModelSystemStructureModel(session, modelSystem.CreateEditingClone(out editingLinkedParameters) as ModelSystemStructure);
     LinkedParameters = new LinkedParametersModel(session, this, editingLinkedParameters);
 }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="realParameter"></param>
        /// <param name="session"></param>
        /// <param name="belongsTo"></param>
        public ParameterModel(ModuleParameter realParameter, ModelSystemEditingSession session, ModelSystemStructureModel belongsTo)
        {
            IsDirty       = false;
            RealParameter = realParameter;
            _Session      = session;
            _Value        = _Value = RealParameter.Value != null?RealParameter.Value.ToString() : string.Empty;

            _belongsTo = belongsTo;
        }
Exemple #8
0
 public ModelSystemModel(ModelSystemEditingSession session, Project project, int modelSystemIndex)
 {
     _Project          = project;
     _ModelSystemIndex = modelSystemIndex;
     Name             = project.ModelSystemStructure[modelSystemIndex].Name;
     _Description     = project.ModelSystemDescriptions[modelSystemIndex];
     Root             = new ModelSystemStructureModel(session, (project.CloneModelSystemStructure(out List <ILinkedParameter> editingLinkedParameters, modelSystemIndex) as ModelSystemStructure));
     _Description     = _Project.ModelSystemDescriptions[modelSystemIndex];
     LinkedParameters = new LinkedParametersModel(session, this, editingLinkedParameters);
 }
Exemple #9
0
 public ModelSystemModel(ModelSystemEditingSession session, Project project, int modelSystemIndex)
 {
     Project = project;
     ModelSystemIndex = modelSystemIndex;
     Name = project.ModelSystemStructure[modelSystemIndex].Name;
     _Description = project.ModelSystemDescriptions[modelSystemIndex];
     List<ILinkedParameter> editingLinkedParameters;
     Root = new ModelSystemStructureModel(session, (project.CloneModelSystemStructure(out editingLinkedParameters, modelSystemIndex) as ModelSystemStructure));
     _Description = Project.ModelSystemDescriptions[modelSystemIndex];
     LinkedParameters = new LinkedParametersModel(session, this, editingLinkedParameters);
 }
Exemple #10
0
 public XTMFRun(Project project, int modelSystemIndex, ModelSystemModel root, Configuration config, string runName)
 {
     Project = project;
     ModelSystemStructureModelRoot = root.Root;
     Configuration = new XTMF.RunProxy.ConfigurationProxy(config, Project);
     RunName = runName;
     RunDirectory = Path.Combine(Configuration.ProjectDirectory, Project.Name, RunName);
     ModelSystemIndex = modelSystemIndex;
     Project.ModelSystemStructure[ModelSystemIndex] = root.ClonedModelSystemRoot;
     Project.LinkedParameters[ModelSystemIndex] = root.LinkedParameters.GetRealLinkedParameters();
 }
Exemple #11
0
 public XTMFRun(Project project, int modelSystemIndex, ModelSystemModel root, Configuration config, string runName)
 {
     Project = project;
     ModelSystemStructureModelRoot = root.Root;
     Configuration    = new XTMF.RunProxy.ConfigurationProxy(config, Project);
     RunName          = runName;
     RunDirectory     = Path.Combine(Configuration.ProjectDirectory, Project.Name, RunName);
     ModelSystemIndex = modelSystemIndex;
     Project.ModelSystemStructure[ModelSystemIndex] = root.ClonedModelSystemRoot;
     Project.LinkedParameters[ModelSystemIndex]     = root.LinkedParameters.GetRealLinkedParameters();
 }
Exemple #12
0
 public XTMFRun(Project project, ModelSystemStructureModel root, Configuration configuration, string runName)
 {
     // we don't make a clone for this type of run
     Project = project;
     ModelSystemStructureModelRoot = root;
     var index = project.ModelSystemStructure.IndexOf(root.RealModelSystemStructure);
     if(index >= 0)
     Configuration = new XTMF.RunProxy.ConfigurationProxy(configuration, Project);
     RunName = runName;
     RunDirectory = Path.Combine(Configuration.ProjectDirectory, Project.Name, RunName);
 }
Exemple #13
0
        public bool MoveModeInParent(int deltaPosition, ref string error)
        {
            ModelSystemStructureModel parent = Session.GetParent(this);

            if (!parent.IsCollection)
            {
                error = "You can only move the children of a collection!";
                return(false);
            }
            var ourIndex = parent.Children.IndexOf(this);

            return(parent.MoveChild(ourIndex, ourIndex + deltaPosition, ref error));
        }
Exemple #14
0
        private void GetAllChildren(List <ModelSystemStructureModel> list, ModelSystemStructureModel root)
        {
            list.Add(root);
            var children = root.Children;

            if (children != null)
            {
                foreach (var child in children)
                {
                    GetAllChildren(list, child);
                }
            }
        }
Exemple #15
0
        public XTMFRun(Project project, ModelSystemStructureModel root, Configuration configuration, string runName)
        {
            // we don't make a clone for this type of run
            Project = project;
            ModelSystemStructureModelRoot = root;
            var index = project.ModelSystemStructure.IndexOf(root.RealModelSystemStructure);

            if (index >= 0)
            {
                Configuration = new XTMF.RunProxy.ConfigurationProxy(configuration, Project);
            }
            RunName      = runName;
            RunDirectory = Path.Combine(Configuration.ProjectDirectory, Project.Name, RunName);
        }
Exemple #16
0
        private static List <ParameterModel> CreateParameterModels(ModelSystemStructureModel modelSystemStructure, ModelSystemEditingSession Session)
        {
            var realParameters = modelSystemStructure.RealModelSystemStructure.Parameters?.Parameters;

            if (realParameters == null)
            {
                return(null);
            }
            var ret = new List <ParameterModel>(realParameters.Count);

            for (int i = 0; i < realParameters.Count; i++)
            {
                ret.Add(new ParameterModel(realParameters[i] as ModuleParameter, Session, modelSystemStructure));
            }
            return(ret);
        }
Exemple #17
0
        private ParameterModel GetParameterModel(ModelSystemStructureModel owner, IModuleParameter moduleParameter)
        {
            var parameters = owner.Parameters.Parameters;

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Count; i++)
                {
                    if (parameters[i].RealParameter == moduleParameter)
                    {
                        return(parameters[i]);
                    }
                }
            }
            return(null);
        }
Exemple #18
0
        private bool Remove(ModelSystemStructureModel current, ModelSystemStructureModel previous, ModelSystemStructureModel selected, ref string error)
        {
            if (current == selected)
            {
                if (previous == null)
                {
                    Root.Type = null;
                    return(true);
                }
                else
                {
                    if (previous.IsCollection)
                    {
                        return(previous.RemoveCollectionMember(previous.Children.IndexOf(selected), ref error));
                    }
                    else
                    {
                        selected.Type = null;
                        return(true);
                    }
                }
            }
            var children = current.Children;

            if (children != null)
            {
                foreach (var child in current.Children)
                {
                    var success = Remove(child, current, selected, ref error);
                    if (success)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #19
0
 public ParametersModel(ModelSystemStructureModel modelSystemStructure, ModelSystemEditingSession session)
 {
     Session = session;
     ModelSystemStructure = modelSystemStructure;
     Parameters = CreateParameterModels(modelSystemStructure, Session);
 }
Exemple #20
0
 public bool Remove(ModelSystemStructureModel selected, ref string error)
 {
     if(selected.IsCollection)
     {
         return selected.RemoveAllCollectionMembers(ref error);
     }
     return Remove(Root, null, selected, ref error);
 }
Exemple #21
0
        private void AddQuickParameters(ObservableCollection <ParameterModel> quickParameters, ModelSystemStructureModel current)
        {
            var parameters = current.Parameters.Parameters;

            if (parameters != null)
            {
                foreach (var p in parameters)
                {
                    if (p.QuickParameter)
                    {
                        quickParameters.Add(p);
                    }
                }
            }
            var children = current.Children;

            if (children != null)
            {
                foreach (var child in children)
                {
                    AddQuickParameters(quickParameters, child);
                }
            }
        }
Exemple #22
0
 private ParameterModel GetParameterFromLink(string[] variableLink, int index, ModelSystemStructureModel current, int indexOffset)
 {
     if (index == variableLink.Length - 1)
     {
         // search the parameters
         var parameters = current.Parameters;
         foreach (var p in parameters.Parameters)
         {
             if (p.Name == variableLink[index])
             {
                 return(p);
             }
         }
     }
     else
     {
         var descList = current.Children;
         if (descList == null)
         {
             return(null);
         }
         if (current.IsCollection)
         {
             int collectionIndex;
             if (int.TryParse(variableLink[index], out collectionIndex))
             {
                 // if we are at the first index we need to look at the index offset.
                 // This is needed if we are copying a collection, thus the indexes will
                 // not be starting at the 0th position in the new model system structure.
                 if (index == 0)
                 {
                     collectionIndex += indexOffset;
                 }
                 if (collectionIndex >= 0 && collectionIndex < descList.Count)
                 {
                     return(GetParameterFromLink(variableLink, index + 1, descList[collectionIndex], indexOffset));
                 }
                 return(null);
             }
         }
         else
         {
             foreach (var sub in descList)
             {
                 if (sub.ParentFieldName == variableLink[index])
                 {
                     return(GetParameterFromLink(variableLink, index + 1, sub, 0));
                 }
             }
         }
     }
     return(null);
 }
Exemple #23
0
 private ParameterModel GetParameterModel(ModelSystemStructureModel owner, IModuleParameter moduleParameter)
 {
     var parameters = owner.Parameters.Parameters;
     if(parameters != null)
     {
         for(int i = 0; i < parameters.Count; i++)
         {
             if(parameters[i].RealParameter == moduleParameter)
             {
                 return parameters[i];
             }
         }
     }
     return null;
 }
Exemple #24
0
 private static List<ParameterModel> CreateParameterModels(ModelSystemStructureModel modelSystemStructure, ModelSystemEditingSession Session)
 {
     if(modelSystemStructure.RealModelSystemStructure.Parameters == null) return null;
     var realParameters = modelSystemStructure.RealModelSystemStructure.Parameters.Parameters;
     if(realParameters == null) return null;
     var ret = new List<ParameterModel>(realParameters.Count);
     for(int i = 0; i < realParameters.Count; i++)
     {
         ret.Add(new ParameterModel(realParameters[i] as ModuleParameter, Session));
     }
     return ret;
 }
 private void GetAllChildren(List<ModelSystemStructureModel> list, ModelSystemStructureModel root)
 {
     list.Add(root);
     var children = root.Children;
     if(children != null)
     {
         foreach(var child in children)
         {
             GetAllChildren(list, child);
         }
     }
 }
 public ModelSystemStructureModel GetParent(ModelSystemStructureModel currentModule)
 {
     return(ModelSystemModel.GetModelFor(
                currentModule.RealModelSystemStructure.GetParent(ModelSystemModel.Root.RealModelSystemStructure)));
 }
Exemple #27
0
 private void AddQuickParameters(ObservableCollection<ParameterModel> quickParameters, ModelSystemStructureModel current)
 {
     var parameters = current.Parameters.Parameters;
     if(parameters != null)
     {
         foreach(var p in parameters)
         {
             if(p.QuickParameter)
             {
                 quickParameters.Add(p);
             }
         }
     }
     var children = current.Children;
     if(children != null)
     {
         foreach(var child in children)
         {
             AddQuickParameters(quickParameters, child);
         }
     }
 }
 private string LookupName(ParameterModel reference, ModelSystemStructureModel current)
 {
     var param = current.Parameters;
     if(param != null && param.Parameters != null)
     {
         int index = param.Parameters.IndexOf(reference);
         if(index >= 0)
         {
             return current.Parameters.Parameters[index].Name;
         }
     }
     var childrenList = current.Children;
     if(childrenList != null)
     {
         for(int i = 0; i < childrenList.Count; i++)
         {
             var res = LookupName(reference, childrenList[i]);
             if(res != null)
             {
                 // make sure to use an escape character before the . to avoid making the mistake of reading it as another index
                 return string.Concat(current.IsCollection ? i.ToString()
                     : childrenList[i].ParentFieldName.Replace(".", "\\."), '.', res);
             }
         }
     }
     return null;
 }
Exemple #29
0
 private List <ParameterModel> GetParametersFromTemp(TempLinkedParameter temp, ModelSystemStructureModel root, int indexOffset)
 {
     return((from path in temp.Paths
             select GetParametersFromTemp(path, root, indexOffset)).ToList());
 }
Exemple #30
0
 private ModelSystemStructureModel GetModelFor(ModelSystemStructure realStructure, ModelSystemStructureModel current)
 {
     if(current.RealModelSystemStructure == realStructure)
     {
         return current;
     }
     var children = current.Children;
     if(children != null)
     {
         for(int i = 0; i < children.Count; i++)
         {
             ModelSystemStructureModel ret;
             if((ret = GetModelFor(realStructure, children[i])) != null)
             {
                 return ret;
             }
         }
     }
     return null;
 }
 /// <summary>
 /// Check to see if this linked parameter has a reference to the given module.
 /// </summary>
 /// <param name="child">The module to test against</param>
 /// <returns>If the given module is referenced</returns>
 internal bool HasContainedModule(ModelSystemStructureModel child)
 {
     return(RealLinkedParameter.Parameters.Any(p => p.BelongsTo == child.RealModelSystemStructure));
 }
 private List<ParameterModel> GetParametersFromTemp(TempLinkedParameter temp, ModelSystemStructureModel root, int indexOffset)
 {
     return (from path in temp.Paths
            select GetParametersFromTemp(path, root, indexOffset)).ToList();
 }
Exemple #33
0
 public ParametersModel(ModelSystemStructureModel modelSystemStructure, ModelSystemEditingSession session)
 {
     Session = session;
     ModelSystemStructure = modelSystemStructure;
     Parameters           = CreateParameterModels(modelSystemStructure, Session);
 }
Exemple #34
0
 private ParameterModel GetParametersFromTemp(string path, ModelSystemStructureModel root, int indexOffset)
 {
     return(GetParameterFromLink(ParseLinkedParameterName(path), 0, root, indexOffset));
 }
 public ModelSystemStructureModel GetRoot(ModelSystemStructureModel currentModule)
 {
     return ModelSystemModel.GetModelFor(currentModule.RealModelSystemStructure.GetRoot(ModelSystemModel.Root.RealModelSystemStructure));
 }
 /// <summary>
 /// Get the available types for the selected module
 /// </summary>
 /// <param name="selectedModule">The module to find the valid types for</param>
 /// <returns>A list of the allowed types.</returns>
 public List<Type> GetValidModules(ModelSystemStructureModel selectedModule)
 {
     return selectedModule.RealModelSystemStructure.GetPossibleModules(ModelSystemModel.Root.RealModelSystemStructure);
 }
 private ParameterModel GetParameterFromLink(string[] variableLink, int index, ModelSystemStructureModel current, int indexOffset)
 {
     if(index == variableLink.Length - 1)
     {
         // search the parameters
         var parameters = current.Parameters;
         foreach(var p in parameters.Parameters)
         {
             if(p.Name == variableLink[index])
             {
                 return p;
             }
         }
     }
     else
     {
         var descList = current.Children;
         if(descList == null)
         {
             return null;
         }
         if(current.IsCollection)
         {
             int collectionIndex;
             if(int.TryParse(variableLink[index], out collectionIndex))
             {
                 // if we are at the first index we need to look at the index offset.
                 // This is needed if we are copying a collection, thus the indexes will
                 // not be starting at the 0th position in the new model system structure.
                 if(index == 0)
                 {
                     collectionIndex += indexOffset;
                 }
                 if(collectionIndex >= 0 && collectionIndex < descList.Count)
                 {
                     return GetParameterFromLink(variableLink, index + 1, descList[collectionIndex], indexOffset);
                 }
                 return null;
             }
         }
         else
         {
             foreach(var sub in descList)
             {
                 if(sub.ParentFieldName == variableLink[index])
                 {
                     return GetParameterFromLink(variableLink, index + 1, sub, 0);
                 }
             }
         }
     }
     return null;
 }
Exemple #38
0
        private ModelSystemStructureModel GetModelFor(ModelSystemStructure realStructure, ModelSystemStructureModel current)
        {
            if (current.RealModelSystemStructure == realStructure)
            {
                return(current);
            }
            var children = current.Children;

            if (children != null)
            {
                for (int i = 0; i < children.Count; i++)
                {
                    ModelSystemStructureModel ret;
                    if ((ret = GetModelFor(realStructure, children[i])) != null)
                    {
                        return(ret);
                    }
                }
            }
            return(null);
        }
 private ParameterModel GetParametersFromTemp(string path, ModelSystemStructureModel root, int indexOffset)
 {
     return GetParameterFromLink(ParseLinkedParameterName(path), 0, root, indexOffset);
 }
Exemple #40
0
 private bool Remove(ModelSystemStructureModel current, ModelSystemStructureModel previous, ModelSystemStructureModel selected, ref string error)
 {
     if(current == selected)
     {
         if(previous == null)
         {
             Root.Type = null;
             return true;
         }
         else
         {
             if(previous.IsCollection)
             {
                 return previous.RemoveCollectionMember(previous.Children.IndexOf(selected), ref error);
             }
             else
             {
                 selected.Type = null;
                 return true;
             }
         }
     }
     var children = current.Children;
     if(children != null)
     {
         foreach(var child in current.Children)
         {
             var success = Remove(child, current, selected, ref error);
             if(success)
             {
                 return true;
             }
         }
     }
     return false;
 }
 /// <summary>
 ///     Get the available types for the selected module
 /// </summary>
 /// <param name="selectedModule">The module to find the valid types for</param>
 /// <returns>A list of the allowed types.</returns>
 public List <Type> GetValidModules(ModelSystemStructureModel selectedModule)
 {
     return(selectedModule.RealModelSystemStructure.GetPossibleModules(ModelSystemModel.Root
                                                                       .RealModelSystemStructure));
 }
Exemple #42
0
 public static XTMFRun CreateLocalRun(Project project, ModelSystemStructureModel root, Configuration configuration, string runName, bool overwrite = false)
 {
     return(new XTMFRunLocal(project, root, configuration, runName, overwrite));
 }
Exemple #43
0
 public static XTMFRun CreateRemoteHost(Project project, ModelSystemStructureModel root, Configuration config, string runName, bool overwrite = false)
 {
     return(new XTMFRunRemoteHost(config, root, new List <ILinkedParameter>(), runName, Path.Combine(config.ProjectDirectory, project.Name, runName),
                                  overwrite));
 }
Exemple #44
0
 /// <summary>
 /// Check to see if this linked parameter has a reference to the given module.
 /// </summary>
 /// <param name="child">The module to test against</param>
 /// <returns>If the given module is referenced</returns>
 internal bool HasContainedModule(ModelSystemStructureModel child)
 {
     return RealLinkedParameter.Parameters.Any(p => p.BelongsTo == child.RealModelSystemStructure);
 }