Back to index

wims  3.65+svn20090927
RayConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: RayConstructor.java
00004 
00005 import rene.util.xml.XmlTag;
00006 import rene.util.xml.XmlTree;
00007 import rene.zirkel.*;
00008 import rene.zirkel.construction.*;
00009 import rene.zirkel.objects.*;
00010 
00011 public class RayConstructor extends LineConstructor
00012 {      public ConstructionObject create (Construction c, PointObject p1, PointObject p2)
00013        {      return new RayObject(c,p1,p2);
00014        }
00015        public void showStatus (ZirkelCanvas zc)
00016        {      if (P1==null) zc.showStatus(
00017                      Zirkel.name("message.ray.first","Ray: Set the root point!"));
00018               else zc.showStatus(
00019                      Zirkel.name("message.ray.second","Ray: Set the second point!"));
00020        }
00021        public boolean construct (XmlTree tree, Construction c)
00022               throws ConstructionException
00023        {      if (!testTree(tree,"Ray")) return false;
00024               XmlTag tag=tree.getTag();
00025               if (!tag.hasParam("from") || !tag.hasParam("to"))
00026                      throw new ConstructionException("Ray points missing!");
00027               try
00028               {      PointObject p1=(PointObject)c.find(tag.getValue("from")); 
00029                      PointObject p2=(PointObject)c.find(tag.getValue("to"));
00030                      RayObject o=new RayObject(c,p1,p2);
00031                      if (tag.hasParam("partial")) o.setPartial(true);
00032                      setName(tag,o);
00033                      set(tree,o);
00034                      c.add(o);
00035                      setConditionals(tree,c,o);
00036               }
00037               catch (ConstructionException e)
00038               {      throw e;
00039               }
00040               catch (Exception e)
00041               {      e.printStackTrace();
00042                      throw new ConstructionException("Ray points illegal!");
00043               }
00044               return true;
00045        }
00046        
00047        public String getPrompt ()
00048        {      return Zirkel.name("prompt.ray");
00049        }
00050        
00051        public String getTag () { return "Ray"; }
00052        public void construct (Construction c, 
00053               String name, String params[], int nparams)
00054               throws ConstructionException
00055        {      if (nparams!=2)
00056                      throw new ConstructionException(Zirkel.name("exception.nparams"));
00057               ConstructionObject
00058                      P1=c.find(params[0]);
00059               if (P1==null)
00060                      throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00061                             params[0]);
00062               ConstructionObject
00063                      P2=c.find(params[1]);
00064               if (P2==null)
00065                      throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00066                             params[1]);
00067               if (!(P1 instanceof PointObject))
00068                      throw new ConstructionException(Zirkel.name("exception.type")+" "+
00069                             params[0]);
00070               if (!(P2 instanceof PointObject))
00071                      throw new ConstructionException(Zirkel.name("exception.type")+" "+
00072                             params[1]);
00073               RayObject s=new RayObject(c,(PointObject)P1,(PointObject)P2);
00074               c.add(s);
00075               s.setDefaults();
00076               if (!name.equals("")) s.setNameCheck(name);
00077        }
00078 
00079 }