private void CreateDTLines(DTAnalyzer analyzer) { foreach (StateClassShape Shape in this.Shapes) { this.CreateOutgoingDTLines(Shape, analyzer); } }
public override void Validate(DataRow proposedRow, DataTransferMethod transferMethod) { base.Validate(proposedRow, transferMethod); DataTable dt = this.GetDataSheet(Strings.DATASHEET_DT_NAME).GetData(); DTAnalyzer Analyzer = new DTAnalyzer(dt, this.Project); int? StratumIdSource = null; int StateClassIdSource = 0; int? StratumIdDest = null; int? StateClassIdDest = null; DTAnalyzer.GetPTFieldValues(proposedRow, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!Analyzer.CanResolveStateClass(StratumIdSource, StratumIdSource, StateClassIdSource)) { Analyzer.ThrowDataException(StateClassIdSource, false); } if (StateClassIdDest.HasValue) { if (!Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)) { Analyzer.ThrowDataException(StateClassIdDest.Value, true); } } }
private void InternalDeleteStateClasses() { this.m_DTDataSheet.BeginDeleteRows(); this.m_PTDataSheet.BeginDeleteRows(); DTAnalyzer Analyzer = new DTAnalyzer(this.m_DTDataSheet.GetData(), this.m_DataFeed.Project); foreach (StateClassShape Shape in this.SelectedShapes) { if (!Shape.IsStatic) { DataRow row = Analyzer.GetStateClassRow(Shape.StratumIdSource, Shape.StateClassIdSource); if (row.RowState == DataRowState.Added) { this.m_DTDataSheet.GetData().Rows.Remove(row); } else { row.Delete(); } } } this.m_DTDataSheet.EndDeleteRows(); this.m_PTDataSheet.EndDeleteRows(); }
private void CreateOutgoingDTOffStratumCues(StateClassShape shape, DTAnalyzer analyzer) { //If there is no destination state class then it is a transition-to-self if (!shape.StateClassIdDest.HasValue) { return; } int?StratumIdActual = null; analyzer.ResolveStateClassStratum(shape.StratumIdSource, shape.StratumIdDest, shape.StateClassIdDest.Value, ref StratumIdActual); //If the class was found in the current stratum then it is not an off-stratum transition if (NullableUtilities.NullableIdsEqual(StratumIdActual, this.m_StratumId)) { return; } //If the class was found in the wild card stratum then it is not an off-stratum transition if (!StratumIdActual.HasValue) { return; } this.AddLine(CreateOutgoingDTOffStratumCue(shape)); }
private void VALIDATE_DETERMINISTIC_TRANSITIONS() { DataTable dtdata = this.GetData(); DTAnalyzer Analyzer = new DTAnalyzer(dtdata, this.Project); foreach (DataRow dr in dtdata.Rows) { if (dr.RowState == DataRowState.Deleted) { continue; } int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (StateClassIdDest.HasValue) { Debug.Assert(Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)); } } }
private static bool IsDTToSelf(DataRow dr) { int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!StateClassIdDest.HasValue) { return(true); } if (StateClassIdSource == StateClassIdDest.Value) { if (!StratumIdDest.HasValue) { return(true); } else { return(NullableUtilities.NullableIdsEqual(StratumIdSource, StratumIdDest)); } } return(false); }
private void VALIDATE_PROBABILISTIC_TRANSITIONS() { DTAnalyzer Analyzer = new DTAnalyzer(this.GetDataSheet(Strings.DATASHEET_DT_NAME).GetData(), this.Project); DataTable ptdata = this.GetDataSheet(Strings.DATASHEET_PT_NAME).GetData(); foreach (DataRow dr in ptdata.Rows) { if (dr.RowState == DataRowState.Deleted) { continue; } int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetPTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); Debug.Assert(Analyzer.CanResolveStateClass(StratumIdSource, StratumIdSource, StateClassIdSource)); if (StateClassIdDest.HasValue) { Debug.Assert(Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)); } } }
private void CreateDTOffStratumCues(DTAnalyzer analyzer) { foreach (StateClassShape Shape in this.Shapes) { this.CreateIncomingDTOffStratumCues(Shape); this.CreateOutgoingDTOffStratumCues(Shape, analyzer); } }
private void PastePT(TransitionDiagramClipData cd, DTAnalyzer analyzer) { List <ProbabilisticTransitionClipData> AlreadyPasted = new List <ProbabilisticTransitionClipData>(); this.PastePTBetween(cd, AlreadyPasted); this.PastePTIncoming(cd, AlreadyPasted, analyzer); this.PastePTOutgoing(cd, AlreadyPasted, analyzer); }
private void RecordStateClassLocation(StateClassShape shape, DTAnalyzer analyzer) { Debug.Assert(this.WorkspaceRectangle.Contains(shape.Bounds)); DataRow row = analyzer.GetStateClassRow(this.m_StratumId, shape.StateClassIdSource); row[Strings.DATASHEET_DT_LOCATION_COLUMN_NAME] = RowColToLocation(shape.Row, shape.Column); }
private void RecordNewStateClassLocations(DTAnalyzer analyzer) { foreach (StateClassShape Shape in this.SelectedShapes) { if (!Shape.IsStatic) { this.RecordStateClassLocation(Shape, analyzer); } } }
private void PasteDTIncoming(TransitionDiagramClipData cd, DTAnalyzer analyzer) { foreach (TransitionDiagramClipDataEntry Entry in cd.Entries) { if (!this.m_ExplicitClasses.ContainsKey(Entry.ShapeData.StateClassIdSource)) { this.PasteDTIncoming(cd, Entry, analyzer); } } }
private void CreateOutgoingDTLines(StateClassShape fromShape, DTAnalyzer analyzer) { //If there is no destination state class then it is a transition-to-self if (!fromShape.StateClassIdDest.HasValue) { return; } StateClassShape ToShape = null; int? StratumIdActual = null; analyzer.ResolveStateClassStratum(fromShape.StratumIdSource, fromShape.StratumIdDest, fromShape.StateClassIdDest.Value, ref StratumIdActual); if (NullableUtilities.NullableIdsEqual(StratumIdActual, this.m_StratumId)) { //If the class was found in the current stratum then it will be in the //explicit lookups if the current stratum is explicit and the wildcard //lookups if it is not. if (this.m_StratumId.HasValue) { ToShape = this.m_ExplicitClasses[fromShape.StateClassIdDest.Value]; } else { ToShape = this.m_WildcardClasses[fromShape.StateClassIdDest.Value]; } } else { //If the class was not found in the current stratum it will be in the //wild card lookups if its stratum is wild. if (this.m_StratumId.HasValue && (!StratumIdActual.HasValue)) { ToShape = this.m_WildcardClasses[fromShape.StateClassIdDest.Value]; } } //If the class was not found or it is a transition-to-self then it is an //off stratum transition. Otherwise, add an outgoing line. if ((ToShape != null) && (ToShape != fromShape)) { DeterministicTransitionLine Line = new DeterministicTransitionLine(Constants.DETERMINISTIC_TRANSITION_LINE_COLOR); this.FillLineSegments(fromShape, ToShape, Line, BoxArrowDiagramConnectorMode.Horizontal); this.AddLine(Line); fromShape.OutgoingDTLines.Add(Line); ToShape.IncomingDTLines.Add(Line); } }
public override void Validate(object proposedValue, string columnName) { base.Validate(proposedValue, columnName); if (columnName == Strings.DATASHEET_DT_LOCATION_COLUMN_NAME) { if (!DTAnalyzer.IsValidLocation(proposedValue)) { throw new DataException(MessageStrings.ERROR_INVALID_CELL_ADDRESS); } } }
private void SaveSelection() { this.m_SelectedStateClasses.Clear(); foreach (StateClassShape Shape in this.Shapes) { if (Shape.IsSelected) { string k = DTAnalyzer.CreateStateClassLookupKey(Shape.StratumIdSource, Shape.StateClassIdSource); this.m_SelectedStateClasses.Add(k, Shape); } } }
private void RestoreSelection() { foreach (StateClassShape Shape in this.Shapes) { string k = DTAnalyzer.CreateStateClassLookupKey(Shape.StratumIdSource, Shape.StateClassIdSource); if (this.m_SelectedStateClasses.ContainsKey(k)) { Shape.IsSelected = true; } else { Shape.IsSelected = false; } } }
/// <summary> /// Overrides Validate /// </summary> /// <param name="data"></param> /// <param name="transferMethod"></param> /// <returns></returns> /// <remarks> /// While the incoming state class Ids can themselves be valid, they must also be valid within the context of the union of the /// incoming data and the existing data. In other words, each destination state class must point to a source state class within /// the same stratum. /// </remarks> public override void Validate(System.Data.DataTable proposedData, DataTransferMethod transferMethod) { base.Validate(proposedData, transferMethod); DataTable dtdata = this.GetData(); DTAnalyzer AnalyzerExisting = new DTAnalyzer(dtdata, this.Project); DTAnalyzer AnalyzerProposed = new DTAnalyzer(proposedData, this.Project); foreach (DataRow ProposedRow in proposedData.Rows) { int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(ProposedRow, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!StateClassIdDest.HasValue) { return; } //If the state class is not part of the incoming data then we need to see if it is part of the existing data, and //if it isn't then we can't continue. Note that if the import option is 'Overwrite' then the state class //will not appear in the existing data! bool ClassInClip = AnalyzerProposed.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value); bool ClassInExisting = AnalyzerExisting.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value); bool IsOverwrite = (transferMethod == SyncroSim.Core.DataTransferMethod.Overwrite); if (!ClassInClip) { if (IsOverwrite || (!ClassInExisting)) { AnalyzerExisting.ThrowDataException(StateClassIdDest.Value, true); } } //Also validate the location if (!DTAnalyzer.IsValidLocation(ProposedRow[Strings.DATASHEET_DT_LOCATION_COLUMN_NAME])) { throw new DataException(MessageStrings.ERROR_INVALID_CELL_ADDRESS); } } }
private bool ResolveProbabilisticTransitions(DTAnalyzer analyzer) { bool HasChanges = false; DataTable dt = this.GetDataSheet(Strings.DATASHEET_PT_NAME).GetData(); for (int Index = dt.Rows.Count - 1; Index >= 0; Index--) { DataRow dr = dt.Rows[Index]; if (dr.RowState == DataRowState.Deleted) { continue; } int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!analyzer.StateClassExists(StratumIdSource, StateClassIdSource)) { DataTableUtilities.DeleteTableRow(dt, dr); HasChanges = true; continue; } if (!StateClassIdDest.HasValue) { continue; } if (!analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)) { DataTableUtilities.DeleteTableRow(dt, dr); HasChanges = true; } } return(HasChanges); }
protected override void OnDropSelectedShapes(DiagramDragEventArgs e) { base.OnDropSelectedShapes(e); DTAnalyzer Analyzer = new DTAnalyzer(this.m_DTDataSheet.GetData(), this.m_DataFeed.Project); this.SaveSelection(); this.RecordNewStateClassLocations(Analyzer); this.InternalRefreshLookups(); this.InternalRefreshTransitionLines(); //DEVTODO: It would be better not to do this, but there is no obvious way to tell //if the user is about to drop the shapes they are dragging. Is there? this.m_DTDataSheet.BeginModifyRows(); this.m_DTDataSheet.EndModifyRows(); this.RestoreSelection(); this.Focus(); }
protected override void OnRowsModified(object sender, DataSheetRowEventArgs e) { base.OnRowsModified(sender, e); DTAnalyzer Analyzer = new DTAnalyzer(this.GetData(), this.Project); if (this.ResolveDeterministicTransitions(Analyzer)) { this.Changes.Add(new ChangeRecord(this, "DT OnRowsModified Modified DT Rows")); } if (this.ResolveProbabilisticTransitions(Analyzer)) { this.GetDataSheet(Strings.DATASHEET_PT_NAME).Changes.Add(new ChangeRecord(this, "DT OnRowsModified Deleted PT Rows")); } #if DEBUG this.VALIDATE_DETERMINISTIC_TRANSITIONS(); this.VALIDATE_PROBABILISTIC_TRANSITIONS(); #endif }
private void InternalRefreshTransitionLines() { this.ClearLines(); if (this.Shapes.Count() == 0) { return; } foreach (BoxDiagramShape Shape in this.Shapes) { Shape.ResetConnectorPoints(); } DTAnalyzer Analyzer = new DTAnalyzer(this.m_DTDataSheet.GetData(), this.m_DataFeed.Project); this.CreateDTLines(Analyzer); this.CreateDTOffStratumCues(Analyzer); this.CreatePTLines(Analyzer); this.CreatePTOffStratumCues(Analyzer); }
public override void Validate(System.Data.DataTable proposedData, DataTransferMethod transferMethod) { base.Validate(proposedData, transferMethod); DataSheet DeterministicSheet = this.GetDataSheet(Strings.DATASHEET_DT_NAME); DTAnalyzer Analyzer = new DTAnalyzer(DeterministicSheet.GetData(), this.Project); const string IMPORT_ERROR = "Error importing transitions." + "\r\n" + "\r\n" + "Note that each probabilistic transition's source and destination state class must exist in " + "this scenario's deterministic transition records. More information:" + "\r\n" + "\r\n"; try { foreach (DataRow dr in proposedData.Rows) { int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetPTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!Analyzer.CanResolveStateClass(StratumIdSource, StratumIdSource, StateClassIdSource)) { Analyzer.ThrowDataException(StateClassIdSource, false); } if (StateClassIdDest.HasValue) { if (!Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)) { Analyzer.ThrowDataException(StateClassIdDest.Value, true); } } } } catch (DataException ex) { throw new DataException(IMPORT_ERROR + ex.Message); } }
private void PasteStateClassesReplace(TransitionDiagramClipDataEntry entry, DTAnalyzer analyzer) { DataRow dr = analyzer.GetStateClassRow(this.m_StratumId, entry.ShapeData.StateClassIdSource); if (entry.ShapeData.AgeMin.HasValue) { dr[Strings.DATASHEET_AGE_MIN_COLUMN_NAME] = entry.ShapeData.AgeMin.Value; } else { dr[Strings.DATASHEET_AGE_MIN_COLUMN_NAME] = DBNull.Value; } if (entry.ShapeData.AgeMax.HasValue) { dr[Strings.DATASHEET_AGE_MAX_COLUMN_NAME] = entry.ShapeData.AgeMax.Value; } else { dr[Strings.DATASHEET_AGE_MAX_COLUMN_NAME] = DBNull.Value; } }
private bool ResolveDeterministicTransitions(DTAnalyzer analyzer) { bool HasChanges = false; DataTable dt = this.GetData(); for (int Index = dt.Rows.Count - 1; Index >= 0; Index--) { DataRow dr = dt.Rows[Index]; if (dr.RowState == DataRowState.Deleted) { continue; } int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(dr, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!StateClassIdDest.HasValue) { continue; } if (!analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)) { dr[Strings.DATASHEET_DT_STRATUMIDDEST_COLUMN_NAME] = DBNull.Value; dr[Strings.DATASHEET_DT_STATECLASSIDDEST_COLUMN_NAME] = DBNull.Value; HasChanges = true; } } return(HasChanges); }
private void CreateOutgoingPTOffStratumCues(StateClassShape shape, DTAnalyzer analyzer) { foreach (Transition t in shape.OutgoingPT) { //If it is a transition-to-self then it is not an off-stratum transition if (!t.StateClassIdDestination.HasValue) { continue; } int?StratumIdActual = null; analyzer.ResolveStateClassStratum( t.StratumIdSource, t.StratumIdDestination, t.StateClassIdDestination.Value, ref StratumIdActual); //If the class was found in the current stratum then it is not an off-stratum transition if (NullableUtilities.NullableIdsEqual(StratumIdActual, this.m_StratumId)) { continue; } //If the class was found in the wild card stratum then it is not an off-stratum transition if (!StratumIdActual.HasValue) { continue; } this.AddLine(this.CreateOutgoingPTOffStratumCue(shape, t)); } }
public override void Validate(DataRow proposedRow, DataTransferMethod transferMethod) { base.Validate(proposedRow, transferMethod); int?StratumIdSource = null; int StateClassIdSource = 0; int?StratumIdDest = null; int?StateClassIdDest = null; DTAnalyzer.GetDTFieldValues(proposedRow, ref StratumIdSource, ref StateClassIdSource, ref StratumIdDest, ref StateClassIdDest); if (!StateClassIdDest.HasValue) { return; } if (StateClassIdDest.Value == StateClassIdSource) { if (!StratumIdDest.HasValue) { return; } if (NullableUtilities.NullableIdsEqual(StratumIdSource, StratumIdDest)) { return; } } DTAnalyzer Analyzer = new DTAnalyzer(this.GetData(), this.Project); if (!Analyzer.CanResolveStateClass(StratumIdSource, StratumIdDest, StateClassIdDest.Value)) { Analyzer.ThrowDataException(StateClassIdDest.Value, true); } }
private void PasteTransitions(TransitionDiagramClipData cd, bool pasteAll, bool pasteBetween, bool pasteDeterministic, bool pasteProbabilistic, DTAnalyzer analyzer) { if (pasteAll) { if (pasteDeterministic) { this.PasteDTIncoming(cd, analyzer); } if (pasteProbabilistic) { this.PastePT(cd, analyzer); } } else if (pasteBetween) { if (pasteProbabilistic) { List <ProbabilisticTransitionClipData> AlreadyPasted = new List <ProbabilisticTransitionClipData>(); this.PastePTBetween(cd, AlreadyPasted); } } }
/// <summary> /// Pastes any incoming deterministic transitions /// </summary> /// <param name="cd"></param> /// <param name="entry"></param> /// <remarks> /// Create all incoming deterministic transitions described in the specified clipboard entry as follows: /// /// (1.) We are not going to look at any state classes that are in the clipboard since the transitions for these state /// classes were established when the state classes paste was performed. /// /// (2.) If the transition is coming from a state class in the same diagram (but that state class is not found in the clipboard) then we /// can create that transition. But we can only do this if the source state class does not have a transition to another state class. /// /// (3.) If it is a transition coming from an off-stratum state class, make sure the state class still exists in the source stratum. And, /// as with a state class in this diagram, only do this if the source state class does not have a transition to another state class. /// </remarks> private void PasteDTIncoming(TransitionDiagramClipData cd, TransitionDiagramClipDataEntry entry, DTAnalyzer analyzer) { foreach (DeterministicTransitionClipData t in entry.IncomingDT) { if (!ClipContainsStateClass(cd, t.StateClassIdSource)) { if (this.m_ExplicitClasses.ContainsKey(t.StateClassIdSource)) { DataRow dr = analyzer.GetStateClassRow(this.m_StratumId, t.StateClassIdSource); if (IsDTToSelf(dr)) { dr[Strings.DATASHEET_DT_STATECLASSIDDEST_COLUMN_NAME] = entry.ShapeData.StateClassIdSource; } } else { DataRow dr = analyzer.GetStateClassRow(t.StratumIdSource, t.StateClassIdSource); if (dr != null && IsDTToSelf(dr)) { dr[Strings.DATASHEET_DT_STATECLASSIDDEST_COLUMN_NAME] = entry.ShapeData.StateClassIdSource; dr[Strings.DATASHEET_DT_STRATUMIDDEST_COLUMN_NAME] = this.m_StratumId; } } } } }
private void PastePTOutgoing(TransitionDiagramClipData cd, List <ProbabilisticTransitionClipData> alreadyPasted, DTAnalyzer analyzer) { foreach (TransitionDiagramClipDataEntry Entry in cd.Entries) { this.PastePTOutgoing(Entry, alreadyPasted, analyzer); } }
private void PastePTOutgoing(TransitionDiagramClipDataEntry entry, List <ProbabilisticTransitionClipData> alreadyPasted, DTAnalyzer analyzer) { foreach (ProbabilisticTransitionClipData t in entry.OutgoingPT) { if (AlreadyPastedPT(t, alreadyPasted)) { continue; } int?StratumIdDest = null; if (t.StateClassIdDest.HasValue) { analyzer.ResolveStateClassStratum(t.StratumIdSource, t.StratumIdDest, t.StateClassIdDest.Value, ref StratumIdDest); } this.CreatePTRecord(this.m_StratumId, entry.ShapeData.StateClassIdSource, StratumIdDest, t.StateClassIdDest, t.TransitionTypeId, t.Probability, t.Proportion, t.AgeMin, t.AgeMax, t.AgeRelative, t.AgeReset, t.TstMin, t.TstMax, t.TstRelative); alreadyPasted.Add(t); } }