Revision a2c79680

View differences:

ide/org.omnetpp.sequencechart/src/org/omnetpp/sequencechart/widgets/SequenceChart.java
848 848
	public org.omnetpp.common.engine.BigDecimal getViewportRightSimulationTime() {
849 849
        return getSimulationTimeForViewportCoordinate(getViewportWidth());
850 850
	}
851
	
852
	public IEvent getLargestEndEvent() {
853
		return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
854
	}
851 855

  
852 856
	/*************************************************************************************
853 857
	 * SCROLLING, GOTOING
......
865 869

  
866 870
		if (eventLog != null && !eventLog.isEmpty()) {
867 871
		    // don't go after the very end
868
			if (eventLog.getLastEvent().getSimulationTime().less(getViewportRightSimulationTime())) {
872
			org.omnetpp.common.engine.BigDecimal time = getLargestEndEvent().getSimulationTime();
873
			if(EventLengthMode.DURATION == getEventLengthMode()) {
874
				time.add(getLargestEndEvent().getEventEntry().getDuration());
875
			}
876
			if (time.less(getViewportRightSimulationTime())) {
869 877
				this.fixPointViewportCoordinate = getViewportWidth();
870
				sequenceChartFacade.relocateTimelineCoordinateSystem(eventLog.getLastEvent());
878
				sequenceChartFacade.relocateTimelineCoordinateSystem(getLargestEndEvent());
871 879
			}
872 880

  
873 881
			// don't go before the very beginning
......
1426 1434
                        setShowTransmissionDurations(sequenceChartState.showTransmissionDurations);
1427 1435

  
1428 1436
                    // restore timeline mode
1429
                    if (sequenceChartState.timelineMode != null)
1437
                    if (sequenceChartState.timelineMode != null) {
1430 1438
                        setTimelineMode(sequenceChartState.timelineMode);
1439
                        if (sequenceChartState.timelineMode == TimelineMode.REAL_TIME) {
1440
                        	setEventLengthMode(EventLengthMode.COMPLEXITY);
1441
                        }
1442
                    }
1443

  
1431 1444

  
1432 1445
					return true;
1433 1446
				}
......
2610 2623
			// draw rectangle after the very end of the simulation
2611 2624
			if (sequenceChartFacade.IEvent_getNextEvent(endEventPtr) == 0) {
2612 2625
				x = clip.right();
2613
				long largestEvent = sequenceChartFacade.getLargestEndtimeInEventRange(startEventPtr,endEventPtr);
2626
				long largestEvent = getLargestEndEvent().getCPtr();
2627
				
2614 2628
				long endX = getEventXViewportCoordinate(largestEvent) + getEventLength(largestEvent) - 2;
2615 2629

  
2616 2630
				if (x != endX)
......
3008 3022
	private void drawTicks(Graphics graphics, int viewportHeigth) {
3009 3023
        calculateTicks(getViewportWidth());
3010 3024

  
3011
        IEvent lastEvent = eventLog.getLastEvent();
3025
        IEvent lastEvent = getLargestEndEvent();
3012 3026
        org.omnetpp.common.engine.BigDecimal endSimulationTime;
3013 3027
        
3014 3028
		if (getTimelineMode() == TimelineMode.REAL_TIME){
3015
			//TODO Cache this
3016
			lastEvent = sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr()));
3017 3029
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : new org.omnetpp.common.engine.BigDecimal(lastEvent.getEarliestProcessingTime()/1000000.0);
3018
		//} else if (getEventLengthMode() == EventLengthMode.DURATION){
3019
		//	endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime().add(lastEvent.getEventEntry().getDuration());
3030
		} else if (getEventLengthMode() == EventLengthMode.DURATION){
3031
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime().add(lastEvent.getEventEntry().getDuration()); //TODO readd duration
3020 3032
		} else {
3021 3033
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime();
3022 3034
		}
......
3024 3036
		for (BigDecimal tick : ticks) {
3025 3037
			// BigDecimal to double conversions loose precision both in Java and C++ but we must stick to the one in C++
3026 3038
			// so that strange problems do not occur (think of comparing the tick's time to the last known simulation time)
3027
		    org.omnetpp.common.engine.BigDecimal simulationTime = new org.omnetpp.common.engine.BigDecimal(tick.doubleValue());
3028
		    if (endSimulationTime.less(simulationTime))
3039
			
3040
			org.omnetpp.common.engine.BigDecimal simulationTime = new org.omnetpp.common.engine.BigDecimal(tick.doubleValue());
3041
			if (endSimulationTime.less(simulationTime))
3029 3042
		        simulationTime = endSimulationTime;
3030 3043
			drawTick(graphics, viewportHeigth, TICK_LINE_COLOR, GUTTER_BACKGROUND_COLOR, tick, (int)getViewportCoordinateForSimulationTime(simulationTime), false);
3031 3044
		}
......
3661 3674
            sequenceChartFacade.IEvent_getSimulationTime(consequenceEventPtr).subtract(transmissionDelay);
3662 3675

  
3663 3676
        // check simulation times for being out of range
3664
        org.omnetpp.common.engine.BigDecimal lastEventSimulationTime = eventLog.getLastEvent().getSimulationTime();
3677
        org.omnetpp.common.engine.BigDecimal lastEventSimulationTime = getLargestEndEvent().getSimulationTime();
3665 3678
        if (t3.greater(lastEventSimulationTime) || t4.greater(lastEventSimulationTime) || t4.less(org.omnetpp.common.engine.BigDecimal.getZero()))
3666 3679
            return isReceptionStart;
3667 3680

  
......
3984 3997
    			long tleft = modX - TICK_SPACING;
3985 3998
    			long tright = modX + viewportWidth + TICK_SPACING;
3986 3999

  
3987
    			IEvent lastEvent = eventLog.getLastEvent();
4000
    			IEvent lastEvent = getLargestEndEvent();
3988 4001

  
3989 4002
    			if (lastEvent != null) {
3990 4003
    				BigDecimal endSimulationTime;
3991 4004
    				if (getTimelineMode() == TimelineMode.REAL_TIME){
3992
    					lastEvent = sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr()));
3993 4005
    					endSimulationTime = lastEvent == null ? BigDecimal.ZERO : new BigDecimal(lastEvent.getEarliestProcessingTime()/1000000);
3994 4006
    				} else if (getEventLengthMode() == EventLengthMode.DURATION){
3995 4007
    					endSimulationTime = lastEvent == null ? BigDecimal.ZERO : lastEvent.getSimulationTime().toBigDecimal().add(lastEvent.getEventEntry().getDuration().toBigDecimal());
......
4020 4032
			return BigDecimal.ZERO;
4021 4033

  
4022 4034
		// query the simulation time for the given coordinate
4023
		BigDecimal simulationTime = getSimulationTimeForViewportCoordinate(x).toBigDecimal();
4024

  
4035
		
4036
		BigDecimal simulationTime = getSimulationTimeForViewportCoordinate(x, getEventLengthMode() == EventLengthMode.DURATION).toBigDecimal();
4037
		
4025 4038
		// defines the range of valid simulation times for the given tick range
4026
		BigDecimal tMin = getSimulationTimeForViewportCoordinate(x - tickRange / 2).toBigDecimal();
4027
		BigDecimal tMax = getSimulationTimeForViewportCoordinate(x + tickRange / 2).toBigDecimal();
4039
		BigDecimal tMin = getSimulationTimeForViewportCoordinate(x - tickRange / 2, getEventLengthMode() == EventLengthMode.DURATION).toBigDecimal();
4040
		BigDecimal tMax = getSimulationTimeForViewportCoordinate(x + tickRange / 2, getEventLengthMode() == EventLengthMode.DURATION).toBigDecimal();
4028 4041

  
4029 4042
		// check some invariants
4030 4043
		// originally we were checking these invariants, but it is impossible to always make these hold
......
4037 4050

  
4038 4051
		if (tMax.compareTo(simulationTime) < 0)
4039 4052
		    tMax = simulationTime;
4040
		Assert.isTrue(tMin.compareTo(tMax) <= 0);
4053
		//Assert.isTrue(tMin.compareTo(tMax) <= 0);
4041 4054

  
4042 4055
		// the idea is to round the simulation time to the shortest (in terms of digits) value
4043 4056
		// as long as it still fits into the range of min and max
src/eventlog/sequencechartfacade.cc
44 44

  
45 45
    biggestEarliestProcessingTime = 0;
46 46

  
47
    biggestEndTimeEvent = NULL;
48

  
47 49
    cachedParallelSet.clear();
48 50
    cachedCriticalPath.clear();
49 51
}
......
459 461
        break;
460 462
        case SIMULATION_TIME:
461 463
            {
462
                simtime_t lastEventSimulationTime = eventLog->getLastEvent()->getSimulationTime();
464
                IEvent* largestEvent = (IEvent*) getLargestEndtimeInEventRange((ptr_t)(eventLog->getFirstEvent()),(ptr_t)(eventLog->getLastEvent()), upperLimit);
465
                simtime_t lastEventSimulationTime= largestEvent->getSimulationTime() + largestEvent->getEventEntry()->duration;
463 466
                simulationTime = max(BigDecimal::Zero, min(lastEventSimulationTime, timelineCoordinate + timelineCoordinateOriginSimulationTime));
464 467
            }
465 468
            break;
......
501 504

  
502 505
    Assert(!simulationTime.isNaN());
503 506
    Assert(simulationTime >= BigDecimal::Zero);
504
    if (timelineMode != REAL_TIME)
507
    /*if (timelineMode != REAL_TIME)
505 508
        Assert(simulationTime <= eventLog->getLastEvent()->getSimulationTime());
506

  
509
    */
507 510
    return simulationTime;
508 511
}
509 512

  
......
515 518
        return 0;
516 519

  
517 520
    Assert(simulationTime >= BigDecimal::Zero);
518
    if (timelineMode != REAL_TIME)
521
    /*if (timelineMode != REAL_TIME)
519 522
        Assert(simulationTime <= eventLog->getLastEvent()->getSimulationTime());
520

  
523
    */
521 524

  
522 525
    double timelineCoordinate;
523 526

  
......
990 993
 * Returns the event with the largest calculated earliest Processing time in REAL_TIME mode
991 994
 * or the largest endtime in other modes within the given event range.
992 995
 */
993
ptr_t SequenceChartFacade::getLargestEndtimeInEventRange(ptr_t startEventPtr, ptr_t endEventPtr) {
994
    IEvent *startEvent = (IEvent *)startEventPtr;
995
    IEvent *endEvent = (IEvent *)endEventPtr;
996
ptr_t SequenceChartFacade::getLargestEndtimeInEventRange(ptr_t startEventPtr,
997
        ptr_t endEventPtr, bool duration)
998
{
999
    IEvent *startEvent = (IEvent *) startEventPtr;
1000
    IEvent *endEvent = (IEvent *) endEventPtr;
996 1001
    switch (timelineMode)
997 1002
    {
998 1003
    case REAL_TIME:
999 1004
    {
1000 1005
        //Use cached result when range contains all events
1001
        if(startEvent == eventLog->getFirstEvent() && endEvent == eventLog->getLastEvent()) {
1002
            return (ptr_t)biggestEarliestProcessingTimeEvent;
1006
        if (startEvent == eventLog->getFirstEvent() && endEvent
1007
                == eventLog->getLastEvent())
1008
        {
1009
            return (ptr_t) biggestEarliestProcessingTimeEvent;
1003 1010
        }
1004 1011

  
1005 1012
        long largest = 0;
1006 1013
        IEvent* largestEvent = startEvent;
1007 1014

  
1008
        for (IEvent* current = startEvent; current; current = current->getNextEvent()) {
1015
        for (IEvent* current = startEvent; current; current
1016
                = current->getNextEvent())
1017
        {
1009 1018
            long temp = current->getEarliestProcessingTime();
1010
            if (temp > largest) {
1019
            if (temp > largest)
1020
            {
1011 1021
                largest = temp;
1012 1022
                largestEvent = current;
1013 1023
            }
1014
            if (current==endEvent) {
1024
            if (current == endEvent)
1025
            {
1015 1026
                break;
1016 1027
            }
1017 1028
        }
......
1022 1033
    case STEP:
1023 1034
    case NONLINEAR:
1024 1035
    default:
1025
        return endEventPtr;
1036
    {
1037
        if (!duration) {
1038
            return endEventPtr;
1039
        }
1040
        //Use cached result when range contains all events
1041
        if (startEvent == eventLog->getFirstEvent() && endEvent
1042
                == eventLog->getLastEvent() && biggestEndTimeEvent != NULL)
1043
        {
1044
            return (ptr_t) biggestEndTimeEvent;
1045
        }
1046
        simtime_t largest = 0;
1047
        IEvent* largestEvent = endEvent;
1048

  
1049
        for (IEvent* current = endEvent; current; current
1050
                = current->getPreviousEvent())
1051
        {
1052
            simtime_t temp = current->getSimulationTime()
1053
                    + current->getEventEntry()->duration;
1054
            if (temp > largest)
1055
            {
1056
                largest = temp;
1057
                largestEvent = current;
1058
            }
1059
            if (current == startEvent)
1060
            {
1061
                break;
1062
            }
1063
        }
1064
        if (startEvent == eventLog->getFirstEvent() && endEvent
1065
                == eventLog->getLastEvent())
1066
        {
1067
            biggestEndTimeEvent = largestEvent;
1068
        }
1069

  
1070
        return (ptr_t) largestEvent;
1071
    }
1026 1072
    }
1027 1073

  
1028 1074
}
1075

  
src/eventlog/sequencechartfacade.h
55 55
        simtime_t biggestEarliestProcessingTime;
56 56
        IEvent* biggestEarliestProcessingTimeEvent;
57 57

  
58
        IEvent* biggestEndTimeEvent;
59

  
58 60
        std::set<ptr_t> cachedParallelSet;
59 61
        IEvent* lastSelected;
60 62

  
......
126 128

  
127 129
        bool isOnCriticalPath(IEvent* event);
128 130

  
129
        ptr_t getLargestEndtimeInEventRange(ptr_t startEventPtr, ptr_t endEventPtr);
131
        ptr_t getLargestEndtimeInEventRange(ptr_t startEventPtr, ptr_t endEventPtr, bool duration=false);
130 132

  
131 133
        /**
132 134
         * Timeline coordinate can be given in the range (-infinity, +infinity).

Also available in: Unified diff