int cmd_exec(struct command_t* command){ if(error1(command)) return -1; if(error2(command)) return -2; if(error3(command)) return -3; if(error4(command)) return -4; if(error5(command)) return -5; if(isNum(command->token[0])){ command->arg1 = atoi(command->token[0]); strcpy(command->operation, command->token[1]); command->arg2 = atoi(command->token[2]); } else{ strcpy(command->operation, command->token[0]); command->arg1 = atoi(command->token[1]); } DoOperation(command); return 0; }
BOOL CModalApiShuttle::OnInitDialog() { CDialog::OnInitDialog(); CRect rc; AfxGetMainWnd()->GetWindowRect(rc); rc.right= rc.left; rc.bottom= rc.top; MoveWindow(rc, false); EnableWindow(true); ShowWindow(SW_SHOW); DoOperation(); EndDialog(IDOK); return TRUE; }
vtkDataArray * avtUnaryMathExpression::DeriveVariable(vtkDataSet *in_ds, int currentDomainsIndex) { int i; vtkDataArray *cell_data = NULL; vtkDataArray *point_data = NULL; vtkDataArray *data = NULL; if (activeVariable == NULL) { // // This hack is getting more and more refined. This situation comes up // when we don't know what the active variable is (mostly for the // constant creation filter). We probably need more infrastructure // to handle this. // Iteration 1 of this hack said take any array. // Iteration 2 said take any array that isn't vtkGhostLevels, etc. // Iteration 3 says take the first scalar array if one is available, // provided that array is not vtkGhostLevels, etc. // This is because most constants we create are scalar. // // Note: this hack used to be quite important because we would use // the resulting array to determine the centering of the variable. // Now we use the IsPointVariable() method. So this data array is // only used to get the type. // int ncellArray = in_ds->GetCellData()->GetNumberOfArrays(); for (i = 0 ; i < ncellArray ; i++) { vtkDataArray *candidate = in_ds->GetCellData()->GetArray(i); if (strstr(candidate->GetName(), "vtk") != NULL) continue; if (strstr(candidate->GetName(), "avt") != NULL) continue; if (candidate->GetNumberOfComponents() == 1) { // Definite winner cell_data = candidate; break; } else // Potential winner -- keep looking cell_data = candidate; } int npointArray = in_ds->GetPointData()->GetNumberOfArrays(); for (i = 0 ; i < npointArray ; i++) { vtkDataArray *candidate = in_ds->GetPointData()->GetArray(i); if (strstr(candidate->GetName(), "vtk") != NULL) continue; if (strstr(candidate->GetName(), "avt") != NULL) continue; if (candidate->GetNumberOfComponents() == 1) { // Definite winner point_data = candidate; break; } else // Potential winner -- keep looking point_data = candidate; } if (cell_data != NULL && cell_data->GetNumberOfComponents() == 1) { data = cell_data; centering = AVT_ZONECENT; } else if (point_data != NULL && point_data->GetNumberOfComponents()== 1) { data = point_data; centering = AVT_NODECENT; } else if (cell_data != NULL) { data = cell_data; centering = AVT_ZONECENT; } else { data = point_data; centering = AVT_NODECENT; } } else { cell_data = in_ds->GetCellData()->GetArray(activeVariable); point_data = in_ds->GetPointData()->GetArray(activeVariable); if (cell_data != NULL) { data = cell_data; centering = AVT_ZONECENT; } else { data = point_data; centering = AVT_NODECENT; } } // // Set up a VTK variable reflecting the calculated variable // int ncomps = 0; int nvals = 0; if (FilterCreatesSingleton()) nvals = 1; else if (activeVariable == NULL || data == NULL) nvals = (IsPointVariable() ? in_ds->GetNumberOfPoints() : in_ds->GetNumberOfCells()); else nvals = data->GetNumberOfTuples(); vtkDataArray *dv = NULL; if (data == NULL) { // // We could not find a single array. We must be doing something with // the mesh. // ncomps = 1; dv = CreateArrayFromMesh(in_ds); } else { ncomps = data->GetNumberOfComponents(); dv = CreateArray(data); } if (data == NULL) { if (! NullInputIsExpected()) { // One way to get here is to have vtkPolyData Curve plots. EXCEPTION2(ExpressionException, outputVariableName, "An internal error occurred when " "trying to calculate your expression. Please contact a " "VisIt developer."); } } int noutcomps = GetNumberOfComponentsInOutput(ncomps); dv->SetNumberOfComponents(noutcomps); dv->SetNumberOfTuples(nvals); // // Should we send in ncomps or noutcomps? They are the same number // unless the derived type re-defined GetNumberOfComponentsInOutput. // If it did, it probably doesn't matter. If not, then it is the same // number. So send in the input. Really doesn't matter. // cur_mesh = in_ds; DoOperation(data, dv, ncomps, nvals); cur_mesh = NULL; return dv; }
void ProcessButtonClick(char command) { //Was a Number Button Clicked? if (command >= '0' && command <= '9') { //Should the Display be cleared out? if (g_DoClear) { SetDisplayText("0"); g_DoClear = FALSE; } //Get current text and text of number pressed char currentText[15]; SendMessage( hwndEditBox, WM_GETTEXT, sizeof(currentText), (LPARAM)(void*)currentText); char numText[2] = { command, '\0' }; ///HACK if (strlen(currentText)>=6) return; //New Text is a concatenation (unless "0") char* newText = strcmp(currentText, "0") ? strcat(currentText, numText) : numText; //Set the new text SetDisplayText(newText); } else if (command == 'C') { //Clear Memory, Operator, and Text SetDisplayText("0"); g_Operator = '~'; strcpy(g_Memory, "0"); } else { //Get current text char currentText[15]; SendMessage( hwndEditBox, WM_GETTEXT, sizeof(currentText), (LPARAM)(void*)currentText); //Get ops double op1 = atof(g_Memory); double op2 = atof(currentText); //get answer/Error indicator int isErr = 0; double ans = DoOperation(g_Operator, op1, op2, &isErr); //Display Answer char newText[15] = "0"; if (isErr == 1) { SetDisplayText("Err"); } else { sprintf(newText, "%g", ans); SetDisplayText(newText); } //Set g_DoClear = TRUE; strcpy(g_Memory, newText); g_Operator = command; } }