Back to index

wims  3.65+svn20090927
IntersectionObject.java
Go to the documentation of this file.
00001 package rene.zirkel.objects;
00002 
00003 // file: IntersectionObject.java
00004 
00005 import java.util.*;
00006 
00007 import rene.util.xml.*;
00008 import rene.zirkel.*;
00009 import rene.zirkel.construction.*;
00010 import rene.zirkel.expression.*;
00011 
00027 public class IntersectionObject extends PointObject
00028 {      protected ConstructionObject P1,P2;
00029        private static Count N=new Count();
00030        protected Expression Away;
00031        protected boolean StayAway=true;
00032        protected boolean First;
00033        protected boolean Switched;
00034        protected boolean Restricted;
00035        protected boolean Alternate;
00036 
00037        public IntersectionObject (Construction c,
00038               ConstructionObject p1, ConstructionObject p2)
00039        {      super(c,0,0);
00040               Moveable=false;
00041               P1=p1; P2=p2;
00042               updateText();
00043               First=true;
00044               Switched=false;
00045               Restricted=true;
00046               Alternate=false;
00047        }
00048        
00049        public String getTag () { return "Intersection"; }
00050        public int getN () { return N.next(); }
00051        
00052        public void updateText()
00053        {      try
00054               {      setText(text2(Zirkel.name("text.intersection"),P1.getName(),P2.getName()));
00055               }
00056               catch (Exception e) {}
00057        }
00058        
00059        public void setFirst (boolean flag)
00060        {      First=flag;
00061        }
00062        public boolean isFirst ()
00063        {      return First;
00064        }
00065        
00066        public void validate ()
00067        {      if (!P1.valid() || !P2.valid()) Valid=false;
00068               else Valid=true;
00069        }
00070        
00071        public void validate (double x, double y)
00072        {
00073        }
00074        
00075        public void printArgs (XmlWriter xml)
00076        {      xml.printArg("first",P1.getName());
00077               xml.printArg("second",P2.getName());
00078               if (getAway()!=null)
00079               {      if (StayAway) xml.printArg("awayfrom",getAway().getName());
00080                      else xml.printArg("closeto",getAway().getName());
00081               }
00082               printType(xml);
00083               if (!Restricted) xml.printArg("valid","true");
00084               if (Alternate) xml.printArg("alternate","true");
00085        }
00086 
00087        public String away ()
00088        {      if (getAway()!=null) return getAway().getName();
00089               else return "";
00090        }
00091        
00092        public boolean stayAway ()
00093        {      return StayAway;
00094        }
00095 
00096        public boolean setAway (String s, boolean flag)
00097        {      Away=null;
00098               if (s.equals("")) return true;
00099               if (Cn==null) return true;
00100               Away=new Expression("@\""+s+"\"",Cn,this);
00101               StayAway=flag;
00102               return getAway()!=null;
00103        }
00104        
00105        public boolean setAway (String s)
00106        {      return setAway(s,true);
00107        }
00108 
00109        public Enumeration depending ()
00110        {      super.depending();
00111               return depset(P1,P2);
00112        }
00113        
00114        public void translate ()
00115        {      P1=P1.getTranslation();
00116               P2=P2.getTranslation();
00117               if (getAway()!=null) 
00118               {      setAway(getAway().getName(),StayAway);
00119                      Away.translate();
00120               }
00121        }
00122        
00123        public boolean isSwitchable ()
00124        {      return false;
00125        }
00126 
00132        public void autoAway ()
00133        {      if (!autoAway(P1,P2)) autoAway(P2,P1);
00134        }
00135        
00136        boolean autoAway (ConstructionObject o1, ConstructionObject o2)
00137        {      if (o1 instanceof CircleObject)
00138               {      PointObject p1=((CircleObject)o1).getP2();
00139                      if (p1.isHidden()) return false;
00140                      if (p1.dependsOn(o2) && !nearto(p1))
00141                      {      setAway(p1.getName());
00142                             return true;
00143                      }
00144                      else if (o2 instanceof CircleObject)
00145                      {      PointObject p2=((CircleObject)o2).getP2();
00146                             if (p2.isHidden()) return false;
00147                             if (p1==p2 && !nearto(p1))
00148                             {      setAway(p1.getName());
00149                                    return true;
00150                             }
00151                             return false;
00152                      }
00153                      else if (o2 instanceof PrimitiveLineObject)
00154                      {      Enumeration en=((PrimitiveLineObject)o2).points();
00155                             while (en.hasMoreElements())
00156                             {      ConstructionObject oo=(ConstructionObject)en.nextElement();
00157                                    if (oo instanceof PointObject)
00158                                    {      PointObject o=(PointObject)oo;
00159                                           if (o.isHidden()) return false;
00160                                           if (p1==o && !nearto(p1))
00161                                           {      setAway(p1.getName());
00162                                                  return true;
00163                                           }
00164                                    }
00165                             }
00166                      }
00167               }
00168               else if (o1 instanceof TwoPointLineObject)
00169               {      PointObject p1=((TwoPointLineObject)o1).getP1();
00170                      if (!p1.isHidden() && p1.dependsOn(o2) && !nearto(p1))
00171                      {      setAway(p1.getName());
00172                             return true;
00173                      }
00174                      PointObject p2=((TwoPointLineObject)o1).getP2();
00175                      if (!p2.isHidden() && p2.dependsOn(o2) && !nearto(p2))
00176                      {      setAway(p2.getName());
00177                             return true;
00178                      }
00179               }
00180               return false;
00181        }
00182        
00183        public void switchBack ()
00184        {      if (Switched) First=!First;
00185               Switched=false;
00186        }
00187        
00188        public void doSwitch ()
00189        {      Switched=!Switched;
00190               First=!First;
00191        }
00192        
00193        public boolean isSwitched ()
00194        {      return Switched;
00195        }
00196 
00197        public boolean isRestricted ()
00198        {      return Restricted;
00199        }
00200        
00201        public void setRestricted (boolean flag)
00202        {      Restricted=flag;
00203        }
00204 
00205        public PointObject getAway ()
00206        {      return getPointObject(Away);
00207        }
00208 
00209        public void setAlternate (boolean flag)
00210        {      Alternate=flag;
00211        }
00212        public boolean isAlternate ()
00213        {      return Alternate;
00214        }
00215 
00221        public boolean canAlternate ()
00222        {      return false;
00223        }
00224 }