void CustomModel::createModel(bool ignorePhysicsManager) { QString pathName = "/"; pathName = pathName.append(getName()); for(QListIterator<SimObject*> i(mSimObjects); i.hasNext();) { SimObject *object = i.next(); object->setName(object->getName().prepend("/")); if(!ignorePhysicsManager) { QList<Value*> parameters = object->getParameters(); for(QListIterator<Value*> j(parameters); j.hasNext();) { StringValue *stringValue = dynamic_cast<StringValue*>(j.next()); if(stringValue != 0) { if(stringValue->get().contains("$name$")) { QString replacedString = stringValue->get().replace("$name$", pathName); stringValue->set(replacedString); } } } } mAgent->addObject(object); } if(!ignorePhysicsManager) { Physics::getPhysicsManager()->addSimObjectGroup(mAgent); } else { delete mAgent; } }
const char *SimDataBlockEvent::getDebugName() { SimObject *obj = Sim::findObject(id); static char buffer[256]; dSprintf(buffer, sizeof(buffer), "%s [%s - %s]", getClassName(), obj ? obj->getName() : "", obj ? obj->getClassName() : "NONE"); return buffer; }
char* SimTreeView::handleItemNameChange( HTREEITEM hItem, char *name ) { lockManager(); SimObject *obj = getObject( hItem ); if ( !obj ) return NULL; obj->assignName( name ); unlockManager(); return ( (char*)avar("%4i,\"%s\", %s",obj->getId(),obj->getName(),obj->getClassName()) ); }
bool DropPointGroup::onDropPointQuery (DropPointQuery *query) { SimObject *obj = NULL; // See if we can find the one they want, check first in // our group, then the named group. if (query->dropPointName) { if ((obj = findObject(query->dropPointName)) == 0) { if (SimObject* op = findObject(NamedDropPoints)) if (SimGroup* gp = dynamic_cast<SimGroup*>(op)) obj = gp->findObject(query->dropPointName); } } // If we can't find the one they asked for, we'll pick one. if (!obj && size()) { // Build a list to simplify selection (have to skip // over the named group). SimObjectList list; list.reserve(size()); for (int i = 0; i < size(); i++) { obj = (*this)[i]; const char* name = obj->getName(); if (!name || strcmp(name,NamedDropPoints)) list.push_back(obj); } if (list.size()) { if (random) { // Random selection (more or less) int seed = (int)manager->getCurrentTime(); currentIndex = seed%(list.size()); } else { // Sequenced selection if (++currentIndex >= list.size()) currentIndex = 0; } obj = list[currentIndex]; } } // if (obj) { SimObjectTransformQuery transQ; if (obj->processQuery (&transQ)) { query->tmat = transQ.tmat; return true; } } return false; }
void CustomModel::addSimObjectPrefix(const QString &prefix) { QList<StringValue*> stringValues; QHash<QString, QString> nameLookup; for(QListIterator<SimObject*> i(mSimObjects); i.hasNext();) { SimObject *object = i.next(); QString name = object->getName(); object->setName(prefix + name); Core::log("Renaming: " + name + " with " + prefix + " to " + object->getName(), true); nameLookup.insert(name, object->getName()); QList<Value*> objectParameters = object->getParameters(); for(QListIterator<Value*> j(objectParameters); j.hasNext();) { StringValue *sv = dynamic_cast<StringValue*>(j.next()); if(sv != 0) { stringValues.append(sv); } } } //check if there are strings to change. for(QListIterator<StringValue*> i(stringValues); i.hasNext();) { StringValue *sv = i.next(); QString value = sv->get(); bool hasNameMacro = false; if(value.startsWith("$name$")) { hasNameMacro = true; value = value.mid(6); } if(nameLookup.contains(value)) { QString prefix = ""; if(hasNameMacro) { prefix = "$name$/"; } sv->set(prefix + nameLookup.value(value)); } } //TODO change variable names }
SimObject* TamlBinaryReader::parseElement( Stream& stream, const U32 versionId ) { // Debug Profiling. PROFILE_SCOPE(TamlBinaryReader_ParseElement); SimObject* pSimObject = NULL; #ifdef TORQUE_DEBUG // Format the type location. char typeLocationBuffer[64]; dSprintf( typeLocationBuffer, sizeof(typeLocationBuffer), "Taml [format='binary' offset=%u]", stream.getPosition() ); #endif // Fetch element name. StringTableEntry typeName = stream.readSTString(); // Fetch object name. StringTableEntry objectName = stream.readSTString(); // Read references. U32 tamlRefId; U32 tamlRefToId; stream.read( &tamlRefId ); stream.read( &tamlRefToId ); // Do we have a reference to Id? if ( tamlRefToId != 0 ) { // Yes, so fetch reference. typeObjectReferenceHash::Iterator referenceItr = mObjectReferenceMap.find( tamlRefToId ); // Did we find the reference? if ( referenceItr == mObjectReferenceMap.end() ) { // No, so warn. Con::warnf( "Taml: Could not find a reference Id of '%d'", tamlRefToId ); return NULL; } // Return object. return referenceItr->value; } #ifdef TORQUE_DEBUG // Create type. pSimObject = Taml::createType( typeName, mpTaml, typeLocationBuffer ); #else // Create type. pSimObject = Taml::createType( typeName, mpTaml ); #endif // Finish if we couldn't create the type. if ( pSimObject == NULL ) return NULL; // Find Taml callbacks. TamlCallbacks* pCallbacks = dynamic_cast<TamlCallbacks*>( pSimObject ); // Are there any Taml callbacks? if ( pCallbacks != NULL ) { // Yes, so call it. mpTaml->tamlPreRead( pCallbacks ); } // Parse attributes. parseAttributes( stream, pSimObject, versionId ); // Does the object require a name? if ( objectName == StringTable->EmptyString() ) { // No, so just register anonymously. pSimObject->registerObject(); } else { // Yes, so register a named object. pSimObject->registerObject( objectName ); // Was the name assigned? if ( pSimObject->getName() != objectName ) { // No, so warn that the name was rejected. #ifdef TORQUE_DEBUG Con::warnf( "Taml::parseElement() - Registered an instance of type '%s' but a request to name it '%s' was rejected. This is typically because an object of that name already exists. '%s'", typeName, objectName, typeLocationBuffer ); #else Con::warnf( "Taml::parseElement() - Registered an instance of type '%s' but a request to name it '%s' was rejected. This is typically because an object of that name already exists.", typeName, objectName ); #endif } } // Do we have a reference Id? if ( tamlRefId != 0 ) { // Yes, so insert reference. mObjectReferenceMap.insertUnique( tamlRefId, pSimObject ); } // Parse custom elements. TamlCustomNodes customProperties; // Parse children. parseChildren( stream, pCallbacks, pSimObject, versionId ); // Parse custom elements. parseCustomElements( stream, pCallbacks, customProperties, versionId ); // Are there any Taml callbacks? if ( pCallbacks != NULL ) { // Yes, so call it. mpTaml->tamlPostRead( pCallbacks, customProperties ); } // Return object. return pSimObject; }
// ----------------------------------------------------------------------------- // Set attribute of top stack element to given value. // ----------------------------------------------------------------------------- void SimXMLDocument::setObjectAttributes(const char* objectID) { if( !objectID || !objectID[0] ) return; if(m_paNode.empty()) return; SimObject *pObject = Sim::findObject( objectID ); if( pObject == NULL ) return; const int iLastElement = m_paNode.size() - 1; TiXmlElement* pElement = m_paNode[iLastElement]; if(!pElement) return; char textbuf[1024]; TiXmlElement field( "Field" ); TiXmlElement group( "FieldGroup" ); pElement->SetAttribute( "Name", pObject->getName() ); // Iterate over our filed list and add them to the XML document... AbstractClassRep::FieldList fieldList = pObject->getFieldList(); AbstractClassRep::FieldList::iterator itr; for(itr = fieldList.begin(); itr != fieldList.end(); itr++) { if( itr->type == AbstractClassRep::DepricatedFieldType || itr->type == AbstractClassRep::StartGroupFieldType || itr->type == AbstractClassRep::EndGroupFieldType) continue; // Not an Array if(itr->elementCount == 1) { // get the value of the field as a string. ConsoleBaseType *cbt = ConsoleBaseType::getType(itr->type); const char *val = Con::getData(itr->type, (void *) (((const char *)pObject) + itr->offset), 0, itr->table, itr->flag); // Make a copy for the field check. if (!val) continue; FrameTemp<char> valCopy( dStrlen( val ) + 1 ); dStrcpy( (char *)valCopy, val ); if (!pObject->writeField(itr->pFieldname, valCopy)) continue; val = valCopy; expandEscape(textbuf, val); if( !pObject->writeField( itr->pFieldname, textbuf ) ) continue; field.SetValue( "Property" ); field.SetAttribute( "name", itr->pFieldname ); if( cbt != NULL ) field.SetAttribute( "type", cbt->getTypeName() ); else field.SetAttribute( "type", "TypeString" ); field.SetAttribute( "data", textbuf ); pElement->InsertEndChild( field ); continue; } } //// IS An Array //for(U32 j = 0; S32(j) < f->elementCount; j++) //{ // // If the start of a group create an element for the group and // // the our chache to it // const char *val = Con::getData(itr->type, (void *) (((const char *)pObject) + itr->offset), j, itr->table, itr->flag); // // Make a copy for the field check. // if (!val) // continue; // FrameTemp<char> valCopy( dStrlen( val ) + 1 ); // dStrcpy( (char *)valCopy, val ); // if (!pObject->writeField(itr->pFieldname, valCopy)) // continue; // val = valCopy; // // get the value of the field as a string. // ConsoleBaseType *cbt = ConsoleBaseType::getType(itr->type); // const char * dstr = Con::getData(itr->type, (void *)(((const char *)pObject) + itr->offset), 0, itr->table, itr->flag); // if(!dstr) // dstr = ""; // expandEscape(textbuf, dstr); // if( !pObject->writeField( itr->pFieldname, dstr ) ) // continue; // field.SetValue( "Property" ); // field.SetAttribute( "name", itr->pFieldname ); // if( cbt != NULL ) // field.SetAttribute( "type", cbt->getTypeName() ); // else // field.SetAttribute( "type", "TypeString" ); // field.SetAttribute( "data", textbuf ); // pElement->InsertEndChild( field ); //} }
void GuiInspectorDynamicField::renameField( const char* newFieldName ) { newFieldName = StringTable->insert( newFieldName ); if ( mDynField == NULL || mParent == NULL || mEdit == NULL ) { Con::warnf("GuiInspectorDynamicField::renameField - No target object or dynamic field data found!" ); return; } if ( !newFieldName ) { Con::warnf("GuiInspectorDynamicField::renameField - Invalid field name specified!" ); return; } // Only proceed if the name has changed if ( dStricmp( newFieldName, getFieldName() ) == 0 ) return; // Grab a pointer to our parent and cast it to GuiInspectorDynamicGroup GuiInspectorDynamicGroup *group = dynamic_cast<GuiInspectorDynamicGroup*>(mParent); if ( group == NULL ) { Con::warnf("GuiInspectorDynamicField::renameField - Unable to locate GuiInspectorDynamicGroup parent!" ); return; } const U32 numTargets = mInspector->getNumInspectObjects(); if( numTargets > 1 ) { mInspector->onBeginCompoundEdit_callback(); } const char* oldFieldName = getFieldName(); SimFieldDictionary::Entry* newEntry = NULL; for( U32 i = 0; i < numTargets; ++ i ) { SimObject* target = mInspector->getInspectObject( i ); // Make sure the new field is not already defined as a static field // on the object. if( target->isField( newFieldName ) ) { // New field is already defined. If we can, let the scripts handle // the error. Otherwise, just emit an error on the console and proceed. if( numTargets == 1 ) { mInspector->onFieldRenameAlreadyDefined_callback( target->getIdString(), oldFieldName, newFieldName ); } else { Con::errorf( "GuiInspectorDynamicField::renameField - field '%s' is already defined on %i:%s (%s)", newFieldName, target->getId(), target->getClassName(), target->getName() ); } // Reset the text entry. if( mRenameCtrl ) mRenameCtrl->setText( oldFieldName ); continue; } char currentValue[1024] = {0}; // Grab our current dynamic field value (we use a temporary buffer as this gets corrupted upon Con::eval) dSprintf( currentValue, sizeof( currentValue ), "%s", target->getDataField( oldFieldName, NULL ) ); // Unset the old field and set the new field. target->setDataField( oldFieldName, NULL, "" ); target->setDataField( newFieldName, NULL, currentValue ); // Notify script. mInspector->onFieldRenamed_callback( target->getIdString(), oldFieldName, newFieldName ); // Look up the new SimFieldDictionary entry. if( !newEntry ) { newEntry = target->getFieldDictionary()->findDynamicField( newFieldName ); if( !newEntry ) { Con::warnf( "GuiInspectorDynamicField::renameField - could not find new field '%s' on object %i:%s (%s)", newFieldName, target->getId(), target->getClassName(), target->getName() ); } mDynField = newEntry; } } if( numTargets > 1 ) { mInspector->onEndCompoundEdit_callback(); } // Lastly we need to reassign our validate field for our value edit control char szBuffer[1024]; dSprintf( szBuffer, sizeof( szBuffer ), "%d.apply(%d.getText());", getId(), mEdit->getId() ); mEdit->setField("validate", szBuffer ); if( mDeleteButton ) { dSprintf(szBuffer, sizeof( szBuffer ), "%d.apply("");%d.inspectGroup();", getId(), newFieldName, group->getId()); mDeleteButton->setField("Command", szBuffer); } }