Example #1
0
void MindMap::createFromXml( Xml xml )
{
	// child elements are MindAreaInfo
	for( Xml xmlChild = xml.getFirstChild( "MindArea" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "MindArea" ) ) {
		// construct MindArea from attributes
		MindAreaInfo *info = new MindAreaInfo;
		mindAreas.add( info );

		info -> createFromXml( xmlChild );

		// get areaId
		String id = info -> getAreaId();
		ASSERTMSG( !id.isEmpty() , "area is not defined: " + xmlChild.serialize() );
		ASSERTMSG( mindAreaMap.get( id ) == NULL , id + ": area duplicate found for id=" + id );

		// add
		mindAreaMap.add( id , info );
	}

	// child elements are MindAreaInfo
	Xml xmlLinks = xml.getFirstChild( "MindLinks" );

	Xml xmlChild;
	if( xmlLinks.exists() )
		xmlChild = xmlLinks.getFirstChild( "MindLink" );
	for( ; xmlChild.exists(); xmlChild = xmlChild.getNextChild( "MindLink" ) ) {
		// construct MindArea from attributes
		MindLinkInfo *info = new MindLinkInfo;
		info -> createFromXml( xmlChild );
		mindLinks.add( info );
	}
}
Example #2
0
void MindAreaInfo::createFromXml( Xml xml )
{
	// attributes are properties
	areaId = xml.getAttribute( "id" );

	int x , y , z;
	x = xml.getIntProperty( "posX" );
	y = xml.getIntProperty( "posY" );
	z = xml.getIntProperty( "posZ" );
	location.setPosition( x , y , z );

	int dx , dy , dz;
	dx = xml.getIntProperty( "sizeX" );
	dy = xml.getIntProperty( "sizeY" );
	dz = xml.getIntProperty( "sizeZ" );
	location.setDimensions( dx , dy , dz );

	size = location.getSize();

	// child elements are MindLink
	for( Xml xmlChild = xml.getFirstChild( "MindLink" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "MindLink" ) ) {
		// construct MindArea from attributes
		MindLinkInfo *info = new MindLinkInfo;
		info -> createFromXml( xmlChild );

		// add
		links.add( info );
	}
}
void XmlBrainTractPath::load( Xml xml ) {
	id = xml.getAttribute( "id" );
	type = xml.getAttribute( "type" );
	function = xml.getAttribute( "function" );
	pathway = xml.getAttribute( "pathway" );

	String src = xml.getAttribute( "src" );
	String dst = xml.getAttribute( "dst" );
	String mids = xml.getAttribute( "mids" , "" );

	items.add( src );
	StringList midlist;
	mids.split( midlist , "," );
	items.add( &midlist );
	items.add( dst );

	tract.addPath( this );

	String fibersvalue = xml.getAttribute( "fibers" );
	fibersvalue.split( fibers , "," );
	String value = xml.getAttribute( "endings" );
	value.split( endings , "," );

	for( Xml xmlChild = xml.getFirstChild( "path" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "path" ) ) {
		XmlBrainTractPath *path = new XmlBrainTractPath( tract , this );
		path -> load( xmlChild );
		childs.add( path -> id , path );
	}
}
void XmlSpinalCordLayout::load( Xml xmlDiv ) {
	Xml layout = xmlDiv.getFirstChild( "layout" );
	ASSERTMSG( layout.exists() , "layout is not found" );

	imgSrc = layout.getAttribute( "imgsrc" , "" );

	for( Xml xmlChild = layout.getFirstChild( "level" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "level" ) ) {
		String id = xmlChild.getAttribute( "id" );
		MapStringToClass<StringList>& levelData = data.getRef( id );

		loadLevel( xmlChild , levelData );
	}
}
void MindConnectionTypeDef::createFromXml( Xml xml ) {
	// attributes
	name = xml.getAttribute( "name" );
	Object::setInstance( name );

	srcRegionType = xml.getAttribute( "regionsrc" );
	dstRegionType = xml.getAttribute( "regiondst" );

	// links
	for( Xml xmlChild = xml.getFirstChild( "link-type" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "link-type" ) ) {
		// construct MindArea from attributes
		MindConnectionLinkTypeDef *link = new MindConnectionLinkTypeDef( this );
		link -> createFromXml( xmlChild );
		links.add( link );
		linkMap.add( link -> getName() , link );
	}
}
void MindRegionTypeDef::createConnectorSetFromXml( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "connector" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "connector" ) ) {
		// construct MindArea from attributes
		MindRegionConnectorDef *connector = new MindRegionConnectorDef;
		connector -> createFromXml( xmlChild );

		String id = connector -> getId();
		ASSERTMSG( !id.isEmpty() , "region type connector is not well-defined: " + xmlChild.serialize() );

		// add to set and map
		connectorSet.add( connector );
		connectorMap.add( id , connector );
	}
}
void MindMap::createCircuitDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	// check using another file
	EnvService *es = EnvService::getService();
	String xmlFile = xml.getAttribute( "xmlfile" , "" );
	if( !xmlFile.isEmpty() )
		xml = es -> loadXml( xmlFile );

	for( Xml xmlChild = xml.getFirstChild( "circuit" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "circuit" ) ) {
		// construct MindArea from attributes
		MindCircuitDef *circuit = new MindCircuitDef;
		circuit -> createFromXml( xmlChild );
		mindCircuitSet.add( circuit );
		mindCircuitMap.add( circuit -> getName() , circuit );
	}
}
Example #8
0
Xml Xml::findChildByPathAttr( String path , String attr , String value ) {
	Xml xml = findChildByPath( path );
	if( !xml.exists() )
		return( xml );

	String key;
	int index = path.findLast( '/' );
	if( index < 0 )
		key = path;
	else
		key = path.getMid( index + 1 );

	while( xml.exists() ) {
		if( xml.getAttribute( attr , "" ).equals( value ) )
			return( xml );

		xml = xml.getNextChild( key );
	}
	return( xml );
}
void MindAreaDef::createFromXml( Xml xml ) {
	// attributes are properties
	areaId = xml.getAttribute( "id" );
	areaType = xml.getAttribute( "type" );
	areaName = xml.getAttribute( "name" );
	areaFunction = xml.getAttribute( "function" );
	Object::setInstance( areaId );

	enabled = xml.getBooleanAttribute( "enabled" , true );
	if( !enabled )
		return;

	// read regions
	for( Xml xmlChild = xml.getFirstChild( "region" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "region" ) ) {
		// construct MindArea from attributes
		MindRegionDef *region = new MindRegionDef( this );
		region -> createFromXml( xmlChild );
		regions.add( region );
		regionMap.add( region -> getId() , region );
	}
}
void MindMap::createAreaDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "area" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "area" ) ) {
		// construct MindArea from attributes
		MindAreaDef *info = new MindAreaDef;
		mindAreaSet.add( info );

		info -> createFromXml( xmlChild );

		// get areaId
		String id = info -> getAreaId();
		ASSERTMSG( !id.isEmpty() , "area is not defined: " + xmlChild.serialize() );
		ASSERTMSG( mindAreaMap.get( id ) == NULL , id + ": area duplicate found for id=" + id );

		// add
		mindAreaMap.add( id , info );

		// add regions to map
		createRegionMap( info );
	}
}
void XmlSpinalCordLayout::loadLevel( Xml xmlLevel , MapStringToClass<StringList>& levelData ) {
	for( Xml xmlChild = xmlLevel.getFirstChild( "lamina" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "lamina" ) ) {
		String id = xmlChild.getAttribute( "id" );
		String elements = xmlChild.getAttribute( "elements" );

		StringList& items = levelData.getRef( id );
		StringList parts;
		elements.split( parts , "," );
		for( int k = 0; k < parts.count(); k++ ) {
			String element = parts.get( k );
			ASSERTMSG( hmind -> getIndexedElement( element ) != NULL , "unknown element index=" + element );

			if( items.find( element ) < 0 )
				items.add( element );
		}
	}
}
void MindCircuitDef::createFromXml( Xml xml ) {
	// attributes are properties
	id = xml.getAttribute( "id" );
	name = xml.getAttribute( "name" );
	Object::setInstance( name );

	enabled = xml.getBooleanAttribute( "enabled" , true );
	if( !enabled )
		return;

	// read connections
	for( Xml xmlChild = xml.getFirstChild( "connection" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "connection" ) ) {
		// construct MindArea from attributes
		MindCircuitConnectionDef *connection = new MindCircuitConnectionDef( this );
		connection -> createFromXml( xmlChild );
		connections.add( connection );
	}
}
void MindMap::createConnectionTypeDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "connection-type" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "connection-type" ) ) {
		// construct MindArea from attributes
		MindConnectionTypeDef *linkType = new MindConnectionTypeDef;
		linkType -> createFromXml( xmlChild );
		connectionTypeSet.add( linkType );
		connectionTypeMap.add( linkType -> getName() , linkType );
	}
}
void MindMap::createRegionTypeDefSet( Xml xml ) {
	if( !xml.exists() )
		return;

	for( Xml xmlChild = xml.getFirstChild( "region-type" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "region-type" ) ) {
		// construct MindRegionType from attributes
		MindRegionTypeDef *info = new MindRegionTypeDef;
		regionTypeSet.add( info );

		info -> createFromXml( xmlChild );

		// get region type name
		String name = info -> getName();
		ASSERTMSG( !name.isEmpty() , "region type is not defined: " + xmlChild.serialize() );
		ASSERTMSG( regionTypeMap.get( name ) == NULL , name + ": region type duplicate found for name=" + name );

		// add
		regionTypeMap.add( name , info );
	}
}
void MindMap::createTargetMeta_defineCircuit( Xml xml , TargetAreaDef *areaDef , bool sensors ) {
	if( sensors )
		areaDef -> defineSensorArea();
	else
		areaDef -> defineEffectorArea();

	mindAreaMap.add( areaDef -> getAreaId() , areaDef );

	// create sensor meta
	String itemsElement = ( sensors )? "sensors" :  "effectors";
	String itemElement = ( sensors )? "sensor" :  "effector";

	Xml config = xml.getChildNode( itemsElement );
	for( Xml xmlChild = config.getFirstChild( itemElement ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( itemElement ) ) {
		TargetRegionDef *regionInfo = new TargetRegionDef( areaDef );

		if( sensors )
			regionInfo -> defineSensorRegion( xmlChild );
		else
			regionInfo -> defineEffectorRegion( xmlChild );

		// add to maps
		areaDef -> addRegion( regionInfo );
		mindRegionMap.add( regionInfo -> getId() , regionInfo );
		TargetRegionTypeDef *regionTypeInfo = ( TargetRegionTypeDef * )regionInfo -> getType();
		regionTypeMap.add( regionTypeInfo -> getName() , regionTypeInfo );

		TargetCircuitDef *circuitInfo = regionTypeInfo -> getCircuitInfo();
		mindCircuitMap.add( circuitInfo -> getName() , circuitInfo );

		regionInfo -> setCircuitDef( circuitInfo );
	}
}
Example #16
0
void ScenarioPlayer::play( Xml scenario ) {
    logger.logInfo( "process scenario ..." );
    for( Xml xmlChild = scenario.getFirstChild( "xmlsignal" ); xmlChild.exists(); xmlChild = xmlChild.getNextChild( "xmlsignal" ) )
        playSignal( xmlChild );
}