%BROADCASTMESSAGE%
CAAD | ARCH TWiki > Catch0405 > KaisersrotPersistenz > SoftwareVersions > ImplementierungInKaisersrot > LegacySource TWiki webs:
Admin| Aizo | Archinf | BIP | Bgyalex | Brandhub | Catch0405 | Cityscan05 | CommunityMedia | Control | Curtain | Easa005 | Easydb | Education | Extern | Extern0405 | Freudenhaus | Fund | Game0405 | Game05 | Gamearch | Luise | MAS0506 | MAS0506stu | Mas0506 | Mas0506stu | Maschinen0405 | Menz | Mill | Mill0405 | NDS | NDS0405 | NDS0405stu | Plugins | Qwipp | RZM | Replay | Replay0405 | Research | Second | Trash | Udintern | Urbandesign |
Catch0405 . { Changes | Index | Search | Go }
Kommentar:

Die relevante Procedur heisst: loadNInfos - hier werden die Daten ab der Exceldatei superMix gelesen.

/*
 * Created on Dec 24, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author t100671
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

import java.awt.*;
import java.io.*;
import BAppApp.*;
import XMLParser.*;

public class ModSwarmConstructor extends SConstructor {
  int numPoints=0;
  int myDisplay=0;
  double fieldAttraction=0;
  double neighbourAttraction=0;
  double radAttraction=5;
  double borderAttraction=1;
  double lineAttraction=0;
  double minSiteSize=0,maxSiteSize=0;
  double sizeScale=1.0;
  double sizePower=1.4;
  double anglePower=2.4;
  boolean realSize=true;
  int nWasser=0,nWald=0,nMarkt=0;
  SSwarm mySwarm=null;
  SGroup myPolys=null;
  SGroup outAreas=null;
  SGroup inAreas=null;
  SPoint myBar=null;
  SPoint myChurch=null;
  EList myInfos=new EList();
  OList myBorderKeepers=new OList();
  OList myEdgeKeepers=new OList();
  SizeNColorInfo scInfo[][][]=new SizeNColorInfo[7][4][4];
  boolean allAverage=false;
   // neue Info
  SizeNColorInfo scNInfo[]=new SizeNColorInfo[100];
  Icon houseIcon=null,churchIcon=null,barIcon=null;
  

   public String getType(){
      return ("swarm");
   }

  public ModSwarmConstructor(SObject ob) {
    myType="mswarm";
    setSObject(ob);
    setIcon("multiarea");
    
    // testen,ob untergruppen vorhanden
    
    SGroup myGroup=(SGroup) mySObject;
    houseIcon=mySObject.getRoot().getStuff().getIcon("house");
    barIcon=mySObject.getRoot().getStuff().getIcon("bar");
    churchIcon=mySObject.getRoot().getStuff().getIcon("church");
    // untergruppen neu
    if(myGroup.getFirstSystem()==null){
       System.out.println("swarmconstructing");
       mySwarm=new SSwarm((SGroup)mySObject);
       SModObject mso=new SModObject(mySwarm);
       mso.setName("punktschwarm");
       mySwarm.addModifier(mso);
       outAreas=new SGroup((SGroup)mySObject);
       SModGroup msg=new SModGroup(outAreas);
       msg.setName("outer area");
       outAreas.addModifier(msg);
       myPolys=new SGroup((SGroup)mySObject);
       msg=new SModGroup(myPolys);
       msg.setName("grundstuecke");
       myPolys.addModifier(msg);
       ModStreetController mss=new ModStreetController(myPolys);
       myPolys.addModifier(mss);
       inAreas=new SGroup((SGroup)mySObject);
       msg=new SModGroup(inAreas);
       msg.setName("inner area");
       inAreas.addModifier(msg);
    }
    // untergruppen schon da
    else{
       System.out.println("swarmreconstructing");
       SObject cSystem=myGroup.getFirstSystem();
       while (cSystem!=null){
          SModGroup modG=(SModGroup)cSystem.getModifier("group");
          if(modG!=null){
             if(modG.getName().equals("outer area")) 
                outAreas=(SGroup) cSystem;
             if(modG.getName().equals("grundstuecke")) 
                myPolys=(SGroup) cSystem;
             if(modG.getName().equals("inner area")) 
                inAreas=(SGroup) cSystem;
          }
          SModObject modO=(SModObject)cSystem.getModifier("object");
          if(modO!=null)
             if(modO.getName().equals("punktschwarm"))
                mySwarm=(SSwarm) cSystem;
          cSystem=(SObject)cSystem.next();
       }
    }
    // *  *  *  tabelle importieren  *  *  *
      importSCInfo();
  }

public SModifier getCopy(SObject ob){
    ModSwarmConstructor mCopy=new ModSwarmConstructor(ob);
    mCopy.setNumPoints(getNumPoints());
    mCopy.setInfos(myInfos);
    return mCopy;
  }
  
  public void generateFromXML(XMLElement myXML){
     numPoints=0;
     System.out.println(myPolys.getFirstSystem());
     XMLElement siteXML=myXML.getFirstChild("siteInfo");
     while (siteXML!=null){
        SiteInfo cInfo=new SiteInfo();
        numPoints++;
        cInfo.generateFromXML(siteXML);
        myInfos.addToLast(cInfo);
        if(mySwarm!=null)
           if(mySwarm.getFirstPoint()!=null){
              int pointIndex=siteXML.getAttributeIntValue("pointIndex");
              SPoint 
point=mySObject.getRoot().getKeeper(pointIndex).getFirstPoint();
              point.setInfo(cInfo);
              cInfo.setPoint(point);
           }
        if(myPolys!=null)
           if(myPolys.getFirstSystem()!=null){
              int polyIndex=siteXML.getAttributeIntValue("polyIndex");
              SPoly poly=(SPoly)myPolys.getObjectByIndex(polyIndex);
              System.out.println("setting polyInfo No."+polyIndex);
              poly.setInfo(cInfo);
              cInfo.setPoly(poly);
           }
        siteXML=siteXML.getNextSiblingOfType();
     }
     infoChangePoints();
     infoChangePolys();
     setBorderKeepers();
  }
  
  public void addXML(XMLElement parentXML){
     XMLElement myXML=new XMLElement("mod");
     myXML.addAttribute("type","swarmconstructor");
     // infos ins XML
     SiteInfo cInfo=(SiteInfo) myInfos.next();
     while (cInfo!=null){
        myXML.addChild(cInfo.getXML());
        cInfo=(SiteInfo)cInfo.next();
        System.out.println("info added");
     }
     parentXML.addChild(myXML);
  }

  public void setNumPoints(int n) {
    numPoints=n;
  }
  
  public void setInfos(EList inf){
     myInfos=inf;
  }
  
  public void setSwarm(SSwarm s){
     mySwarm=s;
  }

  public int getNumPoints(){
    return numPoints;
  }
  
  public String getDragMode(){
     return("rect");
  }  
  
  public void getData(SInput input){
     if(input.getType().equals("Points")){
        input.setData(numPoints);
     }
     if(input.getType().equals("attract Fields")){
        input.setData(fieldAttraction);
     }
     if(input.getType().equals("attract Neighbours")){
        input.setData(neighbourAttraction);
     }
     if(input.getType().equals("attract Lines")){
        input.setData(lineAttraction);
     }
     if(input.getType().equals("radial power")){
        input.setData(radAttraction);
     }
     if(input.getType().equals("attract Border")){
        input.setData(borderAttraction);
     }
     if(input.getType().equals("sizePower")){
        input.setData(sizePower);
     }
     if(input.getType().equals("anglePower")){
        input.setData(anglePower);
     }
     if(input.getType().equals("minSiteSize")){
        input.setData((int)minSiteSize);
     }
     if(input.getType().equals("maxSiteSize")){
        input.setData((int)maxSiteSize);
     }
     if(input.getType().equals("areaSize")){
        input.setData((int)getAreaSize());
     }
  }
  
  public void setData(SInput input){
     if(input.getType().equals("Points")){
        numPoints=input.getIntData();
     }
     if(input.getType().equals("load excel")){
        System.out.println("xel");
        //loadInfos();
        loadNInfos();
     }
     if(input.getType().equals("load old excel")){
        System.out.println("xel");
        loadInfos();
     }
     if(input.getType().equals("create polys")){
        setupConvex(0);
        setupLines();
     }
     if(input.getType().equals("create points")){
        polysToPoints();
     }
     if(input.getType().equals("real size")){
        //if(allAverage) allAverage=false;
        //else allAverage=true;
        //averageSize();
        System.out.println("fff");
        input.setType("full size");
        realSize=!realSize;
        changeSizeScale();
     }
     else if(input.getType().equals("full size")){
        System.out.println("rrr");
        input.setType("real size");
        realSize=!realSize;
        changeSizeScale();
     }
     else if(input.getType().equals("sizePower")){
        sizePower=input.getDoubleData();
        updateSizePower();
     }
     else if(input.getType().equals("anglePower")){
        anglePower=input.getDoubleData();
        updateAnglePower();
     }
     if(input.getType().equals("poly edges")){
        //setupPolyEdges3();
        setupBorderNStreetLines();
        setupPolyEdges4();
     }
     if(input.getType().equals("attract Fields")){
        fieldAttraction=input.getDoubleData();
     }
     if(input.getType().equals("attract Neighbours")){
        neighbourAttraction=input.getDoubleData();
     }
     if(input.getType().equals("attract Lines")){
        lineAttraction=input.getDoubleData();
     }
     if(input.getType().equals("attract Border")){
        borderAttraction=input.getDoubleData();
     }
     if(input.getType().equals("radial power")){
        radAttraction=input.getDoubleData();
     }
     if(input.getType().equals("display")){
        if(myDisplay==1) myDisplay=0;
        else myDisplay=1;
        if(myDisplay==0) infoChangePoints();
     }
  }
  
  public void sendFields(OffCanvas o){
     o.iFieldPointerRight();
      InputText pointsInput=new InputText(this,"Points");
    pointsInput.setDX(100,50);
    o.addSInputNextLine(pointsInput);
    OutputText minSizeOut=new OutputText(this,"minSiteSize");
    minSizeOut.setDX(100,50);
    o.addSInputNextLine(minSizeOut);
    OutputText maxSizeOut=new OutputText(this,"maxSiteSize");
    maxSizeOut.setDX(100,50);
    o.addSInputNextLine(maxSizeOut);
    OutputText areaSizeOut=new OutputText(this,"areaSize");
    areaSizeOut.setDX(100,50);
    o.addSInputNextLine(areaSizeOut);
    InputButton loadButton=new InputButton(this,"load excel");
    loadButton.setDX(100,50);
    loadButton.setSymbol(new PointSymbol(12));
    o.addSInputNextLine(loadButton);
    InputButton loadoButton=new InputButton(this,"load old excel");
    loadoButton.setDX(100,50);
    loadoButton.setSymbol(new PointSymbol(12));
    o.addSInputNextLine(loadoButton);
    InputText attractInput=new InputText(this,"attract Fields");
    attractInput.setDX(100,50);
    o.addSInputNextLine(attractInput);
    InputText attractNInput=new InputText(this,"attract Neighbours");
    attractNInput.setDX(100,50);
    o.addSInputNextLine(attractNInput);
    /*
    InputText attractLInput=new InputText(this,"attract Lines");
    attractLInput.setDX(100,50);
    o.addSInputNextLine(attractLInput);
    */
    InputText radInput=new InputText(this,"radial power");
    radInput.setDX(100,50);
    o.addSInputNextLine(radInput);
    /*
    InputText borderInput=new InputText(this,"attract Border");
    borderInput.setDX(100,50);
    o.addSInputNextLine(borderInput);
    */
    InputText spInput=new InputText(this,"sizePower");
    spInput.setDX(100,50);
    o.addSInputNextLine(spInput);
    InputText angInput=new InputText(this,"anglePower");
    angInput.setDX(100,50);
    o.addSInputNextLine(angInput);
    InputButton polyButton=new InputButton(this,"create polys");
    polyButton.setDX(100,50);
    polyButton.setSymbol(new PointSymbol(12));
    o.addSInputNextLine(polyButton);
    InputButton pointButton=new InputButton(this,"create points");
    pointButton.setDX(100,50);
    pointButton.setSymbol(new PointSymbol(12));
    o.addSInputNextLine(pointButton);
    /*
    InputButton disButton=new InputButton(this,"display");
    disButton.setDX(100,50);
    disButton.setSymbol(new PointSymbol(12));
    o.addSInputNextLine(disButton);
    */
    InputButton avButton;
    if(realSize) avButton=new InputButton(this,"real size");
    else  avButton=new InputButton(this,"full size");
    avButton.setDX(100,50);
    avButton.setSymbol(new PointSymbol(12));
    o.addSInputNextLine(avButton);
    o.iFieldPointerLeft();
  }
  
  public SObject construct(SLineObject swarm,OffCanvas o,OList 
keepers){
      SPoint cPoint,pPoint=null;
      SPointKeeper cKeeper;
      int counter=0;
      
      SPointKeeper firstKeeper=(SPointKeeper)keepers.getObject();
      SiteInfo info=(SiteInfo) myInfos.next();
      
      while(keepers!=null){
         System.out.println(counter);
         cPoint=new SPoint();
         cPoint.setInfo(info);
         info.setPoint(cPoint);
         counter++;
         //cPoint.setPFlag(SPoint.P_ONEDGE);
         if(pPoint==null){
            cPoint.closeLine();
            cPoint.closeKeeper();
            cPoint.setLineObject(swarm);
            swarm.setFirstPoint(cPoint);
         }else{
            pPoint.insertInLine(cPoint);
         }
         cKeeper=(SPointKeeper)keepers.getObject();
         cKeeper.addPoint(cPoint);
         cKeeper.setRep(o);
         
         pPoint=cPoint;
         info=(SiteInfo)info.next();
         keepers=(OList)keepers.next();
      }
      
      swarm.setRep(o);
      for(int i=0; i<(counter); i++) mySwarm.setup();
      
      infoChangePoints();
      return swarm;
   }
   
   public void infoChangePoints(){
      if(mySwarm==null) return;
      if(mySwarm.getFirstPoint()==null) return;
      System.out.println("changing points");
      SPoint fp=mySwarm.getFirstPoint();
      SPoint cp=fp;
      do{
         if(cp.getInfo()!=null){
            SiteInfo pInfo=(SiteInfo) cp.getInfo();
            SRepPoint pRep=(SRepPoint)cp.getKeeper().getRep();
            if(pRep!=null){
               if(pInfo.name.equals("bar")){
                  pRep.setSymbol(barIcon);
                  myBar=cp;
               }
               else if(pInfo.name.equals("church")){
                  pRep.setSymbol(churchIcon);
                  myChurch=cp;
               }
               else if(pInfo.name.equals("default")){
                  pRep.setSymbol(houseIcon);
                  pInfo.r=230;
                  pInfo.g=230;
                  pInfo.b=200;
               }
               else
                  pRep.setSymbol(houseIcon);
               pRep.setColor(new Color(pInfo.r,pInfo.g,pInfo.b));
            }
            cp.set1Value(Math.sqrt(pInfo.minSize/Math.PI));
            cp.set2Value(Math.sqrt(pInfo.maxSize/Math.PI));
            cp.setLValue(pInfo.typGruppe);
            if(pInfo.typGruppe>=10) cp.resetIValue(6);
         }
         cp=cp.nextInLine;
      }while (cp!=fp);
      SiteInfo cInfo=(SiteInfo)myInfos.next();
       while (cInfo!=null){
          SiteInfo nInfo=(SiteInfo)myInfos.next();
          while (nInfo!=null){
             if(cInfo.nachbarName.equals(nInfo.name)){
                cInfo.setNeighbour(nInfo.myPoint);
                System.out.println(nInfo.name);
             }
             nInfo=(SiteInfo)nInfo.next();
          }
          cInfo=(SiteInfo)cInfo.next();
       }
   }
   
   public void infoChangePolys(){
      if(myPolys==null) return;
      SPoly cPoly=(SPoly) myPolys.getFirstSystem();
      while (cPoly!=null){
         if(cPoly.getInfo()!=null){
            SiteInfo pInfo=(SiteInfo) cPoly.getInfo();
            cPoly.setColor(new Color(pInfo.r,pInfo.g,pInfo.b));
            SRepPoly pRep=(SRepPoly)cPoly.getRep();
            if(pRep!=null){
               if(pInfo.name.equals("bar"))
                  pRep.setSymbol(barIcon);
               else if(pInfo.name.equals("church"))
                  pRep.setSymbol(churchIcon);
               else
                  pRep.setSymbol(houseIcon);
            }
              SModObject msg=(SModObject)cPoly.getModifier("object");
              msg.setName(pInfo.name);
              ModSizeController 
msc=(ModSizeController)cPoly.getModifier("size");
              msc.setMinSize(pInfo.minSize);
              msc.setMaxSize(pInfo.maxSize);
         }
         cPoly=(SPoly)cPoly.next();
      }
   }
   
   public void polysToPoints(){
      if(myPolys==null) return;
      if(myPolys.getFirstSystem()==null) return;
      SPoint cPoint=null,pPoint=null;
      SPointKeeper cKeeper=null;
      OffCanvas o=mySObject.getRoot().getStuff().getPanel("bau");
      
      mySwarm=new SSwarm((SGroup)mySObject);
       SModGroup msg=new SModGroup(mySwarm);
       msg.setName("punktschwarm");
       mySwarm.addModifier(msg);
      
      SPoly cPoly=(SPoly) myPolys.getFirstSystem();
      while (cPoly!=null){
         if(cPoly.getInfo()!=null){
            Point2D pCenter=cPoly.getCenter();
            cKeeper=new 
SPointKeeper(pCenter.xd,pCenter.yd,mySObject.getRoot());
            SiteInfo cInfo=(SiteInfo) cPoly.getInfo();
            cPoint=new SPoint();
            cPoint.setInfo(cInfo);
            cInfo.setPoint(cPoint);
            if(pPoint==null){
               cPoint.closeLine();
               cPoint.closeKeeper();
               cPoint.setLineObject(mySwarm);
               mySwarm.setFirstPoint(cPoint);
            }else{
               pPoint.insertInLine(cPoint);
            }
            cKeeper.addPoint(cPoint);
            cKeeper.setRep(o);
            pPoint=cPoint;
         }
         cPoly=(SPoly)cPoly.next();
      }
      mySwarm.setRep(o);
      myPolys.deleteSub();
      infoChangePoints();
   }
   
   public SPoint getNearestPoint(Point2D pos){
      if(myPolys==null) return null;
      if(myPolys.getFirstSystem()==null) return null;
      SPoint cPoint=null,nearest=null;
      SPointKeeper cKeeper=null;
      double minDist=100000000;
      
      SPoly cPoly=(SPoly) myPolys.getFirstSystem();
      while (cPoly!=null){
         cPoint=cPoly.getNearestPoint(pos);
         if(cPoint!=null){
            
            Point2D cPos=cPoint.getKeeper().getPosition();
             double 
dist=Math.sqrt(((cPos.xd-pos.xd)*(cPos.xd-pos.xd))+((cPos.yd-pos.yd)*(cPos.yd-pos.yd)));
            if(dist<minDist){
               nearest=cPoint;
               minDist=dist;
            }
         }
         cPoly=(SPoly)cPoly.next();
      }
      return nearest;
   }
   
   public SObject construct(OffCanvas o,Point2D pA,Point2D pB){
   System.out.println("construct start");
     if(numPoints==0) return null;
     System.out.println("construct continue");
     addWaterNGreen();
     pA=o.getRealPosition(pA);
     pB=o.getRealPosition(pB);
      double xL,xR,yO,yU;
      SGroup myGroup=(SGroup) mySObject;
      OList keepers=new OList();
      SPointKeeper pKeeper;
      
      if(pA.xd<pB.xd){xL=pA.xd;xR=pB.xd;}
      else{xL=pB.xd;xR=pA.xd;}
      if(pA.yd<pB.yd){yO=pA.yd;yU=pB.yd;}
      else{yO=pB.yd;yU=pA.yd;}
   
      for(int i=0; i<numPoints; i++){
         pKeeper=new 
SPointKeeper(xL+(Math.random()*(xR-xL)),yO+(Math.random()*(yU-yO)),myGroup.getRoot());
         if(i==0) keepers.setObject(pKeeper);
         else keepers.addObjectToLast(pKeeper);
      }
      
      if (mySwarm==null) mySwarm=new SSwarm(myGroup);
      construct(mySwarm,o,keepers);   
      return myGroup;
   }
   
    public void loadNInfos(){
     // neues InfoFile:
     String 
myFile=mySObject.getRoot().getStuff().getFrame().loadFile("load CSV-File");
     
     boolean fEnd=false;
     int index=0;
    try{
      DataInputStream dataInput = new DataInputStream(new 
FileInputStream(myFile));
      
      CSVParser myCSV=new CSVParser();
      myCSV.setInput(dataInput);
      myCSV.buildTags();
      boolean eof=myCSV.read();
      nMarkt=1;
      nWald=1;
      nWasser=1;
      index=0;
      while(eof==false){
         if(myCSV.tag.equals("Haustyp")) {
            index++;
            scNInfo[index]=new SizeNColorInfo();
            scNInfo[index].hausTyp=myCSV.getStringData();
         }
         if(myCSV.tag.equals("Anzahl")) 
scNInfo[index].number=myCSV.getIntData();
         if(myCSV.tag.equals("Nname")) 
scNInfo[index].nachbar=myCSV.getStringData();
         if(myCSV.tag.equals("Breite")) 
scNInfo[index].width=myCSV.getDoubleData();
         if(myCSV.tag.equals("Tiefe"))  
scNInfo[index].length=myCSV.getDoubleData();
         if(myCSV.tag.equals("strasse"))  
scNInfo[index].strasse=myCSV.getIntData();
         if(myCSV.tag.equals("gruen"))  {
            scNInfo[index].gruen=myCSV.getIntData();
         }
         if(myCSV.tag.equals("wasser")) 
         {
            scNInfo[index].wasser=myCSV.getIntData();
         }
         if(myCSV.tag.equals("Fläche"))  {
            scNInfo[index].minSize=myCSV.getDoubleData()*1.0;
            scNInfo[index].maxSize=myCSV.getDoubleData()*1.0;
         }
         if(myCSV.tag.equals("minN")) 
scNInfo[index].minN=myCSV.getIntData();
         if(myCSV.tag.equals("maxN")) 
scNInfo[index].maxN=myCSV.getIntData();
         if(myCSV.tag.equals("r")) scNInfo[index].r=myCSV.getIntData();
         if(myCSV.tag.equals("g")) scNInfo[index].g=myCSV.getIntData();
         if(myCSV.tag.equals("b")) scNInfo[index].b=myCSV.getIntData();
         if(myCSV.tag.equals("PPIndex")) 
scNInfo[index].ppIndex=myCSV.getIntData();
         if(myCSV.tag.equals("Push")) 
scNInfo[index].push=myCSV.getIntData();
         if(myCSV.tag.equals("Pull")) 
scNInfo[index].pull=myCSV.getIntData();
         System.out.println(myCSV.tag+":"+myCSV.getStringData()+" 
"+myCSV.getIntData());
         eof=myCSV.read();
      }
      dataInput.close();
    }
    catch (IOException ex){
      ex.printStackTrace();
    }
    
    SiteInfo info=new SiteInfo();
    SiteInfo pInfo;
    nMarkt=0;
    nWald=0;
    nWasser=0;
    numPoints=0;
    int neighbourCounter=0;
    for (int iType=1; iType<=index; iType++){
       neighbourCounter=0;
       for (int iNum=0; iNum<scNInfo[iType].number; iNum++){
          numPoints++;
         info=new SiteInfo();
         myInfos.addToLast(info);
         info.name=scNInfo[iType].hausTyp;//+" "+iType+" "+iNum;
         info.typGruppe=1;
         info.hausTyp=1;
         info.size=1;
         info.accessoires=0;
         info.posVH=0;
         info.posLR=0;
         info.gartenTyp=0;
         info.myAttractor[0]=0;
         info.myAttractor[1]=scNInfo[iType].strasse;
         info.myAttractor[2]=0;
         info.myAttractor[3]=scNInfo[iType].wasser;
         info.myAttractor[4]=scNInfo[iType].gruen;
         info.myAttractor[5]=0;
         info.nachbarName=scNInfo[iType].nachbar;
         info.ppIndex=scNInfo[iType].ppIndex;
         info.push=scNInfo[iType].push;
         info.pull=scNInfo[iType].pull;
         if(neighbourCounter>1){
            info.myAttractor[0]=3;
            pInfo=(SiteInfo)info.previous();
            info.nachbarName=pInfo.name;
            
         }
         info.maxSize=scNInfo[iType].maxSize;
         maxSiteSize+=info.maxSize;
         info.minSize=scNInfo[iType].minSize;
           minSiteSize+=info.minSize;
         info.r=scNInfo[iType].r;
         info.g=scNInfo[iType].g;
         info.b=scNInfo[iType].b;
         neighbourCounter++;
         if(neighbourCounter>scNInfo[iType].minN){
            if(neighbourCounter>scNInfo[iType].maxN){
                neighbourCounter=0;
            }
         }
         System.out.println(numPoints+" "+iType+" "+iNum+" "+info.name+" 
"+info.nachbarName);
       }
    }
    
  }
   public void addWaterNGreen(){
      /*
      if((nWasser==0)&(nWald==0)){
         nWasser=1;
         nWald=1;
      }
      
      double minWald=1400;
      double minWasser=1600;
      double minOverArea=getAreaSize()-maxSiteSize;
      if(minOverArea<=0) minOverArea=minWald;
      double maxOverArea=getAreaSize()-minSiteSize;
      if(maxOverArea<minOverArea) maxOverArea=minOverArea;
      double fWald=1.0*(double)nWald/((double)(nWasser+nWald));
      //System.out.println("fWald"+fWald);
      double fWasser=1.0*(double)nWasser/((double)(nWasser+nWald));
      int nWald=(int)(minOverArea*fWald/minWald)+1;
      int nWasser=(int)(minOverArea*fWasser/minWald)+1;
      double maxWald=minWald*maxOverArea/minOverArea;
      if(maxWald<minWald) maxWald=minWald;
      double maxWasser=minWasser*maxOverArea/minOverArea;
      if(maxWasser<minWasser) maxWasser=minWasser;
      
      //nWald=1;
      //nWasser=1;
      
      for(int i=0; i<nWald; i++){
         SiteInfo sInfo=new SiteInfo();
         sInfo.minSize=minWald;
         sInfo.maxSize=maxWald;
         sInfo.typGruppe=14;
         sInfo.r=0;
         sInfo.g=255;
         sInfo.b=0;
         sInfo.name=("wald");
         sInfo.myAttractor[4]=3;
         sInfo.myAttractor[3]=0;
         myInfos.addToLast(sInfo);
         numPoints++;
      }
      for(int i=0; i<nWasser; i++){
         SiteInfo sInfo=new SiteInfo();
         sInfo.minSize=minWasser;
         sInfo.maxSize=maxWasser;
         sInfo.typGruppe=13;
         sInfo.r=0;
         sInfo.g=0;
         sInfo.b=255;
         sInfo.name=("wasser");
         sInfo.myAttractor[3]=3;
         sInfo.myAttractor[4]=0;
         myInfos.addToLast(sInfo);
         numPoints++;
      }
      for(int i=0; i<2; i++){
         SiteInfo sInfo=new SiteInfo();
         sInfo.minSize=1000;
         sInfo.maxSize=1600;
         sInfo.typGruppe=15;
         sInfo.r=255;
         sInfo.g=230;
         sInfo.b=230;
         sInfo.name=("markt");
         myInfos.addToLast(sInfo);
         numPoints++;
      }
      */
   }
   
   public SObject construct(OffCanvas o,SObject obj){
      return null;
   }
   
   public boolean isConstructed(){
      if(mySwarm==null)return false;
      if(mySwarm.getFirstPoint()==null) return false;
      return true;
   }

   public double getAreaSize(){
      double size=0;
      if(outAreas==null)return 0;
      SLineObject cPoly=(SLineObject)outAreas.getFirstSystem();
      while (cPoly!=null){
         size+=cPoly.getArea();
         cPoly=(SLineObject)cPoly.next();
      }
      return size;
   }

  public void loadInfos(){
     String 
myFile=mySObject.getRoot().getStuff().getFrame().loadFile("load CSV-File");
     //PrintWriter stdout=new PrintWriter(System.out, true);
     boolean fEnd=false;
     int counter=0;
    try{
      DataInputStream dataInput = new DataInputStream(new 
FileInputStream(myFile));
      CSVParser myCSV=new CSVParser();
      myCSV.setInput(dataInput);
      myCSV.buildTags();
      SiteInfo info=new SiteInfo();
      boolean eof=myCSV.read();
      nMarkt=0;
      nWald=0;
      nWasser=0;
      while(eof==false){
         if(myCSV.tag.equals("Name")){
            info=new SiteInfo();
            myInfos.addToLast(info);
            info.name=myCSV.getStringData();
            counter++;
         }
         if(myCSV.tag.equals("TypGruppe")) 
info.typGruppe=myCSV.getIntData();
         if(myCSV.tag.equals("HausTyp")) info.hausTyp=myCSV.getIntData();
         if(myCSV.tag.equals("Accessoires")) 
info.accessoires=myCSV.getIntData();
         if(myCSV.tag.equals("PosVH")) info.posVH=myCSV.getIntData();
         if(myCSV.tag.equals("PosLR")) info.posLR=myCSV.getIntData();
         if(myCSV.tag.equals("GartenTyp")) 
info.gartenTyp=myCSV.getIntData();
         if(myCSV.tag.equals("NStrasse")) 
info.myAttractor[1]=myCSV.getIntData();
         if(myCSV.tag.equals("NBus")) 
info.myAttractor[2]=myCSV.getIntData();
         if(myCSV.tag.equals("NWasser")) {
            info.myAttractor[3]=myCSV.getIntData();
            nWasser+=myCSV.getIntData();
         }
         if(myCSV.tag.equals("NWald")) {
            info.myAttractor[4]=myCSV.getIntData();
            nWald+=myCSV.getIntData();
         }
         if(myCSV.tag.equals("NMarkt")) {
            info.myAttractor[5]=myCSV.getIntData();
            nMarkt+=myCSV.getIntData();
         }
         if(myCSV.tag.equals("NNachbar")) 
info.myAttractor[0]=myCSV.getIntData();
         if(myCSV.tag.equals("NachbarName")) 
info.nachbarName=myCSV.getStringData();
         if(myCSV.tag.equals("Size")) info.size=myCSV.getIntData();
         eof=myCSV.read();
      }
      dataInput.close();
    }
    catch (IOException ex){
      ex.printStackTrace();
    }
    numPoints=counter;
    putSCToInfos();
    doubleHousing();
  }
  
  public void putSCToInfos(){
     SiteInfo info=(SiteInfo)myInfos.next();
     minSiteSize=0;
     maxSiteSize=0;
     while (info!=null){
      
info.maxSize=scInfo[info.typGruppe][info.hausTyp][info.size].maxSize;
      maxSiteSize+=info.maxSize;
      
info.minSize=(scInfo[info.typGruppe][info.hausTyp][info.size].minSize+info.maxSize)/2.0;
        minSiteSize+=info.minSize;
      info.r=scInfo[info.typGruppe][info.hausTyp][info.size].r;
      info.g=scInfo[info.typGruppe][info.hausTyp][info.size].g;
      info.b=scInfo[info.typGruppe][info.hausTyp][info.size].b;
      info=(SiteInfo)info.next();
     }
  }
  
  public void doubleHousing(){
     SiteInfo info=(SiteInfo)myInfos.next();
     while (info!=null){
        if(info.typGruppe==2){
           String nd="",n1="",n2="";
           SiteInfo nInfo=(SiteInfo) info.next();
           SiteInfo bInfo=null,superBInfo=null;
           while(nInfo!=null){
              if(nInfo.typGruppe==2)
                 if(nInfo.hausTyp==info.hausTyp){
                    bInfo=nInfo;
                    if(nInfo.name.equals(info.nachbarName))
                       superBInfo=nInfo;
                    if(nInfo.nachbarName.equals(info.name))
                       superBInfo=nInfo;
                 }
              nInfo=(SiteInfo)nInfo.next();
           }
           if(superBInfo!=null) bInfo=superBInfo;
           if(bInfo==null){
              n1=info.name;
              n2="buerger";
              info.name=info.name+" + buerger";
              nd=info.name;
              info.minSize=info.minSize*2.0;
              info.maxSize=info.maxSize*2.0;
           }else{
              n1=info.name;
              n2=bInfo.name;
              info.name=(info.name+" + "+bInfo.name);
              nd=info.name;
              info.minSize=info.minSize+bInfo.minSize;
              info.maxSize=info.maxSize+bInfo.maxSize;
              for(int i=0;i<6;i++){
                 if(info.myAttractor[i]<bInfo.myAttractor[i])
                    info.myAttractor[i]=bInfo.myAttractor[i];
              }
              bInfo.remove();
              numPoints--;
           }
           SiteInfo tInfo=(SiteInfo)myInfos.next();
           while (tInfo!=null){
              if((tInfo.nachbarName.equals(n1))|(tInfo.nachbarName.equals(n2)))
                 tInfo.nachbarName=nd;
              tInfo=(SiteInfo)tInfo.next();
           }
        }
      info=(SiteInfo)info.next();
     }
  }
  
  public void importSCInfo(){
     String 
myFile=(System.getProperty("user.dir")+"/xmlData/SizeNColor.csv");
     
     boolean fEnd=false;
     int counter=0;
    try{
      DataInputStream dataInput = new DataInputStream(new 
FileInputStream(myFile));
      CSVParser myCSV=new CSVParser();
      myCSV.setInput(dataInput);
      myCSV.buildTags();
      Kees info=new Kees();
      boolean eof=myCSV.read();
        int i=1,j=1,k=1;
      while(eof==false){
         if(myCSV.tag.equals("TypGruppe")){
            i=myCSV.getIntData();
         }
         if(myCSV.tag.equals("HausTyp")){
            j=myCSV.getIntData();
         }
         if(myCSV.tag.equals("Size")){
            k=myCSV.getIntData();
            scInfo[i][j][k]=new SizeNColorInfo();
         }
         if(myCSV.tag.equals("MinSize")) 
scInfo[i][j][k].minSize=myCSV.getDoubleData();
         if(myCSV.tag.equals("MaxSize")) 
scInfo[i][j][k].maxSize=myCSV.getDoubleData();
         if(myCSV.tag.equals("r")) scInfo[i][j][k].r=myCSV.getIntData();
         if(myCSV.tag.equals("g")) scInfo[i][j][k].g=myCSV.getIntData();
         if(myCSV.tag.equals("b")) scInfo[i][j][k].b=myCSV.getIntData();
         //System.out.println(" "+myCSV.tag+" "+myCSV.data);
         eof=myCSV.read();
      }
      dataInput.close();
    }
    catch (IOException ex){
      ex.printStackTrace();
    }
    numPoints=counter;
  }

  public void analyze(){
  }
  
  public void averageSize(){
     double avMin=minSiteSize;
     double avMax=getAreaSize();
     avMin=Math.sqrt(avMin/(double)numPoints/Math.PI);
     avMax=Math.sqrt(avMax/(double)numPoints/Math.PI);
     if(allAverage){
        SPoint fp=mySwarm.getFirstPoint();
        SPoint cp=fp;
        do{
           cp.set1Value(avMax-2);
           cp.set2Value(avMax);
           cp=cp.nextInLine;
        }while (cp!=fp);
     }else{
        SPoint fp=mySwarm.getFirstPoint();
        SPoint cp=fp;
        do{
           SiteInfo cInfo=(SiteInfo) cp.getInfo();
           cp.set1Value(Math.sqrt(cInfo.minSize/Math.PI));
           cp.set2Value(Math.sqrt(cInfo.maxSize/Math.PI));
           cp=cp.nextInLine;
        }while (cp!=fp);
     }
  }

   public void run(){
      if(myPolys.getFirstSystem()!=null){
          runPolys();
      }
      else if(mySwarm!=null) runSwarm();
   }
   
   public void runPolys(){
      Fast2DLine fFL=new Fast2DLine(),cFL;
        SLineObject border=(SLineObject)outAreas.getFirstSystem();
        int inFlag=0;
     
        if(borderAttraction>0){
          while (border!=null){
             SPoint pa,pf=border.getFirstPoint();
             pa=pf;
             if(pa!=null)
                do{
                   if(pa.myNeighbour==null){
                        cFL=new 
Fast2DLine(pa.getPosition(),pa.nextInLine.getPosition());
                        cFL.setup();
                        fFL.add(cFL);
                     }
                     pa=pa.nextInLine;
                  }while(pa!=pf);
                  border=(SLineObject) border.next();
             }
       
             OList polyBorder=(OList)myBorderKeepers.next();
             while (polyBorder!=null){
                SPoint cPoint=(SPoint)polyBorder.getObject();
                double minDist=60.0;
                Point2D mPoint=null;
                cFL=(Fast2DLine)fFL.next();
                Point2D pA=cPoint.getPosition();
                  while (cFL!=null){
                     Point2D cFP=cFL.getOrtoCross(pA);
                     double dist=cFP.getDoubleData();
                     if(dist<minDist){
                        minDist=dist;
                        mPoint=cFP;
                     }
                     cFL=(Fast2DLine)cFL.next();
                  }
                  if(mPoint!=null){
                     
cPoint.getKeeper().addMove(borderAttraction*mPoint.xd/2.0,borderAttraction*mPoint.yd/2.0);
                }
                  polyBorder=(OList)polyBorder.next(); 
             }
       
             OList polyEdges=(OList)myEdgeKeepers.next();
            while (polyEdges!=null){
               SPoint cPoint=(SPoint)polyEdges.getObject();
               Point2D posFrom=cPoint.getPosition();
               SPointKeeper movePoint=cPoint.getKeeper().getMovePoint();
               if(movePoint!=null){
                  Point2D posTo=new Point2D(movePoint.getPosition());
                  posTo.subtractPosition(posFrom);
                  posTo.scale(borderAttraction/2.0); 
                  cPoint.getKeeper().addMove(posTo.xd,posTo.yd);
               }
               polyEdges=(OList)polyEdges.next();
            }
         }
   }

  public void runSwarm(){
     if(mySwarm==null) return;
     if (mySwarm.getFirstPoint()==null) return;
     double xa,ya,ra1,ra2,xb,yb,rb1,rb2,dx,dy;
     Point2D pA=null,pB=null;
     double distMax,distMin,dist;
     boolean iLoop;
     
     /* * *   grenze aufbereiten    * * */
     
     Fast2DLine fFL=new Fast2DLine(),cFL;
     Fast2DLine fFaL=new Fast2DLine();
     SLineObject border=(SLineObject)outAreas.getFirstSystem();
     int inFlag=0;
     
    while (border!=null){
       SModObject borderMod=(SModObject)border.getModifier("object");
       String bName=borderMod.getName();
       int bType=0;
       if(bName.equals("strasse")) bType=1;
       if(bName.equals("bus")) bType=2;
       if(bName.equals("wasser")) bType=3;
       if(bName.equals("gruen")) bType=4;
       if(bName.equals("markt")) bType=5;
       
       SPoint pa,pf=border.getFirstPoint();
       pa=pf;
       if(pa!=null)
          do{
             if(pa.myNeighbour==null){
               cFL=new 
Fast2DLine(pa.getPosition(),pa.nextInLine.getPosition());
               cFL.setup();
               cFL.setIntData(bType);
               if(inFlag==0)
                  fFL.add(cFL);
               else
                  fFaL.add(cFL);
            }
            pa=pa.nextInLine;
         }while(pa!=pf);
      border=(SLineObject) border.next();
      if(border==null){
         if(inFlag==0){
            border=(SLineObject)inAreas.getFirstSystem();
            inFlag=1;
         }
      }
       }
     
     SPoint firstPoint=mySwarm.getFirstPoint();
     SPoint cPoint=firstPoint;
     SPoint ccPoint=null;
     int index=0;
     int[] attract=new int[6];
     SPoint[] bestAttract=new SPoint[6];
     double[] minAttractDist=new double[6];
     
     do{
        cPoint.setI1Value(0);
        cPoint.setI2Value(0);
        cPoint=cPoint.nextInLine;
     }while(cPoint!=firstPoint);
     cPoint=firstPoint;
     
     do{
        double happy=0.0;
        pA=cPoint.getPosition();
        SiteInfo cInfo=(SiteInfo)cPoint.getInfo();
      xa=pA.xd;
      ya=pA.yd;
      ra1=cPoint.get1Value();
      ra2=cPoint.get2Value();
      
        for(int i=1;i<6;i++){
           bestAttract[i]=null;
           minAttractDist[i]=10000000;
           if(cInfo==null){
              attract[i]=0;
           }else{
              attract[i]=cInfo.myAttractor[i];
           }
        }
        
        SPoint r1Attractor=null,r2Attractor=null;
        double r1AttractDist=600,r2AttractDist=600;
      ccPoint=firstPoint;
      if(ccPoint==null)return;
      iLoop=true;
      boolean doAttract=false;
      
      int ccIndex=0;
      do{
         int cci=0;
         int rAttract=0;
         doAttract=false;
         
         //if(cPoint.getLValue()<10){
            if(ccPoint.getLValue()>=10){
               cci=ccPoint.getLValue()-10;
               if(attract[cci]!=0);
               doAttract=true;
            }
           //}
           doAttract=true;
           
           if(cPoint.getLValue()==1){
              if(ccPoint.getLValue()==1){
                 if((cPoint.getI1Value()<2)&(ccPoint.getI1Value()<2)){
                    if(((cPoint.getI2Value())!=(ccPoint.getI2Value()))|
                          (cPoint.getI2Value()==0)|(ccPoint.getI2Value()==0))
                       rAttract=1;
                 }
              }
           }
           
           if(cPoint.getLValue()==2){
              if(ccPoint.getLValue()==2){
                 if((cPoint.getI1Value()<1)&(ccPoint.getI1Value()<1)){
                    rAttract=2;
                 }
              }
           }
      
         if(ccPoint!=cPoint)
         if((doAttract==true)|(ccIndex>index)|(rAttract!=0)){
            pB=ccPoint.getPosition();
            xb=pB.xd;
            yb=pB.yd;
            rb1=ccPoint.get1Value();
            rb2=ccPoint.get2Value();
            distMax=ra2+rb2+5.0;
            dx=xb-xa;
            dy=yb-ya;
            dist=0;
            if(doAttract){
               dist=Math.sqrt((dx*dx)+(dy*dy));
               if(dist<minAttractDist[cci]){
                  minAttractDist[cci]=dist;
                  bestAttract[cci]=ccPoint;
               }
               
               if(neighbourAttraction>0)
               if(dist>(distMax-5)){
                  SiteInfo ccInfo=(SiteInfo)ccPoint.getInfo();
                  if((cInfo.push+cInfo.pull+ccInfo.push+ccInfo.pull)>0){
                     double dPower=50.0-(dist-distMax);
                        if(dPower>0){
                        double ddx=dx/dist;
                        double ddy=dy/dist;
                        double push=0;
                        if(cInfo.pull>0){
                           if(ccInfo.ppIndex==cInfo.pull) push-=1.0;
                        }
                        if(cInfo.push>0){
                           if(ccInfo.ppIndex==cInfo.push) push+=1.0;
                        }
                        if(ccInfo.pull>0){
                           if(cInfo.ppIndex==ccInfo.pull) push-=1.0;
                        }
                        if(ccInfo.push>0){
                           if(cInfo.ppIndex==ccInfo.push) push+=1.0;
                        }
                        if(push>0){
                           ddx=ddx*push/2000.0*neighbourAttraction*dPower;
                           ddy=ddy*push/2000.0*neighbourAttraction*dPower;
                           cPoint.getKeeper().addMove(-ddx,-ddy);
                           ccPoint.getKeeper().addMove(ddx,ddy);
                        }
                     }
                  }
               }
            }
            if(rAttract>0){
               if(dist==0)
                  dist=Math.sqrt((dx*dx)+(dy*dy));
               if(rAttract==1){
                  if(dist<r1AttractDist){
                     r2AttractDist=r1AttractDist;
                     r2Attractor=r1Attractor;
                     r1AttractDist=dist;
                     r1Attractor=ccPoint;
                  }else if(dist<r2AttractDist){
                     r2AttractDist=dist;
                     r2Attractor=ccPoint;
                  }
               }
               if(rAttract==2){
                  if(dist<r1AttractDist){
                     r1AttractDist=dist;
                     r1Attractor=ccPoint;
                  }
               }
            }
            
            if(ccIndex>index)
             if (Math.abs(dx)<distMax){
               if (Math.abs(dy)<distMax){
                  if(dist==0)
                     dist=Math.sqrt((dx*dx)+(dy*dy));
                  if(radAttraction!=0)
                  if (dist<distMax) {
                     distMin=ra1+rb1;
                     distMax=ra2+rb2;
                     if(dist<distMin){
                        dx=dx/dist;
                        dy=dy/dist;
                        
                        if(dist<(distMin/2.0)){
                           //double fDist=(16.0*(distMin-dist)/(distMin))+1.0;
                           dist=dist-distMin;
                           dist=dist*8;
                        }else{
                           //double fDist=(8.0*(distMin-dist)/(distMin))+1.0;
                           dist=dist-distMin;
                           dist=dist*4;
                        }
                        
                        //dist=dist-distMin;
                           //dist=dist*8;
                        dx=(radAttraction*dx*dist/400.0);
                        dy=(radAttraction*dy*dist/400.0);
                        cPoint.getKeeper().addMove(dx,dy);
                        ccPoint.getKeeper().addMove(-dx,-dy);
                     }else if(dist>distMax){
                        dx=dx/dist;
                        dy=dy/dist;
                        dist=dist-distMax;
                        dx=(dx*dist/400.0);
                        dy=(dy*dist/400.0);
                        cPoint.getKeeper().addMove(dx,dy);
                        ccPoint.getKeeper().addMove(-dx,-dy);
                     }else{
                        dx=dx/dist;
                        dy=dy/dist;
                        dist=dist-distMax;
                        dist=dist*1.0;
                        dx=(radAttraction*dx*dist/400.0);
                        dy=(radAttraction*dy*dist/400.0);
                        cPoint.getKeeper().addMove(dx,dy);
                        ccPoint.getKeeper().addMove(-dx,-dy);
                     }
                  }
               }
            }         
         }
         ccPoint=ccPoint.nextInLine;
         ccIndex++;
         if(ccPoint==firstPoint) iLoop=false;
      }while (iLoop);
      
      /* * *             randabfrage             * * */
      
      inFlag=0;
      cFL=(Fast2DLine)fFL.next();
      Point2D[] atr=new Point2D[6];
      while (cFL!=null){
         Point2D cFP=cFL.getOrtoCross(pA);
         dist=cFP.getDoubleData();
         Point2D minAttract=atr[cFL.getIntData()];
         if(minAttract!=null){
            if(minAttract.getDoubleData()>dist){
               atr[cFL.getIntData()]=cFP;
            }
         }else{
            atr[cFL.getIntData()]=cFP;
         }
         if(radAttraction!=0)
         if(inFlag==0){
            ra1=cPoint.get1Value();
            ra2=cPoint.get2Value();
            if(dist<ra1){
               double length=(dist-ra1)*radAttraction;
               
cPoint.getKeeper().addMove(cFP.xd*(length/2.0)/dist,cFP.yd*(length/2.0)/dist);
            }
         }
         cFL=(Fast2DLine)cFL.next();
         if(cFL==null){
            if(inFlag==0){
               inFlag=1;
               cFL=(Fast2DLine)fFaL.next();
            }
         }
      }
      if(fieldAttraction>0)
      
      for(int i=1;i<6;i++){
         if(atr[i]!=null){
            double power=((double)cInfo.myAttractor[i])*fieldAttraction;
            if(power>0){
               double length=atr[i].getDoubleData();
               double distance=length-cPoint.get1Value();
               atr[i].scale((power*distance/60000.0));
               cPoint.getKeeper().addMove(atr[i].xd,atr[i].yd);
               if(distance>0)
                  happy+=(cInfo.myAttractor[i]*distance);
            }else if(power<0){
               double length=atr[i].getDoubleData();
               double distance=length-cPoint.get1Value();
               distance=60-distance;
               if(distance>0){
                  atr[i].scale(power*distance/60000.0);
                  cPoint.getKeeper().addMove(atr[i].xd,atr[i].yd);
               }
            }
         }
      }
      
      
      /* * *        Nachbar       * * */
      
     if(neighbourAttraction!=0){
         cInfo=(SiteInfo)cPoint.getInfo();
         ccPoint=cInfo.myNeighbour;
         if(ccPoint!=null)
         if(ccPoint!=cPoint){
            System.out.println(cInfo.nachbarName);
            dx=ccPoint.getPosition().xd-xa;
            dy=ccPoint.getPosition().yd-ya;
            dist=Math.sqrt((dx*dx)+(dy*dy));
            double distance=dist-(cPoint.get1Value()+ccPoint.get1Value());
            //if(cInfo.myAttractor[0]>0)
            /*
            if(distance>30){
               Point2D bPos=new Point2D(ccPoint.getPosition());
                 bPos.xd+=3;
                 cPoint.getKeeper().setPosition(bPos);
                 bPos=new Point2D(ccPoint.getPosition());
                 bPos.xd-=3;
                 ccPoint.getKeeper().setPosition(bPos);
            }else{
            */
            
            if(distance>0){
                //double 
power=((double)cInfo.myAttractor[0])*neighbourAttraction;
             double power=(2.0)*neighbourAttraction;
               dx=(power*dx*distance/20000.0);
               dy=(power*dy*distance/20000.0);
               cPoint.getKeeper().addMove(dx,dy);
               ccPoint.getKeeper().addMove(-dx,-dy);
            }
         
            if(distance>0)
               happy+=(cInfo.myAttractor[0]*distance);
            
         }
      }
        
      
      /* * *        mobile Attraktoren       * * */ 
      
      if(fieldAttraction!=0){
         //if(cPoint.getLValue()<10)
         for(int i=1; i<6; i++){
            ccPoint=bestAttract[i];
            if(ccPoint!=null){
               dx=ccPoint.getPosition().xd-xa;
               dy=ccPoint.getPosition().yd-ya;
               dist=minAttractDist[i];
               double distance=dist-(cPoint.get1Value()+ccPoint.get1Value());
               
               //distance+=7;
               if(attract[i]>0){
                  if(distance>0)
                     happy+=(cInfo.myAttractor[i]*distance);
                  ccPoint.setIValue(i,ccPoint.getIValue(i)+1);
                  if(distance>0){
                     double power=((double)attract[i])*fieldAttraction;
                     dx=(power*dx*distance/20000.0);
                     dy=(power*dy*distance/20000.0);
                     cPoint.getKeeper().addMove(dx,dy);
                     ccPoint.getKeeper().addMove(-dx/4.0,-dy/4.0);
                  }
               }else if(attract[i]<0){
                  distance=22.0-distance;
                  if(distance>0){
                     double power=((double)attract[i])*fieldAttraction;
                     dx=(power*dx*distance/20000.0);
                     dy=(power*dy*distance/20000.0);
                     cPoint.getKeeper().addMove(dx,dy);
                     //ccPoint.getKeeper().addMove(-dx/4.0,-dy/4.0);
                  }
               }
            }    
         }
      }
      
      
       /* * *        Reihen/Doppelhaus       * * */ 
      
      if(lineAttraction!=0)
      if((cPoint.getLValue()==1)|(cPoint.getLValue()==2)){
         int index1=0,index2=0;
         for(int i=0; i<2; i++){
            if(i==0) {
               ccPoint=r1Attractor;
               dist=r1AttractDist;
               if(ccPoint!=null)
                  index1=ccPoint.getI2Value();
            }
            else{
               ccPoint=r2Attractor;
               dist=r2AttractDist;
               if(dist>50) ccPoint=null;
               if(ccPoint!=null)
                  index2=ccPoint.getI2Value();
               if(cPoint.getI1Value()==2){
                  ccPoint=null;
                  r2Attractor=null;
                  index2=0;
               }
            }
            if(ccPoint!=null){
               dx=ccPoint.getPosition().xd-xa;
               dy=ccPoint.getPosition().yd-ya;
               double 
distance=dist-(cPoint.get1Value()+ccPoint.get1Value())+3;
               if(distance>0){
                  double power=1.0*lineAttraction;
                  dx=(power*dx*distance/20000.0);
                  dy=(power*dy*distance/20000.0);
                  cPoint.getKeeper().addMove(dx,dy);
                  ccPoint.getKeeper().addMove(-dx,-dy);
               }
               //if(distance>0)
                  //happy+=(cInfo.myAttractor[i]*distance);
               ccPoint.setI1Value(ccPoint.getI1Value()+1);
               cPoint.setI1Value(cPoint.getI1Value()+1);
            }    
         }
         
if((cPoint.getLValue()==1)&((r2Attractor!=null)|(r1Attractor!=null))){
            
            if(cPoint.getI2Value()==0){
               cPoint.setI2Value(index);
            }
            int nIndex=cPoint.getI2Value();
            if(index1==0){
               if(r1Attractor!=null) r1Attractor.setI2Value(nIndex);
               index1=index2;
            }
            if(index2==0){
               if(r2Attractor!=null) r2Attractor.setI2Value(nIndex);
               index2=index1;
            }
            if((index1!=0)|(index2!=0)){
               SPoint cccPoint=firstPoint;
               do{
                  if(cccPoint.getI2Value()==index1) 
cccPoint.setI2Value(nIndex);
                  else if(cccPoint.getI2Value()==index2) 
cccPoint.setI2Value(nIndex);
                  cccPoint=cccPoint.nextInLine;
               }while(cccPoint!=firstPoint);
            }
         }
      }
      
      if(cPoint.getLValue()<10)
      if(myDisplay==1){
         int col=255-(int)(happy*2);
         if (col<0) col=0;
         SRepPoint cr=(SRepPoint)cPoint.getKeeper().getRep(); 
         if(col<160)
            cr.setColor(new Color(0,0,0));
         else if(col<230)
            cr.setColor(new Color(255,0,0));
         else
            cr.setColor(new Color(255,255,0));
      }   
      
      if(cInfo.direction==1) cPoint.getKeeper().addMove(0,-1);
      if(cInfo.direction==2) cPoint.getKeeper().addMove(1,0);
      if(cInfo.direction==3) cPoint.getKeeper().addMove(0,1);
      if(cInfo.direction==4) cPoint.getKeeper().addMove(-1,0);
         
      cPoint=cPoint.nextInLine;
      
      index++;
     }while(cPoint!=firstPoint);
     
     if(fieldAttraction!=0){
        SPoint[] bestPoint=new SPoint[6],worstPoint=new SPoint[6];
        int[] besti=new int[6],worsti=new int[6];
        for(int i=1; i<6; i++){
           bestPoint[i]=null;
           worstPoint[i]=null;
           besti[i]=0;
           worsti[i]=100000;
        }
        cPoint=firstPoint;
        do{
           if(cPoint.getLValue()>10){
              int i=cPoint.getLValue()-10;
              if(besti[i]<cPoint.getIValue(i)){
                 besti[i]=cPoint.getIValue(i);
                 bestPoint[i]=cPoint;
              }
              if(worsti[i]>cPoint.getIValue(i)){
                 worsti[i]=cPoint.getIValue(i);
                 worstPoint[i]=cPoint;
              }
           }
           cPoint.resetIValue(6);
           cPoint=cPoint.nextInLine;
        }while(cPoint!=firstPoint);
        /*
        for(int i=1; i<6; i++){
           if((i==3)|(i==4)){
              if(worsti[i]<(4)){
                 Point2D bPos=new Point2D(bestPoint[i].getPosition());
                 bPos.xd+=6.0-(Math.random()*12.0);
                 bPos.yd+=6.0-(Math.random()*12.0);
                 worstPoint[i].getKeeper().setPosition(bPos);
              }
           }
        }
        */
     }
     
  }
  
  public FastPoint getAllPoints(){
     if (mySwarm==null) return null;
     FastPoint fFP,cFP;
     SPoint firstPoint=mySwarm.getFirstPoint();
     SPoint cPoint=firstPoint;
     Point2D pos;
     double x1,y1,r1;
       fFP=new FastPoint();
     do{
        pos=cPoint.getPosition();
      cFP=new FastPoint(pos.xd,pos.yd);
      cFP.setSPoint(cPoint);
      fFP.addToLast(cFP);
      cPoint=cPoint.nextInLine;
    }while(cPoint!=firstPoint);
    return fFP;
    }
  
  
   public void setupConvex(int cStep)
  {
     System.out.println("getting Points");
     
     FastPoint fFP=getAllPoints();
     FastPoint centerPoint,cP,ncP,rP,mP;
     FastLine cLine=null;
     FastTriangle fFT=null,cFT=null,ncFT=null,doneFT=null;
     double min=0;
     
     DirectionVector dV=new DirectionVector();
     
     centerPoint=(FastPoint)fFP.next();
     
     
     System.out.println("setting border points");
     
     SLineObject border=(SLineObject)outAreas.getFirstSystem();
     int inFlag=0;
    while (border!=null){
       SPoint pa,pf=border.getFirstPoint();
       pa=pf;
       Point2D nPos=new Point2D(0,0);
         Point2D dPos=new Point2D(0,0);
       do{
          if(pa.myNeighbour==null){
            double cLength=0;
            Point2D pPos=pa.getPosition();
            
            dPos.setPosition(pa.nextInLine.getPosition());
            dPos.subtractPosition(pPos);
            dPos.scale(1.0/pa.myLength);
            while(cLength<pa.myLength){
               nPos.setPosition(pPos);
               nPos.addPosition(dPos.xd*cLength,dPos.yd*cLength);
               cP=new FastPoint(nPos);
               fFP.addToLast(cP);
               //SPoint p=new SPoint();
               //SPointKeeper pk=new 
SPointKeeper(nPos.xd,nPos.yd,mySObject.getRoot());
               //p.setKeeper(pk);
               //cP.setSPoint(p);
               cLength+=10;
               System.out.println("bPoint"+nPos.xd+" "+nPos.yd);
            }
         }
         pa=pa.nextInLine;
      }while(pa!=pf);
      border=(SLineObject) border.next();
      //if(border==null){
      //   if(inFlag==0){
      //      border=(SLineObject)inAreas.getFirstSystem();
      //      inFlag=1;
      //   }
      //}
    }
       
       
    cP=(FastPoint)centerPoint.next();
     
     System.out.println("setting angles");
     while(cP!=null){
        
dV.setup(cP.getX()-centerPoint.getX(),cP.getY()-centerPoint.getY());
        cP.setDoubleData(dV.getAngle());
        cP=(FastPoint)cP.next();
     }
     
     System.out.println("setting pointOrder");
     cP=centerPoint;
     
     while(cP!=null){
        rP=(FastPoint)cP.next();
        mP=null;
        min=1000;
        while(rP!=null){
           if(rP.getDoubleData()<min){
              min=rP.getDoubleData();
              mP=rP;
           }
           rP=(FastPoint)rP.next();
        }
        if(mP!=null){
           mP=(FastPoint)mP.remove();
           cP.add(mP);
        }
        cP=mP;
     }
     
     System.out.println("building triangles");
     fFT=new FastTriangle();
     cP=(FastPoint)centerPoint.next();
     ncP=(FastPoint)cP.next();
     while(ncP!=null){
        cFT=new FastTriangle();
        cFT.setPoints(centerPoint,cP,ncP);
        fFT.addToLast(cFT);
        cP=ncP;
        ncP=(FastPoint)cP.next();
     }
     
     
     cFT=(FastTriangle)fFT.next();
     ncFT=(FastTriangle)cFT.next();
     while(ncFT!=null){
        cFT.nTriCA=ncFT;
        ncFT.nTriAB=cFT;
        cFT=ncFT;
        ncFT=(FastTriangle)cFT.next();
     }
        
     
     System.out.println("building hull");
     cFT=(FastTriangle)fFT.next();
     for(int i=0; i<(numPoints*numPoints); i++){
        cFT=cFT.tryAddHullTri();
     }
     
     
     cFT=(FastTriangle)fFT.next();
     while (cFT!=null){
        cFT.checkHull();
        if(cFT.isChecked())System.out.println("triplehull");
       cFT=(FastTriangle)cFT.next();
     }
     
     
     /*
            // Dreiecke als Polys (zum Test !!!)
     
     SPoly poly=new SPoly(myPolys);
    SModObject msg=new SModObject(poly);
    msg.setIcon("iring");
    poly.addModifier(msg);
    ModRingConstructor mrc=new ModRingConstructor(poly);
    poly.addModifier(mrc);
    poly.setConstructor(mrc);
    ModSizeController msc=new ModSizeController(poly);
    poly.addModifier(msc);
    ModAngleController mda=new ModAngleController(poly);
    poly.addModifier(mda);
    ModProportionController mpc=new ModProportionController(poly);
    poly.addModifier(mpc);
    mpc.setRelation(1.0);
          OffCanvas 
o=mySwarm.getFirstPoint().getKeeper().getRep().getPanel();

     cFT=(FastTriangle)fFT.next();
     while(cFT!=null){
        OList keeper=new OList();
        SPointKeeper k=new 
SPointKeeper(cFT.pointA.xK,cFT.pointA.yK,mySObject.getRoot());
        keeper.setObject(k);
        k=new 
SPointKeeper(cFT.pointB.xK,cFT.pointB.yK,mySObject.getRoot());
        keeper.addObjectToLast(k);
        k=new 
SPointKeeper(cFT.pointC.xK,cFT.pointC.yK,mySObject.getRoot());
        keeper.addObjectToLast(k);
        
        if(keeper!=null){
           if(poly.isConstructed()) 
poly=(SPoly)poly.getCopy(poly.getMother());
           poly.getConstructor().construct(o,keeper);
        }
        cFT=(FastTriangle)cFT.next();
     }
     */
     
     
     System.out.println("flipping");
     doneFT=new FastTriangle();
     cFT=(FastTriangle)fFT.next();
     int flipcounter=0;
     while(cFT!=null){
        cFT.tryFlip(doneFT);
       cFT=(FastTriangle)fFT.next();
     }
     
     
     System.out.println("hulltrideleting");
     
     cFT=(FastTriangle)doneFT.next();
     
     
     FastTriangle nextFT=null;
     while(cFT!=null){
        nextFT=(FastTriangle)cFT.next();
        if ((cFT.pointA.getSPoint()==null)&
              (cFT.pointB.getSPoint()==null)&
              (cFT.pointC.getSPoint()==null))
        {
           cFT.remove();
           if(cFT.nTriAB!=null) cFT.nTriAB.removeNTri(cFT);
           if(cFT.nTriBC!=null) cFT.nTriBC.removeNTri(cFT);
           if(cFT.nTriCA!=null) cFT.nTriCA.removeNTri(cFT);
        }
        cFT=nextFT;
     }
     
  
     System.out.println("centerKeepers");
     cFT=(FastTriangle)doneFT.next();
     while(cFT!=null){
        Point2D center=cFT.getCenter();
        SPointKeeper k=new 
SPointKeeper(center.xd,center.yd,mySObject.getRoot());
        cFT.setCenterKeeper(k);
        k.setRep(mySwarm.getFirstPoint().getKeeper().getRep().getPanel());
        cFT.pointA.setTri(cFT);
        cFT.pointB.setTri(cFT);
        cFT.pointC.setTri(cFT);
        cFT=(FastTriangle)cFT.next();
     }
     
     System.out.println("building polys");
    
     SPoly poly=new SPoly(myPolys);
    SModObject msg=new SModObject(poly);
    msg.setIcon("iring");
    poly.addModifier(msg);
    ModRingConstructor mrc=new ModRingConstructor(poly);
    poly.addModifier(mrc);
    poly.setConstructor(mrc);
    ModSizeController msc=new ModSizeController(poly);
    poly.addModifier(msc);
    ModAngleController mda=new ModAngleController(poly);
    poly.addModifier(mda);
    ModProportionController mpc=new ModProportionController(poly);
    poly.addModifier(mpc);
    mpc.setRelation(1.0);
    
     int counter=0;
     cFT=(FastTriangle)doneFT.next();
     FastPoint cFP=(FastPoint)fFP.next();
     OffCanvas o=mySwarm.getFirstPoint().getKeeper().getRep().getPanel();
     
     while(cFP!=null){
        if(cFP.getSPoint()!=null){
           OList cKeeper=null;
           OList keeper=null;
           FastTriangle firstFT=cFP.getTri(); 
           FastTriangle nFT=null;
           cFT=firstFT;
           if(cFT!=null)
           do{
              if(cFT.getCenterKeeper()!=null){
                 cKeeper=new OList();
                 if(keeper==null) keeper=cKeeper;
                 else keeper.addToLast(cKeeper);
                 if(cFT==null)System.out.println("null");
                 cKeeper.setObject(cFT.getCenterKeeper());
              }else{
                 System.out.println("kein Zentrum!!");
              }
              nFT=cFT.getNTriNext(cFP);
              if(nFT==null){
                 nFT=cFT;
                 while(nFT.getNTriPrev(cFP)!=null){
                    nFT=nFT.getNTriPrev(cFP);
                    System.out.println("backstepping");
                 }
              }
              cFT=nFT;
           }while(cFT!=firstFT);
        
           SiteInfo info=(SiteInfo) cFP.getSPoint().getInfo();
           
           if(keeper!=null){
              if(poly.isConstructed()) 
poly=(SPoly)poly.getCopy(poly.getMother());
              poly.getConstructor().construct(o,keeper);
              poly.setInfo(info);
              info.setPoly(poly);
           }
        }
        cFP=(FastPoint)cFP.next();
     }
     
     infoChangePolys();
     mySwarm.delete();
     mySwarm=null;
     System.out.println("swarmDeleted");
     
     mySObject.getRoot().setup();
     setBorderKeepers();
  }
  
  public void setupPolyEdges2(){
  
     SPoly cPoly=(SPoly)myPolys.getFirstSystem();
     if (cPoly==null) return;
     int polyCounter=0;
     while (cPoly!=null){
        cPoly.setLFlags(SPoint.L_CHECKED);
        cPoly.deletePFlags(SPoint.P_ONEDGE);
        cPoly.deleteLFlags(SPoint.L_HARD);
        polyCounter++;
        cPoly=(SPoly)cPoly.next();
     }
     
     /*
     for(int i=0;i<polyCounter;i++){
        SPoly fPoly=(SPoly)myPolys.getFirstSystem();
        cPoly=fPoly;
        int pNum=(int)(Math.random()*(polyCounter-i-1));
        for(int j=0;j<pNum;j++){
           cPoly=(SPoly)cPoly.next();
        }
        if(cPoly!=fPoly)
           fPoly.addToLast(cPoly.remove());
     }
     */
     
     cPoly=(SPoly)myPolys.getFirstSystem();
     SPoint fPoint=null,cPoint=null;
     
     while (cPoly!=null){
        
        int sideCount=0,hardCount=0;
        int numSides=0,numHard=0,numChecked=0;
        fPoint=cPoly.getFirstPoint();
        cPoint=fPoint;
        do{
           numSides++;
           if(cPoint.checkLFlag(SPoint.L_HARD))
              numHard++;
           if(cPoint.checkLFlag(SPoint.L_CHECKED))
              numChecked++;
           cPoint=cPoint.nextInLine;
        }while(fPoint!=cPoint);
        
        fPoint=cPoly.getFirstPoint();
        cPoint=fPoint;
        
        do{
           sideCount++;
           if(cPoint.checkLFlag(SPoint.L_CHECKED)){
              if(numHard<2){
                 if(!(cPoint.previousInLine.checkLFlag(SPoint.L_HARD))){
                    cPoint.setLFlag(SPoint.L_HARD);
                    numHard++;
                 }
              }else{
                 SPoint nPoint=cPoint.myNeighbour;
                 if(nPoint!=null){
                    if(nPoint.previousInLine.checkLFlag(SPoint.L_CHECKED)){
                       nPoint.previousInLine.setLFlag(SPoint.L_HARD);
                       nPoint.previousInLine.deleteLFlag(SPoint.L_CHECKED);
                    }
                 }
              }
              cPoint.deleteLFlag(SPoint.L_CHECKED);
           }
           if(cPoint.checkLFlag(SPoint.L_HARD)){
              cPoint.setPFlag(SPoint.P_ONEDGE);
              cPoint.nextInLine.setPFlag(SPoint.P_ONEDGE);
           }
           cPoint=cPoint.nextInLine;
        }while(fPoint!=cPoint);
        
        cPoly=(SPoly)cPoly.next();
     }
  }
  
  
  
  public void setupPolyEdges(){
  
     EList donePolys =(EList)myPolys.getFirstSystem().previous();
     SPoly cPoly=(SPoly)donePolys.next();
     SPoly nPoly;
     if (cPoly==null) return;
     SPoly todoPolys=new SPoly();
     SPoly poolPolys=new SPoly();
     int polyCounter=0;
     while (cPoly!=null){
        nPoly=(SPoly)cPoly.next();
        cPoly.setLFlags(SPoint.L_CHECKED);
        cPoly.deletePFlags(SPoint.P_ONEDGE);
        cPoly.deleteLFlags(SPoint.L_HARD);
        if(cPoly.checkForBorder()){
           todoPolys.addToLast(cPoly.remove());
        }else{
           poolPolys.addToLast(cPoly.remove());
        }
        polyCounter++;
        cPoly=nPoly;
     }
     
     boolean allCheckedFlag=true;
     while(allCheckedFlag){
        cPoly=(SPoly) todoPolys.next();
        while (cPoly!=null){
           nPoly=(SPoly)cPoly.next();
           cPoly.setupSides();
           donePolys.addToLast(cPoly.remove());
           cPoly=nPoly;
        }
        cPoly=(SPoly)poolPolys.next();
        if(cPoly==null) allCheckedFlag=false;
        while (cPoly!=null){
           nPoly=(SPoly)cPoly.next();
           if(cPoly.checkNLFlag(SPoint.L_CHECKED)){
              todoPolys.addToLast(cPoly.remove());
           }
           cPoly=nPoly;
        }
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        cPoly.setupAngles();
        cPoly=(SPoly)cPoly.next();
     }
     
  }
  
  public void setBorderKeepers(){
     SPoly cPoly=(SPoly)myPolys.getFirstSystem();
     if (cPoly==null) return;
     myBorderKeepers=new OList();
     while(cPoly!=null){
        SPoint firstPoint=cPoly.getFirstPoint();
        SPoint cPoint=firstPoint;
        if(cPoint!=null)
        do{
           if(cPoint.myNeighbour==null){
              myBorderKeepers.addObjectToLast(cPoint);
              cPoint.getKeeper().setFlag(SPointKeeper.PK_BORDER);
           }
           else{
              cPoint.getKeeper().deleteFlag(SPointKeeper.PK_BORDER);
           }
           cPoint=cPoint.nextInLine;
        }while (cPoint!=firstPoint);
        cPoly=(SPoly)cPoly.next();
     }
     borderToEdges();
  }
  
  
  public void setupPolyEdges3(){
  
     EList donePolys =(EList)myPolys.getFirstSystem().previous();
     SPoly cPoly=(SPoly)donePolys.next();
     SPoly nPoly;
     if (cPoly==null) return;
     SPoly todoPolys=new SPoly();
     SPoly poolPolys=new SPoly();
     int polyCounter=0;
     while (cPoly!=null){
        nPoly=(SPoly)cPoly.next();
        if(cPoly.checkForBorder())
           cPoly.setFlag(SObject.O_ISBORDER);
        else
           cPoly.deleteFlag(SObject.O_ISBORDER);
        cPoly.deletePFlags(SPoint.P_ONEDGE);
        cPoly.deleteLFlags(SPoint.L_HARD);
        polyCounter++;
        cPoly=nPoly;
     }
     
     for(int i=0;i<polyCounter;i++){
        SPoly fPoly=(SPoly)donePolys.next();
        cPoly=fPoly;
        int pNum=(int)(Math.random()*(polyCounter-i-1));
        for(int j=0;j<pNum;j++){
           cPoly=(SPoly)cPoly.next();
        }
        cPoly.defineRandomFirstPoint();
        if(cPoly!=fPoly)
           fPoly.addToLast(cPoly.remove());
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        nPoly=(SPoly)cPoly.next();
        cPoly.tryConnectToNeighbour();
        cPoly.tryConnectToNeighbour();
        cPoly=nPoly;
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        cPoly.setupAngles();
        cPoly=(SPoly)cPoly.next();
     }
  }
  
  public void setupBorderNStreetLines(){
     EList donePolys =(EList)myPolys.getFirstSystem().previous();
     SPoly cPoly=(SPoly)donePolys.next();
     if (cPoly==null) return;
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        SPoint fPoint=cPoly.getFirstPoint();
        SPoint cPoint=fPoint;
        cPoly.deleteLFlags(SPoint.L_BORDER);
        cPoly.deleteLFlags(SPoint.L_OPPSTREET);
        
        do{
           cPoint.getKeeper().deleteFlag(SPointKeeper.PK_BORDER);
           cPoint=cPoint.nextInLine;
           
        }while (cPoint!=fPoint);
        cPoly=(SPoly)cPoly.next();
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        SPoint fPoint=cPoly.getFirstPoint();
        SPoint cPoint=fPoint;
        do{
           if(cPoint.myNeighbour==null){
              cPoint.getKeeper().setFlag(SPointKeeper.PK_BORDER);
              //cPoint.nextInLine.getKeeper().setFlag(SPointKeeper.PK_BORDER);
              cPoint.setLFlag(SPoint.L_BORDER);
           }
           cPoint=cPoint.nextInLine;
        }while (cPoint!=fPoint);
        cPoly=(SPoly)cPoly.next();
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        SPoint fPoint=cPoly.getFirstPoint();
        SPoint cPoint=fPoint;
        do{
           if((!cPoint.getKeeper().checkFlag(SPointKeeper.PK_STREET))&
              
(!cPoint.nextInLine.getKeeper().checkFlag(SPointKeeper.PK_STREET))&
              (!cPoint.getKeeper().checkFlag(SPointKeeper.PK_BORDER))&
              
(!cPoint.nextInLine.getKeeper().checkFlag(SPointKeeper.PK_BORDER)))
           {
              cPoint.setLFlag(SPoint.L_OPPSTREET);
           }
           cPoint=cPoint.nextInLine;
        }while (cPoint!=fPoint);
        cPoly=(SPoly)cPoly.next();
     }
  }
  
  public void setupPolyEdges4(){
     EList donePolys =(EList)myPolys.getFirstSystem().previous();
     SPoly cPoly=(SPoly)donePolys.next();
     SPoly nPoly;
     if (cPoly==null) return;
     SPoly todoPolys=new SPoly();
     SPoly poolPolys=new SPoly();
     int polyCounter=0;
     while (cPoly!=null){
        nPoly=(SPoly)cPoly.next();
        if(cPoly.checkForBorder())
           cPoly.setFlag(SObject.O_ISBORDER);
        else
           cPoly.deleteFlag(SObject.O_ISBORDER);
        cPoly.deletePFlags(SPoint.P_ONEDGE);
        cPoly.deleteLFlags(SPoint.L_HARD);
        polyCounter++;
        cPoly=nPoly;
     }
     
     for(int i=0;i<polyCounter;i++){
        SPoly fPoly=(SPoly)donePolys.next();
        cPoly=fPoly;
        int pNum=(int)(Math.random()*(polyCounter-i-1));
        for(int j=0;j<pNum;j++){
           cPoly=(SPoly)cPoly.next();
        }
        cPoly.defineRandomFirstPoint();
        if(cPoly!=fPoly)
           fPoly.addToLast(cPoly.remove());
     }
     
     //  *   *   *  Werte setzen  *   *   *  
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        SPoint fPoint=cPoly.getFirstPoint();
        SPoint cPoint=fPoint;
        do{
           if(cPoint.checkLFlag(SPoint.L_BORDER)){
              cPoint.setLValue(0);
           }else{
              if(cPoint.checkLFlag(SPoint.L_STREET)){
                 cPoint.setLValue(1);
              }else{
                 if(cPoint.checkLFlag(SPoint.L_OPPSTREET)){
                    cPoint.setLValue(4);
                 }else{
                    cPoint.setLValue(30);
                 }
              }
           }
           cPoint=cPoint.nextInLine;
        }while(cPoint!=fPoint);
        cPoly=(SPoly)cPoly.next();
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        nPoly=(SPoly)cPoly.next();
        cPoly.tryConnectToNeighbour();
        cPoly.tryConnectToNeighbour();
        cPoly=nPoly;
     }
     
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        cPoly.setupAngles();
        cPoly=(SPoly)cPoly.next();
     }
     
  }
  
  public void borderToEdges(){
     int inFlag=0;
     SLineObject border=(SLineObject)outAreas.getFirstSystem();
     myEdgeKeepers=new OList();
     while (border!=null){
       SPoint pa,pf=border.getFirstPoint();
       pa=pf;
       if(pa!=null){
          do{
             Point2D bPos=pa.getPosition();
             double angle=pa.getOuterAngle();
             OList cbk=(OList)myBorderKeepers.next();
             double minDist=1000000;
             OList bestBK=null;
             while (cbk!=null){
                SPoint bPoint=(SPoint)cbk.getObject();
                
                if(angle>1.25*Math.PI)
                   if(bPoint!=bPoint.nextInKeeper)   bPoint=null;
                if(angle<0.75*Math.PI)
                   if(bPoint==bPoint.nextInKeeper)   bPoint=null;
                if(bPoint!=null){
                   Point2D bKPos=bPoint.getPosition();
                   double 
dist=Math.sqrt(((bKPos.xd-bPos.xd)*(bKPos.xd-bPos.xd))+((bKPos.yd-bPos.yd)*(bKPos.yd-bPos.yd)));
                   if(dist<minDist){
                      minDist=dist;
                      bestBK=cbk;
                   }
                }
                cbk=(OList)cbk.next();
             }
             if(bestBK!=null){
                myEdgeKeepers.addToLast(bestBK.remove());
                SPoint bPoint=(SPoint)bestBK.getObject();
                if(angle>1.25*Math.PI){
                   bPoint.getKeeper().setFlag(SPointKeeper.PK_OUTEDGE);
                   bPoint.getLineObject().setFlag(SObject.O_OUTEDGE);
                }
                if(angle<0.75*Math.PI){
                   bPoint.getKeeper().setFlag(SPointKeeper.PK_INEDGE);
                   bPoint.getLineObject().setFlag(SObject.O_INEDGE);
                   bPoint.nextInKeeper.getLineObject().setFlag(SObject.O_INEDGE);
                }
                bPoint.getKeeper().setMovePoint(pa.getKeeper());
             }
            pa=pa.nextInLine;
         }while(pa!=pf);
         border=(SLineObject) border.next();
         /*
         if(border==null){
            if(inFlag==0){
               border=(SLineObject)inAreas.getFirstSystem();
               inFlag=1;
            }
         }
         */
          }
       }
  }
  
  /*
  public void setupLines(){
     EList donePolys =(EList)myPolys.getFirstSystem().previous();
     SPoly cPoly=(SPoly)donePolys.next();
     if (cPoly==null) return;
     int polyCounter=0;
     while (cPoly!=null){
        SiteInfo cInfo=(SiteInfo)cPoly.getInfo();
        if(cInfo!=null)
        if((cInfo.typGruppe==1)|(cInfo.typGruppe==2)){
           cPoly.deleteLFlags(SPoint.L_HARD);
           cPoly.deleteLFlags(SPoint.L_LINEBORDER);
        }
        cPoly=(SPoly)cPoly.next();
     }
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        SiteInfo cInfo=(SiteInfo)cPoly.getInfo();
        if(cInfo!=null)
        if((cInfo.typGruppe==1)|(cInfo.typGruppe==2)){
           SPoint fPoint=cPoly.getFirstPoint();
           SPoint cPoint=fPoint;
           do{
              if(!cPoint.checkLFlag(SPoint.L_LINEBORDER))
              if(cPoint.myNeighbour!=null){
                 SiteInfo 
nInfo=(SiteInfo)cPoint.myNeighbour.getLineObject().getInfo();
                 if(nInfo!=null){
                    if(cInfo.typGruppe==nInfo.typGruppe){
                       cPoint.previousInLine.setLFlag(SPoint.L_LINEBORDER);
                       cPoint.nextInLine.setLFlag(SPoint.L_LINEBORDER);
                       
cPoint.myNeighbour.previousInLine.setLFlag(SPoint.L_LINEBORDER);
                       cPoint.myNeighbour.nextInLine.setLFlag(SPoint.L_LINEBORDER);
                       cPoint.setLFlag(SPoint.L_HARD);
                    }
                 }
              }
              cPoint=cPoint.nextInLine;
           }while (cPoint!=fPoint);
        }
        cPoly=(SPoly)cPoly.next();
     }
  }
  */
  
  public void setupLines(){
     EList donePolys =(EList)myPolys.getFirstSystem().previous();
     SPoly cPoly=(SPoly)donePolys.next();
     if (cPoly==null) return;
     int polyCounter=0;
     while (cPoly!=null){
        SiteInfo cInfo=(SiteInfo)cPoly.getInfo();
        if(cInfo!=null)
        if((cInfo.typGruppe==1)|(cInfo.typGruppe==2)){
           cPoly.deleteLFlags(SPoint.L_HARD);
           cPoly.deleteLFlags(SPoint.L_LINEBORDER);
        }
        cPoly=(SPoly)cPoly.next();
     }
     cPoly=(SPoly)donePolys.next();
     while (cPoly!=null){
        SiteInfo cInfo=(SiteInfo)cPoly.getInfo();
        if(cInfo!=null)
        if(cInfo.typGruppe==1){
           SPoint fPoint=cPoly.getFirstPoint();
           SPoint cPoint=fPoint;
           if(cPoint!=null)
           do{
              if(!cPoint.checkLFlag(SPoint.L_LINEBORDER))
              if(cPoint.myNeighbour!=null){
                 SiteInfo 
nInfo=(SiteInfo)cPoint.myNeighbour.getLineObject().getInfo();
                 if(nInfo!=null){
                    if(cInfo.typGruppe!=nInfo.typGruppe){
                       cPoint.setLFlag(SPoint.L_LINEBORDER);
                       System.out.println("lBorder");
                    }else{
                       
if(cPoint.myNeighbour.getLineObject().checkFlag(SObject.O_ATSTREET))
                          cPoint.setLFlag(SPoint.L_LINEBORDER);
                    }
                 }
              }
              cPoint=cPoint.nextInLine;
           }while (cPoint!=fPoint);
           cPoint=fPoint;
           double bLength=0,sLength=0;
           if(cPoint!=null)
           do{
              if(cPoint.checkLFlag(SPoint.L_LINEBORDER))
                 bLength+=cPoint.getLength();
              sLength+=cPoint.getLength();
              cPoint=cPoint.nextInLine;
           }while (cPoint!=fPoint);
           cPoint=fPoint;
           if(cPoint!=null)
           if(bLength>(sLength/2.0))
           do{
              if(cPoint.checkLFlag(SPoint.L_LINEBORDER))
                 cPoint.setLFlag(SPoint.L_LINEEND);
              cPoint=cPoint.nextInLine;
           }while (cPoint!=fPoint);
        }
        cPoly=(SPoly)cPoly.next();
     }
  }
  
  public void changeSizeScale(){
     
     sizeScale=getAreaSize()/maxSiteSize;
     if(myPolys.getFirstSystem()!=null){
        ModStreetController 
ms=(ModStreetController)myPolys.getModifier("street");
        if(ms!=null){
           if (ms.getLength()==0)
           sizeScale=getAreaSize()/(maxSiteSize+(ms.myStreetLength*10));
        }
     }
      if(myPolys.getFirstSystem()!=null){
         SPoly cPoly=(SPoly) myPolys.getFirstSystem();
         while(cPoly!=null){
            SiteInfo cInfo=(SiteInfo)cPoly.getInfo();
            if(cInfo!=null){
               ModSizeController 
mSize=(ModSizeController)cPoly.getModifier("size");
               if(mSize!=null){
                  if(realSize){
                     mSize.setMinSize(cInfo.minSize);
                     mSize.setMaxSize(cInfo.maxSize);
                  }else{
                     mSize.setMinSize(cInfo.minSize*sizeScale);
                     mSize.setMaxSize(cInfo.maxSize*sizeScale);
                  }
               }
            }
            cPoly=(SPoly)cPoly.next();
         }
      }
      else if(mySwarm!=null) {
         SPoint cPoint=mySwarm.getFirstPoint();
         SiteInfo cInfo=(SiteInfo)myInfos.next();
         if(cPoint!=null)
         do{
            if(realSize==true){
               cPoint.set1Value(Math.sqrt(cInfo.minSize/Math.PI));
               cPoint.set2Value(Math.sqrt(cInfo.maxSize/Math.PI));
            }else{
               cPoint.set1Value(Math.sqrt(cInfo.minSize/Math.PI)*sizeScale);
               cPoint.set2Value(Math.sqrt(cInfo.maxSize/Math.PI)*sizeScale);
            }
            cPoint=cPoint.nextInLine;
            cInfo=(SiteInfo)myInfos.next();
         }while (cPoint!=mySwarm.getFirstPoint());
      }
      
   }
   
   public void updateSizePower(){
      if(myPolys.getFirstSystem()!=null){
         SPoly cPoly=(SPoly) myPolys.getFirstSystem();
         while(cPoly!=null){
            ModSizeController 
mSize=(ModSizeController)cPoly.getModifier("size");
            if(mSize!=null){
               mSize.sizePower=sizePower;
            }
            cPoly=(SPoly)cPoly.next();
         }
      }
   }
   
   public void updateAnglePower(){
      if(myPolys.getFirstSystem()!=null){
         SPoly cPoly=(SPoly) myPolys.getFirstSystem();
         while(cPoly!=null){
            ModAngleController 
mAngle=(ModAngleController)cPoly.getModifier("angle");
            if(mAngle!=null){
               mAngle.anglePower=anglePower;
            }
            cPoly=(SPoly)cPoly.next();
         }
      }
   }
   
   public SiteInfo getFirstInfo(){
      return (SiteInfo)myInfos.next();
   }
   
   public SGroup getPolys(){
      return myPolys;
   }
}


-- OtherDenisRaschpichler - 28 Dec 2004


Topic LegacySource . { Edit | Attach | Ref-By | Printable | Diffs | r1.1 | More }

Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

This website has been archived and is no longer maintained.