int ReadPosRA (Widget w) /* read RA from text window, return 0 if OK, 1 if error */ { char *value=NULL, ctype[5]; int h, m, toHours, iNumRead, bOK; float s; Display *dpy = XtDisplay(w); double ra; /* read value */ value = XmTextGetString (w); if (!value) /* error */ {MessageShow ("Error reading RA for Mark Position"); return 1;} /* first axis in hours or degrees? */ strncpy (ctype, image[CurImag].cname[0]->sp, 4); toHours = (!strncmp(ctype, "RA", 2)) || (!strncmp(ctype, "LL", 2)); iNumRead = sscanf (value, "%d %d %f", &h, &m, &s); if (value) XtFree(value); bOK = 0; if (toHours) {if (iNumRead==3) bOK = !hmsra(h, m, s, &ra);} else if (iNumRead==3) bOK = !dmsdec(h, m, s, &ra); if (!bOK) { /* error */ MessageShow ("Error reading RA for Mark Position"); return 1;} /* OK, save */ mark.ra = ra; return 0; } /* end ReadPosRA */
int ReadPosDec (Widget w) /* read RA from text window, return 0 if OK, 1 if error */ { char *value=NULL; int d, m, iNumRead, bOK, bSouth, i; float s; double dec; Display *dpy = XtDisplay(w); /* read value */ value = XmTextGetString (w); if (!value) /* error */ {MessageShow("Error reading Dec for Mark Position"); return 1;} bOK = 0; iNumRead = sscanf (value, "%d %d %f", &d, &m, &s); /* southern declination? look for minus sign*/ bSouth = 0; for (i=0;i<20;i++) {if (value[i]=='-') bSouth=1; if (value[i]==0) break;} if (value) XtFree(value); if (iNumRead==3) bOK = !dmsdec(d, m, s, &dec); if (!bOK) { /* error */ MessageShow("Error reading Dec for Mark Position"); return 1;} if (bSouth && (dec>0.0)) dec = -dec; /* make sure declination sign OK */ /* OK, save */ mark.dec = dec; return 0; } /* end ReadPosDec */
UINT8 F_EBookProtectAllFile() { // John @01/22/06 if (IsSDProtect ()) { MessageShow (ErrCardProtect); return 0; } xdcfAttrElm_t tempFileAttr; UINT32 i; xdcfFileCountGet(&ui32FileCnt); MessageShow (MenuWaite); //fqdao for(i=1;i<=ui32FileCnt;i++) { xdcfCurFileByPosSet( i ); xdcfCurFileAttrGet(&tempFileAttr) ; xdcfCurFileAttrSet(xDCF_ATTR_READONLY |tempFileAttr.attribute) ; } xdcfCurFileByPosSet( ui32FileIdx ); return 1; }
UINT8 F_EBookDisProtectSingleFile() { // John @01/22/06 if (IsSDProtect ()) { MessageShow (ErrCardProtect); return 0; } xdcfCurFileByPosSet( ui32FileIdx ); xdcfCurFileAttrGet(&xdcfFileAttr) ; xdcfCurFileAttrSet((~xDCF_ATTR_READONLY) &xdcfFileAttr.attribute) ; return 1; }
int ReadPosSize (Widget w) /* read size from text window, return 0 if OK, 1 if error */ { char *value=NULL; int iInner, iOuter, iNumRead; Display *dpy = XtDisplay(w); /* read value */ value = XmTextGetString (w); if (!value) /* error */ {MessageShow("Error reading cross size for Mark Position"); return 1;} iNumRead = sscanf (value, "%d %d", &iInner, &iOuter); if (value) XtFree(value); if (iNumRead!=2) { /* error */ MessageShow("Error reading cross size for Mark Position"); return 1;} /* OK, save */ mark.iInner = iInner; mark.iOuter = iOuter; return 0; } /* end ReadPosSize */
UINT8 F_EBookDelSingleFile( )//UINT32 idx) { UINT32 err ; if((xdcfCurFileByPosSet( ui32FileIdx )) != 0) { } if (xdcfCurFileAttrGet(&xdcfFileAttr)==0) { // John @01/22/06 if (IsSDProtect ()) { MessageShow (ErrCardProtect); return 0; } if (xdcfFileAttr.attribute & xDCF_ATTR_READONLY) { MessageShow(ErrfileProtect); return 0; } xdcfOneFileErase(xdcfFileAttr.name); err = xdcfFileCountGet( &ui32FileCnt ); if(!ui32FileCnt) { xdcfDirCountGet(&ui32DirCnt); xdcfCurDirPosGet(&ui32DirIdx); xdcfCurDirAttrGet(&xdcfDirAttr); } else if(ui32FileIdx > ui32FileCnt) ui32FileIdx = ui32FileCnt ; } return 1; }
UINT8 F_EBookDelAllFile() { UINT32 Idx, Counts; // John @01/22/06 if (IsSDProtect ()) { MessageShow (ErrCardProtect); return 0; } // John @01/22/06 #if 0 //fqdao_modify 06.5.30 xdcfFileCountGet(&Counts); for (ui32FileIdx = 1; ui32FileIdx <= Counts; ui32FileIdx++) { if(!F_EBookDelSingleFile()) { // return 0; //fqdao_modify for bug del profile nullity 06.5.29 } } #endif xdcfAllFilesErase(); xdcfFileCountGet(&ui32FileCnt); if(!ui32FileCnt) { xdcfDirCountGet(&ui32DirCnt); xdcfCurDirPosGet(&ui32DirIdx); xdcfCurDirAttrGet(&xdcfDirAttr); } else if(ui32FileIdx>ui32FileCnt) ui32FileIdx = ui32FileCnt ; xdcfFileCountGet(&ui32FileCnt); return 1; }
void UpdateInfo (ImageDisplay *IDdata) /* update information about selected pixel in control window */ { Integer ndim; int i, posOK; XmString wierdstring = NULL; char jerkstring[100]; Arg wargs[5]; float fblank, val, pix[7]; char axtype[3][9], label[3][20]; double pos[3]; Logical valid; Integer error, ipos[7] = {0, 0, 0, 0, 0, 0, 0}; MatrixPos *impos=NULL; Display *dpy = XtDisplay(IDdata->display); static Cursor cursor=(Cursor)NULL; extern Widget shell; XSetWindowAttributes attrs; /* check that info defined for current image */ if ((!image[CurImag].Image) || (!image[CurImag].Image->descript)) IDdata->showInfo = 0; /* need to blank display? */ if (!IDdata->showInfo) { wierdstring = XmStringCreateSimple (" "); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info1, wargs, 1); XtSetValues (IDdata->Info2, wargs, 1); XtSetValues (IDdata->Info3, wargs, 1); XtSetValues (IDdata->Info4, wargs, 1); XtSetValues (IDdata->Info5, wargs, 1); XtSetValues (IDdata->Info6, wargs, 1); XtSetValues (IDdata->Info7, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; return; } /* end blank info area */ /* return OK if no valid image */ if (!image[CurImag].valid) return; ndim = image[CurImag].ndim; /* Number of dimensions */ /* make sure hourglass cursor initialized */ if (!cursor) cursor = XCreateFontCursor(dpy, XC_watch); /* fitted or current */ if (ndim>2) sprintf (jerkstring, "(%7.2f,%7.2f, %d)", image[CurImag].fXpixel+1.0, image[CurImag].fYpixel+1.0, image[CurImag].PlaneNo+1); else sprintf (jerkstring, "(%7.2f,%7.2f)", image[CurImag].fXpixel+1.0, image[CurImag].fYpixel+1.0); wierdstring = XmStringCreateSimple (jerkstring); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info1, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; /* get flux */ fblank = MagicBlank(); /* fitted or current? */ if (image[CurImag].iFitted>0) /* fitted values */ {valid = 1; if (image[CurImag].fBpixel==fblank) /* blanked */ sprintf (jerkstring, "pixel blanked"); else sprintf (jerkstring, "value=%f", image[CurImag].fBpixel);} else /* current position */ {val = 0; for (i=3; i<7; i++) ipos[i] = 0; /* Note: Image class pixel numbers are 0 rel; geometry is 1 rel. */ ipos[0] = image[CurImag].iXPixel; ipos[1] = image[CurImag].iYPixel; ipos[2] = image[CurImag].PlaneNo; /* make Matrix */ impos = MakeMatrixPos(ndim, ipos); valid = (ndim>1) && IsValid(image[CurImag].Image->matx, impos); if (valid) /* get pixel value */ { WorkingCursor(True, False, NULL); /* indicate working */ val = MatrixGetPixel(image[CurImag].Image->matx, impos); WorkingCursor(False, False, NULL); /* reset cursor */ error = image[CurImag].Image->matx->fw->error; if (error) /* I/O error */ {MessageShow("UpdateInfo: Error reading pixel value"); IDdata->showInfo= 0; /* file no longer available? */ image[CurImag].valid = 0; /* mark as invalid */ val = fblank;} if (val==fblank) /* blanked */ sprintf (jerkstring, "pixel blanked"); else sprintf (jerkstring, "value=%f", val); } } KillMatrixPos(impos); if (!valid) sprintf (jerkstring, "invalid pixel"); /* write second line (flux density) */ jerkstring[16] = 0; /* limit size of string */ wierdstring = XmStringCreateSimple (jerkstring); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info2, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; /* celestial position */ /* equinox is line 3 */ if ((usr_equinox>0.0) && (image[CurImag].Image->descript->equinox>0.0)) sprintf(jerkstring,"Equinox %6.1f", usr_equinox); else if (image[CurImag].Image->descript->equinox>0.0) sprintf(jerkstring,"Equinox %6.1f", image[CurImag].Image->descript->equinox); else sprintf(jerkstring,"Equinox unknown"); wierdstring = XmStringCreateSimple (jerkstring); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info3, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; /* Get position */ pix[0] = image[CurImag].fXpixel+1.0; pix[1] = image[CurImag].fYpixel+1.0; pix[2] = (float)image[CurImag].PlaneNo+1.0; if (valid) {strncpy(axtype[0], image[CurImag].cname[0]->sp, 8); strncpy(axtype[1], image[CurImag].cname[1]->sp, 8); strncpy(axtype[2], image[CurImag].cname[2]->sp, 8); axtype[0][8] = 0; axtype[1][8] = 0; axtype[2][8] = 0; posOK = !get_wpos(image[CurImag].Image->descript, pix, pos); AxisLabel(pos[0], axtype[0], label[0]); /* human readable */ if (ndim>=2) AxisLabel(pos[1], axtype[1], label[1]); if (ndim>=3) AxisLabel(pos[2], axtype[2], label[2]); if (posOK) { /* valid position */ /* write fourth line (first axis) */ wierdstring = XmStringCreateSimple (label[0]); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info4, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; /* write fifth line (second axis) */ if (ndim>=2) {wierdstring = XmStringCreateSimple (label[1]); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info5, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL;} /* write sixth line (third axis) */ if (ndim>=3) {wierdstring = XmStringCreateSimple (label[2]); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info6, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL;} }} else { /* invalid position */ sprintf (jerkstring, "invalid pixel"); /* write third line (invalid pixel message) */ wierdstring = XmStringCreateSimple (jerkstring); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info3, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; } /* end of give position on invalid */ /* fitted or current? */ if (image[CurImag].iFitted>0) /* fitted values */ sprintf (jerkstring, "fitted"); else if (image[CurImag].iFitted<0) /* fit failed */ sprintf (jerkstring, "fit failed!"); else /* no fit */ sprintf (jerkstring, ""); /* write seventh line */ wierdstring = XmStringCreateSimple (jerkstring); XtSetArg (wargs[0], XmNlabelString, wierdstring); XtSetValues (IDdata->Info7, wargs, 1); if (wierdstring) XmStringFree(wierdstring); wierdstring = NULL; } /* end UpdateInfo */
int FitPos(ImageDisplay *IDdata) /* routine to fit a point near the position of the cursor: */ /* IDdata->iXPixel, iYPixel */ /* Sets Dis[iDs] values fXpixel, fYpixel, fBpixel */ /* returns 1 if worked otherwise 0, -1 => fit failed. */ { int iXcen, iYcen, iX, iY, iXp, iYp; float data[9][9], fblank; Logical valid; Integer error, pos[7] = {0, 0, 0, 0, 0, 0, 0}, ndim; MatrixPos *impos; float s, dx[2]; Display *dpy = XtDisplay(IDdata->canvas); ndim=image[CurImag].ndim; iXcen = image[CurImag].iXPixel; iYcen = image[CurImag].iYPixel; fblank = MagicBlank(); /* default return values */ image[CurImag].fBpixel = 0.; image[CurImag].fXpixel = 0.; image[CurImag].fYpixel = 0.; /* make matrix pos */ impos = MakeMatrixPos(ndim, pos); if (!image[CurImag].valid) return 0; /* use 9x9 values around center */ impos->pos[2] = image[CurImag].PlaneNo; WorkingCursor(True, False, NULL); /* indicate working */ for (iY=0; iY<9; iY++) { iYp = iYcen + iY - 4; impos->pos[1] = iYp; for (iX=0; iX<9; iX++) { iXp = iXcen + iX - 4; impos->pos[0] = iXp; /* check validity */ valid = IsValid(image[CurImag].Image->matx, impos); if (valid) /* read pixel values */ {data[iY][iX] = MatrixGetPixel(image[CurImag].Image->matx, impos); error = image[CurImag].Image->matx->fw->error; if (error) /* I/O error */ {MessageShow("FitPos: error reading pixel value"); KillMatrixPos(impos); IDdata->showInfo= 0; /* file no longer available? */ image[CurImag].valid = 0; /* mark as invalid */ return 0;}/* failed */ } else /* blank */ data [iY][iX] = fblank; } } /* end of loop loading image data in array */ WorkingCursor(False, False, NULL); /* reset cursor */ KillMatrixPos(impos); if (pfit (data, &s, dx, fblank)) {/*fprintf (stderr, "fit failed\n");*/ XBell(dpy, 50); return -1;} /* fit failed*/ image[CurImag].fBpixel = s; image[CurImag].fXpixel = (float)iXcen + dx[0]; image[CurImag].fYpixel = (float)iYcen + dx[1]; return 1; } /* end fit pos */
void MarkPosFromFile (char* filename, ImageDisplay* IDdata) /* read file with marking positing and mark image */ { int i, iRet, iLoop, iXcen, iYcen, iScroll, iHalf, iMore, iErr, iNumOut=0; int inner_size, outer_size; float xpix, ypix; FILE *hFile; iErr = 0; /* Open file */ hFile = fopen (filename, "rt"); if (hFile==NULL) iErr = 1; /* loop over entries */ iMore = (int)(!iErr); while (iMore) { iMore = MarkPosRead(hFile, &image[CurImag], &xpix, &ypix, &inner_size, &outer_size, &iErr); if ((!iMore) || (iErr>0)) break; /* determing center pixel */ if (iErr==0) { /* Only plot if in image otherwise just count */ iXcen = (int)(xpix - 0.5); /* 0-rel posn */ iYcen = (int)(ypix - 0.5); MarkPix (IDdata, iXcen, iYcen, inner_size, outer_size);} else iNumOut++; } /* end of loop over positions */ /* set scroll for last position */ /* Take into account the top and bottom of the image. */ if (IDdata->vscr_vis) { iScroll = image[CurImag].iImageNy - iYcen; IDdata->scrolly = iScroll; iScroll -= IDdata->vscr_half; iScroll = min (iScroll, IDdata->vscr_max); iScroll = max (iScroll, IDdata->vscr_min); /* set scrollbar */ XtVaSetValues(IDdata->vscroll, XmNvalue, iScroll, NULL); } if (IDdata->hscr_vis) { /* Take into account the edges of the image. */ iScroll =iXcen - IDdata->hscr_half; iScroll = min (iScroll, IDdata->hscr_max); iScroll = max (iScroll, IDdata->hscr_min); IDdata->scrollx = iXcen; /* set scroll bar */ XtVaSetValues(IDdata->hscroll, XmNvalue, iScroll, NULL); } if (iNumOut) /* Tell if some out of image */ {sprintf (szErrMess, "%d positions were out of the image", iNumOut); MessageShow (szErrMess);} if (iErr>0) {sprintf (szErrMess, "Error %d with file %s", iErr, filename); MessageShow (szErrMess);} /* redraw image */ PaintImage(IDdata); } /* end MarkPosFromFile */
int MarkPosRead(FILE *hFile, ImageData *ImageDesc, float *xpix, float *ypix, int *inner, int *outer, int *iErr) /* outine to read next position from file and return pixel position and */ /* cross size information. Returns 1 if OK else 0. */ /* File expected open on call and is closed if EOF or error. */ /* iErr = error return; 0=OK else an error occured; */ /* iErr = -1 means the position is out of the image. */ { int h, d, rm, dm, iNumByte, iNumRead, iRet, iInner, iOuter, toHours, i; float rs, ds, xp, yp; double ra, dec; int bRAOK, bDecOK, bOK, bSouth; char szLine[120], ctype[5]; if (!fgets (szLine, 120, hFile)) { /* error or EOF */ if (ferror(hFile)) *iErr = 2; /* Check if error */ fclose(hFile); /* close */ return 0;} /* end of error check */ iNumByte = strlen(szLine); iNumRead = 0; bOK = False; bRAOK = False; bDecOK = False; if (iNumByte>10){ /* decode line */ iNumRead = sscanf (szLine, "%d %d %f %d %d %f %d %d", &h, &rm, &rs, &d, &dm, &ds, &iInner, &iOuter); strncpy (ctype, ImageDesc->cname[0]->sp, 4); toHours = (!strncmp(ctype, "RA", 2)) || (!strncmp(ctype, "LL", 2)); if (toHours) {if (iNumRead>=3) bRAOK = !hmsra(h, rm, rs, &ra);} else if (iNumRead>=3) bRAOK = !dmsdec(h, rm, rs, &ra); if (iNumRead>=6) bDecOK = !dmsdec(d, dm, ds, &dec); /* southern declination? look for minus sign*/ bSouth = 0; for (i=5;i<120;i++) {if (szLine[i]=='-') bSouth=1; if (szLine[i]==0) break; } if (bSouth && (dec>0.0)) dec = -dec; if (bRAOK && bDecOK) { /* get pixel */ strncpy (ctype, ImageDesc->cname[0]->sp+4, 4); ctype[4] = 0; iRet = get_xypix(ImageDesc->Image->descript, ra, dec, &xp, &yp); bOK = (iRet==0);} /* end of convert to pixel */ /* Inner and outer read? */ bOK = bOK && (iNumRead>=8) && (iInner>=0) && (iInner<100) && (iOuter>0) && (iOuter<100); } /* End of decode valid line */ if (bOK) /* everything OK? */ {*xpix = xp; *ypix = yp; *inner = iInner; *outer = iOuter; /* check that pixel is in image. */ if ((xp>0.0) && (yp>0.0) && (xp<(float)(ImageDesc->dim[0])) && (yp<(float)(ImageDesc->dim[1]))) *iErr = 0; else *iErr = -1; /* out of image */ return 1;} else /* bogus dudes */ {*iErr = 3; fclose(hFile); /* close */ sprintf (szErrMess, "Error with file entry %s", szLine); MessageShow (szErrMess); return 0;} } /* end MarkPosRead */
void PosOKButCB (Widget w, XtPointer clientData, XtPointer callData) /* OK button hit - get info and mark */ { int iRet, bOK, iX, iY, iScroll, iHalf; float xp, yp; char ctype[5]; Display *dpy = XtDisplay(w); ImageDisplay *IDdata = (ImageDisplay*)clientData; /* read selected values */ if (ReadPosRA(mark.data1)) return; if (ReadPosDec(mark.data2)) return; if (ReadPosSize(mark.data3)) return; /* convert to pixel */ strncpy (ctype, image[CurImag].cname[0]->sp+4, 4); ctype[4] = 0; iRet = get_xypix(image[CurImag].Image->descript, mark.ra, mark.dec, &xp, &yp); bOK = (iRet==0); /* check that pixel is in image. */ bOK = bOK && (xp>0.0) && (yp>0.0) && (xp<=(float)image[CurImag].dim[0]) && (yp<=(float)image[CurImag].dim[1]); /* everything OK? */ if (!bOK) {sprintf (szErrMess, "invalid position to mark %9.2f, %9.2f", xp, yp); MessageShow (szErrMess); return;} /* mark position in pixelarray; convert to 0-rel */ iX = (int)(xp - 0.5); iY = (int)(yp - 0.5); MarkPix (mark.IDdata, iX, iY, mark.iInner, mark.iOuter); /* set scroll for last position */ iScroll = image[CurImag].iImageNy - iY; if (IDdata->vscr_vis) { IDdata->scrolly = iScroll; iScroll -= IDdata->vscr_half; iScroll = min (iScroll, IDdata->vscr_max); iScroll = max (iScroll, IDdata->vscr_min); /* set scrollbar */ XtVaSetValues(IDdata->vscroll, XmNvalue, iScroll, NULL); } if (IDdata->hscr_vis) { iScroll = iX - IDdata->hscr_half; iScroll = min (iScroll, IDdata->hscr_max); iScroll = max (iScroll, IDdata->hscr_min); IDdata->scrollx = iX; /* set scroll bar */ XtVaSetValues(IDdata->hscroll, XmNvalue, iScroll, NULL); } /* repaint image */ PaintImage (mark.IDdata); /* XtDestroyWidget (mark.dialog);*/ /* PositionBoxActive = 0; mark as inactive */ } /* end PosOKButCB */
void paEBookMenuFunc() { UINT32 key = UI_KEY_MODE_ACCESSORIES; UINT32 err; UINT8 item=0, subitem = 1 ; osdClearScreen(0x00); UINT8 flag; EBookRefreshItem[item](); while(1) { switch(key) { case UI_KEY_DIR_UP: if(subitem>1) subitem -- ; EBookRefreshSubitem[item](subitem) ; break ; case UI_KEY_DIR_DOWN: if(subitem< eBookSubMax[ item ] ) subitem++ ; EBookRefreshSubitem[item](subitem ); break ; case UI_KEY_DIR_LEFT: if(item ) { item -- ; } else { item = EBOOK_ITEM_MAX - 1; } EBookRefreshItem[item](); break ; case UI_KEY_DIR_RIGHT: if(item < EBOOK_ITEM_MAX-1) { item++ ; } else { item = 0 ; } EBookRefreshItem[item]( ); break ; case UI_KEY_FUNC_OK: flag = EBookRefreshFunc[item*2 + subitem - 1 ](); if(flag) { MessageShow (MenuSuccess); } osdClearScreen(0);//fqdao pbEBookShow(EBOOK_DRAW_BG ,0 ); pbEBookRefresh(); return; break ; case UI_KEY_ACCIDENT: pbEBookRefresh(); osQuePost(uiKeyMsgQ, &keyButton[UI_KEY_ACCIDENT]); return; break; case UI_KEY_FUNC_B: case UI_KEY_FUNC_MENU: osdClearScreen(0); //fqdao_add 06.5.19 pbEBookShow(EBOOK_DRAW_BG ,0 ); pbEBookRefresh(); return ; break ; } keyGet(&key) ; } }