//------------------------------------------------------------------------------ // 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 }
//------------------------------------------------------------------------------ // 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 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 }