/// <summary> /// Inform the changing of EcellObject in PathwayEditor to DataManager. /// </summary> /// <param name="proKey">key of process</param> /// <param name="varKey">key of variable</param> /// <param name="changeType">type of change</param> /// <param name="coefficient">coefficient of VariableReference</param> /// <param name="isAnchor">is anchored or not.</param> public void NotifyVariableReferenceChanged(string proKey, string varKey, RefChangeType changeType, int coefficient, bool isAnchor) { // Get EcellObject of identified process. EcellProcess process = (EcellProcess)m_window.GetEcellObject(m_canvas.ModelID, proKey, EcellObject.PROCESS); // End if obj is null. if (null == process) return; // Get EcellReference List. List<EcellReference> refList = process.ReferenceList; List<EcellReference> newList = new List<EcellReference>(); EcellReference oldRef = null; EcellReference newRef = null; foreach (EcellReference er in refList) { if (CheckReference(er, varKey, changeType, coefficient)) oldRef = er.Clone(); else newList.Add(er.Clone()); } if (oldRef != null && changeType != RefChangeType.Delete) { newRef = oldRef.Clone(); switch(changeType) { case RefChangeType.SingleDir: newRef.Coefficient = coefficient; newRef.Name = PathUtil.GetNewReferenceName(newList, coefficient); newList.Add(newRef); if(oldRef.Coefficient != 0 && coefficient != 0 && oldRef.Coefficient != coefficient) newList.Add(oldRef); break; case RefChangeType.BiDir: EcellReference copyRef = newRef.Clone(); newRef.Coefficient = -1; newRef.Name = PathUtil.GetNewReferenceName(newList, -1); copyRef.Coefficient = 1; copyRef.Name = PathUtil.GetNewReferenceName(newList, 1); newList.Add(newRef); newList.Add(copyRef); break; } } else if(newRef == null) { switch(changeType) { case RefChangeType.SingleDir: EcellReference addRef = new EcellReference(); addRef.Coefficient = coefficient; addRef.Key = varKey; addRef.Name = PathUtil.GetNewReferenceName(newList, coefficient); addRef.IsAccessor = 1; newList.Add(addRef); break; case RefChangeType.BiDir: EcellReference addSRef = new EcellReference(); addSRef.Coefficient = -1; addSRef.Key = varKey; addSRef.Name = PathUtil.GetNewReferenceName(newList, -1); addSRef.IsAccessor = 1; newList.Add(addSRef); EcellReference addPRef = new EcellReference(); addPRef.Coefficient = 1; addPRef.Key = varKey; addPRef.Name = PathUtil.GetNewReferenceName(newList, 1); addPRef.IsAccessor = 1; newList.Add(addPRef); break; } } // Check MassCalc if (process.Classname == EcellProcess.MASSCALCULATIONPROCESS) { foreach (EcellReference er in newList) { er.Coefficient = 0; } } process.ReferenceList = newList; try { NotifyDataChanged(proKey, process, true, isAnchor); } catch (Exception e) { Debug.WriteLine(e.Message); throw new PathwayException(MessageResources.ErrCreateEdge); } }
/// <summary> /// Check Selected reference /// </summary> /// <param name="er"></param> /// <param name="varKey"></param> /// <param name="changeType"></param> /// <param name="coefficient"></param> /// <returns></returns> private static bool CheckReference(EcellReference er, string varKey, RefChangeType changeType, int coefficient) { if (!varKey.Equals(er.Key)) return false; if (changeType == RefChangeType.BiDir || coefficient == 0) return true; if (er.Coefficient == coefficient) return true; return false; }
/// <summary> /// Create VariableReferenceList of process. /// </summary> /// <param name="process">VariableReferenceList for this process will be created</param> /// <param name="variable">VariableReferenceList to this variable will be created</param> /// <param name="type">RefChangeType of this connection.</param> /// <param name="coefficient">coefficient of connection.</param> private void CreateEdge(PPathwayProcess process, PPathwayVariable variable, RefChangeType type, int coefficient) { try { m_con.NotifyVariableReferenceChanged( process.EcellObject.Key, variable.EcellObject.Key, RefChangeType.Delete, 0, false); m_con.NotifyVariableReferenceChanged( process.EcellObject.Key, variable.EcellObject.Key, type, coefficient, true); } catch (EcellException) { Util.ShowErrorDialog(MessageResources.ErrCreateEdge); } m_con.Menu.ResetEventHandler(); }