Exemplo n.º 1
0
 private void MonSimulateur_EventquandLeTempsChange(Temps temps)
 {
     if (temps == Temps.Soleil)
     {
         nombreTempsSoleil++;
     }
     nombreChangementTemps++;
 }
Exemplo n.º 2
0
        //c'est cette méthode qui va lever un événement
        //si le temps change et que quelqu'un  s'est abonné  à l'événement, on léve l'événement
        private void GererTemps(Temps temps)
        {
            if (ancienTemps.HasValue && ancienTemps.Value != temps && EventquandLeTempsChange != null)
            {
                EventquandLeTempsChange(temps);

            }
            ancienTemps = temps;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Changer l'image
        /// </summary>
        /// <param name="maintenant"></param>
        /// <param name="tailleEcran"></param>
        public override void Deplace(Temps maintenant, ref Rectangle tailleEcran)
        {
                        #if TRACER
            RenderStart(CHRONO_TYPE.DEPLACE);
                        #endif

            // Deplacement des metaballes
            for (int i = 0; i < NbMetaballes; i++)
            {
                _metaballes[i]._Px += (_metaballes[i]._Vx * maintenant._intervalle);

                if ((_metaballes[i]._Px < -_metaballes[i]._Taille) && (_metaballes[i]._Vx < 0) ||            // Trop a gauche
                    ((_metaballes[i]._Px - _metaballes[i]._Taille) > Largeur) && (_metaballes[i]._Vx > 0) || // Trop a droite
                    (_metaballes[i]._Py < -_metaballes[i]._Taille) ||                                        // Arrivee en haut
                    (_metaballes[i]._Intensite < IntensiteMin)
                    )
                {
                    // Remettre le flocon en bas
                    NouvelleMetaballe(ref _metaballes[i]);
                }
                else
                {
                    _metaballes[i]._Py += (_metaballes[i]._Vy * maintenant._intervalle);
                }

                // Variations de la vitesse horizontale + Variations sinusoidales en fonction de la profondeur
                _metaballes[i]._Vx +=                 //((float)Math.Sin( _metaballes[i]._Py / Hauteur * Math.PI*4.0 ))*0.25f
                                      +FloatRandom(-20, 20) * maintenant._intervalle;

                // De moins en moins opaque
                if (_metaballes[i]._Intensite > IntensiteMin)
                {
                    _metaballes[i]._Intensite -= (_metaballes[i]._Intensite * 0.1 * maintenant._intervalle);
                }

                // de plus en plus grandes
                if (_metaballes[i]._Taille < TailleMax)
                {
                    _metaballes[i]._Taille     += (_metaballes[i]._Taille * 0.1 * maintenant._intervalle);
                    _metaballes[i]._TailleCarre = _metaballes[i]._Taille * _metaballes[i]._Taille;
                }
            }

            // Ajouter eventuellement une metaballe
            if (NbMetaballes < NbMax)
            {
                if (maintenant._temps.Subtract(derniereCreation).TotalMilliseconds > 800)
                {
                    NouvelleMetaballe(ref _metaballes[NbMetaballes]);
                    NbMetaballes++;
                    derniereCreation = maintenant._temps;
                }
            }

            // Deplacer l'emetteur
            xEmetteur += FloatRandom(-5, 5);
            if (xEmetteur < 0)
            {
                xEmetteur = 0;
            }
            else
            if (xEmetteur > Largeur)
            {
                xEmetteur = Largeur;
            }

            updateFrame();
                        #if TRACER
            RenderStop(CHRONO_TYPE.DEPLACE);
                        #endif
        }
Exemplo n.º 4
0
 public void CreateAccounts()
 {
     TotalsAccount = Temps.CreateAccount("<Total>");
 }
Exemplo n.º 5
0
 //---------------------------------------------------------------------------
 public double GetTemp(double time)
 {
     return(Temps.Value(time - 1));
 }
        public static void TempCalc()
        {
            Console.Clear();
            Console.WriteLine("Welcome to a Touchy Temp Converter!\nWhat would you like to convert?");
            string[] conversions =
            {
                "1) \u00B0C -> \u00B0F & K",
                "2) \u00B0F -> \u00B0C & K",
                "3) K -> \u00B0F & \u00B0C"
            };
            foreach (string version in conversions)
            {
                Console.WriteLine(version);
            }
            Console.Write("Make a Selection: ");
            string selection = Console.ReadLine();

            if (selection == "1")
            {
                //c to f/k
                Console.Clear();
                Console.Write("Enter a temperature to convert from Celsius: ");

                // TODO: Build out 'Else' statement if unable to parse to double
                double celTemp;
                if (double.TryParse(Console.ReadLine(), out celTemp))
                {
                    Temps results = ConvertCelsius(celTemp);
                    Console.WriteLine("{0}\u00B0C is: {1} \u00B0F and {2} K", celTemp, results.temp1, results.temp2);
                }
            }
            else if (selection == "2")
            {
                //f to c/k
                Console.Clear();
                Console.Write("Enter a temperature to convert from Fahrenheit: ");

                // TODO: Build out 'Else' statement if unable to parse to double
                double fahrTemp;
                if (double.TryParse(Console.ReadLine(), out fahrTemp))
                {
                    Temps results = ConvertCelsius(fahrTemp);
                    Console.WriteLine("{0}\u00B0F is: {1} \u00B0C and {2} K", fahrTemp, results.temp1, results.temp2);
                }
            }
            else if (selection == "3")
            {
                //k to f/c
                Console.Clear();
                Console.Write("Enter a temperature to convert from Kelvin: ");

                // TODO: Build out 'Else' statement if unable to parse to double
                double kelTemp;
                if (double.TryParse(Console.ReadLine(), out kelTemp))
                {
                    Temps results = ConvertCelsius(kelTemp);
                    Console.WriteLine("{0}K is: {1} \u00B0F and {2} \u00B0C", kelTemp, results.temp1, results.temp2);
                }
            }
            else
            {
                // TODO: Build out 'Else' statement if menu choice 1-3 is not entered.
            }
        }
Exemplo n.º 7
0
 public void CreateAccounts()
 {
     RoundingAccount = Temps.CreateAccount("<Adjustment>");
     RevaluedAccount = Temps.CreateAccount("<Revalued>");
 }
Exemplo n.º 8
0
 /// <summary>
 /// A implementer: retourner le texte
 /// </summary>
 /// <param name="maintenant"></param>
 /// <returns></returns>
 protected abstract String       getTexte(Temps maintenant);
Exemplo n.º 9
0
 protected void AddTemp(System.IDisposable temp)
 {
     Temps.Add(temp);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Ported from report_budget_items
        /// </summary>
        public void ReportBudgetItems(Date date)
        {
            // Cleanup pending items that finished before date
            // We have to keep them until the last day they apply because operator() needs them to see if a
            // posting is budgeted or not
            IList <PendingPostsPair> postsToErase = new List <PendingPostsPair>();

            foreach (PendingPostsPair pair in PendingPosts)
            {
                if (pair.DateInterval.Finish.HasValue && !pair.DateInterval.Start.HasValue && pair.DateInterval.Finish < date)
                {
                    postsToErase.Add(pair);
                }
            }
            foreach (PendingPostsPair pair in postsToErase)
            {
                PendingPosts.Remove(pair);
            }

            if (!PendingPosts.Any())
            {
                return;
            }

            bool reported;

            do
            {
                reported = false;

                foreach (PendingPostsPair pair in PendingPosts)
                {
                    if (pair.DateInterval.Finish.HasValue && !pair.DateInterval.Start.HasValue)
                    {
                        continue;       // skip expired posts
                    }
                    Date?begin = pair.DateInterval.Start;
                    if (!begin.HasValue)
                    {
                        Date?rangeBegin = null;
                        if (pair.DateInterval.Range != null)
                        {
                            rangeBegin = pair.DateInterval.Range.Begin;
                        }

                        Logger.Current.Debug(DebugBudgetGenerate, () => "Finding period for pending post");
                        if (!pair.DateInterval.FindPeriod(rangeBegin ?? date))
                        {
                            continue;
                        }
                        if (!pair.DateInterval.Start.HasValue)
                        {
                            throw new LogicError(LogicError.ErrorMessageFailedToFindPeriodForPeriodicTransaction);
                        }
                        begin = pair.DateInterval.Start;
                    }

                    Logger.Current.Debug(DebugBudgetGenerate, () => String.Format("begin = {0}", begin));
                    Logger.Current.Debug(DebugBudgetGenerate, () => String.Format("date  = {0}", date));
                    if (pair.DateInterval.Finish.HasValue)
                    {
                        Logger.Current.Debug(DebugBudgetGenerate, () => String.Format("pair.first.finish = {0}", pair.DateInterval.Finish));
                    }

                    if (begin <= date && (!pair.DateInterval.Finish.HasValue || begin < pair.DateInterval.Finish))
                    {
                        Post post = pair.Post;

                        pair.DateInterval++;
                        Logger.Current.Debug(DebugBudgetGenerate, () => "Reporting budget for " + post.ReportedAccount.FullName);

                        Xact xact = Temps.CreateXact();
                        xact.Payee = "Budget transaction";
                        xact.Date  = begin.Value;

                        Post temp = Temps.CopyPost(post, xact);
                        temp.Amount.InPlaceNegate();

                        if (Flags.HasFlag(ReportBudgetFlags.BUDGET_WRAP_VALUES))
                        {
                            Value seq = new Value();
                            seq.PushBack(Value.Get(0));
                            seq.PushBack(Value.Get(temp.Amount));

                            temp.XData.CompoundValue = seq;
                            temp.XData.Compound      = true;
                        }

                        base.Handle(temp);

                        reported = true;
                    }
                }
            }while (reported);
        }
Exemplo n.º 11
0
 protected override void getValue(Temps maintenant, out float value, out float decalage)
 {
     decalage = (maintenant._Minute + (maintenant._Seconde + (maintenant._Millieme / 1000.0f)) / 60.0f) / 60.0f;
     value    = maintenant._Heure;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Deplacement de tous les objets: flocons, camera...
        /// </summary>
        /// <param name="maintenant"></param>
        /// <param name="tailleEcran"></param>
        public override void Deplace(Temps maintenant, ref Rectangle tailleEcran)
        {
#if TRACER
            RenderStart(CHRONO_TYPE.DEPLACE);
#endif
            float depuisdebut   = (float)(debut.Subtract(maintenant._temps).TotalMilliseconds / 1000.0);
            float vitesseCamera = (float)Math.Sin(depuisdebut / PERIODE_ROTATION) * VITESSE_ROTATION;
            float vitesseRot    = maintenant._intervalle * 100;

            float CosTheta = (float)Math.Cos(vitesseCamera * maintenant._intervalle);
            float SinTheta = (float)Math.Sin(vitesseCamera * maintenant._intervalle);
            float px, pz;
            bool  trier = false;
            // Deplace les flocons
            for (int i = 0; i < NB_FLOCONS; i++)
            {
                if (_flocons[i].y < -VIEWPORT_Y * 12)
                {
                    NouveauFlocon(ref _flocons[i]);
                    trier = true;
                }
                else
                {
                    // Deplacement
                    _flocons[i].x += ((_flocons[i].vx + _xWind) * maintenant._intervalle);
                    _flocons[i].y -= (_flocons[i].vy * maintenant._intervalle);
                    _flocons[i].z += (_flocons[i].vz * maintenant._intervalle);

                    // Variation de vitesse
                    Varie(ref _flocons[i].vx, -1, 1, 10, maintenant._intervalle);
                    Varie(ref _flocons[i].vz, -1, 1, 10, maintenant._intervalle);
                    // Rotation due a la position de la camera
                    px = (CosTheta * (_flocons[i].x - _xRotation)) - (SinTheta * _flocons[i].z) + _xRotation;
                    pz = (SinTheta * (_flocons[i].x - _xRotation)) + (CosTheta * _flocons[i].z);

                    _flocons[i].x   = px;
                    _flocons[i].z   = pz;
                    _flocons[i].ax += vitesseRot;
                    _flocons[i].ay += vitesseRot;
                    _flocons[i].az += vitesseRot;
                }
            }


            Varie(ref _xWind, -MAX_VENT, MAX_VENT, VITESSE_DELTA_VENT, maintenant._intervalle);
            Varie(ref _xRotation, -_tailleCubeX / 2, _tailleCubeX / 2, 10, maintenant._intervalle);

            if (trier)
            {
                Array.Sort(_flocons, delegate(Flocon O1, Flocon O2)
                {
                    if (O1.z > O2.z)
                    {
                        return(1);
                    }
                    if (O1.z < O2.z)
                    {
                        return(-1);
                    }
                    return(0);
                });
            }
#if TRACER
            RenderStop(CHRONO_TYPE.DEPLACE);
#endif
        }
Exemplo n.º 13
0
        /// <summary>
        /// Deplacer les nuages
        /// </summary>
        /// <param name="maintenant"></param>
        /// <param name="tailleEcran"></param>
        public override void Deplace(Temps maintenant, ref Rectangle tailleEcran)
        {
#if TRACER
            RenderStart(CHRONO_TYPE.DEPLACE);
#endif
            float vitesse = maintenant._intervalle * VITESSE;
            bool  derriereCam;
            bool  trierNuages = false;
            for (int i = 0; i < NB_NUAGES; i++)
            {
                derriereCam   = true;
                _nuages[i].z += vitesse;
                foreach (Particule p in _nuages[i]._particules)
                {
                    p.z += vitesse;

                    if (p.z < _zCamera)
                    {
                        // Au moins une des particules du nuage est devant la camera
                        derriereCam = false;
                    }
                }

                if (derriereCam)
                {
                    // Aucune partie du nuage devant la camera: le recreer au loin
                    creerNuage(ref _nuages[i], false);
                    trierNuages = true;
                }
            }

            if (trierNuages)
            {
                Array.Sort(_nuages, delegate(Nuage O1, Nuage O2)
                {
                    if (O1.z > O2.z)
                    {
                        return(1);
                    }
                    if (O1.z < O2.z)
                    {
                        return(-1);
                    }
                    return(0);
                });
            }

            // Recuperer le tableau des particules, et les trier en fonction de la distance
            _NbParticules = 0;
            foreach (Nuage n in _nuages)
            {
                foreach (Particule p in n._particules)
                {
                    _particules[_NbParticules++] = p;
                }
            }

            //Array.Sort(_particules, 0, _NbParticules);
#if TRACER
            RenderStop(CHRONO_TYPE.DEPLACE);
#endif
        }
Exemplo n.º 14
0
        /// <summary>
        /// Ported from posts_as_equity::report_subtotal
        /// </summary>
        public void ReportSubtotal()
        {
            Date finish = default(Date);

            foreach (Post post in ComponentPosts)
            {
                Date date = post.GetDate();
                if (!finish.IsValid() || date > finish)
                {
                    finish = date;
                }
            }

            Xact xact = Temps.CreateXact();

            xact.Payee = "Opening Balances";
            xact.Date  = finish;

            Value total = Value.Get(0);

            foreach (KeyValuePair <string, AcctValue> pair in Values)
            {
                Value value = pair.Value.Value.StripAnnotations(Report.WhatToKeep());
                if (!Value.IsNullOrEmpty(value))
                {
                    if (value.Type == ValueTypeEnum.Balance)
                    {
                        foreach (Amount amt in value.AsBalance.SortedAmounts())
                        {
                            if (!amt.IsZero)
                            {
                                FiltersCommon.HandleValue(
                                    /* value=      */ Value.Get(amt),
                                    /* account=    */ pair.Value.Account,
                                    /* xact=       */ xact,
                                    /* temps=      */ Temps,
                                    /* handler=    */ (PostHandler)Handler,
                                    /* date=       */ finish,
                                    /* act_date_p= */ false);
                            }
                        }
                    }
                    else
                    {
                        FiltersCommon.HandleValue(
                            /* value=      */ Value.Get(value.AsAmount),
                            /* account=    */ pair.Value.Account,
                            /* xact=       */ xact,
                            /* temps=      */ Temps,
                            /* handler=    */ (PostHandler)Handler,
                            /* date=       */ finish,
                            /* act_date_p= */ false);
                    }
                }

                if (!pair.Value.IsVirtual || pair.Value.MustBalance)
                {
                    total.InPlaceAdd(value);
                }
            }
            Values.Clear();

            // This last part isn't really needed, since an Equity:Opening
            // Balances posting with a null amount will automatically balance with
            // all the other postings generated.  But it does make the full
            // balancing amount clearer to the user.
            if (!total.IsZero)
            {
                Action <Amount> postCreator = amt =>
                {
                    Post balancePost = Temps.CreatePost(xact, BalanceAccount);
                    balancePost.Amount = amt.Negated();
                    Handler.Handle(balancePost);
                };

                if (total.Type == ValueTypeEnum.Balance)
                {
                    total.AsBalance.MapSortedAmounts(postCreator);
                }
                else
                {
                    postCreator(total.AsAmount);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Ported from changed_value_posts::output_revaluation
        /// </summary>
        public void OutputRevaluation(Post post, Date date)
        {
            if (date.IsValid())
            {
                post.XData.Date = date;
            }

            try
            {
                BindScope boundScope = new BindScope(Report, post);
                RepricedTotal = TotalExpr.Calc(boundScope);
            }
            finally
            {
                post.XData.Date = default(Date);
            }

            Logger.Current.Debug("filters.changed_value", () => String.Format("output_revaluation(last_total)     = {0}", LastTotal));
            Logger.Current.Debug("filters.changed_value", () => String.Format("output_revaluation(repriced_total) = {0}", RepricedTotal));

            if (!Value.IsNullOrEmpty(LastTotal))
            {
                Value diff = RepricedTotal - LastTotal;
                if (!Value.IsNullOrEmptyOrFalse(diff))
                {
                    Logger.Current.Debug("filters.changed_value", () => String.Format("output_revaluation(strip(diff)) = {0}", diff.StripAnnotations(Report.WhatToKeep())));

                    Xact xact = Temps.CreateXact();
                    xact.Payee = "Commodities revalued";
                    xact.Date  = date.IsValid() ? date : post.ValueDate;

                    if (!ForAccountsReports)
                    {
                        FiltersCommon.HandleValue(
                            /* value=         */ diff,
                            /* account=       */ RevaluedAccount,
                            /* xact=          */ xact,
                            /* temps=         */ Temps,
                            /* handler=       */ (PostHandler)Handler,
                            /* date=          */ xact.Date.Value,
                            /* act_date_p=    */ true,
                            /* total=         */ RepricedTotal);
                    }
                    else if (ShowUnrealized)
                    {
                        FiltersCommon.HandleValue(
                            /* value=         */ diff.Negated(),
                            /* account=       */
                            (diff.IsLessThan(Value.Zero) ?
                             LossesEquityAccount :
                             GainsEquityAccount),
                            /* xact=          */ xact,
                            /* temps=         */ Temps,
                            /* handler=       */ (PostHandler)Handler,
                            /* date=          */ xact.Date.Value,
                            /* act_date_p=    */ true,
                            /* total=         */ new Value(),
                            /* direct_amount= */ false,
                            /* mark_visited=  */ true);
                    }
                }
            }
        }
Exemplo n.º 16
0
 public Statisticien()
 {
     NbSoleil          = 0;
     NbChangementTemps = -1;
     DernierTemps      = Temps.Inconnu;
 }
Exemplo n.º 17
0
 public void CreateAccounts()
 {
     RevaluedAccount = DisplayFilter != null ? DisplayFilter.RevaluedAccount : Temps.CreateAccount("<Revalued>");
 }
Exemplo n.º 18
0
        /// <summary>
        /// Ported from subtotal_posts::report_subtotal
        /// </summary>
        public void ReportSubtotal(string specFmt = null, DateInterval interval = null)
        {
            if (!ComponentPosts.Any())
            {
                return;
            }

            Date?rangeStart  = interval != null ? interval.Start : null;
            Date?rangeFinish = interval != null ? interval.InclusiveEnd : null;

            if (!rangeStart.HasValue || !rangeFinish.HasValue)
            {
                foreach (Post post in ComponentPosts)
                {
                    Date date      = post.GetDate();
                    Date valueDate = post.ValueDate;

                    if (!rangeStart.HasValue || date < rangeStart)
                    {
                        rangeStart = date;
                    }
                    if (!rangeFinish.HasValue || valueDate > rangeFinish)
                    {
                        rangeFinish = valueDate;
                    }
                }
            }

            ComponentPosts.Clear();

            string outDate;

            if (!String.IsNullOrEmpty(specFmt))
            {
                outDate = TimesCommon.Current.FormatDate(rangeFinish.Value, FormatTypeEnum.FMT_CUSTOM, specFmt);
            }
            else if (!String.IsNullOrEmpty(DateFormat))
            {
                outDate = "- " + TimesCommon.Current.FormatDate(rangeFinish.Value, FormatTypeEnum.FMT_CUSTOM, DateFormat);
            }
            else
            {
                outDate = "- " + TimesCommon.Current.FormatDate(rangeFinish.Value);
            }

            Xact xact = Temps.CreateXact();

            xact.Payee = outDate;
            xact.Date  = rangeStart.Value;

            foreach (KeyValuePair <string, AcctValue> pair in Values)
            {
                FiltersCommon.HandleValue(
                    /* value=      */ pair.Value.Value,
                    /* account=    */ pair.Value.Account,
                    /* xact=       */ xact,
                    /* temps=      */ Temps,
                    /* handler=    */ (PostHandler)Handler,
                    /* date=       */ rangeFinish.Value,
                    /* act_date_p= */ false);
            }

            Values.Clear();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Ported from changed_value_posts::output_intermediate_prices
        /// </summary>
        public void OutputIntermediatePrices(Post post, Date current)
        {
            // To fix BZ#199, examine the balance of last_post and determine whether the
            // price of that amount changed after its date and before the new post's
            // date.  If so, generate an output_revaluation for that price change.
            // Mostly this is only going to occur if the user has a series of pricing
            // entries, since a posting-based revaluation would be seen here as a post.

            Value displayTotal = Value.Clone(LastTotal);

            if (displayTotal.Type == ValueTypeEnum.Sequence)
            {
                Xact xact = Temps.CreateXact();
                xact.Payee = "Commodities revalued";
                xact.Date  = current.IsValid() ? current : post.ValueDate;

                Post temp = Temps.CopyPost(post, xact);
                temp.Flags |= SupportsFlagsEnum.ITEM_GENERATED;

                PostXData xdata = temp.XData;
                if (current.IsValid())
                {
                    xdata.Date = current;
                }

                switch (LastTotal.Type)
                {
                case ValueTypeEnum.Boolean:
                case ValueTypeEnum.Integer:
                    LastTotal.InPlaceCast(ValueTypeEnum.Amount);
                    temp.Amount = LastTotal.AsAmount;
                    break;

                case ValueTypeEnum.Amount:
                    temp.Amount = LastTotal.AsAmount;
                    break;

                case ValueTypeEnum.Balance:
                case ValueTypeEnum.Sequence:
                    xdata.CompoundValue = LastTotal;
                    xdata.Compound      = true;
                    break;

                default:
                    throw new InvalidOperationException();
                }

                BindScope innerScope = new BindScope(Report, temp);
                displayTotal = DisplayTotalExpr.Calc(innerScope);
            }

            switch (displayTotal.Type)
            {
            case ValueTypeEnum.Void:
            case ValueTypeEnum.Integer:
            case ValueTypeEnum.Sequence:
                break;

            case ValueTypeEnum.Amount:
            case ValueTypeEnum.Balance:
            {
                if (displayTotal.Type == ValueTypeEnum.Amount)
                {
                    displayTotal.InPlaceCast(ValueTypeEnum.Balance);
                }

                IDictionary <DateTime, Amount> allPrices = new SortedDictionary <DateTime, Amount>();

                foreach (KeyValuePair <Commodity, Amount> amtComm in displayTotal.AsBalance.Amounts)
                {
                    amtComm.Key.MapPrices((d, a) => allPrices[d] = a, current, post.ValueDate, true);
                }

                // Choose the last price from each day as the price to use
                IDictionary <Date, bool> pricingDates = new SortedDictionary <Date, bool>();

                foreach (KeyValuePair <DateTime, Amount> price in allPrices.Reverse())
                {
                    // This insert will fail if a later price has already been inserted
                    // for that date.
                    var priceDate = (Date)price.Key.Date;
                    Logger.Debug("filters.revalued", () => String.Format("re-inserting {0} at {1}", price.Value, priceDate));
                    pricingDates[priceDate] = true;
                }

                // Go through the time-sorted prices list, outputting a revaluation for
                // each price difference.
                foreach (KeyValuePair <Date, bool> price in pricingDates)
                {
                    OutputRevaluation(post, price.Key);
                    LastTotal = RepricedTotal;
                }
                break;
            }

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 20
0
        public override void Handle(Post post)
        {
            bool copyXactDetails = false;

            if (LastXact != post.Xact)
            {
                Temps.CopyXact(post.Xact);
                LastXact        = post.Xact;
                copyXactDetails = true;
            }
            Xact xact = Temps.LastXact;

            xact.Code = null;

            if (copyXactDetails)
            {
                xact.CopyDetails(post.Xact);

                string buf = String.Format("{0}{1}{0}", post.Xact.Payee, IntegerGen.Value());

                xact.Payee = SHA1.GetHash(buf);
                xact.Note  = null;
            }
            else
            {
                xact.Journal = post.Xact.Journal;
            }

            IList <string> accountNames = new List <string>();

            for (Account acct = post.Account; acct != null; acct = acct.Parent)
            {
                string buf = String.Format("{0}{1}{2}", IntegerGen.Value(), acct, acct.FullName);

                accountNames.Add(SHA1.GetHash(buf));
            }

            Account newAccount = FiltersCommon.CreateTempAccountFromPath(accountNames, Temps, xact.Journal.Master);
            Post    temp       = Temps.CopyPost(post, xact, newAccount);

            temp.Note   = null;
            temp.Flags |= SupportsFlagsEnum.POST_ANONYMIZED;

            RenderCommodity(temp.Amount);
            if (temp.Amount.HasAnnotation)
            {
                temp.Amount.Annotation.Tag = null;
                if (temp.Amount.Annotation.Price != null)
                {
                    RenderCommodity(temp.Amount.Annotation.Price);
                }
            }

            if (temp.Cost != null)
            {
                RenderCommodity(temp.Cost);
            }
            if (temp.AssignedAmount != null)
            {
                RenderCommodity(temp.AssignedAmount);
            }

            base.Handle(temp);
        }
Exemplo n.º 21
0
 public void CreateAccounts()
 {
     EmptytAccount = Temps.CreateAccount("<None>");
 }
Exemplo n.º 22
0
        public override void AfficheOpenGL(OpenGL gl, Temps maintenant, Rectangle tailleEcran, Color couleur)
        {
#if TRACER
            RenderStart(CHRONO_TYPE.RENDER);
#endif
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.ClearColor(0, 0, 0, 0);
            gl.PushMatrix();
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Ortho2D(0.0, LARGEUR, 0.0, HAUTEUR);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);

            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_DEPTH);
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            gl.Disable(OpenGL.GL_BLEND);
            textureCellule.Bind(gl);

            Color  Naissance  = getCouleurOpaqueAvecAlpha(couleur, 70);
            byte[] cNaissance = { Naissance.R, Naissance.G, Naissance.B };
            Color  Normal     = getCouleurOpaqueAvecAlpha(couleur, 150);
            byte[] cNormal    = { Normal.R, Normal.G, Normal.B };

            byte ancienType = MORT;
            gl.Begin(OpenGL.GL_QUADS);
            for (int x = 0; x < LARGEUR; x++)
            {
                for (int y = 0; y < HAUTEUR; y++)
                {
                    if (cellules[x, y] != MORT)
                    {
                        if (cellules[x, y] != ancienType)
                        {
                            if (cellules[x, y] == NAISSANCE)
                            {
                                gl.Color(cNaissance[0], cNaissance[1], cNaissance[2]);
                            }
                            else
                            {
                                gl.Color(cNormal[0], cNormal[1], cNormal[2]);
                            }
                            ancienType = cellules[x, y];
                        }

                        gl.TexCoord(0.0f, 0.0f); gl.Vertex(x, y + 1);
                        gl.TexCoord(0.0f, 1.0f); gl.Vertex(x, y);
                        gl.TexCoord(1.0f, 1.0f); gl.Vertex(x + 1, y);
                        gl.TexCoord(1.0f, 0.0f); gl.Vertex(x + 1, y + 1);
                    }
                }
            }
            gl.End();
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PopMatrix();
#if TRACER
            RenderStop(CHRONO_TYPE.RENDER);
#endif
        }
Exemplo n.º 23
0
        public override void Flush()
        {
            if (Interval.Duration == null)
            {
                base.Flush();
                return;
            }

            // Sort all the postings we saw by date ascending
            // [DM] Enumerable.OrderBy is a stable sort that preserve original positions for equal items
            AllPosts = AllPosts.OrderBy(p => p, new IntervalPostCompare()).ToList();

            // only if the interval has no start use the earliest post
            if (!(Interval.Begin.HasValue && Interval.FindPeriod(Interval.Begin.Value)))
            {
                // Determine the beginning interval by using the earliest post
                if (AllPosts.Any() && !Interval.FindPeriod(AllPosts.First().GetDate()))
                {
                    throw new LogicError(LogicError.ErrorMessageFailedToFindPeriodForIntervalReport);
                }
            }

            // Walk the interval forward reporting all posts within each one
            // before moving on, until we reach the end of all_posts
            bool sawPosts = false;

            for (int i = 0; i < AllPosts.Count;)
            {
                Post post = AllPosts[i];

                Logger.Current.Debug("filters.interval", () => String.Format("Considering post {0} = {1}", post.GetDate(), post.Amount));
                Logger.Current.Debug("filters.interval", () => String.Format("interval is:{0}", DebugInterval(Interval)));

                if (Interval.Finish.HasValue && post.GetDate() >= Interval.Finish.Value)
                {
                    throw new InvalidOperationException("assert(! interval.finish || post->date() < *interval.finish)");
                }

                if (Interval.WithinPeriod(post.GetDate()))
                {
                    Logger.Current.Debug("filters.interval", () => "Calling subtotal_posts::operator()");
                    base.Handle(post);
                    ++i;
                    sawPosts = true;
                }
                else
                {
                    if (sawPosts)
                    {
                        Logger.Current.Debug("filters.interval", () => "Calling subtotal_posts::report_subtotal()");
                        ReportSubtotal(Interval);
                        sawPosts = false;
                    }
                    else if (GenerateEmptyPosts)
                    {
                        // Generate a null posting, so the intervening periods can be
                        // seen when -E is used, or if the calculated amount ends up
                        // being non-zero
                        Xact nullXact = Temps.CreateXact();
                        nullXact.Date = Interval.InclusiveEnd.Value;

                        Post nullPost = Temps.CreatePost(nullXact, EmptytAccount);
                        nullPost.Flags |= SupportsFlagsEnum.POST_CALCULATED;
                        nullPost.Amount = new Amount(0);

                        base.Handle(nullPost);
                        ReportSubtotal(Interval);
                    }

                    Logger.Current.Debug("filters.interval", () => "Advancing interval");
                    ++Interval;
                }
            }

            // If the last postings weren't reported, do so now.
            if (sawPosts)
            {
                Logger.Current.Debug("filters.interval", () => "Calling subtotal_posts::report_subtotal() at end");
                ReportSubtotal(Interval);
            }

            // Tell our parent class to flush
            base.Flush();
        }
Exemplo n.º 24
0
        /// <summary>
        /// Ported from forecast_posts::flush
        /// </summary>
        public override void Flush()
        {
            IList <Post> passed = new List <Post>();
            Date         last   = TimesCommon.Current.CurrentDate;

            // If there are period transactions to apply in a continuing series until
            // the forecast condition is met, generate those transactions now.  Note
            // that no matter what, we abandon forecasting beyond the next 5 years.
            //
            // It works like this:
            //
            // Earlier, in forecast_posts::add_period_xacts, we cut up all the periodic
            // transactions into their components postings, so that we have N "periodic
            // postings".  For example, if the user had this:
            //
            // ~ daily
            //   Expenses:Food       $10
            //   Expenses:Auto:Gas   $20
            // ~ monthly
            //   Expenses:Food       $100
            //   Expenses:Auto:Gas   $200
            //
            // We now have 4 periodic postings in `pending_posts'.
            //
            // Each periodic postings gets its own copy of its parent transaction's
            // period, which is modified as we go.  This is found in the second member
            // of the pending_posts_list for each posting.
            //
            // The algorithm below works by iterating through the N periodic postings
            // over and over, until each of them mets the termination critera for the
            // forecast and is removed from the set.

            while (PendingPosts.Any())
            {
                // At each step through the loop, we find the first periodic posting whose
                // period contains the earliest starting date.
                PendingPostsPair least = PendingPosts.First();
                foreach (PendingPostsPair i in PendingPosts)
                {
                    if (!i.DateInterval.Start.HasValue)
                    {
                        throw new InvalidOperationException("Start is empty");
                    }
                    if (!least.DateInterval.Start.HasValue)
                    {
                        throw new InvalidOperationException("least.Start is empty");
                    }

                    if (i.DateInterval.Start < least.DateInterval.Start)
                    {
                        least = i;
                    }
                }

                // If the next date in the series for this periodic posting is more than 5
                // years beyond the last valid post we generated, drop it from further
                // consideration.
                Date next = least.DateInterval.Next.Value;
                if (next <= least.DateInterval.Start)
                {
                    throw new InvalidOperationException("next <= least.DateInterval.Start");
                }

                if (((next - last).Days) > (365 * ForecastYears))
                {
                    Logger.Current.Debug("filters.forecast", () => String.Format("Forecast transaction exceeds {0} years beyond today", ForecastYears));
                    PendingPosts.Remove(least);
                    continue;
                }

                // `post' refers to the posting defined in the period transaction.  We
                // make a copy of it within a temporary transaction with the payee
                // "Forecast transaction".
                Post post = least.Post;
                Xact xact = Temps.CreateXact();
                xact.Payee = "Forecast transaction";
                xact.Date  = next;
                Post temp = Temps.CopyPost(post, xact);

                // Submit the generated posting
                Logger.Current.Debug("filters.forecast", () => String.Format("Forecast transaction: {0} {1} {2}", temp.GetDate(), temp.Account.FullName, temp.Amount));
                base.Handle(temp);

                // If the generated posting matches the user's report query, check whether
                // it also fails to match the continuation condition for the forecast.  If
                // it does, drop this periodic posting from consideration.
                if (temp.HasXData && temp.XData.Matches)
                {
                    Logger.Current.Debug("filters.forecast", () => "  matches report query");
                    BindScope boundScope = new BindScope(Context, temp);
                    if (!Pred.Calc(boundScope).Bool)
                    {
                        Logger.Current.Debug("filters.forecast", () => "  fails to match continuation criteria");
                        PendingPosts.Remove(least);
                        continue;
                    }
                }

                // Increment the 'least', but remove it from pending_posts if it
                // exceeds its own boundaries.
                ++least.DateInterval;
                if (!least.DateInterval.Start.HasValue)
                {
                    PendingPosts.Remove(least);
                    continue;
                }
            }

            base.Flush();
        }
Exemplo n.º 25
0
        private void UpdateEntity(QUpdateEntityMessage msg)
        {
            Entity e;

            if (!Entities.ContainsKey(msg.Entity))
            {
                e = new Entity()
                {
                    Parent = this, Number = msg.Entity
                };
                Entities[msg.Entity] = e;
            }
            else
            {
                e = Entities[msg.Entity];
            }

            if (e.Model == "progs/player.mdl" || e.Model == "progs/eyes.mdl")
            {
                Temps.Add(new Footstep(e.Origin));
            }

            if (msg.AnglesX.HasValue)
            {
                e.Angles.X = msg.AnglesX.Value;
            }
            if (msg.AnglesY.HasValue)
            {
                e.Angles.Y = msg.AnglesY.Value;
            }
            if (msg.AnglesZ.HasValue)
            {
                e.Angles.Z = msg.AnglesZ.Value;
            }
            if (msg.Colormap.HasValue)
            {
                e.Colormap = msg.Colormap.Value;
            }
            if (msg.Effects.HasValue)
            {
                e.Effects = msg.Effects.Value;
            }
            if (msg.Frame.HasValue)
            {
                e.Frame = msg.Frame.Value;
            }
            if (msg.ModelIndex.HasValue)
            {
                e.ModelIndex = msg.ModelIndex.Value;
            }
            if (msg.OriginX.HasValue)
            {
                e.Origin.X = msg.OriginX.Value;
            }
            if (msg.OriginY.HasValue)
            {
                e.Origin.Y = msg.OriginY.Value;
            }
            if (msg.OriginZ.HasValue)
            {
                e.Origin.Z = msg.OriginZ.Value;
            }
            if (msg.Skin.HasValue)
            {
                e.Skin = msg.Skin.Value;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Ported from collapse_posts::report_subtotal
        /// </summary>
        public void ReportSubtotal()
        {
            if (Count == 0)
            {
                return;
            }

            int displayedCount = 0;

            foreach (Post post in ComponentPosts)
            {
                BindScope boundScope = new BindScope(Report, post);
                if (OnlyPredicate.Calc(boundScope).Bool&& DisplayPredicate.Calc(boundScope).Bool)
                {
                    displayedCount++;
                }
            }

            if (displayedCount == 1)
            {
                base.Handle(LastPost);
            }
            else if (OnlyCollapseIfZero && !Subtotal.IsZero)
            {
                foreach (Post post in ComponentPosts)
                {
                    base.Handle(post);
                }
            }
            else
            {
                Date earliestDate = default(Date);
                Date latestDate   = default(Date);

                foreach (Post post in ComponentPosts)
                {
                    Date date      = post.GetDate();
                    Date valueDate = post.ValueDate;
                    if (!earliestDate.IsValid() || date < earliestDate)
                    {
                        earliestDate = date;
                    }
                    if (!latestDate.IsValid() || valueDate > latestDate)
                    {
                        latestDate = valueDate;
                    }
                }

                Xact xact = Temps.CreateXact();
                xact.Payee = LastXact.Payee;
                xact.Date  = earliestDate.IsValid() ? earliestDate : LastXact.Date;

                Logger.Current.Debug("filters.collapse", () => String.Format("Pseudo-xact date = {0}", xact.Date));
                Logger.Current.Debug("filters.collapse", () => String.Format("earliest date    = {0}", earliestDate));
                Logger.Current.Debug("filters.collapse", () => String.Format("latest date      = {0}", latestDate));

                FiltersCommon.HandleValue(
                    /* value=      */ Subtotal,
                    /* account=    */ TotalsAccount,
                    /* xact=       */ xact,
                    /* temps=      */ Temps,
                    /* handler=    */ (PostHandler)Handler,
                    /* date=       */ latestDate,
                    /* act_date_p= */ false);
            }

            ComponentPosts.Clear();

            LastXact = null;
            LastPost = null;
            Subtotal = Value.Get(0);
            Count    = 0;
        }
Exemplo n.º 27
0
 public void CreateAccounts()
 {
     EquityAccount  = Temps.CreateAccount("Equity");
     BalanceAccount = EquityAccount.FindAccount("Opening Balances");
 }
Exemplo n.º 28
0
 public override void Dispose()
 {
     Temps.Dispose();
     base.Dispose();
 }
Exemplo n.º 29
0
        public override void AfficheGDI(Graphics g, Temps maintenant, Rectangle tailleEcran, Color couleur)
        {
#if DEBUG
            RenderStart(CHRONO_TYPE.RENDER);
#endif
            System.Drawing.Drawing2D.SmoothingMode s = g.SmoothingMode;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            CompositingQuality q = g.CompositingQuality;
            g.CompositingQuality = CompositingQuality.HighSpeed;
            InterpolationMode In = g.InterpolationMode;
            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            using (LinearGradientBrush linGrBrush = new LinearGradientBrush(tailleEcran,
                                                                            Color.Black,    // Opaque red
                                                                            getCouleurOpaqueAvecAlpha(couleur, 255),
                                                                            LinearGradientMode.Vertical))
                g.FillRectangle(linGrBrush, tailleEcran);

            float X, Y, X2, Y2;

            bool nuageAffiche;

            using (Bitmap bmp1 = BitmapNuance(g, _nuage1, getCouleurAvecAlpha(couleur, ALPHA)),
                   bmp2 = BitmapNuance(g, _nuage2, getCouleurAvecAlpha(couleur, ALPHA)),
                   bmp3 = BitmapNuance(g, _nuage3, getCouleurAvecAlpha(couleur, ALPHA))
                   )
                for (int i = 0; i < NB_NUAGES; i++)
                {
                    nuageAffiche = false;

                    for (int j = 0; j < _nuages[i]._nbParticules; j++)
                    {
                        if (_nuages[i]._points[j].z > _zCamera)
                        {
                            Coord2DFrom3D(_nuages[i]._points[j].x - _nuages[i]._tailles[j],
                                          _nuages[i]._points[j].y - _nuages[i]._tailles[j],
                                          _nuages[i]._points[j].z,
                                          out X, out Y);

                            Coord2DFrom3D(_nuages[i]._points[j].x + _nuages[i]._tailles[j],
                                          _nuages[i]._points[j].y + _nuages[i]._tailles[j],
                                          _nuages[i]._points[j].z,
                                          out X2, out Y2);
                            try
                            {
                                NormalizeCoord(ref X, ref X2, ref Y, ref Y2);
                                if ((X < _largeur) && (X2 > 0) && (Y < _hauteur) && (Y2 > 0))
                                {
                                    switch (_nuages[i]._type[j])
                                    {
                                    case 0:
                                        g.DrawImage(bmp1, X, Y, X2 - X, Y2 - Y);
                                        break;

                                    case 1:
                                        g.DrawImage(bmp2, X, Y, X2 - X, Y2 - Y);
                                        break;

                                    case 2:
                                        g.DrawImage(bmp3, X, Y, X2 - X, Y2 - Y);
                                        break;
                                    }
                                    nuageAffiche = true;
                                }
                            }
                            catch
                            {
                                nuageAffiche = false;
                            }
                        }
                    }

                    if (!nuageAffiche)
                    {
                        CreateNuage(ref _nuages[i], false);
                    }
                }

            g.SmoothingMode      = s;
            g.CompositingQuality = q;
            g.InterpolationMode  = In;
#if DEBUG
            RenderStop(CHRONO_TYPE.RENDER);
#endif
        }