//------------------------------------------------------------------------------ bool PropagationStateManager::SetProperty(std::string propName) { #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Entered SetProperty(%s); current = %ld\n", propName.c_str(), current); #endif if (current) { // Validate that the property can be propagated if (current->SetPropItem(propName) == Gmat::UNKNOWN_STATE) throw PropagatorException(propName + " is not a known propagation parameter on " + current->GetName()); // Only add it if it is not yet there if (find(elements[current]->begin(), elements[current]->end(), propName) == elements[current]->end()) elements[current]->push_back(propName); #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Current property List:\n"); for (StringArray::iterator i = elements[current]->begin(); i != elements[current]->end(); ++i) MessageInterface::ShowMessage(" %s\n", i->c_str()); #endif return true; } return false; }
//------------------------------------------------------------------------------ const StringArray& ObjectReferencedAxes::GetRefObjectNameArray(const Gmat::ObjectType type) { if (type == Gmat::UNKNOWN_OBJECT || type == Gmat::SPACE_POINT) { static StringArray refs; refs.clear(); refs = DynamicAxes::GetRefObjectNameArray(type); if (find(refs.begin(), refs.end(), primaryName) == refs.end()) refs.push_back(primaryName); if (find(refs.begin(), refs.end(), secondaryName) == refs.end()) refs.push_back(secondaryName); if (find(refs.begin(), refs.end(), originName) == refs.end()) refs.push_back(originName); if (find(refs.begin(), refs.end(), j2000BodyName) == refs.end()) refs.push_back(j2000BodyName); #ifdef DEBUG_REFERENCE_SETTING MessageInterface::ShowMessage("+++ReferenceObjects:\n"); for (StringArray::iterator i = refs.begin(); i != refs.end(); ++i) MessageInterface::ShowMessage(" %s\n", i->c_str()); #endif return refs; } // Not handled here -- invoke the next higher GetRefObject call return DynamicAxes::GetRefObjectNameArray(type); }
//------------------------------------------------------------------------------ bool Formation::SetStringParameter(const Integer id, const std::string &value) { if (id == ADDED_SPACECRAFT) { if (find(componentNames.begin(), componentNames.end(), value) != componentNames.end()) return false; componentNames.push_back(value); #ifdef DEBUG_FORMATION_ACTIONS MessageInterface::ShowMessage("%s%s%s\n", "Formation \"", instanceName.c_str(), "\" now consists of these spacecraft names:"); for (StringArray::iterator i = componentNames.begin(); i != componentNames.end(); ++i) MessageInterface::ShowMessage(" \"%s\"\n", i->c_str()); #endif parmsChanged = true; return true; } if (id == REMOVED_SPACECRAFT) { return RemoveSpacecraft(value); } return FormationInterface::SetStringParameter(id, value); }
//------------------------------------------------------------------------------ bool PropagationStateManager::SetProperty(std::string propName, GmatBase *forObject) { #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Entered SetProperty(%s, %s)\n", propName.c_str(), forObject->GetName().c_str()); #endif if (find(objects.begin(), objects.end(), forObject) == objects.end()) throw PropagatorException("Prop object " + forObject->GetName() + " not found in a propagation state manager\n"); if (forObject) { // Validate that the property can be propagated if (forObject->SetPropItem(propName) == Gmat::UNKNOWN_STATE) throw PropagatorException(propName + " is not a known propagation parameter on " + forObject->GetName()); if (find(elements[forObject]->begin(), elements[forObject]->end(), propName) == elements[forObject]->end()) elements[forObject]->push_back(propName); #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Current property List:\n"); for (StringArray::iterator i = elements[forObject]->begin(); i != elements[forObject]->end(); ++i) MessageInterface::ShowMessage(" %s\n", i->c_str()); #endif return true; } return false; }
//------------------------------------------------------------------------------ const StringArray& HarmonicField::GetRefObjectNameArray(const Gmat::ObjectType type) { static StringArray refs; // Start from an empty list refs.clear(); if (type == Gmat::UNKNOWN_OBJECT) { refs = GravityBase::GetRefObjectNameArray(type); //refs.clear(); // why would I want to clear this???? refs.push_back(inputCSName); refs.push_back(fixedCSName); refs.push_back(targetCSName); #ifdef DEBUG_REFERENCE_SETTING MessageInterface::ShowMessage("+++ReferenceObjects:\n"); for (StringArray::iterator i = refs.begin(); i != refs.end(); ++i) MessageInterface::ShowMessage(" %s\n", i->c_str()); #endif return refs; } if (type == Gmat::COORDINATE_SYSTEM) { refs = GravityBase::GetRefObjectNameArray(type); refs.push_back(inputCSName); refs.push_back(fixedCSName); refs.push_back(targetCSName); #ifdef DEBUG_REFERENCE_SETTING MessageInterface::ShowMessage("+++ReferenceObjects:\n"); for (StringArray::iterator i = refs.begin(); i != refs.end(); ++i) MessageInterface::ShowMessage(" %s\n", i->c_str()); #endif return refs; } // Not handled here -- invoke the next higher GetRefObject call return GravityBase::GetRefObjectNameArray(type); }
//------------------------------------------------------------------------------ bool Formation::RemoveSpacecraft(const std::string &name) { #ifdef DEBUG_FORMATION_ACTIONS MessageInterface::ShowMessage("%s%s\"\n", "Formation::RemoveSpacecraft called to remove \"", name.c_str()); #endif StringArray::iterator scPos = find(componentNames.begin(), componentNames.end(), name); if (scPos != componentNames.end()) { componentNames.erase(scPos); // Now remove the pointer from the component list std::vector<SpaceObject *>::iterator j; SpaceObject *current; for (j = components.begin(); j < components.end(); ++j) { current = *j; if (current->GetName() == name) { components.erase(j); break; } } #ifdef DEBUG_FORMATION_ACTIONS MessageInterface::ShowMessage("%s%s%s\n", "Formation \"", instanceName.c_str(), "\" now consists of these spacecraft names:"); for (StringArray::iterator i = componentNames.begin(); i != componentNames.end(); ++i) MessageInterface::ShowMessage(" \"%s\"\n", i->c_str()); MessageInterface::ShowMessage("%s%s%s\n", "Formation \"", instanceName.c_str(), "\" now consists of these spacecraft:"); for (j = components.begin(); j < components.end(); ++j) { MessageInterface::ShowMessage( " \"%s\"\n", (*j)->GetName().c_str()); } #endif parmsChanged = true; return true; } #ifdef DEBUG_FORMATION_ACTIONS MessageInterface::ShowMessage("%s%s\"\n", "Formation::RemoveSpacecraft Did not find \"", name.c_str()); #endif return false; }
//------------------------------------------------------------------------------ const StringArray& Estimator::GetRefObjectNameArray(const Gmat::ObjectType type) { #ifdef DEBUG_ESTIMATOR_INITIALIZATION MessageInterface::ShowMessage( "Estimator::GetRefObjectNameArray(%d) entered\n", type); #endif refObjectList.clear(); if ((type == Gmat::UNKNOWN_OBJECT) || (type == Gmat::PROP_SETUP) || (type == Gmat::MEASUREMENT_MODEL)) { if ((type == Gmat::UNKNOWN_OBJECT) || (type == Gmat::PROP_SETUP)) { #ifdef DEBUG_ESTIMATOR_INITIALIZATION MessageInterface::ShowMessage( " Adding propagator: %s\n", propagatorName.c_str()); #endif if (find(refObjectList.begin(), refObjectList.end(), propagatorName) == refObjectList.end()) refObjectList.push_back(propagatorName); } if ((type == Gmat::UNKNOWN_OBJECT) || (type == Gmat::MEASUREMENT_MODEL)) { // Add the measurements this simulator needs for (StringArray::iterator i = measurementNames.begin(); i != measurementNames.end(); ++i) { #ifdef DEBUG_ESTIMATOR_INITIALIZATION MessageInterface::ShowMessage( " Adding measurement: %s\n", i->c_str()); #endif if (find(refObjectList.begin(), refObjectList.end(), *i) == refObjectList.end()) refObjectList.push_back(*i); } } } else { // Fill in any base class needs refObjectList = Solver::GetRefObjectNameArray(type); } return refObjectList; }
void Group::HandleAllMsgs( HOBJECT hSender, const CParsedMsg &crParsedMsg ) { char szMsgArgs[256]; crParsedMsg.ReCreateMsg( szMsgArgs, ARRAY_LEN(szMsgArgs), 0 ); if( !szMsgArgs[0] ) return; for( StringArray::iterator iter = m_saObjectNames.begin(); iter != m_saObjectNames.end(); ++iter ) { if( !(*iter).empty() ) { const char* pszObjectName = iter->c_str(); // This needs to be format string characters + // LTARRAYSIZE(szMsgArgs) + MaxObjectName characters long. char szMsg[10 + LTARRAYSIZE(szMsgArgs) + MAX_CS_FILENAME_LEN]; LTSNPrintF(szMsg, LTARRAYSIZE(szMsg), "msg %s (%s);", pszObjectName, szMsgArgs ); g_pCmdMgr->QueueCommand( szMsg, hSender, NULL ); } } }
//------------------------------------------------------------------------------ bool PropagationStateManager::SetProperty(std::string propName, Integer index) { #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Entered SetProperty(%s, %d)\n", propName.c_str(), index); #endif if ((index < 0) || (index >= (Integer)objects.size())) throw PropagatorException("Index out of bounds specifying a prop object " "in a propagation state manager\n"); GmatBase *obj = objects[index]; if (obj) { // Validate that the property can be propagated if (obj->SetPropItem(propName) == Gmat::UNKNOWN_STATE) throw PropagatorException(propName + " is not a known propagation parameter on " + obj->GetName()); if (find(elements[obj]->begin(), elements[obj]->end(), propName) == elements[obj]->end()) elements[obj]->push_back(propName); #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Current property List:\n"); for (StringArray::iterator i = elements[obj]->begin(); i != elements[obj]->end(); ++i) MessageInterface::ShowMessage(" %s\n", i->c_str()); #endif return true; } return false; }
//------------------------------------------------------------------------------ void Formation::BuildState() { #ifdef DEBUG_FORMATION_ACTIONS MessageInterface::ShowMessage("%s%s%s%d\n", "In BuildState, Formation \"", instanceName.c_str(), "\" has dimension ", dimension); #endif if (dimension <= 0) throw SpaceObjectException( "Error building Formation state; no spacecraft are set"); // Setup the GmatState Real *data = new Real[dimension], *st; Integer j = 0, k; GmatState *ps; if (state.GetSize() < dimension) state.SetSize(dimension); for (std::vector<SpaceObject*>::iterator i = components.begin(); i != components.end(); ++i) { if ((*i) == NULL) throw SpaceObjectException( "Error building Formation state; member spacecraft not set"); ps = &((*i)->GetState()); st = ps->GetState(); for (k = 0; k < ps->GetSize(); ++k) { data[j + k] = st[k]; } j += ps->GetSize(); } #ifdef DEBUG_FORMATION_ACTIONS MessageInterface::ShowMessage("%s%s%s\n", "In BuildState, Formation \"", instanceName.c_str(), "\" consists of these spacecraft names:"); for (StringArray::iterator i = componentNames.begin(); i != componentNames.end(); ++i) MessageInterface::ShowMessage(" \"%s\"\n", i->c_str()); MessageInterface::ShowMessage("%s%s%s\n", "In BuildState, Formation \"", instanceName.c_str(), "\" consists of these spacecraft:"); for (std::vector<SpaceObject *>::iterator j = components.begin(); j < components.end(); ++j) { MessageInterface::ShowMessage(" \"%s\"\n", (*j)->GetName().c_str()); } #endif if (!state.SetState(data, dimension)) { delete [] data; throw SpaceObjectException("Error building Formation state"); } // as per kw report // Shouldn't we delete data here since GmatState::SetState() copies the data delete [] data; }
//------------------------------------------------------------------------------ Integer EstimationStateManager::SortVector() { StringArray *elementList; std::vector<Integer> order; std::vector<Integer> idList; ObjectArray owners; StringArray property; std::vector<Integer>::iterator oLoc; Integer id = -1; Integer size, loc = 0, val; stateSize = 0; // First build a list of the property IDs and objects, measuring state size // at the same time for (std::map<GmatBase*, StringArray*>::iterator i = elements.begin(); i != elements.end(); ++i) { current = i->first; elementList = i->second; for (StringArray::iterator j = elementList->begin(); j != elementList->end(); ++j) { id = current->GetEstimationParameterID(*j); // if (id == Gmat::UNKNOWN_STATE) // throw EstimatorException("Unknown state element: " + (*j)); #ifdef DEBUG_OBJECT_MAPPING MessageInterface::ShowMessage("Element ID for %s is %d;", j->c_str(), id); #endif size = current->GetEstimationParameterSize(id); #ifdef DEBUG_OBJECT_MAPPING MessageInterface::ShowMessage(" size is %d\n", size); #endif stateSize += size; for (Integer k = 0; k < size; ++k) { idList.push_back(id); owners.push_back(current); property.push_back(*j); // Put this item in the ordering list oLoc = order.begin(); while (oLoc != order.end()) { val = idList[*oLoc]; if (id < val) { #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("Inserting; id = %d, z = %d," " loc = %d\n", id, (*oLoc), loc); #endif order.insert(oLoc, loc); break; } ++oLoc; } if (oLoc == order.end()) order.push_back(loc); ++loc; } } } ListItem *newItem; val = 0; for (Integer i = 0; i < stateSize; ++i) { #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("%d <- %d: %d %s.%s gives ", i, order[i], idList[order[i]], owners[order[i]]->GetName().c_str(), property[order[i]].c_str()); #endif newItem = new ListItem; newItem->objectName = owners[order[i]]->GetName(); newItem->elementName = property[order[i]]; newItem->object = owners[order[i]]; newItem->elementID = idList[order[i]]; newItem->subelement = ++val; newItem->parameterID = owners[order[i]]->GetParameterID(property[order[i]]); newItem->parameterType = owners[order[i]]->GetParameterType(newItem->parameterID); if (newItem->parameterType == Gmat::REAL_TYPE) newItem->parameterID += val - 1; #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("[%s, %s, %d, %d, %d, %d]\n", newItem->objectName.c_str(), newItem->elementName.c_str(), newItem->elementID, newItem->subelement, newItem->parameterID, newItem->parameterType); #endif if (newItem->parameterType == Gmat::RVECTOR_TYPE) { const Rvector mat = owners[order[i]]->GetRvectorParameter(property[order[i]]); newItem->rowLength = mat.GetSize(); newItem->rowIndex = val-1; } if (newItem->parameterType == Gmat::RMATRIX_TYPE) { const Rmatrix mat = owners[order[i]]->GetRmatrixParameter(property[order[i]]); newItem->rowLength = mat.GetNumColumns(); newItem->colIndex = (val-1) % newItem->rowLength; newItem->rowIndex = (Integer)((val - 1) / newItem->rowLength); #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage( "RowLen = %d, %d -> row %2d col %2d\n", newItem->rowLength, val, newItem->rowIndex, newItem->colIndex); #endif } newItem->length = owners[order[i]]->GetEstimationParameterSize(idList[order[i]]); if (val == newItem->length) val = 0; stateMap.push_back(newItem); } #ifdef DEBUG_STATE_CONSTRUCTION MessageInterface::ShowMessage("State size = %d; map contents:\n", stateSize); for (std::vector<ListItem*>::iterator i = stateMap.begin(); i != stateMap.end(); ++i) MessageInterface::ShowMessage(" %s %s %d %d of %d, id = %d\n", (*i)->objectName.c_str(), (*i)->elementName.c_str(), (*i)->elementID, (*i)->subelement, (*i)->length, (*i)->parameterID); #endif return stateSize; }
//------------------------------------------------------------------------------ bool Minimize::InterpretAction() { #ifdef DEBUG_MINIMIZE // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ debug ~~~~ MessageInterface::ShowMessage("Interpreting Minimize command ...\n"); MessageInterface::ShowMessage("generatingString = %s", generatingString.c_str()); #endif // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ end debug ~~~~ /// @todo: Clean up this hack for the Minimize::InterpretAction method // Sample string: "Minimize myDC(Sat1.SMA = 21545.0, {Tolerance = 0.1});" /// @todo clean that up - because that's not even right ^^^^^ // Clean out any old data wrapperObjectNames.clear(); ClearWrappers(); StringArray chunks = InterpretPreface(); #ifdef DEBUG_MINIMIZE_PARSING MessageInterface::ShowMessage("Preface chunks as\n"); for (StringArray::iterator i = chunks.begin(); i != chunks.end(); ++i) MessageInterface::ShowMessage(" \"%s\"\n", i->c_str()); MessageInterface::ShowMessage("\n"); #endif // Find and set the solver object name // This is the only setting in Vary that is not in a wrapper StringArray currentChunks = parser.Decompose(chunks[1], "()", false); if (!GmatStringUtil::HasNoBrackets(currentChunks.at(0), false)) throw CommandException( "Solver name for Minimize command may not contain brackets, braces, or parentheses."); SetStringParameter(OPTIMIZER_NAME, currentChunks[0]); if (currentChunks.size() < 2) throw CommandException("Missing field or value for Minimize command."); // The remaining text in the instruction is the variable definition and // parameters, all contained in currentChunks[1]. Deal with those next. std::string cc = GmatStringUtil::Strip(currentChunks[1]); Integer ccEnd = cc.size() - 1; if ((cc.at(0) != '(') || (cc.at(ccEnd) != ')')) throw CommandException( "Missing parentheses, or unexpected characters found, around argument to Minimize command."); if (!GmatStringUtil::IsBracketBalanced(cc, "()")) throw CommandException("Parentheses unbalanced in Minimize command."); if ((cc.find('[') != cc.npos) || (cc.find(']') != cc.npos) || (cc.find('{') != cc.npos) || (cc.find('}') != cc.npos) ) throw CommandException("Minimize command may not contain brackets or braces."); std::string noSpaces = GmatStringUtil::RemoveAll(cc,' '); currentChunks = parser.Decompose(noSpaces, "()", true, true); #ifdef DEBUG_MINIMIZE_PARSING MessageInterface::ShowMessage( "Minimize: after Decompose, current chunks = \n"); for (Integer jj = 0; jj < (Integer) currentChunks.size(); jj++) MessageInterface::ShowMessage(" %s\n", currentChunks[jj].c_str()); #endif if (currentChunks.size() == 0) throw CommandException("The objective function name is missing in the " "Minimize command\n"); // First chunk is the objectiveName objectiveName = currentChunks[0]; #ifdef DEBUG_MINIMIZE_PARSE // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ debug ~~~~ MessageInterface::ShowMessage("Minimize::InterpretAction() exiting\n"); #endif // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ end debug ~~~~ interpreted = true; return true; }
//------------------------------------------------------------------------------ // void Create() //------------------------------------------------------------------------------ void TargetPanel::Create() { Integer bsize = 5; //------------------------------------------------------- // Solver ComboBox //------------------------------------------------------- wxStaticText *solverNameStaticText = new wxStaticText(this, ID_TEXT, wxT("Solver Name"), wxDefaultPosition, wxDefaultSize, 0); wxStaticText *solverModeStaticText = new wxStaticText(this, ID_TEXT, wxT("Solver Mode"), wxDefaultPosition, wxDefaultSize, 0); wxStaticText *exitModeStaticText = new wxStaticText(this, ID_TEXT, wxT("Exit Mode"), wxDefaultPosition, wxDefaultSize, 0); mSolverComboBox = theGuiManager->GetBoundarySolverComboBox(this, ID_COMBO, wxSize(180,-1)); StringArray options = theCommand->GetStringArrayParameter("SolveModeOptions"); wxArrayString theOptions; for (StringArray::iterator i = options.begin(); i != options.end(); ++i) theOptions.Add(i->c_str()); mSolverModeComboBox = new wxComboBox(this, ID_COMBO, wxT(""), wxDefaultPosition, wxSize(180,-1), theOptions, wxCB_READONLY); options = theCommand->GetStringArrayParameter("ExitModeOptions"); theOptions.Clear(); for (StringArray::iterator i = options.begin(); i != options.end(); ++i) theOptions.Add(i->c_str()); mExitModeComboBox = new wxComboBox(this, ID_COMBO, wxT(""), wxDefaultPosition, wxSize(180,-1), theOptions, wxCB_READONLY);; mApplyCorrectionsButton = new wxButton(this, ID_APPLYBUTTON, wxT("Apply Corrections")); wxFlexGridSizer *pageSizer = new wxFlexGridSizer(2); pageSizer->Add(solverNameStaticText, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mSolverComboBox, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(solverModeStaticText, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mSolverModeComboBox, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(exitModeStaticText, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mExitModeComboBox, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mApplyCorrectionsButton, 0, wxALIGN_CENTER|wxALL, bsize); theMiddleSizer->Add(pageSizer, 0, wxGROW, bsize); }
//------------------------------------------------------------------------------ bool BeginFiniteBurn::Initialize() { bool retval = GmatCommand::Initialize(); #ifdef DEBUG_BEGIN_MANEUVER MessageInterface::ShowMessage ("BeginFiniteBurn::Initialize() entered. burnName=%s\n", burnName.c_str()); #endif GmatBase *mapObj = NULL; if (retval) { // Look up the maneuver object if ((mapObj = FindObject(burnName)) == NULL) throw CommandException("Unknown finite burn \"" + burnName + "\"\n"); if (mapObj->IsOfType("FiniteBurn") == false) throw CommandException(burnName + " is not a FiniteBurn\n"); maneuver = (FiniteBurn*)mapObj; #ifdef DEBUG_BEGIN_MANEUVER MessageInterface::ShowMessage( "BeginFiniteBurn::Initialize() found %s with type %s\n", maneuver->GetName().c_str(), maneuver->GetTypeName().c_str()); #endif // find all of the spacecraft StringArray::iterator scName; Spacecraft *sc; sats.clear(); for (scName = satNames.begin(); scName != satNames.end(); ++scName) { if ((mapObj = FindObject(*scName)) == NULL) throw CommandException("Unknown SpaceObject \"" + (*scName) + "\""); if (mapObj->IsOfType(Gmat::SPACECRAFT) == false) throw CommandException((*scName) + " is not a Spacecraft"); sc = (Spacecraft*)mapObj; #ifdef DEBUG_BEGIN_MANEUVER MessageInterface::ShowMessage( "BeginFiniteBurn::Initialize() found %s with type %s\n", scName->c_str(), sc->GetTypeName().c_str()); #endif sats.push_back(sc); } // Delete old burnForce if (burnForce != NULL) { #ifdef DEBUG_MEMORY MemoryTracker::Instance()->Remove (burnForce, burnForce->GetName(), "BeginFiniteBurn::Initialize()", "deleting burn force"); #endif if (transientForces != NULL) { std::vector<PhysicalModel *>::iterator transient = find( transientForces->begin(), transientForces->end(), burnForce); if (transient != transientForces->end()) { #ifdef DEBUG_TRANSIENTFORCE_MANAGEMENT MessageInterface::ShowMessage("Removing burn force <%p> from " "the transient force list\n", burnForce); #endif transientForces->erase(transient); } } delete burnForce; burnForce = NULL; } // If all is okay, create the FiniteThrust object and configure it. std::string thrustName = burnName + "_FiniteThrust"; burnForce = new FiniteThrust(thrustName); #ifdef DEBUG_MEMORY MemoryTracker::Instance()->Add (burnForce, thrustName, "BeginFiniteBurn::Initialize()", "burnForce = new FiniteThrust()"); #endif burnForce->SetRefObject(maneuver, maneuver->GetType(), maneuver->GetName()); Gmat::ObjectType type = Gmat::SPACECRAFT; StringArray::iterator iter; // load up the spacecraft name list for (iter = satNames.begin(); iter != satNames.end(); ++iter) { #ifdef DEBUG_BEGIN_MANEUVER MessageInterface::ShowMessage( "BeginFiniteBurn::Initialize() setting %s on %s\n", iter->c_str(), thrustName.c_str()); #endif burnForce->SetRefObjectName(type, *iter); } } #ifdef DEBUG_BEGIN_MANEUVER MessageInterface::ShowMessage ("BeginFiniteBurn::Initialize() returning %d\n", isInitialized); #endif return isInitialized; }
//------------------------------------------------------------------------------ // void LoadData() //------------------------------------------------------------------------------ void CallFunctionPanel::LoadData() { #ifdef DEBUG_CALLFUNCTION_PANEL_LOAD MessageInterface::ShowMessage(wxT("CallFunctionPanel::LoadData() entered\n")); #endif // Set the pointer for the "Show Script" button mObject = theCommand; int id = theCommand->GetParameterID(wxT("FunctionName")); wxString functionName = theCommand->GetStringParameter(id); // If function name is not in the ComboBox list, add blank if (!theFunctionComboBox->SetStringSelection(functionName.c_str())) { theFunctionComboBox->Append(wxT("")); theFunctionComboBox->SetStringSelection(wxT("")); } #ifdef DEBUG_CALLFUNCTION_PANEL_LOAD MessageInterface::ShowMessage (wxT(" Function name is: <%s>\n"), functionName.c_str()); #endif // get input parameters StringArray inputList = theCommand->GetStringArrayParameter(wxT("AddInput")); mNumInput = inputList.size(); mInputWxStrings.Clear(); #ifdef DEBUG_CALLFUNCTION_PANEL_LOAD MessageInterface::ShowMessage (wxT(" Found %d input parameters:\n"), mNumInput); for (StringArray::iterator i = inputList.begin(); i != inputList.end(); ++i) MessageInterface::ShowMessage(wxT(" '%s'\n"), i->c_str()); #endif if (mNumInput > 0) { wxString *inputNames = new wxString[mNumInput]; GmatBase *param; wxString cellValue = wxT(""); wxString delimiter = wxT(", "); for (int i=0; i<mNumInput; i++) { inputNames[i] = inputList[i].c_str(); #ifdef DEBUG_CALLFUNCTION_PANEL_LOAD MessageInterface::ShowMessage(wxT(" Looking up ") + inputList[i] + wxT("\n")); #endif param = theGuiInterpreter->GetConfiguredObject(inputList[i]); if (i == mNumInput-1) delimiter = wxT(""); if (param != NULL) { cellValue = cellValue + param->GetName().c_str() + delimiter; mInputWxStrings.Add(param->GetName().c_str()); } } #ifdef __USE_GRID_FOR_INPUT_OUTPUT__ theInputGrid->SetCellValue(0, 0, cellValue); #else theInputTextCtrl->SetValue(cellValue); #endif delete [] inputNames; } // get output parameters StringArray outputList = theCommand->GetStringArrayParameter(wxT("AddOutput")); mNumOutput = outputList.size(); mOutputWxStrings.Clear(); #ifdef DEBUG_CALLFUNCTION_PANEL_LOAD MessageInterface::ShowMessage (wxT(" Found %d output parameters:\n"), mNumOutput); for (StringArray::iterator i = outputList.begin(); i != outputList.end(); ++i) MessageInterface::ShowMessage(wxT(" '%s'\n"), i->c_str()); #endif if (mNumOutput > 0) { wxString *outputNames = new wxString[mNumOutput]; GmatBase *param; wxString cellValue = wxT(""); wxString delimiter = wxT(", "); for (int i=0; i<mNumOutput; i++) { outputNames[i] = outputList[i].c_str(); #ifdef DEBUG_CALLFUNCTION_PANEL_LOAD MessageInterface::ShowMessage(wxT(" Looking up ") + outputList[i] + wxT("\n")); #endif param = theGuiInterpreter->GetConfiguredObject(outputList[i]); if (i == mNumOutput-1) delimiter = wxT(""); if (param != NULL) { cellValue = cellValue + param->GetName().c_str() + delimiter; mOutputWxStrings.Add(param->GetName().c_str()); } } #ifdef __USE_GRID_FOR_INPUT_OUTPUT__ theOutputGrid->SetCellValue(0, 0, cellValue); #else theOutputTextCtrl->SetValue(cellValue); #endif delete [] outputNames; } }
//------------------------------------------------------------------------------ // void Create() //------------------------------------------------------------------------------ void TargetPanel::Create() { Integer bsize = 5; //------------------------------------------------------- // Solver ComboBox //------------------------------------------------------- wxStaticText *solverNameStaticText = new wxStaticText(this, ID_TEXT, wxT("Solver Name"), wxDefaultPosition, wxDefaultSize, 0); wxStaticText *solverModeStaticText = new wxStaticText(this, ID_TEXT, wxT("Solver Mode"), wxDefaultPosition, wxDefaultSize, 0); wxStaticText *exitModeStaticText = new wxStaticText(this, ID_TEXT, wxT("Exit Mode"), wxDefaultPosition, wxDefaultSize, 0); mSolverComboBox = theGuiManager->GetBoundarySolverComboBox(this, ID_COMBO, wxSize(180,-1)); StringArray options = theCommand->GetStringArrayParameter("SolveModeOptions"); wxArrayString theOptions; for (StringArray::iterator i = options.begin(); i != options.end(); ++i) theOptions.Add(i->c_str()); mSolverModeComboBox = new wxComboBox(this, ID_COMBO, wxT(""), wxDefaultPosition, wxSize(180,-1), theOptions, wxCB_READONLY); options = theCommand->GetStringArrayParameter("ExitModeOptions"); theOptions.Clear(); for (StringArray::iterator i = options.begin(); i != options.end(); ++i) theOptions.Add(i->c_str()); mExitModeComboBox = new wxComboBox(this, ID_COMBO, wxT(""), wxDefaultPosition, wxSize(180,-1), theOptions, wxCB_READONLY);; //---------------------------------------------------------------------- // ShowProgressWindow flag //---------------------------------------------------------------------- mProgressWindowCheckBox = new wxCheckBox(this, ID_PROGRESS_CHECKBOX, gmatwxT(GUI_ACCEL_KEY"Show Progress Window"), wxDefaultPosition, wxDefaultSize); mProgressWindowCheckBox->SetToolTip(_T("Show Progress Window during targeting")); mApplyCorrectionsButton = new wxButton(this, ID_APPLYBUTTON, wxT("Apply Corrections")); wxFlexGridSizer *pageSizer = new wxFlexGridSizer(2); pageSizer->Add(solverNameStaticText, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mSolverComboBox, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(solverModeStaticText, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mSolverModeComboBox, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(exitModeStaticText, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(mExitModeComboBox, 0, wxALIGN_CENTER|wxALL, bsize); // pageSizer->Add(NULL, 0, wxALIGN_CENTER|wxALL, bsize); pageSizer->Add(20,20); pageSizer->Add(mProgressWindowCheckBox, 0, wxALIGN_LEFT|wxALL, bsize); pageSizer->Add(mApplyCorrectionsButton, 0, wxALIGN_CENTER|wxALL, bsize); theMiddleSizer->Add(pageSizer, 0, wxGROW, bsize); }
//------------------------------------------------------------------------------ bool NonlinearConstraint::InterpretAction() { bool tooMuch = false; // Clean out any old data wrapperObjectNames.clear(); ClearWrappers(); StringArray chunks = InterpretPreface(); #ifdef DEBUG_NLC_PARSING MessageInterface::ShowMessage(wxT("Preface chunks as\n")); for (StringArray::iterator i = chunks.begin(); i != chunks.end(); ++i) MessageInterface::ShowMessage(wxT(" \"%s\"\n"), i->c_str()); MessageInterface::ShowMessage(wxT("\n")); #endif // Find and set the solver object name // This is the only setting in Vary that is not in a wrapper StringArray currentChunks = parser.Decompose(chunks[1], wxT("()"), false); if (!GmatStringUtil::HasNoBrackets(currentChunks.at(0), false)) throw CommandException( wxT("Solver name for NonlinearConstraint command may not contain brackets, braces, or parentheses.")); SetStringParameter(OPTIMIZER_NAME, currentChunks[0]); if (currentChunks.size() < 2) throw CommandException(wxT("Missing field or value for NonlinearConstraint command.")); if (currentChunks.size() > 2) tooMuch = true; wxString cc = GmatStringUtil::Strip(currentChunks[1]); Integer ccEnd = cc.size() - 1; if ((tooMuch) || (cc.at(0) != wxT('(')) || (cc.at(ccEnd) != wxT(')'))) throw CommandException( wxT("Missing parentheses, or unexpected characters found, around logical expression argument to NonlinearConstraint command.")); if (!GmatStringUtil::IsBracketBalanced(cc, wxT("()"))) throw CommandException(wxT("Parentheses unbalanced in NonlinearConstraint command.")); // @todo - if tolerance allowed later, will need to not check for braces here ... if ((cc.find(wxT('[')) != cc.npos) || (cc.find(wxT(']')) != cc.npos) || (cc.find(wxT('{')) != cc.npos) || (cc.find(wxT('}')) != cc.npos) ) throw CommandException(wxT("NonlinearConstraint command may not contain brackets or braces.")); wxString noSpaces2 = GmatStringUtil::RemoveAll(cc,wxT(' ')); //wxString noSpaces2 = GmatStringUtil::RemoveAll(currentChunks[1],' '); currentChunks = parser.SeparateBrackets(noSpaces2, wxT("()"), wxT(","), false); #ifdef DEBUG_NLC_PARSING MessageInterface::ShowMessage( wxT("NLC: noSpaces2 = %s\n"), noSpaces2.c_str()); MessageInterface::ShowMessage( wxT("NLC: after SeparateBrackets, current chunks = \n")); for (Integer jj = 0; jj < (Integer) currentChunks.size(); jj++) MessageInterface::ShowMessage(wxT(" %s\n"), currentChunks[jj].c_str()); #endif bool testForMore = false; if ((Integer) currentChunks.size() > 1) testForMore = true; Integer end; wxString constraintStr = currentChunks[0]; Integer opSize = 1; if ((end = constraintStr.find(wxT(">="), 0)) != (Integer) constraintStr.npos) { op = GREATER_THAN_OR_EQUAL; isInequality = true; isIneqString = wxT("IneqConstraint"); opSize = 2; #ifdef DEBUG_NONLINEAR_CONSTRAINT_INIT MessageInterface::ShowMessage(wxT("NLC:InterpretAction: greater_than_or_equal\n")); #endif } else if ((end = constraintStr.find(wxT("<="), 0)) != (Integer) constraintStr.npos) { op = LESS_THAN_OR_EQUAL; isInequality = true; isIneqString = wxT("IneqConstraint"); opSize = 2; #ifdef DEBUG_NONLINEAR_CONSTRAINT_INIT MessageInterface::ShowMessage(wxT("NLC:InterpretAction: less_than_or_equal\n")); #endif } else if ((end = constraintStr.find(wxT("=>"), 0)) != (Integer) constraintStr.npos) { wxString errmsg = wxT("The string \"=>\" is an invalid conditonal operator"); errmsg += wxT(" in a NonlinearConstraint command.\n"); errmsg += wxT("The allowed values are [=, <=, >=]\n"); throw CommandException(errmsg); } else if ((end = constraintStr.find(wxT("=<"), 0)) != (Integer) constraintStr.npos) { wxString errmsg = wxT("The string \"=<\" is an invalid conditonal operator"); errmsg += wxT(" in a NonlinearConstraint command.\n"); errmsg += wxT("The allowed values are [=, <=, >=]\n"); throw CommandException(errmsg); } else if ((end = constraintStr.find(wxT("=="), 0)) != (Integer) constraintStr.npos) { wxString errmsg = wxT("The string \"==\" is an invalid conditonal operator"); errmsg += wxT(" in a NonlinearConstraint command.\n"); errmsg += wxT("The allowed values are [=, <=, >=]\n"); throw CommandException(errmsg); } else if ((end = constraintStr.find(wxT("="), 0)) != (Integer) constraintStr.npos) { //end = constraintStr.find("=", 0); op = EQUAL; isInequality = false; isIneqString = wxT("EqConstraint"); #ifdef DEBUG_NONLINEAR_CONSTRAINT_INIT MessageInterface::ShowMessage(wxT("NLC:InterpretAction: equal\n")); #endif } else { wxString errmsg = wxT("The conditional operator is missing or invalid "); errmsg += wxT(" in a NonlinearConstraint command.\n"); errmsg += wxT("The allowed values are [=, <=, >=]\n"); throw CommandException(errmsg); } arg1Name = constraintStr.substr(0,end); arg2Name = constraintStr.substr(end+opSize, (constraintStr.npos - end + opSize - 1)); #ifdef DEBUG_NLC_PARSING MessageInterface::ShowMessage(wxT("... arg1Name = %s\n"), arg1Name.c_str()); MessageInterface::ShowMessage(wxT("... operator = %s\n"), OP_STRINGS[(Integer)op].c_str()); MessageInterface::ShowMessage(wxT("... arg2Name = %s\n"), arg2Name.c_str()); #endif // Currently, this should not happen ..... if (testForMore) { wxString noSpaces = GmatStringUtil::RemoveAll(currentChunks[1],wxT(' ')); currentChunks = parser.SeparateBrackets(noSpaces, wxT("{}"), wxT(","), false); #ifdef DEBUG_NLC_PARSING MessageInterface::ShowMessage( wxT("NLC: After SeparateBrackets, current chunks = \n")); for (Integer jj = 0; jj < (Integer) currentChunks.size(); jj++) MessageInterface::ShowMessage(wxT(" %s\n"), currentChunks[jj].c_str()); #endif // currentChunks now holds all of the pieces - no need for more separation wxString lhs, rhs; for (StringArray::iterator i = currentChunks.begin(); i != currentChunks.end(); ++i) { SeparateEquals(*i, lhs, rhs); if (IsSettable(lhs)) SetStringParameter(GetParameterID(lhs), rhs); else { throw CommandException(wxT("The setting \"") + lhs + wxT("\" is not a valid setting for a ") + typeName + wxT(" command.\n")); } } } interpreted = true; return true; }
//------------------------------------------------------------------------------ bool Set::InterpretAction() { #ifdef DEBUG_PARSING MessageInterface::ShowMessage("%s::InterpretAction for \"%s\" entered, " "type = %s\n", typeName.c_str(), generatingString.c_str(), typeName.c_str()); #endif std::string mainString = generatingString; // Remove trailing semicolons // Note: Cannot use UnsignedInt here because return is really a size_t size_t loc = mainString.find_last_of(';'); while (loc != std::string::npos) { #ifdef DEBUG_PARSING MessageInterface::ShowMessage("Went from '%s' to ", mainString.c_str()); #endif mainString = mainString.substr(0, loc); #ifdef DEBUG_PARSING MessageInterface::ShowMessage("'%s'\n", mainString.c_str()); #endif loc = mainString.find_last_of(';'); } StringArray blocks = parser.DecomposeBlock(mainString); #ifdef DEBUG_PARSING MessageInterface::ShowMessage("Top level blocks from \"%s\":\n", generatingString.c_str()); for (StringArray::iterator i = blocks.begin(); i != blocks.end(); ++i) MessageInterface::ShowMessage(" \"%s\"\n", i->c_str()); #endif // Check for paren matching loc = blocks[0].find('('); if (loc != std::string::npos) { size_t loc2 = blocks[0].find('(', loc+1); if (loc2 != std::string::npos) { throw CommandException("Too many opening parens in the Set command"); } loc2 = blocks[0].find(')'); if (loc2 == std::string::npos) { throw CommandException("Missing closing parens in the Set command"); } if (loc > loc2) { throw CommandException("Closing paren found before opening paren in the Set command"); } size_t loc3 = blocks[0].find(')', loc2+1); if (loc3 != std::string::npos) { throw CommandException("Too many closing parens in the Set command"); } } StringArray chunks = parser.SeparateBy(blocks[0], "()"); #ifdef DEBUG_PARSING MessageInterface::ShowMessage("Chunks from block \"%s\":\n", blocks[0].c_str()); for (StringArray::iterator i = chunks.begin(); i != chunks.end(); ++i) MessageInterface::ShowMessage(" \"%s\"\n", i->c_str()); #endif StringArray subchunks = parser.SeparateBy(chunks[0], " "); if (subchunks.size() < 3) throw CommandException(typeName + "::InterpretAction() cannot identify " "either the target or the data source -- is one missing? -- in " "line\n" + generatingString); if (subchunks.size() > 3) throw CommandException(typeName + "::InterpretAction() has too many " "component strings in the line\n" + generatingString); // Parse the main part of the command if (subchunks[0] != typeName) throw CommandException(typeName + "::InterpretAction() does not identify " "the correct command type in line\n" + generatingString); targetName = subchunks[1]; interfaceName = subchunks[2]; #ifdef DEBUG_PARSING MessageInterface::ShowMessage("Identified the target \"%s\" and the " "data source \"%s\"\n", targetName.c_str(), interfaceName.c_str()); #endif if (chunks.size() > 2) throw CommandException(typeName + "::InterpretAction() found too many components to parse in the " "line\n" + generatingString); // Parse the command options if (chunks.size() == 2) CheckForOptions(chunks[1]); #ifdef DEBUG_PARSING MessageInterface::ShowMessage("%s::InterpretAction succeeded\n", typeName.c_str()); #endif return true; }