/// <summary>
        /// Try to find a connection between a previously defined startNode and previously defined possible endNodes.
        /// Depth-first search via main track at junctions.
        /// Also reversing the start or single endNode is tried, in case one of these nodes has a non-defined orientation
        /// because both before and after the node the path is broken.
        /// </summary>
        /// <param name="firstTvnIndex">If non-null define the first TVN index that needs to be followed</param>
        /// <param name="allowOnlyStartReverse">If true, only start node is allowed to be reversed</param>
        /// <returns>Whether a path has been found</returns>
        protected bool FindConnectionFromTo(int?firstTvnIndex, bool allowOnlyStartReverse)
        {
            if (FindConnectionSameTrack(firstTvnIndex))
            {
                return(true);
            }

            //first try to see if we succeed without re-orienting the startNode or reconnectNode
            if (FindConnectionThisOrientation(firstTvnIndex))
            {
                return(true);
            }

            //perhaps there is a path with a reversed start node.
            if (allowOnlyStartReverse || CanReverse(autoConnectFromNode.OriginalNode))
            {
                autoConnectFromNode.ReverseOrientation();
                FromNodeNeedsReverse = FindConnectionThisOrientation(firstTvnIndex);
                autoConnectFromNode.ReverseOrientation(); // we only do the actual reverse in CreateFoundConnection
                if (FromNodeNeedsReverse)
                {
                    return(true);
                }
            }

            //perhaps there is a path with a reversed reconnect node.
            ConnectableNode reconnectNode = autoConnectToNodeOptions.SingleNode();

            if ((reconnectNode != null) && !allowOnlyStartReverse && CanReverse(reconnectNode.OriginalNode))
            {
                reconnectNode.ReverseOrientation();
                ToNodeNeedsReverse = FindConnectionThisOrientation(firstTvnIndex);
                reconnectNode.ReverseOrientation(); // we only do the actual reverse in CreateFoundConnection
                if (ToNodeNeedsReverse)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Actually create the path by linking nodes following the stored linking tvns.
        /// </summary>
        /// <param name="modificationTools">The tool set that is used to actually modify the path</param>
        /// <param name="isMainPath">Do we add the node to the main path or not</param>
        /// <param name="isFromNodeDirectionOK">Set this to true when the FromNode has already been set to correct orientation elsewhere</param>
        public void CreateFoundConnection(ModificationTools modificationTools, bool isMainPath, bool isFromNodeDirectionOK)
        {
            ConnectableNode autoConnectToNode = autoConnectToNodeOptions.ActualReconnectNode;


            if (FromNodeNeedsReverse && !isFromNodeDirectionOK)
            {
                autoConnectFromNode.ReverseOrientation();
            }
            if (ToNodeNeedsReverse)
            {
                autoConnectToNode.ReverseOrientation();
            }

            if (!autoConnectToNode.IsConnectingForward)
            {
                linkingTvns.Reverse();
                ConnectableNode swap = autoConnectToNode;
                autoConnectToNode   = autoConnectFromNode;
                autoConnectFromNode = swap;
            }


            TrainpathNode currentNode = autoConnectFromNode.OriginalNode;

            if ((currentNode is TrainpathVectorNode) && !sameTrackConnect)
            {   // in case the first node is a vector node (and not a direct connect), go to its junction first
                currentNode = modificationTools.AddAdditionalNode(currentNode, isMainPath);
            }

            //create the new path using the stored Tvns
            foreach (int tvn in linkingTvns)
            {
                currentNode = modificationTools.AddAdditionalNode(currentNode, tvn, isMainPath);
                while (currentNode is TrainpathVectorNode)
                {   // apparently a disambiguity node has been added.
                    currentNode = modificationTools.AddAdditionalNode(currentNode, tvn, isMainPath);
                }
            }

            //make the final connections
            TrainpathNode toNode = autoConnectToNode.OriginalNode;

            modificationTools.StitchTwoPaths(currentNode, toNode, isMainPath);
        }