[592] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[583] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Xml;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Operators.Programmable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Communication.Data {
|
---|
| 31 | public class StateTransition : ItemBase {
|
---|
| 32 | private ProtocolState sourceState;
|
---|
| 33 | public ProtocolState SourceState {
|
---|
| 34 | get { return sourceState; }
|
---|
| 35 | set {
|
---|
| 36 | sourceState = value;
|
---|
| 37 | OnChanged();
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | private ProtocolState targetState;
|
---|
| 41 | public ProtocolState TargetState {
|
---|
| 42 | get { return targetState; }
|
---|
| 43 | set {
|
---|
| 44 | targetState = value;
|
---|
| 45 | OnChanged();
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | private ProgrammableOperator transitionCondition;
|
---|
| 49 | public ProgrammableOperator TransitionCondition {
|
---|
| 50 | get { return transitionCondition; }
|
---|
| 51 | set {
|
---|
| 52 | transitionCondition = value;
|
---|
| 53 | OnChanged();
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public StateTransition()
|
---|
| 58 | : base() {
|
---|
| 59 | sourceState = null;
|
---|
| 60 | targetState = null;
|
---|
| 61 | transitionCondition = new ProgrammableOperator();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | public override IView CreateView() {
|
---|
| 65 | return new StateTransitionView(this);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 69 | StateTransition clone = new StateTransition();
|
---|
| 70 | clonedObjects.Add(Guid, clone);
|
---|
[883] | 71 | clone.sourceState = (ProtocolState)Auxiliary.Clone(SourceState, clonedObjects);
|
---|
| 72 | clone.targetState = (ProtocolState)Auxiliary.Clone(TargetState, clonedObjects);
|
---|
[583] | 73 | clone.TransitionCondition = (ProgrammableOperator)Auxiliary.Clone(TransitionCondition, clonedObjects);
|
---|
| 74 | return clone;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | #region persistence
|
---|
| 78 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
| 79 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
| 80 | XmlNode sourceStateNode = PersistenceManager.Persist("SourceState", SourceState, document, persistedObjects);
|
---|
| 81 | node.AppendChild(sourceStateNode);
|
---|
| 82 | XmlNode targetStateNode = PersistenceManager.Persist("TargetState", TargetState, document, persistedObjects);
|
---|
| 83 | node.AppendChild(targetStateNode);
|
---|
| 84 | XmlNode transitionConditionNode = PersistenceManager.Persist("TransitionCondition", TransitionCondition, document, persistedObjects);
|
---|
| 85 | node.AppendChild(transitionConditionNode);
|
---|
| 86 | return node;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
| 90 | base.Populate(node, restoredObjects);
|
---|
| 91 | sourceState = (ProtocolState)PersistenceManager.Restore(node.SelectSingleNode("SourceState"), restoredObjects);
|
---|
| 92 | targetState = (ProtocolState)PersistenceManager.Restore(node.SelectSingleNode("TargetState"), restoredObjects);
|
---|
| 93 | transitionCondition = (ProgrammableOperator)PersistenceManager.Restore(node.SelectSingleNode("TransitionCondition"), restoredObjects);
|
---|
| 94 | }
|
---|
| 95 | #endregion persistence
|
---|
| 96 | }
|
---|
| 97 | }
|
---|