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());
        }
        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);
        }
コード例 #3
0
        public ICommand UpdateDefaultStateAndValueOriginFor(IQuantity quantity, IBuildingBlock buildingBlock)
        {
            var macroCommand = new MoBiMacroCommand();

            addUpdateDefaultStateAndValueOriginCommand(macroCommand, quantity, buildingBlock, setParameterDefaultStateInBuildingBlock, UpdateQuantityValueOriginInBuildingBlock);
            return(macroCommand);
        }
コード例 #4
0
ファイル: ObjectBaseTask.cs プロジェクト: onwhenrdy/MoBi
        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);
        }
コード例 #5
0
ファイル: SimulationUpdateTask.cs プロジェクト: Yuri05/MoBi
        private ICommand <IMoBiContext> updateSimulation(
            IMoBiSimulation simulationToUpdate,
            IMoBiBuildConfiguration buildConfigurationReferencingTemplates,
            IMoBiCommand configurationCommands,
            IBuildingBlock templateBuildingBlock       = null,
            PathCache <IQuantity> fixedValueQuantities = null)
        {
            //create model using referencing templates
            var model = createModelAndValidate(simulationToUpdate.Model.Name, buildConfigurationReferencingTemplates);

            var simulationBuildConfiguration = createBuildConfigurationToUseInSimulation(buildConfigurationReferencingTemplates);

            var updateSimulationCommand = templateBuildingBlock == null
            ? // is null when we a simulation is being configured. Otherwise this is the template building block to user
                                          new UpdateSimulationCommand(simulationToUpdate, model, simulationBuildConfiguration)
            : new UpdateSimulationCommand(simulationToUpdate, model, simulationBuildConfiguration, templateBuildingBlock);

            updateSimulationCommand.Run(_context);

            synchronizeFixedParameterValues(simulationToUpdate, templateBuildingBlock, fixedValueQuantities);

            var macro = new MoBiMacroCommand
            {
                Description = updateSimulationCommand.Description,
                CommandType = updateSimulationCommand.CommandType,
                ObjectType  = updateSimulationCommand.ObjectType
            };

            macro.Add(configurationCommands);
            macro.Add(updateSimulationCommand);
            return(macro);
        }
コード例 #6
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);
        }
コード例 #7
0
        private IOSPSuiteCommand withUpdatedDefaultStateAndValueOrigin <T>(
            IOSPSuiteCommand executedCommand,
            IQuantity quantity,
            T buildingBlockOrSimulation,
            Func <IParameter, bool, T, ICommand> setParameterDefaultStateFunc,
            Func <IParameter, ValueOrigin, T, ICommand> setParameterValueOriginFunc
            )
        {
            if (executedCommand.IsEmpty() || executedCommand.IsEmptyMacro())
            {
                return(executedCommand);
            }

            var updateCommand = new MoBiMacroCommand();

            addUpdateDefaultStateAndValueOriginCommand(updateCommand, quantity, buildingBlockOrSimulation, setParameterDefaultStateFunc, setParameterValueOriginFunc);

            if (updateCommand.IsEmtpy)
            {
                return(executedCommand);
            }

            var macroCommand = new MoBiMacroCommand().WithHistoryEntriesFrom(executedCommand);

            macroCommand.Add(executedCommand);
            macroCommand.AddRange(updateCommand.All());
            return(macroCommand);
        }
コード例 #8
0
        public override IMoBiCommand AddNew(IMoBiProject project, IBuildingBlock buildingBlockToAddTo)
        {
            if (!project.MoleculeBlockCollection.Any() || !project.SpatialStructureCollection.Any())
            {
                throw new MoBiException(AppConstants.Exceptions.UnableToCreateStartValues);
            }

            TBuildingBlock newEntity;

            using (var createPresenter = ApplicationController.Start <ICreateStartValuesPresenter <TBuildingBlock> >())
            {
                newEntity = createPresenter.Create();
            }

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

            var macroCommand = new MoBiMacroCommand
            {
                ObjectType  = ObjectName,
                CommandType = AppConstants.Commands.AddCommand
            };

            macroCommand.Add(GetAddCommand(newEntity, project, buildingBlockToAddTo).Run(Context));

            //Icon may depend on name.
            newEntity.Icon           = InteractionTask.IconFor(newEntity);
            macroCommand.Description = AppConstants.Commands.AddToProjectDescription(ObjectName, newEntity.Name);
            _editTask.EditBuildingBlock(newEntity);
            return(macroCommand);
        }
コード例 #9
0
ファイル: MoBiFormulaTask.cs プロジェクト: onwhenrdy/MoBi
        private IMoBiCommand withUpdatedDefaultStateAndValueOrigin(IMoBiCommand executedCommand, IFormula formula, IBuildingBlock buildingBlock)
        {
            if (executedCommand.IsEmpty())
            {
                return(executedCommand);
            }

            var parametersUsingFormula = _parameterInBuildingBlockRetriever.AllFrom(buildingBlock, p => Equals(p.Formula, formula));

            if (!parametersUsingFormula.Any())
            {
                return(executedCommand);
            }

            var updateValueOriginCommand = new MoBiMacroCommand();

            parametersUsingFormula.Each(p => updateValueOriginCommand.Add(_quantityTask.UpdateDefaultStateAndValueOriginFor(p, buildingBlock)));

            //we have depending parameters but they all have default state and value origin set;
            if (updateValueOriginCommand.IsEmtpy)
            {
                return(executedCommand);
            }

            var macroCommand = new MoBiMacroCommand().WithHistoryEntriesFrom(executedCommand);

            macroCommand.Add(executedCommand);
            macroCommand.AddRange(updateValueOriginCommand.All());
            return(macroCommand);
        }
コード例 #10
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);
        }
コード例 #11
0
        public IMoBiCommand ImportModelFromSBML(string filename, IMoBiProject project)
        {
            var command = new MoBiMacroCommand()
            {
                CommandType = AppConstants.Commands.AddCommand,
                ObjectType  = SBMLConstants.Model,
                Comment     = AppConstants.Commands.AddToProjectDescription(SBMLConstants.Model, filename)
            };
            var model = GetModel(filename);

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

            initialiseDimensionFactory(project);
            project.Name = getProjectName(model);

            reportConstraints(project, model);

            foreach (var importer in _importerRepository.AllFor(model))
            {
                importer.DoImport(model, project, SBMLInformation, command);
            }
            ShowNotificationsMessages();
            return(command);
        }
コード例 #12
0
        public void Visit(IMoBiSimulation simulation)
        {
            var command = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.AddCommand,
                ObjectType  = ObjectTypes.Simulation,
                Description = AppConstants.Commands.AddToProjectDescription(ObjectTypes.Simulation, simulation.Name)
            };

            command.Add(_simulationLoader.AddSimulationToProject(simulation));
            addCommand(command);
        }
        public virtual IMoBiCommand CreateCommitToBuildingBlockCommand(IMoBiSimulation simulation, IBuildingBlock templateBuildingBlock)
        {
            var macroCommand = new MoBiMacroCommand();

            macroCommand.Add(CreateCommitCommand(simulation, templateBuildingBlock));
            //hide this command that is only required for separation of concerns
            macroCommand.Add(new ResetFixedConstantParametersToDefaultInSimulationCommand <T>(simulation, _buildingBlockRetriever(simulation.BuildConfiguration))
            {
                Visible = false
            });
            return(macroCommand);
        }
コード例 #14
0
        private MoBiMacroCommand getMoveCommands(IMoBiReactionBuildingBlock sourceBuildingBlock, IMoBiReactionBuildingBlock targetBuildingBlock, IReactionBuilder builder, string builderOriginalName)
        {
            var macroCommand = new MoBiMacroCommand();

            macroCommand.Add(getMoveCommand(sourceBuildingBlock, targetBuildingBlock, builder.Name, builderOriginalName));


            builder.Educts.Each(educt => macroCommand.Add(movePartnersCommand(sourceBuildingBlock, targetBuildingBlock, educt)));
            builder.Products.Each(product => macroCommand.Add(movePartnersCommand(sourceBuildingBlock, targetBuildingBlock, product)));
            builder.ModifierNames.Each(modifier => macroCommand.Add(movePartnerNamed(sourceBuildingBlock, targetBuildingBlock, modifier)));
            return(macroCommand);
        }
        public override IMoBiCommand CreateCommitToBuildingBlockCommand(IMoBiSimulation simulation, IBuildingBlock templateBuildingBlock)
        {
            var macroCommand = new MoBiMacroCommand();

            macroCommand.Add(CreateCommitCommand(simulation, templateBuildingBlock));
            //hide this command that is only required for separation of concerns
            macroCommand.Add(new ResetMoleculeValuesToDefaultFromStartValuesInSimulationCommand(simulation)
            {
                Visible = false
            });
            return(macroCommand);
        }
コード例 #16
0
        public ICommand <IMoBiContext> AddNewFormulaAtMoleculeStartValueBuildingBlock <T>(IMoleculeStartValuesBuildingBlock buildingBlock, IMoleculeStartValue moleculeStartValue)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.EditCommand,
                ObjectType  = _interactionTaskContext.GetTypeFor(moleculeStartValue),
                Description = AppConstants.Commands.SetStartValueAndFormula
            };

            macroCommand.Add(AddFormulaToFormulaCacheAndSetOnStartValue <ExplicitFormula>(buildingBlock, moleculeStartValue, referenceParameter: null));

            return(macroCommand);
        }
コード例 #17
0
        public IMoBiCommand SetIsPresent(IMoleculeStartValuesBuildingBlock moleculeStartValues, IEnumerable <IMoleculeStartValue> startValues, bool isPresent)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.EditCommand,
                Description = AppConstants.Commands.SettingIsPresentCommandDescription(isPresent),
                ObjectType  = ObjectTypes.MoleculeStartValue,
            };

            startValues.Where(x => x.IsPresent != isPresent).Each(msv =>
                                                                  macroCommand.Add(updateIsPresent(moleculeStartValues, msv, isPresent)));

            return(macroCommand);
        }
コード例 #18
0
        public IMoBiCommand SetNegativeValuesAllowed(IMoleculeStartValuesBuildingBlock moleculeStartValues, IEnumerable <IMoleculeStartValue> startValues, bool negativeValuesAllowed)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.EditCommand,
                Description = AppConstants.Commands.SettingNegativeValuesAllowedCommandDescription(negativeValuesAllowed),
                ObjectType  = ObjectTypes.MoleculeStartValue,
            };

            startValues.Where(x => x.NegativeValuesAllowed != negativeValuesAllowed).Each(msv =>
                                                                                          macroCommand.Add(updateNegativeValuesAllowed(moleculeStartValues, msv, negativeValuesAllowed)));

            return(macroCommand);
        }
        private IMoBiCommand addNeighborhoodsToProject(IList <INeighborhoodBuilder> neighborhoods, IMoBiSpatialStructure spatialStructure)
        {
            if (neighborhoods == null || !neighborhoods.Any())
            {
                return(new MoBiEmptyCommand());
            }
            var command = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.AddCommand,
                ObjectType  = ObjectTypes.NeighborhoodBuilder,
                Description = AppConstants.Commands.AddDependentDescription(spatialStructure, ObjectTypes.NeighborhoodBuilder, ObjectTypes.SpatialStructure)
            };

            return(neighborhoods.Any(existingItem => !addNeighborhood(existingItem, command, spatialStructure)) ? CancelCommand(command) : command);
        }
コード例 #20
0
        public ICommand <IMoBiContext> AddNewFormulaAtParameterStartValueBuildingBlock <T>(IParameterStartValuesBuildingBlock buildingBlock, IParameterStartValue parameterStartValue)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.EditCommand,
                ObjectType  = _interactionTaskContext.GetTypeFor(parameterStartValue),
                Description = AppConstants.Commands.SetStartValueAndFormula
            };

            var parameter = GetpossibleParameterFromProject(parameterStartValue.Path);

            macroCommand.Add(AddFormulaToFormulaCacheAndSetOnStartValue <ExplicitFormula>(buildingBlock, parameterStartValue, parameter));

            return(macroCommand);
        }
コード例 #21
0
        public IMoBiCommand SetValue(TBuildingBlock buildingBlock, double?valueInDisplayUnit, TStartValue startValue)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.EditCommand,
                ObjectType  = _interactionTaskContext.GetTypeFor <TStartValue>(),
                Description = AppConstants.Commands.SetStartValueAndFormula
            };

            macroCommand.Add(setValue(startValue, valueInDisplayUnit, startValue.DisplayUnit, buildingBlock));
            if (startValue.Formula != null)
            {
                macroCommand.Add(setFormula(buildingBlock, startValue, null));
            }
            return(macroCommand);
        }
コード例 #22
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);
        }
        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);
        }
コード例 #24
0
        public void AddMoleculeNode()
        {
            using (var presenter = _applicationController.Start <IMultipleStringSelectionPresenter>())
            {
                var moleculeNames = presenter.Show(AppConstants.Captions.AddReactionMolecule,
                                                   AppConstants.Dialog.GetReactionMoleculeName, getMoleculeNames(), ToolTips.AddMoleculeNameToList, canAdd: true);

                var command = new MoBiMacroCommand
                {
                    ObjectType  = ObjectTypes.Molecule,
                    CommandType = AppConstants.Commands.AddCommand,
                    Description = AppConstants.Commands.AddManyMoleculesDescription
                };
                moleculeNames.Each(nodeName => addMoleculeNode(nodeName, command));
                AddCommand(command.Run(_context));
            }
        }
コード例 #25
0
        protected override ICommand <IMoBiContext> GetInverseCommand(IMoBiContext context)
        {
            var command = new MoBiMacroCommand()
            {
                ObjectType  = ObjectType,
                CommandType = AppConstants.Commands.AddCommand,
                Description = AppConstants.Commands.AddToDescription(ObjectType, _itemToRemove.Name, _parent.Name)
            }.AsInverseFor(this);

            command.Add(new AddContainerToSpatialStructureCommand(_parent, _itemToRemove, _spatialStructure));
            foreach (var neighborhood in _removedNeighborhoods)
            {
                command.Add(new AddContainerToSpatialStructureCommand(_spatialStructure.NeighborhoodsContainer,
                                                                      neighborhood, _spatialStructure));
            }
            return(command);
        }
コード例 #26
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);
        }
コード例 #27
0
        public void RemoveResultsFromSimulations(IReadOnlyList <DataRepository> resultsToRemove)
        {
            if (_dialogCreator.MessageBoxYesNo(AppConstants.Dialog.RemoveSelectedResultsFromSimulations) != ViewResult.Yes)
            {
                return;
            }

            var macroCommand = new MoBiMacroCommand
            {
                Description = AppConstants.Commands.RemoveMultipleResultsFromSimulations,
                ObjectType  = AppConstants.MoBiObjectTypes.Data,
                CommandType = AppConstants.Commands.DeleteCommand
            };

            resultsToRemove.Each(result => { macroCommand.Add(removeResultFromSimulationCommand(result)); });

            _context.AddToHistory(macroCommand.Run(_context));
        }
コード例 #28
0
        private void addMoleculeNode(string moleculeName, MoBiMacroCommand command)
        {
            if (moleculeName.Equals(String.Empty))
            {
                return;
            }

            var moleculeNodes = reactionDiagramManager.GetMoleculeNodes(moleculeName);

            var message = AppConstants.Diagram.MoleculeNodeAlreadyExistsForMolecule(moleculeName);

            if (moleculeNodes.Any() && (_dialogCreator.MessageBoxYesNo(message) == ViewResult.No))
            {
                return;
            }

            command.Add(new AddMoleculeToReactionBuildingBlockCommand(_model, moleculeName));
        }
コード例 #29
0
        public override IMoBiCommand RefreshStartValuesFromBuildingBlocks(IMoleculeStartValuesBuildingBlock buildingBlock, IEnumerable <IMoleculeStartValue> startValuesToRefresh)
        {
            var macroCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.EditCommand,
                Description = AppConstants.Commands.RefreshStartValuesFromBuildingBlocks,
                ObjectType  = ObjectTypes.MoleculeStartValue
            };

            startValuesToRefresh.Each(startValue =>
            {
                var moleculeBuilder = _moleculeResolver.Resolve(startValue.ContainerPath, startValue.MoleculeName, SpatialStructureReferencedBy(buildingBlock), MoleculeBuildingBlockReferencedBy(buildingBlock));
                if (moleculeBuilder == null)
                {
                    return;
                }

                var originalStartValue = moleculeBuilder.GetDefaultMoleculeStartValue();
                var originalUnit       = moleculeBuilder.DisplayUnit;

                if (!ValueComparer.AreValuesEqual(Constants.DEFAULT_SCALE_DIVISOR, startValue.ScaleDivisor))
                {
                    macroCommand.Add(UpdateStartValueScaleDivisor(buildingBlock, startValue, Constants.DEFAULT_SCALE_DIVISOR, startValue.ScaleDivisor));
                }

                if (!HasEquivalentDimension(startValue, moleculeBuilder))
                {
                    macroCommand.Add(UpdateStartValueDimension(buildingBlock, startValue, moleculeBuilder.Dimension));
                }

                if (!HasEquivalentStartValue(startValue, originalStartValue))
                {
                    macroCommand.Add(SetStartValueWithUnit(startValue, originalStartValue, originalUnit, buildingBlock));
                }

                if (!HasEquivalentFormula(startValue, moleculeBuilder.DefaultStartFormula))
                {
                    macroCommand.Add(ChangeStartValueFormulaCommand(buildingBlock, startValue,
                                                                    moleculeBuilder.DefaultStartFormula.IsConstant() ? null : _cloneManagerForBuildingBlock.Clone(moleculeBuilder.DefaultStartFormula, buildingBlock.FormulaCache)));
                }
            });

            return(macroCommand);
        }
コード例 #30
0
        public IMoBiCommand MergeBuildingBlocks(IList <IBuildingBlock> buildingBlocksToMerge, IList <IBuildingBlock> targetBuildingBlocks, CancellationToken cancellationToken)
        {
            if (buildingBlocksToMerge.Count != targetBuildingBlocks.Count)
            {
                throw new ArgumentException(AppConstants.Exceptions.MergeBuildingBlocksCountError);
            }
            var mergeCommand = new MoBiMacroCommand
            {
                CommandType = AppConstants.Commands.MergeCommand,
                ObjectType  = ObjectTypes.Project
            };

            for (var i = 0; i < buildingBlocksToMerge.Count; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();
                mergeCommand.Add(MergeBuildingBlock(buildingBlocksToMerge[i], targetBuildingBlocks[i]));
            }
            return(mergeCommand);
        }