Пример #1
0
bool __stdcall elaborate(IUnknown* currentObj)
{
	try {
		CComPtr<IMgaFCO> fcoCurrentObj;
		currentObj->QueryInterface(&fcoCurrentObj);
		if (fcoCurrentObj)
		{
			CComPtr<IMgaProject> project;
			if (SUCCEEDED(fcoCurrentObj->get_Project(&project)))
			{
				UdmGme::GmeDataNetwork dn(CyPhyML::diagram);
				dn.OpenExisting(project, Udm::CHANGES_LOST_DEFAULT, true);
				Udm::Object current = dn.Gme2Udm(fcoCurrentObj);

				CyPhyElaborate cpe;
				if (current.type() == ComponentAssembly::meta) {
					cpe.elaborate( CyPhyML::ComponentAssembly::Cast(current) );
					return true;
				} else if (current.type() == TestBench::meta) {
					cpe.elaborate( CyPhyML::TestBench::Cast(current) );
					return true;
				}
			}
		}
	} catch (udm_exception& e) {
		return false;
	}
	return false;
}
void CyPhyElaborate::SwitchReference(CyPhyML::TestBenchType tb)
{
	set<Udm::Object> bTargets = tb.GetChildObjects(CHILD_CLASS::meta);
	for (auto bTargetIt = bTargets.begin(); bTargetIt != bTargets.end(); bTargetIt++)
	{
		CHILD_CLASS bTarget = CHILD_CLASS::Cast(*bTargetIt);
		//Udm::Object bTargetCopy = btb.__impl()->createChild(Udm::NULLCHILDROLE, *referenceMeta);
		CHILD_CLASS bTargetCopy = CHILD_CLASS::Create(tb);

		TIPRefBase base;
		auto copyIt = originalObjectToCopies.find(bTarget.ref());
		if (copyIt == originalObjectToCopies.end())
		{
			throw udm_exception("Bug: could not find BallisticTarget copy");
		}
		while (copyIt != originalObjectToCopies.end())
		{
			base = TIPRefBase::Cast(copyIt->second);
			copyIt = originalObjectToCopies.find(base);
		}
		bTargetCopy.ref() = TIPRefBase::Cast(base);
		bTargetCopy.__impl()->CopyAttributesFrom(bTarget.__impl());

		// Debugging
		// std::string d1 = bTarget.getPath("/");
		// std::string d2 = bTargetCopy.getPath("/");
		//std::string d3 = TIPRefBase::Cast(base).getPath("/");
		// std::string target_type = static_cast<Udm::Object>(bTarget.ref()).type().name();
		// OutputDebugStringA("\n\n");
		// for (auto it = originalObjectToCopies.begin(); it != originalObjectToCopies.end(); ++it)
		// {
		// 	OutputDebugStringA((UdmUtil::ExtractName(it->first) + "\t" + UdmGme::UdmId2GmeId(it->first) + "\t" + UdmUtil::ExtractName(it->second) + "\n").c_str());
		// }

		SwitchConnections(bTarget, bTargetCopy, Udm::null, bTarget.GetParent());
		Udm::Object eventualTarget = bTarget;
		while (!!getReferredOrNull(eventualTarget))
		{
			eventualTarget = getReferredOrNull(eventualTarget);
		}
		// std::string d4 = eventualTarget.getPath("/");
		// std::string d5 = eventualTarget.type().name();
		// std::string d6 = getReferredOrNull(bTargetCopy).getPath("/");
		// std::string d22 = UdmGme::UdmId2GmeId(bTargetCopy.uniqueId());
		// std::string d22ref = UdmGme::UdmId2GmeId(Udm::Object(bTargetCopy.ref()).uniqueId());
		
		if (!!eventualTarget && Uml::IsDerivedFrom(eventualTarget.type(), CyPhyML::Component::meta))
			// Components are created as instances, so the RelIDs are the same
			SwitchRefportConnections(bTarget, bTargetCopy, map<Udm::Object, Udm::Object>(), *dynamic_cast<UdmGme::GmeDataNetwork*>(bTarget.__impl()->__getdn()));
		else
			// ComponentAssemblys are created with CopyObjectHierarchy, so the originalObjectToCopies map is correct
			SwitchRefportConnections(bTarget, bTargetCopy, originalObjectToCopies, *dynamic_cast<UdmGme::GmeDataNetwork*>(bTarget.__impl()->__getdn()));
		bTarget.DeleteObject();
		//bTarget.name() = std::string(bTarget.name()) + "tobedeleted";
		//std::string d7 = getReferredOrNull(bTargetCopy).getPath("/");
		//std::string d6_2 = getReferredOrNull(bTargetCopy).getPath("/");
		//std::string d22_2 = UdmGme::UdmId2GmeId(bTargetCopy.uniqueId());
		//std::string d22ref_2 = UdmGme::UdmId2GmeId(Udm::Object(bTargetCopy.ref()).uniqueId());
	}
}
Пример #3
0
Udm::Object SFUtils::getTopArchetype( Udm::Object object ) {
    if ( object == Udm::null ) return object;

    Udm::Object archetype = object.archetype();
    while( archetype != Udm::null ) {
        object = archetype;
        archetype = object.archetype();
    }
    return object;
}
Пример #4
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 "";
}
Пример #5
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;
}
Пример #6
0
	static StateVector getStateAncestors( SLSF::State state ) {
		StateVector stateVector;
		stateVector.push_back( state );

		Udm::Object object = state.GetParent();
		while( object.type() == SLSF::State::meta ) {
			state = SLSF::State::Cast( object );
			stateVector.push_back( state );
			object = state.GetParent();
		}

		return stateVector;
	}
Пример #7
0
void SFManager::initVar( SFC::CompoundStatement compoundStatement, SFC::Var var ) {
	Udm::Object object = Udm::Object::Cast( var );
	if ( object.type() != SFC::LocalVar::meta ) return;
	SFC::LocalVar localVar = SFC::LocalVar::Cast( var );

	SFC::DT dt = localVar.dt();
	std::string name = localVar.name();
	if ( dt.type() == SFC::Struct::meta ) {
		initVarAux( compoundStatement, localVar, name );
		return;
	}

	std::string initial = localVar.initial();
	if ( initial.empty() ) initial = "0";
	::mstat2SFC( compoundStatement, name + " = " + initial, true, true );
}
CComPtr<IMgaFCO> Udm2MgaFCO(Udm::Object& o)
{
	o.isLibObject(); // will throw if o is Udm::null
	CComPtr<IUnknown> pUnk;
	pUnk.Attach(UdmGme::Udm2Gme(o));
	CComQIPtr<IMgaFCO> pFCO = pUnk;
	return pFCO.p;
}
void ElementVisitor::Visit_OS( const ESMoL::OS & os ) {

	// STRONG ASSUMPTION -- we have already visited the parent and created a semantics entry for it.
	Udm::Object obj = os.parent();
	Semantics::Node sNode = IndexKeeper::Inst()->Lookup< Semantics::Node >( obj.uniqueId() );
	//get os specific values
	std::string str;		
	try {
		str = os.TickResolution();
		sNode.tickresolutionsecs() = TimeStr2secs( str );
	}
	catch ( ConversionErr &err ) {
		std::cout << _contextTracker.GetContext() << " Node resolution :" << err._what << std::endl;
	}
	try {
		str = os.ContextSwitchTime();
		sNode.ctxtswitchsecs() = TimeStr2secs(str);
	}
	catch ( ConversionErr &err ) {
		std::cout << _contextTracker.GetContext() << " Node context switch time :" << err._what << std::endl;
	}
	try {
		str = os.ISROverheadTime();
		sNode.isrohdsecs() = TimeStr2secs(str);
	}
	catch ( ConversionErr &err ) {
		std::cout << _contextTracker.GetContext() << " ISR overhead time :" << err._what << std::endl;
	}
	try {
		str = os.SendOverheadTime();
		sNode.sndohdsecs() = TimeStr2secs(str);
	}
	catch ( ConversionErr &err ) {
		std::cout << _contextTracker.GetContext() << " Node send overhead :" << err._what << std::endl;
	}
	try {
		str = os.RecvOverheadTime();
		sNode.rcvohdsecs() = TimeStr2secs(str);
	}
	catch ( ConversionErr &err ) {
		std::cout << _contextTracker.GetContext() << " Node receive overhead :" << err._what << std::endl;
	}

	sNode.maxtasknum() = os.MaxTaskNumber();
	sNode.schedalgorithm() = os.SchedulingAlgorithm();
}
Пример #10
0
SFUtils::ObjectSet SFUtils::getAllInstanceEquivalent( Udm::Object object ) {

	Udm::Object archetype = getTopArchetype( object );
	if ( archetype == Udm::null ) return ObjectSet();

	ObjectList objectList;
	/*objectList.push_back( archetype );
	for( ObjectList::iterator oblItr = objectList.begin() ; oblItr != objectList.end() ; (void)++oblItr ) {*/
		ObjectSet objectSet =archetype.instances();
		for(ObjectSet::iterator obj_it=objectSet.begin();obj_it!=objectSet.end();++obj_it)
		{
			if(isFromSameSignalFlowModel(*obj_it))
				objectList.push_back(*obj_it);
		}
//		objectList.insert( objectList.end(), objectSet.begin(), objectSet.end() );
	//}
	return ObjectSet( objectList.begin(), objectList.end() );
}
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;
	}
}
Пример #12
0
//
// Visit_PackageFile_i
//
void Stub_Generator::
Visit_PackageFile_i  (const Udm::Object & obj)
{
  // Gather all the necessary elements.
  std::set <CHAOS::Event> events = Udm::ChildrenAttr <CHAOS::Event> (obj.__impl (), Udm::NULLCHILDROLE);
  for (auto event : events)
    event.Accept (*this);

  // Write the output stream generators.
  std::set <CHAOS::Aggregate> aggrs = Udm::ChildrenAttr <CHAOS::Aggregate> (obj.__impl (), Udm::NULLCHILDROLE);
  for (auto aggr : aggrs)
    aggr.Accept (*this);

  std::set <CHAOS::Collection> colls = Udm::ChildrenAttr <CHAOS::Collection> (obj.__impl (), Udm::NULLCHILDROLE);
  for (auto coll : colls)
    coll.Accept (*this);

  std::set <CHAOS::Package> packages =
    Udm::ChildrenAttr <CHAOS::Package> (obj.__impl (), Udm::NULLCHILDROLE);

  for (auto package : packages)
    package.Accept (*this);
}
Пример #13
0
  void Visit_PackageFile_i (const Udm::Object & obj)
  {
    // Visit all the packages.
    std::vector <CHAOS::Package> packages =
      Udm::ChildrenAttr <CHAOS::Package> (obj.__impl (), Udm::NULLCHILDROLE);

    for (auto package : packages)
      package.Accept (*this);

    // Does this level contain any events.
    std::vector <CHAOS::Event> events =
      Udm::ChildrenAttr <CHAOS::Event> (obj.__impl (), Udm::NULLCHILDROLE);

    if (!events.empty () && !this->has_events_)
      this->has_events_ = true;

    // Visit all the components.
    std::vector <CHAOS::Component> components =
      Udm::ChildrenAttr <CHAOS::Component> (obj.__impl (), Udm::NULLCHILDROLE);

    for (auto component : components)
      component.Accept (*this);
  }
Пример #14
0
//
// Visit_PackageFile_i
//
void CUTS_BE_TCPIP_Stub_Source_Generator::
Visit_PackageFile_i  (const Udm::Object & obj)
{
  CUTS_BE_TCPIP::Output_Stream_Source_Generator osg (this->outfile_);
  CUTS_BE_TCPIP::Input_Stream_Source_Generator isg (this->outfile_);

  // Gather all the necessary elements.
  std::set <CHAOS::Event> events = Udm::ChildrenAttr <CHAOS::Event> (obj.__impl (), Udm::NULLCHILDROLE);
  std::set <CHAOS::Aggregate> aggrs = Udm::ChildrenAttr <CHAOS::Aggregate> (obj.__impl (), Udm::NULLCHILDROLE);
  std::set <CHAOS::Collection> colls = Udm::ChildrenAttr <CHAOS::Collection> (obj.__impl (), Udm::NULLCHILDROLE);

  // Write the output stream generators.
  for (auto aggr : aggrs)
    aggr.Accept (osg);

  for (auto event : events)
    event.Accept (osg);

  for (auto coll : colls)
    coll.Accept (osg);

  // Write the input stream generators.
  for (auto aggr : aggrs)
    aggr.Accept (isg);

  for (auto event : events)
    event.Accept (isg);

  for (auto coll : colls)
    coll.Accept (isg);

  std::set <CHAOS::Package> packages =
    Udm::ChildrenAttr <CHAOS::Package> (obj.__impl (), Udm::NULLCHILDROLE);

  for (auto package : packages)
    package.Accept (*this);
}
CString ModelHandler::extractPortType(Udm::Object portObj)
{
	// whenever the connected port found is derived from DataPort then extract type from the enum attribute of the dstPort
	if(Udm::IsDerivedFrom(portObj.type(), SignalFlow::DataPort::meta))
	{
		return CString(((string) SignalFlow::DataPort::Cast(portObj).DataType()).c_str()).Trim();
	}
	// whenever the connected Port is derived from SF_Port then find the contained TypeRef Port to get the type
	else if(Udm::IsDerivedFrom(portObj.type(), Simulink::SF_Port::meta) ||
			Udm::IsDerivedFrom(portObj.type(), Simulink::SFStateDE::meta) ||
			Udm::IsDerivedFrom(portObj.type(), Simulink::StateDE::meta)
		)
	{
		// find type from the contained type ref
		set<Udm::Object> typerefSet = portObj.GetChildObjects(Simulink::TypeBaseRef::meta);
		// a port can have only a single type
		if(typerefSet.size() == 1)
		{
			Simulink::TypeBaseRef typeBaseRef = Simulink::TypeBaseRef::Cast(*(typerefSet.begin()));
			try
			{
				return CString(((string) Simulink::SF_Matrix::Cast(typeBaseRef.getReferencedObject()).Type()).c_str()).Trim();
			} catch(udm_exception e)
			{
				throw udm_exception(_T("Simulink::TypeBaseRef is currently allowed to refer to objects of only Simulink::SF_Matrix type! @[OBJECT:]") +
									MyUdmUtil::getHyperLinkPath_StdString(typeBaseRef));
			}
		}
		else if(typerefSet.size() > 1)
		{
			throw udm_exception(MyUdmUtil::getHyperLinkPath_StdString(portObj) + _T(" contains more than 1 Simulink::TypeBaseRef type objects. "));
		}
	}
	// the portObj is an InputSignalInterface of a ModelicaComponent
	else if(portObj.type().name() == "InputSignalInterface")
	{
		return CString(((string) InputSignalInterface::Cast(portObj).Class()).c_str()).Trim();
	}
	// the portObj is an OutputSignalInterface of a ModelicaComponent
	else if(portObj.type().name() == "OutputSignalInterface")
	{
		return CString(((string) OutputSignalInterface::Cast(portObj).Class()).c_str()).Trim();
	}
	// the portObj is a ParameterRef of a ModelicaComponent
	else if(portObj.type().name() == "ParameterRef")
	{
		return CString(((string) ParameterRef::Cast(portObj).Class()).c_str()).Trim();
	}

	return CString(_T(""));
}
Пример #16
0
string CUdmApp::ExtractName(Udm::Object ob)
{
	Uml::Class cls= ob.type();				
	set<Uml::Attribute> attrs=cls.attributes();		
	
	// Adding parent attributes
	set<Uml::Attribute> aattrs=Uml::AncestorAttributes(cls);
	attrs.insert(aattrs.begin(),aattrs.end());

	for(set<Uml::Attribute>::iterator ai = attrs.begin();ai != attrs.end(); ai++)
	{
		if(string(ai->type())=="String")
		{
			string str=ai->name();
			if(str=="name")
			{
				string value=ob.getStringAttr(*ai);
				if(value.empty())value="<empty string>";
				return value;
			}			
		}				
	}	
	return string("<no name specified>");
}
Пример #17
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;
}
	std::string Formatter::MakeObjectHyperlink(const std::string & text, const Udm::Object& object)
	{
		ostringstream ostr;
		ostr <<"<a href=\"mga:" << UdmGme::UdmId2GmeId(object.uniqueId()) << "\">" << text << "</a>";
		return ostr.str();
	}
ComponentAssembly CyPhyElaborate::expand(const ComponentAssembly& ca, string ID_Prefix, std::set<Udm::Object> expandedInThisStack) {
	log("expand(CA)",ca.getPath());
	expandedInThisStack.insert(ca);

	set<ComponentAssembly> caKids = ca.ComponentAssembly_kind_children();
	for (set<ComponentAssembly>::const_iterator i = caKids.begin(); i != caKids.end(); i++) {
		if (i->isSubtype() || i->isInstance())
		{
			DetachFromArchetype(*i);
		}
		expand(*i, "", expandedInThisStack);
	}
	
	set<ComponentRef> crToElaborate = ca.ComponentRef_kind_children();
	// For each of these, replace the reference with an instance. Then replicate all connections.
	for (set<ComponentRef>::const_iterator i = crToElaborate.begin(); i != crToElaborate.end(); i++) {
		ComponentRef cri(*i);
		ComponentAssembly parent = cri.ComponentAssembly_parent();
		
		DesignElement cType = DesignElement::Cast(cri.ref());
		
		if (cType != Udm::null)
		{
			DesignElement instance;
			if (cType.type() == Component::meta)
			{
				instance = Component::Cast(cType).CreateInstance(parent);
				// traceability: save this component
				addCopy(instance, cType);
				addCopy(instance, cri);
				
				// Copy InstanceGUID
				string newInstanceGUID = ID_Prefix;
				newInstanceGUID.append(cri.InstanceGUID());
				(Component::Cast(instance)).InstanceGUID() = newInstanceGUID;

				set<Object> children = instance.GetChildObjects();
				for (auto childIt = children.begin(); childIt != children.end(); childIt++)
				{
					// traceability: save all child objects of a component
					addCopy(*childIt, (*childIt).archetype());
					addAllObjectsToTraceability(*childIt);

					SwitchConnections(childIt->archetype(), *childIt, cri, ca);
				}
				// TODO: cannot test this, since connections of this type is not possible
				SwitchConnections(cri, instance, Udm::null, parent);

				// DY: 9/9/11 - copy registry value from ref to instance
				this->copyCADPropertyRegistry2Inst(cri, CyPhyML::Component::Cast(instance));
			}
			else if (expandedInThisStack.find(cType) == expandedInThisStack.end())
			{
				map<Object, Object> cam;
				deque<Object> queue;
				queue.push_back(cType);
				while (queue.size() > 0)
				{
					Object o = queue.front();
					queue.pop_front();
                    Udm::Object referred = getReferredOrNull(o);
					if (referred)
					{
						set<Object> refCompChildren = referred.GetChildObjects();
						for_each(refCompChildren.begin(), refCompChildren.end(), [&](const Object& o) { cam[o] = o; });
					}
					set<Object> qChildren = o.GetChildObjects();
					std::copy(qChildren.begin(), qChildren.end(), back_inserter(queue));
				}
				// instance = ComponentAssembly::Create(parent);
				instance = DesignElement::Cast(parent.CreateObject(cType.type()));
				UdmUtil::CopyObjectHierarchy(cType.__impl(), instance.__impl(), parent.__impl()->__getdn(), cam);

				set<Object> children = cType.GetChildObjects();
				for (auto childIt = children.begin(); childIt != children.end(); childIt++)
				{
					auto to = cam.find(*childIt);
					if (to == cam.end())
						throw udm_exception();
					//if (_ExtractName(to->second) != _ExtractName(*childIt))
					//	throw udm_exception();
					SwitchConnections(*childIt, to->second, cri, parent);
				}
				addCopies(cam);
				// TODO: cannot test this, since connections of this type is not possible
				//SwitchConnections(cri, instance, Udm::null, parent);				
				expand(ComponentAssembly::Cast(instance), ID_Prefix + static_cast<std::string>(cri.InstanceGUID()), expandedInThisStack);
			} else {
				throw udm_exception(std::string("ComponentAssembly '") + static_cast<std::string>(cType.name())
					+ "' cannot contain a ComponentRef to itself");
			}
			instance.name() = cri.name();
			// Copy layout information as well.
			string pos = cri.position();
			if (pos == "")
				instance.position() = "0,0";
			else
				instance.position() = pos;

			// If "ID" is non-zero, copy it too.
			if (cri.ID() != 0)
				instance.ID() = cri.ID();

			cri.DeleteObject();
			// cri.name() = std::string(cri.name()) + "tobedeleted";
		}
		else
		{
			cr_null_ref_set.insert(cri);
		}
	}

	return ca;
};
Пример #20
0
void CUdmApp::UdmMain(
					 Udm::DataNetwork* p_backend,		// Backend pointer(already open!)
					 Udm::Object focusObject,			// Focus object
					 std::set<Udm::Object> selectedObjects,	// Selected objects
					 long param)						// Parameters
{	

	// TODO: Your Code Comes Here...

	try
	{
		if (param == 128)
		{
			automated_expand = true;
			ConsoleMessagesOn = false;
		}
		set<Udm::Object> mySet;
		if (focusObject) {
			mySet.insert(focusObject);
		} else {
			for (set<Udm::Object>::const_iterator i = selectedObjects.begin(); i != selectedObjects.end(); i++)
				mySet.insert(*i);
		}

		bool expand = automated_expand;
		bool collapse = automated_collapse;
		if (!automated_expand && !automated_collapse) {
			int result = IDYES; // collapse is broken MessageBoxA(NULL, "Yes to expand, No to collapse", "Operation", MB_YESNO);
			if (result == IDYES)
				expand = true;
			else if (result == IDNO)
				collapse = true;
		}
		
		CyPhyElaborate cpe;

		for (std::set<Udm::Object>::const_iterator i = mySet.begin(); i != mySet.end(); i++) {
			Udm::Object oi(*i);

			if (oi.type() == ComponentAssembly::meta) {
				if (expand)
				{
					cpe.elaborate( CyPhyML::ComponentAssembly::Cast(oi) );
					for (set<Udm::Object>::const_iterator j = cpe.cr_null_ref_set.begin(); j != cpe.cr_null_ref_set.end(); j++)
						GMEConsole::Console::writeLine("ComponentRef [" + (string)(CyPhyML::ComponentRef::Cast(*j).name()) + "] is null!" , MSG_WARNING);
				}
				else if (collapse)
					; // cpe.collapse( CyPhyML::ComponentAssembly::Cast(oi) );
			} else if (Udm::IsDerivedFrom(focusObject.type(), TestBenchType::meta)) {
				if (expand)
				{
					cpe.elaborate(TestBenchType::Cast(oi));
				}
				else if (collapse)
				{
					; // cpe.collapse(TestBenchType::Cast(oi));
				}
			}
		}
		traceability.Attach(new CyPhyElaborateTraceability(std::unique_ptr<std::map<Udm::Object, Udm::Object> >(std::move(cpe.copiedObjectsToOriginals))));
	}
	catch (udm_exception &exc)
	{
		GMEConsole::Console::writeLine("Udm exception occured! Exception description: " + (std::string)exc.what(), MSG_ERROR);
        msg_exception = exc.what();
        throw exc;
	}
	catch (...)
	{
		GMEConsole::Console::writeLine("Non-Udm exception occured.", MSG_ERROR);
	}
}
Пример #21
0
std::string appendObjLink(const Udm::Object &obj)
{
	if (!obj)
		return "null";
	return ("<A HREF=\"mga:"+ UdmGme::UdmId2GmeId(obj.uniqueId()) + "\">" + UdmUtil::ExtractName(obj) + "</A>");
}
TestBenchType CyPhyElaborate::expand(const TestBenchType& tb) {
	log("elaborate(TB)",tb.getPath());

	set<ComponentAssembly> caKids = tb.ComponentAssembly_kind_children();
	for (set<ComponentAssembly>::const_iterator i = caKids.begin(); i != caKids.end(); i++) {
		if (i->isSubtype() || i->isInstance())
		{
			DetachFromArchetype(*i);
		}
		expand(*i, "", std::set<Udm::Object>());
	}
	
    set<TopLevelSystemUnderTest> crToElaborate = tb.TopLevelSystemUnderTest_kind_children();
	// For each of these, replace the reference with an instance. Then replicate all connections.
	for (set<TopLevelSystemUnderTest>::const_iterator i = crToElaborate.begin(); i != crToElaborate.end(); i++) {
		TopLevelSystemUnderTest cri(*i);
		TestBenchType parent = cri.TestBenchType_parent();

		if (!Uml::IsDerivedFrom(static_cast<DesignEntity>(cri.ref()).type(), DesignElement::meta))
			continue;
		DesignElement cType = DesignElement::Cast(cri.ref());
		
		if (cType != Udm::null)
		{
			DesignElement instance;
			if (Uml::IsDerivedFrom(cType.type(), CyPhyML::ComponentType::meta))
			{
				if (cType.type() == CyPhyML::TestComponent::meta)
				{
					instance = DesignElement::Cast(Udm::Object::Create(cType.type(), parent, CyPhyML::TestBenchType::meta_TopLevelSystemUnderTest, cType.__impl(), false));
				}
				else
					instance = Component::Cast(cType).CreateInstance(parent);
				// traceability: save the instance to the map
				addCopy(instance, cType);

				set<Object> children = instance.GetChildObjects();
				for (auto childIt = children.begin(); childIt != children.end(); childIt++)
				{
					// traceability: save all child objects of a component
					addCopy(*childIt, (*childIt).archetype());
					SwitchConnections(childIt->archetype(), *childIt, cri, tb);
				}
				// TODO: cannot test this, since connections of this type is not possible
				//SwitchConnections(cri, instance, Udm::null, parent);

			}
			else
			{
				map<Object, Object> cam;
				deque<Object> queue;
				queue.push_back(cType);
				while (queue.size() > 0)
				{
					Object o = queue.front();
					queue.pop_front();
                    Udm::Object referred = getReferredOrNull(o);
					if (referred)
					{
						set<Object> refCompChildren = referred.GetChildObjects();
						for_each(refCompChildren.begin(), refCompChildren.end(), [&](const Object& o) { cam[o] = o; });
					}
					set<Object> qChildren = o.GetChildObjects();
					std::copy(qChildren.begin(), qChildren.end(), back_inserter(queue));
				}
				// instance = ComponentAssembly::Create(parent);
				// std::string d1 = cType.type().name();
				instance = DesignElement::Cast(parent.CreateObject(cType.type()));
				Store(instance, cType);
				UdmUtil::CopyObjectHierarchy(cType.__impl(), instance.__impl(), parent.__impl()->__getdn(), cam);

				set<Object> children = cType.GetChildObjects();
				for (auto childIt = children.begin(); childIt != children.end(); childIt++)
				{
					auto to = cam.find(*childIt);
					if (to == cam.end())
						throw udm_exception();
					//if (_ExtractName(to->second) != _ExtractName(*childIt))
					//	throw udm_exception();
					SwitchConnections(*childIt, to->second, cri, parent);
				}
				addCopies(cam);
				// TODO: cannot test this, since connections of this type is not possible
				//SwitchConnections(cri, instance, Udm::null, parent);
				expand(ComponentAssembly::Cast(instance));
				addCopy(instance, cType);
			}
			instance.name() = cri.name();
			// Copy layout information as well.
			string pos = cri.position();
			if (pos == "")
				instance.position() = "0,0";
			else
				instance.position() = pos;

			cri.DeleteObject();
			//cri.name() = std::string(cri.name()) + "tobedeleted";
		}
		else
		{
			cr_null_ref_set.insert(cri);			
		}
	}

	if (Uml::IsDerivedFrom(tb.type(), CyPhyML::BallisticTestBench::meta))
	{
		CyPhyElaborate::SwitchReference<CyPhyML::BallisticTarget>(tb);
		CyPhyElaborate::SwitchReference<CyPhyML::CriticalComponent>(tb);
	}
	CyPhyElaborate::SwitchReference<CyPhyML::TestInjectionPoint>(tb);

	return tb;
}
Пример #23
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;
}
Пример #24
0
bool UdmComparator::compareNodeAux( Udm::Object udmObject1, Udm::Object udmObject2 ) {

	bool retval = true;

	_udmObjectMap.insert(  std::make_pair( udmObject1, udmObject2 )  );

	const Uml::Class &umlClass1 = udmObject1.type();
	const Uml::Class &umlClass2 = udmObject2.type();

	if ( umlClass1 != umlClass2 ) {
		std::cerr << "Classes of objects \"" << udmObject1.getPath( "/" ) << "\" and \"" << udmObject2.getPath( "/" ) << "\" do not match!" << std::endl << std::endl;
		return false;
	}

	getObjectNameSingleton().ObjectNameCache.insert(std::make_pair(udmObject1, getObjectNameSingleton()(udmObject1)));
	getObjectNameSingleton().ObjectNameCache.insert(std::make_pair(udmObject2, getObjectNameSingleton()(udmObject2)));

	UmlAttributeSet umlAttributeSet = _classNameFilter.filterUmlAttributeSet( umlClass1 );
	for( UmlAttributeSet::iterator uasItr = umlAttributeSet.begin() ; uasItr != umlAttributeSet.end() ; ++uasItr ) {
		Uml::Attribute umlAttribute = *uasItr;
		std::string umlAttributeName = umlAttribute.name();
		std::string value1, value2;
		
		std::string umlAttributeType = umlAttribute.type();
		if ( umlAttributeType == "Boolean" ) {
			value1 = boost::lexical_cast< std::string >(  udmObject1.getBooleanAttr( umlAttribute )  );
			value2 = boost::lexical_cast< std::string >(  udmObject2.getBooleanAttr( umlAttribute )  );
		} else if ( umlAttributeType == "Integer" ) {
			value1 = boost::lexical_cast< std::string >(  udmObject1.getIntegerAttr( umlAttribute )  );
			value2 = boost::lexical_cast< std::string >(  udmObject2.getIntegerAttr( umlAttribute )  );
		} else if ( umlAttributeType == "Real" ) {
			value1 = boost::lexical_cast< std::string >(  udmObject1.getRealAttr( umlAttribute )  );
			value2 = boost::lexical_cast< std::string >(  udmObject2.getRealAttr( umlAttribute )  );
		} else {
			value1 = udmObject1.getStringAttr( umlAttribute );
			value2 = udmObject2.getStringAttr( umlAttribute );
		}

		if ( value1 != value2 ) {
			Report::get_singleton().incrementDifferences( udmObject1 );
			std::cerr << "Value of \"" << umlAttributeName << "\" attribute value differs for \"" << udmObject1.getPath( "/" ) << "\" objects:  \"" << value1 << "\" vs. \"" << value2 << "\"" << std::endl << std::endl;
			retval = false;
		}
	}

	UdmObjectSet udmObjectSet1 = _classNameFilter.filterUdmObjectSet( udmObject1.GetChildObjects() );
	UdmObjectSet udmObjectSet2 = _classNameFilter.filterUdmObjectSet( udmObject2.GetChildObjects() );

	if ( udmObjectSet1.size() != udmObjectSet2.size() ) {
		std::cerr << "\"" << udmObject1.getPath( "/" ) << "\" objects have a different number of children:  " << udmObjectSet1.size() << "," << udmObjectSet2.size() << std::endl << std::endl;
		tallyChildrenClasses( udmObjectSet1, udmObjectSet2 );
		retval = false;
	}

	udmObjectSet1 = _classNameFilter.filterConnections( udmObjectSet1 );
	udmObjectSet2 = _classNameFilter.filterConnections( udmObjectSet2 );

	UdmChildObjectSet udmChildObjectSet1;
	udmChildObjectSet1.rehash(udmObjectSet1.size());
	std::copy(udmObjectSet1.begin(), udmObjectSet1.end(), std::inserter(udmChildObjectSet1, udmChildObjectSet1.begin()));
	if ( udmChildObjectSet1.size() != udmObjectSet1.size() ) {
		std::cerr << "Object \"" << udmObject1.getPath( "/" ) << "\" in the first  model has children that cannot be distinguished (duplicate name?)." << std::endl << std::endl;
		retval = false;
	}

	UdmChildObjectSet udmChildObjectSet2;
	udmChildObjectSet2.rehash(udmObjectSet2.size());
	std::copy(udmObjectSet2.begin(), udmObjectSet2.end(), std::inserter(udmChildObjectSet2, udmChildObjectSet2.begin()));
	if ( udmChildObjectSet2.size() != udmObjectSet2.size() ) {
		std::cerr << "Object \"" << udmObject2.getPath( "/" ) << "\" in the second model has children that cannot be distinguished (duplicate name?)." << std::endl << std::endl;
		retval = false;
	}

	UdmChildObjectSet::iterator ucsItr1 = udmChildObjectSet1.begin();
	
	for (; ucsItr1 != udmChildObjectSet1.end(); ++ucsItr1) {

		UdmChildObjectSet::iterator ucsItr2 = udmChildObjectSet2.find(*ucsItr1);

		if (ucsItr2 == udmChildObjectSet2.end()) {
			std::cerr << "No corresponding object for \"" << ucsItr1->object.getPath( "/" ) << "\" in first model found in second model." << std::endl;
			Report::get_singleton().incrementDifferences( udmObject1 );
			retval = false;
			continue;
		} 

		if (compareNodeAux(ucsItr1->object, ucsItr2->object) == false) {
			retval = false;
			Report::get_singleton().addToDifferences( udmObject1 );
		}
		udmChildObjectSet2.erase(ucsItr2);
	}

	UdmChildObjectSet::iterator ucsItr2 = udmChildObjectSet2.begin();
	for (; ucsItr2 != udmChildObjectSet2.end(); ++ucsItr2) {
		std::cerr << "No corresponding object for \"" << ucsItr2->object.getPath( "/" ) << "\" in second model found in first model." << std::endl;
		Report::get_singleton().incrementDifferences( udmObject1 );
		retval = false;
	}
//	if ( !retval ) return false;


	UmlAssociationRoleSet umlAssociationRoleSet = getAllUmlAssociationRoles( umlClass1 );
	for( UmlAssociationRoleSet::iterator arsItr = umlAssociationRoleSet.begin() ; arsItr != umlAssociationRoleSet.end() ; ++arsItr ) {

		Uml::AssociationRole umlAssociationRole = *arsItr;
		UdmObjectSet udmObjectSet1 = _classNameFilter.filterUdmObjectSet(   udmObject1.getAssociation(  Uml::theOther( umlAssociationRole )  )   );
		UdmObjectSet udmObjectSet2 = _classNameFilter.filterUdmObjectSet(   udmObject2.getAssociation(  Uml::theOther( umlAssociationRole )  )   );

		if ( udmObjectSet1.size() != udmObjectSet2.size() ) {
			std::cerr << "Objects \"" << udmObject1.getPath( "/" ) << "\" and \"" << udmObject2.getPath( "/" ) << "\"" << std::endl;
			std::cerr << "have a different number of \"" << umlAssociationRole.name() << "\" associations: " << udmObjectSet1.size() << " vs. " << udmObjectSet2.size() << std::endl << std::endl;
			retval = false;
		}

		UdmAssociationObjectSet udmAssociationObjectSet1;
		udmAssociationObjectSet1.rehash(udmObjectSet1.size());
		std::copy(udmObjectSet1.begin(), udmObjectSet1.end(), std::inserter(udmAssociationObjectSet1, udmAssociationObjectSet1.begin()));
		if ( udmAssociationObjectSet1.size() != udmObjectSet1.size() ) {
			std::cerr << "Object \"" << udmObject1.getPath( "/" ) << "\" has \"" << umlAssociationRole.name() << "\" associated objects that cannot be distinguished (probably due to duplicate name)." << std::endl << std::endl;
			retval = false;
		}

		UdmAssociationObjectSet udmAssociationObjectSet2;
		udmAssociationObjectSet2.rehash(udmObjectSet2.size());
		std::copy(udmObjectSet2.begin(), udmObjectSet2.end(), std::inserter(udmAssociationObjectSet2, udmAssociationObjectSet2.begin()));
		if ( udmAssociationObjectSet2.size() != udmObjectSet2.size() ) {
			std::cerr << "Object \"" << udmObject2.getPath( "/" ) << "\" has \"" << umlAssociationRole.name() << "\" associated objects that cannot be distinguished (probably due to duplicate name)." << std::endl << std::endl;
			retval = false;
		}

		UdmAssociationObjectSet::iterator ucsItr1 = udmAssociationObjectSet1.begin();
		
		for( ; ucsItr1 != udmAssociationObjectSet1.end(); ++ucsItr1 ) {

			UdmAssociationObjectSet::iterator ucsItr2 = udmAssociationObjectSet2.find(*ucsItr1);

			if ( ucsItr2 == udmAssociationObjectSet2.end()) {
				std::cerr << "In first model, \"" << udmObject1.getPath( "/" ) << "\" has a \"" << umlAssociationRole.name() << "\" association object \"" << ucsItr1->object.getPath( "/" ) << "\", but not in the second model." << std::endl;
				Report::get_singleton().incrementDifferences( udmObject1 );
				retval = false;
				continue;
			}

			Udm::Object udmAssociationObject1 = ucsItr1->object;
			Udm::Object udmAssociationObject2 = ucsItr2->object;

			udmAssociationObjectSet2.erase(ucsItr2);

			if ( udmAssociationObject1 == Udm::null ) {
				if ( udmAssociationObject2 != Udm::null ) {
					Report::get_singleton().incrementDifferences( udmObject1 );
					std::cerr << "Association Error:" << std::endl;
					std::cerr << "In first model, object \"" << udmObject1.getPath( "/" ) << "is \"" << umlAssociationRole.name() << "\" associated with Udm::null" << std::endl;
					std::cerr << "However, in the second model, \"" << udmObject2.getPath( "/" ) << "\" is \"" << umlAssociationRole.name() << "\" associated with \"" << udmAssociationObject2.getPath( "/" ) << "\"" << std::endl << std::endl;
					retval = false;
				}
			} else if ( udmAssociationObject2 == Udm::null ) {
				Report::get_singleton().incrementDifferences( udmObject1 );
				std::cerr << "Association Error:" << std::endl;
				std::cerr << "In second model, object \"" << udmObject2.getPath( "/" ) << "is \"" << umlAssociationRole.name() << "\" associated with Udm::null" << std::endl;
				std::cerr << "However, in the first model, \"" << udmObject1.getPath( "/" ) << "\" is \"" << umlAssociationRole.name() << "\" associated with \"" << udmAssociationObject1.getPath( "/" ) << "\"" << std::endl << std::endl;
				retval = false;
			} else {

				UdmObjectMap::iterator uomItr = _udmObjectMap.find( udmAssociationObject1 );
				if ( uomItr != _udmObjectMap.end() ) {

					Udm::Object udmMappedObject = uomItr->second;
					if ( udmMappedObject != udmAssociationObject2 ) {
						Report::get_singleton().incrementDifferences( udmObject1 );
						std::cerr << "Association Error:" << std::endl;
						std::cerr << "In first  model, \"" << udmObject1.getPath( "/" ) << "\" is \"" << umlAssociationRole.name() << "\" associated with \"" << udmAssociationObject1.getPath( "/" ) << "\"." << std::endl;
						std::cerr << "In second model, \"" << udmObject2.getPath( "/" ) << "\" is \"" << umlAssociationRole.name() << "\" associated with \"" << udmAssociationObject2.getPath( "/" ) << "\"." << std::endl;
						std::cerr << "However, \"" << udmAssociationObject1.getPath( "/" ) << "\" of the first model corresponds to \"" << udmMappedObject.getPath( "/" ) << "\"" << std::endl;
						std::cerr << "instead of \"" << udmAssociationObject2.getPath( "/" ) << "\" as it should." << std::endl << std::endl;
						retval = false;
					}

				}
			}
		}

		UdmAssociationObjectSet::iterator ucsItr2 = udmAssociationObjectSet2.begin();
		for( ; ucsItr2 != udmAssociationObjectSet2.end(); ++ucsItr2 ) {
			std::cerr << "In second model, \"" << udmObject2.getPath( "/" ) << "\" has a \"" << umlAssociationRole.name() << "\" association object \"" << ucsItr2->object.getPath( "/" ) << "\", but not in the first model." << std::endl;
			Report::get_singleton().incrementDifferences( udmObject2 );
			retval = false;
			continue;
		}
	}

	Report::get_singleton().addToReport( udmObject1 );

	return retval;
}
Пример #25
0
void CUdmApp::UdmMain(
					 Udm::DataNetwork* p_backend,		// Backend pointer(already open!)
					 Udm::Object focusObject,			// Focus object
					 set<Udm::Object> selectedObjects,	// Selected objects
					 long param,						// Parameters
					 CComPtr<IMgaProject> mgaProject)
{
	/*char currtime[128];
	time_t now = time(0);
	struct tm* tm = localtime(&now);
	sprintf(currtime,"%02d-%02d-%04d  %02d:%02d:%02d", (tm->tm_mon + 1), tm->tm_mday, (tm->tm_year+1900), tm->tm_hour, tm->tm_min, tm->tm_sec);
	std::string ct(currtime);
*/
	std::string start_time = getTimeNow();
	try{
		CyPhyML::RootFolder cyphy_rf = CyPhyML::RootFolder::Cast(p_backend->GetRootObject());
		set<CyPhyML::CWC> cwcs;
		if(	focusObject!=Udm::null 
			&& (Uml::IsDerivedFrom(focusObject.type(), CyPhyML::CWC::meta)))
		{	
			cwcs.insert(CyPhyML::CWC::Cast(focusObject));
		}
		else
		{
			for(set<Udm::Object>::iterator i=selectedObjects.begin();i!=selectedObjects.end();++i)
			{
				Udm::Object currObj = *i;
				if(Uml::IsDerivedFrom(currObj.type(), CyPhyML::CWC::meta))
				{
					cwcs.insert(CyPhyML::CWC::Cast(currObj));					
				}

				// User has selected a Configurations container -- elaborate all CWC within.
				if(Uml::IsDerivedFrom(currObj.type(), CyPhyML::Configurations::meta))
				{
					set<CWC> s_cwc = Configurations::Cast(currObj).CWC_children();
					for (set<CWC>::const_iterator i = s_cwc.begin(); i != s_cwc.end(); i++)
					{
						cwcs.insert(*i);
					}
				}
			}
		}

		if(cwcs.empty()){
			AfxMessageBox(L"Please open a CWC model or select CWC model(s) to invoke the interpreter.");
			return;
		}

		CyPhyML::Configurations cfg_model = (*(cwcs.begin())).Configurations_parent();
		CyPhyML::DesignContainer rootDC = cfg_model.DesignContainer_parent();

		CyPhyML::Configurations cfgModel;
		bool useCurrent = true;
		bool flatten = false;
		std::string outFdr;
		
		// Hide dialog box in silent mode OR if user isn't pressing CTRL
		if (param == GME_SILENT_MODE ||
			!((GetKeyState(VK_CONTROL) & 0x8000)))
		{
			param = GME_SILENT_MODE;
		}
		if (param == GME_SILENT_MODE)
		{
			useCurrent = true;
			flatten = false;
			outFdr = "notused";
		}
		else
		{
			CConfigExportDialog cfgExDlg;
			if (cfgExDlg.DoModal()==IDOK)
			{
				useCurrent = cfgExDlg.m_useCurrent;
				flatten = cfgExDlg.m_flatten;
				outFdr = (LPCSTR)((CStringA)cfgExDlg.m_outputfdr);
			}
			else 
				return;
		}

		int idCnt = cwcs.size();	
		CStatusDialog prgDlg;
		if (param != GME_SILENT_MODE)
		{
			prgDlg.Create(IDD_PROGRESS_DIALOG);
			GetStatusDlg(&prgDlg);
			prgDlg.SetProgress("Preparing to export models...");
		}
		
		if(!useCurrent)
		{
			if (param != GME_SILENT_MODE)
			{
				prgDlg.SetRange(40*idCnt);
			}
			std::string outfileBase = outFdr+"\\"+getFileNameNoExt((LPCSTR)((CStringA)mgaPath));
			for(set<CyPhyML::CWC>::iterator i=cwcs.begin();i!=cwcs.end();++i)
			{
				CyPhyML::CWC cwc = *i;
				std::string outfile = outfileBase+"_"+(std::string)cwc.name()+".mga";					
				std::string msg ="create new CyPhy model for: "+(std::string)cwc.name()+"...";
				if (param != GME_SILENT_MODE)
				{
					prgDlg.SetProgress(CString(msg.c_str()));
				}

				Udm::SmartDataNetwork outDN(CyPhyML::diagram);
				outDN.CreateNew(outfile,"CyPhyML", CyPhyML::RootFolder::meta, Udm::CHANGES_LOST_DEFAULT);
				CyPhyML::RootFolder out_rf = CyPhyML::RootFolder::Cast(outDN.GetRootObject());
				UdmUtil::copy_assoc_map copymap;
				udmCopy(p_backend->GetRootObject().__impl(), outDN.GetRootObject().__impl(),&outDN,copymap,"mga");
			//	UdmUtil::CopyObjectHierarchy(p_backend->GetRootObject().__impl(), outDN.GetRootObject().__impl(), &outDN, copymap);		
				UdmUtil::copy_assoc_map::iterator map_it = copymap.find(cwc);
				ASSERT(map_it!=copymap.end());
				Udm::Object to_cwc_obj = (*map_it).second;
				ASSERT(to_cwc_obj.type() == CyPhyML::CWC::meta);

				if (param != GME_SILENT_MODE)
				{
					prgDlg.SetProgress(CString(msg.c_str()));
				}

				//CyPhyML::Components coms = CyPhyML::Components::Create(out_rf);
				//coms.name() = "Configurations ("+start_time+")";
				CyPhyML::ComponentAssemblies ca_rootFdr = CyPhyML::ComponentAssemblies::Create(out_rf);
				ca_rootFdr.name() = "Generated configurations";
				CyPhyML::ComponentAssemblies ca_folder_dc = CyPhyML::ComponentAssemblies::Create(ca_rootFdr);
				ca_folder_dc.name() = rootDC.name();
				CyPhyML::ComponentAssemblies ca_folder = CyPhyML::ComponentAssemblies::Create(ca_folder_dc);
				ca_folder.name() = "Configurations ("+start_time+")";
				CyPhyCAExporter dexport(ca_folder, CyPhyML::CWC::Cast(to_cwc_obj), flatten);
				dexport.showGui = param != GME_SILENT_MODE;
				dexport.createComponentAssembly();

				//outDN.SaveAs(outfile);
				outDN.CloseWithUpdate();
				
				std::string addlog("CyPhy model \"<A HREF=\""+outfile+ "\">"+outfile+"\"</A> generated for "+appendObjLink(cwc));
				GMEConsole::Console::Out::writeLine(addlog);
			}			
		}
		else
		{
			if (param != GME_SILENT_MODE)
			{
				prgDlg.SetRange(25*idCnt);
			}
			
			set<CyPhyML::ComponentAssemblies>::iterator cafdr_it;
			CyPhyML::ComponentAssemblies ca_rootFdr;
			set<CyPhyML::ComponentAssemblies> ca_fdrs = cyphy_rf.ComponentAssemblies_kind_children();
			for(cafdr_it=ca_fdrs.begin();cafdr_it!=ca_fdrs.end();++cafdr_it)
			{
				CyPhyML::ComponentAssemblies ca_fdr = *cafdr_it;
				if((std::string)ca_fdr.name()=="Generated configurations")
				{
					ca_rootFdr = ca_fdr;
					break;
				}
			}
			if(ca_rootFdr==Udm::null)
			{
				ca_rootFdr = CyPhyML::ComponentAssemblies::Create(cyphy_rf);
				ca_rootFdr.name() = "Generated configurations";
			}
		
			CyPhyML::ComponentAssemblies ca_folder_dc;
			std::string rootDC_name = rootDC.name();
			set<CyPhyML::ComponentAssemblies> ca_fdr_fdrs = ca_rootFdr.ComponentAssemblies_kind_children();
			for(cafdr_it=ca_fdr_fdrs.begin();cafdr_it!=ca_fdr_fdrs.end();++cafdr_it)
			{
				CyPhyML::ComponentAssemblies ca_fdr = *cafdr_it;
				if((std::string)ca_fdr.name()==rootDC_name)
				{
					ca_folder_dc = ca_fdr;
					break;
				}
			}
			if(ca_folder_dc==Udm::null)
			{
				ca_folder_dc = CyPhyML::ComponentAssemblies::Create(ca_rootFdr);
				ca_folder_dc.name() = rootDC_name;
			}

			CyPhyML::ComponentAssemblies ca_folder = CyPhyML::ComponentAssemblies::Create(ca_folder_dc);
			ca_folder.name() = "Configurations ("+start_time+")";

			int txCount = 0;
			for(set<CyPhyML::CWC>::iterator i=cwcs.begin();i!=cwcs.end();++i)
			{
				if (idCnt > 40 && txCount++ == 20)
				{
					txCount = 0;
					COMTHROW(mgaProject->CommitTransaction());
					COMTHROW(mgaProject->FlushUndoQueue());
					CComPtr<IMgaTerritory> terr;
					COMTHROW(mgaProject->BeginTransactionInNewTerr(TRANSACTION_GENERAL, &terr));
				}
				CyPhyML::CWC cwc = *i;
				std::string msg ="create ComponentAssembly for:"+(std::string)cwc.name()+"...";
				if (param != GME_SILENT_MODE)
				{
					prgDlg.SetProgress(CString(msg.c_str()));
				}
				try
				{
					CyPhyCAExporter dexport(ca_folder, cwc, flatten);
					dexport.showGui = param != GME_SILENT_MODE;
					dexport.createComponentAssembly();
					std::string addlog("ComponentAssembly "+appendObjLink(dexport.getComponentAssembly())+"  generated for "+appendObjLink(cwc));
					GMEConsole::Console::Out::writeLine(addlog);

								
//#ifdef _DEBUG
//					std::string end_time = getTimeNow();
//					coms.name() = "Configurations ("+start_time+"-"+end_time+")";
//#else
//					coms.name() = "Configurations ("+start_time+")";
//#endif
				}
				catch(udm_exception &exc)
				{
					ca_folder.DeleteObject();
				//	coms.DeleteObject();
					std::string addlog("ComponentAssembly for "+appendObjLink(cwc)+" has failed: "+(std::string)exc.what());
					GMEConsole::Console::Out::writeLine(addlog);
				}
				catch(...)
				{
					std::string addlog("ComponentAssembly for "+appendObjLink(cwc)+" has failed.");
					GMEConsole::Console::Out::writeLine(addlog);
				}				
			}

		}
		if (param != GME_SILENT_MODE)
		{
			prgDlg.OnFinished();
		}
	}
	catch(udm_exception &exc)
	{
		AfxMessageBox(CString(exc.what()));
		throw exc;
	}
	catch(...)
	{
		throw;
	}
}