Back to index

wims  3.65+svn20090927
QuadricConstructor.java
Go to the documentation of this file.
00001 package rene.zirkel.constructors;
00002 
00003 // file: QuadricConstructor.java
00004 
00005 import java.awt.event.*;
00006 
00007 import rene.util.xml.*;
00008 import rene.zirkel.*;
00009 import rene.zirkel.construction.*;
00010 import rene.zirkel.objects.*;
00011 
00012 public class QuadricConstructor extends ObjectConstructor
00013 {      PointObject P[];
00014        int NPoints;
00015        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00016        {      if (!zc.Visual) return;
00017               PointObject p=zc.selectCreatePoint(e.getX(),e.getY());
00018               if (p!=null)
00019               {      P[NPoints++]=p;
00020                      p.setSelected(true);
00021                      zc.repaint();
00022               }
00023               showStatus(zc);
00024               if (NPoints==5)
00025               {      QuadricObject Q=new QuadricObject(zc.getConstruction(),P);
00026                      zc.addObject(Q);
00027                      Q.setDefaults();
00028                      zc.clearSelected();
00029                      reset(zc);
00030                      zc.repaint();
00031               }
00032        }
00033 
00034        public void showStatus (ZirkelCanvas zc)
00035        {      zc.showStatus(Zirkel.name("message.quadric")+" "+(NPoints+1));
00036        }
00037        
00038        public void reset (ZirkelCanvas zc)
00039        {      super.reset(zc);
00040               if (zc.Visual)
00041               {      P=new PointObject[5]; NPoints=0;
00042                      showStatus(zc);
00043               }
00044               else
00045               {      zc.setPrompt(Zirkel.name("prompt.quadric"));
00046               }
00047        }
00048 
00049        public boolean construct (XmlTree tree, Construction c)
00050               throws ConstructionException
00051        {      if (!testTree(tree,"Quadric")) return false;
00052               XmlTag tag=tree.getTag();
00053               for (int i=0; i<5; i++)
00054               if (!tag.hasParam("point"+(i+1)))
00055                      throw new ConstructionException("Quadric points missing!");
00056               try
00057               {      PointObject P[]=new PointObject[5];
00058                      for (int i=0; i<5; i++)
00059                             P[i]=(PointObject)c.find(tag.getValue("point"+(i+1))); 
00060                      QuadricObject p=new QuadricObject(c,P);
00061                      setName(tag,p);
00062                      set(tree,p);
00063                      c.add(p);
00064                      setConditionals(tree,c,p);
00065               }
00066               catch (ConstructionException e)
00067               {      throw e;
00068               }
00069               catch (Exception e)
00070               {      throw new ConstructionException("Quadric points illegal!");
00071               }
00072               return true;
00073        }
00074 
00075        public String getPrompt ()
00076        {      return Zirkel.name("prompt.quadric");
00077        }
00078 
00079        public String getTag () { return "Quadric"; }
00080 
00081        public void construct (Construction c, 
00082               String name, String params[], int nparams)
00083               throws ConstructionException
00084        {      if (nparams!=5)
00085                      throw new ConstructionException(Zirkel.name("exception.nparams"));
00086               ConstructionObject P[]=new PointObject[5];
00087               for (int i=0; i<5; i++)
00088               {
00089                      P[i]=c.find(params[i]);
00090                      if (P[i]==null)
00091                             throw new ConstructionException(Zirkel.name("exception.notfound")+" "+
00092                                    params[i]);
00093                      if (!(P[i] instanceof PointObject))
00094                             throw new ConstructionException(Zirkel.name("exception.type")+" "+
00095                                    params[i]);
00096               }
00097               QuadricObject s=new QuadricObject(c,(PointObject[])P);
00098               if (!name.equals("")) s.setNameCheck(name);
00099               c.add(s);
00100               s.setDefaults();
00101        }
00102 
00103 }