public IMoBiCommand Add(IContainer firstNeighbor, IContainer secondNeighbor)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.AddCommand,
                ObjectType  = ObjectName,
            };

            var spatialStructure = getSpatialStructure();

            var neighborhoodBuilder = CreateNewEntity(spatialStructure.NeighborhoodsContainer);

            neighborhoodBuilder.FirstNeighbor  = firstNeighbor;
            neighborhoodBuilder.SecondNeighbor = secondNeighbor;

            if (_editTask.EditEntityModal(neighborhoodBuilder, spatialStructure, macroCommand, spatialStructure))
            {
                macroCommand.AddCommand(GetAddCommand(neighborhoodBuilder, spatialStructure.NeighborhoodsContainer, spatialStructure).Run(Context));
                macroCommand.Description = AppConstants.Commands.AddToDescription(ObjectName, neighborhoodBuilder.Name,
                                                                                  spatialStructure.Name);
                _editTask.Edit(neighborhoodBuilder);
                return(macroCommand);
            }
            return(new MoBiEmptyCommand());
        }
Ejemplo n.º 2
0
        public void CreateNewFromSelection()
        {
            var allMolecules = Context.CurrentProject.MoleculeBlockCollection;
            NewMoleculeBuildingBlockDescription newMoleculeBuildingBlockDescription = null;

            using (var selectMoleculesPresenter = ApplicationController.Start <ISelectMoleculesForBuildingBlockPresenter>())
            {
                selectMoleculesPresenter.MoleculeBuildinBlocks = allMolecules;
                if (selectMoleculesPresenter.AskForCreation())
                {
                    newMoleculeBuildingBlockDescription = selectMoleculesPresenter.Selected;
                }
            }
            if (newMoleculeBuildingBlockDescription == null)
            {
                return;
            }

            var moleculeBuildingBlock         = Context.Create <IMoleculeBuildingBlock>().WithName(newMoleculeBuildingBlockDescription.Name);
            var cloneManagerForBuildingBlocks = new CloneManagerForBuildingBlock(Context.ObjectBaseFactory, new DataRepositoryTask())
            {
                FormulaCache = moleculeBuildingBlock.FormulaCache
            };

            newMoleculeBuildingBlockDescription.Molecules.Each(x => moleculeBuildingBlock.Add(cloneManagerForBuildingBlocks.Clone(x)));
            var command = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.AddCommand,
                ObjectType  = ObjectName,
                Description = AppConstants.Commands.CreateFromSelectionDescription(moleculeBuildingBlock.Name, moleculeBuildingBlock.Select(x => x.Name).ToList())
            };

            command.AddCommand(GetAddCommand(moleculeBuildingBlock, null, null).Run(Context));
            AddCommand(command);
        }
Ejemplo n.º 3
0
        public void UpdateDimension(ParameterStartValueDTO startValueObject, IDimension newDimension)
        {
            var macroCommand = new MoBiMacroCommand();
            var startValue   = StartValueFrom(startValueObject);

            macroCommand.CommandType = AppConstants.Commands.EditCommand;
            macroCommand.Description = AppConstants.Commands.UpdateDimensionsAndUnits;
            macroCommand.ObjectType  = new ObjectTypeResolver().TypeFor <ParameterStartValue>();

            var value = startValue.ConvertToDisplayUnit(startValue.StartValue);

            macroCommand.AddCommand(_parameterStartValuesTask.UpdateStartValueDimension(_buildingBlock, startValue, newDimension));
            macroCommand.AddCommand(_parameterStartValuesTask.SetStartDisplayValueWithUnit(startValue, value, _displayUnitRetriever.PreferredUnitFor(startValue), _buildingBlock));

            AddCommand(macroCommand);
        }
Ejemplo n.º 4
0
        public IMoBiCommand Rename(IObjectBase objectBase, IEnumerable <string> allreadyNames, IBuildingBlock buildingBlock)
        {
            var unallowedNames = new List <string>(allreadyNames);

            unallowedNames.AddRange(AppConstants.UnallowedNames);
            var    objectName = _objectTypeResolver.TypeFor(objectBase);
            string newName    = _dialogCreator.AskForInput(AppConstants.Dialog.AskForNewName(objectBase.Name), AppConstants.Captions.NewName, objectBase.Name, unallowedNames);

            if (string.IsNullOrEmpty(newName))
            {
                return(new MoBiEmptyCommand());
            }


            var commandCollector = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.RenameCommand,
                ObjectType  = objectName,
                Description = AppConstants.Commands.RenameDescription(objectBase, newName)
            };

            if (CheckUsagesFor(newName, objectBase.Name, objectBase, commandCollector))
            {
                commandCollector.AddCommand(new RenameObjectBaseCommand(objectBase, newName, buildingBlock)
                {
                    ObjectType = objectName
                });
            }

            commandCollector.Run(_context);
            return(commandCollector);
        }
Ejemplo n.º 5
0
        public IMoBiCommand RemoveMultipleSimulations(IReadOnlyList <IMoBiSimulation> simulations)
        {
            var currentProject = _interactionTaskContext.Context.CurrentProject;

            if (DialogCreator.MessageBoxYesNo(AppConstants.Dialog.RemoveSimulationsFromProject(currentProject.Name)) != ViewResult.Yes)
            {
                return(new MoBiEmptyCommand());
            }

            simulations.Each(simulation => _simulationReferenceUpdater.RemoveSimulationFromParameterIdentificationsAndSensitivityAnalyses(simulation));

            var macroCommand = new MoBiMacroCommand
            {
                Description = AppConstants.Commands.RemoveSimulationsFromProject,
                ObjectType  = ObjectTypes.Simulation,
                CommandType = AppConstants.Commands.DeleteCommand
            };

            simulations.Each(simulation =>
            {
                macroCommand.AddCommand(GetRemoveCommand(simulation, currentProject, null).Run(Context));
                Context.PublishEvent(new RemovedEvent(simulation, currentProject));
            });

            return(macroCommand);
        }
        public void ChangeTranportName(TransporterMoleculeContainer transporterMoleculeContainer, IBuildingBlock buildingBlock)
        {
            var unallowedNames = new List <string>(AppConstants.UnallowedNames);

            unallowedNames.AddRange(GetForbiddenNamesWithoutSelf(transporterMoleculeContainer, transporterMoleculeContainer.ParentContainer));
            var oldTransportName = transporterMoleculeContainer.TransportName;
            var newName          = _dialogCreator.AskForInput(AppConstants.Dialog.AskForNewName(oldTransportName), AppConstants.Captions.NewName, oldTransportName, unallowedNames);

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

            var commandCollector = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.RenameCommand,
                ObjectType  = ObjectName,
                Description = AppConstants.Commands.RenameDescription(transporterMoleculeContainer, newName)
            };

            if (_objectBaseTask.CheckUsagesFor(newName, transporterMoleculeContainer.TransportName, transporterMoleculeContainer, commandCollector))
            {
                commandCollector.AddCommand(new EditObjectBasePropertyInBuildingBlockCommand(transporterMoleculeContainer.PropertyName(x => x.TransportName), newName, oldTransportName, transporterMoleculeContainer, buildingBlock)
                {
                    ObjectType = ObjectName
                });
            }
            commandCollector.Run(_context);
            _context.AddToHistory(commandCollector);
        }
Ejemplo n.º 7
0
        private void addObservedDataToProject(IEnumerable <DataRepository> allObservedData, MoBiMacroCommand loadCommand)
        {
            if (allObservedData == null)
            {
                return;
            }

            var project = _context.CurrentProject;

            allObservedData.Where(observedData => !project.AllObservedData.ExistsById(observedData.Id))
            .Each(x => loadCommand.AddCommand(new AddObservedDataToProjectCommand(x)));
        }
Ejemplo n.º 8
0
        public void AddConditionFormula()
        {
            string newName = _dialogCreator.AskForInput(AppConstants.Captions.NewName, AppConstants.Captions.EnterNewFormulaName, string.Empty, AllFormulaNames());

            checkFormulaName(newName);
            if (string.IsNullOrEmpty(newName))
            {
                return;
            }

            var newFormula        = _context.Create <ExplicitFormula>().WithName(newName);
            var newFormulaCommand = new MoBiMacroCommand
            {
                Description = AppConstants.Commands.EditDescription(ObjectTypes.EventBuilder, _formulaPropertyName, string.Empty, newName, _eventBuilder.Name),
                CommandType = AppConstants.Commands.EditCommand,
                ObjectType  = ObjectTypes.EventBuilder
            };

            newFormulaCommand.AddCommand(new AddFormulaToFormulaCacheCommand(BuildingBlock, newFormula).Run(_context));
            newFormulaCommand.AddCommand(new EditObjectBasePropertyInBuildingBlockCommand(_formulaPropertyName, newFormula, _eventBuilder.Formula, _eventBuilder, BuildingBlock).Run(_context));
            AddCommand(newFormulaCommand);
            Edit(_eventBuilder);
        }
Ejemplo n.º 9
0
        private static MoBiMacroCommand deleteAllResultsFromSimulationCommand(IMoBiSimulation simulation)
        {
            var macoCommand = new MoBiMacroCommand
            {
                CommandType = Command.CommandTypeDelete,
                ObjectType  = ObjectTypes.ObservedData,
                Description = AppConstants.Commands.DeleteResultsFromSimulation(simulation.Name),
            };

            if (simulation.Results != null)
            {
                macoCommand.AddCommand(new ClearResultsCommand(simulation));
            }

            simulation.HistoricResults.Each(x => macoCommand.Add(new RemoveHistoricResultFromSimulationCommand(simulation, x)));
            return(macoCommand);
        }
        private bool addNeighborhood(INeighborhoodBuilder neighborhoodBuilder, MoBiMacroCommand command, IMoBiSpatialStructure spatialStructure)
        {
            var forbiddenNames = spatialStructure.NeighborhoodsContainer.Children.Select(x => x.Name).Union(AppConstants.UnallowedNames).ToList();

            if (forbiddenNames.Contains(neighborhoodBuilder.Name))
            {
                string newName = _dialogCreator.AskForInput(AppConstants.Dialog.AskForChangedName(neighborhoodBuilder.Name, ObjectTypes.NeighborhoodBuilder), AppConstants.Captions.NewName, neighborhoodBuilder.Name, forbiddenNames);

                if (string.IsNullOrEmpty(newName))
                {
                    return(false);
                }
                neighborhoodBuilder.Name = newName;
            }
            command.AddCommand(new AddContainerToSpatialStructureCommand(spatialStructure.NeighborhoodsContainer, neighborhoodBuilder, spatialStructure).Run(Context));
            return(true);
        }
Ejemplo n.º 11
0
        public void DeleteAllResultsFromAllSimulation()
        {
            var viewResult = _dialogCreator.MessageBoxYesNo(AppConstants.Dialog.RemoveAllResultsFromProject());

            if (viewResult == ViewResult.No)
            {
                return;
            }

            var simulations = _context.CurrentProject.Simulations;
            var macoCommand = new MoBiMacroCommand
            {
                CommandType = Command.CommandTypeDelete,
                ObjectType  = ObjectTypes.ObservedData,
                Description = AppConstants.Commands.DeleteAllResultsFromAllSimulations,
            };

            simulations.Each(s => macoCommand.AddCommand(deleteAllResultsFromSimulationCommand(s)));
            _context.AddToHistory(macoCommand.Run(_context));
        }
Ejemplo n.º 12
0
        protected IMoBiCommand AddFormulaToFormulaCacheAndSetOnStartValue <TFormula>(TBuildingBlock startValuesBuildingBlock, TStartValue startValue, IParameter referenceParameter)
            where TFormula : IFormula
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.AddCommand,
                Description = AppConstants.Commands.AddFormulaToBuildingBlock,
                ObjectType  = _interactionTaskContext.GetTypeFor <TFormula>()
            };

            var newFormula = _moBiFormulaTask.CreateNewFormula <TFormula>(startValue.Dimension);

            macroCommand.AddCommand(new AddFormulaToFormulaCacheCommand(startValuesBuildingBlock, newFormula).Run(Context));

            if (!_moBiFormulaTask.EditNewFormula(newFormula, macroCommand, startValuesBuildingBlock, referenceParameter))
            {
                return(CancelCommand(macroCommand));
            }

            macroCommand.Add(SetFormula(startValuesBuildingBlock, startValue, newFormula));
            return(macroCommand);
        }
        public IMoBiCommand Rename(IObjectBase objectBase, IEnumerable <string> alreadyUsedNames, IBuildingBlock buildingBlock)
        {
            var unallowedNames = new List <string>(alreadyUsedNames);

            unallowedNames.AddRange(AppConstants.UnallowedNames);
            var objectName = _objectTypeResolver.TypeFor(objectBase);

            string newName;

            using (var renameObjectPresenter = _applicationController.Start <IRenameObjectPresenter>())
            {
                newName = renameObjectPresenter.NewNameFrom(objectBase, unallowedNames);
            }


            if (string.IsNullOrEmpty(newName))
            {
                return(new MoBiEmptyCommand());
            }


            var commandCollector = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.RenameCommand,
                ObjectType  = objectName,
                Description = AppConstants.Commands.RenameDescription(objectBase, newName)
            };

            if (CheckUsagesFor(newName, objectBase.Name, objectBase, commandCollector))
            {
                commandCollector.AddCommand(new RenameObjectBaseCommand(objectBase, newName, buildingBlock)
                {
                    ObjectType = objectName
                });
            }

            commandCollector.Run(_context);
            return(commandCollector);
        }
Ejemplo n.º 14
0
        private void addSimulationToProject(IMoBiSimulation simulation, MoBiMacroCommand loadCommand, bool shouldCloneSimulation)
        {
            var moBiSimulation = simulation;

            simulation.MoBiBuildConfiguration.AllBuildingBlockInfos().Each(checkTemplateBuildingBlock);
            var project = _context.CurrentProject;

            if (shouldCloneSimulation)
            {
                moBiSimulation = cloneSimulation(moBiSimulation);
            }

            addBuildConfigurationToProject(project, moBiSimulation.MoBiBuildConfiguration, loadCommand);

            moBiSimulation.Results = simulation.Results;
            if (!_nameCorrector.CorrectName(project.Simulations, moBiSimulation))
            {
                return;
            }

            moBiSimulation.HasChanged = true;
            loadCommand.AddCommand(new AddSimulationCommand(moBiSimulation));
        }