Пример #1
0
        // Determine what the selection will be after deletion
        private NodeSelection GetPostDeleteSelection(bool IsAutoPageGenerationInvoked)
        {
            ObiNode node = null;

            if (mNode is SectionNode)
            {
                if (View.Selection.Control is ProjectView.ContentView)
                {
                    // Select the next strip; if there is no next strip, select the previous one.
                    node = ((SectionNode)mNode).FollowingSection;
                    if (node == null)
                    {
                        node = ((SectionNode)mNode).PrecedingSection;
                    }
                }
                else
                {
                    // TODO: review this.
                    ObiNode parent = mNode.ParentAs <ObiNode>();
                    int     index  = mNode.Index;
                    node = index < parent.SectionChildCount - 1 ?
                           (ObiNode)parent.SectionChild(index + 1) :
                           index > 0 ? (ObiNode)parent.SectionChild(index - 1) :
                           parent == View.Presentation.RootNode ? null : parent;
                }
            }
            else
            {
                SectionNode parent = mNode.ParentAs <SectionNode>();
                int         index  = mNode.Index;
                // Select the next sibling;
                // if last child, select the previous sibling;
                // if first child, select the parent.
                node = index < parent.PhraseChildCount - 1 ?
                       (ObiNode)parent.PhraseChild(index + 1) :
                       index > 0 ? (ObiNode)parent.PhraseChild(index - 1) :
                       (ObiNode)parent;
                if (IsAutoPageGenerationInvoked && node != null && node is EmptyNode)
                {
                    while (node.Parent == parent && (!(node is PhraseNode) || (node is PhraseNode && ((node as PhraseNode).Role_ == PhraseNode.Role.Page)) && node is EmptyNode))
                    {
                        if (node.PrecedingNode != null)
                        {
                            node = node.PrecedingNode;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return(node == null ? null : new NodeSelection(node, View.Selection.Control));
        }
Пример #2
0
        private string GetEmptyNodeString(EmptyNode node)
        {
            if (node == null)
            {
                return("");
            }
            string info = null;

            if (node.Role_ == EmptyNode.Role.Custom && EmptyNode.SkippableNamesList.Contains(node.CustomRole))
            {
                SectionNode parentSection = node.ParentAs <SectionNode>();
                EmptyNode   lastNode      = parentSection.PhraseChild(parentSection.PhraseChildCount - 1);
                for (int i = node.Index; i < parentSection.PhraseChildCount; i++)
                {
                    if (parentSection.PhraseChild(i).Role_ != node.Role_ ||
                        parentSection.PhraseChild(i).CustomRole != node.CustomRole)
                    {
                        break;
                    }
                    lastNode = parentSection.PhraseChild(i);
                }
                string range = node != lastNode? (node.Index + 1).ToString() + " to " + (lastNode.Index + 1).ToString():
                               (node.Index + 1).ToString();
                info = Localizer.Message("AssociateNode_Section") + parentSection.Label + " " + node.CustomRole + " " + range;
                return(info);
            }
            else
            {
                double durationMs = node.Duration;
                double seconds    = Math.Round((durationMs / 1000), 1, MidpointRounding.ToEven);
                string dur        = "(" + Convert.ToString(seconds) + "s)";
                info = String.Format(Localizer.Message("phrase_to_string"),
                                     "",
                                     "",
                                     node.IsRooted ? node.Index + 1 : 0,
                                     node.IsRooted ? node.ParentAs <ObiNode>().PhraseChildCount : 0,
                                     "",
                                     node.Role_ == EmptyNode.Role.Custom ? String.Format(Localizer.Message("phrase_extra_custom"), node.CustomRole) :

                                     Localizer.Message("phrase_extra_" + node.Role_.ToString()));
                info = info.Replace("(", "");
                info = info.Replace(")", "");
                return(info);
            }
        }
Пример #3
0
        // Determine what the selection will be after deletion
        private NodeSelection GetPostDeleteSelection()
        {
            ObiNode node = null;

            if (mNode is SectionNode)
            {
                if (View.Selection.Control is ProjectView.ContentView)
                {
                    // Select the next strip; if there is no next strip, select the previous one.
                    node = ((SectionNode)mNode).FollowingSection;
                    if (node == null)
                    {
                        node = ((SectionNode)mNode).PrecedingSection;
                    }
                }
                else
                {
                    // TODO: review this.
                    ObiNode parent = mNode.ParentAs <ObiNode>();
                    int     index  = mNode.Index;
                    node = index < parent.SectionChildCount - 1 ?
                           (ObiNode)parent.SectionChild(index + 1) :
                           index > 0 ? (ObiNode)parent.SectionChild(index - 1) :
                           parent == View.Presentation.RootNode ? null : parent;
                }
            }
            else
            {
                SectionNode parent = mNode.ParentAs <SectionNode>();
                int         index  = mNode.Index;
                // Select the next sibling;
                // if last child, select the previous sibling;
                // if first child, select the parent.
                node = index < parent.PhraseChildCount - 1 ?
                       (ObiNode)parent.PhraseChild(index + 1) :
                       index > 0 ? (ObiNode)parent.PhraseChild(index - 1) :
                       (ObiNode)parent;
            }
            return(node == null ? null : new NodeSelection(node, View.Selection.Control));
        }
Пример #4
0
        public static urakawa.command.CompositeCommand GetCompositeCommandForAssigningRoleOnMultipleNodes(ProjectView.ProjectView view, EmptyNode startNode, EmptyNode endNode, EmptyNode.Role role, string customeClassName)
        {
            SectionNode section = startNode.ParentAs <SectionNode>();

            urakawa.command.CompositeCommand command = view.Presentation.CommandFactory.CreateCompositeCommand();

            for (int i = startNode.Index; i <= endNode.Index; i++)
            {
                command.ChildCommands.Insert(command.ChildCommands.Count,
                                             new Commands.Node.AssignRole(view, section.PhraseChild(i), role, customeClassName));
            }
            return(command);
        }
Пример #5
0
        private void AddToSpecialNodeListbox(SectionNode node, int i)
        {
            string tempString = "";

            if (node.PhraseChild(i).Role_ == EmptyNode.Role.Custom && (node.PhraseChild(i).CustomRole == EmptyNode.Footnote || node.PhraseChild(i).CustomRole == EmptyNode.EndNote || node.PhraseChild(i).CustomRole == EmptyNode.Annotation || node.PhraseChild(i).CustomRole == EmptyNode.ProducerNote || node.PhraseChild(i).CustomRole == EmptyNode.Note))
            {
                tempString = node.PhraseChild(i).CustomRole;
                if (i <= node.PhraseChildCount - 1)
                {
                    if (((node.PhraseChild(i).PrecedingNode is SectionNode || (node.PhraseChild(i).PrecedingNode is EmptyNode && tempString != ((EmptyNode)node.PhraseChild(i).PrecedingNode).CustomRole)) && node.PhraseChild(i).FollowingNode is EmptyNode && tempString == ((EmptyNode)node.PhraseChild(i).FollowingNode).CustomRole) ||
                        (node.PhraseChild(i).PrecedingNode is EmptyNode && node.PhraseChild(i).FollowingNode is EmptyNode && tempString != ((EmptyNode)node.PhraseChild(i).PrecedingNode).CustomRole && tempString != ((EmptyNode)node.PhraseChild(i).FollowingNode).CustomRole) ||
                        (i == node.PhraseChildCount - 1 && ((node.PhraseChild(i).PrecedingNode is SectionNode || (node.PhraseChild(i).PrecedingNode is EmptyNode && ((EmptyNode)node.PhraseChild(i).PrecedingNode).CustomRole != tempString))))
                        )
                    {
                        listOfFirstNodeOfSpecialNodes.Add(node.PhraseChild(i));
                    }
                }
            }
        }
Пример #6
0
        private void AddToAnchorNodeListbox(SectionNode node, int i)
        {
            string selectedSymbol = m_SelectedNode != null && m_SelectedNode == node.PhraseChild(i) ? Localizer.Message("AssociateNode_SelectedSection") : Localizer.Message("AssociateNode_Section");

            if (IsAnchor(node.PhraseChild(i)) || (m_SelectedNode != null && node == m_SelectedNode.ParentAs <SectionNode>() && node.PhraseChild(i) == m_SelectedNode))
            {
                if (m_IsShowAll || m_SelectedNode == null)
                {
                    if (m_SelectedNode == node.PhraseChild(i))
                    {
                        if (GetReferedNode(m_SelectedNode) != null)
                        {
                            m_lb_listOfAllAnchorNodes.Items.Add(selectedSymbol + node.Label + " " + GetEmptyNodeString(node.PhraseChild(i)) + " = " + GetEmptyNodeString(GetReferedNode(node.PhraseChild(i))));
                        }
                        else
                        {
                            m_lb_listOfAllAnchorNodes.Items.Add(selectedSymbol + node.Label + " " + GetEmptyNodeString(node.PhraseChild(i)));
                        }
                    }
                    else if (GetReferedNode(node.PhraseChild(i)) != null)
                    {
                        m_lb_listOfAllAnchorNodes.Items.Add(selectedSymbol + node.Label + " " + GetEmptyNodeString(node.PhraseChild(i)) + " = " + GetEmptyNodeString(GetReferedNode(node.PhraseChild(i))));
                    }
                    else
                    {
                        m_lb_listOfAllAnchorNodes.Items.Add(selectedSymbol + node.Label + " " + GetEmptyNodeString(node.PhraseChild(i)));
                    }

                    listOfAnchorNodes.Add(node.PhraseChild(i));
                }
                listOfAnchorNodesCopy.Add(node.PhraseChild(i));
            }
            if (m_IsShowAll == false)
            {
                listOfAnchorNodes.Clear();
                listOfAnchorNodes.Add(m_SelectedNode);
            }
        }
Пример #7
0
        /// <summary>
        /// Create the phrase detection command.
        /// </summary>
        public static CompositeCommand GetPhraseDetectionCommand(ProjectView.ProjectView view, ObiNode node,
                                                                 long threshold, double gap, double before, bool mergeFirstTwoPhrases, ObiPresentation presentation = null)
        {
            List <PhraseNode> phraseNodesList = new List <PhraseNode> ();

            if (node is PhraseNode)
            {
                phraseNodesList.Add((PhraseNode)node);
            }
            else if (node is SectionNode)
            {
                SectionNode section = (SectionNode)node;
                for (int i = 0; i < section.PhraseChildCount; i++)
                {
                    if (section.PhraseChild(i) is PhraseNode && ((PhraseNode)section.PhraseChild(i)).Role_ != EmptyNode.Role.Silence)
                    {
                        phraseNodesList.Add((PhraseNode)section.PhraseChild(i));
                    }
                }
            }
            List <List <PhraseNode> > phrasesToMerge = new List <List <PhraseNode> >();
            CompositeCommand          command        = null;

            if (view.Presentation == null && presentation != null)
            {
                command = presentation.CreateCompositeCommand(Localizer.Message("phrase_detection"));
            }
            else
            {
                command = view.Presentation.CreateCompositeCommand(Localizer.Message("phrase_detection"));
            }

            // if phrase is selected but phrase detection node is section,select section
            if (node is SectionNode && view.GetSelectedPhraseSection != null &&
                view.GetSelectedPhraseSection == node)
            {
                command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(node, view.Selection.Control)));
            }

            ObiNode parent = node is SectionNode ? node : node.ParentAs <ObiNode> ();
            int     index  = 0;

            if (phraseNodesList.Count > 0)
            {
                view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), 0);
            }
            for (int j = 0; j < phraseNodesList.Count; j++)
            {
                PhraseNode phrase = phraseNodesList[j];

                if (j == 0)
                {
                    index = phrase.Index + 1;
                }
                System.Collections.Generic.List <PhraseNode> phrases = null;
                if (view.Presentation == null && presentation != null)
                {
                    phrases = presentation.CreatePhraseNodesFromAudioAssetList(
                        Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before));
                }
                else
                {
                    phrases = view.Presentation.CreatePhraseNodesFromAudioAssetList(
                        Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before));
                }
                for (int i = 0; i < phrases.Count; ++i)
                {
                    // Copy page/heading role for the first phrase only
                    if (i == 0 || (phrase.Role_ != EmptyNode.Role.Page && phrase.Role_ != EmptyNode.Role.Heading))
                    {
                        phrases[i].CopyAttributes(phrase);
                    }
                    phrases[i].Used = phrase.Used;
                    phrases[i].TODO = phrase.TODO;
                    if (i == 0 && phrase.TODO && (phrase as EmptyNode).CommentText != null)
                    {
                        (phrases[i] as EmptyNode).CommentText = (phrase as EmptyNode).CommentText;
                    }
                    if (phrases[i].Role_ == EmptyNode.Role.Heading && i > 0)
                    {
                        phrases[i].Role_ = EmptyNode.Role.Plain;
                    }

                    // in following add node constructor, update selection is made false, to improve performance (19 may, 2010)
                    command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, phrases[i], parent, index, false));
                    index++;
                }
                // add first 2 phrases to the list if the merge flag is true
                if (phrases.Count >= 2 && mergeFirstTwoPhrases &&
                    phrases[0] is PhraseNode && phrases [1] is PhraseNode)
                {
                    List <PhraseNode> mergeList = new List <PhraseNode>();
                    mergeList.Add(phrases[0]);
                    mergeList.Add(phrases[1]);
                    phrasesToMerge.Add(mergeList);
                }

                if (node is PhraseNode && phrases.Count > 0 && view.Selection != null)
                {
                    //command.append ( new UpdateSelection ( view, new NodeSelection ( node, view.Selection.Control ) ) );
                    command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(phrases[0], view.Selection.Control)));    //uncommenting this because unexecute for update selection can handle null unexecute now
                }
                Commands.Node.Delete deleteCmd = new Commands.Node.Delete(view, phrase, false);
                command.ChildCommands.Insert(command.ChildCommands.Count, deleteCmd);//@singleSection: moved delete command last for improve undo selection

                if (Obi.Audio.PhraseDetection.CancelOperation)
                {
                    break;
                }
                // skip to next indexes if the two consequtive phrases in phrase list are not consequitive according to phrase index in the parent section
                if (j < phraseNodesList.Count - 1 &&
                    phrase.Index + 1 < phraseNodesList[j + 1].Index)
                {
                    EmptyNode empty = null;
                    for (int i = phrase.Index + 1; i < phraseNodesList[j + 1].Index; ++i)
                    {
                        empty = phrase.ParentAs <SectionNode>().PhraseChild(i);
                        command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.Delete(view, empty, false));
                        command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, empty, parent, index, false));
                        index++;
                    }
                    //index = index + (phraseNodesList[j + 1].Index - (phrase.Index + 1));
                }
                view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), (100 * j) / phraseNodesList.Count);
            }
            if (phrasesToMerge.Count > 0)
            {
                for (int i = 0; i < phrasesToMerge.Count; i++)
                {
                    List <PhraseNode>        mergeList = phrasesToMerge[i];
                    Commands.Node.MergeAudio mergeCmd  = new MergeAudio(view, mergeList[0], mergeList[1]);
                    mergeCmd.UpdateSelection = false;
                    command.ChildCommands.Insert(command.ChildCommands.Count, mergeCmd);
                }
            }
            return(command);
        }
Пример #8
0
        private void CollectPhrases()
        {
            m_btnOK.Enabled = false;
            this.m_lbSpecialPhrasesList.Items.Clear();
            string    sectionName     = null;
            EmptyNode lastNodeOfChunk = null;

            mView.Presentation.RootNode.AcceptDepthFirst(
                delegate(urakawa.core.TreeNode n)
            {
                switch (m_cb_SpecialPhrases.SelectedIndex)
                {
                case 0:
                    if (n is EmptyNode && ((EmptyNode)n).TODO)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 1:
                    if (n is EmptyNode && ((EmptyNode)n).TODO && ((EmptyNode)n).CommentText != null)
                    {
                        string commentText = string.Empty;
                        if (((EmptyNode)n).CommentText.Length > 20)
                        {
                            commentText = ((EmptyNode)n).CommentText.Substring(0, 20) + "...";
                        }
                        else
                        {
                            commentText = ((EmptyNode)n).CommentText;
                        }

                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n) + " " + Localizer.Message("CommentText") + commentText;
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 2:
                    if ((n is EmptyNode && !(n is PhraseNode)) || (n is PhraseNode && ((PhraseNode)n).Duration == 0))
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " + ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 3:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Heading)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 4:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Silence)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 5:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Page)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 6:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Page &&
                        ((EmptyNode)n).PageNumber.Kind == PageKind.Front)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 7:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Page &&
                        ((EmptyNode)n).PageNumber.Kind == PageKind.Normal)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 8:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Page &&
                        ((EmptyNode)n).PageNumber.Kind == PageKind.Special)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 9:
                    if (n is EmptyNode && ((EmptyNode)n).Role_ == EmptyNode.Role.Anchor)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                case 10:
                    if (n is EmptyNode && !((EmptyNode)n).Used)
                    {
                        sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                      ((EmptyNode)n);
                        m_lbSpecialPhrasesList.Items.Add(sectionName);
                        backendList.Add(((EmptyNode)n));
                    }
                    break;

                default:
                    {
                        string itemString = (string)m_cb_SpecialPhrases.SelectedItem;
                        if (n is EmptyNode && !string.IsNullOrEmpty(itemString) &&
                            ((EmptyNode)n).Role_ == EmptyNode.Role.Custom &&
                            ((EmptyNode)n).CustomRole == itemString)
                        {
                            if (lastNodeOfChunk != null && n.Parent == lastNodeOfChunk.Parent &&
                                ((EmptyNode)n).Index <= lastNodeOfChunk.Index)
                            {
                                return(true);
                            }
                            else
                            {
                                lastNodeOfChunk = null;
                            }

                            SectionNode section = ((EmptyNode)n).ParentAs <SectionNode>();
                            int phraseIndex     = ((EmptyNode)n).Index;
                            if (phraseIndex < section.PhraseChildCount - 1 &&
                                ((EmptyNode)n).CustomRole ==
                                section.PhraseChild(phraseIndex + 1).CustomRole)
                            {
                                int customRoleEndIndex = phraseIndex;
                                for (int i = phraseIndex; i < section.PhraseChildCount - 1; i++)
                                {
                                    if (section.PhraseChild(i).CustomRole !=
                                        section.PhraseChild(i + 1).CustomRole)
                                    {
                                        customRoleEndIndex = i;
                                        break;
                                    }
                                }
                                sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                              itemString + ": " + phraseIndex.ToString() + " - " +
                                              customRoleEndIndex.ToString();
                                m_lbSpecialPhrasesList.Items.Add(sectionName);
                                backendList.Add(((EmptyNode)n));
                                //n = section.PhraseChild(customRoleEndIndex + 1);
                                lastNodeOfChunk = section.PhraseChild(customRoleEndIndex + 1);
                            }
                            else
                            {
                                sectionName = ((EmptyNode)n).ParentAs <SectionNode>().Label + " : " +
                                              ((EmptyNode)n);
                                m_lbSpecialPhrasesList.Items.Add(sectionName);
                                backendList.Add(((EmptyNode)n));
                            }
                        }
                    }
                    break;
                }
                return(true);
            },
                delegate(urakawa.core.TreeNode n) { });
        }
Пример #9
0
        private XmlNode CreateElementsForSection(XmlDocument nccDocument, SectionNode section, int sectionIndex, XmlNode prevPageXmlNode)
        {
            string  nccFileName = "ncc.html";
            XmlNode bodyNode    = nccDocument.GetElementsByTagName("body")[0];
            XmlNode headingNode = nccDocument.CreateElement(null, "h" + section.Level.ToString(), bodyNode.NamespaceURI);

            if (sectionIndex == 0)
            {
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, headingNode, "class", "title");
            }
            else
            {
                XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, headingNode, "class", "section");
            }
            string headingID = "h" + IncrementID;

            XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, headingNode, "id", headingID);
            headingNode.AppendChild(nccDocument.CreateTextNode(section.Label));
            bodyNode.AppendChild(headingNode);


            bool isFirstPhrase = true;
            //EmptyNode adjustedPageNode = m_NextSectionPageAdjustmentDictionary[section];
            bool isPreviousNodeEmptyPage = false;

            if (prevPageXmlNode != null)
            {
                XmlNode parent = prevPageXmlNode.ParentNode;
                parent.RemoveChild(prevPageXmlNode);

                bodyNode.AppendChild(prevPageXmlNode);
                bodyNode.AppendChild(nccDocument.CreateElement(null, "br", bodyNode.NamespaceURI));
                prevPageXmlNode = null;
                //Console.WriteLine("Prev: " + prevPageXmlNode.InnerText);
            }

            for (int i = 0; i < section.PhraseChildCount; i++)
            {    //1
                EmptyNode phrase = section.PhraseChild(i);

                if ((phrase is PhraseNode && phrase.Used) ||
                    (phrase is EmptyNode && phrase.Role_ == EmptyNode.Role.Page && phrase.Used))
                {    //2
                    string  pageID   = null;
                    XmlNode pageNode = null;
                    if (phrase.Role_ == EmptyNode.Role.Page)
                    {    //3
                        string strClassVal = null;
                        // increment page counts and get page kind
                        switch (phrase.PageNumber.Kind)
                        {    //4
                        case PageKind.Front:
                            //m_PageFrontCount++;
                            strClassVal = "page-front";
                            break;

                        case PageKind.Normal:
                            m_PageNormalCount++;
                            //if (phrase.PageNumber.Number > m_MaxPageNormal) m_MaxPageNormal = phrase.PageNumber.Number;
                            strClassVal = "page-normal";
                            break;

                        case PageKind.Special:
                            //m_PageSpecialCount++;
                            strClassVal = "page-special";
                            break;
                        }    //-4

                        XmlNode pageXmlNode = pageNode = nccDocument.CreateElement(null, "span", bodyNode.NamespaceURI);
                        XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, pageNode, "class", strClassVal);
                        pageID = "p" + IncrementID;
                        XmlDocumentHelper.CreateAppendXmlAttribute(nccDocument, pageNode, "id", pageID);
                        string pageString = Profile_VA ? "Page " + phrase.PageNumber.ToString() :
                                            phrase.PageNumber.ToString();
                        pageXmlNode.AppendChild(nccDocument.CreateTextNode(pageString));
                        bodyNode.AppendChild(pageNode);
                        prevPageXmlNode = pageNode;
                        bodyNode.AppendChild(nccDocument.CreateElement(null, "br", bodyNode.NamespaceURI));
                    }    //-3

                    // add anchor and href to ncc elements
                    //XmlNode anchorNode = nccDocument.CreateElement ( null, "a", bodyNode.NamespaceURI );

                    //if (isFirstPhrase)
                    //{
                    //headingNode.AppendChild ( anchorNode );
                    //CreateAppendXmlAttribute ( nccDocument, anchorNode, "href", smilFileName + "#" + txtID );
                    //anchorNode.AppendChild (
                    //nccDocument.CreateTextNode ( section.Label ) );
                    //}
                    //else if (pageNode != null)
                    //{

                    //pageNode.AppendChild ( anchorNode );
                    //CreateAppendXmlAttribute ( nccDocument, anchorNode, "href", smilFileName + "#" + txtID );

                    //anchorNode.AppendChild (
                    //nccDocument.CreateTextNode ( phrase.PageNumber.ToString () ) );

                    //}
                    //}


                    isFirstPhrase = false;

                    if (phrase is EmptyNode && phrase.Role_ == EmptyNode.Role.Page)
                    {
                        isPreviousNodeEmptyPage = true;
                    }
                    else
                    {
                        isPreviousNodeEmptyPage = false;
                    }
                } // for loop ends
            }
            // Console.WriteLine("returning : " + prevPageXmlNode.InnerText);
            return(prevPageXmlNode);
        }
Пример #10
0
        private void LoadBlocksLayout(int initIndex)
        {
            if (initIndex < 0)
            {
                return;
            }

            int maxCountDisplay = mNode.PhraseChildCount > m_BlocksDisplayedCount ? m_BlocksDisplayedCount : mNode.PhraseChildCount;

            if (mNode.PhraseChildCount < m_BlocksDisplayedCount ||
                mBlockLayout.Controls.Count == 0)
            {
                Console.WriteLine(mNode.PhraseChildCount.ToString() + ":" + m_BlocksDisplayedCount + ":" + maxCountDisplay.ToString());
                int lastBlockIndex = LastBlock != null && LastBlock.Node.Index >= 0 ? LastBlock.Node.Index: 0;
                for (int i = lastBlockIndex
                     ; i < maxCountDisplay
                     ; i++)
                {
                    AddBlockForNode(mNode.PhraseChild(i));
                }
            }
            else
            {
                if (initIndex >= 0 &&
                    initIndex < FirstBlock.Node.Index)
                {
                    //MessageBox.Show ( "create in front" );
                    int countToAdd = FirstBlock.Node.Index - initIndex;
                    // first add blocks in front
                    for (int i = 0; i < countToAdd; i++)
                    {
                        //MessageBox.Show ("Adding " +   mNode.PhraseChild ( i + initIndex ).Index.ToString () );
                        AddBlockForNode(mNode.PhraseChild(i + initIndex));
                    }

                    // now remove blocks from rear

                    /*
                     * int lastBlockIndexInLayout = LastBlock.Node.Index;
                     *
                     * for (int i = 0; i < countToAdd; i++)
                     *  {
                     *  //MessageBox.Show ("Removing " +   mNode.PhraseChild ( lastBlockIndexInLayout - i ).Index.ToString () );
                     *  RemoveBlock ( mNode.PhraseChild(lastBlockIndexInLayout - i), true );
                     *  }
                     */
                }
                else if (initIndex > 0 &&
                         initIndex > FirstBlock.Node.Index)
                {
                    //MessageBox.Show ( "inside" );
                    int countToAdd = initIndex - FirstBlock.Node.Index;

                    if (LastBlock.Node.Index == mNode.PhraseChildCount - 1)
                    {
                        //MessageBox.Show ( "already showing to end " );
                        return;
                    }

                    // now add blocks at rear
                    for (int i = 0; i < countToAdd; i++)
                    {
                        //MessageBox.Show ( "adding " + (LastBlock.Node.Index + 1 ).ToString () );
                        try
                        {
                            AddBlockForNode(mNode.PhraseChild(LastBlock.Node.Index + 1));
                        }
                        catch (System.Exception ex)
                        {
                            countToAdd = i;
                            break;
                            MessageBox.Show(ex.ToString());
                        }
                    }

                    /*
                     * int removeStartIndex = FirstBlock.Node.Index;
                     * // first remove blocks from front
                     * for (int i = 0; i < countToAdd; i++)
                     *  {
                     *  RemoveBlock ( mNode.PhraseChild ( removeStartIndex ), true );
                     *
                     *  }
                     */
                }
            }
        }
Пример #11
0
        //@singleSection
        private ObiNode SearchInSection(string searchString, SearchDirection direction)
        {
            if (m_SectionActiveInContentView == null)
            {
                return(null);
            }

            EmptyNode currentlySelectedNode = mProjectView.Selection != null && mProjectView.Selection.Node is EmptyNode ? (EmptyNode)mProjectView.Selection.Node : null;

            ObiNode foundNode = null;

            if (direction == SearchDirection.NEXT)
            {
                int iterationIndex = currentlySelectedNode == null ? -1 : currentlySelectedNode.Index;

                for (int i = 0; i < m_SectionActiveInContentView.PhraseChildCount; ++i)
                {
                    ++iterationIndex;
                    if (iterationIndex >= m_SectionActiveInContentView.PhraseChildCount)
                    {
                        iterationIndex = 0;
                        System.Media.SystemSounds.Beep.Play();
                    }
                    if (m_SectionActiveInContentView.PhraseChild(iterationIndex).BaseStringShort().Contains(searchString.ToLower()))
                    {
                        foundNode = m_SectionActiveInContentView.PhraseChild(iterationIndex);
                        if (!mFoundFirst)
                        {
                            mFoundFirst = true;
                        }
                        break;
                    }

                    if (iterationIndex == m_SectionActiveInContentView.PhraseChildCount - 1 &&
                        m_SectionActiveInContentView.Label.ToLower().Contains(searchString.ToLower()))
                    {
                        foundNode = m_SectionActiveInContentView;
                        if (!mFoundFirst)
                        {
                            mFoundFirst = true;
                        }
                        break;
                    }
                }
            }
            else
            {
                int iterationIndex = currentlySelectedNode == null ? m_SectionActiveInContentView.PhraseChildCount : currentlySelectedNode.Index;

                for (int i = m_SectionActiveInContentView.PhraseChildCount - 1; i >= 0; --i)
                {
                    --iterationIndex;
                    if (iterationIndex < 0)
                    {
                        iterationIndex = m_SectionActiveInContentView.PhraseChildCount - 1;
                        System.Media.SystemSounds.Beep.Play();
                    }
                    if (m_SectionActiveInContentView.PhraseChild(iterationIndex).BaseStringShort().ToLower().Contains(searchString.ToLower()))
                    {
                        foundNode = m_SectionActiveInContentView.PhraseChild(iterationIndex);
                        break;
                    }

                    if (iterationIndex == 0 &&
                        m_SectionActiveInContentView.Label.ToLower().Contains(searchString.ToLower()))
                    {
                        foundNode = m_SectionActiveInContentView;
                        break;
                    }
                }
            }
            if (foundNode != null && m_ContentView != null)
            {
                if (m_FindStartNode != null && m_FindStartNode == foundNode)
                {
                    mProjectView.ObiForm.Status(Localizer.Message("Find_ReachedInitialPoint"));
                }

                if (!mFoundFirst)
                {
                    mFoundFirst     = true;
                    m_FindStartNode = foundNode;
                }
                if (foundNode is EmptyNode)
                {
                    m_ContentView.SelectPhraseBlockOrStrip((EmptyNode)foundNode);
                }
                else
                {
                    mProjectView.Selection = new NodeSelection(foundNode, m_ContentView);
                }

                return(foundNode);
            }
            mProjectView.ObiForm.Status(Localizer.Message("not_found_in_text"));
            return(null);
        }
Пример #12
0
        private void CreateElementsForSection(XmlDocument nccDocument, SectionNode section, int sectionIndex)
        {
            Time    sectionDuration = new Time();
            string  nccFileName     = "ncc.html";
            XmlNode bodyNode        = nccDocument.GetElementsByTagName("body")[0];
            XmlNode headingNode     = nccDocument.CreateElement(null, "h" + section.Level.ToString(), bodyNode.NamespaceURI);

            if (sectionIndex == 0)
            {
                CreateAppendXmlAttribute(nccDocument, headingNode, "class", "title");
            }
            else
            {
                CreateAppendXmlAttribute(nccDocument, headingNode, "class", "section");
            }
            string headingID = "h" + IncrementID;

            CreateAppendXmlAttribute(nccDocument, headingNode, "id", headingID);
            bodyNode.AppendChild(headingNode);

            // create smil document
            string      smilNumericFrag = (sectionIndex + 1).ToString().PadLeft(3, '0');
            string      smilFileName    = smilNumericFrag + ".smil";
            XmlDocument smilDocument    = CreateSmilStubDocument();
            XmlNode     smilBodyNode    = smilDocument.GetElementsByTagName("body")[0];

            // create main seq
            XmlNode mainSeq = smilDocument.CreateElement(null, "seq", smilBodyNode.NamespaceURI);

            CreateAppendXmlAttribute(smilDocument, mainSeq, "id", "sq" + IncrementID);

            // declare aseq node which is parent of audio elements
            XmlNode seqNode_AudioParent = null;
            // declare seq for heading phrase
            XmlNode seqNode_HeadingAudioParent = null;

            smilBodyNode.AppendChild(mainSeq);
            bool      isFirstPhrase           = true;
            EmptyNode adjustedPageNode        = m_NextSectionPageAdjustmentDictionary[section];
            bool      isPreviousNodeEmptyPage = false;

            for (int i = 0; i < section.PhraseChildCount || adjustedPageNode != null; i++)
            {
                EmptyNode phrase = null;
                //first handle the first phrase of the project if it is also the page
                // in such a case i=0 will be skipped being page, second phrase is exported and then first page is inserted to i=2
                if (i == 2 && m_FirstPageNumberedPhraseOfFirstSection != null)
                {
                    phrase = m_FirstPageNumberedPhraseOfFirstSection;
                    m_FirstPageNumberedPhraseOfFirstSection = null;
                    --i;
                }
                else if (i < section.PhraseChildCount)
                {
                    phrase = section.PhraseChild(i);
                }
                else
                {
                    phrase           = adjustedPageNode;
                    adjustedPageNode = null;
                }
                if (phrase.Role_ == EmptyNode.Role.Page && isFirstPhrase && i < section.PhraseChildCount)
                {
                    continue;
                }

                if ((phrase is PhraseNode && phrase.Used) ||
                    (phrase is EmptyNode && phrase.Role_ == EmptyNode.Role.Page && phrase.Used))
                {
                    string  pageID   = null;
                    XmlNode pageNode = null;
                    if (!isFirstPhrase && phrase.Role_ == EmptyNode.Role.Page)
                    {
                        string strClassVal = null;
                        // increment page counts and get page kind
                        switch (phrase.PageNumber.Kind)
                        {
                        case PageKind.Front:
                            m_PageFrontCount++;
                            strClassVal = "page-front";
                            break;

                        case PageKind.Normal:
                            m_PageNormalCount++;
                            if (phrase.PageNumber.Number > m_MaxPageNormal)
                            {
                                m_MaxPageNormal = phrase.PageNumber.Number;
                            }
                            strClassVal = "page-normal";
                            break;

                        case PageKind.Special:
                            m_PageSpecialCount++;
                            strClassVal = "page-special";
                            break;
                        }

                        pageNode = nccDocument.CreateElement(null, "span", bodyNode.NamespaceURI);
                        CreateAppendXmlAttribute(nccDocument, pageNode, "class", strClassVal);
                        pageID = "p" + IncrementID;
                        CreateAppendXmlAttribute(nccDocument, pageNode, "id", pageID);
                        bodyNode.AppendChild(pageNode);
                    }

                    // create smil nodes

                    // if phrase node is first phrase of section or is page node then create par and text
                    if (isFirstPhrase ||
                        phrase.Role_ == EmptyNode.Role.Page ||
                        isPreviousNodeEmptyPage)
                    {
                        // create par
                        XmlNode parNode = smilDocument.CreateElement(null, "par", smilBodyNode.NamespaceURI);
                        mainSeq.AppendChild(parNode);
                        CreateAppendXmlAttribute(smilDocument, parNode, "endsync", "last");
                        CreateAppendXmlAttribute(smilDocument, parNode, "id", "pr" + IncrementID);

                        XmlNode txtNode = smilDocument.CreateElement(null, "text", smilBodyNode.NamespaceURI);
                        parNode.AppendChild(txtNode);
                        string txtID = "txt" + IncrementID;
                        CreateAppendXmlAttribute(smilDocument, txtNode, "id", txtID);

                        if (isFirstPhrase ||
                            (isPreviousNodeEmptyPage && phrase.Role_ != EmptyNode.Role.Page))
                        {
                            //if(phrase.PageNumber != null)  Console.WriteLine("Page: " + phrase.PageNumber.ToString());
                            //Console.WriteLine("first page " + isFirstPhrase + " prev empty page " + isPreviousNodeEmptyPage);
                            CreateAppendXmlAttribute(smilDocument, txtNode, "src", nccFileName + "#" + headingID);
                        }
                        else if (pageNode != null)
                        {
                            CreateAppendXmlAttribute(smilDocument, txtNode, "src", nccFileName + "#" + pageID);
                        }

                        // create seq which will hol audio children
                        if (phrase is PhraseNode)
                        {
                            seqNode_AudioParent = smilDocument.CreateElement(null, "seq", smilBodyNode.NamespaceURI);
                            parNode.AppendChild(seqNode_AudioParent);
                            // hold seq for heading phrase in a variable.
                            if (isFirstPhrase)
                            {
                                seqNode_HeadingAudioParent = seqNode_AudioParent;
                            }
                            CreateAppendXmlAttribute(smilDocument, seqNode_AudioParent, "id", "sq" + IncrementID);
                        }

                        // add anchor and href to ncc elements
                        XmlNode anchorNode = nccDocument.CreateElement(null, "a", bodyNode.NamespaceURI);

                        if (isFirstPhrase)
                        {
                            headingNode.AppendChild(anchorNode);
                            CreateAppendXmlAttribute(nccDocument, anchorNode, "href", smilFileName + "#" + txtID);
                            anchorNode.AppendChild(
                                nccDocument.CreateTextNode(section.Label));
                        }
                        else if (pageNode != null)
                        {
                            pageNode.AppendChild(anchorNode);
                            CreateAppendXmlAttribute(nccDocument, anchorNode, "href", smilFileName + "#" + txtID);

                            anchorNode.AppendChild(
                                nccDocument.CreateTextNode(phrase.PageNumber.ToString()));
                        }
                    }

                    // create audio elements for external audio medias
                    if (phrase is PhraseNode)
                    {
                        Channel            publishChannel = m_Presentation.ChannelsManager.GetChannelsByName(urakawa.daisy.export.Daisy3_Export.PUBLISH_AUDIO_CHANNEL_NAME)[0];
                        ExternalAudioMedia externalMedia  = (ExternalAudioMedia)phrase.GetProperty <ChannelsProperty>().GetMedia(publishChannel);

                        XmlNode audioNode = smilDocument.CreateElement(null, "audio", smilBodyNode.NamespaceURI);
                        seqNode_AudioParent.AppendChild(audioNode);
                        string relativeSRC = AddSectionNameToAudioFile?
                                             AddSectionNameToAudioFileName(externalMedia.Src, phrase.ParentAs <SectionNode>().Label):
                                             Path.GetFileName(externalMedia.Src);
                        CreateAppendXmlAttribute(smilDocument, audioNode, "src", relativeSRC);
                        CreateAppendXmlAttribute(smilDocument, audioNode, "clip-begin",
                                                 GetNPTSmiltime(new TimeSpan(externalMedia.ClipBegin.AsTimeSpanTicks)));
                        CreateAppendXmlAttribute(smilDocument, audioNode, "clip-end",
                                                 GetNPTSmiltime(new TimeSpan(externalMedia.ClipEnd.AsTimeSpanTicks)));
                        CreateAppendXmlAttribute(smilDocument, audioNode, "id", "aud" + IncrementID);
                        sectionDuration.Add(externalMedia.Duration);
                        if (!m_FilesList.Contains(relativeSRC))
                        {
                            m_FilesList.Add(relativeSRC);
                        }

                        // copy audio element if phrase has  heading role and is not first phrase
                        if (phrase.Role_ == EmptyNode.Role.Heading && !isFirstPhrase)
                        {
                            XmlNode audioNodeCopy = audioNode.Clone();
                            audioNodeCopy.Attributes.GetNamedItem("id").Value = "aud" + IncrementID;
                            seqNode_HeadingAudioParent.PrependChild(audioNodeCopy);
                            sectionDuration.Add(externalMedia.Duration);
                        }
                    }//Check for audio containing phrase ends
                    isFirstPhrase = false;

                    if (phrase  is EmptyNode && phrase.Role_ == EmptyNode.Role.Page)
                    {
                        isPreviousNodeEmptyPage = true;
                    }
                    else
                    {
                        isPreviousNodeEmptyPage = false;
                    }
                } // if for phrasenode ends
            }     // for loop ends

            // check if heading node have some children else remove it.
            // it is possible that all phrases are empty phrases or unused phrases, so there are no anchor children of heading node.
            if (headingNode.ChildNodes.Count == 0)
            {
                bodyNode.RemoveChild(headingNode);
            }
            else
            {
                // first increment exported section count
                m_ExportedSectionCount++;

                string strDurTime = TruncateTimeToDecimalPlaces(new TimeSpan(sectionDuration.AsTimeSpanTicks).TotalSeconds.ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US")), 3);
                //string strDurTime = Math.Round ( sectionDuration.getTime ().TotalSeconds, 3, MidpointRounding.ToEven).ToString ();
                strDurTime = strDurTime + "s";
                CreateAppendXmlAttribute(smilDocument, mainSeq, "dur", strDurTime);

                //AddSmilHeadElements ( smilDocument, m_SmilElapseTime.ToString (), sectionDuration.ToString () );
                AddSmilHeadElements(smilDocument, AdjustTimeStringForDay(new TimeSpan(m_SmilElapseTime.AsTimeSpanTicks)),
                                    AdjustTimeStringForDay(new TimeSpan(sectionDuration.AsTimeSpanTicks)));
                m_SmilElapseTime.Add(sectionDuration);
                m_SmilFile_TitleMap.Add(smilFileName, section.Label);

                WriteXmlDocumentToFile(smilDocument,
                                       Path.Combine(m_ExportDirectory, smilFileName));
                if (!m_FilesList.Contains(smilFileName))
                {
                    m_FilesList.Add(smilFileName);
                }
            }
        }