Exemple #1
0
        private void BuildNextStep(bool setCurrentItem)
        {
            if (!InitSystem())
            {
                return;
            }

            // Iterate.
            LSystems.IRewriteRules rules = definition as LSystems.IRewriteRules;
            if (rules != null)
            {
                LSystems.System nextStep = system.Clone();

                switch (rules.RewriteDirection)
                {
                case LSystems.RewriteDirection.LeftToRight:
                    nextStep.RewriteLeftToRight();
                    break;

                case LSystems.RewriteDirection.RightToLeft:
                    nextStep.RewriteRightToLeft();
                    break;

                default:
                    throw new InvalidOperationException("Unknown RewriteDirection");
                }

                nextStep.Decomposite();

                this.steps.Insert(0, new Step()
                {
                    System = nextStep, Name = string.Format("Step {0}", steps.Count)
                });

                system = nextStep;
            }

            if (setCurrentItem)
            {
                if (this.steps.Count > 0)
                {
                    CollectionViewSource.GetDefaultView(this.steps).MoveCurrentTo(this.steps[0]);
                }

                NotifyPropertyChanged("System");
            }
        }
Exemple #2
0
 public void Build()
 {
     if (system == null)
     {
         if (InitSystem())
         {
             LSystems.IRewriteRules rules = definition as LSystems.IRewriteRules;
             if (rules != null)
             {
                 for (int i = 0; i < rules.Depth; ++i)
                 {
                     BuildNextStep(i == rules.Depth - 1);
                 }
             }
         }
     }
 }
Exemple #3
0
        private bool InitSystem()
        {
            if (system != null)
            {
                return(true);
            }

            SystemError = null;

            if (!BuildDefinition())
            {
                return(false);
            }

            try
            {
                system = LSystems.SystemBuilder.BuildSystem(definition);
            }
            catch (InvalidOperationException e)
            {
                // Failure.
                SystemError = e.Message;
                return(false);
            }

            LSystems.IRewriteRules rules = definition as LSystems.IRewriteRules;
            if (rules != null)
            {
                system.String = rules.Axiom;
            }

            steps.Clear();
            this.steps.Insert(0, new Step()
            {
                System = system, Name = "Axiom"
            });

            return(true);
        }