package osp; import java.awt.geom.Point2D; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.text.DecimalFormat; import java.util.Iterator; import jsky.coords.WorldCoords; import jsky.image.gui.ImageCoordinateConverter; import org.jdom.Attribute; import org.jdom.Element; import org.jdom.Document; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import osp.ui.OSPE_MainFrame; import osp.utils.CustomJDialog; /** * Class used to save the properties of a mask or a project in an XML file. */ public class Writer { // Attributes // ----------- /** The field of view */ private FieldOfView fov; /** Parent: main frame */ private OSPE_MainFrame pater; private ImageCoordinateConverter icc; // Constructors // ----------- /** * Constructs a new writer. * * @param p * Main frame of the application. * @param fov2 * Field of view of the application */ public Writer(OSPE_MainFrame p, FieldOfView fov) { pater = p; this.fov = fov; icc = new ImageCoordinateConverter(pater.getVisuPanel().getNavigatorImageDisplay()); } // Methods // ----------- /** * Writes all the project components and their properties in an XML file : * images, objects, masks, and slits. * * @param fileName * File name of the project. */ public void write(String fileName) { Element fieldOfView = new Element("fieldOfView"); Document document = new Document(fieldOfView); Attribute path = new Attribute("path", fov.getCompletePath()); fieldOfView.setAttribute(path); Attribute selectedImage = new Attribute("selectedImage", String.valueOf(fov .getSelectedImage())); fieldOfView.setAttribute(selectedImage); // Images loop for (int i = 0; i < fov.getNbrImages(); i++) { Image im = fov.getImage(i); fieldOfView.addContent(writeImageObjectsMasksAndSlits(im)); } // Write in the XML file save(fileName, document); }// End write /** * Writes XML file on the disk with * - if it's a project : the list of the images, all the masks descriptions and objects. * - if it's a mask : save the mask description with the references objects. * * @param fileM * Name of the XML file * @param doc * The document to write. */ static void save(String fileM, Document doc) { try { XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); // Notice that you can simply create an instance of FileOutputStream // with the name of the file for the serialization. sortie.output(doc, new FileOutputStream(fileM)); } catch (java.io.IOException e) { } } /** * Get all the image components : objects and masks. * @param image : current image * @return e_image : image element */ private Element writeImageObjectsMasksAndSlits(Image image) { Element e_AllIm=new Element("image"); writeImageAndProperties(e_AllIm,image); if (image.getNbrMasks()>0) { // Masks loop for (int j = 0; j < image.getNbrMasks(); j++) { Mask mask = image.getMask(j); writeMaskAndProperties(e_AllIm, mask); } } if (image.getNbrObjects()>0) { Element e_objectsList = new Element("objectsList"); e_AllIm.addContent(e_objectsList); // Objects loop for (Iterator itr = image.getListObjects().iterator(); itr.hasNext();) { SkyObject sk = itr.next(); writeProjectObjects(e_objectsList, sk); } } return (e_AllIm); } /** * Get the image properties : center, scale, resolution, color and cut levels if there are. * @param e_image : image element * @param im : current image */ private void writeImageAndProperties(Element e_image, Image im) { //Element e_image = new Element("image"); Attribute absPath = new Attribute("absPath", im.getAbsPath()); e_image.setAttribute(absPath); Attribute selectedMask = new Attribute("selectedMask", String.valueOf(im .getSelectedMask())); e_image.setAttribute(selectedMask); // Image name and catalog from (if there is) String imName=null; String imCat=null; Element e_imName = new Element("imageName"); Element e_imCatalog = new Element("imageCatalog"); imName=im.getImName(); imCat=im.getImageCatalog(); e_imName.setText(imName); e_imCatalog.setText(imCat); e_image.addContent(e_imName); e_image.addContent(e_imCatalog); /** Image center to reload the project */ Element e_imCenter = new Element("center"); Element e_imCenterX = new Element("x"); e_imCenterX.setText(String.valueOf(im.getCenter().getX())); Element e_imCenterY = new Element("y"); e_imCenterY.setText(String.valueOf(im.getCenter().getY())); e_imCenter.addContent(e_imCenterX); e_imCenter.addContent(e_imCenterY); e_image.addContent(e_imCenter); /** Image coordinates in RA-DEC J2000 */ Element e_imCoord = new Element("coordinates"); Element e_imCoordX = new Element("ra"); e_imCoordX.setText(String.valueOf(im.getAlpha())); Element e_imCoordY = new Element("dec"); e_imCoordY.setText(String.valueOf(im.getDelta())); e_imCoord.addContent(e_imCoordX); e_imCoord.addContent(e_imCoordY); e_image.addContent(e_imCoord); // Image scale Element e_scale = new Element("scale"); e_scale.setText(String.valueOf(im.getScale())); e_image.addContent(e_scale); // Image resolution Element e_resol = new Element("resol"); e_resol.setText(String.valueOf(im.getResol())); e_image.addContent(e_resol); // If there are cuts levels defined: if (String.valueOf(im.getLowCut())!= null) { Element e_lowCut = new Element("lowCut"); e_lowCut.setText(String.valueOf(im.getLowCut())); e_image.addContent(e_lowCut); } if (String.valueOf(im.getHighCut())!= null) { Element e_highCut = new Element("highCut"); e_highCut.setText(String.valueOf(im.getHighCut())); e_image.addContent(e_highCut); } // Test if the image colors have been modified and saved them if (im.colorsChanged) { String cMap = im.getColorMap(); String cIntens=im.getColorIntensity(); int cAlgo=im.getColorAlgorithm(); if (cMap != null) { Element e_colorMap = new Element("colorMap"); e_colorMap.setText(cMap); e_image.addContent(e_colorMap); } if (cIntens != null) { Element e_colorIntens = new Element("colorIntensity"); e_colorIntens.setText(cIntens); e_image.addContent(e_colorIntens); } Element e_colorAlgo = new Element("colorAlgo"); e_colorAlgo.setText(String.valueOf(cAlgo)); e_image.addContent(e_colorAlgo); } // Fi colorChanged } /** * Write a mask on disk with all the slits description and the reference objects needed. * @param m - Mask * @param fileName - mask file name */ public void writeMask(Mask m, String fileName) { Document document = new Document(writeMaskAndProperties(m)); // Write to the XML file save(fileName, document); } /** * Write the mask and its properties * Called when saving a mask only * @param m : Current Mask * @return */ private Element writeMaskAndProperties(Mask m) { boolean onlyMask=true; Element e_mask = new Element("mask"); Attribute maskValidation = new Attribute("validated", String.valueOf(m.validated)); e_mask.setAttribute(maskValidation); Attribute selectedSlit = new Attribute("selectedSlit", String.valueOf(m.getSelectedSlit())); e_mask.setAttribute(selectedSlit); String mUUID=m.getS_uuid(); if (mUUID.isEmpty()) m.setM_uuid(); Element e_maskUUID = new Element("maskUUID"); e_maskUUID.setText(m.getS_uuid()); e_mask.addContent(e_maskUUID); // Mask alpha delta Coord in degree. Element e_maskAlpha = new Element("alpha"); e_maskAlpha.setText(String.valueOf(m.getCenterDeg().getX())); e_mask.addContent(e_maskAlpha); Element e_maskDelta = new Element("delta"); e_maskDelta.setText(String.valueOf(m.getCenterDeg().getY())); e_mask.addContent(e_maskDelta); Element e_maskAngle = new Element("angle"); e_maskAngle.setText(String.valueOf(m.getOmega())); e_mask.addContent(e_maskAngle); /** Mask coordinates RA - DEC **/ Element e_maskCoord = new Element("maskCoord"); Element e_maskCoordX = new Element("ra"); e_maskCoordX.setText(m.getAlpha().toString()); Element e_maskCoordY = new Element("dec"); e_maskCoordY.setText(m.getDelta().toString()); e_maskCoord.addContent(e_maskCoordX); e_maskCoord.addContent(e_maskCoordY); e_mask.addContent(e_maskCoord); /** Mask Coordinates RA - DEC left up corner **/ Element e_maskCoord_leftd = new Element("maskCoordLeftCorner"); Element e_maskCoord_leftdX = new Element("ra"); Element e_maskCoord_leftdY = new Element("dec"); if ((m.getAlphaCorner().getVal() != 0.0) || (m.getDeltaCorner().getVal() != 0.0)) { e_maskCoord_leftdX.setText(m.getAlphaCorner().toString()); e_maskCoord_leftdY.setText(m.getDeltaCorner().toString()); } else { e_maskCoord_leftdX.setText("0.0"); e_maskCoord_leftdY.setText("0.0"); } e_maskCoord_leftd.addContent(e_maskCoord_leftdX); e_maskCoord_leftd.addContent(e_maskCoord_leftdY); e_mask.addContent(e_maskCoord_leftd); //writeRefObjects(m, e_mask); writeSlits(m, e_mask, onlyMask); return (e_mask); } /** * Write mask from a project when saving the project. * @param e_im : parent element (image) * @param m : Current Mask */ private void writeMaskAndProperties(Element e_im, Mask m) { boolean isOnlyAMask=false; Element e_mask = new Element("mask"); e_im.addContent(e_mask); Attribute maskValidation = new Attribute("validated", String.valueOf(m.validated)); e_mask.setAttribute(maskValidation); Attribute selectedSlit = new Attribute("selectedSlit", String.valueOf(m.getSelectedSlit())); e_mask.setAttribute(selectedSlit); // Element e_maskUUID = new Element("maskUUID"); // e_maskUUID.setText(m.getS_uuid()); // e_mask.addContent(e_maskUUID); // Mask properties in the image selected /** Mask coordinates RA - DEC */ Element e_maskCoord = new Element("maskCoord"); Element e_maskCoordX = new Element("ra"); e_maskCoordX.setText(m.getAlpha().toString()); Element e_maskCoordY = new Element("dec"); e_maskCoordY.setText(m.getDelta().toString()); e_maskCoord.addContent(e_maskCoordX); e_maskCoord.addContent(e_maskCoordY); e_mask.addContent(e_maskCoord); /** Mask Coordinates RA - DEC left up corner **/ if ((m.getAlphaCorner().getVal() != 0.0) || (m.getDeltaCorner().getVal() != 0.0)) { Element e_maskCoord_leftd = new Element("maskCoordLeftCorner"); Element e_maskCoord_leftdX = new Element("ra"); Element e_maskCoord_leftdY = new Element("dec"); e_maskCoord_leftdX.setText(m.getAlphaCorner().toString()); e_maskCoord_leftdY.setText(m.getDeltaCorner().toString()); e_maskCoord_leftd.addContent(e_maskCoord_leftdX); e_maskCoord_leftd.addContent(e_maskCoord_leftdY); e_mask.addContent(e_maskCoord_leftd); } Element e_maskCenter = new Element("center"); Element e_maskCenterX = new Element("x"); e_maskCenterX.setText(String.valueOf(m.getCenter().getX())); Element e_maskCenterY = new Element("y"); e_maskCenterY.setText(String.valueOf(m.getCenter().getY())); e_maskCenter.addContent(e_maskCenterX); e_maskCenter.addContent(e_maskCenterY); e_mask.addContent(e_maskCenter); Element e_maskAlpha = new Element("alpha"); e_maskAlpha.setText(String.valueOf(m.getAlphaDouble())); e_mask.addContent(e_maskAlpha); Element e_maskDelta = new Element("delta"); e_maskDelta.setText(String.valueOf(m.getDeltaDouble())); e_mask.addContent(e_maskDelta); Element e_maskAngle = new Element("angle"); e_maskAngle.setText(String.valueOf(m.getOmega())); e_mask.addContent(e_maskAngle); writeSlits(m, e_mask, isOnlyAMask); } /** * Write reference objects in a mask file * @param m - mask * @param e_mask - xml element for the mask contain */ // private void writeRefObjects(Mask m, Element e_mask) // { // // Reference objects loop // for (Iterator itr = m.getRefObjectsList().iterator(); itr.hasNext();) // { // SkyObject sk = itr.next(); // // Element e_refObjects = new Element("refObject"); // e_mask.addContent(e_refObjects); // writeObjPosition(e_refObjects, sk, true); // writeObjFrom(sk, e_refObjects); // // } // End objects loop // // } /** * Write the slits specifications * @param m : current mask * @param e_mask : mask element * @param onlyMask : flag if it's only a mask or a project part. * If this flag is not true, an element is added if it'a affected and with the object id */ private void writeSlits(Mask m, Element e_mask, boolean onlyMask) { Element e_slitsList = new Element("slitsList"); e_mask.addContent(e_slitsList); // Slits loop for (int k = 0; k < Mask._NBRSLITS_; k++) { Slit curSlit=m.getSlit(k); Element e_slit = new Element("slit"); /** If aperture and position != 0, then the slit is used **/ if ((curSlit.getPosition()!= 0.0) || (curSlit.getAperture()!=0.0)) { e_slitsList.addContent(e_slit); int idSlit=curSlit.getId()+1; Attribute id = new Attribute("id", String.valueOf(idSlit)); e_slit.setAttribute(id); Element e_position = new Element("position"); double slitPosition = curSlit.getPosition(); e_position.setText(String.valueOf(slitPosition)); e_slit.addContent(e_position); Element e_width = new Element("width"); e_width.setText(String.valueOf(curSlit.getAperture())); e_slit.addContent(e_width); if ((slitPosition != 0.0) && (curSlit.getAperture()>0) && curSlit.fSkyCoord ) { /** slit coordinates RA - DEC in HMS / DMS format */ Element e_slitCoord = new Element("slitCoord"); Element e_slitCoordX = new Element("ra"); e_slitCoordX.setText(curSlit.getWcPosCenter().getRA().toString()); Element e_slitCoordY = new Element("dec"); e_slitCoordY.setText(curSlit.getWcPosCenter().getDec().toString()); e_slitCoord.addContent(e_slitCoordX); e_slitCoord.addContent(e_slitCoordY); e_slit.addContent(e_slitCoord); /** slit coordinates RA - DEC in degree */ Element e_slitDegCoord = new Element("slitDegCoord"); WorldCoords wc = new WorldCoords(curSlit.getWcPosCenter().getRaDeg(),curSlit.getWcPosCenter().getDecDeg()); Element e_slitCoordDegX = new Element("raDeg"); e_slitCoordDegX.setText(String.valueOf(wc.getRaDeg())); Element e_slitCoordDegY = new Element("decDeg"); e_slitCoordDegY.setText(String.valueOf(wc.getDecDeg())); e_slitDegCoord.addContent(e_slitCoordDegX); e_slitDegCoord.addContent(e_slitCoordDegY); e_slit.addContent(e_slitDegCoord); boolean isJoined = curSlit.isJoined(); if (isJoined) { Element e_joined = new Element("isJoined"); e_joined.setText(String.valueOf(isJoined)); e_slit.addContent(e_joined); int joinedRefSlitId =-1; joinedRefSlitId = curSlit.getJoinedRefSlit()+1; Element e_joinedSlit = new Element("joinedRefSlit"); e_joinedSlit.setText(String.valueOf(joinedRefSlitId)); e_slit.addContent(e_joinedSlit); } } Element e_affObject = new Element("affectedObject"); int numObject=0; numObject=m.getSlit(k).getAffectedObject(); //WorldCoords wcObj = new WorldCoords(0,0); if (numObject>0) { if (!onlyMask) { e_affObject.setText(String.valueOf(numObject)); } else { SkyObject sk= fov.getCurrentImage().getListObjects().get(numObject); Element e_objId = new Element("ObjectId"); e_objId.setText(sk.getTargetId()); e_affObject.addContent(e_objId); Element e_objCoord = new Element("objCoord"); writeObjPosition(e_objCoord, sk, true); e_affObject.addContent(e_objCoord); Element e_objComments = new Element("Comments"); writeObjFrom(sk, e_objComments); e_affObject.addContent(e_objComments); if (sk.isRef()) { Element e_objIsRef = new Element("IsReference"); e_objIsRef.setText("true"); e_affObject.addContent(e_objIsRef); } } e_slit.addContent(e_affObject); } // Fi numObject>0 } // Fi Slit positionned } // End slits loop } /** * Write the object position in degree for the reference objects with a mask. * @param e_obj : object element. * @param sk : skyObject descriptor. * @param from : 0 - from project - write position in canvas coord * 1 - from mask -write position in degrees world coord */ private void writeObjPosition(Element e_obj, SkyObject sk, boolean from) { Element e_position = new Element("position"); Point2D.Double position = new Point2D.Double(sk.getPosPix().getX(), sk.getPosPix() .getY()); // if writing a mask, conversion from displayed coord (Canvas) to world position if (from) icc.imageToWorldCoords(position, false); Element e_positionX = new Element("x"); e_positionX.setText(String.valueOf(position.x)); e_position.addContent(e_positionX); Element e_positionY = new Element("y"); e_positionY.setText(String.valueOf(position.y)); e_position.addContent(e_positionY); e_obj.addContent(e_position); /** Object coordinates RA - DEC */ Element e_objCoord = new Element("objCoord"); Element e_objCoordX = new Element("ra"); e_objCoordX.setText(sk.getObjWorldCenter().getRA().toString()); Element e_objCoordY = new Element("dec"); e_objCoordY.setText((sk.getObjWorldCenter().getDec().toString())); e_objCoord.addContent(e_objCoordX); e_objCoord.addContent(e_objCoordY); e_obj.addContent(e_objCoord); if (sk.isCenterRecalc()) { Element e_newPosition = new Element("newPosition"); Point2D.Double newPosition = new Point2D.Double(sk.getPosPixRecalc().getX(), sk .getPosPixRecalc().getY()); icc.imageToWorldCoords(newPosition, false); Element e_newPositionX = new Element("x"); e_newPositionX.setText(String.valueOf(newPosition.x)); e_newPosition.addContent(e_newPositionX); Element e_newPositionY = new Element("y"); e_newPositionY.setText(String.valueOf(newPosition.y)); e_newPosition.addContent(e_newPositionY); e_obj.addContent(e_newPosition); /** Object coordinates RA - DEC */ Element e_objNewCoord = new Element("objNewCoord"); Element e_objNewCoordX = new Element("ra"); e_objNewCoordX.setText(sk.getObjWorldRecalc().getRA().toString()); Element e_objNewCoordY = new Element("dec"); e_objNewCoordY.setText(sk.getObjWorldRecalc().getDec().toString()); e_objNewCoord.addContent(e_objNewCoordX); e_objNewCoord.addContent(e_objNewCoordY); e_obj.addContent(e_objNewCoord); } } /** * Write the objects of the project * The coordinates are only in the project references. * @param e_objectsList : objects element * @param sk : SkyObject descriptor */ private void writeProjectObjects(Element e_objectsList, SkyObject sk ) { Element e_skyObjects = new Element("skyObject"); e_objectsList.addContent(e_skyObjects); /* This id is the object num in the project*/ Attribute id = new Attribute("id", String.valueOf(sk.getNum())); e_skyObjects.setAttribute(id); /* This id is the id object when loaded from catalog */ Attribute idCat = new Attribute("idCat", String.valueOf(sk.getTargetId())); e_skyObjects.setAttribute(idCat); /* This is the catalog group when loaded from catalog */ Attribute group = new Attribute("group", String.valueOf(sk.getGroup())); e_skyObjects.setAttribute(group); Attribute isRef = new Attribute("isRef", String.valueOf(sk.isRef())); e_skyObjects.setAttribute(isRef); writeObjFrom(sk, e_skyObjects); Element e_priority = new Element("priority"); e_priority.setText(String.valueOf(sk.getPriority())); e_skyObjects.addContent(e_priority); writeObjPosition(e_skyObjects, sk, false); } private void writeObjFrom(SkyObject sk, Element e_skyObjects) { // TODO Auto-generated method stub // Element e_from = new Element("from"); // e_from.setText(String.valueOf(sk.getNbCat())); // e_skyObjects.addContent(e_from); Element e_fromLib = new Element("libelleFrom"); String libFrom=String.valueOf(sk.getProperty()); if (libFrom.equals("")) libFrom=" "; e_fromLib.setText(libFrom); e_skyObjects.addContent(e_fromLib); } /** * Save the image objects list in a file. * @param im : current image * @param filename : created file * @return */ public boolean writeLocalCatalog(Image im, String filename) { boolean noError=true; File ff=null; ff=new File(filename); FileWriter ffw=null; try { ffw=new FileWriter(ff); if (im.getNbrObjects()>0) { SkyObject sk; // Objects loop for (Iterator itr = im.getListObjects().iterator(); itr.hasNext();) { sk = itr.next(); ffw.write(String.valueOf(sk.getNum())); ffw.write("\t"); ffw.write(sk.getObjWorldCenter().getRA().toString()); ffw.write("\t"); ffw.write(sk.getObjWorldCenter().getDec().toString()); ffw.write("\t"); ffw.write(String.valueOf(sk.getPriority())); ffw.write("\t"); ffw.write(String.valueOf(sk.getProperty())); ffw.write("\n"); } } ffw.close(); } catch (Exception e) { noError = false; String loadError = "Error wrinting local objects catalog !"; new CustomJDialog(loadError, CustomJDialog._ERROR_,CustomJDialog._CLOSE_BUTTON_, pater); // System.out.println("Could not create file ! "); } finally { try { if (ffw != null) ffw.close(); } catch (IOException e) { noError = false; e.printStackTrace(); } } return noError; } /** * Save the image objects list in a file. * @param im : current image * @param filename : created file * @return */ public boolean writeSlitsLocation( String fileName, String [][] slitsArray, Mask curMask, double IpaOffset) { boolean noError=true; File ff=null; fileName=fileName+".csu"; ff=new File(fileName); FileWriter ffw=null; double angle=curMask.getOmega()+ IpaOffset; WorldCoords wc=new WorldCoords(curMask.getAlpha(),curMask.getDelta()); String entete="RA : "+wc.getRA().toString()+" Dec :"+wc.getDec().toString()+" Angle+offset "+String.valueOf(angle); String uuid=curMask.getS_uuid(); entete = entete+"\n"+"# Mask_ID : "+uuid; try { ffw=new FileWriter(ff); ffw.write("# "); ffw.write(entete); ffw.write("\n# \n"); ffw.write("# id"); ffw.write("\n"); ffw.write("# pos[mm]"); ffw.write("\n"); ffw.write("# flag: 0/1/2 - not assig. / assig./ reference "); ffw.write("\n"); ffw.write("# Virt_Px_X of assigned object"); ffw.write("\n"); ffw.write("# Virt_Px_Y of assigned object"); ffw.write("\n"); ffw.write("# Real_Px_X of assigned object"); ffw.write("\n"); ffw.write("# Real_Px_Y of assigned object"); ffw.write("\n"); int size=slitsArray.length; if (size >0) { // slits values loop for (int i=0; i < size; i++) { boolean rep=false; int s=Integer.valueOf(slitsArray[i][0]); String num=""; int ref=Integer.valueOf(slitsArray[i][4]); int k=0; k=Integer.valueOf(slitsArray[i][13]); if ((k>0) &&((ref == 2) || (ref==1))) { if (k>0) if (s!=k) { rep=true; // to replicate affected slit informations } } // Slit id and detector values if (slitsArray[i][0].length()<2 ) num="00"+slitsArray[i][0]; else if (slitsArray[i][0].length()<3 ) num="0"+slitsArray[i][0]; ffw.write(num); ffw.write(" "); ffw.write(slitsArray[i][1]); ffw.write(" "); ffw.write(slitsArray[i][4]); ffw.write(" "); if (rep) { // When joined slits, get the reference slit values ffw.write(slitsArray[k-1][5]); ffw.write(" "); ffw.write(slitsArray[k-1][6]); ffw.write(" "); ffw.write(slitsArray[k-1][9]); ffw.write(" "); ffw.write(slitsArray[k-1][10]); } else { ffw.write(slitsArray[i][5]); ffw.write(" "); ffw.write(slitsArray[i][6]); ffw.write(" "); ffw.write(slitsArray[i][9]); ffw.write(" "); ffw.write(slitsArray[i][10]); } ffw.write("\n"); // Slit Id if (slitsArray[i][2].length()<3 ) num="0"+slitsArray[i][2]; else num=slitsArray[i][2]; // CSU Value ffw.write(num); ffw.write(" "); ffw.write(slitsArray[i][3]); ffw.write(" "); ffw.write(slitsArray[i][4]); ffw.write(" "); if (rep) { ffw.write(slitsArray[k-1][7]); ffw.write(" "); ffw.write(slitsArray[k-1][8]); ffw.write(" "); ffw.write(slitsArray[k-1][11]); ffw.write(" "); ffw.write(slitsArray[k-1][12]); rep=false; } else { ffw.write(slitsArray[i][7]); ffw.write(" "); ffw.write(slitsArray[i][8]); ffw.write(" "); ffw.write(slitsArray[i][11]); ffw.write(" "); ffw.write(slitsArray[i][12]); } ffw.write("\n"); } } ffw.close(); } catch (Exception e) { noError = false; String loadError = "Error writing slits location file !"; new CustomJDialog(loadError, CustomJDialog._ERROR_,CustomJDialog._CLOSE_BUTTON_, pater); // System.out.println("Could not create file ! "); } finally { try { if (ffw != null) ffw.close(); } catch (IOException e) { noError = false; e.printStackTrace(); } } return noError; } // end writeSlitsLocation /** * Write a text file with mask description. * * **/ public boolean writeMaskConfiguration(String fileName, Mask curMask) { boolean noError=true; File ff=null; fileName=fileName+".conf"; ff=new File(fileName); FileWriter ffw=null; double angle=curMask.getOmega(); String uuid=curMask.getS_uuid(); String entete = "Mask_ID : "+uuid+"\n"; WorldCoords wc=new WorldCoords(curMask.getAlpha(),curMask.getDelta()); entete=entete+"# RA "+wc.getRA().toString()+" Dec "+wc.getDec().toString()+" Angle "+String.valueOf(angle); try { ffw=new FileWriter(ff); ffw.write(entete); ffw.write("\n# \n"); for (int k = 0; k < Mask._NBRSLITS_; k++) { Slit sl=curMask.getSlit(k); boolean isJ=false; int idObj= -1; String infos=""; idObj=sl.getAffectedObject(); isJ=sl.isJoined(); if ((idObj > 0 ) || (isJ)) { int v=sl.getId()+1; String slitId = Integer.toString(v); infos=infos+slitId; if (isJ) { int i=sl.getJoinedRefSlit(); //i++; if (i!=k+1) { //Slit sref=curMask.getSlit(i-1); Slit sref=curMask.getSlit(i); int obj=sref.getAffectedObject(); if (obj>0) { SkyObject sk=fov.getCurrentImage().getObject(obj); infos=infos+" : "+sk.getTargetId()+" : "+sk.getProperty(); } } } if (idObj > 0 ) { SkyObject sk=fov.getCurrentImage().getObject(idObj); infos=infos+" : "+sk.getTargetId()+" : "+sk.getProperty(); } ffw.write(infos); ffw.write("\n"); } } ffw.close(); } catch (Exception e) { noError = false; String loadError = "Error writing mask configuration file !"; new CustomJDialog(loadError, CustomJDialog._ERROR_,CustomJDialog._CLOSE_BUTTON_, pater); // System.out.println("Could not create file ! "); } finally { try { if (ffw != null) ffw.close(); } catch (IOException e) { noError = false; e.printStackTrace(); } } return noError; } }