Exemplo n.º 1
0
bool CreateCustomDomains(DesertSystem& ds, UdmDesertMap& des_map, DesertUdmMap &inv_des_map,  UdmMemberSet &mb_set)
{
		//custom domains
		set<CustomDomain> cd_set = ds.CustomDomain_kind_children();
		set<CustomDomain>::iterator  cd_iterator;
		

		if (!cd_set.empty())
		{
			CustomDomain cd;

			
			for (cd_iterator = cd_set.begin(); cd_iterator != cd_set.end(); cd_iterator++)
			{
				cd = *(cd_iterator);
				CustomMember dummy;
				//
				//create the custom domain 
				//

				long cd_id = CreateCustomDomain(utf82cstring((string)cd.name()));
				//long cd_id =  CreateCustomDomain(((string)cd.name()).c_str(), cd.id(), cd.externalID());
		
				//inserting custom domain in map
				DoMap(cd,des_map, inv_des_map, cd_id);
				TRACE("Created customdomain %s: %d\n", ((string)cd.name()).c_str(), (long)cd_id);
		
				
				
				CreateCustomDomain(cd, dummy, des_map, inv_des_map, mb_set, true);
			}//eo cd_iterator

		}//eo if (!cd_set.empty())
		return true;
};
Exemplo n.º 2
0
bool CreateMemberRelations(DesertSystem &ds, UdmDesertMap &des_map, DesertUdmMap &inv_des_map)
{

		//MemberRelations
		//
		set<MemberRelation> mr_set = ds.MemberRelation_kind_children();
		set<MemberRelation>::iterator  m_iterator;
		if (!mr_set.empty())
		{
			MemberRelation mr;
			//progress bar indication
			CDesertStatusDlg * st_dlg = GetStatusDlg(NULL);
			int pos = 0;

			for(m_iterator = mr_set.begin(); m_iterator != mr_set.end(); m_iterator ++)
			{
				mr = *m_iterator;
				long src_id, dst_id, par_id;
				CustomMember src = mr.src_end();
				CustomMember dst = mr.dst_end();

				DesertBase par1 = DesertBase::Cast(src.parent());
				DesertBase par2 = DesertBase::Cast(dst.parent());
				
				//enforce same parent
				ASSERT( (long)par1.id() == (long)par2.id());
					
				UdmDesertMap::iterator i;
				
				src_id = GetID(src, des_map);
				dst_id = GetID(dst, des_map);
				par_id = GetID(par1, des_map);

				TRACE("%s member relation: src_id: %d, dst_id: %d, context: %d\n",
					((string)mr.name()).c_str(),
					src_id, 
					dst_id,
					par_id);

				long rel_id = CreateRelation(par_id, src_id, dst_id);
				//long rel_id = CreateRelation(par_id, src_id, dst_id, mr.id(), mr.externalID());
				DoMap(mr, des_map, inv_des_map,  rel_id);

				//progress bar indication
				pos++;
				//st_dlg->StepInState((short) (float)pos *100.00 /(float)mr_set.size());

			}//eo for (e_iterator)

		}//if (!mr_set.empty())

		return true;
};
Exemplo n.º 3
0
bool CreateSimpleFormulas(DesertSystem &ds, UdmDesertMap& des_map, DesertUdmMap &inv_des_map)
{
	set<FormulaSet> f_sets = ds.FormulaSet_kind_children();
	set<FormulaSet>::iterator fts_it;
	if(!f_sets.empty())
	{
		FormulaSet fs;
		for(fts_it=f_sets.begin();fts_it!=f_sets.end();++fts_it)
		{
			fs = *fts_it;
			set<SimpleFormula> sfs = fs.SimpleFormula_kind_children();
			for(set<SimpleFormula>::iterator it=sfs.begin();it!=sfs.end();++it)
			{
				SimpleFormula sf = *it;
				std::map<long, long> srcps, dstps;
				set<VariableProperty>::iterator vp_it;
				set<VariableProperty> out_vps = sf.property_end();
				for(vp_it=out_vps.begin();vp_it!=out_vps.end();++vp_it)
				{
					VariableProperty out_vp = *vp_it;
					long out_vp_id = GetID(out_vp, des_map);
					Udm::Object out_vp_parent = out_vp.parent();
					if(out_vp_parent.type()!=Element::meta) continue;
					Element out_elem = Element::Cast(out_vp_parent);
					long out_elem_id = GetID(out_elem, des_map);
					dstps[out_vp_id] = out_elem_id;
				}
			
				set<VariableProperty> in_vps = sf.srcProperty();
				if(in_vps.empty())
				{
					std::string err = "There is no source VariableProperty for SimpleFormula: "+(std::string)sf.name();
					throw new CDesertException(utf82cstring(err));
				}
				for(vp_it=in_vps.begin();vp_it!=in_vps.end();++vp_it)
				{
					VariableProperty in_vp = *vp_it;
					long in_vp_id = GetID(in_vp, des_map);
					Udm::Object in_vp_parent = in_vp.parent();
					if(in_vp_parent.type()!=Element::meta) continue;
					Element in_elem = Element::Cast(in_vp_parent);
					long in_elem_id = GetID(in_elem, des_map);
					srcps[in_vp_id] = in_elem_id;					
				}
			
				long sf_id = CreateSimpleFormula(utf82cstring((std::string)sf.ComputationType()), srcps, dstps);
				DoMap(sf, des_map, inv_des_map,  sf_id);
			}
		}
	}
	return true;
};
Exemplo n.º 4
0
bool CreateElementRelations(DesertSystem &ds, UdmDesertMap &des_map, DesertUdmMap &inv_des_map)
{
	//progress bar indication
	CDesertStatusDlg * st_dlg = GetStatusDlg(NULL);
	int pos = 0;

		//ElementRelations
		//
		set<ElementRelation> er_set = ds.ElementRelation_kind_children();
		set<ElementRelation>::iterator  e_iterator;
		if (!er_set.empty())
		{
			ElementRelation er;
			for(e_iterator = er_set.begin(); e_iterator != er_set.end(); e_iterator ++)
			{
				er = *e_iterator;
				long src_id, dst_id, par_id;
				Element src = er.src_end();
				Element dst = er.dst_end();
				DesertBase par1 = DesertBase::Cast(src.parent());
				DesertBase par2 = DesertBase::Cast(dst.parent());
				
				//enforce same parent
				ASSERT( (long)par1.id() == (long)par2.id());
					
				UdmDesertMap::iterator i;
				
				src_id = GetID(src, des_map);
				dst_id = GetID(dst, des_map);
				par_id = GetID(par1, des_map);

				TRACE("%s relation: src_id: %d, dst_id: %d, context: %d\n",
					((string)er.name()).c_str(),
					src_id, 
					dst_id,
					par_id);

				long rel_id = CreateRelation(par_id, src_id, dst_id);
				//long rel_id = CreateRelation(par_id, src_id, dst_id, er.id(), er.externalID());
				DoMap(er, des_map, inv_des_map,  rel_id);
				
				//progress bar indication
				pos++;
				//st_dlg->StepInState((short) (float)pos *100.00 /(float)er_set.size());


			}//eo for (e_iterator)

		}//if (!er_set.empty())

		return true;
};
Exemplo n.º 5
0
bool CreateNaturalDomains(DesertSystem& ds, UdmDesertMap& des_map, DesertUdmMap &inv_des_map)
{
		//natural domains
		set<NaturalDomain> nd_set = ds.NaturalDomain_kind_children();
		set<NaturalDomain>::iterator  nd_iterator;
		

		if (!nd_set.empty())
		{
			//progress bar indication
			CDesertStatusDlg * st_dlg = GetStatusDlg(NULL);
			int pos = 0;

			NaturalDomain nd;
			
			for (nd_iterator = nd_set.begin(); nd_iterator != nd_set.end(); nd_iterator++)
			{
				nd = *(nd_iterator);
				
				long d_id = CreateNaturalDomain( 
					utf82cstring((string)nd.name()),
					nd.maximum(),
					nd.minimum());
					
				/*
				long d_id = CreateNaturalDomain( 
					(((string)nd.name()).c_str()),
					nd.maximum(),
					nd.minimum(),
					nd.id(),
					nd.externalID());
				*/

				TRACE("Created NaturalDomain %s, min: %d, max: %d, id: %d\n",
					((string)nd.name()).c_str(),
					(long)nd.minimum(),
					(long)nd.maximum(),
					(long)d_id);

				DoMap(nd, des_map,inv_des_map,  d_id);
				//progress bar indication
				pos++;
			//	st_dlg->StepInState((short) (float)pos *100.00 /(float)nd_set.size());


			}//eo nd_iterator

		}//eo if (!nd_set.empty())
		return true;
};
Exemplo n.º 6
0
bool CreateCustomFormulas(DesertSystem &ds, UdmDesertMap &des_map, DesertUdmMap &inv_des_map)
{
	set<FormulaSet> f_sets = ds.FormulaSet_kind_children();
	set<FormulaSet>::iterator fts_it;

	if (!f_sets.empty())
	{
		FormulaSet fs;
		for (fts_it = f_sets.begin(); fts_it != f_sets.end(); fts_it++)
		{
			fs = *(fts_it);
			set<CustomFormula> cf_set = fs.CustomFormula_kind_children();

			if (cf_set.empty()) continue;
			CreateDesertFormulaSet(fs, des_map, inv_des_map);

		}//eo for cts_iterator
	}//eo if (!c_sets.empty())
	return true;
};
Exemplo n.º 7
0
bool CreateConstraints(DesertSystem &ds, UdmDesertMap &des_map, DesertUdmMap &inv_des_map)
{

	//constrainsets, constrainst
	set<ConstraintSet> c_sets = ds.ConstraintSet_kind_children();
	set<ConstraintSet>::iterator cts_iterator;


	if (!c_sets.empty())
	{
		ConstraintSet cs;
		for (cts_iterator = c_sets.begin(); cts_iterator != c_sets.end(); cts_iterator++)
		{
			cs = *(cts_iterator);
			set<Constraint> ct_set = cs.Constraint_kind_children();

			if (ct_set.empty()) continue;
			CreateDesertConstraintSet(cs, des_map, inv_des_map);

		}//eo for cts_iterator
	}//eo if (!c_sets.empty())
	return true;
};
Exemplo n.º 8
0
BOOL CDesertToolApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif


	//this hack is offered gratiously by our very talented grad. student, Tihamer Levendovszky)

	SetRegistryKey(_T("ISIS"));
	CString str(m_pszHelpFilePath);
	WriteProfileString(_T("Data"),_T("Path"), str.Left(str.GetLength()-3) +CString(_T("exe")));

	//end of the hack offered by our very gifted, talented, and I could continue... grad student

	//check for command line
	//if an argument is received, and actually ends up with stg. like
	// "xml", "mga", or "mem", we will use that one.
	bool command_arg_ok = false;
	bool cancel_input = false;
	bool cancel_output = false;
	bool isSilent= false;
	bool multiRun = false;
	CString consList;
	TCHAR** consGroupNames = NULL;
	TCHAR** consGroups = NULL;
	int numConsGroups = 0;
	TCHAR input_file[_MAX_PATH];
	TCHAR output_file[_MAX_PATH];
	tstring desert_config_info_file = _T("");
	FILE* fdDcif = 0;
	
	static TCHAR szFilterUDM[] = _T("XML Backend Files (*.xml)|*.xml|MEM Backend Files (*.mem)|*.mem|MGA Backend Files (*.mga)|*.mga|All Files (*.*)|*.*||");
	
	bool hasInputFile = false;
	bool hasOutputFile = false;
	
	if (m_lpCmdLine)
	{
		if (_tcslen(m_lpCmdLine))
		{
			if (_tcsstr(m_lpCmdLine, _T("/?")) || _tcsstr(m_lpCmdLine, _T("/help")) || _tcsstr(m_lpCmdLine, _T("--help")) || _tcsstr(m_lpCmdLine, _T("/h")))
			{
				CString usage(_T("Usage: deserttool.exe [<DesertInput xml>] [/o <Output Filename>] [/c \"constraint1:constraint2\"] [/m \"__CG__GroupA:constraint1:constraint2:__CG__GroupB:constraint1:constraint3\"\r\n\r\nArgument details:\r\n"));
				usage.Append(_T("DesertInput xml: input desert xml file\r\n"));
				usage.Append(_T("/c \"constraint1 : constraint2\": apply the constraint list directly without GUI shown up\r\n"));
				usage.Append(_T("/c \"applyAll\": apply all constraints directly without GUI shown up\r\n"));
				usage.Append(_T("/c \"none\": does not apply any constraint and computes total no. of configurations, without GUI shown up\r\n"));
				usage.Append(_T("/m : when used calls desert process for \"none\", \"applyAll\", and all given constraint groups (with names using '__CG__' prefix) one by one, without GUI shown up\r\n"));
				std::cout << usage;
				AfxMessageBox(usage,MB_ICONINFORMATION);
				return TRUE;
			}
			if (_tcsstr(m_lpCmdLine, _T(".xml")) || _tcsstr(m_lpCmdLine, _T(".mem")) || _tcsstr(m_lpCmdLine, _T(".mga"))  
				|| _tcsstr(m_lpCmdLine, _T(".XML")) || _tcsstr(m_lpCmdLine, _T(".MEM")) || _tcsstr(m_lpCmdLine, _T(".MGA")))
			{
				CWzdCommandLineInfo cmdInfo;
				ParseCommandLine(cmdInfo);

				//seems to be a valid file name
				command_arg_ok = true;
				_tcscpy(input_file, cmdInfo.desert_file);				
				hasInputFile = !(cmdInfo.desert_file).IsEmpty();

				_tcscpy(output_file, cmdInfo.desert_output_file);
				hasOutputFile = !(cmdInfo.desert_output_file).IsEmpty();
				
				isSilent = cmdInfo.silent;
				if (cmdInfo.applyCons)
					consList = cmdInfo.consList;

				if(cmdInfo.multiRun) {
					int ncgs = cmdInfo.consGroupNames.GetCount();
					numConsGroups = ncgs;
					if(ncgs > 0) {
						consGroupNames = new TCHAR* [ncgs];
						consGroups = new TCHAR* [ncgs];
					}
					POSITION p1 = cmdInfo.consGroupNames.GetHeadPosition();
					int cIdx = 0;
					while (p1 != NULL) {
						CString s = cmdInfo.consGroupNames.GetNext(p1);
						consGroupNames[cIdx++] = _tcsdup(s);
					}

					POSITION p2 = cmdInfo.consGroups.GetHeadPosition();
					cIdx = 0;
					while (p2 != NULL) {
						CString s = cmdInfo.consGroups.GetNext(p2);
						consGroups[cIdx++] = _tcsdup(s);
					}

					multiRun = true;
					isSilent = true;
				}
			}
		}//eo if (_tcslen(m_lpCmdLine))
	}//eo if (m_lpCmdLine)
	
	if (!command_arg_ok && !hasInputFile)
	{
		CFileDialog Open(	TRUE,									//construct a file open dialog
							_T("xml"),									//default file name extension
							NULL,									//default file name
							OFN_FILEMUSTEXIST |OFN_HIDEREADONLY ,	//default behaviour
							szFilterUDM,							//no filter
							NULL									//no parent windows
							);
		if (Open.DoModal() == IDOK)
		{
			_tcscpy(input_file, Open.GetPathName());
		} 
		else 
		{
			cancel_input = true;
			return TRUE;
		}
	}
	
	tstring infile= stripQuotes( input_file);
	infile.copy( input_file, infile.length(), 0);
	input_file[ infile.length()]= 0;

	// If output_file name is given, use it, else tack an _back at the end
	// (i.e., output has the same name, but sufxed by _back.[xml|mga|mem])
	if(hasOutputFile) {
		tstring outFile = stripQuotes( output_file );
		outFile.copy( output_file, outFile.length(), 0);
		output_file[ outFile.length() ] = 0;

		tstring strOutFName = output_file;
		std::size_t dotPos = strOutFName.find_last_of('.');
		if(dotPos != std::string::npos) {
			desert_config_info_file = strOutFName.substr(0, dotPos) + _T("_configs.xml");
		} else {
			desert_config_info_file = strOutFName + _T("_configs.xml");
		}
		fdDcif = _tfopen(desert_config_info_file.c_str(), _T("w+"));
	}
	else {
		_tcsncpy(output_file, input_file, _tcslen(input_file)-4);
		*(output_file+_tcslen(input_file)-4)='\0';

		desert_config_info_file = output_file;
		desert_config_info_file += _T("_configs.xml");
		fdDcif = _tfopen(desert_config_info_file.c_str(), _T("w+"));
	
		if (_tcsstr(input_file, _T(".xml")) || _tcsstr(input_file, _T(".XML"))) _tcscat(output_file, _T("_back.xml"));
		if (_tcsstr(input_file, _T(".mem")) || _tcsstr(input_file, _T(".MEM"))) _tcscat(output_file, _T("_back.mem"));
		if (_tcsstr(input_file, _T(".mga")) || _tcsstr(input_file, _T(".MGA"))) _tcscat(output_file, _T("_back.mga"));
	}

	if (!cancel_input)
	{
		CStatusDlg s_dlg( 0, isSilent);
		s_dlg.Create(IDD_DIALOG1);
		GetStatusDlg(&s_dlg);

		
		DesertSystem ds;
		Udm::SmartDataNetwork nw(diagram);
		try
		{

			s_dlg.SetStatus(SD_INIT);
			s_dlg.SetStatus(SD_PARSE);

			nw.OpenExisting(std::string(CStringA(input_file)), "", Udm::CHANGES_LOST_DEFAULT);
			ds = DesertSystem::Cast(nw.GetRootObject());
			DesertInit(CString(((std::string)ds.SystemName()).c_str()));
			
			s_dlg.SetStatus(SD_SPS);
			//spaces, elements
			set<Space> spaces = ds.Space_kind_children();
			set<Space>::iterator sp_iterator;

			ASSERT(spaces.begin() != spaces.end());	
			
			UdmDesertMap des_map;
			DesertUdmMap inv_des_map;


			UdmElementSet elements;
			UdmMemberSet custom_members;
						
			CStatusDlg * st_dlg = GetStatusDlg(NULL);
			std::function<void(short)> UpdateStatus = [&st_dlg](short status) { st_dlg->StepInState(status); };
	
			//Build spaces
			if (!spaces.empty())
			{
				Space sp;
				Element dummy;
				
				for (sp_iterator = spaces.begin(); sp_iterator != spaces.end(); sp_iterator++)
				{
					Space sp = *(sp_iterator);
					TRACE("Creating space: %s\n", ((string)sp.name()).c_str());
					CreateDesertSpace(sp, dummy, des_map, inv_des_map, elements, true, UpdateStatus);
				}//eo for (sp_iterator)
			}//if (!spaces.empty())
			
			//create relations
			s_dlg.SetStatus(SD_ERS);
			CreateElementRelations(ds, des_map, inv_des_map, UpdateStatus);

			//create constrains
			s_dlg.SetStatus(SD_CTS);
			CreateConstraints(ds, des_map, inv_des_map);

			//create foumulas
			CreateCustomFormulas(ds, des_map, inv_des_map);

			//create natural domains
			s_dlg.SetStatus(SD_NDS);
			CreateNaturalDomains(ds, des_map, inv_des_map, UpdateStatus);

			//create custom domains
			s_dlg.SetStatus(SD_CDS);
			CreateCustomDomains(ds, des_map, inv_des_map, custom_members, UpdateStatus);

			//create custom domain relations
			s_dlg.SetStatus(SD_MRS);
			CreateMemberRelations(ds, des_map, inv_des_map, UpdateStatus);

			//create variable properties
			s_dlg.SetStatus(SD_VPS);
			CreateVariableProperties(des_map, inv_des_map, elements, UpdateStatus);

			//create constant properties
			s_dlg.SetStatus(SD_CPS);
			CreateConstantProperties(des_map, inv_des_map, elements, custom_members, UpdateStatus);
	
			//create simpleformula for properties
			CreateSimpleFormulas(ds, des_map, inv_des_map);
			//create assignments for VariableProperties
			s_dlg.SetStatus(SD_ASS);
			CreateAssignments(des_map, inv_des_map, elements, custom_members, UpdateStatus);
	
			//invoking Desert UI
			s_dlg.SetStatus(SD_GUI);

			using namespace BackIfaceFunctions;
		
			fprintf(fdDcif, "<?xml version=\"1.1\"?>\n");
			fprintf(fdDcif, "<DesertConfigurations>\n");

			if (multiRun) {
				// Initialize
				std::cout << "Starting Multirun" << std::endl;
				DesertFinitWithMultirun_Pre(numConsGroups, consGroupNames, consGroups);

				// First run with no constraints applied
				int numCfgs = DesertFinitWithMultirun_Exec(true, CString(((std::string) ds.SystemName()).c_str()), _T("NONE"), _T(""));
				std::cout << "Group: NONE\tConfigs: " << numCfgs << std::endl;
				fprintf(fdDcif, "\t<None NumConfigs=\"%d\"/>\n", numCfgs);
				ReInitializeManager(&ds, &des_map, &inv_des_map);

				// Next run with all constraints applied
				numCfgs = DesertFinitWithMultirun_Exec(true, CString(((std::string) ds.SystemName()).c_str()), _T("ALL"), _T("applyAll"));
				std::cout << "Group: NONE\tConfigs: " << numCfgs << std::endl;
				fprintf(fdDcif, "\t<All NumConfigs=\"%d\"/>\n", numCfgs);
				ReInitializeManager(&ds, &des_map, &inv_des_map);

				// Next run for all groups
				fprintf(fdDcif, "\t<Groups>\n");
				for (int j = 0; j < numConsGroups; j++) {
					numCfgs = DesertFinitWithMultirun_Exec(true, CString(((std::string) ds.SystemName()).c_str()), consGroupNames[j], consGroups[j]);

					std::cout << "Group: NONE\tConfigs: " << numCfgs << std::endl;
					fprintf(fdDcif, "\t\t<Group Name=\"%S\" NumConfigs=\"%d\">\n", consGroupNames[j], numCfgs);
					std::vector<tstring> splittedCons = splitConstraints(consGroups[j]);
					for (std::vector<tstring>::iterator conIt = splittedCons.begin(); conIt != splittedCons.end(); ++conIt)
						fprintf(fdDcif, "\t\t\t<Constraint Name=\"%S\"/>\n", conIt->c_str());
					fprintf(fdDcif, "\t\t</Group>\n");

					if (j < numConsGroups) {
						ReInitializeManager(&ds, &des_map, &inv_des_map);
					}
				}
				fprintf(fdDcif, "\t</Groups>\n");

				// Finalize
				DesertFinitWithMultirun_Post();
				std::cout << "Finished Multirun" << std::endl;
				std::cout.flush();
			}
			else {

				// AfxMessageBox(CString("Calling DESERT Finit w/:") + consList );
				std::cout << "Running with constraint set: \t" << consList << std::endl;
				DBConfigurations * confs = (DBConfigurations *)DesertFinit(true, isSilent, consList == "" ? NULL : (LPCTSTR)consList);
				int numCfgs = (confs) ? confs->GetCount() : 0;
				
				tstring strConsList = trimSpaces(tstring(consList));
				if (strConsList.length() == 0 || strConsList.compare(_T("None")) == 0 || strConsList.compare(_T("none")) == 0) {
					fprintf(fdDcif, "\t<None NumConfigs=\"%d\"/>\n", numCfgs);
				} else if(strConsList.compare(_T("applyAll")) == 0) {
					fprintf(fdDcif, "\t<All NumConfigs=\"%d\"/>\n", numCfgs);
				} else {
					fprintf(fdDcif, "\t<ConstraintSet NumConfigs=\"%d\">\n", numCfgs);
					std::vector<tstring> allStrCons = splitConstraints(strConsList);
					for (std::vector<tstring>::iterator strCIt = allStrCons.begin(); strCIt != allStrCons.end(); ++strCIt)
						fprintf(fdDcif, "\t\t<Constraint Name=\"%S\"/>\n", strCIt->c_str());
					fprintf(fdDcif, "\t</ConstraintSet>\n");
				}
				std::cout << "Configs: " << numCfgs << std::endl;
				std::cout.flush();
			
				if (confs)
				{
					//open file dialog to write out configurations
					if (!command_arg_ok || !isSilent)
					{
						CFileDialog SaveAs(
								FALSE,									//construct a file open dialog
								_T("xml"),									//default file name extension
								output_file,							//default file name
								OFN_HIDEREADONLY ,						//default behaviour
								szFilterUDM,							//no filter
								NULL									//no parent windows
								);
						if (SaveAs.DoModal() == IDOK)
						{
							_tcscpy(output_file, SaveAs.GetPathName());
						}
							else cancel_output = true;

					}
					if (!cancel_output)
					{
				
						//create data network
						Udm::SmartDataNetwork bw(DesertIfaceBack::diagram);
						DesertIfaceBack::DesertBackSystem dbs;
						bw.CreateNew(
							//(LPCTSTR)SaveAs.GetFileName(), 
							std::string(CStringA(output_file)),
							"DesertIfaceBack",	
							DesertIfaceBack::DesertBackSystem::meta,
							Udm::CHANGES_PERSIST_ALWAYS);	

						//get&take care of the root object
						dbs = DesertIfaceBack::DesertBackSystem::Cast(bw.GetRootObject());
						dbs.SystemName() = ds.SystemName();

						//elements, custommembers and natural members will be created
						//on the fly, as it they are participating in an assignment

						int confn = confs->GetCount();
						POSITION pos = confs->GetHeadPosition();
						int count = 0;
						s_dlg.SetStatus(SD_PREP);
						while (pos)
						{
		
							DBConfiguration * config = confs->GetNext(pos);
							if (config)
							{
								DesertIfaceBack::Configuration dummy;
								//check for the existence of elements, properties,
								//and values which will be associated then
								POSITION pos1 = config->assignments.GetHeadPosition();
								while (pos1)
								{
									long valid_ass = config->assignments.GetNext(pos1);				
									BackIfaceFunctions::CreatePropertyAssignment(dbs, dummy, inv_des_map, des_map, valid_ass, false);
								}
								POSITION pos2 = config->alt_assignments.GetStartPosition();
								while (pos2)
								{
									long alt, alt_of;
									config->alt_assignments.GetNextAssoc(pos2, alt_of, alt);
									BackIfaceFunctions::CreateAlternativeAssignment(dbs, dummy, inv_des_map, alt_of, alt, false);

								};
							}//eo if (config)	
							s_dlg.StepInState((double)(((double)(++count)) / ((double)(confs->GetCount())))*100.0);	//progress bar

						}//eo while(pos)
						pos = confs->GetHeadPosition();
						s_dlg.SetStatus(SD_BACK);
						count = 0;
						while (pos)
						{
							DBConfiguration * config = confs->GetNext(pos);
							if (config)
							{
								//create configuration
								DesertIfaceBack::Configuration dib_conf = DesertIfaceBack::Configuration::Create(dbs);
								CString s;
								s.Format(_T("Conf. no: %d"), config->id);
								dib_conf.name() = static_cast<LPCSTR>(CStringA(s));
								dib_conf.id() = config->id;
							

								POSITION pos1 = config->assignments.GetHeadPosition();
								while (pos1)
								{
									long valid_ass = config->assignments.GetNext(pos1);				
									BackIfaceFunctions::CreatePropertyAssignment(dbs, dib_conf, inv_des_map, des_map, valid_ass, true);
								}
								POSITION pos2 = config->alt_assignments.GetStartPosition();
								while (pos2)
								{
									long alt, alt_of;
									config->alt_assignments.GetNextAssoc(pos2, alt_of, alt);
									BackIfaceFunctions::CreateAlternativeAssignment(dbs, dib_conf, inv_des_map, alt_of, alt, true);
								};
							
								TRACE("Got %d of configurations!\n", confs->GetCount());


								delete config;
							}//eo if (config)
							s_dlg.StepInState((double)(((double)(++count)) / ((double)(confs->GetCount())))*100.0);	//progress bar
						}//eo while(pos)
					
						delete confs;
			
						set<DesertIfaceBack::Configuration> cfgs = dbs.Configuration_kind_children();		
						for (set<DesertIfaceBack::Configuration>::iterator it = cfgs.begin(); it != cfgs.end(); ++it)
						{
							DesertIfaceBack::Configuration cfg = *it;
							std::string cfgid = cfg.cfgId();
							boost::crc_32_type id_hash;
							id_hash.process_bytes(cfgid.c_str(), cfgid.length());
							int uid = id_hash.checksum();
							std::stringstream sstream;
							sstream << std::hex << uid;
							cfg.cfgId() = sstream.str();
						}
					}//eo if DoModal() == IDOK
				}//eo if (configs)	
		
				//all done
				s_dlg.SetStatus(SD_FINIT);
			
				/*{
					//debug test
					set<ConstraintSet> ts_set = ds.ConstraintSet_kind_children();
				
					set<ConstraintSet>::iterator i = ts_set.begin();
					ConstraintSet cts = *i;
				
					Constraint ct = Constraint::Create(cts);
				
					ct.id() = 1234567890;
					ct.externalID() = -1234567890;
					ct.name() = "f**k name";
					ct.expression() = "f**k expression";
				

					set<Space> sp_set = ds.Space_kind_children();
					set<Space> :: iterator j = sp_set.begin();
					Space sp = *j;
				
					set<Element> e_set = sp.Element_kind_children();
					set<Element> :: iterator k = e_set.begin();
					Element e = *k;
				
					ct.context() = e;
				


				}*/

			} // eo multiRun

			fprintf(fdDcif, "</DesertConfigurations>\n");
			fflush(fdDcif);
			fclose(fdDcif);

		}//eo try
		catch (CDesertException *e)
		{
			fprintf(fdDcif, "</DesertConfigurations>\n");
			fflush(fdDcif);
			fclose(fdDcif);

			e->ReportError();
			//	throw e;
			return FALSE;
		}
		catch (udm_exception e)
		{
			fprintf(fdDcif, "</DesertConfigurations>\n");
			fflush(fdDcif);
			fclose(fdDcif);

			if (m_lpCmdLine && command_arg_ok)
				std::cerr << std::string("Udm exception: ") + e.what();
			else
				AfxMessageBox(CString("Udm exception: ") + CString(e.what()));
			//	throw e;
			return FALSE;
		}
	
	}//eo if (Open.DoModal())

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return TRUE;
}