Esempio n. 1
0
 /// <summary>
 /// The constructor for DataChangeAction with initial parameters.
 /// </summary>
 /// <param name="paramID">A parameter ID.</param>
 /// <param name="oldObj">An object before changing.</param>
 /// <param name="newObj">An object after changing.</param>
 public DataChangeAction(string paramID, EcellObject oldObj, EcellObject newObj)
 {
     m_paramID = paramID;
     m_oldObj = oldObj.Clone();
     m_newObj = newObj.Clone();
 }
Esempio n. 2
0
        /// <summary>
        /// Changes the "System".
        /// </summary>
        /// <param name="modelID">The model ID</param>
        /// <param name="key">The key</param>
        /// <param name="type">The type</param>
        /// <param name="ecellObject">The changed "System"</param>
        /// <param name="isRecorded">Whether this action is recorded or not</param>
        /// <param name="isAnchor">Whether this action is an anchor or not</param>
        private void DataChanged4System(string modelID, string key, string type, EcellObject ecellObject, bool isRecorded, bool isAnchor)
        {
            m_currentProject.SortSystems();
            List<EcellObject> systemList = m_currentProject.SystemDic[modelID];

            string paramId = m_currentProject.Info.SimulationParam;
            if (Constants.defaultSimParam.Equals(paramId))
                paramId = null;

            // When system path is not modified.
            if (modelID.Equals(ecellObject.ModelID) && key.Equals(ecellObject.Key))
            {
                // Changes some properties.
                for (int i = 0; i < systemList.Count; i++)
                {
                    if (!systemList[i].Key.Equals(key))
                        continue;

                    CheckDifferences(systemList[i], ecellObject, paramId);

                    if (m_currentProject.Info.SimulationParam.Equals(Constants.defaultSimParam))
                    {
                        systemList[i] = ecellObject.Clone();
                    }
                    else
                    {
                        m_currentProject.DeleteInitialCondition(systemList[i]);
                        m_currentProject.SetInitialCondition(ecellObject);
                    }

                    m_env.PluginManager.DataChanged(modelID, key, type, ecellObject);
                    return;
                }
            }

            // Check Root
            if (key == Constants.delimiterPath)
                throw new EcellException(MessageResources.ErrChangeRoot);

            // Changes the object.
            Dictionary<string, string> variableKeyDic = new Dictionary<string, string>();
            Dictionary<string, string> oldKeyDic = new Dictionary<string, string>();
            List<EcellObject> tempList = new List<EcellObject>();
            tempList.AddRange(systemList);
            foreach (EcellObject system in tempList)
            {
                if (!system.Key.Equals(key) && !system.Key.StartsWith(key + Constants.delimiterPath))
                    continue;

                // Adds the new "System" object.
                string newKey = ecellObject.Key + system.Key.Substring(key.Length);
            //                oldKeyDic.Add(newKey, system.Key);
                EcellSystem newSystem
                    = (EcellSystem)EcellObject.CreateObject(modelID, newKey, system.Type, system.Classname, system.Value);
                if (newSystem.Key == ecellObject.Key)
                    newSystem.SetPosition(ecellObject);
                else
                    newSystem.SetPosition(system);
                CheckEntityPath(newSystem);
                CheckDifferences(system, newSystem, paramId);
                CheckParameterObservedData(system, newSystem.Key);
                m_currentProject.AddSystem(newSystem);
                m_currentProject.DeleteSystem(system);

                // Change Child
                foreach (EcellObject child in system.Children)
                {
                    EcellObject copy = child.Clone();
                    copy.ParentSystemID = newKey;
                    CheckEntityPath(copy);
                    m_currentProject.AddEntity(copy);
                    CheckParameterObservedData(child, copy.Key);
                    CheckLogger(child, copy.Key);

            //                    oldKeyDic.Add(copy.Key, child.Key);
                    if (copy.Type.Equals(Constants.xpathVariable))
                        variableKeyDic.Add(child.Key, copy.Key);
                }
            }

            ecellObject = m_currentProject.GetEcellObject(modelID, Constants.xpathSystem, ecellObject.Key, false);
            m_env.PluginManager.DataChanged(modelID, key, ecellObject.Type, ecellObject);
            // Checks all processes.
            m_currentProject.SortSystems();
            List<EcellObject> processList = CheckVariableReferenceChanges(variableKeyDic);
            DataChanged(processList, true, false);
        }
Esempio n. 3
0
        /// <summary>
        /// Changes the "Variable" or the "Process".
        /// </summary>
        /// <param name="modelID">The model ID</param>
        /// <param name="key">The key</param>
        /// <param name="type">The type</param>
        /// <param name="ecellObject">The changed "Variable" or the "Process"</param>
        /// <param name="isRecorded">Whether this action is recorded or not</param>
        /// <param name="isAnchor">Whether this action is an anchor or not</param>
        private void DataChanged4Entity(
            string modelID, string key, string type, EcellObject ecellObject, bool isRecorded, bool isAnchor)
        {
            // Get changed node.
            EcellObject oldNode = m_currentProject.GetEcellObject(modelID, type, key, false);
            Debug.Assert(oldNode != null);

            string paramId = m_currentProject.Info.SimulationParam;
            if (Constants.defaultSimParam.Equals(paramId))
                paramId = null;

            CheckDifferences(oldNode, ecellObject, paramId);
            if (key.Equals(ecellObject.Key))
            {
                if (m_currentProject.Info.SimulationParam.Equals(Constants.defaultSimParam) ||
                    !oldNode.Classname.Equals(ecellObject.Classname) || oldNode.Value.Count != ecellObject.Value.Count)
                {
                    EcellObject oldSystem = m_currentProject.GetEcellObject(modelID, Constants.xpathSystem, Util.GetSuperSystemPath(key), true);
                    Debug.Assert(oldSystem != null);
                    oldSystem.Children.Remove(oldNode);
                    oldSystem.Children.Add(ecellObject);
                }
                else
                {
                    m_currentProject.DeleteInitialCondition(oldNode);
                    m_currentProject.SetInitialCondition(ecellObject);
                }
                m_env.PluginManager.DataChanged(modelID, key, type, ecellObject);
                return;
            }

            // Get parent system.
            // Add new object.
            DataAdd4Entity(ecellObject.Clone(), false);
            m_currentProject.UpdateInitialCondition(oldNode, ecellObject);
            m_env.PluginManager.DataChanged(modelID, key, type, ecellObject);
            if (type.Equals(Constants.xpathVariable))
            {
                List<EcellObject> list = CheckVariableReferenceChanges(key, ecellObject.Key);
                DataChanged(list, false, false);
            }
            // Deletes the old object.
            DataDelete4Node(modelID, key, type, false, true, false);
            return;
        }
Esempio n. 4
0
        /// <summary>
        /// Adds the "Process" or the "Variable".
        /// </summary>
        /// <param name="entity">The "Variable"</param>
        /// <param name="messageFlag">The flag of the messages</param>
        private void DataAdd4Entity(EcellObject entity, bool messageFlag)
        {
            string modelID = entity.ModelID;
            string key = entity.Key;
            string type = entity.Type;
            string systemKey = entity.ParentSystemID;

            Dictionary<string, List<EcellObject>> sysDic = m_currentProject.SystemDic;

            // Check Stepper
            if (entity is EcellProcess)
            {
                EcellProcess process = (EcellProcess)entity;
                string stepperID = process.StepperID;
                EcellObject stepper = null;
                foreach (EcellObject s in GetStepper(modelID))
                {
                    if (s.Key.Equals(stepperID))
                        stepper = s;
                }
                if (stepper == null)
                    process.StepperID = GetStepper(entity.ModelID)[0].Key;
            }

            // Add object.
            bool findFlag = false;
            foreach (EcellObject system in sysDic[modelID])
            {
                if (!system.ModelID.Equals(modelID) || !system.Key.Equals(systemKey))
                    continue;
                // Check duplicated object.
                foreach (EcellObject child in system.Children)
                {
                    if (!child.Key.Equals(key) || !child.Type.Equals(type))
                        continue;
                    throw new EcellException(
                        string.Format(
                            MessageResources.ErrExistObj,
                            new object[] { key }
                        )
                    );
                }
                // Set object.
                CheckEntityPath(entity);
                system.Children.Add(entity.Clone());
                SetLogger(entity);

                findFlag = true;
                break;
            }

            if (messageFlag)
            {
                MessageCreateEntity(type, string.Format(MessageResources.InfoAdd,
                    new object[] { type, entity.Key }));
            }
            Debug.Assert(findFlag);
        }
Esempio n. 5
0
 /// <summary>
 /// The constructor for DataDeleteAction with initial parameters.
 /// </summary>
 /// <param name="obj">deleted object.</param>
 public DataDeleteAction(EcellObject obj)
 {
     m_obj = obj.Clone();
 }
Esempio n. 6
0
 /// <summary>
 /// The constructor for DataAddAction with initial parameters.
 /// </summary>
 /// <param name="obj">the added object</param>
 /// <param name="isUndoable">The flag the action is undoable.</param>
 public DataAddAction(EcellObject obj, bool isUndoable)
 {
     m_obj = obj.Clone();
     m_obj.IsLayouted = true;
     m_isUndoable = isUndoable;
 }