Back to index

wims  3.65+svn20090927
PlumbObject.java
Go to the documentation of this file.
00001 package rene.zirkel.objects;
00002 
00003 // file: PlumbObject.java
00004 
00005 import java.util.Enumeration;
00006 
00007 import rene.util.xml.XmlWriter;
00008 import rene.zirkel.*;
00009 import rene.zirkel.construction.*;
00010 
00011 public class PlumbObject extends PrimitiveLineObject
00012        implements MoveableObject
00013 {      PrimitiveLineObject L;
00014        static Count N=new Count();
00015        protected boolean Restricted=false;
00016        public PlumbObject (Construction c, PrimitiveLineObject l, PointObject p)
00017        {      super(c);
00018               P1=p; L=l;
00019               validate();
00020               updateText();
00021        }
00022        public String getTag () { return "Plumb"; }
00023        public int getN () { return N.next(); }
00024        
00025        public void updateText()
00026        {      setText(text2(Zirkel.name("text.plumb"),P1.getName(),L.getName()));
00027        }
00028        public void validate ()
00029        {      if (!P1.valid() || !L.valid()) Valid=false;
00030               else
00031               {      Valid=true;
00032                      X1=P1.getX(); Y1=P1.getY();
00033                      DX=-L.getDY(); DY=L.getDX();
00034                      if (L instanceof SegmentObject &&
00035                             ((SegmentObject)L).getLength()==0)
00036                      {      Valid=false;
00037                      }
00038                      if (Restricted)
00039                      {      if (!L.contains(X1,Y1)) Valid=false;
00040                      }
00041               }
00042        }
00043        public void printArgs (XmlWriter xml)
00044        {      xml.printArg("point",P1.getName());
00045               xml.printArg("line",L.getName());
00046               if (!Restricted) xml.printArg("valid","true");
00047               super.printArgs(xml);
00048        }      
00049        public boolean isRestricted () { return Restricted; }
00050        public void setRestricted (boolean flag) { Restricted=flag; }
00051        public boolean canRestrict ()
00052        {      return (L instanceof SegmentObject) ||
00053                      (L instanceof RayObject);
00054        }
00055        public void setMainParameter ()
00056        {      MainParameter=true;
00057        }      
00058        public Enumeration depending ()
00059        {      super.depending();
00060               return depset(P1,L);
00061        }
00062        public void translate ()
00063        {      P1=(PointObject)P1.getTranslation();
00064               L=(PrimitiveLineObject)L.getTranslation();
00065        }
00066        public boolean contains (PointObject p)
00067        {      return p==P1;
00068        }
00069        public boolean hasUnit ()
00070        {      return false;
00071        }
00072        public void dragTo (double x, double y) 
00073        {      P1.move(x1+(x-x3),y1+(y-y3));
00074        }
00075 
00076        public void move (double x, double y) 
00077        {
00078        }
00079 
00080        public boolean moveable () 
00081        {      if (P1.moveable()) return true;
00082               return false;
00083        }
00084 
00085        double x1,y1,x2,y2,x3,y3;
00086        
00087        public void startDrag (double x, double y) 
00088        {      x1=P1.getX(); y1=P1.getY();
00089               x3=x; y3=y;
00090        }
00091 
00092        public void snap (ZirkelCanvas zc)
00093        {      if (moveable())
00094               {      P1.snap(zc);
00095               }
00096        }
00097 }