/****************************************************************************** * * Title : listEditUir.c * Version 0.0 * * Description: Command list editor callback functions. * Related files: listEditUir.uir * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ #include #include #include "commandListEditUir.h" #include "uirUtility.h" #include "globalDefinitions.h" #include "hostUtility.h" #include "mainUir.h" #include "RWlists.h" /****************************************************************************** * Static Function Declarations * ******************************************************************************/ /****************************************************************************** * LW_CVI callback functions * ******************************************************************************/ /*============================================================================= * commandListEdit() *============================================================================= * * Command list edit functions. * */ int CVICALLBACK clistEditButtons(int panel, int control, int event,void *callbackData, int eventData1, int eventData2){ unsigned char hostIndex; int status; struct HOST *host; ERROR_ID errorId; struct COMMAND *command; char commandName[100]; static int rowIndex; static int commandIndex; int index; char file[PATHNAME_LENGTH]; UINT32 length; static struct COMMAND_LIST commandListEdit; /* list currently opened in TestEditWindow */ struct COMMAND_LIST *commandListLoad; int itemIndex; Point tablePoint; unsigned char slotNumber; Rect rect; char text[300]; char directory[300]; char lastList[300]; void *filePtr; int value; int ifError; unsigned int repetitions; if((event==EVENT_COMMIT)||(event==EVENT_LEFT_DOUBLE_CLICK)){ switch(control){ case CLIST_EDIT_CLEAR_CLCOMM: ResetTextBox(panel, CLIST_EDIT_CLIST_COMMENT, 0); break; case CLIST_EDIT_CLEAR_CCOMM: ResetTextBox(panel, CLIST_EDIT_CMD_COMMENT, 0); break; case CLIST_EDIT_SEND_CLIST_TO_ROD: /* execute command list -> send command list to control thread(s) */ GetCtrlVal(panel, CLIST_EDIT_SLOT_NUMBER, &slotNumber); status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); if(slotNumber==TIM_SLOT_NUMBER){ /* slot#13 */ /* * Send command list only to TIM! * Only RW_VME and COMPARE_FILES commands are valid for TIM command list!! */ errorId=executeTimCommandList(&commandListEdit); ERROR_CHECK(errorId, runTimCommandList()); break; /* !! */ } if(slotNumber!=ALL_RODS){ host=global.host[HOST_INDEX(slotNumber)]; if(host==NULL){ sprintf(text, "ROD in slot#%d not loaded!!", slotNumber); status = MessagePopup ("WARNING", text); UIR_STATUS_CHECK(status, MessagePopup()); break; } } if(commandListEdit.commandCount==0){ status=MessagePopup ("Warning", "Command list is empty!"); UIR_STATUS_CHECK(status, MessagePopup()); break; } GetCtrlVal(panel, CLIST_EDIT_CLIST_REP, &repetitions); //GetCtrlVal(global.panel.main, MAIN_IF_ERROR, &ifError); ifError=0; /* default */ if(slotNumber==ALL_RODS) hostIndex=0; //all rods else hostIndex=HOST_INDEX(slotNumber); //only one rod for( ; hostIndexcListFile[0]=0; errorId=executeCommandList(host, &commandListEdit, repetitions, ifError); ERROR_CHECK(errorId, addTestToControlThread()); if(slotNumber!=0) break; //only one rod } break; case CLIST_EDIT_ADD_BEFORE: /* add command to list */ /* NO BREAK */ case CLIST_EDIT_REPLACE: /* NO BREAK */ case CLIST_EDIT_ADD_AFTER: /* NO BREAK */ /* get command index */ status=GetActiveTableCell (panel, CLIST_EDIT_LIST_TABLE, &tablePoint); UIR_STATUS_CHECK(status, GetActiveTableCell()); rowIndex=tablePoint.y; status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); if((control!=CLIST_EDIT_REPLACE)&&(commandListEdit.commandCount>=MAXCOMMANDS_IN_LIST)){ status = MessagePopup ("WARNING", "TestCount>MAXCOMMANDS_IN_LIST!!"); UIR_STATUS_CHECK(status, MessagePopup()); break; } if((rowIndex>0)&&(control!=CLIST_EDIT_ADD_AFTER)){ /* *primCount==0 ie. rowIndex==0 */ commandIndex=rowIndex-1; } else { commandIndex=rowIndex; } command=&commandListEdit.command[commandIndex]; GetCtrlVal(panel, CLIST_EDIT_COMMAND_REPEAT, &command->numRepetitions); GetCtrlVal(panel, CLIST_EDIT_CONT_IF_ERROR, &command->continueIfError); if(commandListEdit.commandCount>0){ if((control!=CLIST_EDIT_REPLACE)){ memmove(&commandListEdit.command[commandIndex+1], command, (commandListEdit.commandCount-commandIndex)*sizeof(struct COMMAND)); } } /* add command to list */ command->id=global.editCommandId; errorId=(*global.commandFunction[command->id])(COMMAND_TO_LIST, command, 0, 0); ERROR_CHECK(errorId, commandFunction()); if(errorId!=SUCCESS) return(errorId); /* get comment */ GetCtrlVal(panel, CLIST_EDIT_CMD_COMMENT, command->comment); if((control!=CLIST_EDIT_REPLACE)||(rowIndex==0)){ status = InsertTableRows (panel, CLIST_EDIT_LIST_TABLE, commandIndex+1, 1, VAL_USE_MASTER_CELL_TYPE); UIR_STATUS_CHECK(status, InsertTableRows()); } status = GetCtrlIndex (panel, CLIST_EDIT_COMMAND_RING, &itemIndex); UIR_STATUS_CHECK(status, GetCtrlIndex()); status = GetLabelFromIndex (panel, CLIST_EDIT_COMMAND_RING, itemIndex, commandName); UIR_STATUS_CHECK(status, GetLabelFromIndex()); status=SetTableCellVal (panel, CLIST_EDIT_LIST_TABLE, MakePoint(1, commandIndex+1), commandName); UIR_STATUS_CHECK(status, SetTableCellVal()); status=SetTableCellVal (panel, CLIST_EDIT_LIST_TABLE, MakePoint(2, commandIndex+1), command->numRepetitions); UIR_STATUS_CHECK(status, SetTableCellVal()); status = SetTableSelection (panel, CLIST_EDIT_LIST_TABLE, MakeRect(commandIndex+1,1,1,2)); UIR_STATUS_CHECK(status, SetTableSelection()); status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); SetCtrlVal(panel, CLIST_EDIT_COMMAND_COUNT, commandListEdit.commandCount); break; case CLIST_EDIT_LIST_TABLE: /* double click */ /* no break here */ case CLIST_EDIT_EDIT_COMMAND: /* edit command */ /* get command index */ status=GetActiveTableCell (panel, CLIST_EDIT_LIST_TABLE, &tablePoint); UIR_STATUS_CHECK(status, GetActiveTableCell()); rowIndex=tablePoint.y; status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); if(commandListEdit.commandCount==0){ break; } else { commandIndex=rowIndex-1; } command=&commandListEdit.command[commandIndex]; SetCtrlVal(panel, CLIST_EDIT_COMMAND_RING, command->id); status=HidePanel(global.panel.commandEdit[global.editCommandId]); UIR_STATUS_CHECK(status, HidePanel()); global.editCommandId=command->id; status=DisplayPanel(global.panel.commandEdit[command->id]); UIR_STATUS_CHECK(status, DisplayPanel()); SetCtrlVal(panel, CLIST_EDIT_COMMAND_REPEAT, command->numRepetitions); SetCtrlVal(panel, CLIST_EDIT_CONT_IF_ERROR, command->continueIfError); errorId=(*global.commandFunction[command->id])(LIST_TO_COMMAND, command, 0, 0); ERROR_CHECK(errorId, commandFunction()); /* Set comment */ ResetTextBox(panel, CLIST_EDIT_CMD_COMMENT, command->comment); break; case CLIST_EDIT_DELETE_COMMAND: /* delete command in list */ /* get command index */ status=GetActiveTableCell (panel, CLIST_EDIT_LIST_TABLE, &tablePoint); UIR_STATUS_CHECK(status, GetActiveTableCell()); rowIndex=tablePoint.y; status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); if(commandListEdit.commandCount==0){ break; } else { commandIndex=rowIndex-1; } command=&commandListEdit.command[commandIndex]; if(commandListEdit.commandCount>0){ /* move one step up */ memmove(command, &commandListEdit.command[rowIndex], (commandListEdit.commandCount-rowIndex)*sizeof(struct COMMAND)); } status = DeleteTableRows (panel, CLIST_EDIT_LIST_TABLE, rowIndex, 1); UIR_STATUS_CHECK(status, SetTableCellVal()); status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); SetCtrlVal(panel, CLIST_EDIT_COMMAND_COUNT, commandListEdit.commandCount); if(commandIndex>=commandListEdit.commandCount){ commandIndex=commandListEdit.commandCount-1; } if(commandListEdit.commandCount>0){ status = SetTableSelection (panel, CLIST_EDIT_LIST_TABLE, MakeRect(commandIndex+1,1,1,2)); UIR_STATUS_CHECK(status, SetTableSelection()); } break; case CLIST_EDIT_LOAD_LIST: (void) clistEditButtons(global.panel.commandListEdit, CLIST_EDIT_CLEAR_LIST, EVENT_COMMIT, 0, 0, 0); (void) clistEditButtons(global.panel.commandListEdit, CLIST_EDIT_INSERT_LIST, EVENT_COMMIT, 0, 0, 0); break; case CLIST_EDIT_CLEAR_LIST: if(eventData1!=1){ GetCtrlVal(panel, CLIST_EDIT_COMMAND_COUNT, &value); if(value!=0){ status = ConfirmPopup ("Confirm popup", "Delete current list?"); UIR_STATUS_CHECK(status, ConfirmPopup()); if(status==0){ break; } } } status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); if(commandListEdit.commandCount>0){; status = DeleteTableRows (panel, CLIST_EDIT_LIST_TABLE, 1, -1); UIR_STATUS_CHECK(status, DeleteTableRows()); } status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); SetCtrlVal(panel, CLIST_EDIT_COMMAND_COUNT, commandListEdit.commandCount); break; case CLIST_EDIT_INSERT_LIST: /* load command list from file and insert AFTER current position in the list */ status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); status=GetActiveTableCell (panel, CLIST_EDIT_LIST_TABLE, &tablePoint); UIR_STATUS_CHECK(status, GetActiveTableCell()); rowIndex=tablePoint.y; commandIndex=rowIndex; if(eventData1!=1){ GetCtrlVal(panel, CLIST_EDIT_LAST_FILE, directory); if(directory[0]==0) { strcpy(directory, global.testingDataDir); strcpy(lastList, "*.cl"); }else{ GetFirstFile (directory, 1, 0, 0, 0, 0, 0, lastList); directory[strlen(directory)-strlen(lastList)]=0; } status = FileSelectPopup (directory, lastList, "*.cl", "",VAL_SELECT_BUTTON, 0, 1, 1, 1, file); if(status==VAL_NO_FILE_SELECTED){ break; } filePtr=file; }else{ filePtr=callbackData; } commandListLoad=(struct COMMAND_LIST*)calloc(1, sizeof(struct COMMAND_LIST)); /* allocate and clear memory for data buffer */ if(commandListLoad==NULL){ ERROR_CHECK(PROGRAM_ERROR, calloc()); return(0); } errorId=readCmdListFile(filePtr, commandListLoad); ERROR_CHECK(errorId, readCmdListFile()); if((commandListEdit.commandCount+commandListLoad->commandCount)>MAXCOMMANDS_IN_LIST){ status = MessagePopup ("WARNING", "TestCount>MAXCOMMANDS_IN_LIST!!"); UIR_STATUS_CHECK(status, MessagePopup()); free(commandListLoad); /* !!! */ break; } if(commandListEdit.commandCount==0) ResetTextBox(panel, CLIST_EDIT_CLIST_COMMENT, commandListLoad->comment); command=&commandListEdit.command[commandIndex]; /* move down */ memmove(&commandListEdit.command[commandIndex+commandListLoad->commandCount], command, (commandListEdit.commandCount-commandIndex)*sizeof(struct COMMAND)); memcpy(command, (UINT32*)&commandListLoad->command, commandListLoad->commandCount*sizeof(struct COMMAND)); /* insert new command list */ for(index=0; indexcommandCount; ++index){ UIR_STATUS_CHECK(status, InsertTableRows()); command=&commandListEdit.command[commandIndex]; status = GetIndexFromValue (panel, CLIST_EDIT_COMMAND_RING, &itemIndex, command->id); UIR_STATUS_CHECK(status, GetLabelFromIndex()); status = GetLabelFromIndex (panel, CLIST_EDIT_COMMAND_RING, itemIndex, commandName); UIR_STATUS_CHECK(status, GetLabelFromIndex()); ++commandIndex; status = InsertTableRows (panel, CLIST_EDIT_LIST_TABLE, commandIndex, 1, VAL_USE_MASTER_CELL_TYPE); status=SetTableCellVal (panel, CLIST_EDIT_LIST_TABLE, MakePoint(1, commandIndex), commandName); UIR_STATUS_CHECK(status, SetTableCellVal()); status=SetTableCellVal (panel, CLIST_EDIT_LIST_TABLE, MakePoint(2, commandIndex), command->numRepetitions); UIR_STATUS_CHECK(status, SetTableCellVal()); } free(commandListLoad); /* !!! */ status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); SetCtrlVal(panel, CLIST_EDIT_COMMAND_COUNT, commandListEdit.commandCount); SetCtrlVal(panel, CLIST_EDIT_LAST_FILE, filePtr); break; case CLIST_EDIT_SAVE_LIST: /* save command list to file */ GetCtrlVal(panel, CLIST_EDIT_LAST_FILE, directory); if(directory[0]==0) { strcpy(directory, global.testingDataDir); strcpy(lastList, "*.cl"); }else{ GetFirstFile (directory, 1, 0, 0, 0, 0, 0, lastList); directory[strlen(directory)-strlen(lastList)]=0; } status = FileSelectPopup (directory, lastList, "*.cl", "",VAL_SAVE_BUTTON, 0, 1, 1, 1, file); switch(status){ case 0: /* no file selected */ break; case 1: /* existing file selected */ /* no break here */ case 2: /* new file selected */ status = GetNumTableRows (panel, CLIST_EDIT_LIST_TABLE, &commandListEdit.commandCount); UIR_STATUS_CHECK(status, GetNumTableRows()); /* get comment */ GetCtrlVal(panel, CLIST_EDIT_CLIST_COMMENT, commandListEdit.comment); errorId=writeCmdListFile(file, &commandListEdit); ERROR_CHECK(errorId, writeCmdListFile()); SetCtrlVal(panel, CLIST_EDIT_LAST_FILE, file); break; default: break; } break; default: ; } } if(global.option.programExit==FALSE){ /* set table as a active control - to see current command */ status=SetActiveCtrl (global.panel.commandListEdit, CLIST_EDIT_LIST_TABLE); UIR_STATUS_CHECK(status, DisplayPanel()); } return 0; } /*============================================================================= * commandRing() *============================================================================= * * Updates command parameter window. * */ int CVICALLBACK commandRing (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int status; unsigned char hostIndex; struct HOST *host; unsigned int commandId; if(event==EVENT_VAL_CHANGED){ status=HidePanel(global.panel.commandEdit[global.editCommandId]); UIR_STATUS_CHECK(status, HidePanel()); GetCtrlVal(panel, control, &commandId); global.editCommandId=commandId; status=DisplayPanel(global.panel.commandEdit[commandId]); UIR_STATUS_CHECK(status, DisplayPanel()); } if(global.option.programExit==FALSE){ status=SetActiveCtrl (global.panel.commandListEdit, CLIST_EDIT_LIST_TABLE); UIR_STATUS_CHECK(status, DisplayPanel()); } return 0; } /*============================================================================= * listEditMenu() *============================================================================= * * Command list editor menu. * */ void CVICALLBACK commandListEditMenu (int menuBar, int menuprimTable, void *callbackData, int panel){ int status; char string[300]; switch(menuprimTable){ case CLIST_MENU_CLOSE: status=HidePanel(panel); UIR_STATUS_CHECK(status, HidePanel()); break; case CLIST_MENU_GOTO_MAIN: status=SetActivePanel(global.panel.main); UIR_STATUS_CHECK(status, SetActivePanel()); break; case CLIST_MENU_PRIM_LIST_EDIT: status=SetActivePanel(global.panel.primListEdit); UIR_STATUS_CHECK(status, SetActivePanel()); break; case CLIST_MENU_DATA_FILE_CREATOR: strcpy(string, global.mainDir); strcat(string, DATA_FILE_CREATOR); status=LaunchExecutable(string); UIR_STATUS_CHECK(status, LaunchExecutable()); break; default: ; } } /******************************************************************************/