Commit f270c074 authored by Simon Tenbusch's avatar Simon Tenbusch

[sequencechart] -implementing second event order

		- fixing bugs introduced due to second event order
parent 9bd9afa7
......@@ -125,7 +125,7 @@ public class SequenceChart
extends CachingCanvas
implements IVirtualContentWidget<IEvent>, ISelectionProvider, IEventLogChangeListener
{
private static final boolean debug = false;
private static final boolean debug = true;
private static final boolean debug2 = true;
public static final String STATE_PROPERTY = "SequenceChartState";
......@@ -432,7 +432,7 @@ public class SequenceChart
int moduleId = event.getModuleId();
while (event != null) {
event = event.getPreviousEvent();
event = getPreviousEventAccordingToTimelineMode(event);
if (event != null && moduleId == event.getModuleId()) {
gotoClosestElement(event);
......@@ -466,7 +466,7 @@ public class SequenceChart
int moduleId = event.getModuleId();
while (event != null) {
event = event.getNextEvent();
event = getNextEventAccordingToTimelineMode(event);
if (event != null && moduleId == event.getModuleId()) {
gotoClosestElement(event);
......@@ -877,7 +877,11 @@ public class SequenceChart
}
public IEvent getLargestEndEvent() {
return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
if(getTimelineMode() == SequenceChart.TimelineMode.REAL_TIME) {
return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEventRealTime().getCPtr(),eventLog.getLastEventRealTime().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
} else {
return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
}
}
/*************************************************************************************
......@@ -931,7 +935,7 @@ public class SequenceChart
eventPtrRange = getFirstLastEventPtrForViewportRange(0, getViewportWidth());
if (eventPtrRange != null && eventPtrRange[0] != 0 && eventPtrRange[1] != 0 &&
(sequenceChartFacade.IEvent_getPreviousEvent(eventPtrRange[0]) != 0 || sequenceChartFacade.IEvent_getNextEvent(eventPtrRange[1]) != 0))
(getPreviousEventPtrAccordingToTimelineMode(eventPtrRange[0]) != 0 || getNextEventPtrAccordingToTimelineMode(eventPtrRange[1]) != 0))
{
long numberOfElements = eventLog.getApproximateNumberOfEvents();
horizontalBar.setMaximum((int)Math.max(numberOfElements, 1E+6));
......@@ -1060,16 +1064,16 @@ public class SequenceChart
if (startEventPtr != 0 && endEventPtr != 0) {
// look one event backward
long previousEventPtr = sequenceChartFacade.IEvent_getPreviousEvent(startEventPtr);
long previousEventPtr = getPreviousEventPtrAccordingToTimelineMode(startEventPtr);
if (previousEventPtr != 0)
startEventPtr = previousEventPtr;
// and forward so that one additional event scrolling can be done with less distraction
long nextEventPtr = sequenceChartFacade.IEvent_getNextEvent(endEventPtr);
long nextEventPtr = getNextEventPtrAccordingToTimelineMode(endEventPtr);
if (nextEventPtr != 0)
endEventPtr = nextEventPtr;
for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
if (eventPtr == event.getCPtr())
found = true;
......@@ -1680,13 +1684,13 @@ public class SequenceChart
EventLogEntry startEventLogEntry = null;
if (findTextDialog.isBackward()) {
event = event.getPreviousEvent();
event = getPreviousEventAccordingToTimelineMode(event);
if (event == null)
return;
startEventLogEntry = event.getEventLogEntry(event.getNumEventLogEntries() - 1);
}
else {
event = event.getNextEvent();
event = getNextEventAccordingToTimelineMode(event);
if (event == null)
return;
startEventLogEntry = event.getEventEntry();
......@@ -1784,7 +1788,7 @@ public class SequenceChart
if (debug)
Debug.println("Collecting axis modules for events using event range: " + sequenceChartFacade.IEvent_getEventNumber(startEventPtr) + " -> " + sequenceChartFacade.IEvent_getEventNumber(endEventPtr));
for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
if (!isInitializationEvent(eventPtr))
axisModuleIds.add(sequenceChartFacade.IEvent_getModuleId(eventPtr));
......@@ -2317,12 +2321,12 @@ public class SequenceChart
// and focus to the range of those events
int distance = 20;
while (--distance > 0 || sequenceChartFacade.getTimelineCoordinate(referenceEvent) == sequenceChartFacade.getTimelineCoordinate(neighbourEvent)) {
IEvent newNeighbourEvent = neighbourEvent.getNextEvent();
IEvent newNeighbourEvent = getNextEventAccordingToTimelineMode(neighbourEvent);
if (newNeighbourEvent != null)
neighbourEvent = newNeighbourEvent;
else {
IEvent newReferenceEvent = referenceEvent.getPreviousEvent();
IEvent newReferenceEvent = getPreviousEventAccordingToTimelineMode(referenceEvent);
if (newReferenceEvent != null)
referenceEvent = newReferenceEvent;
......@@ -2406,6 +2410,9 @@ public class SequenceChart
eventLogInput.checkEventLogForChanges();
else {
internalErrorHappenedDuringPaint = true;
if(debug2) {
e.printStackTrace();
}
throw e;
}
}
......@@ -2624,8 +2631,7 @@ public class SequenceChart
// draw rectangles where simulation time has not elapsed between
// events
if (getTimelineMode() != TimelineMode.REAL_TIME) {
for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade
.IEvent_getNextEvent(eventPtr)) {
for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
if (previousEventPtr != -1) {
x = getEventXViewportCoordinate(eventPtr);
long previousX = getEventXViewportCoordinate(previousEventPtr);
......@@ -2647,7 +2653,7 @@ public class SequenceChart
}
}
// draw rectangle after the very end of the simulation
if (sequenceChartFacade.IEvent_getNextEvent(endEventPtr) == 0) {
if (getNextEventPtrAccordingToTimelineMode(endEventPtr) == 0) {
x = clip.right();
long largestEvent = getLargestEndEvent().getCPtr();
......@@ -2790,7 +2796,7 @@ public class SequenceChart
//HashMap<Integer, Integer> axisYtoLastX = new HashMap<Integer, Integer>();
// NOTE: navigating through next event takes care about leaving events out which are not in the filter's result
for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
if (isInitializationEvent(eventPtr))
drawEvent(graphics, eventPtr);
else {
......@@ -2880,6 +2886,48 @@ public class SequenceChart
return ((duration.doubleValue() - low.doubleValue())*1.0) / (high.doubleValue() - low.doubleValue());
}
private IEvent getNextEventAccordingToTimelineMode(IEvent event) {
if (event==null) {
return null;
}
if(getTimelineMode() == SequenceChart.TimelineMode.REAL_TIME) {
return event.getNextEventRealTime();
}
return event.getNextEvent();
}
private IEvent getPreviousEventAccordingToTimelineMode(IEvent event) {
if (event==null) {
return null;
}
if(getTimelineMode() == SequenceChart.TimelineMode.REAL_TIME) {
return event.getPreviousEventRealTime();
}
return event.getPreviousEvent();
}
private long getNextEventPtrAccordingToTimelineMode(long eventPtr) {
IEvent e = sequenceChartFacade.IEvent_getEvent(eventPtr);
if (e == null) {
System.out.println("nullpointer!");
}
e = getNextEventAccordingToTimelineMode(e);
if (e == null) {
return 0;
}
return e.getCPtr();
}
private long getPreviousEventPtrAccordingToTimelineMode(long eventPtr) {
IEvent e = getPreviousEventAccordingToTimelineMode(sequenceChartFacade.IEvent_getEvent(eventPtr));
if (e == null) {
return 0;
}
return e.getCPtr();
}
private boolean isOverlappingWithSelection(long eventPtr) {
IEvent ev = sequenceChartFacade.IEvent_getEvent(eventPtr);
if( ev.getEventEndEntry()== null) {
......@@ -3091,7 +3139,7 @@ public class SequenceChart
if (getTimelineMode() == TimelineMode.REAL_TIME){
endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : new org.omnetpp.common.engine.BigDecimal(lastEvent.getEarliestProcessingTime()/1000000.0);
} else if (getEventLengthMode() == EventLengthMode.DURATION){
endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime().add(lastEvent.getEventEntry().getDuration()); //TODO readd duration
endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime().add(lastEvent.getEventEntry().getDuration());
} else {
endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime();
}
......@@ -3933,25 +3981,37 @@ public class SequenceChart
if (eventLog == null || eventLog.isEmpty() || eventLog.getApproximateNumberOfEvents() == 0)
return new long[] {0, 0};
else {
//TODO: speed this up
//Fix for REAL_TIME Visualization:
//In this mode, events are not necessarily ordered in event number order so
//that an interval of visible events may not be correct.
//fix it by just returning the interval of all events.
if (getTimelineMode() == TimelineMode.REAL_TIME){
return new long[] { eventLog.getFirstEvent().getCPtr(), eventLog.getLastEvent().getCPtr() };
return new long[] { eventLog.getFirstEventRealTime().getCPtr(), eventLog.getLastEventRealTime().getCPtr() };
}
double leftTimelineCoordinate = getTimelineCoordinateForViewportCoordinate(x1);
double rightTimelineCoordinate = getTimelineCoordinateForViewportCoordinate(x2);
IEvent startEvent = sequenceChartFacade.getLastEventNotAfterTimelineCoordinate(leftTimelineCoordinate);
if (startEvent == null)
startEvent = eventLog.getFirstEvent();
if (startEvent == null) {
if (getTimelineMode() == TimelineMode.REAL_TIME) {
startEvent = eventLog.getFirstEventRealTime();
} else {
startEvent = eventLog.getFirstEvent();
}
}
IEvent endEvent = sequenceChartFacade.getFirstEventNotBeforeTimelineCoordinate(rightTimelineCoordinate);
if (endEvent == null)
endEvent = eventLog.getLastEvent();
if (endEvent == null) {
if (getTimelineMode() == TimelineMode.REAL_TIME) {
endEvent = eventLog.getLastEventRealTime();
} else {
endEvent = eventLog.getLastEvent();
}
}
return new long[] {startEvent == null ? 0 : startEvent.getCPtr(), endEvent == null ? 0 : endEvent.getCPtr()};
}
......@@ -3989,10 +4049,12 @@ public class SequenceChart
}
private boolean isInitializationEvent(long eventPtr) {
if(eventPtr==0) return false;
return sequenceChartFacade.IEvent_getEventNumber(eventPtr) == 0;
}
private boolean isInitializationEvent(IEvent event) {
if (event==null) return false;
return event.getEventNumber() == 0;
}
......@@ -4733,7 +4795,7 @@ public class SequenceChart
long endEventPtr = eventPtrRange[1];
if (startEventPtr != 0 && endEventPtr != 0) {
for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
int x = (int)getEventXViewportCoordinate(eventPtr);
int length = getEventLength(eventPtr);
if (isInitializationEvent(eventPtr)) {
......@@ -5067,7 +5129,7 @@ public class SequenceChart
return; // Legacy, no duration
}
org.omnetpp.common.engine.BigDecimal minimum = selected.getSimulationTime().add(selected.getEventEntry().getDuration());
for (IEvent event = eventLog.getFirstEvent(); event != null; event = event.getNextEvent()) {
for (IEvent event = eventLog.getFirstEvent(); event != null; event = getNextEventAccordingToTimelineMode(event)) {
if (event.getSimulationTime().greaterOrEqual(selected.getSimulationTime())) {
if(minimum.greater(event.getSimulationTime().add(event.getEventEntry().getDuration()))) {
minimum = event.getSimulationTime().add(event.getEventEntry().getDuration());
......
......@@ -321,8 +321,8 @@ IEvent *SequenceChartFacade::getLastEventNotAfterTimelineCoordinate(double timel
{
IEvent* res = eventLog->getFirstEventRealTime();
for (IEvent *current = eventLog->getFirstEventRealTime(); current; current = current->getNextEventRealTime()) {
if ((double) current->getEarliestStartTime() / 1000000.0 < timelineCoordinate) {
if (current->getEarliestStartTime() > res->getEarliestStartTime()) {
if ((double) current->getEarliestProcessingTime() / 1000000.0 < timelineCoordinate) {
if (current->getEarliestProcessingTime() > res->getEarliestProcessingTime()) {
res = current;
}
} else {
......@@ -432,7 +432,11 @@ void SequenceChartFacade::extractSimulationTimesAndTimelineCoordinates(
}
// linear approximation between two enclosing events
nextEvent = event ? event->getNextEvent() : eventLog->getFirstEvent();
if(timelineMode==REAL_TIME) {
nextEvent = event ? event->getNextEventRealTime() : eventLog->getFirstEventRealTime();
} else {
nextEvent = event ? event->getNextEvent() : eventLog->getFirstEvent();
}
if (nextEvent) {
if(timelineMode==REAL_TIME) {
......@@ -601,7 +605,7 @@ std::vector<ptr_t> *SequenceChartFacade::getModuleMethodBeginEntries(ptr_t start
Assert(endEvent);
std::vector<ptr_t> *moduleMethodBeginEntries = new std::vector<ptr_t>();
for (IEvent *event = startEvent;; event = event->getNextEvent()) {
for (IEvent *event = startEvent; event; event = timelineMode==REAL_TIME ? event->getNextEventRealTime() : event->getNextEvent()) {
eventLog->progress();
for (int i = 0; i < event->getNumEventLogEntries(); i++) {
......@@ -626,34 +630,26 @@ std::vector<ptr_t> *SequenceChartFacade::getIntersectingMessageDependencies(ptr_
Assert(endEvent);
std::set<ptr_t> messageDependencies;
eventnumber_t startEventNumber = startEvent->getEventNumber();
// TODO: LONG RUNNING OPERATION
// this might take a while if start and end events are far away from each other
// if not completed then some dependencies will not be included
for (IEvent *event = startEvent;; event = event->getNextEvent()) {
for (IEvent *event = startEvent; event; event = timelineMode==REAL_TIME ? event->getNextEventRealTime() : event->getNextEvent()) {
eventLog->progress();
IMessageDependencyList *causes = event->getCauses();
for (IMessageDependencyList::iterator it = causes->begin(); it != causes->end(); it++) {
IMessageDependency *messageDependency = *it;
if (messageDependency->getCauseEventNumber() < startEventNumber)
messageDependencies.insert((ptr_t)messageDependency);
}
IMessageDependencyList *consequences = event->getConsequences();
for (IMessageDependencyList::iterator it = consequences->begin(); it != consequences->end(); it++)
messageDependencies.insert((ptr_t)*it);
if (event == endEvent)
break;
}
std::vector<ptr_t> *result = new std::vector<ptr_t>;
result->resize(messageDependencies.size());
std::copy(messageDependencies.begin(), messageDependencies.end(), result->begin());
return result;
}
......@@ -958,16 +954,15 @@ bool SequenceChartFacade::isOnCriticalPath(IEvent* event) {
void SequenceChartFacade::calculateCriticalPath() {
long maxEarliestProcessingTime = 0;
IEvent* maxEarliestProcessingTimeEvent;
printf("bla1");
for (IEvent *current = eventLog->getFirstEvent(); current; current = current->getNextEvent()) {
simtime_t startTime = current->getSimulationTime();
int moduleId = current->getModuleId();
if(current->getEventEndEntry()) {
current->_earliestProcessingTime = current->getComplexity();
}
printf("%i \n", current->getEventNumber());
current->setCriticalPredecessor(eventLog->getFirstEvent());
for (IEvent *antecessor = eventLog->getFirstEvent(); antecessor; antecessor = antecessor->getNextEvent()) {
if(antecessor==current) {
break; //We have to consider earlier events only
......@@ -1015,8 +1010,8 @@ ptr_t SequenceChartFacade::getLargestEndtimeInEventRange(ptr_t startEventPtr,
case REAL_TIME:
{
//Use cached result when range contains all events
if (startEvent == eventLog->getFirstEvent() && endEvent
== eventLog->getLastEvent())
if (startEvent == eventLog->getFirstEventRealTime() && endEvent
== eventLog->getLastEventRealTime())
{
return (ptr_t) biggestEarliestProcessingTimeEvent;
}
......@@ -1025,7 +1020,7 @@ ptr_t SequenceChartFacade::getLargestEndtimeInEventRange(ptr_t startEventPtr,
IEvent* largestEvent = startEvent;
for (IEvent* current = startEvent; current; current
= current->getNextEvent())
= current->getNextEventRealTime())
{
long temp = current->getEarliestProcessingTime();
if (temp > largest)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment