Model Railroad System  2.2.1
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Parsers::LayoutFile Class Reference

File to parse an XTrkCad layout file and create a track graph. More...

#include <ParseFile.h>

Inheritance diagram for Parsers::LayoutFile:
Parsers::ParseFile Parsers::MRRXtrkCad

Public Member Functions

 LayoutFile (const char *filename, MRRXtrkCad *p)
 Constructor. More...
 
virtual ~LayoutFile ()
 Destructor. More...
 
void Emit (ostream &outstream)
 Function to Emit a track graph to an output stream. More...
 
bool IsNodeP (int nid) const
 Tests if a node id exists in the graph. More...
 
int NumEdges (int nid) const
 Returns the number of edges for the specificed node id. More...
 
int EdgeIndex (int nid, int edgenum) const
 Returns the node id of the specificed edge of the node. More...
 
float EdgeX (int nid, int edgenum) const
 Returns the $X$ coordinate of the specificed edge of the node. More...
 
float EdgeY (int nid, int edgenum) const
 Returns the $Y$ coordinate of the specificed edge of the node. More...
 
float EdgeA (int nid, int edgenum) const
 Returns the angle of the specificed edge of the node. More...
 
float EdgeLength (int nid, int edgenum) const
 Returns the length of an edge. More...
 
TrackGraph::NodeType TypeOfNode (int nid) const
 Returns the type of the node. More...
 
const TurnoutGraphicNodeTurnoutGraphic (int nid) const
 Returns the TurnoutGraphic of the node. More...
 
const TurnoutRoutelistNodeTurnoutRoutelist (int nid) const
 Returns the TurnoutRoutelist of the node. More...
 
float LengthOfNode (int nid) const
 Return the track length of a node. More...
 
const IntegerListTrackList (int nid) const
 Return a block's tracklist. More...
 
int TurnoutNumber (int nid) const
 Return a switchmotor's turnout number. More...
 
const char * NameOfNode (int nid) const
 Return a block's or switchmotor's name. More...
 
const char * SenseScript (int nid) const
 Return a block's or switchmotor's sense script. More...
 
const char * NormalActionScript (int nid) const
 Return a switchmotor's normal action script. More...
 
const char * ReverseActionScript (int nid) const
 Return a block's or switchmotor's reverse action script. More...
 
int NumberOfHeads (int nid) const
 Return a Signal's number of heads. More...
 
const StringPairList * SignalAspects (int nid) const
 Return a Signal's aspect list. More...
 
float OrigX (int nid) const
 Return the $x$ coordinate of the signal base. More...
 
float OrigY (int nid) const
 Return the $y$ coordinate of the signal base. More...
 
float Angle (int nid) const
 Return the angle of the signal. More...
 
const char * OnScript (int nid) const
 Return the on action script. More...
 
const char * OffScript (int nid) const
 Return the off action script. More...
 
int LowestNode () const
 Returns the lowest numbered node id. More...
 
int HighestNode () const
 Returns the highest numbered node id. More...
 
void CompressGraph ()
 Create a compressed graph. More...
 
int CompressedEdgeCount (int cnid) const
 Number of compressed graph edges. More...
 
float CompressedEdgeLength (int cnid, int edgenum) const
 Length of a compressed graph edge. More...
 
int CompressedEdgeNode (int cnid, int edgenum) const
 Next Edge node. More...
 
IntegerListCompressedNodeSegments (int cnid) const
 Raw nodes in a compressed graph node. More...
 
bool IsCompressed () const
 
const IntegerListHeads ()
 
bool IsCompressedNode (int cnid) const
 Is cid a node in the compressed graph? More...
 
const IntegerListRoots ()
 Compressed graph roots. More...
 
double CompressedNodePositionX (int cnid) const
 X Coordinate of a Compressed Node position. More...
 
double CompressedNodePositionY (int cnid) const
 X Coordinate of a Compressed Node position. More...
 
void CompressedGraphCircleLayout (double radius)
 Run the BGL circle_graph_layout for a given radius. More...
 
bool CompressedGraphKamadaKawaiSpring (double sidelength)
 Run the BGL kamada_kawai_spring_layout for a given side length. More...
 
TrackGraph::CompressedEdgePairVector CompressedGraphKruskalMinimumSpanningTree ()
 Run the kruskal_minimum_spanning_tree algorithm and return a vector of edge pairs. More...
 
TrackGraph::CompressedEdgePairVector CompressedGraphPrimMinimumSpanningTree ()
 Run the prim_minimum_spanning_tree algorithm and return a vector of edge pairs. More...
 
- Public Member Functions inherited from Parsers::ParseFile
const char * SourceFile () const
 Return the name of the source file. More...
 
 ParseFile (const char *filename)
 Constructor. More...
 
virtual ~ParseFile ()
 Destructor. More...
 
int ProcessFile (ostream &err)
 open file and parse it. More...
 

Protected Member Functions

virtual int Parse ()
 Parseer function. More...
 
virtual void ParseError (const char *m)
 Parse error handler. More...
 

Protected Attributes

MRRXtrkCadparser
 Parser. More...
 
TrackGraphtrackGraph
 Track graph, a graph of all of the trackwork in the layput file. More...
 
- Protected Attributes inherited from Parsers::ParseFile
char * lp
 Input line buffer pointer. More...
 
FILE * fp
 Input file pointer. More...
 
int source_line
 Source line number. More...
 
char line_buffer [buffersize]
 Input line buffer. More...
 
ostream * errorstream
 Stream for error reporting. More...
 
char * source_file
 Name of the source file. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from Parsers::ParseFile
static const int buffersize = 1024
 Size of line buffer. More...
 

Detailed Description

File to parse an XTrkCad layout file and create a track graph.

Author
Robert Heller <heller@deepsoft.com>

Constructor & Destructor Documentation

◆ LayoutFile()

Parsers::LayoutFile::LayoutFile ( const char *  filename,
MRRXtrkCad p 
)

Constructor.

See MRRXtrkCad. User code normally creates a MRRXtrkCad object and the MRRXtrkCad constructor calls this constructor. User code then accesses the inherited methods of LayoutFile and ParseFile from the MRRXtrkCad object.

◆ ~LayoutFile()

virtual Parsers::LayoutFile::~LayoutFile ( )
virtual

Destructor.

Member Function Documentation

◆ Angle()

float Parsers::LayoutFile::Angle ( int  nid) const
inline

Return the angle of the signal.

Parameters
nidThe node to look at.

References Parsers::TrackGraph::Angle(), and trackGraph.

◆ CompressedEdgeCount()

int Parsers::LayoutFile::CompressedEdgeCount ( int  cnid) const
inline

Number of compressed graph edges.

References Parsers::TrackGraph::CompressedEdgeCount(), and trackGraph.

◆ CompressedEdgeLength()

float Parsers::LayoutFile::CompressedEdgeLength ( int  cnid,
int  edgenum 
) const
inline

Length of a compressed graph edge.

References Parsers::TrackGraph::CompressedEdgeLength(), and trackGraph.

◆ CompressedEdgeNode()

int Parsers::LayoutFile::CompressedEdgeNode ( int  cnid,
int  edgenum 
) const
inline

Next Edge node.

References Parsers::TrackGraph::CompressedEdgeNode(), and trackGraph.

◆ CompressedGraphCircleLayout()

void Parsers::LayoutFile::CompressedGraphCircleLayout ( double  radius)
inline

Run the BGL circle_graph_layout for a given radius.

References Parsers::TrackGraph::CompressedGraphCircleLayout(), and trackGraph.

◆ CompressedGraphKamadaKawaiSpring()

bool Parsers::LayoutFile::CompressedGraphKamadaKawaiSpring ( double  sidelength)
inline

Run the BGL kamada_kawai_spring_layout for a given side length.

References Parsers::TrackGraph::CompressedGraphKamadaKawaiSpring(), and trackGraph.

◆ CompressedGraphKruskalMinimumSpanningTree()

TrackGraph::CompressedEdgePairVector Parsers::LayoutFile::CompressedGraphKruskalMinimumSpanningTree ( )
inline

Run the kruskal_minimum_spanning_tree algorithm and return a vector of edge pairs.

References Parsers::TrackGraph::CompressedGraphKruskalMinimumSpanningTree(), and trackGraph.

◆ CompressedGraphPrimMinimumSpanningTree()

TrackGraph::CompressedEdgePairVector Parsers::LayoutFile::CompressedGraphPrimMinimumSpanningTree ( )
inline

Run the prim_minimum_spanning_tree algorithm and return a vector of edge pairs.

References Parsers::TrackGraph::CompressedGraphPrimMinimumSpanningTree(), and trackGraph.

◆ CompressedNodePositionX()

double Parsers::LayoutFile::CompressedNodePositionX ( int  cnid) const
inline

X Coordinate of a Compressed Node position.

References Parsers::TrackGraph::CompressedNodePositionX(), and trackGraph.

◆ CompressedNodePositionY()

double Parsers::LayoutFile::CompressedNodePositionY ( int  cnid) const
inline

X Coordinate of a Compressed Node position.

References Parsers::TrackGraph::CompressedNodePositionY(), and trackGraph.

◆ CompressedNodeSegments()

IntegerList* Parsers::LayoutFile::CompressedNodeSegments ( int  cnid) const
inline

Raw nodes in a compressed graph node.

References Parsers::TrackGraph::CompressedNodeSegments(), and trackGraph.

◆ CompressGraph()

void Parsers::LayoutFile::CompressGraph ( )
inline

Create a compressed graph.

References Parsers::TrackGraph::CompressGraph(), and trackGraph.

◆ EdgeA()

float Parsers::LayoutFile::EdgeA ( int  nid,
int  edgenum 
) const
inline

Returns the angle of the specificed edge of the node.

References Parsers::TrackGraph::EdgeA(), and trackGraph.

◆ EdgeIndex()

int Parsers::LayoutFile::EdgeIndex ( int  nid,
int  edgenum 
) const
inline

Returns the node id of the specificed edge of the node.

References Parsers::TrackGraph::EdgeIndex(), and trackGraph.

◆ EdgeLength()

float Parsers::LayoutFile::EdgeLength ( int  nid,
int  edgenum 
) const
inline

Returns the length of an edge.

References Parsers::TrackGraph::EdgeLength(), and trackGraph.

◆ EdgeX()

float Parsers::LayoutFile::EdgeX ( int  nid,
int  edgenum 
) const
inline

Returns the $X$ coordinate of the specificed edge of the node.

References Parsers::TrackGraph::EdgeX(), and trackGraph.

◆ EdgeY()

float Parsers::LayoutFile::EdgeY ( int  nid,
int  edgenum 
) const
inline

Returns the $Y$ coordinate of the specificed edge of the node.

References Parsers::TrackGraph::EdgeY(), and trackGraph.

◆ Emit()

void Parsers::LayoutFile::Emit ( ostream &  outstream)

Function to Emit a track graph to an output stream.

Parameters
outstreamThe output stream to write the graph to.

◆ Heads()

const IntegerList* Parsers::LayoutFile::Heads ( )
inline

◆ HighestNode()

int Parsers::LayoutFile::HighestNode ( ) const
inline

Returns the highest numbered node id.

References Parsers::TrackGraph::HighestNode(), and trackGraph.

◆ IsCompressed()

bool Parsers::LayoutFile::IsCompressed ( ) const
inline

◆ IsCompressedNode()

bool Parsers::LayoutFile::IsCompressedNode ( int  cnid) const
inline

Is cid a node in the compressed graph?

References Parsers::TrackGraph::IsCompressedNode(), and trackGraph.

◆ IsNodeP()

bool Parsers::LayoutFile::IsNodeP ( int  nid) const
inline

Tests if a node id exists in the graph.

References Parsers::TrackGraph::IsNodeP(), and trackGraph.

◆ LengthOfNode()

float Parsers::LayoutFile::LengthOfNode ( int  nid) const
inline

Return the track length of a node.

References Parsers::TrackGraph::LengthOfNode(), and trackGraph.

◆ LowestNode()

int Parsers::LayoutFile::LowestNode ( ) const
inline

Returns the lowest numbered node id.

References Parsers::TrackGraph::LowestNode(), and trackGraph.

◆ NameOfNode()

const char* Parsers::LayoutFile::NameOfNode ( int  nid) const
inline

Return a block's or switchmotor's name.

References Parsers::TrackGraph::NameOfNode(), and trackGraph.

◆ NodeTurnoutGraphic()

const TurnoutGraphic* Parsers::LayoutFile::NodeTurnoutGraphic ( int  nid) const
inline

Returns the TurnoutGraphic of the node.

References Parsers::TrackGraph::NodeTurnoutGraphic(), and trackGraph.

◆ NodeTurnoutRoutelist()

const TurnoutRoutelist* Parsers::LayoutFile::NodeTurnoutRoutelist ( int  nid) const
inline

Returns the TurnoutRoutelist of the node.

References Parsers::TrackGraph::NodeTurnoutRoutelist(), and trackGraph.

◆ NormalActionScript()

const char* Parsers::LayoutFile::NormalActionScript ( int  nid) const
inline

Return a switchmotor's normal action script.

References Parsers::TrackGraph::NormalActionScript(), and trackGraph.

◆ NumberOfHeads()

int Parsers::LayoutFile::NumberOfHeads ( int  nid) const
inline

Return a Signal's number of heads.

References Parsers::TrackGraph::NumberOfHeads(), and trackGraph.

◆ NumEdges()

int Parsers::LayoutFile::NumEdges ( int  nid) const
inline

Returns the number of edges for the specificed node id.

References Parsers::TrackGraph::NumEdges(), and trackGraph.

◆ OffScript()

const char* Parsers::LayoutFile::OffScript ( int  nid) const
inline

Return the off action script.

Parameters
nidThe node to look at.

References Parsers::TrackGraph::OffScript(), and trackGraph.

◆ OnScript()

const char* Parsers::LayoutFile::OnScript ( int  nid) const
inline

Return the on action script.

Parameters
nidThe node to look at.

References Parsers::TrackGraph::OnScript(), and trackGraph.

◆ OrigX()

float Parsers::LayoutFile::OrigX ( int  nid) const
inline

Return the $x$ coordinate of the signal base.

Parameters
nidThe node to look at.

References Parsers::TrackGraph::OrigX(), and trackGraph.

◆ OrigY()

float Parsers::LayoutFile::OrigY ( int  nid) const
inline

Return the $y$ coordinate of the signal base.

Parameters
nidThe node to look at.

References Parsers::TrackGraph::OrigY(), and trackGraph.

◆ Parse()

virtual int Parsers::LayoutFile::Parse ( )
protectedvirtual

Parseer function.

Implements Parsers::ParseFile.

◆ ParseError()

virtual void Parsers::LayoutFile::ParseError ( const char *  m)
protectedvirtual

Parse error handler.

Implements Parsers::ParseFile.

◆ ReverseActionScript()

const char* Parsers::LayoutFile::ReverseActionScript ( int  nid) const
inline

Return a block's or switchmotor's reverse action script.

References Parsers::TrackGraph::ReverseActionScript(), and trackGraph.

◆ Roots()

const IntegerList* Parsers::LayoutFile::Roots ( )
inline

Compressed graph roots.

References Parsers::TrackGraph::Roots(), and trackGraph.

◆ SenseScript()

const char* Parsers::LayoutFile::SenseScript ( int  nid) const
inline

Return a block's or switchmotor's sense script.

References Parsers::TrackGraph::SenseScript(), and trackGraph.

◆ SignalAspects()

const StringPairList* Parsers::LayoutFile::SignalAspects ( int  nid) const
inline

Return a Signal's aspect list.

References Parsers::TrackGraph::SignalAspects(), and trackGraph.

◆ TrackList()

const IntegerList* Parsers::LayoutFile::TrackList ( int  nid) const
inline

Return a block's tracklist.

References trackGraph, and Parsers::TrackGraph::TrackList().

◆ TurnoutNumber()

int Parsers::LayoutFile::TurnoutNumber ( int  nid) const
inline

Return a switchmotor's turnout number.

References trackGraph, and Parsers::TrackGraph::TurnoutNumber().

◆ TypeOfNode()

TrackGraph::NodeType Parsers::LayoutFile::TypeOfNode ( int  nid) const
inline

Returns the type of the node.

References trackGraph, and Parsers::TrackGraph::TypeOfNode().

Member Data Documentation

◆ parser

MRRXtrkCad* Parsers::LayoutFile::parser
protected

Parser.

◆ trackGraph

TrackGraph* Parsers::LayoutFile::trackGraph
protected