コード例 #1
0
ファイル: MindMapView.Edit.cs プロジェクト: namit3/BlueMind
        public virtual Topic AddBarrierRight()
        {
            Topic selectedTp = SelectedTopic;
            Topic refTopic   = null;

            if (selectedTp.Type == TopicType.Barrier)
            {
                refTopic   = SelectedTopic;
                selectedTp = selectedTp.ParentTopic;
                if (refTopic.Left <= refTopic.GetRoot().Left)
                {
                    XList <Topic> siblings = refTopic.ParentTopic.Children;
                    int           index    = siblings.IndexOf(refTopic) - 1;
                    if (index >= 0)
                    {
                        refTopic = siblings[index];
                    }
                    else
                    {
                        refTopic = null;
                    }
                }
            }
            if (selectedTp != null && (selectedTp.Type == TopicType.Consequence || selectedTp.Type == TopicType.Threat || selectedTp.Type == TopicType.Escalation))
            {
                return(AddSubTopic(selectedTp, refTopic, TopicType.Barrier, false));
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: CustomSortCommand.cs プロジェクト: namit3/BlueMind
        private TopicType ChildrenType; // Only use for Threat & Consequence type

        public CustomSortCommand(Topic[] topics, int step)
        {
            if (topics == null || topics.Length == 0 || step == 0)
            {
                return;
            }

            Parent = topics[0].ParentTopic;
            if (Parent == null)
            {
                return;
            }

            ChildrenType = topics[0].Type;

            // get topics them have a same parent
            XList <Topic> siblings = new XList <Topic>();

            if (Parent.IsRoot)
            {
                siblings = Parent.GetChildrenByType(ChildrenType);
            }
            List <int> moveIndices = new List <int>();

            foreach (Topic topic in topics)
            {
                if (topic.ParentTopic == Parent)
                {
                    if (Parent.IsRoot)
                    {
                        moveIndices.Add(siblings.IndexOf(topic));
                    }
                    else
                    {
                        moveIndices.Add(topic.Index);
                    }
                }
            }
            XList <Topic> children = GetChildren(Parent);

            NewIndices = GetNewIndices(children.Count, moveIndices.ToArray(), step);
        }
コード例 #3
0
        Rectangle LayoutSubTopics(Topic parent, Topic[] subTopics, Vector4 vector, XList <int> rows, XList <int> columns, int parentRow, int parentCol, MindMapLayoutArgs e)
        {
            if (parent == null)
            {
                throw new ArgumentNullException();
            }

            if (rows.IsEmpty || columns.IsEmpty)
            {
                return(Rectangle.Empty);
            }

            if (parent.Folded || parent.Children.IsEmpty)
            {
                return(Rectangle.Empty);
            }

            int   vSpace = e.ItemsSpace;
            Topic root   = parent.GetRoot();

            Rectangle rectFull = Rectangle.Empty;
            Point     pp       = PaintHelper.CenterPoint(root.ContentBounds);

            int   fullHeight = GetYPos(rows.Count - 1, vSpace, rows);
            int   x          = vector == Vector4.Left ? root.Left - e.LayerSpace : root.Right + e.LayerSpace;
            int   y          = pp.Y - (fullHeight / 2) - 30;
            int   hSpace     = 10;
            Topic previous   = parent == root ? root : parent.ParentTopic;
            int   prevRow    = 0;

            for (int i = 0, n = subTopics.Length; i < n; ++i)
            {
                Topic subTopic = subTopics[i];
                subTopic.Vector = vector;
                int row = 0, column = 0;
                switch (vector)
                {
                case Vector4.Top:
                    subTopic.Location = new Point(root.Bounds.Left - (subTopic.Width - root.Width) / 2, parent.Location.Y - e.LayerSpace - subTopic.Size.Height);
                    break;

                case Vector4.Left:
                case Vector4.Right:
                default:
                    if (subTopic.Type == TopicType.Barrier)
                    {
                        column = parentCol - subTopics.Length + i;
                        row    = parentRow;
                    }
                    else
                    {
                        column = parentCol + (subTopic.Folded ? 0 : subTopic.Children.Count) + 1;
                        row    = parentRow + 1;
                        if (subTopic.Type == TopicType.Escalation)
                        {
                            int maxUncleRow = 0;
                            if (parent.ParentTopic != null)
                            {
                                XList <Topic> children  = parent.ParentTopic.Children;
                                int           nextIndex = children.IndexOf(parent) + 1;
                                if (nextIndex < children.Count)
                                {
                                    maxUncleRow = CalculateMaxRow(children[nextIndex], children.ToArray());
                                }
                            }

                            int maxSiblingRow = 0;
                            int prevIndex     = i - 1;
                            if (prevIndex >= 0)
                            {
                                maxSiblingRow = CalculateMaxRow(parent.Children[prevIndex], parent.Children.ToArray());
                            }
                            row += maxSiblingRow + maxUncleRow;
                        }
                        else if (parent.IsRoot)
                        {
                            int prevIndex = i - 1;
                            if (prevIndex >= 0)
                            {
                                row += CalculateMaxRow(subTopics[prevIndex], subTopics);
                            }
                        }
                    }
                    Point pt = new Point(GetXPos(column, hSpace, columns, vector), GetYPos(row, vSpace, rows));
                    if (subTopic.Type == TopicType.Barrier)
                    {
                        if (vector == Vector4.Left)
                        {
                            pt.X -= (subTopic.ContentBounds.Width - subTopic.Width) / 2;
                        }
                        else
                        {
                            pt.X += (subTopic.ContentBounds.Width - subTopic.Width) / 2;
                        }
                    }
                    subTopic.Location = new Point(vector == Vector4.Left ? x - pt.X: x + pt.X, pt.Y + y);
                    prevRow           = row;
                    break;
                }

                // line
                if (!parent.Folded && subTopic.Type == TopicType.Barrier)
                {
                    var lines = CreateTopicLines(e, previous, subTopic, vector, GetReverseVector(vector));
                    if (lines != null)
                    {
                        parent.Lines.AddRange(lines);
                    }
                }
                subTopic.Lines.Clear();

                Rectangle rectFullSub = LayoutSubTopics(subTopic, subTopic.Children.ToArray(), vector, rows, columns, row, column, e);
                // Threat topic will be drawn as the last element
                if (subTopic.Type == TopicType.Threat || subTopic.Type == TopicType.Consequence || subTopic.Type == TopicType.Escalation)
                {
                    Topic beginNode, endNode;
                    if (subTopic.HasChildren && !subTopic.Folded)
                    {
                        beginNode = subTopic.Children[subTopic.Children.Count - 1];
                        endNode   = subTopic;
                    }
                    else
                    {
                        beginNode = parent;
                        endNode   = subTopic;
                    }
                    var lines = CreateTopicLines(e, beginNode, endNode, vector, GetReverseVector(vector));
                    if (lines != null)
                    {
                        beginNode.Lines.AddRange(lines);
                    }

                    if (subTopic.HasChildren)
                    {
                        int foldBtnSize = FoldingButtonSize;
                        if (vector == Vector4.Left)
                        {
                            subTopic.FoldingButton = new Rectangle(subTopic.Right - foldBtnSize + 4,
                                                                   subTopic.Top + (int)Math.Round((60 - foldBtnSize) / 2.0f, MidpointRounding.AwayFromZero),
                                                                   foldBtnSize,
                                                                   foldBtnSize);
                        }
                        else if (vector == Vector4.Right)
                        {
                            subTopic.FoldingButton = new Rectangle(subTopic.Left - foldBtnSize + 4,
                                                                   subTopic.Top + (int)Math.Round((60 - foldBtnSize) / 2.0f, MidpointRounding.AwayFromZero),
                                                                   foldBtnSize,
                                                                   foldBtnSize);
                        }
                    }
                }
                else if (subTopic.Type == TopicType.Hazard)
                {
                    var lines = CreateTopicLines(e, root, subTopic, vector, GetReverseVector(vector));
                    if (lines != null)
                    {
                        root.Lines.AddRange(lines);
                    }
                }

                rectFull = Rectangle.Union(rectFull, subTopic.ContentBounds);
                if (!rectFullSub.IsEmpty)
                {
                    rectFull = Rectangle.Union(rectFull, rectFullSub);
                }
                previous = subTopic;
            }

            return(rectFull);
        }
コード例 #4
0
ファイル: MindMapChartPage.cs プロジェクト: namit3/BlueMind
        public override IEnumerable <ExtendActionInfo> GetExtendActions()
        {
            var actions = new List <ExtendActionInfo>();

            if (mindMapView1.CanPasteAsRemark && Clipboard.ContainsText())
            {
                //actions.Add(new ExtendActionInfo("Paste as Note", Properties.Resources.paste_as_remark, MenuPasteAsNote_Click));
            }

            if (mindMapView1.CanPaste && Clipboard.ContainsImage())
            {
                //actions.Add(new ExtendActionInfo("Paste as Image", Properties.Resources.paste_as_image, MenuPasteAsImage_Click));
            }

            Topic topic = mindMapView1.SelectedTopic;

            if (topic != null && !ReadOnly && topic.Type != TopicType.Hazard)
            {
                Topic root = topic.GetRoot();
                if (topic.ParentTopic != null && topic.ParentTopic.Children.Count > 0)
                {
                    int           index    = topic.Index;
                    XList <Topic> children = topic.ParentTopic.Children;
                    if (topic.ParentTopic.IsRoot)
                    {
                        children = topic.ParentTopic.GetChildrenByType(topic.Type);
                        index    = children.IndexOf(topic);
                    }
                    if (index > 0)
                    {
                        if (topic.Type == TopicType.Barrier)
                        {
                            if (topic.Left <= root.Left)
                            {
                                actions.Add(new ExtendActionInfo("Move Right", Properties.Resources.right, KeyMap.MoveRight.ToString(), MenuMoveDown_Click));
                            }
                            else
                            {
                                actions.Add(new ExtendActionInfo("Move Left", Properties.Resources.left, KeyMap.MoveLeft.ToString(), MenuMoveUp_Click));
                            }
                        }
                        else
                        {
                            actions.Add(new ExtendActionInfo("Move Up", Properties.Resources.up, KeyMap.MoveUp.ToString(), MenuMoveUp_Click));
                        }
                    }

                    if (index < children.Count - 1)
                    {
                        if (topic.Type == TopicType.Barrier)
                        {
                            if (topic.Left <= root.Left)
                            {
                                actions.Add(new ExtendActionInfo("Move Left", Properties.Resources.left, KeyMap.MoveLeft.ToString(), MenuMoveUp_Click));
                            }
                            else
                            {
                                actions.Add(new ExtendActionInfo("Move Right", Properties.Resources.right, KeyMap.MoveRight.ToString(), MenuMoveDown_Click));
                            }
                        }
                        else
                        {
                            actions.Add(new ExtendActionInfo("Move Down", Properties.Resources.down, KeyMap.MoveDown.ToString(), MenuMoveDown_Click));
                        }
                    }
                }

                if (SelectedObjects.Length == 1 && topic.Children.Count > 1)
                {
                    //actions.Add(new ExtendActionInfo(Lang.GetTextWithEllipsis("Custom Sort"), null, MenuCustomSort_Click));
                }
            }

            return(actions);
        }