void createCWCReference(CyPhyML::DesignContainer &container)
{
	if(container == cfgs_model.parent()) return;

	set<CyPhyML::CWCReference> cwcrefs = container.CWCReference_kind_children();
	for(set<CyPhyML::CWCReference>::iterator i=cwcrefs.begin();i!=cwcrefs.end();++i)
	{
		CyPhyML::Configurations cfgmodels = (*i).ref();
		if(cfgmodels == cfgs_model)
			return;
	}

	string tmp = container.name();
	if(!container.isInstance())
	{
		CyPhyML::CWCReference cwc_ref = CyPhyML::CWCReference::Create(container);
		cwc_ref.name() = "configurations ref";
		cwc_ref.ref() = cfgs_model;
	}
	else
	{
		cfg_model.DeleteObject();
		throw udm_exception((string)container.name()+" cannot be instance model.");
	}
}
Пример #2
0
void CDSERootSelDialog::FillDSETree(CyPhyML::DesignContainer &cyphy_con, HTREEITEM parent)
{
	std::string iname = (std::string)cyphy_con.name() + " [" + (std::string)cyphy_con.ContainerType()+"]";
	HTREEITEM dse_node = m_dstree.InsertItem(utf82cstring(iname.c_str()), parent, TVI_LAST);
	dseTreeMap[dse_node] = cyphy_con;

	set<CyPhyML::DesignEntity> entities = cyphy_con.DesignEntity_kind_children();
	for(set<CyPhyML::DesignEntity>::iterator i=entities.begin();i!=entities.end();++i)
	{
		CyPhyML::DesignEntity entity = *i;
		if(!Uml::IsDerivedFrom(entity.type(), CyPhyML::DesignContainer::meta))
			continue;
		FillDSETree((CyPhyML::DesignContainer::Cast(entity)), dse_node);
	}
	m_dstree.SortChildren(dse_node);
	m_dstree.Expand(dse_node,TVE_EXPAND);
}
void addSelectedEntity(set<CyPhyML::DesignEntity>& allEntities, set<CyPhyML::DesignEntity>* curEntities, const CyPhyML::DesignEntity& selectedCom, const CyPhyML::DesignContainer& parent)
{
	CyPhyML::DesignContainer groupBaseType = parent;
	if(groupBaseType.isInstance() || groupBaseType.isSubtype()) {
		groupBaseType = CyPhyML::DesignContainer::Cast(groupBaseType.Archetype());
		while(groupBaseType.isInstance() || groupBaseType.isSubtype()) {
			groupBaseType = CyPhyML::DesignContainer::Cast(groupBaseType.Archetype());
		}
	}
	curEntities->insert(groupBaseType);
	allEntities.insert(groupBaseType);
	set<CyPhyML::DesignEntity> rootChildren = groupBaseType.DesignEntity_kind_children();
	for(set<CyPhyML::DesignEntity>::iterator rootChIt = rootChildren.begin(); rootChIt != rootChildren.end(); ++rootChIt) {
		CyPhyML::DesignEntity rootChild = *rootChIt;
		if(componentFollowsFromInTypeInstanceHierarchy(selectedCom, rootChild)) {
			curEntities->insert(rootChild);
			allEntities.insert(rootChild);
		}
	}
}
void traverseContainerForMorphMatrix(CyPhyML::DesignContainer &container, MorphMatrix& morphMatrix, set<CyPhyML::DesignEntity>& allEntities)
{
	set<CyPhyML::DesignEntity> entities = container.DesignEntity_kind_children();

	// First, populate the Morph Matrix
	set<CyPhyML::DesignEntity>* curEntities = 0;
	MorphMatrix::iterator pos;
	try {
		pos = morphMatrix.find(config);
	} catch (...) {
		// shouldn't normally occur
		pos = morphMatrix.end();
	}
	if(pos==morphMatrix.end()) {
		curEntities = new set<CyPhyML::DesignEntity>(); // FIXME: need to delete this
		morphMatrix.insert(MorphMatrix::value_type(config, curEntities));
	} else {
		curEntities = morphMatrix[config];
	}

	// Continue with configurations
	if((std::string)container.ContainerType()!="Compound")
	{
		map<int, int>::iterator pos = alternativeMap.find(container.ID());
		if(pos==alternativeMap.end())
			return;
		
		//get object by id
		int altId = (*pos).second;
		if(altId<=0) return;

		CyPhyML::DesignEntity selectedCom;
		for(set<CyPhyML::DesignEntity>::iterator i=entities.begin();i!=entities.end();++i)
		{
			if((*i).ID() == altId)
			{
				selectedCom = *i;
				break;
			}
		}
		if(selectedCom == Udm::null) 
		{
			char buffer[10];
			_itoa(altId, buffer, 10);
			std::string err = "Cannot find the Component with ID: "+(std::string)buffer+" in DesignContainer: "+(std::string)container.name();
			throw udm_exception(err.c_str());
		}

		addSelectedEntity(allEntities, curEntities, selectedCom, container);

		//if(Uml::IsDerivedFrom(selectedCom.type(), CyPhyML::DesignContainer::meta))
		if((std::string)selectedCom.type().name()=="DesignContainer")
		{
			traverseContainerForMorphMatrix(CyPhyML::DesignContainer::Cast(selectedCom), morphMatrix, allEntities);
		}
	}
	else 
	{
		for(set<CyPhyML::DesignEntity>::iterator i=entities.begin();i!=entities.end();++i)
		{
			const CyPhyML::DesignEntity &com = *i;
			addSelectedEntity(allEntities, curEntities, com, container);
			//if(Uml::IsDerivedFrom(com.type(), CyPhyML::DesignContainer::meta))
			if((std::string)com.type().name()=="DesignContainer")
			{
				traverseContainerForMorphMatrix(CyPhyML::DesignContainer::Cast(com), morphMatrix, allEntities);
			}
		}
	}
}
Пример #5
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;
	}
}