/// <summary>
 /// Exit a parse tree produced by <see cref="DDD_layout_scriptParser.object_content"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitObject_content([NotNull] DDD_layout_scriptParser.Object_contentContext context)
 {
 }
Beispiel #2
0
        /* 3D objektumok attribútumlistáját készíti elő.
         *
         * Készít egy AttributeListet. (Add-ja kezeli a duplikátumokat és warningot dob)
         * Végigmegy az összes beincludolt attr-group-on és hozzáadja az attr-group listáit.
         * Ha nem talál egy attr-group-ot az persze error.
         *
         * Ezután az összes nem attr-groupból származó attribútumon is végigmegy. Ezeket is hozzáadja a közös listához.
         * A végén összerendeli a rotation-axis, rotation-angle párokat.
         */
        public override object VisitObject_content([NotNull] DDD_layout_scriptParser.Object_contentContext context)
        {
            var includes = context.include_statement();
            List <AttributeList> attributeLists   = new List <AttributeList>();
            AttributeList        objectAttributes = new AttributeList();

            foreach (var include in includes)
            {
                string attrGroupToFind  = include.STRING().ToString();
                bool   addingSuccessful = false;
                foreach (var attrBlock in attributeBlocks)
                {
                    if (attrBlock.Name == attrGroupToFind)
                    {
                        attributeLists.Add(attrBlock.GetAttributeList());
                        addingSuccessful = true;
                        break;
                    }
                }

                if (!addingSuccessful)
                {
                    alerts.Add(new error(include.Start.Line, $"Attr-group {attrGroupToFind} has not been declared"));
                }
            }

            if (attributeLists.Count != 0)
            {
                for (int i = 0; i < attributeLists.Count; ++i)
                {
                    List <Attribute> attrs = attributeLists[i].GetAttributeList();

                    foreach (Attribute a in attrs)
                    {
                        if (objectAttributes.Add(a) == false)
                        {
                            alerts.Add(new warning(includes[i].Start.Line, $"Attribute value '{a.Name}' is set twice or more. Only the last defined will be valid"));
                        }
                    }
                }
            }

            foreach (var attr in context.attr())
            {
                dynamic attrToAdd = VisitAttr(attr);
                if (attrToAdd != null)
                {
                    attrToAdd = (Attribute)attrToAdd;
                    if (objectAttributes.Add(attrToAdd) == false)
                    {
                        alerts.Add(new warning(attr.Start.Line, $"Attribute value '{attrToAdd.Name}' is set twice or more. Only the last defined will be valid"));
                    }
                }
            }

            /* Megnézzük, hogy szögből több volt-e megadva mint forgatási tengelyből vagy épp fordítva.
             *
             * Ha több szög volt, mint forgatási tengely, akkor az extra szögeket kivesszük a listából és warning-ot hozunk fel.
             * Fordított esetben, az extra forgatási tengelyekhez, hozzárendeljük a forráskódban (blokkra nézve) utolsó definiált szöget.
             * Ha ilyen nincs akkor szimplán 0°-ot rendelünk hozzá. Mindkettő esetben warning-ot dobunk.
             */
            int rotAnglesCnt = 0;
            int rotAxesCnt   = 0;

            foreach (var attr in objectAttributes)
            {
                if (attr.Name == "rotation-angle")
                {
                    rotAnglesCnt++;
                }
                else if (attr.Name == "rotation-axis")
                {
                    rotAxesCnt++;
                }
            }

            if (rotAnglesCnt > rotAxesCnt)
            {
                alerts.Add(new warning(context.Start.Line - 1, "There are more 'rotation-angle' defined than 'rotation-axis'. The extra ones will be ignored"));
                objectAttributes.FitRotationAngles(rotAxesCnt);
            }
            else if (rotAxesCnt > rotAnglesCnt)
            {
                alerts.Add(new warning(context.Start.Line - 1, "There are more 'rotation-axis' defined than 'rotation-angle'. The extra ones will be using the last defined 'rotation-angle' value or the default 0°"));
                objectAttributes.FitRotationAxes(rotAxesCnt - rotAnglesCnt);
            }


            return(objectAttributes);
        }
Beispiel #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DDD_layout_scriptParser.object_content"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitObject_content([NotNull] DDD_layout_scriptParser.Object_contentContext context)
 {
     return(VisitChildren(context));
 }