Revision f270c074

View differences:

ide/org.omnetpp.sequencechart/src/org/omnetpp/sequencechart/widgets/SequenceChart.java
125 125
	extends CachingCanvas
126 126
	implements IVirtualContentWidget<IEvent>, ISelectionProvider, IEventLogChangeListener
127 127
{
128
	private static final boolean debug = false;
128
	private static final boolean debug = true;
129 129
	private static final boolean debug2 = true;
130 130

  
131 131
	public static final String STATE_PROPERTY = "SequenceChartState";
......
432 432
                            int moduleId = event.getModuleId();
433 433

  
434 434
                            while (event != null) {
435
                                event = event.getPreviousEvent();
435
                                event = getPreviousEventAccordingToTimelineMode(event);
436 436

  
437 437
                                if (event != null && moduleId == event.getModuleId()) {
438 438
                                    gotoClosestElement(event);
......
466 466
                            int moduleId = event.getModuleId();
467 467

  
468 468
                            while (event != null) {
469
                                event = event.getNextEvent();
469
                                event = getNextEventAccordingToTimelineMode(event);
470 470

  
471 471
                                if (event != null && moduleId == event.getModuleId()) {
472 472
                                    gotoClosestElement(event);
......
877 877
	}
878 878
	
879 879
	public IEvent getLargestEndEvent() {
880
		return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
880
		if(getTimelineMode() == SequenceChart.TimelineMode.REAL_TIME) {
881
			return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEventRealTime().getCPtr(),eventLog.getLastEventRealTime().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
882
		} else {
883
			return sequenceChartFacade.IEvent_getEvent(sequenceChartFacade.getLargestEndtimeInEventRange(eventLog.getFirstEvent().getCPtr(),eventLog.getLastEvent().getCPtr(), getEventLengthMode()==EventLengthMode.DURATION));
884
		}
881 885
	}
882 886

  
883 887
	/*************************************************************************************
......
931 935
			eventPtrRange = getFirstLastEventPtrForViewportRange(0, getViewportWidth());
932 936

  
933 937
		if (eventPtrRange != null && eventPtrRange[0] != 0 && eventPtrRange[1] != 0 &&
934
			(sequenceChartFacade.IEvent_getPreviousEvent(eventPtrRange[0]) != 0 || sequenceChartFacade.IEvent_getNextEvent(eventPtrRange[1]) != 0))
938
			(getPreviousEventPtrAccordingToTimelineMode(eventPtrRange[0]) != 0 || getNextEventPtrAccordingToTimelineMode(eventPtrRange[1]) != 0))
935 939
		{
936 940
			long numberOfElements = eventLog.getApproximateNumberOfEvents();
937 941
			horizontalBar.setMaximum((int)Math.max(numberOfElements, 1E+6));
......
1060 1064

  
1061 1065
            if (startEventPtr != 0 && endEventPtr != 0) {
1062 1066
        		// look one event backward
1063
        		long previousEventPtr = sequenceChartFacade.IEvent_getPreviousEvent(startEventPtr);
1067
        		long previousEventPtr = getPreviousEventPtrAccordingToTimelineMode(startEventPtr);
1064 1068
        		if (previousEventPtr != 0)
1065 1069
        			startEventPtr = previousEventPtr;
1066 1070

  
1067 1071
        		// and forward so that one additional event scrolling can be done with less distraction
1068
        		long nextEventPtr = sequenceChartFacade.IEvent_getNextEvent(endEventPtr);
1072
        		long nextEventPtr = getNextEventPtrAccordingToTimelineMode(endEventPtr);
1069 1073
        		if (nextEventPtr != 0)
1070 1074
        			endEventPtr = nextEventPtr;
1071 1075

  
1072
        		for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
1076
        		for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
1073 1077
        			if (eventPtr == event.getCPtr())
1074 1078
        				found = true;
1075 1079

  
......
1680 1684

  
1681 1685
                    EventLogEntry startEventLogEntry = null;
1682 1686
                    if (findTextDialog.isBackward()) {
1683
                        event = event.getPreviousEvent();
1687
                        event = getPreviousEventAccordingToTimelineMode(event);
1684 1688
                        if (event == null)
1685 1689
                            return;
1686 1690
                        startEventLogEntry = event.getEventLogEntry(event.getNumEventLogEntries() - 1);
1687 1691
                    }
1688 1692
                    else {
1689
                        event = event.getNextEvent();
1693
                        event = getNextEventAccordingToTimelineMode(event);
1690 1694
                        if (event == null)
1691 1695
                            return;
1692 1696
                        startEventLogEntry = event.getEventEntry();
......
1784 1788
            if (debug)
1785 1789
                Debug.println("Collecting axis modules for events using event range: " + sequenceChartFacade.IEvent_getEventNumber(startEventPtr) + " -> " + sequenceChartFacade.IEvent_getEventNumber(endEventPtr));
1786 1790

  
1787
            for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
1791
            for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
1788 1792
                if (!isInitializationEvent(eventPtr))
1789 1793
                    axisModuleIds.add(sequenceChartFacade.IEvent_getModuleId(eventPtr));
1790 1794

  
......
2317 2321
    	    // and focus to the range of those events
2318 2322
    	    int distance = 20;
2319 2323
            while (--distance > 0 || sequenceChartFacade.getTimelineCoordinate(referenceEvent) == sequenceChartFacade.getTimelineCoordinate(neighbourEvent)) {
2320
                IEvent newNeighbourEvent = neighbourEvent.getNextEvent();
2324
                IEvent newNeighbourEvent = getNextEventAccordingToTimelineMode(neighbourEvent);
2321 2325

  
2322 2326
                if (newNeighbourEvent != null)
2323 2327
                    neighbourEvent = newNeighbourEvent;
2324 2328
                else {
2325
                    IEvent newReferenceEvent = referenceEvent.getPreviousEvent();
2329
                    IEvent newReferenceEvent = getPreviousEventAccordingToTimelineMode(referenceEvent);
2326 2330

  
2327 2331
                    if (newReferenceEvent != null)
2328 2332
                        referenceEvent = newReferenceEvent;
......
2406 2410
				            eventLogInput.checkEventLogForChanges();
2407 2411
				        else {
2408 2412
	                        internalErrorHappenedDuringPaint = true;
2413
	                        if(debug2) {
2414
	                        	e.printStackTrace();
2415
	                        }
2409 2416
				            throw e;
2410 2417
				        }
2411 2418
				    }
......
2624 2631
			// draw rectangles where simulation time has not elapsed between
2625 2632
			// events
2626 2633
			if (getTimelineMode() != TimelineMode.REAL_TIME) {
2627
				for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade
2628
						.IEvent_getNextEvent(eventPtr)) {
2634
				for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
2629 2635
					if (previousEventPtr != -1) {
2630 2636
						x = getEventXViewportCoordinate(eventPtr);
2631 2637
						long previousX = getEventXViewportCoordinate(previousEventPtr);
......
2647 2653
				}
2648 2654
			}
2649 2655
			// draw rectangle after the very end of the simulation
2650
			if (sequenceChartFacade.IEvent_getNextEvent(endEventPtr) == 0) {
2656
			if (getNextEventPtrAccordingToTimelineMode(endEventPtr) == 0) {
2651 2657
				x = clip.right();
2652 2658
				long largestEvent = getLargestEndEvent().getCPtr();
2653 2659
				
......
2790 2796
			//HashMap<Integer, Integer> axisYtoLastX = new HashMap<Integer, Integer>();
2791 2797

  
2792 2798
			// NOTE: navigating through next event takes care about leaving events out which are not in the filter's result
2793
			for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
2799
			for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
2794 2800
                if (isInitializationEvent(eventPtr))
2795 2801
			        drawEvent(graphics, eventPtr);
2796 2802
			    else {
......
2880 2886
		return ((duration.doubleValue() - low.doubleValue())*1.0) / (high.doubleValue() - low.doubleValue());
2881 2887
	}
2882 2888
	
2889
	private IEvent getNextEventAccordingToTimelineMode(IEvent event) {
2890
		if (event==null) {
2891
			return null;
2892
		}
2893
		if(getTimelineMode() == SequenceChart.TimelineMode.REAL_TIME) {
2894
			return event.getNextEventRealTime();
2895
		}
2896
		return event.getNextEvent();
2897
	}
2898
	
2899
	private IEvent getPreviousEventAccordingToTimelineMode(IEvent event) {
2900
		if (event==null) {
2901
			return null;
2902
		}
2903
		if(getTimelineMode() == SequenceChart.TimelineMode.REAL_TIME) {
2904
			return event.getPreviousEventRealTime();
2905
		}
2906
		return event.getPreviousEvent();
2907
	}
2908
	
2909
	private long getNextEventPtrAccordingToTimelineMode(long eventPtr) {
2910
		IEvent e = sequenceChartFacade.IEvent_getEvent(eventPtr);
2911
		if (e == null) {
2912
			System.out.println("nullpointer!");
2913
			
2914
		}
2915
		e = getNextEventAccordingToTimelineMode(e);
2916
		if (e == null) {
2917
			return 0;
2918
		}
2919
		return e.getCPtr();
2920
	}
2921
	
2922
	private long getPreviousEventPtrAccordingToTimelineMode(long eventPtr) {
2923
		IEvent e = getPreviousEventAccordingToTimelineMode(sequenceChartFacade.IEvent_getEvent(eventPtr));
2924
		if (e == null) {
2925
			return 0;
2926
		}
2927
		return e.getCPtr();
2928
	}
2929
	
2930
	
2883 2931
	private boolean isOverlappingWithSelection(long eventPtr) {
2884 2932
		IEvent ev = sequenceChartFacade.IEvent_getEvent(eventPtr);
2885 2933
		if( ev.getEventEndEntry()== null) {
......
3091 3139
		if (getTimelineMode() == TimelineMode.REAL_TIME){
3092 3140
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : new org.omnetpp.common.engine.BigDecimal(lastEvent.getEarliestProcessingTime()/1000000.0);
3093 3141
		} else if (getEventLengthMode() == EventLengthMode.DURATION){
3094
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime().add(lastEvent.getEventEntry().getDuration()); //TODO readd duration
3142
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime().add(lastEvent.getEventEntry().getDuration());
3095 3143
		} else {
3096 3144
			endSimulationTime = lastEvent == null ? org.omnetpp.common.engine.BigDecimal.getZero() : lastEvent.getSimulationTime();
3097 3145
		}
......
3933 3981
		if (eventLog == null || eventLog.isEmpty() || eventLog.getApproximateNumberOfEvents() == 0)
3934 3982
			return new long[] {0, 0};
3935 3983
		else {
3936
			
3984
			//TODO: speed this up
3937 3985
			//Fix for REAL_TIME Visualization:
3938 3986
			//In this mode, events are not necessarily ordered in event number order so 
3939 3987
			//that an interval of visible events may not be correct.
3940 3988
			//fix it by just returning the interval of all events.
3941 3989
			if (getTimelineMode() == TimelineMode.REAL_TIME){
3942
				return new long[] { eventLog.getFirstEvent().getCPtr(), eventLog.getLastEvent().getCPtr() };
3990
				return new long[] { eventLog.getFirstEventRealTime().getCPtr(), eventLog.getLastEventRealTime().getCPtr() };
3943 3991
			}
3944 3992
			
3945 3993
    		double leftTimelineCoordinate = getTimelineCoordinateForViewportCoordinate(x1);
3946 3994
    		double rightTimelineCoordinate = getTimelineCoordinateForViewportCoordinate(x2);
3947 3995

  
3948 3996
    		IEvent startEvent = sequenceChartFacade.getLastEventNotAfterTimelineCoordinate(leftTimelineCoordinate);
3949
    		if (startEvent == null)
3950
    			startEvent = eventLog.getFirstEvent();
3997
    		if (startEvent == null) {
3998
    			if (getTimelineMode() == TimelineMode.REAL_TIME) {
3999
    				startEvent = eventLog.getFirstEventRealTime();
4000
    			} else {
4001
    				startEvent = eventLog.getFirstEvent();
4002
    			}
4003
    		}
4004
    			
3951 4005

  
3952 4006
    		IEvent endEvent = sequenceChartFacade.getFirstEventNotBeforeTimelineCoordinate(rightTimelineCoordinate);
3953
    		if (endEvent == null)
3954
    			endEvent = eventLog.getLastEvent();
4007
    		if (endEvent == null) {
4008
    			if (getTimelineMode() == TimelineMode.REAL_TIME) {
4009
        			endEvent = eventLog.getLastEventRealTime();
4010
    			} else {
4011
        			endEvent = eventLog.getLastEvent();
4012
    			}
4013
    		}
4014

  
3955 4015
            
3956 4016
    		return new long[] {startEvent == null ? 0 : startEvent.getCPtr(), endEvent == null ? 0 : endEvent.getCPtr()};
3957 4017
		}
......
3989 4049
    }
3990 4050

  
3991 4051
    private boolean isInitializationEvent(long eventPtr) {
4052
    	if(eventPtr==0) return false;
3992 4053
        return sequenceChartFacade.IEvent_getEventNumber(eventPtr) == 0;
3993 4054
    }
3994 4055

  
3995 4056
    private boolean isInitializationEvent(IEvent event) {
4057
    	if (event==null) return false;
3996 4058
        return event.getEventNumber() == 0;
3997 4059
    }
3998 4060

  
......
4733 4795
	                        long endEventPtr = eventPtrRange[1];
4734 4796

  
4735 4797
	                        if (startEventPtr != 0 && endEventPtr != 0) {
4736
    			            	for (long eventPtr = startEventPtr;; eventPtr = sequenceChartFacade.IEvent_getNextEvent(eventPtr)) {
4798
    			            	for (long eventPtr = startEventPtr; eventPtr!=0; eventPtr = getNextEventPtrAccordingToTimelineMode(eventPtr)) {
4737 4799
    			            	    int x = (int)getEventXViewportCoordinate(eventPtr);
4738 4800
    			            	    int length = getEventLength(eventPtr);
4739 4801
    			            	    if (isInitializationEvent(eventPtr)) {
......
5067 5129
					return; // Legacy, no duration
5068 5130
				}
5069 5131
				org.omnetpp.common.engine.BigDecimal minimum = selected.getSimulationTime().add(selected.getEventEntry().getDuration());
5070
				for (IEvent event = eventLog.getFirstEvent(); event != null; event = event.getNextEvent()) {
5132
				for (IEvent event = eventLog.getFirstEvent(); event != null; event = getNextEventAccordingToTimelineMode(event)) {
5071 5133
					if (event.getSimulationTime().greaterOrEqual(selected.getSimulationTime())) {
5072 5134
						if(minimum.greater(event.getSimulationTime().add(event.getEventEntry().getDuration()))) {
5073 5135
							minimum = event.getSimulationTime().add(event.getEventEntry().getDuration());
src/eventlog/sequencechartfacade.cc
321 321
        {
322 322
            IEvent* res = eventLog->getFirstEventRealTime();
323 323
            for (IEvent *current = eventLog->getFirstEventRealTime(); current; current = current->getNextEventRealTime()) {
324
                if ((double) current->getEarliestStartTime() / 1000000.0 < timelineCoordinate) {
325
                    if (current->getEarliestStartTime() > res->getEarliestStartTime()) {
324
                if ((double) current->getEarliestProcessingTime() / 1000000.0 < timelineCoordinate) {
325
                    if (current->getEarliestProcessingTime() > res->getEarliestProcessingTime()) {
326 326
                        res = current;
327 327
                    }
328 328
                } else {
......
432 432
    }
433 433

  
434 434
    // linear approximation between two enclosing events
435
    nextEvent = event ? event->getNextEvent() : eventLog->getFirstEvent();
435
    if(timelineMode==REAL_TIME) {
436
        nextEvent = event ? event->getNextEventRealTime() : eventLog->getFirstEventRealTime();
437
    } else {
438
        nextEvent = event ? event->getNextEvent() : eventLog->getFirstEvent();
439
    }
436 440

  
437 441
    if (nextEvent) {
438 442
        if(timelineMode==REAL_TIME) {
......
601 605
    Assert(endEvent);
602 606
    std::vector<ptr_t> *moduleMethodBeginEntries = new std::vector<ptr_t>();
603 607

  
604
    for (IEvent *event = startEvent;; event = event->getNextEvent()) {
608
    for (IEvent *event = startEvent; event; event = timelineMode==REAL_TIME ? event->getNextEventRealTime() : event->getNextEvent()) {
605 609
        eventLog->progress();
606 610

  
607 611
        for (int i = 0; i < event->getNumEventLogEntries(); i++) {
......
626 630
    Assert(endEvent);
627 631
    std::set<ptr_t> messageDependencies;
628 632
    eventnumber_t startEventNumber = startEvent->getEventNumber();
629

  
630 633
    // TODO: LONG RUNNING OPERATION
631 634
    // this might take a while if start and end events are far away from each other
632 635
    // if not completed then some dependencies will not be included
633
    for (IEvent *event = startEvent;; event = event->getNextEvent()) {
636
    for (IEvent *event = startEvent; event; event = timelineMode==REAL_TIME ? event->getNextEventRealTime() : event->getNextEvent()) {
634 637
        eventLog->progress();
635 638
        IMessageDependencyList *causes = event->getCauses();
636

  
637 639
        for (IMessageDependencyList::iterator it = causes->begin(); it != causes->end(); it++) {
638 640
            IMessageDependency *messageDependency = *it;
639

  
640 641
            if (messageDependency->getCauseEventNumber() < startEventNumber)
641 642
                messageDependencies.insert((ptr_t)messageDependency);
642 643
        }
643

  
644 644
        IMessageDependencyList *consequences = event->getConsequences();
645

  
646 645
        for (IMessageDependencyList::iterator it = consequences->begin(); it != consequences->end(); it++)
647 646
            messageDependencies.insert((ptr_t)*it);
648

  
649 647
        if (event == endEvent)
650 648
            break;
651 649
    }
652

  
653 650
    std::vector<ptr_t> *result = new std::vector<ptr_t>;
654 651
    result->resize(messageDependencies.size());
655 652
    std::copy(messageDependencies.begin(), messageDependencies.end(), result->begin());
656

  
657 653
    return result;
658 654
}
659 655

  
......
958 954
void SequenceChartFacade::calculateCriticalPath() {
959 955
    long maxEarliestProcessingTime = 0;
960 956
    IEvent* maxEarliestProcessingTimeEvent;
961

  
957
    printf("bla1");
962 958
    for (IEvent *current = eventLog->getFirstEvent(); current; current = current->getNextEvent()) {
963 959
        simtime_t startTime = current->getSimulationTime();
964 960
        int moduleId = current->getModuleId();
965 961
        if(current->getEventEndEntry()) {
966 962
            current->_earliestProcessingTime = current->getComplexity();
967 963
        }
968

  
964
        printf("%i \n", current->getEventNumber());
969 965
        current->setCriticalPredecessor(eventLog->getFirstEvent());
970

  
971 966
        for (IEvent *antecessor = eventLog->getFirstEvent(); antecessor; antecessor = antecessor->getNextEvent()) {
972 967
            if(antecessor==current) {
973 968
                break; //We have to consider earlier events only
......
1015 1010
    case REAL_TIME:
1016 1011
    {
1017 1012
        //Use cached result when range contains all events
1018
        if (startEvent == eventLog->getFirstEvent() && endEvent
1019
                == eventLog->getLastEvent())
1013
        if (startEvent == eventLog->getFirstEventRealTime() && endEvent
1014
                == eventLog->getLastEventRealTime())
1020 1015
        {
1021 1016
            return (ptr_t) biggestEarliestProcessingTimeEvent;
1022 1017
        }
......
1025 1020
        IEvent* largestEvent = startEvent;
1026 1021

  
1027 1022
        for (IEvent* current = startEvent; current; current
1028
                = current->getNextEvent())
1023
                = current->getNextEventRealTime())
1029 1024
        {
1030 1025
            long temp = current->getEarliestProcessingTime();
1031 1026
            if (temp > largest)

Also available in: Unified diff