00001
00006 package DisplayGUI;
00007 import org.omg.CORBA.IntHolder;
00008 import ipc.*;
00009
00010
00011 import java.util.*;
00012 import GuiComponents.System.*;
00013
00014 public class ConfigurationInterface implements displayParams, SCTInfo {
00015 private static ConfigurationInterface instance = new ConfigurationInterface();
00016 private int maxWidth=0;
00017 private int midX=0, midY=0;
00018 private int moduleCount=0;
00019 private java.awt.Polygon polygon;
00020
00021 double[] radius = {0.,0.,0.,0.,0.,0.};
00022 int[] xPoints = {0,0,0,0};
00023 int[] yPoints = {0,0,0,0};
00024 long fillsn=3000;
00025
00026 public static final int VIEW_CATEGORIES=2;
00027 public static final int SCT_VIEWS=0;
00028 public static final int RODCRATE_VIEWS=1;
00029
00030
00031
00032
00033 private String[][][][] serialnos;
00034
00035 private Map moduleCellMap;
00036
00037 private Set[][] orderedList;
00038
00039 private Map viewMap;
00040
00041 private Map[] slotMap;
00042
00043 private boolean dcsAvailable;
00044
00045 private ConfigurationInterface() {
00046 Refresh();
00047 }
00048
00049 public static ConfigurationInterface getInstance() {
00050 return instance;
00051 }
00052
00053 public void setWindowSize(int maxWidth, int maxHeight) {
00054 this.maxWidth=maxWidth;
00055 midX=maxWidth/2;
00056 midY=maxHeight/2;
00057 maxWidth*=0.95;
00058 radius[0]=0.35 * (double)maxWidth/2.;
00059 radius[1]=0.52 * (double)maxWidth/2.;
00060 radius[2]= 0.5 * (double)maxWidth/2.;
00061 radius[3]= 0.76* (double)maxWidth/2.;
00062 radius[4]= 0.74 * (double)maxWidth/2.;
00063 radius[5]= maxWidth/2.;
00064 }
00065
00066 public void Refresh() {
00067 orderedList = new TreeSet[VIEW_CATEGORIES][];
00068 orderedList[SCT_VIEWS] = new TreeSet[sctViews];
00069 for(int i=0;i<sctViews;i++) orderedList[SCT_VIEWS][i]=new TreeSet();
00070 serialnos = new String[VIEW_CATEGORIES][][][];
00071 serialnos[SCT_VIEWS] = new String[sctViews][][];
00072 moduleCellMap = new HashMap();
00073 viewMap = new LinkedHashMap();
00074 dcsAvailable=false;
00075 moduleCount=0;
00076 }
00077
00078 public Map getRodCrateViewMap() {
00079 return viewMap;
00080 }
00081
00082 public boolean isConfigured() {
00083 return (moduleCount>0);
00084 }
00085
00086 public void getConfiguration() {
00087 getConfiguration(-1);
00088 }
00089
00090 public void getConfiguration(int moduleGroup) {
00091 sctConf.Configuration h = SystemInterface.getInstance().getConfigurationService();
00092 Sct_SctApi.SctApiIPC sctApi = SystemInterface.getInstance().getSctApi();
00093 if(h==null) {System.err.println("SctGUI::ConfigurationInterface - null ref to Config service");return;}
00094 if(sctApi==null) {System.err.println("SctGUI::ConfigurationInterface - null ref to SctApi");return;}
00095 try {
00096
00097
00098 int[] parts = h.listPartitions();
00099 viewMap = new LinkedHashMap();
00100 int viewCount=0;
00101 for(int p=0; p<parts.length; p++) {
00102
00103 int[] crates = h.listCratesInPartition(parts[p]);
00104 for(int c=0; c<crates.length; c++) {
00105 viewMap.put(getRODCrateKey(parts[p],crates[c]),new Integer(viewCount));
00106 viewCount++;
00107 }
00108 }
00109
00110 if(viewCount>0) {
00111 slotMap = new HashMap[viewMap.size()];
00112 serialnos[RODCRATE_VIEWS] = new String[viewMap.size()][][];
00113 orderedList[RODCRATE_VIEWS] = new TreeSet[viewMap.size()];
00114 for(int i=0;i<viewMap.size();i++) {
00115 orderedList[RODCRATE_VIEWS][i]=new TreeSet();
00116 slotMap[i] = new HashMap();
00117 }
00118 }
00119
00120
00121 for(int p=0; p<parts.length; p++) {
00122 int[] crates = h.listCratesInPartition(parts[p]);
00123 for(int c=0; c<crates.length; c++) {
00124 int[] rods = h.listRodsInCrate(parts[p], crates[c]);
00125 for(int r=0; r<rods.length; r++) {
00126
00127
00128
00129
00130 int[] MURs = h.listMURSInRod(parts[p], crates[c], rods[r]);
00131 for(int mur=0; mur<MURs.length; mur++) {
00132
00133 String[] modules = h.listModulesInMUR(parts[p], MURs[mur]);
00134
00135 for(int m=0; m<modules.length; m++) {
00136
00137
00138 IntHolder MUR = new IntHolder(), num = new IntHolder();
00139 h.translateFromSN(modules[m], MUR, num);
00140
00141 IntHolder partition = new IntHolder(), crate = new IntHolder(), rodno=new IntHolder(), channel=new IntHolder() ;
00142 h.translateToROD(MUR.value, num.value, partition, crate, rodno, channel);
00143
00144 SNInfo snInfo = new SNInfo();
00145 snInfo.set(SNInfo.PARTITION,Integer.toString(partition.value));
00146 snInfo.set(SNInfo.ROD_CRATE,Integer.toString(crate.value));
00147 snInfo.set(SNInfo.ROD_NUMBER,Integer.toString(rodno.value));
00148 snInfo.set(SNInfo.ROD_CHANNEL,Integer.toString(channel.value));
00149 snInfo.set(SNInfo.ROD_SLOT,Integer.toString(sctApi.getCrateLegacy(partition.value, crate.value).getRodSlot(rodno.value)));
00150
00151 try {
00152 moduleGroup = h.getModuleGroup(modules[m]);
00153 }catch(Exception groupE){
00154 System.err.println("SctGUI::ConfigurationInterface - can't retrieve moduleGroup : "+groupE.toString());
00155 moduleGroup=0;
00156 }
00157
00158 IntHolder barrel = new IntHolder(), row = new IntHolder(), number = new IntHolder();
00159 try {
00160 h.translateToBarrel(MUR.value, num.value, barrel, row, number);
00161 defineBarrelModuleGraphicsCell(barrel.value, row.value, number.value, MUR.value, moduleGroup, modules[m],snInfo);
00162 } catch(sctConf.ConfigurationException eConfig) {
00163 h.translateToEndcap(MUR.value, num.value, barrel, row, number);
00164 defineEndCapModuleGraphicsCell(barrel.value, row.value, number.value, MUR.value, moduleGroup, modules[m],snInfo);
00165 }
00166 try {
00167 h.translateToPowerSupply(MUR.value, num.value,partition,crate,channel);
00168 definePowerSupplyMapping(crate.value,channel.value,modules[m]);
00169 }catch(Exception ee) {}
00170
00171
00172 }
00173 }
00174 }
00175 }
00176 }
00177 } catch(sctConf.ConfigurationException eConfig) {
00178 System.err.println("Configuration exception retrieving configuration " + eConfig.detail);
00179 eConfig.printStackTrace();
00180 } catch(Exception e) {
00181 System.err.println("Non-configuration exception retrieving configuration ..." + e);
00182 e.printStackTrace();
00183 }
00184
00185 writeLookUpTable();
00186
00187
00188 }
00189
00190 public String getRODCrateKey(int partition, int crate) {
00191 return getRODCrateKey(Integer.toString(partition),Integer.toString(crate));
00192 }
00193 public String getRODCrateKey(String partition, String crate) {
00194 return "Partition"+partition+".Crate"+crate;
00195 }
00196
00197 public void definePowerSupplyMapping(int crate, int channel, String sn) {
00198
00199 dcsAvailable=true;
00200
00201 ModuleCell thisCell = (ModuleCell)moduleCellMap.get(sn);
00202 SNInfo snInfo = thisCell.getSNInfo();
00203 if(snInfo==null) snInfo = new SNInfo();
00204
00205 String crateString = Integer.toString(crate);
00206 snInfo.set(SNInfo.DCS_CRATE,crateString);
00207 String channelString = Integer.toString(channel);
00208 snInfo.set(SNInfo.DCS_CHANNEL,channelString);
00209
00210 if(crateString.length()==1) crateString="0"+crateString;
00211 if(channelString.length()==1) channelString="0"+channelString;
00212 snInfo.set(SNInfo.DCS_HEADER,"Crate"+crateString+".Channel"+channelString+".");
00213 snInfo.set(SNInfo.IV_FILE_HEADER,"CRATE"+crateString+"CHAN"+channelString);
00214
00215 thisCell.addSNInfo(snInfo);
00216
00217 }
00218 public String getSNInfo(String sn, int index) {
00219 ModuleCell thisCell = (ModuleCell)moduleCellMap.get(sn);
00220 if(thisCell==null) return "-1";
00221 SNInfo snInfo = thisCell.getSNInfo();
00222 if(snInfo==null) return "-1";
00223 return snInfo.get(index);
00224 }
00225
00226 public String getASerialNumberForSlot(int selection,int slot) {
00227 return (String)slotMap[selection].get(new Integer(slot));
00228 }
00229
00230 public boolean isDCSAvailable() {
00231 return dcsAvailable;
00232 }
00233
00234
00235 public String addModule(int barrel, int row, int number, int MUR, int moduleGroup, String serialNo) {
00236
00237 for(int i=0;i<sctViews;i++) {
00238 if(orderedList[SCT_VIEWS][i].contains(serialNo)) return "Module "+serialNo+" is already defined in "+SCTViewNames[i];
00239 }
00240
00241 for (Iterator i=orderedList[SCT_VIEWS][barrel].iterator(); i.hasNext(); ) {
00242 String thisSerialNo = (String)i.next();
00243 ModuleCell thisCell = (ModuleCell)moduleCellMap.get(thisSerialNo);
00244 if(thisCell.getRow()==row && thisCell.getModulePosition()==number) return "That location already taken by "+thisSerialNo;
00245 }
00246 int thisSCTView = barrel;
00247
00248 try {
00249 moduleGroup = SystemInterface.getInstance().getConfigurationService().getModuleGroup(serialNo);
00250 }catch(Exception ee){System.err.println("SctGUI::ConfigurationInterface - can't retrieve moduleGroup : "+ee.toString());}
00251
00252 if(barrel<4) {
00253 thisSCTView+=3;
00254 defineBarrelModuleGraphicsCell(thisSCTView, row, number, MUR, moduleGroup, serialNo, new SNInfo());
00255 }
00256 else if(barrel>12) {
00257 thisSCTView-=12;
00258 defineEndCapModuleGraphicsCell(thisSCTView, row, number, MUR, moduleGroup, serialNo, new SNInfo());
00259 }
00260 else {
00261 thisSCTView-=3;
00262 thisSCTView*=-1;
00263 defineEndCapModuleGraphicsCell(thisSCTView, row, number, MUR, moduleGroup, serialNo, new SNInfo());
00264 }
00265 return null;
00266 }
00267
00268 private void defineBarrelModuleGraphicsCell(int barrel, int row, int number, int MUR, int moduleGroup, String serialNo, SNInfo snInfo) {
00269 for(int i=0;i<sctViews;i++) {
00270 if(orderedList[SCT_VIEWS][i].contains(serialNo)) {
00271 System.out.println("** Module "+serialNo+" defined more than once!");
00272 return;
00273 }
00274 }
00275 if(barrel < 3 || barrel > 6) {
00276 System.out.println("** Module "+serialNo+" reported to be in nonexistant barrel " + barrel + "!");
00277 return;
00278 }
00279
00280 int thisSCTView=barrel-3;
00281 int moduleIndex = number;
00282 moduleIndex+=6;
00283 if(moduleIndex>5) moduleIndex--;
00284 int thisRow=row;
00285
00286 ModuleCell thisCell = new ModuleCell(serialNo,thisSCTView,row,number,MUR,moduleGroup);
00287 thisCell.addSNInfo(snInfo);
00288 calculateSCTPolygon(thisSCTView,row,number);
00289 thisCell.addPolygon(SCT_VIEWS,xPoints,yPoints,4);
00290
00291 if(serialnos[SCT_VIEWS][thisSCTView]==null) serialnos[SCT_VIEWS][thisSCTView] = new String[barrelRows[thisSCTView]][];
00292 if(serialnos[SCT_VIEWS][thisSCTView][thisRow]==null) serialnos[SCT_VIEWS][thisSCTView][thisRow] = new String[12];
00293 serialnos[SCT_VIEWS][thisSCTView][thisRow][moduleIndex] = new String(serialNo);
00294 orderedList[SCT_VIEWS][thisSCTView].add(serialNo);
00295
00296 Integer viewIndex = (Integer)viewMap.get(getRODCrateKey(snInfo.get(SNInfo.PARTITION),snInfo.get(SNInfo.ROD_CRATE)));
00297 if(viewIndex==null) System.err.println("SctGUI::ConfigurationInterface - invalid view index");
00298 else {
00299 int slot = Integer.parseInt(snInfo.get(SNInfo.ROD_SLOT));
00300
00301 if(slot>=5) {
00302 int channel = Integer.parseInt(snInfo.get(SNInfo.ROD_CHANNEL));
00303
00304 if(!slotMap[viewIndex.intValue()].containsKey(new Integer(slot))) slotMap[viewIndex.intValue()].put(new Integer(slot),serialNo);
00305
00306 int slotIndex = slot-5;
00307
00308 if(serialnos[RODCRATE_VIEWS][viewIndex.intValue()]==null) serialnos[RODCRATE_VIEWS][viewIndex.intValue()] = new String[rodSlots][];
00309 if(serialnos[RODCRATE_VIEWS][viewIndex.intValue()][slotIndex]==null) serialnos[RODCRATE_VIEWS][viewIndex.intValue()][slotIndex] = new String[rodChannels];
00310 serialnos[RODCRATE_VIEWS][viewIndex.intValue()][slotIndex][channel] = new String(serialNo);
00311
00312 calculateRodCratePolygon(slot,channel);
00313 thisCell.addPolygon(RODCRATE_VIEWS,xPoints,yPoints,4);
00314
00315 orderedList[RODCRATE_VIEWS][viewIndex.intValue()].add(serialNo);
00316 }
00317
00318 }
00319
00320 moduleCellMap.put(serialNo,thisCell);
00321 moduleCount++;
00322 }
00323
00324 private void defineEndCapModuleGraphicsCell(int disk, int quadrant, int number, int MUR, int moduleGroup, String serialNo, SNInfo snInfo) {
00325 for(int i=0;i<sctViews;i++) {
00326 if(orderedList[SCT_VIEWS][i].contains(serialNo)) {
00327 System.out.println("** Module "+serialNo+" defined more than once!");
00328 return;
00329 }
00330 }
00331
00332
00333 int thisSCTView = (disk<0) ? 3-disk : 12+disk;
00334 if(serialnos[SCT_VIEWS][thisSCTView]==null) serialnos[SCT_VIEWS][thisSCTView] = new String[4][];
00335 if(serialnos[SCT_VIEWS][thisSCTView][quadrant]==null) serialnos[SCT_VIEWS][thisSCTView][quadrant] = new String[33];
00336
00337 ModuleCell thisCell = new ModuleCell(serialNo,thisSCTView,quadrant,number,MUR,moduleGroup);
00338 thisCell.addSNInfo(snInfo);
00339 calculateSCTPolygon(thisSCTView,quadrant,number);
00340 thisCell.addPolygon(SCT_VIEWS,xPoints,yPoints,4);
00341
00342
00343
00344 serialnos[SCT_VIEWS][thisSCTView][quadrant][number] = new String(serialNo);
00345 orderedList[SCT_VIEWS][thisSCTView].add(serialNo);
00346
00347 Integer viewIndex = (Integer)viewMap.get(getRODCrateKey(snInfo.get(SNInfo.PARTITION),snInfo.get(SNInfo.ROD_CRATE)));
00348 if(viewIndex==null) System.err.println("SctGUI::ConfigurationInterface - invalid view index");
00349 else {
00350 int slot = Integer.parseInt(snInfo.get(SNInfo.ROD_SLOT));
00351 int channel = Integer.parseInt(snInfo.get(SNInfo.ROD_CHANNEL));
00352 if(!slotMap[viewIndex.intValue()].containsKey(new Integer(slot))) slotMap[viewIndex.intValue()].put(new Integer(slot),serialNo);
00353 int slotIndex=slot-5;
00354 if(serialnos[RODCRATE_VIEWS][viewIndex.intValue()]==null) serialnos[RODCRATE_VIEWS][viewIndex.intValue()] = new String[rodSlots][];
00355 if(serialnos[RODCRATE_VIEWS][viewIndex.intValue()][slotIndex]==null) serialnos[RODCRATE_VIEWS][viewIndex.intValue()][slotIndex] = new String[rodChannels];
00356 serialnos[RODCRATE_VIEWS][viewIndex.intValue()][slotIndex][channel] = new String(serialNo);
00357
00358 calculateRodCratePolygon(slot,channel);
00359 thisCell.addPolygon(RODCRATE_VIEWS,xPoints,yPoints,4);
00360 orderedList[RODCRATE_VIEWS][viewIndex.intValue()].add(serialNo);
00361 }
00362
00363 moduleCellMap.put(serialNo,thisCell);
00364 moduleCount++;
00365 }
00366
00367 public int getRodSlotNumber(int selection, java.awt.event.MouseEvent e) {
00368
00369 if(!isConfigured()) return -1;
00370
00371 if(selection<0) return -1;
00372 int x = e.getX();
00373 int y = e.getY();
00374
00375 int ww = rcBoxWidth + rcBoxGap;
00376 int midPoint = midX + rcXOffSet;
00377 int yIndex = 47 - (y - yOffSet - rcYOffSet)/boxHeight;
00378 if(yIndex<-1 || yIndex>47) return -1;
00379
00380 int diff = x - midPoint;
00381 diff += 8*ww;
00382 int xIndex = diff/ww;
00383 if(xIndex<0 || xIndex>17) return -1;
00384 int xdiff = midPoint - 8*(rcBoxWidth+rcBoxGap) + xIndex*(rcBoxWidth+rcBoxGap);
00385 if(x-xdiff<rcBoxGap) return -1;
00386 if(serialnos[RODCRATE_VIEWS]!=null || serialnos[RODCRATE_VIEWS][selection]!=null && serialnos[RODCRATE_VIEWS][selection][xIndex]!=null) return xIndex+5;
00387 return -1;
00388 }
00389
00390 public ModuleCell getCell(int viewCategory, int sctView, int x, int y) {
00391
00392
00393
00394
00395 if(viewCategory<0 || sctView<0 || !isConfigured()) return null;
00396
00397 switch(viewCategory) {
00398 case SCT_VIEWS:
00399 if(sctView<4) {
00400 int yIndex = ((yOffSetCount[sctView]+barrelRows[sctView])*boxHeight - y + yOffSet)/boxHeight;
00401 if(yIndex<0 || yIndex>barrelRows[sctView]-1) return null;
00402 int diff = x -maxWidth/2;
00403
00404 int xIndex = diff/boxWidth;
00405 if(diff>0 && xIndex==0) return null;
00406
00407
00408 xIndex*=-1;
00409 xIndex+=6;
00410
00411
00412
00413 if(xIndex<0 || xIndex>11) return null;
00414 if(serialnos[SCT_VIEWS]!=null && serialnos[viewCategory][sctView]!=null && serialnos[viewCategory][sctView][yIndex]!=null && serialnos[viewCategory][sctView][yIndex][xIndex]!=null) {
00415 return (ModuleCell) moduleCellMap.get(serialnos[viewCategory][sctView][yIndex][xIndex]);
00416 }
00417 }
00418 else {
00419
00420
00421 for (Iterator i=orderedList[viewCategory][sctView].iterator(); i.hasNext(); ) {
00422 String sn = (String) i.next();
00423 ModuleCell thisCell = (ModuleCell)moduleCellMap.get(sn);
00424 if(thisCell.getPolygon(viewCategory).contains(x,y)) return thisCell;
00425 }
00426 }
00427 break;
00428 case RODCRATE_VIEWS:
00429 int ww = rcBoxWidth + rcBoxGap;
00430 int midPoint = midX + rcXOffSet;
00431 int yIndex = 47 - (y - yOffSet - rcYOffSet)/boxHeight;
00432 if(yIndex<0 || yIndex>47) return null;
00433
00434 int diff = x - midPoint;
00435 diff += 8*ww;
00436 int xIndex = diff/ww;
00437 if(xIndex<0 || xIndex>16) return null;
00438 int xdiff = midPoint - 8*(rcBoxWidth+rcBoxGap) + xIndex*(rcBoxWidth+rcBoxGap);
00439 if(x-xdiff<rcBoxGap) return null;
00440 if(serialnos[RODCRATE_VIEWS]!=null && serialnos[RODCRATE_VIEWS][sctView]!=null && serialnos[viewCategory][sctView][xIndex]!=null && serialnos[viewCategory][sctView][xIndex][yIndex]!=null) {
00441 return (ModuleCell) moduleCellMap.get(serialnos[RODCRATE_VIEWS][sctView][xIndex][yIndex]);
00442 }
00443 break;
00444 default:
00445 }
00446
00447 return null;
00448 }
00449
00450 public Set getSerialNumberList(int viewCategory, int sctView) {
00451 if(viewCategory==-1 || sctView==-1 || !isConfigured()) return new TreeSet();
00452 if(orderedList[viewCategory]==null || orderedList[viewCategory][sctView]==null) {
00453 System.out.println("SctGUI::ConfigurationInterface null orderedlist");
00454 return new TreeSet();
00455 }
00456 return orderedList[viewCategory][sctView];
00457 }
00458
00459 public Set[] buildSerialNumberMap() {
00460 Set[] serialNumberMap = new HashSet[sctViews];
00461 for(int i=0;i<sctViews;i++) serialNumberMap[i] = new HashSet(getSerialNumberList(SCT_VIEWS,i));
00462 return serialNumberMap;
00463 }
00464
00465 public int getNumberOfModules(int viewCategory, int sctView) {
00466 return orderedList[viewCategory][sctView].size();
00467 }
00468 public int getTotalNumberOfModules() {
00469 return moduleCount;
00470 }
00471 public ModuleCell getModuleCell(String serialNo) {
00472 return (ModuleCell)moduleCellMap.get(serialNo);
00473 }
00474
00475 public void drawRodCrateViewOutline(java.awt.Graphics2D g2, int selection) {
00476 g2.setColor(java.awt.Color.lightGray);
00477 g2.setFont(displayTextFont);
00478 java.awt.FontMetrics metrics = g2.getFontMetrics();
00479 int rowNo=0;
00480 int ww = rcBoxWidth + rcBoxGap;
00481
00482 int thisXOffSet = midX + rcXOffSet - 8*ww + rcBoxGap;
00483 int thisYOffSet = yOffSet + rcYOffSet;
00484 int timX = thisXOffSet+1+8*ww;
00485 int[] timPolyX = {timX,timX,timX+rcBoxWidth,timX+rcBoxWidth};
00486 int[] timPolyY = {thisYOffSet,thisYOffSet+48*boxHeight,thisYOffSet+48*boxHeight,thisYOffSet};
00487 g2.setColor(java.awt.Color.lightGray);
00488 g2.fill(new java.awt.Polygon(timPolyX,timPolyY,4));
00489 g2.setColor(java.awt.Color.black);
00490 String[] letters = {"T","I","M"," ","M","O","D","U","L","E"};
00491 for(int i=0;i<letters.length;i++) {
00492 int letterWidth = metrics.stringWidth(letters[i]);
00493 int xlabel = timX+rcBoxWidth/2-letterWidth/2;
00494 int ylabel = thisYOffSet+(i+1)*20;
00495 g2.drawString(letters[i],xlabel,ylabel);
00496 }
00497
00498 g2.setColor(java.awt.Color.lightGray);
00499 for(int i=0;i<48;i++) {
00500 String rowLabel = Integer.toString(rowNo);
00501 int labelWidth = metrics.stringWidth(rowLabel);
00502 int xLabel = thisXOffSet - labelWidth - 4;
00503 for(int x=5;x<=21;x++) {
00504 if(x!=13) g2.drawRect(thisXOffSet + (x-5)*ww, thisYOffSet + (47-i)*boxHeight, rcBoxWidth, boxHeight);
00505 }
00506 g2.drawString(rowLabel,xLabel,thisYOffSet + (47-i)*boxHeight + boxHeight);
00507 rowNo++;
00508 }
00509 g2.setColor(java.awt.Color.lightGray);
00510
00511 g2.drawRect(thisXOffSet, thisYOffSet, rodSlots*ww - rcBoxGap, 48*boxHeight);
00512
00513 int ylabeloffset = thisYOffSet + 50* boxHeight;
00514
00515 boolean slots_used=false;
00516 for(int i=0;i<rodSlots;i++) {
00517 boolean slotUsed = (serialnos[RODCRATE_VIEWS]!=null && serialnos[RODCRATE_VIEWS][selection]!=null && serialnos[RODCRATE_VIEWS][selection][i]!=null);
00518 java.awt.Color labelColor = slotUsed ? java.awt.Color.black : java.awt.Color.lightGray;
00519 if(slotUsed) slots_used=true;
00520 g2.setColor(labelColor);
00521 String slot = Integer.toString(i+5);
00522 int labelWidth = metrics.stringWidth(slot);
00523 int xlabeloffset = midX + rcXOffSet - 8*ww + (i+1)*ww - rcBoxWidth/2 - labelWidth/2;
00524 g2.drawString(slot, xlabeloffset, ylabeloffset);
00525 if(slotUsed) {
00526 g2.drawRect(thisXOffSet + i*ww,thisYOffSet,rcBoxWidth,48*boxHeight);
00527 Integer theSlot = new Integer(i+5);
00528 if(slotMap[selection].containsKey(theSlot)) {
00529 String sampleSerialNo = (String)slotMap[selection].get(theSlot);
00530 String rodno = getSNInfo(sampleSerialNo,SNInfo.ROD_NUMBER);
00531 labelWidth = metrics.stringWidth(rodno);
00532 xlabeloffset = midX + rcXOffSet - 8*ww + (i+1)*ww - rcBoxWidth/2 - labelWidth/2;
00533 g2.drawString(rodno,xlabeloffset,ylabeloffset+boxHeight+10);
00534 }
00535 }
00536 }
00537 java.awt.Color labelColor = slots_used ? java.awt.Color.black : java.awt.Color.lightGray;
00538 g2.setColor(labelColor);
00539 String slotString = "Slot:";
00540 g2.drawString(slotString,thisXOffSet - 4 - metrics.stringWidth(slotString),ylabeloffset);
00541 slotString = "ID:";
00542 g2.drawString(slotString,thisXOffSet - 4 - metrics.stringWidth(slotString),ylabeloffset+boxHeight+10);
00543 }
00544
00545 public void drawViewOutline(java.awt.Graphics2D g2,int viewCategory, int selection) {
00546 switch(viewCategory) {
00547 case SCT_VIEWS:
00548 drawSCTViewOutline(g2,selection);
00549 break;
00550 case RODCRATE_VIEWS:
00551 drawRodCrateViewOutline(g2,selection);
00552 break;
00553 default:
00554 }
00555 }
00556
00557 public void drawSCTViewOutline(java.awt.Graphics2D g2, int selection) {
00558 g2.setColor(java.awt.Color.lightGray);
00559 g2.setFont(displayTextFont);
00560 java.awt.FontMetrics metrics = g2.getFontMetrics();
00561 int rowNo=0;
00562
00563 switch(selection) {
00564 case Barrel3:
00565 case Barrel4:
00566 case Barrel5:
00567 case Barrel6:
00568 int ilow = yOffSetCount[selection];
00569
00570 int ihigh = ilow+barrelRows[selection];
00571 int midX= maxWidth/2;
00572
00573
00574 for(int y=ihigh-1;y>=ilow;y--) {
00575 String rowLabel = Integer.toString(rowNo);
00576 int labelWidth = metrics.stringWidth(rowLabel);
00577 int xLabel = midX - 6*boxWidth - labelWidth -8;
00578
00579 int thisRow = rowNo;
00580
00581 boolean rowUsed = (serialnos[SCT_VIEWS]!=null && serialnos[SCT_VIEWS][selection]!=null && serialnos[SCT_VIEWS][selection][thisRow]!=null);
00582 g2.setColor(java.awt.Color.lightGray);
00583 for(int x=-6;x<=6;x++) {
00584 if(x==0) continue;
00585 g2.drawRect(midX+(boxWidth*x),yOffSet+(y*boxHeight), boxWidth, boxHeight);
00586 }
00587 java.awt.Color labelColor = rowUsed ? java.awt.Color.black : java.awt.Color.lightGray;
00588 g2.setColor(labelColor);
00589 g2.drawString(rowLabel,xLabel,yOffSet+y*boxHeight+boxHeight);
00590 rowNo++;
00591 }
00592 g2.setColor(java.awt.Color.lightGray);
00593 g2.drawRect(midX - 6*boxWidth, yOffSet, 13*boxWidth, 56*boxHeight);
00594
00595
00596 int x1 = midX-100;
00597 int x2 = midX+120;
00598
00599
00600 int y1 = yOffSet + 58*boxHeight;
00601
00602 g2.drawLine(x1,y1,x2,y1);
00603 g2.drawLine(x1,y1,x1+5,y1-5);
00604 g2.drawLine(x1,y1,x1+5,y1+5);
00605 g2.drawLine(x2,y1,x2-5,y1-5);
00606 g2.drawLine(x2,y1,x2-5,y1+5);
00607 g2.drawString("Z+",x1-20,y1);
00608 g2.drawString("Z-",x2+10,y1);
00609 break;
00610 case EndCap1a:
00611 case EndCap1c:
00612 case EndCap7a:
00613 case EndCap7c:
00614 case EndCap8a:
00615 case EndCap8c:
00616 for(int quadrant=0;quadrant<4;quadrant++) {
00617 for(int number=13;number<23;number++) {
00618 calculateSCTPolygon(selection,quadrant,number);
00619 if(polygon!=null) {
00620 g2.setColor(java.awt.Color.white);
00621 g2.fill(polygon);
00622 g2.setColor(java.awt.Color.lightGray);
00623 g2.draw(polygon);
00624 }
00625 }
00626 }
00627 for(int quadrant=0;quadrant<4;quadrant++) {
00628 for(int number=0;number<13;number++) {
00629 calculateSCTPolygon(selection,quadrant,number);
00630 if(polygon!=null) {
00631 g2.setColor(java.awt.Color.white);
00632 g2.fill(polygon);
00633 g2.setColor(java.awt.Color.lightGray);
00634 g2.draw(polygon);
00635 }
00636 }
00637 }
00638 break;
00639 case EndCap2a:
00640 case EndCap2c:
00641 case EndCap3a:
00642 case EndCap3c:
00643 case EndCap4a:
00644 case EndCap4c:
00645 case EndCap5a:
00646 case EndCap5c:
00647 case EndCap6a:
00648 case EndCap6c:
00649 for(int quadrant=0;quadrant<4;quadrant++) {
00650 for(int number=13;number<23;number++) {
00651 calculateSCTPolygon(selection,quadrant,number);
00652 if(polygon!=null) {
00653 g2.setColor(java.awt.Color.white);
00654 g2.fill(polygon);
00655 g2.setColor(java.awt.Color.lightGray);
00656 g2.draw(polygon);
00657 }
00658 }
00659 }
00660 for(int quadrant=0;quadrant<4;quadrant++) {
00661 for(int number=0;number<33;number++) {
00662 if(number>=13 && number<23) continue;
00663 calculateSCTPolygon(selection,quadrant,number);
00664 if(polygon!=null) {
00665 g2.setColor(java.awt.Color.white);
00666 g2.fill(polygon);
00667 g2.setColor(java.awt.Color.lightGray);
00668 g2.draw(polygon);
00669 }
00670 }
00671 }
00672 break;
00673 case EndCap9a:
00674 case EndCap9c:
00675 for(int quadrant=0;quadrant<4;quadrant++) {
00676 for(int number=0;number<13;number++) {
00677 calculateSCTPolygon(selection,quadrant,number);
00678 if(polygon!=null) g2.draw(polygon);
00679 }
00680 }
00681 break;
00682 default:
00683
00684 }
00685
00686
00687 }
00688
00689 private void calculateRodCratePolygon(int slot, int channel) {
00690 int ww = rcBoxWidth+rcBoxGap;
00691 int xloc = maxWidth/2 - 8*ww + (slot-5)*ww + rcBoxGap + rcXOffSet;
00692 int yloc = yOffSet + rcYOffSet + (47-channel)*boxHeight;
00693 xPoints[0] = xPoints[1] = xloc;
00694 xPoints[2] = xPoints[3] = xloc+rcBoxWidth;
00695 yPoints[0] = yPoints[3] = yloc;
00696 yPoints[1] = yPoints[2] = yloc+boxHeight;
00697 polygon = new java.awt.Polygon(xPoints,yPoints,4);
00698 return;
00699 }
00700
00701 private void calculateSCTPolygon(int view, int quadrant, int number) {
00702
00703 if(view<4) {
00704
00705
00706
00707 int xloc=maxWidth/2 - number*boxWidth;
00708
00709 int yloc = yOffSet + (yOffSetCount[view] + barrelRows[view] - quadrant - 1)*boxHeight;
00710
00711
00712 xPoints[0] = xPoints[1] = xloc;
00713 xPoints[2] = xPoints[3] = xloc+boxWidth;
00714 yPoints[0] = yPoints[3] = yloc;
00715 yPoints[1] = yPoints[2] = yloc+boxHeight;
00716 polygon = new java.awt.Polygon(xPoints,yPoints,4);
00717 return;
00718 }
00719
00720
00721 double thetaOffset=0.;
00722 double theta=0.;
00723 int rindex=0;
00724 int segment=0;
00725 int modules=0;
00726 if(number<13) {
00727 thetaOffset = Math.PI/52.;
00728 theta = Math.PI/26.;
00729 rindex=4;
00730 segment=number;
00731 modules=13;
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745 }
00746 else if(number>=13 && number<23) {
00747 thetaOffset=0.;
00748 theta = Math.PI/20.;
00749 rindex=2;
00750 segment=number-13;
00751 modules=10;
00752 }
00753 else {
00754 thetaOffset=Math.PI/40.;
00755 theta = Math.PI/20.;
00756 rindex=0;
00757 segment=number-23;
00758 modules=10;
00759 }
00760 segment += quadrant*modules;
00761
00762 xPoints[0] = midX+(int)(radius[rindex]*Math.sin(segment*theta+thetaOffset));
00763 xPoints[1] = midX+(int)(radius[rindex]*Math.sin((segment+1)*theta+thetaOffset));
00764 xPoints[2] = midX+(int)(radius[rindex+1]*Math.sin((segment+1)*theta+thetaOffset));
00765 xPoints[3] = midX+(int)(radius[rindex+1]*Math.sin(segment*theta+thetaOffset));
00766
00767 yPoints[0] = midY-(int)(radius[rindex]*Math.cos(segment*theta+thetaOffset));
00768 yPoints[1] = midY-(int)(radius[rindex]*Math.cos((segment+1)*theta+thetaOffset));
00769 yPoints[2] = midY-(int)(radius[rindex+1]*Math.cos((segment+1)*theta+thetaOffset));
00770 yPoints[3] = midY-(int)(radius[rindex+1]*Math.cos(segment*theta+thetaOffset));
00771 polygon = new java.awt.Polygon(xPoints,yPoints,4);
00772
00773 }
00774
00775 public void updateModuleGroups(List cellList) {
00776 for(int i=0;i<cellList.size();i++) {
00777 ModuleCell thisCell = (ModuleCell)cellList.get(i);
00778 try {
00779 SystemInterface.getInstance().getConfigurationService().setModuleGroup(thisCell.getSerialNo(),(short)thisCell.getModuleGroup());
00780 }catch(Exception e){System.err.println("Exception setting modulegroup for module "+thisCell.getSerialNo()+" : "+e.toString());}
00781 }
00782 }
00783 private void writeLookUpTable() {
00784 String directory = Preferences.PreferencesInterface.getInstance().getPreference(Preferences.PreferencesInterface.WEB_LOOKUP_DIR);
00785 if(directory.equals(Preferences.PreferencesInterface.unDefinedString)) return;
00786
00787
00788
00789 for(int i=0;i<SCTViewNames.length;i++) {
00790 Map lookupMap = new HashMap();
00791 Set moduleList = getSerialNumberList(SCT_VIEWS,i);
00792 for (java.util.Iterator m = moduleList.iterator(); m.hasNext(); ) {
00793 String thisSN=(String)m.next();
00794 ModuleCell thisCell = getModuleCell(thisSN);
00795 String desc = SCTViewNames[i]+", Row "+thisCell.getRow()+", Position "+thisCell.getPosition();
00796 lookupMap.put(thisSN,desc);
00797 }
00798 if(lookupMap.size()>0) saveLookUpMap(i,directory,lookupMap);
00799 }
00800
00801 }
00802 private Map getLookUpMap(String directory) {
00803 Map thisMap = new HashMap();
00804 java.util.regex.Pattern p = java.util.regex.Pattern.compile("(\\d{14})=(.*)");
00805 java.io.File lookupFile = new java.io.File(directory,"moduleMap.txt");
00806 try {
00807 if(lookupFile.exists()) {
00808 java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(lookupFile));
00809 String line;
00810 while((line=in.readLine())!=null) {
00811 java.util.regex.Matcher matcher = p.matcher(line);
00812 if(matcher.matches()) thisMap.put(line.substring(matcher.start(1),matcher.end(1)),line.substring(matcher.start(2),matcher.end(2)));
00813 }
00814 in.close();
00815 }
00816 }catch(Exception e){System.err.println("SctGUI::ConfigurationInterface - Exception reading in "+lookupFile.getName()+" - "+e.toString());}
00817 return thisMap;
00818 }
00819 private void saveLookUpMap(int view,String directory,Map thisMap) {
00820 java.io.File lookupFile = new java.io.File(directory,"moduleMap"+Integer.toString(view)+".txt");
00821 int lineCount=0;
00822 try {
00823 java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(lookupFile));
00824 String line;
00825 for (Iterator i=thisMap.entrySet().iterator(); i.hasNext(); ) {
00826 Map.Entry e = (Map.Entry) i.next();
00827 out.write((String)e.getKey()+"="+(String)e.getValue());
00828 out.newLine();
00829 lineCount++;
00830 }
00831 out.close();
00832
00833 }catch(Exception e){System.err.println("SctGUI::ConfigurationInterface - Exception writing to "+lookupFile.getName()+" - "+e.toString());}
00834 }
00835
00836
00837
00838
00839
00840
00841
00842
00843 }