Exemplo n.º 1
0
        public void ApplySpaceReactionLayout()
        {
            var copier = new LayoutCopyService();

            // if only one organ is visible, in following Copy steps some wrong locations are calculated
            ShowChildren(DiagramModel);

            try
            {
                _view.BeginUpdate();
                var reactionDiagramModel = getReactionBlockDiagramModel();
                if (reactionDiagramModel != null && reactionDiagramModel.IsLayouted)
                {
                    copier.Copy(reactionDiagramModel, DiagramModel);
                }

                var spaceDiagramModel = getSpaceBlockDiagramModel();
                if (spaceDiagramModel != null && spaceDiagramModel.IsLayouted)
                {
                    copier.Copy(spaceDiagramModel, DiagramModel);
                }

                DiagramManager.RefreshFromDiagramOptions();
                DiagramModel.IsLayouted = true;
            }
            finally
            {
                _view.EndUpdate();
            }

            Refresh();
            //to avoid scrollbar error
            ResetViewSize();
        }
Exemplo n.º 2
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(); }
        }
        public override IMoBiCommand AddExisting(TParent parent, IBuildingBlock buildingBlockWithFormulaCache)
        {
            string filename = InteractionTask.AskForFileToOpen(AppConstants.Dialog.Load(_editTask.ObjectName), Constants.Filter.PKML_FILE_FILTER, Constants.DirectoryKey.MODEL_PART);

            if (filename.IsNullOrEmpty())
            {
                return(new MoBiEmptyCommand());
            }

            var sourceSpatialStructure = InteractionTask.LoadItems <IMoBiSpatialStructure>(filename).FirstOrDefault();

            if (sourceSpatialStructure == null)
            {
                return(new MoBiEmptyCommand());
            }

            var allAvailableContainersToImport = sourceSpatialStructure.TopContainers
                                                 .SelectMany(x => x.GetAllContainersAndSelf <IContainer>(cont => !cont.IsAnImplementationOf <IParameter>()));

            var allImportedContainers    = selectContainersToImport(allAvailableContainersToImport).ToList();
            var allImportedNeighborhoods = getConnectingNeighborhoods(allImportedContainers, sourceSpatialStructure);

            allImportedContainers.Each(registerLoadedIn);
            allImportedNeighborhoods.Each(registerLoadedIn);

            var targetSpatialStructure = GetSpatialStructure();

            var command = AddItemsToProject(allImportedContainers, parent, buildingBlockWithFormulaCache);

            if (command.IsEmpty())
            {
                return(new MoBiEmptyCommand());
            }


            var addNeighborhoodsCommand = addNeighborhoodsToProject(allImportedNeighborhoods, targetSpatialStructure);

            if (addNeighborhoodsCommand.IsEmpty())
            {
                return(command);
            }

            var macroCommand = new MoBiMacroCommand()
            {
                CommandType = command.CommandType, ObjectType = command.ObjectType, Comment = command.Comment, Description = command.Description, ExtendedDescription = command.ExtendedDescription
            };

            macroCommand.Add(command);
            macroCommand.Add(addNeighborhoodsCommand);

            if (sourceSpatialStructure.DiagramModel == null || targetSpatialStructure.DiagramModel == null)
            {
                return(macroCommand);
            }
            var lcs = new LayoutCopyService();

            foreach (var container in allImportedContainers)
            {
                var sourceContainer = sourceSpatialStructure.DiagramModel.GetNode <IContainerNode>(container.Id);
                var targetContainer = targetSpatialStructure.DiagramModel.GetNode <IContainerNode>(container.Id);
                try
                {
                    targetSpatialStructure.DiagramModel.BeginUpdate();
                    lcs.Copy(sourceContainer, targetContainer);
                }
                finally
                {
                    targetSpatialStructure.DiagramModel.EndUpdate();
                }
            }
            if (targetSpatialStructure.DiagramManager.IsInitialized)
            {
                targetSpatialStructure.DiagramManager.RefreshFromDiagramOptions();
            }

            return(macroCommand);
        }