Ejemplo n.º 1
0
std::string SFManager::getContainingFunctionScope( Udm::Object object ) {

	while(  !Udm::IsDerivedFrom( object.type(), SFC::Program::meta )  ) {
		if (  Udm::IsDerivedFrom( object.type(), SFC::Function::meta )  ) {
			return SFC::Function::Cast( object ).scope();
		}

		object = object.GetParent();
	}

	return "";
}
Ejemplo n.º 2
0
Udm::Object SFUtils::getTopLevelInstance( Udm::Object object ) {
    if ( object == Udm::null ) return Udm::null;

    Udm::Object parent = object.GetParent();

    Udm::Object archetype = parent.archetype();
    while( archetype != Udm::null ) {
        if (  ( object = object.archetype() ) == Udm::null  ) return Udm::null;
        parent = archetype;
        archetype = parent.archetype();
    }
    return object;
}
Ejemplo n.º 3
0
bool SFUtils::isFromSameSignalFlowModel(Udm::Object obj)
{
	Udm::Object obj_parent = obj.GetParent();
	while(obj_parent.type()!=SLSF_ROOT::RootFolder::meta)
	{
		if(obj_parent.type()==SLSF_ROOT::SimulinkWrapper::meta)
		{
			SLSF_ROOT::SimulinkWrapper sfmodel = SLSF_ROOT::SimulinkWrapper::Cast(obj_parent);
			if(sfmodel==rootSFModel) 
				return true;
			else
				return false;
		}
		obj_parent = obj_parent.GetParent();
	}
	return false;
}
Ejemplo n.º 4
0
std::string UdmComparator::ObjectName::operator()( Udm::Object udmObject ) {

	static StringSet reportedClassNameSet;

	Uml::Class umlClass = udmObject.type();
	Uml::Attribute umlNameAttribute;

	UmlClassNameAttributeMap::iterator cnmItr = _umlClassNameAttributeMap.find( umlClass );
	if ( cnmItr != _umlClassNameAttributeMap.end() ) {

		umlNameAttribute = cnmItr->second;

	} else {

		NameUmlAttributeMap nameUmlAttributeMap = getNameUmlAttributeMap( umlClass );
			
		NameUmlAttributeMap::iterator numItr = nameUmlAttributeMap.find( "name" );
		if ( numItr != nameUmlAttributeMap.end() ) {

			umlNameAttribute = numItr->second;

		} else {

			numItr = nameUmlAttributeMap.find( "Name" );
			if ( numItr != nameUmlAttributeMap.end() ) {

				umlNameAttribute = numItr->second;

			} else if (  static_cast< std::string >( umlClass.stereotype() ) != "Connection"  ) {

				std::string className = umlClass.name();
				if ( reportedClassNameSet.find( className ) == reportedClassNameSet.end() ) {
					std::cerr << "WARNING: Class \"" << className << "\" has no \"[Nn]ame\" attribute." << std::endl << std::endl;
					reportedClassNameSet.insert( className );
				}
				return "";

			}

		}

		_umlClassNameAttributeMap.insert(  std::make_pair( umlClass, umlNameAttribute )  );

	}

	std::string udmObjectName = "";
	if ( umlNameAttribute != Udm::null ) {
		udmObjectName = udmObject.getStringAttr( umlNameAttribute );
		if (  umlClass.stereotype() == "Connection" && udmObjectName == static_cast< std::string >( umlClass.name() )  ) {
			udmObjectName = "";
		}
	}

	if ( udmObjectName == "" && umlClass.stereotype() == "Connection" ) {

		UmlAssociationRoleSet umlAssociationRoleSet = getAllUmlAssociationRoles( umlClass );

		for( UmlAssociationRoleSet::iterator arsItr = umlAssociationRoleSet.begin() ; arsItr != umlAssociationRoleSet.end() ; ++arsItr ) {
			
			UdmObjectSet udmObjectSet = udmObject.getAssociation( *arsItr, Udm::TARGETFROMCLASS );
			for( UdmObjectSet::iterator uosItr = udmObjectSet.begin() ; uosItr != udmObjectSet.end() ; ++uosItr ) {

				if ( !udmObjectName.empty() ) udmObjectName += ":";
				udmObjectName += (*this)(*uosItr);

			}

		}

		if ( umlNameAttribute != Udm::null ) {
			udmObject.setStringAttr( umlNameAttribute, udmObjectName );
		}

	}

	Udm::Object udmObjectParent = udmObject.GetParent();

	if ( udmObjectParent != Udm::null ) {
		const auto& it = ObjectNameCache.find(udmObjectParent);
		if (it != ObjectNameCache.end())
		{
			udmObjectName = it->second + "/" + udmObjectName;
		}
		else
		{
			udmObjectName = operator()( udmObjectParent ) + "/" + udmObjectName;
		}
	}

	return udmObjectName;
}
void copyDataflows( ESMoL::ModelsFolder inputModelsFolder, ESMoL::ModelsFolder outputModelsFolder ) {

	getPortList().clear();
	getPortMap().clear();

	DataflowVector dataflowVector = inputModelsFolder.Dataflow_kind_children();
	for( DataflowVector::iterator dfvItr = dataflowVector.begin() ; dfvItr != dataflowVector.end() ; ++dfvItr ) {
		ESMoL::Dataflow inputDataflow = *dfvItr;
		ESMoL::Dataflow outputDataflow = ESMoL::Dataflow::Create( outputModelsFolder );
		outputDataflow.name() = inputDataflow.name();
		copySubsystems_flatten( inputDataflow, outputDataflow );
	}

	for( PortList::iterator ptlItr = getPortList().begin() ; ptlItr != getPortList().end() ; ++ptlItr ) {

		ESMoL::Port inputDstPort = *ptlItr;

		LineSet lineSet = inputDstPort.srcLine();
		if ( lineSet.empty() ) continue;
		ESMoL::Line line = *lineSet.begin();
		ESMoL::Port inputSrcPort = line.srcLine_end();
		lineSet = inputSrcPort.srcLine();
		while( getPortMap().find( inputSrcPort ) == getPortMap().end() && !lineSet.empty() ) {
			line = *lineSet.begin();
			inputSrcPort = line.srcLine_end();
			lineSet = inputSrcPort.srcLine();
		}

		PortMap::iterator ptmItr = getPortMap().find( inputDstPort );
		if ( ptmItr == getPortMap().end() ) {
			std::cerr << "Warning: port not in PortMap" << std::endl;
			continue;
		}
		ESMoL::Port outputDstPort = ptmItr->second;

		ptmItr = getPortMap().find( inputSrcPort );
		if ( ptmItr == getPortMap().end() ) {
			std::cerr << "Warning: port not in PortMap" << std::endl;
			continue;
		}
		ESMoL::Port outputSrcPort = ptmItr->second;

		Udm::Object lineParent = outputSrcPort.GetParent();
		if (  Udm::IsDerivedFrom( outputSrcPort.type(), ESMoL::OutPort::meta )  ) lineParent = lineParent.GetParent();

		ESMoL::Line outputLine = ESMoL::Line::Create( lineParent );
		outputLine.srcLine_end() = outputSrcPort;
		outputLine.dstLine_end() = outputDstPort;
	}
}