Exemplo n.º 1
0
        protected virtual void UpdateReaction(IObjectBase reactionAsEntity, IBaseNode reactionNodeAsBaseNode)
        {
            var reaction     = reactionAsEntity.DowncastTo <IReaction>();
            var reactionNode = reactionNodeAsBaseNode.DowncastTo <ReactionNode>();

            reactionNode.ClearLinks();

            var newEductDistance    = new PointF(-70, 0);
            var newProductDistance  = new PointF(30, 0);
            var newModifierDistance = new PointF(-30, -30);

            foreach (var rp in reaction.Educts)
            {
                createReactionLink(ReactionLinkType.Educt, reactionNode, moleculeNodeFor(rp.Partner.Id, reactionNode, newEductDistance));
            }

            foreach (var rp in reaction.Products)
            {
                createReactionLink(ReactionLinkType.Product, reactionNode, moleculeNodeFor(rp.Partner.Id, reactionNode, newProductDistance));
            }

            foreach (var modifierName in reaction.ModifierNames)
            {
                // modifier are in the same container as reaction (and not in subcontainers)
                var modifier = getModifierNode(reaction, modifierName);
                if (modifier != null)
                {
                    createReactionLink(ReactionLinkType.Modifier, reactionNode, moleculeNodeFor(modifier.Id, reactionNode, newModifierDistance));
                }
            }
        }
Exemplo n.º 2
0
        public bool CheckUsagesFor(string newName, string oldName, IObjectBase renamedObject, ICommandCollector commandCollector)
        {
            if (renamedObject.IsAnImplementationOf <IModelCoreSimulation>())
            {
                return(changeUsagesInSumulation(newName, renamedObject.DowncastTo <IModelCoreSimulation>(), commandCollector));
            }

            return(checkUsagesInBuildingBlocks(newName, renamedObject, commandCollector, oldName));
        }
        protected override bool MustHandleNew(IObjectBase obj)
        {
            if (obj == null || PkModel == null)
            {
                return(false);
            }

            return(obj.IsAnImplementationOf <IReactionBuilder>() && PkModel.Contains(obj.DowncastTo <IReactionBuilder>()));
        }
Exemplo n.º 4
0
        protected override void ExecuteWith(IMoBiContext context)
        {
            base.ExecuteWith(context);
            OldName          = _objectBase.Name;
            _objectBase.Name = _newName;
            if (_objectBase.IsAnImplementationOf <IBuildingBlock>())
            {
                var renameBuildingBlockTask = context.Resolve <IRenameBuildingBlockTask>();
                renameBuildingBlockTask.RenameInSimulationUsingTemplateBuildingBlock(_objectBase.DowncastTo <IBuildingBlock>());
            }

            context.PublishEvent(new RenamedEvent(_objectBase));
        }
Exemplo n.º 5
0
        protected virtual bool DecoupleObjectBase(IObjectBase objectBase, bool recursive)
        {
            if (objectBase.GetType() == typeof(Container))
            {
                var container = objectBase.DowncastTo <IContainer>();
                if (recursive)
                {
                    foreach (var child in container.Children)
                    {
                        DecoupleObjectBase(child, recursive: true);
                    }
                }
                return(Decouple <IContainer, IContainerNode>(container));
            }

            if (objectBase.IsAnImplementationOf <INeighborhoodBase>())
            {
                return(Decouple <INeighborhoodBase, TNeighborhoodNode>(objectBase.DowncastTo <INeighborhoodBase>()));
            }

            return(false); // not removed by this implementation
        }
Exemplo n.º 6
0
        /// <summary>
        ///    Creates the path from entity.
        /// </summary>
        /// <param name="objectBase">The object base that should be referenced</param>
        /// <param name="shouldCreateAbsolutePaths">if set to <c>true</c> should create absolute paths otherwise relative paths are created.</param>
        /// <param name="refObject">The object from which the path is created.</param>
        /// <param name="editedObject"></param>
        /// <returns> the dto Object for the reference</returns>
        public virtual ReferenceDTO CreatePathsFromEntity(IObjectBase objectBase, bool shouldCreateAbsolutePaths, IEntity refObject, IUsingFormula editedObject)
        {
            var dto = new ReferenceDTO();

            if (!objectBase.IsAnImplementationOf <IFormulaUsable>())
            {
                return(null);
            }
            var formulaUseable = objectBase.DowncastTo <IFormulaUsable>();

            if (isGlobal(objectBase))
            {
                // This a global parameters that we always use as absolute paths
                dto.Path = CreateAlwaysAbsolutePaths(objectBase, formulaUseable);
            }
            else
            {
                // local reaction and molecule properties are always referenced local.
                if (formulaUseable.IsAtReaction() || formulaUseable.IsAtMolecule())
                {
                    shouldCreateAbsolutePaths = false;
                }
                dto.Path = shouldCreateAbsolutePaths
               ? CreateAbsolutePath(formulaUseable)
               : CreateRelativePath(formulaUseable, refObject, editedObject);
            }
            var parameter = formulaUseable as IParameter;

            if (parameter == null)
            {
                return(dto);
            }

            dto.BuildMode = parameter.BuildMode;
            updateReferenceForTransportMoleculeContainer(dto, parameter, shouldCreateAbsolutePaths);
            return(dto);
        }
        // signature is necessary for use as argument in RegisterUpdateMethod
        public void UpdateReactionBuilder(IObjectBase reactionAsObjectBase, IBaseNode reactionNodeAsBaseNode)
        {
            var reactionBuilder = reactionAsObjectBase.DowncastTo <IReactionBuilder>();
            var reactionNode    = reactionNodeAsBaseNode.DowncastTo <ReactionNode>();

            reactionNode.ClearLinks();

            foreach (var rpb in reactionBuilder.Educts)
            {
                createReactionLink(ReactionLinkType.Educt, reactionNode, getMoleculeNode(rpb.MoleculeName, reactionNode.Location));
            }

            foreach (var rpb in reactionBuilder.Products)
            {
                createReactionLink(ReactionLinkType.Product, reactionNode, getMoleculeNode(rpb.MoleculeName, reactionNode.Location));
            }

            foreach (var modifierName in reactionBuilder.ModifierNames)
            {
                createReactionLink(ReactionLinkType.Modifier, reactionNode, getMoleculeNode(modifierName, reactionNode.Location));
            }

            reactionNode.SetColorFrom(DiagramOptions.DiagramColors);
        }
Exemplo n.º 8
0
        private void updateObserver(IObjectBase observerAsEntity, IBaseNode observerNodeAsBaseNode)
        {
            var observer     = observerAsEntity.DowncastTo <IObserver>();
            var observerNode = observerNodeAsBaseNode.DowncastTo <ObserverNode>();

            observerNode.ClearLinks();

            foreach (var oRef in observer.Formula.ObjectReferences)
            {
                var refId        = oRef.Object.Id;
                var refParentId  = oRef.Object.ParentContainer.Id;
                var moleculeNode = DiagramModel.GetNode <MoleculeNode>(refId);
                // if object reference is not molecule amount itself, it could be a child of molecule amount, e.g. a concentration
                if (moleculeNode == null)
                {
                    moleculeNode = DiagramModel.GetNode <MoleculeNode>(refParentId);
                }

                if (moleculeNode != null)
                {
                    createObserverLink(observerNode, moleculeNode);
                }
            }
        }