Exemplo n.º 1
0
        protected override void SetModelMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase, IBaseNode node)
        {
            var container = Get <IContainer>(node.Id);

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddNew(ObjectTypes.Container))
                                        .WithCommandFor <AddNewCommandFor <IContainer, IContainer>, IContainer>(container)
                                        .WithIcon(ApplicationIcons.ContainerAdd));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddExisting(ObjectTypes.Container))
                                        .WithCommandFor <AddExistingCommandFor <IContainer, IContainer>, IContainer>(container)
                                        .WithIcon(ApplicationIcons.ContainerLoad));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddNew(ObjectTypes.Parameter))
                                        .WithCommandFor <AddNewCommandFor <IContainer, IParameter>, IContainer>(container)
                                        .WithIcon(ApplicationIcons.Parameters));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddExisting(ObjectTypes.Parameter))
                                        .WithCommandFor <AddExistingCommandFor <IContainer, IParameter>, IContainer>(container)
                                        .WithIcon(ApplicationIcons.PKMLLoad));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddNew(ObjectTypes.DistributedParameter))
                                        .WithCommandFor <AddNewCommandFor <IContainer, IDistributedParameter>, IContainer>(container)
                                        .WithIcon(ApplicationIcons.ParameterDistribution));

            base.SetModelMenuItems(contextMenuView, containerBase, node);

            if (container.ParentContainer == null) // container is TopContainer
            {
                contextMenuView.RemoveMenuItem(AppConstants.MenuNames.Delete);
                contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.Delete)
                                            .WithCommandFor <RemoveTopContainerCommand, IContainer>(Get <IContainer>(node.Id))
                                            .WithIcon(ApplicationIcons.Delete));
            }
        }
 protected override void SetLayoutMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase)
 {
     AddTemplateLayoutMenuItems(contextMenuView, containerBase);
     AddAutoLayoutMenuItems(contextMenuView, containerBase);
     contextMenuView.AddMenuItem(SubMenuLayout);
     contextMenuView.AddMenuItem(CreateMenuButton.WithCaption("AutoLayout in layers")
                                 .WithActionCommand(() => Presenter.LayerLayout(containerBase)));
 }
Exemplo n.º 3
0
        public void Copy(IContainerBase sourceTopContainer, IContainerBase targetTopContainer)
        {
            if (sourceTopContainer == null || targetTopContainer == null)
            {
                return;
            }

            bool   expanded        = true;
            PointF location        = targetTopContainer.Location;
            int    topLevelsToSkip = 0;

            var targetContainerNode = targetTopContainer as IContainerNode;

            if (targetContainerNode != null)
            {
                expanded = targetContainerNode.IsExpanded;
                location = targetContainerNode.Location;
                targetContainerNode.IsExpanded = true;
                topLevelsToSkip = 1;
            }

            foreach (var targetNode in targetTopContainer.GetDirectChildren <IContainerNode>())
            {
                copyContainerRecursive(sourceTopContainer, targetTopContainer, targetNode, topLevelsToSkip);

                var sourceNode = getNodeByPath(sourceTopContainer, targetTopContainer, targetNode, topLevelsToSkip);
                if (sourceNode == null)
                {
                    continue;
                }

                targetNode.CopyLayoutInfoFrom(sourceNode, location);
            }

            foreach (var targetNode in targetTopContainer.GetDirectChildren <IElementBaseNode>())
            {
                var sourceNode = getNodeByPath(sourceTopContainer, targetTopContainer, targetNode, topLevelsToSkip);
                if (sourceNode == null)
                {
                    continue;
                }

                targetNode.CopyLayoutInfoFrom(sourceNode, location);
            }

            if (targetContainerNode != null)
            {
                targetContainerNode.IsExpanded = expanded;
                targetContainerNode.Location   = location;

                var sourceContainerNode = sourceTopContainer as IContainerNode;
                if (sourceContainerNode != null)
                {
                    targetContainerNode.IsExpandedByDefault = sourceContainerNode.IsExpandedByDefault;
                }
            }
        }
Exemplo n.º 4
0
 public void SelectChildren(IContainerBase containerBase)
 {
     _view.ClearSelection();
     foreach (var baseNode in containerBase.GetDirectChildren <IBaseNode>())
     {
         _view.Select(baseNode);
     }
     _view.Refresh();
 }
Exemplo n.º 5
0
        protected void AddAutoLayoutMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase)
        {
            if (containerBase == null)
            {
                return;
            }

            SubMenuLayout.AddItem(CreateMenuButton.WithCaption("AutoLayout Children").AsGroupStarter().WithActionCommand(() => Presenter.Layout(containerBase, AppConstants.Diagram.Base.LayoutDepthChildren, null)));
        }
Exemplo n.º 6
0
        public void CopyRecursive(IContainerBase source, IContainerBase target)
        {
            foreach (var targetChild in target.GetDirectChildren <IContainerNode>())
            {
                CopyRecursive(source, targetChild);
            }

            Copy(source, target);
        }
        protected override void SetLayoutMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase)
        {
            AddTemplateLayoutMenuItems(contextMenuView, containerBase);

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption("Apply current Layouts from Structure and Reactions")
                                        .WithActionCommand(askAndApplySpaceReactionLayout));

            AddAutoLayoutMenuItems(contextMenuView, containerBase);
            contextMenuView.AddMenuItem(SubMenuLayout);
        }
Exemplo n.º 8
0
        public void SaveBitmapToFile(IContainerBase containerBase)
        {
            var imageFilePath = _dialogCreator.AskForFileToSave(Captions.SaveImage, Constants.Filter.DIAGRAM_IMAGE_FILTER, Constants.DirectoryKey.REPORT);

            if (string.IsNullOrEmpty(imageFilePath))
            {
                return;
            }
            GetBitmap(containerBase).Save(imageFilePath, ImageFormat.Png);
        }
        protected override IBaseNode AddObjectBase(IContainerBase parent, IObjectBase objectBase, bool recursive, bool coupleAll)
        {
            var node = AddAndCoupleNode <IReactionBuilder, ReactionNode>(parent, objectBase as IReactionBuilder, coupleAll);

            if (node != null)
            {
                return(node);
            }

            return(base.AddObjectBase(parent, objectBase, recursive, coupleAll));
        }
Exemplo n.º 10
0
        protected virtual IBaseNode AddObjectBase(IContainerBase parent, IObjectBase objectBase, bool recursive, bool coupleAll)
        {
            IBaseNode node = AddNeighborhood(objectBase as INeighborhoodBase);

            if (node != null)
            {
                return(node);
            }
            node = AddContainer(parent, objectBase as IContainer, recursive, coupleAll);
            return(node);
        }
Exemplo n.º 11
0
        public void CopyBitmapToClipboard(IContainerBase containerBase)
        {
            using (var ms = new MemoryStream())
            {
                GetBitmap(containerBase).Save(ms, ImageFormat.Png);
                ms.Seek(0, SeekOrigin.Begin);

                Image image = Image.FromStream(ms);
                Clipboard.SetImage(image);
            }
        }
Exemplo n.º 12
0
        public void PerformLayout(IContainerBase containerBase, IList <IHasLayoutInfo> freeNodes)
        {
            GoDocument doc = containerBase as GoDocument;

            if (doc == null && containerBase as GoObject == null)
            {
                _dialogCreator.MessageBoxInfo("Bad ContainerBase Type = " + containerBase.GetType().Name);
                return;
            }

            if (doc == null)
            {
                doc = ((GoObject)containerBase).Document;
            }
            Document = doc;

            doc.StartTransaction();

            string text = "DiagramModel";
            var    containerBaseNode = containerBase as IContainerNode;

            if (containerBaseNode != null)
            {
                text = containerBaseNode.GetLongName();
            }

            LayerSpacing      = 0F;
            ColumnSpacing     = 0F;
            DirectionOption   = GoLayoutDirection.Right;
            CycleRemoveOption = GoLayoutLayeredDigraphCycleRemove.DepthFirst;
            LayeringOption    = GoLayoutLayeredDigraphLayering.OptimalLinkLength;
            InitializeOption  = GoLayoutLayeredDigraphInitIndices.DepthFirstOut;
            Iterations        = 4;
            AggressiveOption  = GoLayoutLayeredDigraphAggressive.Less;
            PackOption        = GoLayoutLayeredDigraphPack.Straighten;
            SetsPortSpots     = false;


            var net = CreateNetwork();

            net.AddNodesAndLinksFromCollection(containerBase as IGoCollection, true);

            setNodeType(net, freeNodes);

            Network = net;

            if (net.NodeCount > 0)
            {
                base.PerformLayout();
            }
            doc.FinishTransaction("DoLayerLayout");
        }
        public void SaveContainerToXml(IContainerBase containerBase, string diagramTemplateXmlFilePath)
        {
            if (string.IsNullOrEmpty(diagramTemplateXmlFilePath))
            {
                diagramTemplateXmlFilePath = _dialogCreator.AskForFileToSave(AppConstants.Captions.SaveLayoutToFile, AppConstants.Filter.MOBI_DIAGRAM_TEMPLATE_FILTER, AppConstants.DirectoryKey.LAYOUT);
            }

            if (string.IsNullOrEmpty(diagramTemplateXmlFilePath))
            {
                return;
            }

            _diagramTask.SaveContainerToXml(containerBase, diagramTemplateXmlFilePath);
        }
        public override void ShowContextMenu(IBaseNode baseNode, Point popupLocation, PointF locationInDiagramView)
        {
            var            popupMenu     = GetPopupMenu(baseNode);
            IContainerBase containerBase = null;

            if (baseNode == null)
            {
                containerBase = DiagramModel;
            }
            else if (baseNode.IsAnImplementationOf <IContainerNode>())
            {
                containerBase = baseNode as IContainerNode;
            }

            popupMenu?.Show(_view, popupLocation, locationInDiagramView, containerBase, baseNode);
        }
Exemplo n.º 15
0
        public void LayoutReactionDiagram(IContainerBase containerBase)
        {
            var diagramModel = containerBase as IDiagramModel;

            foreach (var reactionNode in containerBase.GetAllChildren <ReactionNode>())
            {
                reactionNode.DisplayEductsRight = false;
            }

            _layerLayouter.PerformLayout(containerBase, null);

            if (diagramModel != null)
            {
                diagramModel.IsLayouted = true;
            }
        }
Exemplo n.º 16
0
        public void Layout(IContainerBase containerBase, int levelDepth, IList <IHasLayoutInfo> freeNodes)
        {
            if (containerBase == null)
            {
                containerBase = DiagramModel;
            }

            if (containerBase == DiagramModel)
            {
                FixLocationFirstVisibleTopContainer(); // to avoid moving container
            }
            _layouter.ForceLayoutConfiguration = LayoutConfiguration;
            _layouter.DoForceLayout(containerBase, freeNodes, levelDepth);
            DiagramModel.IsLayouted = true;
            _view.Refresh();
        }
Exemplo n.º 17
0
        public void DoForceLayout(IContainerBase containerBase, IList <IHasLayoutInfo> freeNodes, int levelDepth)
        {
            var doc = containerBase as GoDocument;

            if (doc == null)
            {
                doc = ((GoObject)containerBase).Document;
            }

            _simpleForceLayouter.Document = doc;

            doc.StartTransaction();
            doc.Bounds = doc.ComputeBounds();
            DoLayoutForContainerBase(_simpleForceLayouter, containerBase, freeNodes, levelDepth);
            doc.Bounds = doc.ComputeBounds();
            doc.FinishTransaction("DoCompleteForceLayout");
        }
        protected override void SetModelMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase, IBaseNode node)
        {
            var entity = Get <T>(node.Id);

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.Rename)
                                        .WithCommandFor <RenameObjectCommand <T>, T>(entity).WithIcon(ApplicationIcons.Rename));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.Edit)
                                        .WithCommandFor <EditCommandFor <T>, T>(entity).WithIcon(ApplicationIcons.Edit));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.SaveAsPKML)
                                        .WithCommandFor <SaveUICommandFor <T>, T>(entity).WithIcon(ApplicationIcons.SaveIconFor(typeof(T).Name)));

            createRemoveCommandFor(contextMenuView, entity);

            base.SetModelMenuItems(contextMenuView, containerBase, node);
        }
Exemplo n.º 19
0
        public void InvertSelection(IContainerBase containerBase)
        {
            IList <IBaseNode> notSelectedNodes = new List <IBaseNode>();

            foreach (var baseNode in containerBase.GetDirectChildren <IBaseNode>())
            {
                if (!_view.SelectionContains(baseNode))
                {
                    notSelectedNodes.Add(baseNode);
                }
            }
            _view.ClearSelection();
            foreach (var baseNode in notSelectedNodes)
            {
                _view.Select(baseNode);
            }
        }
        protected override void SetModelMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase, IBaseNode node)
        {
            var parent   = Presenter.Subject as IMoBiSpatialStructure;
            var menuItem = CreateMenuButton.WithCaption(AppConstants.MenuNames.AddNew("Top Container"))
                           .WithCommandFor <AddNewTopContainerCommand, IMoBiSpatialStructure>(parent)
                           .WithIcon(ApplicationIcons.ContainerAdd);

            contextMenuView.AddMenuItem(menuItem);

            var menuItem2 = CreateMenuButton.WithCaption(AppConstants.MenuNames.AddExisting("Top Container"))
                            .WithCommand <AddExistingTopContainerCommand>()
                            .WithIcon(ApplicationIcons.ContainerLoad);

            contextMenuView.AddMenuItem(menuItem2);

            base.SetModelMenuItems(contextMenuView, containerBase, node);
        }
        protected override void SetModelMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase, IBaseNode node)
        {
            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.RibbonButtonNames.NewMolecule)
                                        .WithActionCommand(() => Presenter.AddMoleculeNode())
                                        .WithIcon(ApplicationIcons.MoleculeAdd));

            var parent = Presenter.Subject as IMoBiReactionBuildingBlock;

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddNew(ObjectTypes.Reaction))
                                        .WithCommandFor <AddNewCommandFor <IMoBiReactionBuildingBlock, IReactionBuilder>, IMoBiReactionBuildingBlock>(parent)
                                        .WithIcon(ApplicationIcons.ReactionAdd));

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption(AppConstants.MenuNames.AddExisting(ObjectTypes.Reaction))
                                        .WithCommandFor <AddExistingCommandFor <IMoBiReactionBuildingBlock, IReactionBuilder>, IMoBiReactionBuildingBlock>(parent)
                                        .WithIcon(ApplicationIcons.ReactionLoad));

            base.SetModelMenuItems(contextMenuView, containerBase, node);
        }
Exemplo n.º 22
0
        public void RemoveNode(string id)
        {
            IBaseNode node = GetNode(id);

            if (node == null)
            {
                return;
            }

            IContainerBase parent = node.GetParent();

            parent.RemoveChildNode(node);

            if (_nodes.Contains(id))
            {
                _nodes.Remove(id);
            }
        }
Exemplo n.º 23
0
        protected virtual TContainerNode AddContainer(IContainerBase parent, IContainer container, bool recursive, bool coupleAll)
        {
            if (container == null || container.GetType() != typeof(Container))
            {
                return(null);
            }

            var containerNode = AddAndCoupleNode <IContainer, TContainerNode>(parent, container, coupleAll);

            if (recursive)
            {
                foreach (var child in container.Children)
                {
                    AddObjectBase(containerNode, child, true, coupleAll);
                }
            }

            return(containerNode);
        }
Exemplo n.º 24
0
        private IEnumerable <IContainerBase> getExpandedChildren(IContainerBase containerBase, int level)
        {
            var children = new List <IContainerBase>();

            if (level == 0)
            {
                children.Add(containerBase);
            }
            else
            {
                foreach (var childContainerNode in containerBase.GetDirectChildren <IContainerNode>())
                {
                    if (childContainerNode.IsExpanded)
                    {
                        children.AddRange(getExpandedChildren(childContainerNode, level - 1));
                    }
                }
            }
            return(children);
        }
Exemplo n.º 25
0
        protected virtual void SetDiagramMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase)
        {
            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption("Refresh").WithActionCommand(() => Presenter.Refresh()).WithIcon(ApplicationIcons.Refresh).AsGroupStarter());

            contextMenuView.AddMenuItem(CreateMenuButton.WithCaption("Undo Diagram Layout Change").WithActionCommand(() => Presenter.Undo()).WithIcon(ApplicationIcons.Undo));

            if (Presenter.SelectionContains <IBaseNode>())
            {
                SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("To Front").AsGroupStarter().WithActionCommand(() => Presenter.MoveDiagramSelectionToFront()).WithIcon(ApplicationIcons.Forward));
                SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("To Back").WithActionCommand(() => Presenter.MoveDiagramSelectionToBack()).WithIcon(ApplicationIcons.Back));
            }


            SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("Zoom In").AsGroupStarter().WithCommand <ZoomInCommand>().WithIcon(ApplicationIcons.ZoomIn));
            SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("Zoom Out").WithCommand <ZoomOutCommand>().WithIcon(ApplicationIcons.ZoomOut));
            SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("Fit into Window").WithCommand <FitToPageCommand>().WithIcon(ApplicationIcons.FitToPage));
            SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("Copy Image to Clipboard").AsGroupStarter().WithActionCommand(() => Presenter.CopyBitmapToClipboard(containerBase)));
            SubMenuDiagram.AddItem(CreateMenuButton.WithCaption("Save Image...").WithActionCommand(() => Presenter.SaveBitmapToFile(containerBase)));

            contextMenuView.AddMenuItem(SubMenuDiagram);
        }
Exemplo n.º 26
0
        private void replaceInnerNeighborhoodNodesByDirectLinks(IContainerBase containerBase, GoLayoutForceDirectedNetwork net)
        {
            // replace neighborhood nodes and neighbor links by direct links between the nodes they connect (ContainerNodes or PortNodes)
            foreach (var neighborHoodNode in containerBase.GetDirectChildren <INeighborhoodNode>())
            {
                var fromLink = net.FindLink(neighborHoodNode.FirstNeighborLink as GoObject);
                var toLink   = net.FindLink(neighborHoodNode.SecondNeighborLink as GoObject);
                if (fromLink == null || toLink == null)
                {
                    continue;
                }

                var netLink = new GoLayoutForceDirectedLink {
                    FromNode = fromLink.ToNode, ToNode = toLink.ToNode
                };
                netLink.GoObject  = neighborHoodNode as GoObject;
                netLink.Length    = Config.BaseSpringLength * Config.RelativeSpringLengthOf[NodeLayoutType.CONTAINER_NODE, NodeLayoutType.CONTAINER_NODE].Value;
                netLink.Stiffness = Config.BaseSpringLength * Config.RelativeSpringStiffnessOf[NodeLayoutType.CONTAINER_NODE, NodeLayoutType.CONTAINER_NODE].Value;
                net.DeleteNode(neighborHoodNode as GoObject);
                net.AddLink(netLink);
            }
        }
Exemplo n.º 27
0
        protected override IBaseNode AddObjectBase(IContainerBase parent, IObjectBase objectBase, bool recursive, bool coupleAll)
        {
            IElementBaseNode eNode = AddAndCoupleNode <IMoleculeAmount, MoleculeNode>(parent, objectBase as IMoleculeAmount, coupleAll);

            if (eNode == null)
            {
                eNode = AddAndCoupleNode <IObserver, ObserverNode>(parent, objectBase as IObserver, coupleAll);
            }

            if (eNode == null)
            {
                eNode = AddAndCoupleNode <IReaction, ReactionNode>(parent, objectBase as IReaction, coupleAll);
            }

            if (eNode != null)
            {
                eNode.CanLink = false;
                return(eNode);
            }

            return(base.AddObjectBase(parent, objectBase, recursive, coupleAll));
        }
        /// <summary>
        ///    Handle select event by selecting node.
        /// </summary>
        public void Handle(EntitySelectedEvent eventToHandle)
        {
            if (DiagramManager == null)
            {
                return;
            }
            if (!DiagramManager.MustHandleExisting(eventToHandle.ObjectBase.Id))
            {
                return;
            }

            IBaseNode baseNode = DiagramModel.GetNode(eventToHandle.ObjectBase.Id);

            if (baseNode == null)
            {
                return;
            }

            IContainerBase parentContainer = baseNode.GetParent();

            // Show node and parents
            baseNode.Hidden = false;
            baseNode.ShowParents();

            _view.ExpandParents(baseNode);

            // Expand parent
            var parentContainerNode = parentContainer as IContainerNode;

            if (parentContainerNode != null)
            {
                Focus(parentContainerNode);
            }

            _view.ClearSelection();
            _view.Select(baseNode);
            _view.CenterAt(baseNode);
        }
Exemplo n.º 29
0
        protected void DoLayoutForContainerBase(IBaseForceLayout layouter, IContainerBase containerBase, IList <IHasLayoutInfo> freeNodes, int levelDepth)
        {
            // Layout each childcontainer to determine the right size
            for (int level = levelDepth; level > 0; level--)
            {
                foreach (var childContainer in getExpandedChildren(containerBase, level))
                {
                    layouter.PerformLayout(childContainer, freeNodes);
                    childContainer.PostLayoutStep();
                }
            }

            // Layout each childcontainer again to layout the content based on neighborhood ports
            for (int level = 0; level <= levelDepth; level++)
            {
                foreach (var childContainer in getExpandedChildren(containerBase, level))
                {
                    layouter.PerformLayout(childContainer, freeNodes);
                    childContainer.PostLayoutStep();
                }
            }
            containerBase.PostLayoutStep();
        }
Exemplo n.º 30
0
        public void ApplyLayoutTemplate(IContainerBase containerBase, string diagramTemplateXmlFilePath, IDiagramModel model, Action refreshFromDiagramOptions, bool recursive)
        {
            if (string.IsNullOrEmpty(diagramTemplateXmlFilePath))
            {
                throw new MoBiException(AppConstants.Exceptions.MissingName);
            }
            var diagramTemplateModel = LoadDiagramTemplate(diagramTemplateXmlFilePath);

            if (diagramTemplateModel == null)
            {
                throw new MoBiException(AppConstants.Exceptions.DeserializationFailed);
            }

            try
            {
                model.BeginUpdate();

                var copier = new LayoutCopyService();
                if (recursive)
                {
                    copier.CopyRecursive(diagramTemplateModel, containerBase);
                }
                else
                {
                    copier.Copy(diagramTemplateModel, containerBase);
                }

                foreach (var neighborhoodNode in containerBase.GetAllChildren <INeighborhoodNode>())
                {
                    neighborhoodNode.AdjustPosition();
                }

                refreshFromDiagramOptions();
                model.IsLayouted = true;
            }
            finally { model.EndUpdate(); }
        }