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 "P"+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(selection<0) return -1;
00370 int x = e.getX();
00371 int y = e.getY();
00372
00373 int ww = rcBoxWidth + rcBoxGap;
00374 int midPoint = midX + rcXOffSet;
00375 int yIndex = 47 - (y - yOffSet - rcYOffSet)/boxHeight;
00376 if(yIndex<-1 || yIndex>47) return -1;
00377
00378 int diff = x - midPoint;
00379 diff += 8*ww;
00380 int xIndex = diff/ww;
00381 if(xIndex<0 || xIndex>17) return -1;
00382 int xdiff = midPoint - 8*(rcBoxWidth+rcBoxGap) + xIndex*(rcBoxWidth+rcBoxGap);
00383 if(x-xdiff<rcBoxGap) return -1;
00384 if(serialnos[RODCRATE_VIEWS]!=null || serialnos[RODCRATE_VIEWS][selection]!=null && serialnos[RODCRATE_VIEWS][selection][xIndex]!=null) return xIndex+5;
00385 return -1;
00386 }
00387
00388 public ModuleCell getCell(int viewCategory, int sctView, int x, int y) {
00389
00390
00391
00392
00393 if(viewCategory<0 || sctView<0) return null;
00394
00395 switch(viewCategory) {
00396 case SCT_VIEWS:
00397 if(sctView<4) {
00398 int yIndex = ((yOffSetCount[sctView]+barrelRows[sctView])*boxHeight - y + yOffSet)/boxHeight;
00399 if(yIndex<0 || yIndex>barrelRows[sctView]-1) return null;
00400 int diff = x -maxWidth/2;
00401
00402 int xIndex = diff/boxWidth;
00403 if(diff>0 && xIndex==0) return null;
00404
00405
00406 xIndex*=-1;
00407 xIndex+=6;
00408
00409
00410
00411 if(xIndex<0 || xIndex>11) return null;
00412 if(serialnos[SCT_VIEWS]!=null && serialnos[viewCategory][sctView]!=null && serialnos[viewCategory][sctView][yIndex]!=null && serialnos[viewCategory][sctView][yIndex][xIndex]!=null) {
00413 return (ModuleCell) moduleCellMap.get(serialnos[viewCategory][sctView][yIndex][xIndex]);
00414 }
00415 }
00416 else {
00417
00418
00419 for (Iterator i=orderedList[viewCategory][sctView].iterator(); i.hasNext(); ) {
00420 String sn = (String) i.next();
00421 ModuleCell thisCell = (ModuleCell)moduleCellMap.get(sn);
00422 if(thisCell.getPolygon(viewCategory).contains(x,y)) return thisCell;
00423 }
00424 }
00425 break;
00426 case RODCRATE_VIEWS:
00427 int ww = rcBoxWidth + rcBoxGap;
00428 int midPoint = midX + rcXOffSet;
00429 int yIndex = 47 - (y - yOffSet - rcYOffSet)/boxHeight;
00430 if(yIndex<0 || yIndex>47) return null;
00431
00432 int diff = x - midPoint;
00433 diff += 8*ww;
00434 int xIndex = diff/ww;
00435 if(xIndex<0 || xIndex>16) return null;
00436 int xdiff = midPoint - 8*(rcBoxWidth+rcBoxGap) + xIndex*(rcBoxWidth+rcBoxGap);
00437 if(x-xdiff<rcBoxGap) return null;
00438 if(serialnos[RODCRATE_VIEWS]!=null && serialnos[RODCRATE_VIEWS][sctView]!=null && serialnos[viewCategory][sctView][xIndex]!=null && serialnos[viewCategory][sctView][xIndex][yIndex]!=null) {
00439 return (ModuleCell) moduleCellMap.get(serialnos[RODCRATE_VIEWS][sctView][xIndex][yIndex]);
00440 }
00441 break;
00442 default:
00443 }
00444
00445 return null;
00446 }
00447
00448 public Set getSerialNumberList(int viewCategory, int sctView) {
00449 if(viewCategory==-1 || sctView==-1) return new TreeSet();
00450 if(orderedList[viewCategory]==null || orderedList[viewCategory][sctView]==null) {
00451 System.out.println("SctGUI::ConfigurationInterface null orderedlist");
00452 return new TreeSet();
00453 }
00454 return orderedList[viewCategory][sctView];
00455 }
00456
00457 public Set[] buildSerialNumberMap() {
00458 Set[] serialNumberMap = new HashSet[sctViews];
00459 for(int i=0;i<sctViews;i++) serialNumberMap[i] = new HashSet(getSerialNumberList(SCT_VIEWS,i));
00460 return serialNumberMap;
00461 }
00462
00463 public int getNumberOfModules(int viewCategory, int sctView) {
00464 return orderedList[viewCategory][sctView].size();
00465 }
00466 public int getTotalNumberOfModules() {
00467 return moduleCount;
00468 }
00469 public ModuleCell getModuleCell(String serialNo) {
00470 return (ModuleCell)moduleCellMap.get(serialNo);
00471 }
00472
00473 public void drawRodCrateViewOutline(java.awt.Graphics2D g2, int selection) {
00474 g2.setColor(java.awt.Color.lightGray);
00475 g2.setFont(displayTextFont);
00476 java.awt.FontMetrics metrics = g2.getFontMetrics();
00477 int rowNo=0;
00478 int ww = rcBoxWidth + rcBoxGap;
00479
00480 int thisXOffSet = midX + rcXOffSet - 8*ww + rcBoxGap;
00481 int thisYOffSet = yOffSet + rcYOffSet;
00482 int timX = thisXOffSet+1+8*ww;
00483 int[] timPolyX = {timX,timX,timX+rcBoxWidth,timX+rcBoxWidth};
00484 int[] timPolyY = {thisYOffSet,thisYOffSet+48*boxHeight,thisYOffSet+48*boxHeight,thisYOffSet};
00485 g2.setColor(java.awt.Color.lightGray);
00486 g2.fill(new java.awt.Polygon(timPolyX,timPolyY,4));
00487 g2.setColor(java.awt.Color.black);
00488 String[] letters = {"T","I","M"," ","M","O","D","U","L","E"};
00489 for(int i=0;i<letters.length;i++) {
00490 int letterWidth = metrics.stringWidth(letters[i]);
00491 int xlabel = timX+rcBoxWidth/2-letterWidth/2;
00492 int ylabel = thisYOffSet+(i+1)*20;
00493 g2.drawString(letters[i],xlabel,ylabel);
00494 }
00495
00496 g2.setColor(java.awt.Color.lightGray);
00497 for(int i=0;i<48;i++) {
00498 String rowLabel = Integer.toString(rowNo);
00499 int labelWidth = metrics.stringWidth(rowLabel);
00500 int xLabel = thisXOffSet - labelWidth - 4;
00501 for(int x=5;x<=21;x++) {
00502 if(x!=13) g2.drawRect(thisXOffSet + (x-5)*ww, thisYOffSet + (47-i)*boxHeight, rcBoxWidth, boxHeight);
00503 }
00504 g2.drawString(rowLabel,xLabel,thisYOffSet + (47-i)*boxHeight + boxHeight);
00505 rowNo++;
00506 }
00507 g2.setColor(java.awt.Color.lightGray);
00508
00509 g2.drawRect(thisXOffSet, thisYOffSet, rodSlots*ww - rcBoxGap, 48*boxHeight);
00510
00511 int ylabeloffset = thisYOffSet + 50* boxHeight;
00512
00513 boolean slots_used=false;
00514 for(int i=0;i<rodSlots;i++) {
00515 boolean slotUsed = (serialnos[RODCRATE_VIEWS]!=null && serialnos[RODCRATE_VIEWS][selection]!=null && serialnos[RODCRATE_VIEWS][selection][i]!=null);
00516 java.awt.Color labelColor = slotUsed ? java.awt.Color.black : java.awt.Color.lightGray;
00517 if(slotUsed) slots_used=true;
00518 g2.setColor(labelColor);
00519 String slot = Integer.toString(i+5);
00520 int labelWidth = metrics.stringWidth(slot);
00521 int xlabeloffset = midX + rcXOffSet - 8*ww + (i+1)*ww - rcBoxWidth/2 - labelWidth/2;
00522 g2.drawString(slot, xlabeloffset, ylabeloffset);
00523 if(slotUsed) {
00524 g2.drawRect(thisXOffSet + i*ww,thisYOffSet,rcBoxWidth,48*boxHeight);
00525 Integer theSlot = new Integer(i+5);
00526 if(slotMap[selection].containsKey(theSlot)) {
00527 String sampleSerialNo = (String)slotMap[selection].get(theSlot);
00528 String rodno = getSNInfo(sampleSerialNo,SNInfo.ROD_NUMBER);
00529 labelWidth = metrics.stringWidth(rodno);
00530 xlabeloffset = midX + rcXOffSet - 8*ww + (i+1)*ww - rcBoxWidth/2 - labelWidth/2;
00531 g2.drawString(rodno,xlabeloffset,ylabeloffset+boxHeight+10);
00532 }
00533 }
00534 }
00535 java.awt.Color labelColor = slots_used ? java.awt.Color.black : java.awt.Color.lightGray;
00536 g2.setColor(labelColor);
00537 String slotString = "Slot:";
00538 g2.drawString(slotString,thisXOffSet - 4 - metrics.stringWidth(slotString),ylabeloffset);
00539 slotString = "ID:";
00540 g2.drawString(slotString,thisXOffSet - 4 - metrics.stringWidth(slotString),ylabeloffset+boxHeight+10);
00541 }
00542
00543 public void drawViewOutline(java.awt.Graphics2D g2,int viewCategory, int selection) {
00544 switch(viewCategory) {
00545 case SCT_VIEWS:
00546 drawSCTViewOutline(g2,selection);
00547 break;
00548 case RODCRATE_VIEWS:
00549 drawRodCrateViewOutline(g2,selection);
00550 break;
00551 default:
00552 }
00553 }
00554
00555 public void drawSCTViewOutline(java.awt.Graphics2D g2, int selection) {
00556 g2.setColor(java.awt.Color.lightGray);
00557 g2.setFont(displayTextFont);
00558 java.awt.FontMetrics metrics = g2.getFontMetrics();
00559 int rowNo=0;
00560
00561 switch(selection) {
00562 case Barrel3:
00563 case Barrel4:
00564 case Barrel5:
00565 case Barrel6:
00566 int ilow = yOffSetCount[selection];
00567
00568 int ihigh = ilow+barrelRows[selection];
00569 int midX= maxWidth/2;
00570
00571
00572 for(int y=ihigh-1;y>=ilow;y--) {
00573 String rowLabel = Integer.toString(rowNo);
00574 int labelWidth = metrics.stringWidth(rowLabel);
00575 int xLabel = midX - 6*boxWidth - labelWidth -8;
00576
00577 int thisRow = rowNo;
00578
00579 boolean rowUsed = (serialnos[SCT_VIEWS]!=null && serialnos[SCT_VIEWS][selection]!=null && serialnos[SCT_VIEWS][selection][thisRow]!=null);
00580 g2.setColor(java.awt.Color.lightGray);
00581 for(int x=-6;x<=6;x++) {
00582 if(x==0) continue;
00583 g2.drawRect(midX+(boxWidth*x),yOffSet+(y*boxHeight), boxWidth, boxHeight);
00584 }
00585 java.awt.Color labelColor = rowUsed ? java.awt.Color.black : java.awt.Color.lightGray;
00586 g2.setColor(labelColor);
00587 g2.drawString(rowLabel,xLabel,yOffSet+y*boxHeight+boxHeight);
00588 rowNo++;
00589 }
00590 g2.setColor(java.awt.Color.lightGray);
00591 g2.drawRect(midX - 6*boxWidth, yOffSet, 13*boxWidth, 56*boxHeight);
00592
00593
00594 int x1 = midX-100;
00595 int x2 = midX+120;
00596
00597
00598 int y1 = yOffSet + 58*boxHeight;
00599
00600 g2.drawLine(x1,y1,x2,y1);
00601 g2.drawLine(x1,y1,x1+5,y1-5);
00602 g2.drawLine(x1,y1,x1+5,y1+5);
00603 g2.drawLine(x2,y1,x2-5,y1-5);
00604 g2.drawLine(x2,y1,x2-5,y1+5);
00605 g2.drawString("Z+",x1-20,y1);
00606 g2.drawString("Z-",x2+10,y1);
00607 break;
00608 case EndCap1a:
00609 case EndCap1c:
00610 case EndCap7a:
00611 case EndCap7c:
00612 case EndCap8a:
00613 case EndCap8c:
00614 for(int quadrant=0;quadrant<4;quadrant++) {
00615 for(int number=13;number<23;number++) {
00616 calculateSCTPolygon(selection,quadrant,number);
00617 if(polygon!=null) {
00618 g2.setColor(java.awt.Color.white);
00619 g2.fill(polygon);
00620 g2.setColor(java.awt.Color.lightGray);
00621 g2.draw(polygon);
00622 }
00623 }
00624 }
00625 for(int quadrant=0;quadrant<4;quadrant++) {
00626 for(int number=0;number<13;number++) {
00627 calculateSCTPolygon(selection,quadrant,number);
00628 if(polygon!=null) {
00629 g2.setColor(java.awt.Color.white);
00630 g2.fill(polygon);
00631 g2.setColor(java.awt.Color.lightGray);
00632 g2.draw(polygon);
00633 }
00634 }
00635 }
00636 break;
00637 case EndCap2a:
00638 case EndCap2c:
00639 case EndCap3a:
00640 case EndCap3c:
00641 case EndCap4a:
00642 case EndCap4c:
00643 case EndCap5a:
00644 case EndCap5c:
00645 case EndCap6a:
00646 case EndCap6c:
00647 for(int quadrant=0;quadrant<4;quadrant++) {
00648 for(int number=13;number<23;number++) {
00649 calculateSCTPolygon(selection,quadrant,number);
00650 if(polygon!=null) {
00651 g2.setColor(java.awt.Color.white);
00652 g2.fill(polygon);
00653 g2.setColor(java.awt.Color.lightGray);
00654 g2.draw(polygon);
00655 }
00656 }
00657 }
00658 for(int quadrant=0;quadrant<4;quadrant++) {
00659 for(int number=0;number<33;number++) {
00660 if(number>=13 && number<23) continue;
00661 calculateSCTPolygon(selection,quadrant,number);
00662 if(polygon!=null) {
00663 g2.setColor(java.awt.Color.white);
00664 g2.fill(polygon);
00665 g2.setColor(java.awt.Color.lightGray);
00666 g2.draw(polygon);
00667 }
00668 }
00669 }
00670 break;
00671 case EndCap9a:
00672 case EndCap9c:
00673 for(int quadrant=0;quadrant<4;quadrant++) {
00674 for(int number=0;number<13;number++) {
00675 calculateSCTPolygon(selection,quadrant,number);
00676 if(polygon!=null) g2.draw(polygon);
00677 }
00678 }
00679 break;
00680 default:
00681
00682 }
00683
00684
00685 }
00686
00687 private void calculateRodCratePolygon(int slot, int channel) {
00688 int ww = rcBoxWidth+rcBoxGap;
00689 int xloc = maxWidth/2 - 8*ww + (slot-5)*ww + rcBoxGap + rcXOffSet;
00690 int yloc = yOffSet + rcYOffSet + (47-channel)*boxHeight;
00691 xPoints[0] = xPoints[1] = xloc;
00692 xPoints[2] = xPoints[3] = xloc+rcBoxWidth;
00693 yPoints[0] = yPoints[3] = yloc;
00694 yPoints[1] = yPoints[2] = yloc+boxHeight;
00695 polygon = new java.awt.Polygon(xPoints,yPoints,4);
00696 return;
00697 }
00698
00699 private void calculateSCTPolygon(int view, int quadrant, int number) {
00700
00701 if(view<4) {
00702
00703
00704
00705 int xloc=maxWidth/2 - number*boxWidth;
00706
00707 int yloc = yOffSet + (yOffSetCount[view] + barrelRows[view] - quadrant - 1)*boxHeight;
00708
00709
00710 xPoints[0] = xPoints[1] = xloc;
00711 xPoints[2] = xPoints[3] = xloc+boxWidth;
00712 yPoints[0] = yPoints[3] = yloc;
00713 yPoints[1] = yPoints[2] = yloc+boxHeight;
00714 polygon = new java.awt.Polygon(xPoints,yPoints,4);
00715 return;
00716 }
00717
00718
00719 double thetaOffset=0.;
00720 double theta=0.;
00721 int rindex=0;
00722 int segment=0;
00723 int modules=0;
00724 if(number<13) {
00725 thetaOffset = Math.PI/52.;
00726 theta = Math.PI/26.;
00727 rindex=4;
00728 segment=number;
00729 modules=13;
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 }
00744 else if(number>=13 && number<23) {
00745 thetaOffset=0.;
00746 theta = Math.PI/20.;
00747 rindex=2;
00748 segment=number-13;
00749 modules=10;
00750 }
00751 else {
00752 thetaOffset=Math.PI/40.;
00753 theta = Math.PI/20.;
00754 rindex=0;
00755 segment=number-23;
00756 modules=10;
00757 }
00758 segment += quadrant*modules;
00759
00760 xPoints[0] = midX+(int)(radius[rindex]*Math.sin(segment*theta+thetaOffset));
00761 xPoints[1] = midX+(int)(radius[rindex]*Math.sin((segment+1)*theta+thetaOffset));
00762 xPoints[2] = midX+(int)(radius[rindex+1]*Math.sin((segment+1)*theta+thetaOffset));
00763 xPoints[3] = midX+(int)(radius[rindex+1]*Math.sin(segment*theta+thetaOffset));
00764
00765 yPoints[0] = midY-(int)(radius[rindex]*Math.cos(segment*theta+thetaOffset));
00766 yPoints[1] = midY-(int)(radius[rindex]*Math.cos((segment+1)*theta+thetaOffset));
00767 yPoints[2] = midY-(int)(radius[rindex+1]*Math.cos((segment+1)*theta+thetaOffset));
00768 yPoints[3] = midY-(int)(radius[rindex+1]*Math.cos(segment*theta+thetaOffset));
00769 polygon = new java.awt.Polygon(xPoints,yPoints,4);
00770
00771 }
00772
00773 public void updateModuleGroups(List cellList) {
00774 for(int i=0;i<cellList.size();i++) {
00775 ModuleCell thisCell = (ModuleCell)cellList.get(i);
00776 try {
00777 SystemInterface.getInstance().getConfigurationService().setModuleGroup(thisCell.getSerialNo(),(short)thisCell.getModuleGroup());
00778 }catch(Exception e){System.err.println("Exception setting modulegroup for module "+thisCell.getSerialNo()+" : "+e.toString());}
00779 }
00780 }
00781 private void writeLookUpTable() {
00782 String directory = Preferences.PreferencesInterface.getInstance().getPreference(Preferences.PreferencesInterface.WEB_LOOKUP_DIR);
00783 if(directory.equals(Preferences.PreferencesInterface.unDefinedString)) return;
00784
00785
00786
00787 for(int i=0;i<SCTViewNames.length;i++) {
00788 Map lookupMap = new HashMap();
00789 Set moduleList = getSerialNumberList(SCT_VIEWS,i);
00790 for (java.util.Iterator m = moduleList.iterator(); m.hasNext(); ) {
00791 String thisSN=(String)m.next();
00792 ModuleCell thisCell = getModuleCell(thisSN);
00793 String desc = SCTViewNames[i]+", Row "+thisCell.getRow()+", Position "+thisCell.getPosition();
00794 lookupMap.put(thisSN,desc);
00795 }
00796 if(lookupMap.size()>0) saveLookUpMap(i,directory,lookupMap);
00797 }
00798
00799 }
00800 private Map getLookUpMap(String directory) {
00801 Map thisMap = new HashMap();
00802 java.util.regex.Pattern p = java.util.regex.Pattern.compile("(\\d{14})=(.*)");
00803 java.io.File lookupFile = new java.io.File(directory,"moduleMap.txt");
00804 try {
00805 if(lookupFile.exists()) {
00806 java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(lookupFile));
00807 String line;
00808 while((line=in.readLine())!=null) {
00809 java.util.regex.Matcher matcher = p.matcher(line);
00810 if(matcher.matches()) thisMap.put(line.substring(matcher.start(1),matcher.end(1)),line.substring(matcher.start(2),matcher.end(2)));
00811 }
00812 in.close();
00813 }
00814 }catch(Exception e){System.err.println("SctGUI::ConfigurationInterface - Exception reading in "+lookupFile.getName()+" - "+e.toString());}
00815 return thisMap;
00816 }
00817 private void saveLookUpMap(int view,String directory,Map thisMap) {
00818 java.io.File lookupFile = new java.io.File(directory,"moduleMap"+Integer.toString(view)+".txt");
00819 int lineCount=0;
00820 try {
00821 java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(lookupFile));
00822 String line;
00823 for (Iterator i=thisMap.entrySet().iterator(); i.hasNext(); ) {
00824 Map.Entry e = (Map.Entry) i.next();
00825 out.write((String)e.getKey()+"="+(String)e.getValue());
00826 out.newLine();
00827 lineCount++;
00828 }
00829 out.close();
00830
00831 }catch(Exception e){System.err.println("SctGUI::ConfigurationInterface - Exception writing to "+lookupFile.getName()+" - "+e.toString());}
00832 }
00833
00834
00835
00836
00837
00838
00839
00840
00841 }