Back to index

wims  3.65+svn20090927
Interpreter.java
Go to the documentation of this file.
00001 /*
00002  * Created on 24.10.2005
00003  *
00004  */
00005 package rene.zirkel.construction;
00006 
00007 import java.util.*;
00008 
00009 import rene.zirkel.*;
00010 import rene.zirkel.constructors.AngleConstructor;
00011 import rene.zirkel.constructors.AreaConstructor;
00012 import rene.zirkel.constructors.CircleConstructor;
00013 import rene.zirkel.constructors.ExpressionConstructor;
00014 import rene.zirkel.constructors.FunctionConstructor;
00015 import rene.zirkel.constructors.IntersectionConstructor;
00016 import rene.zirkel.constructors.LineConstructor;
00017 import rene.zirkel.constructors.MidpointConstructor;
00018 import rene.zirkel.constructors.ObjectConstructor;
00019 import rene.zirkel.constructors.ParallelConstructor;
00020 import rene.zirkel.constructors.PlumbConstructor;
00021 import rene.zirkel.constructors.PointConstructor;
00022 import rene.zirkel.constructors.QuadricConstructor;
00023 import rene.zirkel.constructors.RayConstructor;
00024 import rene.zirkel.constructors.SegmentConstructor;
00025 import rene.zirkel.macro.Macro;
00026 import rene.zirkel.macro.MacroRunner;
00027 import rene.zirkel.objects.*;
00028 
00029 public class Interpreter 
00030 {      Construction C;
00031 
00032        public Interpreter (Construction c)
00033        {      C=c;
00034        }
00035        
00040        public void interpret (ZirkelCanvas zc, String s, String comment)
00041               throws ConstructionException
00042        {      boolean Parameter=false,Target=false,Prompt=false;
00043               Vector V=C.V;
00044               int VN=V.size(); // note the current construction size
00045               int k;
00046 
00047               // Look for special start tags:
00048               if ((k=startTest("parameter",s))>=0)
00049                      // Parameter objects are set at the end of the function.
00050               {      Parameter=true;
00051                      s=s.substring(k).trim();
00052               }
00053               else if (s.toLowerCase().equals(Zirkel.name("showall")) ||
00054                      s.toLowerCase().equals("showall"))
00055                      // This will show all objects even, if there are targets
00056               {      C.ShowAll=true;
00057                      return;
00058               }
00059               else if (s.toLowerCase().equals(Zirkel.name("invisible")) ||
00060                      s.toLowerCase().equals("invisible"))
00061                      // This will superhide all objects
00062               {      C.SuperHide=true;
00063                      return;
00064               }
00065               else if ((k=startTest("target",s))>=0)
00066                      // Target objects are either set immediate (name only) or
00067                      // at the end of the function.
00068               {      Target=true;
00069                      s=s.substring(k).trim();
00070                      ConstructionObject o=C.find(s);
00071                      // see, if the target ist constructable from the
00072                      // parameters, which are already marked cosntructable.
00073                      C.determineConstructables();
00074                      if (o!=null && o.isFlag())
00075                      {      o.setTarget(true);
00076                             C.addTarget(o);
00077                             return;
00078                      }
00079                      else Target=true;
00080               }
00081               else if ((k=startTest("prompt",s))>=0)
00082               {      Prompt=true;
00083                      s=s.substring(k).trim();
00084                      if (C.find(s)!=null)
00085                      {      C.PromptFor.addElement(s);
00086                             return;
00087                      }
00088               }
00089               
00090               // Interpret s. First decompose into function and parameters:
00091               String name="",function="",params[]=new String[16];
00092               int NParams=0,n;
00093               if ((n=s.indexOf('='))>=0)
00094               {      name=s.substring(0,n).trim();
00095                      s=s.substring(n+1).trim();
00096               }
00097               int bracketn=0;
00098               if (s.startsWith("\""))
00099               {      bracketn=s.indexOf("\"",1);
00100               }
00101               if (bracketn<0)
00102                      throw new ConstructionException("exception.brackets");
00103               if ((n=s.indexOf('(',bracketn))>=0)
00104               {      function=s.substring(0,n).trim();
00105                      if (function.startsWith("\"") && function.endsWith("\"") && function.length()>1)
00106                      {      function=function.substring(1,function.length()-1);
00107                      }
00108                      s=s.substring(n+1).trim();
00109                      if (!s.endsWith(")"))
00110                             throw new ConstructionException("exception.brackets");
00111                      char a[]=s.substring(0,s.length()-1).toCharArray();
00112                      int ia=0;
00113                      int BCount=0;
00114                      while (ia<a.length && NParams<params.length)
00115                      {      int ia0=ia;
00116                             while (ia<a.length && (BCount>0 || a[ia]!=','))
00117                             {      if (a[ia]=='\"')
00118                                    {      ia++;
00119                                           while (ia<a.length && a[ia]!='\"') ia++;
00120                                           if (ia>=a.length)
00121                                                  throw new ConstructionException(
00122                                                         Zirkel.name("exception.quotes"));
00123                                           ia++;
00124                                    }
00125                                    else if (a[ia]=='(')
00126                                    {      BCount++;
00127                                           ia++;
00128                                    }
00129                                    else if (a[ia]==')')
00130                                    {      if (BCount>0) BCount--;
00131                                           else 
00132                                                  throw new ConstructionException(
00133                                                         Zirkel.name("exception.brackets"));
00134                                           ia++;
00135                                    }
00136                                    else ia++;
00137                             }
00138                             params[NParams++]=new String(a,ia0,ia-ia0).trim();
00139                             ia++;
00140                      }
00141               }
00142               else function=s;
00143               String f=function;
00144               
00145               // Interpret special functions:
00146               
00147               if (NParams==3 && ptest(f,"window")) 
00148                      // window size
00149               {      try
00150                      {      double x=new Double(params[0]).doubleValue();
00151                             double y=new Double(params[1]).doubleValue();
00152                             double w=new Double(params[2]).doubleValue();
00153                             C.setXYW(x,y,w);
00154                             zc.recompute();
00155                      }
00156                      catch (Exception e)
00157                      {      throw new ConstructionException(Zirkel.name("exception.value"));
00158                      }
00159                      return;
00160               }
00161               if ((NParams==1 || NParams==2) && ptest(f,"color"))
00162                      // color for object or default color
00163               {      int i=0;
00164                      for (i=0; i<ZirkelFrame.ColorStrings.length; i++)
00165                      {      if (test(params[0],"colors",ZirkelFrame.ColorStrings[i]))
00166                                    break;
00167                      }
00168                      if (i<ZirkelFrame.ColorStrings.length)
00169                      {      if (NParams==2)
00170                             {      ConstructionObject o=C.find(params[1]);
00171                                    if (o==null)
00172                                           throw new ConstructionException(
00173                                                  Zirkel.name("exception.notfound"));
00174                                    o.setColor(i);
00175                             }
00176                             else
00177                             {      C.DefaultColor=i;
00178                             }
00179                      }
00180                      else
00181                             throw new ConstructionException(
00182                                    Zirkel.name("exception.color"));
00183                      return;
00184               }
00185               if ((NParams==1 || NParams==2) && ptest(f,"thickness"))
00186                      // thickness for objects or default thickness
00187               {      int i=0;
00188                      for (i=0; i<ZirkelFrame.ColorTypes.length; i++)
00189                      {      if (test(params[0],"color.type",ZirkelFrame.ColorTypes[i]))
00190                                    break;
00191                      }
00192                      if (i<ZirkelFrame.ColorTypes.length)
00193                      {      if (NParams==2)
00194                             {      ConstructionObject o=C.find(params[1]);
00195                                    if (o==null)
00196                                           throw new ConstructionException(
00197                                                  Zirkel.name("exception.notfound"));
00198                                    o.setColorType(i);
00199                             }
00200                             else
00201                             {      C.DefaultColorType=i;
00202                             }
00203                      }
00204                      else
00205                             throw new ConstructionException(
00206                                    Zirkel.name("exception.colortype"));
00207                      return;
00208               }
00209               if ((NParams==1 || NParams==2) && ptest(f,"type"))
00210                      // point type for point or default point type
00211               {      int i=0;
00212                      for (i=0; i<ZirkelFrame.PointTypes.length; i++)
00213                      {      if (test(params[0],"point.type",ZirkelFrame.PointTypes[i]))
00214                                    break;
00215                      }
00216                      if (i<ZirkelFrame.PointTypes.length)
00217                      {      if (NParams==2)
00218                             {      ConstructionObject o=C.find(params[1]);
00219                                    if (o==null || !(o instanceof PointObject))
00220                                           throw new ConstructionException(
00221                                                  Zirkel.name("exception.notfound"));
00222                                    ((PointObject)o).setType(i);
00223                             }
00224                             else
00225                             {      C.DefaultType=i;
00226                             }
00227                      }
00228                      else
00229                             throw new ConstructionException(
00230                                    Zirkel.name("exception.type"));
00231                      return;
00232               }
00233               if ((NParams==1 || NParams==2) && ptest(f,"partial"))
00234                      // partail view for circle or line or default partial view
00235               {      if (NParams==1 && !truecheck(params[0]))
00236                      {      ConstructionObject o=C.find(params[0]);
00237                             if (o==null)
00238                                    throw new ConstructionException(
00239                                           Zirkel.name("exception.notfound"));
00240                             if (o instanceof PrimitiveCircleObject)
00241                                    ((PrimitiveCircleObject)o).setPartial(true);
00242                             if (o instanceof LineObject)
00243                                    ((LineObject)o).setPartial(true);
00244                             return;
00245                      }
00246                      boolean partial=truetest(params[0]);
00247                      if (NParams==2)
00248                      {      ConstructionObject o=C.find(params[1]);
00249                             if (o==null)
00250                                    throw new ConstructionException(
00251                                           Zirkel.name("exception.notfound"));
00252                             if (o instanceof PrimitiveCircleObject)
00253                                    ((PrimitiveCircleObject)o).setPartial(partial);
00254                             if (o instanceof LineObject)
00255                                    ((LineObject)o).setPartial(partial);
00256                      }
00257                      else
00258                      {      C.Partial=partial;
00259                             C.PartialLines=partial;
00260                      }
00261                      return;
00262               }
00263               if ((NParams==1 || NParams==2) && ptest(f,"hide"))
00264                      // hide object or toggle show hidden state
00265               {      if (NParams==1 && !truecheck(params[0]))
00266                      {      ConstructionObject o=C.find(params[0]);
00267                             if (o==null)
00268                                    throw new ConstructionException(
00269                                           Zirkel.name("exception.notfound"));
00270                             o.setHidden(true);
00271                             return;
00272                      }
00273                      boolean hidden=truetest(params[0]);
00274                      if (NParams==2)
00275                      {      ConstructionObject o=C.find(params[1]);
00276                             if (o==null)
00277                                    throw new ConstructionException(
00278                                           Zirkel.name("exception.notfound"));
00279                             o.setHidden(hidden);
00280                      }
00281                      else
00282                      {      C.Hidden=hidden;
00283                      }
00284                      return;
00285               }
00286               if (NParams==2 && ptest(f,"invisible"))
00287                      // totally invisible for an object
00288               {      if (NParams==1 && !truecheck(params[0]))
00289                      {      ConstructionObject o=C.find(params[0]);
00290                             if (o==null)
00291                                    throw new ConstructionException(
00292                                           Zirkel.name("exception.notfound"));
00293                             o.setSuperHidden(true);
00294                             return;
00295                      }
00296                      boolean hidden=truetest(params[0]);
00297                      if (NParams==2)
00298                      {      ConstructionObject o=C.find(params[1]);
00299                             if (o==null)
00300                                    throw new ConstructionException(
00301                                           Zirkel.name("exception.notfound"));
00302                             o.setSuperHidden(hidden);
00303                      }
00304                      else
00305                             throw new ConstructionException(
00306                                           Zirkel.name("exception.notfound"));
00307                      return;
00308               }
00309               if (NParams>=1 && ptest(f,"back"))
00310                      // push object into background
00311               {      if (NParams==1)
00312                      {      ConstructionObject o=C.find(params[0]);
00313                             if (o==null)
00314                                    throw new ConstructionException(
00315                                           Zirkel.name("exception.notfound"));
00316                             o.setBack(true);
00317                             return;
00318                      }
00319                      boolean back=truetest(params[0]);
00320                      ConstructionObject o=C.find(params[1]);
00321                      if (o==null)
00322                             throw new ConstructionException(
00323                                    Zirkel.name("exception.notfound"));
00324                      o.setBack(back);
00325                      return;
00326               }
00327               if (NParams>=1 && ptest(f,"acute"))
00328                      // set acute state of angle, or set default acute state
00329               {      if (NParams==1 && !truecheck(params[0]))
00330                      {      ConstructionObject o=C.find(params[0]);
00331                             if (o==null)
00332                                    throw new ConstructionException(
00333                                           Zirkel.name("exception.notfound"));
00334                             o.setObtuse(false);
00335                             return;
00336                      }
00337                      boolean acute=truetest(params[0]);
00338                      if (NParams==2)
00339                      {      ConstructionObject o=C.find(params[1]);
00340                             if (o==null)
00341                                    throw new ConstructionException(
00342                                           Zirkel.name("exception.notfound"));
00343                             o.setObtuse(!acute);
00344                      }
00345                      else
00346                      {      C.Obtuse=!acute;
00347                      }
00348                      return;
00349               }
00350               if (NParams>=1 && ptest(f,"obtuse"))
00351                      // revorse of acute
00352               {      if (NParams==1 && !truecheck(params[0]))
00353                      {      ConstructionObject o=C.find(params[0]);
00354                             if (o==null)
00355                                    throw new ConstructionException(
00356                                           Zirkel.name("exception.notfound"));
00357                             o.setObtuse(false);
00358                             return;
00359                      }
00360                      boolean obtuse=truetest(params[0]);
00361                      if (NParams==2)
00362                      {      ConstructionObject o=C.find(params[1]);
00363                             if (o==null)
00364                                    throw new ConstructionException(
00365                                           Zirkel.name("exception.notfound"));
00366                             o.setObtuse(obtuse);
00367                      }
00368                      else
00369                      {      C.Obtuse=obtuse;
00370                      }
00371                      return;
00372               }
00373               if (NParams>=1 && ptest(f,"solid"))
00374                      // set solid state of object, or default solid state
00375               {      if (NParams==1 && !truecheck(params[0]))
00376                      {      ConstructionObject o=C.find(params[0]);
00377                             if (o==null)
00378                                    throw new ConstructionException(
00379                                           Zirkel.name("exception.notfound"));
00380                             o.setSolid(false);
00381                             return;
00382                      }
00383                      boolean solid=truetest(params[0]);
00384                      if (NParams==2)
00385                      {      ConstructionObject o=C.find(params[1]);
00386                             if (o==null)
00387                                    throw new ConstructionException(
00388                                           Zirkel.name("exception.notfound"));
00389                             o.setSolid(solid);
00390                      }
00391                      else
00392                      {      C.Solid=solid;
00393                      }
00394                      return;
00395               }
00396               if (NParams==3 && ptest(f,"restrict"))
00397                      // set range for circle arcs
00398               {      try
00399                      {      PrimitiveCircleObject c=(PrimitiveCircleObject)C.find(params[0]);
00400                             if (!c.setRange(params[1],params[2]))
00401                                    throw new Exception("");
00402                      }
00403                      catch (Exception e)
00404                      {      throw new ConstructionException(
00405                                    Zirkel.name("exception.notfound"));
00406                      }
00407                      return;
00408               }
00409               if (NParams>=1 && ptest(f,"fill"))
00410                      // set fill state for objects: fill(o), fill(t/f,o)
00411               {      if (NParams==1)
00412                      {      ConstructionObject o=C.find(params[0]);
00413                             if (o==null)
00414                                    throw new ConstructionException(
00415                                           Zirkel.name("exception.notfound"));
00416                             o.setFilled(true);
00417                             o.setBack(true);
00418                             return;
00419                      }
00420                      boolean fill=truetest(params[0]);
00421                      ConstructionObject o=C.find(params[1]);
00422                      if (o==null)
00423                             throw new ConstructionException(
00424                                    Zirkel.name("exception.notfound"));
00425                      o.setFilled(fill);
00426                      o.setBack(fill);
00427                      return;
00428               }
00429               if (NParams>=1 && ptest(f,"valid"))
00430                      // set always valid state of intersection
00431               {      if (NParams==1)
00432                      {      ConstructionObject o=C.find(params[0]);
00433                             if (o==null)
00434                                    throw new ConstructionException(
00435                                           Zirkel.name("exception.notfound"));
00436                             if (o instanceof PlumbObject)
00437                             {      ((PlumbObject)o).setRestricted(false);
00438                             }
00439                             else if (o instanceof IntersectionObject)
00440                             {      ((IntersectionObject)o).setRestricted(false);
00441                             }
00442                             return;
00443                      }
00444                      boolean fill=truetest(params[0]);
00445                      ConstructionObject o=C.find(params[1]);
00446                      if (o==null)
00447                             throw new ConstructionException(
00448                                    Zirkel.name("exception.notfound"));
00449                      if (o instanceof PlumbObject)
00450                      {      ((PlumbObject)o).setRestricted(false);
00451                      }
00452                      else if (o instanceof IntersectionObject)
00453                      {      ((IntersectionObject)o).setRestricted(false);
00454                      }
00455                      return;
00456               }
00457               if (NParams>=1 && (ptest(f,"rename") || ptest(f,"name")))
00458                      // works like name
00459               {      if (NParams==1 && !truecheck(params[0]))
00460                      {      ConstructionObject o=C.find(params[0]);
00461                             if (o==null)
00462                                    throw new ConstructionException(
00463                                           Zirkel.name("exception.notfound"));
00464                             o.setShowName(true);
00465                             return;
00466                      }
00467                      ConstructionObject o=C.find(params[0]);
00468                      if (o==null)
00469                      {      boolean shownames=truetest(params[0]);
00470                             if (NParams==2)
00471                             {      o=C.find(params[1]);
00472                                    if (o==null)
00473                                           throw new ConstructionException(
00474                                                  Zirkel.name("exception.notfound"));
00475                                    o.setShowName(truetest(params[0]));
00476                             }
00477                             else
00478                             {      C.ShowNames=shownames;
00479                             }
00480                      }
00481                      else if (!params[1].equals("")) o.setName(params[1]);
00482                      return;
00483               }
00484               if (NParams==2 && ptest(f,"away"))
00485                      // keep interesction away from object
00486               {      ConstructionObject o=C.find(params[0]);
00487                      ConstructionObject p=C.find(params[1]);
00488                      if (!(o instanceof IntersectionObject) ||
00489                             !(p instanceof PointObject))
00490                             throw new ConstructionException(
00491                                    Zirkel.name("exception.parameter"));
00492                      ((IntersectionObject)o).setAway(p.getName());
00493                      return;
00494               }
00495               if (NParams==2 && ptest(f,"close"))
00496                      // keep interesction close to object
00497               {      ConstructionObject o=C.find(params[0]);
00498                      ConstructionObject p=C.find(params[1]);
00499                      if (!(o instanceof IntersectionObject) ||
00500                             !(p instanceof PointObject))
00501                             throw new ConstructionException(
00502                                    Zirkel.name("exception.parameter"));
00503                      ((IntersectionObject)o).setAway(p.getName(),false);
00504                      return;
00505               }
00506               
00507               if (NParams>=1 && ptest(f,"value"))
00508                      // set the size of an object, value of expression, position of point   
00509                      // or toggle value display
00510               {      if (NParams==1 && !truecheck(params[0])) // value(o)
00511                      {      ConstructionObject o=C.find(params[0]);
00512                             if (o==null)
00513                                    throw new ConstructionException(
00514                                           Zirkel.name("exception.notfound"));
00515                             o.setShowValue(true);
00516                             return;
00517                      }
00518                      ConstructionObject o=C.find(params[0]);
00519                      if (o==null) // value(t/f), value(t/f,o)
00520                      {      try
00521                             {      truetest(params[0]);
00522                             }
00523                             catch (Exception e)
00524                             {      throw new ConstructionException(
00525                                           Zirkel.name("exception.notfound"));
00526                             }
00527                             if (NParams==2)
00528                             {      o=C.find(params[1]);
00529                                    if (o==null)
00530                                           throw new ConstructionException(
00531                                                  Zirkel.name("exception.notfound"));
00532                                    o.setShowValue(truetest(params[0]));
00533                             }
00534                             else
00535                             {      C.ShowValues=true;
00536                             }
00537                      }
00538                      else if (NParams==2) // value(o,x)
00539                      { if (o instanceof SegmentObject)
00540                             {      SegmentObject os=(SegmentObject)o;
00541                                    if (!os.canFix())
00542                                           throw new ConstructionException(
00543                                                  Zirkel.name("exception.canfix"));
00544                                    os.setFixed(true,params[1]);
00545                                    os.validate();
00546                             }
00547                             else if (o instanceof CircleObject)
00548                             {      CircleObject os=(CircleObject)o;
00549                                    if (!os.canFix())
00550                                           throw new ConstructionException(
00551                                                  Zirkel.name("exception.canfix"));
00552                                    os.setFixed(true,params[1]);
00553                                    os.validate();
00554                             }
00555                             else if (o instanceof FixedCircleObject)
00556                             {      FixedCircleObject os=(FixedCircleObject)o;
00557                                    os.setFixed(params[1]);
00558                                    os.validate();
00559                             }
00560                             else if (o instanceof AngleObject)
00561                             {      AngleObject os=(AngleObject)o;
00562                                    if (!os.canFix())
00563                                           throw new ConstructionException(
00564                                                  Zirkel.name("exception.canfix"));
00565                                    os.setFixed(params[1]);
00566                                    os.validate();
00567                             }
00568                             else if (o instanceof FixedAngleObject)
00569                             {      FixedAngleObject os=(FixedAngleObject)o;
00570                                    os.setFixed(params[1]);
00571                                    os.validate();
00572                             }
00573                             else if (o instanceof ExpressionObject)
00574                             {      ExpressionObject os=(ExpressionObject)o;
00575                                    os.setFixed(params[1]);
00576                                    os.validate();
00577                             }
00578                             else 
00579                                    throw new ConstructionException(
00580                                           Zirkel.name("exception.parameter"));
00581                      }
00582                      else if (NParams==3) // value(P,x,y)
00583                      {      if (o instanceof PointObject)
00584                             {      PointObject os=(PointObject)o;
00585                                    if (!os.moveablePoint())
00586                                           throw new ConstructionException(
00587                                                  Zirkel.name("exception.canfix"));
00588                                    os.setFixed(params[1],params[2]);
00589                                    os.validate();
00590                             }
00591                             else 
00592                                    throw new ConstructionException(
00593                                           Zirkel.name("exception.parameter"));
00594                      }
00595                      else
00596                             throw new ConstructionException(
00597                                    Zirkel.name("exception.parameter"));
00598                      return;
00599               }
00600               
00601               // Look for the normal construction functions:
00602               int i=findFunction(function,zc);
00603               if (i>=0)
00604               {      for (int j=0; j<NParams; j++)
00605                      {      params[j]=extend(params[j]);
00606                      }
00607                      OCs[i].construct(C,name,params,NParams);
00608                      
00609                      // the following are for macro definition in scripts
00610                      if (Parameter)
00611                      {      if (VN>=V.size())
00612                                    throw new ConstructionException(
00613                                           Zirkel.name("exception.macroparameter"));                             
00614                             ConstructionObject o=C.last();
00615                             o.setMainParameter();
00616                             if (o.isMainParameter())
00617                             {      C.addParameter(o);
00618                                    C.Prompts.addElement(comment);
00619                             }
00620                             else
00621                                    throw new ConstructionException(
00622                                           Zirkel.name("exception.macroparameter"));
00623                      }
00624                      else if (Target)
00625                      {      if (VN+1!=V.size())
00626                                    throw new ConstructionException(
00627                                           Zirkel.name("exception.macrotarget"));
00628                             ConstructionObject o=C.last();
00629                             o.setTarget(true);
00630                             C.addTarget(o);
00631                      }
00632                      else if (Prompt)
00633                      {      ConstructionObject o=C.last();
00634                             C.PromptFor.addElement(o.getName());
00635                      }
00636                      
00637                      return;
00638               }
00639               
00640               // Finally, look for macros:
00641               Macro m=zc.chooseMacro(function);
00642               if (m==null)
00643               {      throw new ConstructionException(Zirkel.name("exception.function"));
00644               }
00645               MR.setMacro(m,zc);
00646               MR.run(zc,C,name,params,NParams);
00647               
00648               // Only for macro definition in scripts
00649               if (Target)
00650               {      ConstructionObject o=C.find(name);
00651                      if (o==null)
00652                             throw new ConstructionException(
00653                                    Zirkel.name("exception.macrotarget"));
00654                      o.setTarget(true);
00655                      C.addTarget(o);
00656               }
00657               else if (Prompt)
00658               {      ConstructionObject o=C.find(name);
00659                      if (o!=null) C.PromptFor.addElement(o.getName());
00660               }
00661               
00662        }
00663        
00664        public void interpret (ZirkelCanvas zc, String s)
00665               throws ConstructionException
00666        {      interpret(zc,s,"");
00667        }
00668        
00669        static public boolean truetest (String s)
00670               throws ConstructionException
00671        {      s=s.toLowerCase();
00672               if (s.equals("true") || s.equals(Zirkel.name("true"))) return true;
00673               if (s.equals("false") || s.equals(Zirkel.name("false"))) return false;
00674               throw new ConstructionException(Zirkel.name("exception.boolean"));
00675        }
00676        
00677        static public boolean truecheck (String s)
00678        {      s=s.toLowerCase();
00679               if (s.equals("true") || s.equals(Zirkel.name("true"))) return true;
00680               if (s.equals("false") || s.equals(Zirkel.name("false"))) return true;
00681               return false;
00682        }
00683        
00684        static public boolean test (String f, String tag, String s)
00685        {      return f.equalsIgnoreCase(Zirkel.name(tag+"."+s,""))
00686                      || f.equals(Zirkel.name(tag+".short."+s,""))
00687                      || f.equals(Zirkel.name(tag+"."+s+".short",""))
00688                      || f.equalsIgnoreCase(s);
00689        }
00690        
00691        static public int startTest (String tag, String s)
00692        {      int i=startTest0(Zirkel.name(tag,tag).toLowerCase(),s.toLowerCase());
00693               if (i>0) return i;
00694               i=startTest0(Zirkel.name(tag+".short",tag),s);
00695               if (i>0) return i;
00696               return startTest0(tag,s.toLowerCase());
00697        }
00698        
00699        static public int startTest0 (String tag, String s)
00700        {      if (s.startsWith(tag+" ")) return tag.length()+1;
00701               return -1;
00702        }
00703        
00704        static public boolean ptest (String f, String s)
00705        {      return test(f,"function",s);
00706        }
00707 
00708        static public boolean nametest (String f, String s)
00709        {      return test(f,"name",s);
00710        }
00711        
00715        public String extend (String s)
00716        {      if (s.startsWith("c(") && s.endsWith(")"))
00717               {      s=s.substring(2,s.length()-1);
00718                      ConstructionObject o=C.find(s);
00719                      if (o instanceof PrimitiveCircleObject)
00720                             return ((PrimitiveCircleObject)o).getP1().getName();
00721               }
00722               else if (s.startsWith("a(") && s.endsWith(")"))
00723               {      s=s.substring(2,s.length()-1);
00724                      ConstructionObject o=C.find(s);
00725                      if (o instanceof TwoPointLineObject)
00726                             return ((TwoPointLineObject)o).getP1().getName();
00727               }
00728               else if (s.startsWith("b(") && s.endsWith(")"))
00729               {      s=s.substring(2,s.length()-1);
00730                      ConstructionObject o=C.find(s);
00731                      if (o instanceof TwoPointLineObject)
00732                             return ((TwoPointLineObject)o).getP2().getName();
00733               }
00734               return s;
00735        }
00736 
00737        MacroRunner MR=new MacroRunner();
00738        
00739        static ObjectConstructor OCs[]=
00740        {      new PointConstructor(),
00741               new SegmentConstructor(),
00742               new LineConstructor(),
00743               new RayConstructor(),
00744               new CircleConstructor(),
00745               new IntersectionConstructor(),
00746               new ParallelConstructor(),
00747               new PlumbConstructor(),
00748               new MidpointConstructor(),
00749               new AngleConstructor(),
00750               new AreaConstructor(),
00751               new QuadricConstructor(),
00752               new ExpressionConstructor(),
00753               new FunctionConstructor()
00754        };
00755        
00756        static public String ONs[]=
00757        {      "point","segment","line","ray","circle","intersection",
00758               "parallel","plumb","midpoint","angle","area","quadric",
00759               "expression","function"
00760        };
00761        
00762        static public int findFunction (String function, ZirkelCanvas zc)
00763        {      for (int i=0; i<OCs.length; i++)
00764               {      if (nametest(function,OCs[i].getTag()) && zc.enabled(ONs[i]))
00765                             return i;
00766               }
00767               return -1;
00768        }
00769 
00770 }