bool GetVariable(unsigned char& type, unsigned char& size, int& address, int& indexSourcePtr) { bool bEof = false; if (!g_pElementizer->GetNext(bEof)) { return false; } bool bVariable = false; if (!CheckVariable(bVariable, type, size, address, indexSourcePtr)) { return false; } if (!bVariable) { g_pCompilerData->error = true; g_pCompilerData->error_msg = g_pErrorStrings[error_eav]; return false; } return true; }
void IniSpawn::SpawnCreature(CritterEntry &critter) const { if (!critter.creaturecount) { return; } ieDword specvar = CheckVariable(map, critter.SpecVar, critter.SpecContext); if (critter.SpecVar[0]) { if (critter.SpecVarOperator>=0) { // dunno if this should be negated if (!DiffCore(specvar, critter.SpecVarValue, critter.SpecVarOperator) ) { return; } } else { //ar0203 in PST seems to want the check this way. //if other areas conflict and you want to use (!specvar), //please research further //researched further - ar0203 respawns only if specvar is 1 if (!specvar) { return; } } } if (!(critter.Flags&CF_IGNORECANSEE)) { if (map->IsVisible(critter.SpawnPoint, false) ) { return; } } if (critter.Flags&CF_NO_DIFF_MASK) { ieDword difficulty; ieDword diff_bit; core->GetDictionary()->Lookup("Difficulty Level", difficulty); switch (difficulty) { case 0: diff_bit = CF_NO_DIFF_1; break; case 1: diff_bit = CF_NO_DIFF_2; break; case 2: diff_bit = CF_NO_DIFF_3; break; default: diff_bit = 0; } if (critter.Flags&diff_bit) { return; } } if (critter.ScriptName[0] && (critter.Flags&CF_CHECK_NAME) ) { //maybe this one needs to be using getobjectcount as well //currently we cannot count objects with scriptname??? if (map->GetActor( critter.ScriptName, 0 )) { return; } } else { //Object *object = new Object(); Object object; //objectfields based on spec object.objectFields[0]=critter.Spec[0]; object.objectFields[1]=critter.Spec[1]; object.objectFields[2]=critter.Spec[2]; object.objectFields[3]=critter.Spec[3]; object.objectFields[4]=critter.Spec[4]; object.objectFields[5]=critter.Spec[5]; object.objectFields[6]=critter.Spec[6]; object.objectFields[7]=critter.Spec[7]; object.objectFields[8]=critter.Spec[8]; int cnt = GetObjectCount(map, &object); if (cnt>=critter.TotalQuantity) { return; } } int x = core->Roll(1,critter.creaturecount,-1); Actor* cre = gamedata->GetCreature(critter.CreFile[x]); if (!cre) { return; } SetVariable(map, critter.SpecVar, critter.SpecContext, specvar+(ieDword) critter.SpecVarInc); map->AddActor(cre, true); for (x=0;x<9;x++) { if (critter.SetSpec[x]) { cre->SetBase(StatValues[x], critter.SetSpec[x]); } } cre->SetPosition( critter.SpawnPoint, 0, 0);//maybe critters could be repositioned cre->SetOrientation(critter.Orientation,false); if (critter.ScriptName[0]) { cre->SetScriptName(critter.ScriptName); } //increases death variable if (critter.Flags&CF_DEATHVAR) { cre->AppearanceFlags|=APP_DEATHVAR; } //increases faction specific variable if (critter.Flags&CF_FACTION) { cre->AppearanceFlags|=APP_FACTION; } //increases team specific variable if (critter.Flags&CF_TEAM) { cre->AppearanceFlags|=APP_TEAM; } //increases good variable if (critter.Flags&CF_GOOD) { cre->DeathCounters[DC_GOOD] = critter.DeathCounters[DC_GOOD]; cre->AppearanceFlags|=APP_GOOD; } //increases law variable if (critter.Flags&CF_LAW) { cre->DeathCounters[DC_LAW] = critter.DeathCounters[DC_LAW]; cre->AppearanceFlags|=APP_LAW; } //increases lady variable if (critter.Flags&CF_LADY) { cre->DeathCounters[DC_LADY] = critter.DeathCounters[DC_LADY]; cre->AppearanceFlags|=APP_LADY; } //increases murder variable if (critter.Flags&CF_MURDER) { cre->DeathCounters[DC_MURDER] = critter.DeathCounters[DC_MURDER]; cre->AppearanceFlags|=APP_MURDER; } //triggers help from same group if (critter.Flags&CF_BUDDY) { cre->AppearanceFlags|=APP_BUDDY; } if (critter.OverrideScript[0]) { cre->SetScript(critter.OverrideScript, SCR_OVERRIDE); } if (critter.ClassScript[0]) { cre->SetScript(critter.ClassScript, SCR_CLASS); } if (critter.RaceScript[0]) { cre->SetScript(critter.RaceScript, SCR_RACE); } if (critter.GeneralScript[0]) { cre->SetScript(critter.GeneralScript, SCR_GENERAL); } if (critter.DefaultScript[0]) { cre->SetScript(critter.DefaultScript, SCR_DEFAULT); } if (critter.AreaScript[0]) { cre->SetScript(critter.AreaScript, SCR_AREA); } if (critter.SpecificScript[0]) { cre->SetScript(critter.SpecificScript, SCR_SPECIFICS); } if (critter.Dialog[0]) { cre->SetDialog(critter.Dialog); } }
//unimplemented tags (* marks partially implemented, # marks not working in original either): //*check_crowd // control_var // spec_area //*death_faction //*death_team // check_by_view_port //*do_not_spawn // hold_selected_point_key // inc_spawn_point_index //*find_safest_point //#spawn_time_of_day // exit - similar to enter[spawn], this is a spawn branch type (on exiting an area?) // PST only //*auto_buddy //*detail_level void IniSpawn::ReadCreature(DataFileMgr *inifile, const char *crittername, CritterEntry &critter) const { const char *s; int ps; memset(&critter,0,sizeof(critter)); //first assume it is a simple numeric value critter.TimeOfDay = (ieDword) inifile->GetKeyAsInt(crittername,"time_of_day", 0xffffffff); //at this point critter.TimeOfDay is usually 0xffffffff s = inifile->GetKeyAsString(crittername,"time_of_day",NULL); if (s && strlen(s)>=24) { ieDword value = 0; ieDword j = 1; for(int i=0;i<24 && s[i];i++) { if (s[i]=='0' || s[i]=='o') value |= j; j<<=1; } //turn off individual bits marked by a 24 long string scheduling //example: '0000xxxxxxxxxxxxxxxx00000000' critter.TimeOfDay^=value; } if (inifile->GetKeyAsBool(crittername,"do_not_spawn",false)) { //if the do not spawn flag is true, ignore this entry return; } s = inifile->GetKeyAsString(crittername,"detail_level",NULL); if (s) { ieDword level; switch(s[0]) { case 'h': case 'H': level = 2; break; case 'm': case 'M': level = 1; break; default: level = 0; break; } //If the detail level is lower than this creature's detail level, //skip this entry, creature_count is 0, so it will be ignored at evaluation of the spawn if (level>detail_level) { return; } } //all specvars are using global, but sometimes it is explicitly given s = inifile->GetKeyAsString(crittername,"spec_var",NULL); if (s) { if ((strlen(s)>9) && s[6]==':' && s[7]==':') { strnuprcpy(critter.SpecContext, s, 6); strnlwrcpy(critter.SpecVar, s+8, 32); } else { strnuprcpy(critter.SpecContext, "GLOBAL", 6); strnlwrcpy(critter.SpecVar, s, 32); } } //add this to specvar at each spawn ps = inifile->GetKeyAsInt(crittername,"spec_var_inc", 0); critter.SpecVarInc=ps; //use this value with spec_var_operation to determine spawn ps = inifile->GetKeyAsInt(crittername,"spec_var_value",0); critter.SpecVarValue=ps; //this operation uses DiffCore s = inifile->GetKeyAsString(crittername,"spec_var_operation",""); critter.SpecVarOperator=GetDiffMode(s); //the amount of critters to spawn critter.TotalQuantity = inifile->GetKeyAsInt(crittername,"spec_qty",1); critter.SpawnCount = inifile->GetKeyAsInt(crittername,"create_qty",critter.TotalQuantity); //the creature resource(s) s = inifile->GetKeyAsString(crittername,"cre_file",NULL); if (s) { critter.creaturecount = CountElements(s,','); critter.CreFile=new ieResRef[critter.creaturecount]; GetElements(s, critter.CreFile, critter.creaturecount); } else { Log(ERROR, "IniSpawn", "Invalid spawn entry: %s", crittername); } s = inifile->GetKeyAsString(crittername,"point_select",NULL); if (s) { ps=s[0]; } else { ps=0; } s = inifile->GetKeyAsString(crittername,"spawn_point",NULL); if (s) { //expect more than one spawnpoint if (ps=='r') { //select one of the spawnpoints randomly int count = core->Roll(1,CountElements(s,']'),-1); //go to the selected spawnpoint while(count--) { while(*s++!=']') ; } } //parse the selected spawnpoint int x,y,o; if (sscanf(s,"[%d,%d:%d]", &x, &y, &o)==3) { critter.SpawnPoint.x=(short) x; critter.SpawnPoint.y=(short) y; critter.Orientation=o; } else if (sscanf(s,"[%d.%d:%d]", &x, &y, &o)==3) { critter.SpawnPoint.x=(short) x; critter.SpawnPoint.y=(short) y; critter.Orientation=o; } else if (sscanf(s,"[%d,%d]", &x, &y)==2) { critter.SpawnPoint.x=(short) x; critter.SpawnPoint.y=(short) y; critter.Orientation=core->Roll(1,16,-1); } else if (sscanf(s,"[%d.%d]", &x, &y)==2) { critter.SpawnPoint.x=(short) x; critter.SpawnPoint.y=(short) y; critter.Orientation=core->Roll(1,16,-1); } } //store or retrieve spawn point s = inifile->GetKeyAsString(crittername,"spawn_point_global", NULL); if (s) { switch (ps) { case 'e': critter.SpawnPoint.fromDword(CheckVariable(map, s+8,s)); break; default: //see save_selected_point //SetVariable(map, s+8, s, critter.SpawnPoint.asDword()); break; } } //take facing from variable s = inifile->GetKeyAsString(crittername,"spawn_facing_global", NULL); if (s) { switch (ps) { case 'e': critter.Orientation=(int) CheckVariable(map, s+8,s); break; default: //see save_selected_point //SetVariable(map, s+8, s, (ieDword) critter.Orientation); break; } } s = inifile->GetKeyAsString(crittername,"save_selected_point",NULL); if (s) { if ((strlen(s)>9) && s[6]==':' && s[7]==':') { SetVariable(map, s+8, s, critter.SpawnPoint.asDword()); } else { SetVariable(map, s, "GLOBAL", critter.SpawnPoint.asDword()); } } s = inifile->GetKeyAsString(crittername,"save_selected_facing",NULL); if (s) { if ((strlen(s)>9) && s[6]==':' && s[7]==':') { SetVariable(map, s+8, s, (ieDword) critter.Orientation); } else { SetVariable(map, s, "GLOBAL", (ieDword) critter.Orientation); } } //sometimes only the orientation is given, the point is stored in a variable ps = inifile->GetKeyAsInt(crittername,"facing",-1); if (ps!=-1) critter.Orientation = ps; ps = inifile->GetKeyAsInt(crittername, "ai_ea",-1); if (ps!=-1) critter.SetSpec[AI_EA] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_team",-1); if (ps!=-1) critter.SetSpec[AI_TEAM] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_general",-1); if (ps!=-1) critter.SetSpec[AI_GENERAL] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_race",-1); if (ps!=-1) critter.SetSpec[AI_RACE] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_class",-1); if (ps!=-1) critter.SetSpec[AI_CLASS] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_specifics",-1); if (ps!=-1) critter.SetSpec[AI_SPECIFICS] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_gender",-1); if (ps!=-1) critter.SetSpec[AI_GENDER] = (ieByte) ps; ps = inifile->GetKeyAsInt(crittername, "ai_alignment",-1); if (ps!=-1) critter.SetSpec[AI_ALIGNMENT] = (ieByte) ps; s = inifile->GetKeyAsString(crittername,"spec",NULL); if (s) { int x[9]; ps = sscanf(s,"[%d.%d.%d.%d.%d.%d.%d.%d.%d]", x, x+1, x+2, x+3, x+4, x+5, x+6, x+7, x+8); if (ps == 0) { strnuprcpy(critter.ScriptName, s, 32); critter.Flags|=CF_CHECK_NAME; memset(critter.Spec,-1,sizeof(critter.Spec)); } else { while(ps--) { critter.Spec[ps]=(ieByte) x[ps]; } } } s = inifile->GetKeyAsString(crittername,"script_name",NULL); if (s) { strnuprcpy(critter.ScriptName, s, 32); } //iwd2 script names (override remains the same) //special 1 == area s = inifile->GetKeyAsString(crittername,"script_special_1",NULL); if (s) { strnuprcpy(critter.AreaScript,s, 8); } //special 2 == class s = inifile->GetKeyAsString(crittername,"script_special_2",NULL); if (s) { strnuprcpy(critter.ClassScript,s, 8); } //special 3 == general s = inifile->GetKeyAsString(crittername,"script_special_3",NULL); if (s) { strnuprcpy(critter.GeneralScript,s, 8); } //team == specific s = inifile->GetKeyAsString(crittername,"script_team",NULL); if (s) { strnuprcpy(critter.SpecificScript,s, 8); } //combat == race s = inifile->GetKeyAsString(crittername,"script_combat",NULL); if (s) { strnuprcpy(critter.RaceScript,s, 8); } //movement == default s = inifile->GetKeyAsString(crittername,"script_movement",NULL); if (s) { strnuprcpy(critter.DefaultScript,s, 8); } //pst script names s = inifile->GetKeyAsString(crittername,"script_override",NULL); if (s) { strnuprcpy(critter.OverrideScript,s, 8); } s = inifile->GetKeyAsString(crittername,"script_class",NULL); if (s) { strnuprcpy(critter.ClassScript,s, 8); } s = inifile->GetKeyAsString(crittername,"script_race",NULL); if (s) { strnuprcpy(critter.RaceScript,s, 8); } s = inifile->GetKeyAsString(crittername,"script_general",NULL); if (s) { strnuprcpy(critter.GeneralScript,s, 8); } s = inifile->GetKeyAsString(crittername,"script_default",NULL); if (s) { strnuprcpy(critter.DefaultScript,s, 8); } s = inifile->GetKeyAsString(crittername,"script_area",NULL); if (s) { strnuprcpy(critter.AreaScript,s, 8); } s = inifile->GetKeyAsString(crittername,"script_specifics",NULL); if (s) { strnuprcpy(critter.SpecificScript,s, 8); } s = inifile->GetKeyAsString(crittername,"dialog",NULL); if (s) { strnuprcpy(critter.Dialog,s, 8); } //flags if (inifile->GetKeyAsBool(crittername,"death_scriptname",false)) { critter.Flags|=CF_DEATHVAR; } if (inifile->GetKeyAsBool(crittername,"death_faction",false)) { critter.Flags|=CF_FACTION; } if (inifile->GetKeyAsBool(crittername,"death_team",false)) { critter.Flags|=CF_TEAM; } ps = inifile->GetKeyAsInt(crittername,"good_mod",0); if (ps) { critter.Flags|=CF_GOOD; critter.DeathCounters[DC_GOOD] = ps; } ps = inifile->GetKeyAsInt(crittername,"law_mod",0); if (ps) { critter.Flags|=CF_LAW; critter.DeathCounters[DC_LAW] = ps; } ps = inifile->GetKeyAsInt(crittername,"lady_mod",0); if (ps) { critter.Flags|=CF_LADY; critter.DeathCounters[DC_LADY] = ps; } ps = inifile->GetKeyAsInt(crittername,"murder_mod",0); if (ps) { critter.Flags|=CF_MURDER; critter.DeathCounters[DC_MURDER] = ps; } if(inifile->GetKeyAsBool(crittername,"auto_buddy", false)) { critter.Flags|=CF_BUDDY; } //don't spawn when spawnpoint is visible if (inifile->GetKeyAsBool(crittername,"ignore_can_see",false)) { critter.Flags|=CF_IGNORECANSEE; } //unsure, but could be similar to previous if (inifile->GetKeyAsBool(crittername,"check_view_port", false)) { critter.Flags|=CF_CHECKVIEWPORT; } //unknown, this is used only in pst if (inifile->GetKeyAsBool(crittername,"check_crowd", false)) { critter.Flags|=CF_CHECKCROWD; } //unknown, this is used only in pst if (inifile->GetKeyAsBool(crittername,"find_safest_point", false)) { critter.Flags|=CF_SAFESTPOINT; } //disable spawn based on game difficulty if (inifile->GetKeyAsBool(crittername,"area_diff_1", false)) { critter.Flags|=CF_NO_DIFF_1; } if (inifile->GetKeyAsBool(crittername,"area_diff_2", false)) { critter.Flags|=CF_NO_DIFF_2; } if (inifile->GetKeyAsBool(crittername,"area_diff_3", false)) { critter.Flags|=CF_NO_DIFF_3; } }
//------------------------------------------------------------------------------ // void SaveData() //------------------------------------------------------------------------------ void AchievePanel::SaveData() { #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage (wxT("AchievePanel::SaveData() entered, mIsTextModified=%d\n"), mIsTextModified); #endif canClose = true; wxString inputString; //----------------------------------------------------------------- // check input values: Number, Variable, Array element, Parameter //----------------------------------------------------------------- if (mIsTextModified) { inputString = mGoalValue.c_str(); CheckVariable(mGoalValue.c_str(), Gmat::SPACECRAFT, wxT("GoalValue"), wxT("Real Number, Variable, Array element, plottable Parameter"), true); inputString = mToleranceTextCtrl->GetValue(); CheckVariable(inputString.c_str(), Gmat::SPACECRAFT, wxT("Tolerance"), wxT("Real Number, Variable, Array element, plottable Parameter"), true); } if (!canClose) return; //------------------------------------------------------- // Saving Solver Data //------------------------------------------------------- try { mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID(wxT("TargeterName")), mSolverName.c_str()); mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID(wxT("Goal")), mGoalName.c_str()); if (mIsTextModified) { #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage (wxT(" Setting GoalValue to %s\n Setting Tolerance to %s\n"), mGoalValue.c_str(), mTolerance.c_str()); #endif mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID(wxT("GoalValue")), mGoalValue.c_str()); mTolerance = mToleranceTextCtrl->GetValue(); mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID(wxT("Tolerance")), mTolerance.c_str()); mIsTextModified = false; } if (!theGuiInterpreter->ValidateCommand(mAchieveCommand)) canClose = false; } catch (BaseException &e) { MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage()); canClose = false; } }
//------------------------------------------------------------------------------ // void SaveData() //------------------------------------------------------------------------------ void AchievePanel::SaveData() { #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage ("AchievePanel::SaveData() entered, mIsTextModified=%d\n", mIsTextModified); #endif canClose = true; std::string inputString; //----------------------------------------------------------------- // check input values: Number, Variable, Array element, Parameter //----------------------------------------------------------------- if (mIsTextModified) { ObjectTypeArray objTypes; objTypes.push_back(Gmat::SPACE_POINT); objTypes.push_back(Gmat::IMPULSIVE_BURN); inputString = mGoalValue.c_str(); CheckVariable(mGoalValue.c_str(), objTypes, "GoalValue", "Real Number, Variable, Array element, plottable Parameter", true); inputString = mToleranceTextCtrl->GetValue(); CheckVariable(inputString.c_str(), objTypes, "Tolerance", "Real Number, Variable, Array element, plottable Parameter", true); } if (!canClose) return; //------------------------------------------------------- // Saving Solver Data //------------------------------------------------------- try { #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage(" Setting Solver to '%s'\n", mSolverName.c_str()); #endif mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID("TargeterName"), mSolverName.c_str()); if (mIsTextModified) { #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage (" Setting Goal to '%s', Value to '%s', Tolerance to '%s'\n", mGoalName.c_str(), mGoalValue.c_str(), mTolerance.c_str()); #endif mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID("Goal"), mGoalName.c_str()); mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID("GoalValue"), mGoalValue.c_str()); mTolerance = mToleranceTextCtrl->GetValue(); mAchieveCommand->SetStringParameter (mAchieveCommand->GetParameterID("Tolerance"), mTolerance.c_str()); mIsTextModified = false; #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage(" Calling theGuiInterpreter->ValidateCommand()\n"); #endif if (!theGuiInterpreter->ValidateCommand(mAchieveCommand)) { #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage(" Failed to validate command\n"); #endif canClose = false; } } } catch (BaseException &e) { MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage()); canClose = false; } #if DEBUG_ACHIEVE_PANEL_SAVE MessageInterface::ShowMessage ("AchievePanel::SaveData() leaving, canClose=%d\n", canClose); #endif }
//------------------------------------------------------------------------------ // void SaveData() //------------------------------------------------------------------------------ void VaryPanel::SaveData() { #ifdef DEBUG_VARYPANEL_SAVE MessageInterface::ShowMessage("VaryPanel::SaveData() entered\n"); #endif canClose = true; std::string strInitVal, strPert, strLower, strUpper, strMaxStep; std::string strAddSf, strMultSf; //----------------------------------------------------------------- // check input values: Number, Variable, Array element, Parameter //----------------------------------------------------------------- std::string expRange = "Real Number, Variable, Array element, Plottable Parameter"; ObjectTypeArray objTypes; objTypes.push_back(Gmat::UNKNOWN_OBJECT); // Any plottable Parameters allowed, so use UNKNOWN_OBJECT if (mInitialTextCtrl->IsModified()) { strInitVal = mInitialTextCtrl->GetValue().c_str(); CheckVariable(strInitVal, objTypes, "InitialValue", expRange, true); } if (mPertTextCtrl->IsModified()) { strPert = mPertTextCtrl->GetValue().c_str(); CheckVariable(strPert, objTypes, "Perturbation", expRange, true); } if (mLowerValueTextCtrl->IsModified()) { strLower = mLowerValueTextCtrl->GetValue().c_str(); CheckVariable(strLower, objTypes, "Lower", expRange, true); } if (mUpperValueTextCtrl->IsModified()) { strUpper = mUpperValueTextCtrl->GetValue().c_str(); CheckVariable(strUpper.c_str(), objTypes, "Upper", expRange, true); } if (mMaxStepTextCtrl->IsModified()) { strMaxStep = mMaxStepTextCtrl->GetValue().c_str(); CheckVariable(strMaxStep.c_str(), objTypes, "MaxStep", expRange, true); } if (mAdditiveTextCtrl->IsModified()) { strAddSf = mAdditiveTextCtrl->GetValue().c_str(); CheckVariable(strAddSf.c_str(), objTypes, "AdditiveScaleFactor", expRange, true); } if (mMultiplicativeTextCtrl->IsModified()) { strMultSf = mMultiplicativeTextCtrl->GetValue().c_str(); CheckVariable(strMultSf.c_str(), objTypes, "MultiplicativeScaleFactor", expRange, true); } if (!canClose) return; //----------------------------------------------------------------- // save values to base, base code should do the range checking //----------------------------------------------------------------- #ifdef DEBUG_VARYPANEL_SAVE MessageInterface::ShowMessage(" solverName=%s, variableName=%s\n", solverName.c_str(), variableName.c_str()); #endif Solver *solver = (Solver*)theGuiInterpreter->GetConfiguredObject(solverName); if (solver == NULL) throw GmatBaseException("Cannot find the solver: " + solverName); bool validateCommand = false; try { bool changed = false; if (solverChanged) { #ifdef DEBUG_VARYPANEL_SAVE MessageInterface::ShowMessage (" Solver changed, solver=<%p>'%s'\n", solver, solver->GetName().c_str()); #endif mVaryCommand->SetStringParameter("SolverName", solverName); mVaryCommand->SetRefObject(solver, Gmat::SOLVER, solverName); solverChanged = false; changed = true; } if (variableChanged) { #ifdef DEBUG_VARYPANEL_SAVE MessageInterface::ShowMessage (" Variable changed, variableName='%s'\n", variableName.c_str()); #endif validateCommand = true; mVaryCommand->SetStringParameter("Variable", variableName); solver->SetStringParameter("Variables", variableName); variableChanged = false; changed = true; } if (mInitialTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("InitialValue", strInitVal.c_str()); mInitialTextCtrl->DiscardEdits(); changed = true; } if (mPertTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("Perturbation", strPert.c_str()); mPertTextCtrl->DiscardEdits(); changed = true; } if (mLowerValueTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("Lower", strLower.c_str()); mLowerValueTextCtrl->DiscardEdits(); changed = true; } if (mUpperValueTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("Upper", strUpper.c_str()); mUpperValueTextCtrl->DiscardEdits(); changed = true; } if (mMaxStepTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("MaxStep", strMaxStep.c_str()); mMaxStepTextCtrl->DiscardEdits(); changed = true; } if (mAdditiveTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("AdditiveScaleFactor", strAddSf.c_str()); mAdditiveTextCtrl->DiscardEdits(); changed = true; } if (mMultiplicativeTextCtrl->IsModified()) { validateCommand = true; mVaryCommand->SetStringParameter("MultiplicativeScaleFactor", strMultSf.c_str()); mMultiplicativeTextCtrl->DiscardEdits(); changed = true; } if (changed) mVaryCommand->SetRefObject(solver, Gmat::SOLVER, solverName); // avoid unnecessary validation since it clears all wrappers and recreates them if (validateCommand) { #ifdef DEBUG_VARYPANEL_SAVE MessageInterface::ShowMessage(" Calling ValidateCommand()\n"); #endif if (!theGuiInterpreter->ValidateCommand(mVaryCommand)) canClose = false; } } catch (BaseException &e) { MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage()); canClose = false; } #ifdef DEBUG_VARYPANEL_SAVE MessageInterface::ShowMessage("VaryPanel::SaveData() leaving\n"); #endif }
/************************************************************************** * Function: prepareParameter * Functionality: it will get the parameter from pipe and check it * @IN : fd: the file description id for the pipe * enable: enable or disable flag * @OUT: 0 success, else failed. * Used description: The parameter is a xml, it will get from the pipe * Date: 20080108 * Changed history: * Date Who Reason * 20080108 kelly First creation ***************************************************************************/ int prepareParameter(PSystemConfig **pList,int *count) { IXML_Document *rootDom = NULL; IXML_NodeList *nodeList = NULL; IXML_NodeList *nodeList2 = NULL; IXML_Node *node = NULL; IXML_Node *cmdNode = NULL; IXML_Node *node2 = NULL; char buffer[1024] = {0}; char Str[1024] = {0}; int i = 0; int i_ret=0; int nodeLen = 0; PSystemConfig *pConfigList = NULL; while(1) { fgets(Str, 1024, stdin); strcat(buffer, Str); if(strstr(buffer,EndFlag)) break; } if(strlen(buffer) == 0) goto failed; if((rootDom = ixmlParseBuffer(buffer)) == NULL){ i_ret = -1; goto Err_handler; } if((nodeList = ixmlDocument_getElementsByTagName(rootDom,"cmd")) != NULL) { cmdNode = ixmlGetFirstNodeByTagName(rootDom,"cmd"); nodeList2 = ixmlNode_getChildNodes(cmdNode); nodeLen = ixmlNodeList_length(nodeList2); pConfigList = (PSystemConfig*)malloc(sizeof(PSystemConfig) * nodeLen); memset(pConfigList, 0, sizeof(PSystemConfig)*nodeLen); node = ixmlNodeList_item(nodeList, 0); node = ixmlNode_getFirstChild(node); while (node != NULL) { pConfigList[i] = (PSystemConfig)malloc(sizeof(SystemConfig)); memset(pConfigList[i],0,sizeof(SystemConfig)); pConfigList[i]->name = strdup(ixmlNode_getNodeName(node)); node2 = ixmlNode_getFirstChild(node); pConfigList[i]->value = (ixmlNode_getNodeValue(node2))?strdup(ixmlNode_getNodeValue(node2)):strdup(""); /* fprintf(stderr, "name->%s , value ->%s\n" , pConfigList[i]->name , pConfigList[i]->value); */ i_ret=CheckVariable(pConfigList[i]->name,pConfigList[i]->value); if(i_ret<0) { i_ret = -3; goto Err_handler; } node = ixmlNode_getNextSibling(node); i++; } } *count = nodeLen; if(pConfigList){ *pList = pConfigList; } else{ fprintf(stderr, " !!!!!!pLIST is NULL"); } if (rootDom) ixmlDocument_free(rootDom); if (nodeList) ixmlNodeList_free(nodeList); if (nodeList2) ixmlNodeList_free(nodeList2); return i; failed: fprintf(stderr,"Got a command parameter->%s", buffer); //fprintf(stderr,"Got a command parameter->%s", buffer); return i; Err_handler: if (rootDom) ixmlDocument_free(rootDom); if (nodeList) ixmlNodeList_free(nodeList); if (nodeList2) ixmlNodeList_free(nodeList2); return i_ret; }
//------------------------------------------------------------------------------ // void SaveData() //------------------------------------------------------------------------------ void NonlinearConstraintPanel::SaveData() { #if DEBUG_NLC_PANEL MessageInterface::ShowMessage(wxT("NonlinearConstraintPanel::SaveData() entered\n")); #endif canClose = true; wxString inputString; //----------------------------------------------------------------- // check input values: Number, Variable, Array element, Parameter //----------------------------------------------------------------- inputString = mLHSTextCtrl->GetValue().c_str(); CheckVariable(inputString, Gmat::SPACECRAFT, wxT("Constraint"), wxT("Real Number, Variable, Array element, plottable Parameter"), true); inputString = mRHSTextCtrl->GetValue().c_str(); CheckVariable(inputString, Gmat::SPACECRAFT, wxT("Constraint Value"), wxT("Real Number, Variable, Array element, plottable Parameter"), true); if (!canClose) return; //----------------------------------------------------------------- // save values to base, base code should do the range checking //----------------------------------------------------------------- try { mNonlinearConstraintCommand->SetStringParameter (mNonlinearConstraintCommand->GetParameterID(wxT("OptimizerName")), mSolverComboBox->GetValue().c_str()); mNonlinearConstraintCommand->SetStringParameter (mNonlinearConstraintCommand->GetParameterID(wxT("ConstraintArg1")), mLHSTextCtrl->GetValue().c_str()); mNonlinearConstraintCommand->SetStringParameter (mNonlinearConstraintCommand->GetParameterID(wxT("Operator")), mComparisonComboBox->GetValue().c_str()); #if DEBUG_NLC_PANEL MessageInterface::ShowMessage(wxT(" about to save ConstraintArg2 value\n")); #endif mNonlinearConstraintCommand->SetStringParameter (mNonlinearConstraintCommand->GetParameterID(wxT("ConstraintArg2")), mRHSTextCtrl->GetValue().c_str()); #if DEBUG_NLC_PANEL MessageInterface::ShowMessage(wxT(" finished saving ConstraintArg2 value\n")); #endif theGuiInterpreter->ValidateCommand(mNonlinearConstraintCommand); EnableUpdate(false); } catch (BaseException &e) { MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage()); canClose = false; return; } #if DEBUG_NLC_PANEL MessageInterface::ShowMessage(wxT("NonlinearConstraintPanel::SaveData() exited\n")); #endif }
//------------------------------------------------------------------------------ // void SaveData() //------------------------------------------------------------------------------ void WhilePanel::SaveData() { canClose = true; //----------------------------------------------------------------- // check for incomplete conditions //----------------------------------------------------------------- mNumberOfConditions = 0; Integer itemMissing = 0; mLogicalOpStrings.clear(); mLhsList.clear(); mEqualityOpStrings.clear(); mRhsList.clear(); for (Integer i=0; i<MAX_ROW; i++) { itemMissing = 0; for (Integer j=0; j<MAX_COL; j++) { if (conditionGrid->GetCellValue(i, j) == wxT("")) itemMissing++; } if (itemMissing == 0) { mNumberOfConditions++; mLogicalOpStrings.push_back(conditionGrid->GetCellValue(i, 0).c_str()); mLhsList.push_back(conditionGrid->GetCellValue(i, 1).c_str()); mEqualityOpStrings.push_back(conditionGrid->GetCellValue(i, 2).c_str()); mRhsList.push_back(conditionGrid->GetCellValue(i, 3).c_str()); } else if (itemMissing < 4) { MessageInterface::PopupMessage (Gmat::ERROR_, wxT("Logical operator or parameters are missing in row %d.\n"), i+1); canClose = false; return; } } #if DEBUG_WHILE_PANEL MessageInterface::ShowMessage (wxT("WhilePanel::SaveData() mNumberOfConditions=%d\n"), mNumberOfConditions); #endif if (mNumberOfConditions == 0) { MessageInterface::PopupMessage (Gmat::WARNING_, wxT("Incomplete parameters for If condition.\n") wxT("Updates have not been saved")); canClose = false; return; } //----------------------------------------------------------------- // check input values: Number, Variable, Array element, Parameter //----------------------------------------------------------------- for (UnsignedInt i=0; i<mLhsList.size(); i++) CheckVariable(mLhsList[i].c_str(), Gmat::SPACECRAFT, wxT("LHS"), wxT("Variable, Array element, plottable Parameter"), true); for (UnsignedInt i=0; i<mRhsList.size(); i++) CheckVariable(mRhsList[i].c_str(), Gmat::SPACECRAFT, wxT("RHS"), wxT("Variable, Array element, plottable Parameter"), true); if (!canClose) return; //----------------------------------------------------------------- // save values to base, base code should do the range checking //----------------------------------------------------------------- try { for (Integer i = 0; i < mNumberOfConditions; i++) { #if DEBUG_WHILE_PANEL MessageInterface::ShowMessage (wxT(" i=%d, mLogicalOpStrings='%s', mLhsList='%s', mEqualityOpStrings='%s'\n") wxT(" mRhsList='%s'\n"), i, mLogicalOpStrings[i].c_str(), mLhsList[i].c_str(), mEqualityOpStrings[i].c_str(), mRhsList[i].c_str()); #endif try { theWhileCommand->SetCondition(mLhsList[i], mEqualityOpStrings[i], mRhsList[i], i); if (i > 0) theWhileCommand->SetConditionOperator(mLogicalOpStrings[i], i-1); } catch (BaseException &be) { MessageInterface::PopupMessage(Gmat::WARNING_, be.GetFullMessage()); canClose = false; // We want to go through all conditions and show errors if any //return; } } if (canClose) if (!theGuiInterpreter->ValidateCommand(theWhileCommand)) canClose = false; } catch (BaseException &e) { MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage()); canClose = false; } }
//------------------------------------------------------------------------------ void ForPanel::SaveData() { #if DEBUG_FOR_PANEL_SAVE MessageInterface::ShowMessage("ForPanel::SaveData() entered\n"); #endif canClose = true; ObjectTypeArray objTypes; objTypes.push_back(Gmat::SPACE_POINT); objTypes.push_back(Gmat::IMPULSIVE_BURN); //----------------------------------------------------------------- // check input values: Number, Variable, Array element, Parameter //----------------------------------------------------------------- CheckVariable(mIndexString.c_str(), objTypes, "Index", "Variable", false); CheckVariable(mStartString.c_str(), objTypes, "Start", "Real Number, Variable, Array element, plottable Parameter", true); CheckVariable(mIncrString.c_str(), objTypes, "Increment", "Real Number, Variable, Array element, plottable Parameter", true); CheckVariable(mEndString.c_str(), objTypes, "End", "Real Number, Variable, Array element, plottable Parameter", true); if (!canClose) { #if DEBUG_FOR_PANEL_SAVE MessageInterface::ShowMessage("ForPanel::SaveData() leaving, error encountered\n"); #endif return; } //----------------------------------------------------------------- // save values to base, base code should do the range checking //----------------------------------------------------------------- try { // Since validation is not done until element wrappers are created, // need to create a clone For *clonedForCommand = (For*)theForCommand->Clone(); Integer paramId; paramId = clonedForCommand->GetParameterID("IndexName"); clonedForCommand->SetStringParameter(paramId, mIndexString.c_str()); paramId = clonedForCommand->GetParameterID("StartName"); clonedForCommand->SetStringParameter(paramId, mStartString.c_str()); paramId = clonedForCommand->GetParameterID("EndName"); clonedForCommand->SetStringParameter(paramId, mEndString.c_str()); paramId = clonedForCommand->GetParameterID("IncrementName"); clonedForCommand->SetStringParameter(paramId, mIncrString.c_str()); bool contOnError = theGuiInterpreter->GetContinueOnError(); theGuiInterpreter->SetContinueOnError(false); if (!theGuiInterpreter->ValidateCommand(clonedForCommand)) canClose = false; theGuiInterpreter->SetContinueOnError(contOnError); // Copy cloned command to original and validate if cloned validation was successful if (canClose) { #if DEBUG_FOR_PANEL_SAVE MessageInterface::ShowMessage (" Copying cloned <%p> to original <%p>, and validating command to create wrppers\n", clonedForCommand, theForCommand); #endif theForCommand->Copy(clonedForCommand); theGuiInterpreter->ValidateCommand(theForCommand); } delete clonedForCommand; } catch (BaseException &e) { MessageInterface::PopupMessage(Gmat::ERROR_, e.GetFullMessage()); canClose = false; } #if DEBUG_FOR_PANEL_SAVE MessageInterface::ShowMessage("ForPanel::SaveData() leaving, canClose=%d\n", canClose); #endif }