• Ingen resultater fundet

JAVA program structure

This section describes the structure of the JAVA code constituting the railway simulator.

The JAVA code has been divided into seven packages with coherent content.

These packages are shown in figure 20.8.

Figure 20.8: JAVA packages

types contains a number of entity classes derived from the data types in the Types module in the model.

statics contains a number of classes derived from the Statics module in the model.

dynamics contains a number of classes derived from the Dynamics module in the model.

20.2 JAVA program structure 187

control contains a number of classes derived from the Control module in the model.

gui contains a number of classes used to make the graphical user interface (GUI) of the simulator. The configuration editor is not a part of this package.

editor contains a number of classes used to make the graphical user interface for the configuration editor part of the simulator.

exceptions contains a number of exception classes used for error handling.

The next sections describe in further details the content of these packages.

20.2.1 The types package

The most important classes in the types package are shown in figure 20.9 and in figure 20.10.

Figure 20.9 shows a number of different classes (mostly entity classes). Some of them are composite. The classes in figure 20.9 are easy recognized in theTypes module in the model.

Figure 20.9: The types package

Figure 20.10 shows some classes used in the control part for communication purpose. TheComMsgclass is used for sending messages between trains (TCCs) and SBs (SBCCs). The ComID class contains the ID of either a train or a SB while theMessageclass contains the actual message. The structure of the classes in figure 20.10 is easy recognized in theTypes module in the model.

188 Implementing the simulator

Figure 20.10: The types package

20.2.2 The statics package

The most important classes in the statics package are shown in figure 20.11.

The structure of the classes is easy recognized in theStaticspart of the model.

Statics is the main class in thestaticspackage. It gathers everything dealing with the configuration of the railway line.

Trains contains the configuration part that deals with trains only and functions to read from this configuration part.

Segs contains the configuration part that deals with segments only and func-tions to read from this configuration part.

SBs contains the configuration part that deals with SB only and functions to read from this configuration part.

ESAs contains the configuration part that deals with the two ESAs only and functions to read from this configuration part.

TrainData is an entity class containing the configuration data for one train.

SegData is an entity class containing the configuration data for one segment.

20.2 JAVA program structure 189

Figure 20.11: The statics package

SBData is an entity class containing the configuration data for one SB.

ESAData is an entity class containing the configuration data for both ESAs.

20.2.3 The dynamics package

The most important classes in the dynamics package are shown in figure 20.12.

The structure of the classes is easy recognized in the Dynamics part of the model.

Figure 20.12: The dynamics package

Dynamics is the main class in the dynamicspackage. It gathers everything

190 Implementing the simulator

dealing with the physical state of the railway line.

TrainDyn contains the part of the physical state that deals with trains only, functions updating the position and speed of the trains and functions to read from the states.

SBDyn contains the part of the physical state that deals with SBs only and functions to read from the states.

TrainStates contains the physical states of all the trains in a Hasbtable.

SBStates contains the physical states of all the SBs in a Hasbtable.

TrainState is an entity class containing the physical state of one train. The TrainState objects are stored in theTrainStatesobject.

SBState is an entity class containing the physical state of one SB. TheSBState objects are stored in the SBStatesobject.

20.2.4 The control package

The most important classes in the control package are shown in figure 20.13.

The structure of the classes is easy recognized in theControlpart of the model.

Figure 20.13: The control package

Control is the main class in thecontrolpackage. It gathers everything dealing with the control state of the railway line. It i.a. contains two objects of theTCCsand SBCCsclass.

20.2 JAVA program structure 191

TCCs contains the TCC objects of all the trains in a Hasbtable.

SBCCs contains the SBCC objects of all the SBs in a Hasbtable.

TCC contains the control state of one train, functions to modify the state, functions implementing the TCC algorithm and functions to communicate with otherTCCs andSBCCs. TheTCCobjects are stored in theTCCsobject.

SBCC contains the control state of one SB, functions to modify the state, functions implementing the SB algorithm and functions to communicate with other SBCCs and TCCs. The SBCC objects are stored in the SBCCs object.

ComService provides the communication service that enables the entities (TCC andSBCC) to communicate with each other.

20.2.5 The gui package

The most important classes in the gui package are shown in figure 20.14.

Figure 20.14: The gui package

Simulator is the main class of the simulator. It starts up the GUI etc.

SimulatorListener is an action listener class that handles the events from the GUI (pressing buttons etc.)

192 Implementing the simulator

SimulatorPanel is a GUI panel that shows the railway simulator.

RailwayLinePanel is a GUI panel that is part of the SimulatorPanel. It shows the layout of the railway line with all the entities (ESAs, segments, SBs and trains).

ButtonPanel is a GUI panel that is a part of the SimulatorPanel. It shows a number of buttons that each corresponds to an entity in the railway line (as shown in the RailwayLinePanel). If a button is pressed the correspond entity’s properties are shown below the buttons (PropertiesPanel).

PropertiesPanel is a GUI panel that contains the static-, dynamic- and con-trol properties (configuration, physical state and concon-trol state) of one en-tity.

DrawTrain provides the ability to draw one train at theRailwayLinePanel.

DrawSB provides the ability to draw one SB at theRailwayLinePanel.

DrawSeg provides the ability to draw one SB at theRailwayLinePanel.

SimulatorPosition is a class that keeps track of the global position of the static entities in theRailwayLinePanel. I.e. it keeps track of the distance from the left most position of the railway line to the left most position of each segment, to the center of each SB and to the left most position of the high ESA (the distance to the low ESA is zero). In this way when a static entity is to be drawnSimulatorPositioncan tell the position (in pixels) where the entity should be drawn. SimulatorPositionis initialized when a configuration is loaded into the simulator. A scale factor is included in the class to scale the layout of the railway line when displayed on the computer screen.

SBCCStatePanel is a GUI panel that is a used by thePropertiesPanelto show the control state of a SB.

SBStatePanel is a GUI panel that is a used by thePropertiesPanelto show the physical state of a SB.

TCCStatePanel is a GUI panel that is a used by the PropertiesPanel to show the control state of a train.

TrainStatePanel is a GUI panel that is a used by the PropertiesPanelto show the physical state of a train.

TrainDriverActions is a class that stores actions initiated by pressing a but-ton in the GUI. These actions can be either changing the acceleration or direction of a train (train driver actions), switching a point or open-ing/closing a crossing. The model is not synchronized since the physical system and control system are ticked sequentially. TrainDriverActions are therefore used to save an action. The action is then performed after

20.2 JAVA program structure 193

the physical system is ticked but before the control system is ticked so that the control system always can undo the action if it is not allowed (if it will result in the speed being to large etc.)

PropertiesTimer is a timer class used for updating the PropertiesPanel repeatedly when an entity has been selected in theButtonPanel.

Ticker is a timer class used for ticking of the physical system and the control system. At every tick it also performs thetrain driver action from the TrainDriverActionclass and updates theRailwayLinePanel.

20.2.6 The editor package

The most important classes in the editor package are shown in figure 20.15.

Figure 20.15: The editor package

ConfigurationEditor is a GUI panel that shows the configuration editor which is a part of the simulator program.

EditorListener is an action listener class that handles all the events from the configuration editor GUI (pressing buttons etc.).

TopLeftPanel is a GUI panel that contains the buttons in the top left corner (Import, Export, Delete, Load, Is wellformed and New).

194 Implementing the simulator

ConfScrollPane is a GUI scroll pane that contains a list of all the configura-tions in the configuration editor.

RLConfPanel is a GUI panel that shows a railway line configuration in the form of buttons for each entity. When a button is pressed the configuration data of that entity is showed above and can now be updated.

TrainConfPanel is a GUI panel that shows the configuration data of one train and allows the user to change this data.

ESAConfPanel is a GUI panel that shows the configuration data of one ESA and allows the user to change this data.

SegmentConfPanel is a GUI panel that shows the configuration data of one segment and allows the user to change this data.

PSegsConfPanel is a GUI panel that shows the configuration data of two coherent branch segments and allows the user to change this data.

SBConfPanel is a GUI panel that shows the configuration data of one SB and allows the user to change this data.

20.2.7 The exceptions package

The classes in the exceptions package are shown in figure 20.16.

Figure 20.16: The exceptions package

GeneralException is anException class that also has a title besides the ex-ception message.

CollisionException extends theGeneralExceptionclass and specializes the class for handling exceptions thrown when a collision occurs.