Пример #1
0
void CFormula::WriteFormula(CArchive& ar) 
{
	CString		s = "";
	char		nowtime[26] = {0};

	//  First write the standard formula functions...
	//  These are functions and symbols, that
	//	* are essential to control the behaviour 
	//	  of (nearly) every poker bot.
	//	* configure some very important constants.
	//  
	s.Format("##%s##\r\n\r\n", get_time(nowtime)); ar.WriteString(s);

	WriteStandardFunction(ar, "notes");
	WriteStandardFunction(ar, "dll");
	// ToDo: Check, if that can be done the normal way too?
	WriteStandardFunction(ar, "f$prwin_number_of_iterations");
	WriteStandardFunction(ar, "f$alli");
	WriteStandardFunction(ar, "f$betsize");
	WriteStandardFunction(ar, "f$betpot_2_1");
	WriteStandardFunction(ar, "f$betpot_1_1");
	WriteStandardFunction(ar, "f$betpot_3_4");
	WriteStandardFunction(ar, "f$betpot_2_3");
	WriteStandardFunction(ar, "f$betpot_1_2");
	WriteStandardFunction(ar, "f$betpot_1_3");
	WriteStandardFunction(ar, "f$betpot_1_4");
	WriteStandardFunction(ar, "f$rais");
	WriteStandardFunction(ar, "f$call");
	WriteStandardFunction(ar, "f$prefold");
	WriteStandardFunction(ar, "f$rebuy");
	WriteStandardFunction(ar, "f$delay");
	WriteStandardFunction(ar, "f$chat");
	WriteStandardFunction(ar, "f$prwin_number_of_opponents"); 
	WriteStandardFunction(ar, "f$sitin");
	WriteStandardFunction(ar, "f$sitout");
	WriteStandardFunction(ar, "f$leave");
	WriteStandardFunction(ar, "f$close");
	WriteStandardFunction(ar, "f$test");
	WriteStandardFunction(ar, "f$debug");

	// handlists for both ohf and old whf style
	for (int i=0; i<(int) _formula.mHandList.GetSize(); i++) 
		ar.WriteString("##" + _formula.mHandList[i].list + "##\r\n" + _formula.mHandList[i].list_text + "\r\n\r\n");

	// User defined functions for new ohf style only.
	// We don't ever have to save them, as for a conversion
	// we only have to generate an ohf file and (for technical reasons)
	// recreate the old whf (which is already open for storing).
	//
	for (int i=0; i<(int) _formula.mFunction.GetSize(); i++) 
	{
		if (!IsStandardFormula(_formula.mFunction[i].func))
		{
			ar.WriteString("##" + _formula.mFunction[i].func + "##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
		}
	}
}
Пример #2
0
void CMarkdownEditorDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		ar.WriteString(Util::ANSIToUTF8(_strText.c_str()).c_str());
		// TODO: 在此添加存储代码
	}
	else
	{
		CString str;
		const int BUF_SIZE = 64*1024;
		unsigned char buf[BUF_SIZE + 1];
		while(true){
			UINT uRead = ar.Read(buf, BUF_SIZE);
			buf[uRead] = '\0';
			str += (const char*)buf;
			if(uRead < BUF_SIZE)
				break;
		}

		_strText = Util::UTF8ToANSI(str);
		this->UpdateAllViews(NULL);
		// TODO: 在此添加加载代码
	}
}
Пример #3
0
void CChildView::SaveSettings(CArchive &ar)
{
	ar << m_crBackColor;
	ar << m_WndTextColor;
	ar << m_crGraphBkClr;
	ar << m_crBorderClr;
	ar << m_iBorderStyle;
	ar << m_iBorderWidth;
	if (m_bBorder) ar << 1;
	else ar << 0;
	if (IsBlackAndWhite()) ar << 1;
	else                   ar << 0;

	if(m_WndLogFont.lfCharSet == 0) m_WndLogFont.lfCharSet = DEFAULT_CHARSET;
	ar << m_WndLogFont.lfCharSet;
	ar << m_WndLogFont.lfClipPrecision;
	ar << m_WndLogFont.lfEscapement;
	ar << m_WndLogFont.lfHeight;
	ar << m_WndLogFont.lfItalic;
	ar << m_WndLogFont.lfOrientation;
	ar << m_WndLogFont.lfOutPrecision;
	ar << m_WndLogFont.lfPitchAndFamily;
	ar << m_WndLogFont.lfQuality;
	ar << m_WndLogFont.lfStrikeOut;
	ar << m_WndLogFont.lfUnderline;
	ar << m_WndLogFont.lfWeight;
	ar << m_WndLogFont.lfWidth;
	CString strong;
	strong = m_WndLogFont.lfFaceName;//let MFC do the conversion...
	ar << strong.GetLength();
	ar.WriteString(strong);
	m_DefaultGraph.Serialize(ar);
}
Пример #4
0
void CFormula::WriteStandardFunction(CArchive& ar, CString name)
{
	int	number_of_functions = (int) _formula.mFunction.GetSize();

	for (int i=0; i<number_of_functions; i++) 
		if (_formula.mFunction[i].func == name) 
			ar.WriteString("##" + name + "##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
}
Пример #5
0
void CProjectDoc::SaveOpenFiles(CArchive &ar)
// Unlike CWideApp::SaveOpenFiles, this version saves them
// remembers their positions and closes them.  It is called
// when the project is being closed.
{
   if (theApp.m_pMFW->PrologGet())
   {
      AfxMessageBox(_T("Let Prolog query finish first (Ctrl-Break will stop it)"));
      return;
   }

   _TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
   _TCHAR szBuffer[sizeof(_T("-32767"))*8 + sizeof(_T("65535"))*2];

   POSITION posDoc = theApp.m_dplateEdit->GetFirstDocPosition();
   CEditDoc* pEditDoc;
   CEditFrame* pEditFr;
   WINDOWPLACEMENT wp;
   wp.length = sizeof wp;

   while(posDoc != NULL)
   {
      pEditDoc = (CEditDoc*)theApp.m_dplateEdit->GetNextDoc(posDoc);
      if (pEditDoc->IsModified())
         pEditDoc->DoSave(pEditDoc->GetPathName());

	  CString pathName = pEditDoc->GetPathName();
	  if (pathName.IsEmpty()) continue;

      pEditFr = pEditDoc->GetEditFrame();

      pEditFr->GetWindowPlacement(&wp);
      wsprintf(szBuffer, szFormat,
         wp.flags, wp.showCmd,
         wp.ptMinPosition.x, wp.ptMinPosition.y,
         wp.ptMaxPosition.x, wp.ptMaxPosition.y,
         wp.rcNormalPosition.left, wp.rcNormalPosition.top,
         wp.rcNormalPosition.right, wp.rcNormalPosition.bottom);
      ar.WriteString( pathName );
      ar.WriteString(_T("="));
      ar.WriteString(szBuffer);
      ar.WriteString(CRLF);

      //pEditFr->SendMessage(WM_CLOSE);
   }
}
Пример #6
0
void RectangleFigure::Serialize(CArchive& ar)
{
	if(ar.IsStoring())
	{
		CString line;
		line.Format(_T("%d %d %d %d %d \r\n"), 2, this->topLeftX, this->topLeftY, this->downRightX, this->downRightY);
		ar.WriteString(line);
	}
}
void CFunctionCollection::SaveObject(
    CArchive &ar, 
    COHScriptObject *function_or_list) {
  CSLock lock(m_critsec);
  if (function_or_list == NULL) return;
  // Don't save OpenPPL-symbols from the OpenPPL-library
  // to user-defined bot-logic files
  if (function_or_list->IsOpenPPLSymbol()) return;
  ar.WriteString(function_or_list->Serialize());
}
void CFunctionCollection::Save(CArchive &ar)
{
  CSLock lock(m_critsec);
  // First write the date
  char nowtime[26] = {0};
  CString s;
  s.Format("##%s##\r\n\r\n", get_time(nowtime)); 
  ar.WriteString(s);
  // DLL  and notes are a bit special "functions",
  // so they get extra treatment.
  SaveObject(ar, LookUp("notes"));
  SaveObject(ar, LookUp("dll"));
  // Then write the standard formula functions...
  // These are functions and symbols, that
  //   * are essential to control the behaviour 
  //	 of (nearly) every poker bot.
  //   * configure some very important constants.
  for (int i=k_autoplayer_function_allin; 
      i<k_number_of_standard_functions; 
      ++i) {
	  SaveObject(ar, LookUp(k_standard_function_names[i]));
  }
  // f$test and f$debug are again special
  SaveObject(ar, LookUp("f$test"));
  SaveObject(ar, LookUp("f$debug"));
  // Handlists
  COHScriptObject *next_object = GetFirst();
  while (next_object != NULL) {
    if (next_object->IsList()) {
      SaveObject(ar, next_object);
    }
    next_object = GetNext();
  }
  // OpenPPL-functions
  for (int i=k_betround_preflop; i<=k_betround_river; ++i) {
    assert(k_OpenPPL_function_names[i] != "");
    SaveObject(ar, LookUp(k_OpenPPL_function_names[i]));
  }
  // User defined functions
  // We already saved the standard-functions
  next_object = GetFirst();
  while (next_object != NULL) {
    if (next_object->IsUserDefinedFunction()) {
      SaveObject(ar, next_object);
    }
    next_object = GetNext();
  }
}
Пример #9
0
void SerializeAlias( CArchive & ar, CAliasArray & aAliases )
{
	char szFileMagic[]		=	"NETTSALIAS";
	DWORD	dwFileVersion	=	0x20040825;

	if( ar.IsStoring() )
	{
		ar.WriteString( szFileMagic );
		ar << dwFileVersion;

		ar << (int)aAliases.GetSize();
		for( int i=0; i<aAliases.GetSize(); i++ )
		{
			CAlias & a = aAliases.ElementAt(i);
			ar << a.m_strName;
			ar << a.m_strValue;
		}
	}
	else
	{
		TCHAR buffer[64];
		memset( buffer, 0, sizeof(buffer) );
		ar.ReadString( buffer, strlen(szFileMagic) );
		if( 0 != strncmp( szFileMagic, buffer, strlen(szFileMagic) ) )
			return;

		DWORD	dwVer;				
		ar >> dwVer;
		if( dwVer > dwFileVersion )
			return;

		int size;
		ar >> size;
		if( size < 0 || size > 10000 )	// too big
			return;

		aAliases.SetSize( 0, size+2 );
		for( int i=0; i<size; i++ )
		{
			CAlias a;
			ar >> a.m_strName;
			ar >> a.m_strValue;
			aAliases.Add( a );
		}
	}
}
Пример #10
0
void CIBADoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		CString strTmp;
		
		strTmp = _T("FFFFFFFFFFFF");

		//char c1 = 0xFF, c2 = 0xFE;

		//ar << c1 << c2 << strTmp;
		
		ar.WriteString(strTmp);

	}
	else
	{
		// TODO: add loading code here
	}
}
Пример #11
0
void NNLayer::Serialize(CArchive &ar)
{
	VectorNeurons::iterator nit;
	VectorWeights::iterator wit;
	VectorConnections::iterator cit;
	
	int ii, jj;
	
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		
		ar.WriteString( label.c_str() );
		ar.WriteString( _T("\r\n") );  // ar.ReadString will look for \r\n when loading from the archive
		ar << m_Neurons.size();
		ar << m_Weights.size();
		
		
		
		for ( nit=m_Neurons.begin(); nit<m_Neurons.end(); nit++ )
		{
			NNNeuron& n = *(*nit);
			ar.WriteString( n.label.c_str() );
			ar.WriteString( _T("\r\n") );
			ar << n.m_Connections.size();
			
			for ( cit=n.m_Connections.begin(); cit<n.m_Connections.end(); cit++ )
			{
				ar << (*cit).NeuronIndex;
				ar << (*cit).WeightIndex;
			}
		}
		
		for ( wit=m_Weights.begin(); wit<m_Weights.end(); wit++ )
		{
			ar.WriteString( (*wit)->label.c_str() );
			ar.WriteString( _T("\r\n") );
			ar << (*wit)->value;
		}
		
		
	}
	else
	{
		// TODO: add loading code here
		
		CString str;
		ar.ReadString( str );
		
		label = str;
		
		int iNumNeurons, iNumWeights, iNumConnections;
		double value;
		
		NNNeuron* pNeuron;
		NNWeight* pWeight;
		NNConnection conn;
		
		ar >> iNumNeurons;
		ar >> iNumWeights;
		
		for ( ii=0; ii<iNumNeurons; ++ii )
		{
			ar.ReadString( str );
			pNeuron = new NNNeuron( (LPCTSTR)str );
			m_Neurons.push_back( pNeuron );
			
			ar >> iNumConnections;
			
			for ( jj=0; jj<iNumConnections; ++jj )
			{
				ar >> conn.NeuronIndex;
				ar >> conn.WeightIndex;
				
				pNeuron->AddConnection( conn );
			}
		}
		
		for ( jj=0; jj<iNumWeights; ++jj )
		{
			ar.ReadString( str );
			ar >> value;
			
			pWeight = new NNWeight( (LPCTSTR)str, value );
			m_Weights.push_back( pWeight );
		}
		
	}
	
}
Пример #12
0
void CFormula::WriteFormula(CArchive& ar, bool use_new_OHF_style) 
{
	CString		s = "";
	int			i = 0, N = (int) _formula.mFunction.GetSize();
	char		nowtime[26] = {0};

	//  First write the standard formula functions...
	//  These are functions and symbols, that
	//	* are essential to control the behaviour 
	//	  of (nearly) every poker bot.
	//	* configure some very important constants.
	//  
	s.Format("##%s##\r\n\r\n", get_time(nowtime)); ar.WriteString(s);

	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "notes") 
			ar.WriteString("##notes##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n"); 

	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "dll")
			ar.WriteString("##dll##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");

	s.Format("##bankroll##\r\n%f\r\n\r\n", _formula.dBankroll); ar.WriteString(s);
	
	s.Format("##defcon##\r\n%f\r\n\r\n", _formula.dDefcon); ar.WriteString(s);
	
	s.Format("##rake##\r\n%f\r\n\r\n", _formula.dRake); ar.WriteString(s);
	
	s.Format("##nit##\r\n%d\r\n\r\n", (int) _formula.dNit); ar.WriteString(s);
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$alli")
			ar.WriteString("##f$alli##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$swag") 
			ar.WriteString("##f$swag##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$srai") 
			ar.WriteString("##f$srai##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$rais") 
			ar.WriteString("##f$rais##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$call") 
			ar.WriteString("##f$call##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$prefold") 
			ar.WriteString("##f$prefold##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	// New standard formulas are
	//   * f$delay
	//   * f$chat
	//
	// Old standard formulas are:
	//   * f$evrais 
	//   * f§evcall
	//
	if (use_new_OHF_style)
	{
		for (i=0; i<N; i++) 
			if (_formula.mFunction[i].func == "f$delay") 
				ar.WriteString("##f$delay##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
		for (i=0; i<N; i++) 
			if (_formula.mFunction[i].func == "f$chat") 
				ar.WriteString("##f$chat##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	}
	else
	{
		for (i=0; i<N; i++) 
			if (_formula.mFunction[i].func == "f$evrais") 
				ar.WriteString("##f$evrais##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
		for (i=0; i<N; i++) 
			if (_formula.mFunction[i].func == "f$evcall") 
				ar.WriteString("##f$evcall##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	}

	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$P") 
			ar.WriteString("##f$P##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$play") 
			ar.WriteString("##f$play##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$test") 
			ar.WriteString("##f$test##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
	
	for (i=0; i<N; i++) 
		if (_formula.mFunction[i].func == "f$debug") 
			ar.WriteString("##f$debug##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");

	// handlists for both ohf and old whf style
	for (i=0; i<(int) _formula.mHandList.GetSize(); i++) 
		ar.WriteString("##" + _formula.mHandList[i].list + "##\r\n" + _formula.mHandList[i].list_text + "\r\n\r\n");

	// User defined functions for new ohf style only.
	// We don't ever have to save them, as for a conversion
	// we only have to generate an ohf file and (for technical reasons)
	// recreate the old whf (which is already open for storing).
	//
	if (use_new_OHF_style)
	{
		for (i=0; i<(int) _formula.mFunction.GetSize(); i++) 
		{
			if (_formula.mFunction[i].func != "notes" &&
				_formula.mFunction[i].func != "dll" &&
				_formula.mFunction[i].func != "f$alli" &&
				_formula.mFunction[i].func != "f$swag" &&
				_formula.mFunction[i].func != "f$srai" &&
				_formula.mFunction[i].func != "f$rais" &&
				_formula.mFunction[i].func != "f$call" &&
				_formula.mFunction[i].func != "f$prefold" &&
				_formula.mFunction[i].func != "f$delay" &&
				_formula.mFunction[i].func != "f$chat" &&
				_formula.mFunction[i].func != "f$P" &&
				_formula.mFunction[i].func != "f$play" &&
				_formula.mFunction[i].func != "f$test" &&
				_formula.mFunction[i].func != "f$debug" ) 
			{
				ar.WriteString("##" + _formula.mFunction[i].func + "##\r\n" + _formula.mFunction[i].func_text + "\r\n\r\n");
			}
		}
	}
}
Пример #13
0
void CWedDoc::Serialize(CArchive& ar, const char *docname)

{
    CString 	num, str;
    CString 	filename = docname;

    PathToFname(filename);

    if (ar.IsStoring())
    	{
		// Writing
		CWaitCursor cursor;

        POSITION pos;
		pos = strlist.GetHeadPosition();
		origlines = 0;
        while(TRUE)
        	{
        	CString line;
			if(!(origlines % 100))
				{
				num.Format("Writing %s line %d", filename, origlines);
				message(num);
				}
			origlines++;
            if (!pos)
            	break;

            line = strlist.GetNext(pos);

            // Obey tab save option
			if(Tab2Space ||	spaceify)
				ExpandTabs(line);

            // Dispose space from EOL
			line.TrimRight();

            // Write out to file
            ar.WriteString(line);

            // Do end of line according to settings
			if(unix)
				ar.WriteString("\n");
			else
				ar.WriteString("\r\n");
        	}
		num.Format("Wrote %s", filename);  message(num);

		// If user decides to save, save undo/redo info as well
		SaveUndo(); SaveRedo();
    	}
    else
    	{
		// Reading
		CWaitCursor cursor;
		char buff[DETECTSIZE];

        strlist.RemoveAll();

		// Determine file type
		CFile* fp = ar.GetFile();
		int rlen = fp->Read(buff, DETECTSIZE);

		// File without a newline ---> default to DOS
		if(!strstr(buff, "\n"))
			unix = FALSE;
		else if (strstr(buff, "\r\n"))
			unix = FALSE;
		else
			unix = TRUE;

		// Take a wild guess for tabs
		if(!strstr(buff, "\t") && rlen > DETECTSIZE/2 )
			{
			spaceify = TRUE;
			}

		// Start over on file
		fp->Seek(0,CFile::begin);
		origlines = 0;

		// Load file
        while(TRUE)
        	{
            str = "";
			if(!(origlines % 100))
				{
				CString num;
				num.Format("Reading %s line %d", filename, origlines);
				message(num);
				}
			if(YieldToWinEx())
				{
				readonly = TRUE;
				AfxMessageBox("Aborted load, partial buffer is readonly.");
				break;
				}
			TRY
            	{
            	if(!ar.ReadString(str))
                	break;
            	}
	        	CATCH_ALL(ee); END_CATCH_ALL
			origlines++;
            TRY
            	{
            	strlist.AddTail(str);
            	}
            	CATCH(CMemoryException, ee)
            		{
                	//P2N("Memory exception\r\n");
					break;
            		}
            	END_CATCH
        	}

		// So unix can see an unlocked file
		// Let others see it
		// ReleaseFile(fp, 1);

        // Patch things up
        if( strlist.IsEmpty())
        	{
            //P2N("Empty file\r\n");
            strlist.AddTail("");
        	}
    }
}
Пример #14
0
void CProjectDoc::Serialize(CArchive& ar)
{
   CProjectView* pview = GetProjectView();
   int i, l;

   if (ar.IsStoring())
   {  // Output
#ifdef _UNICODE
      _TCHAR uniflag = 0xfeff;  // written as fffe, which is right for PC unicode
      ar.Write(&uniflag, 2);
#endif
      pview->UpdateData(TRUE);
      ar.WriteString(_T("amzirel=4"));  // so we can check for valid ppj files
      ar.WriteString(CRLF);
      ar.WriteString(_T("xplfile="));
      ar.WriteString(pview->m_xplfile);
      ar.WriteString(CRLF);
      ar.WriteString(_T("directory="));
      ar.WriteString(pview->m_directory);
      ar.WriteString(CRLF);
      ar.WriteString(_T("opdefs="));
      ar.WriteString(pview->m_opdefs);
      ar.WriteString(CRLF);

      CListBox* pLB;
      CString s;

      pLB = (CListBox*)(pview->GetDlgItem(IDP_FILELIST));
      l = pLB->GetCount();
      for (i=0; i<l; i++)
      {
         pLB->GetText(i, s);
         ar.WriteString(_T("file="));
         ar.WriteString(s);
         ar.WriteString(CRLF);
      }

      pLB = (CListBox*)(pview->GetDlgItem(IDP_LIBLIST));
      l = pLB->GetCount();
      for (i=0; i<l; i++)
      {
         pLB->GetText(i, s);
         ar.WriteString(_T("library="));
         ar.WriteString(s);
         ar.WriteString(CRLF);
      }

      SaveOpenFiles(ar);
   }
   else
   {  // Input
      ReadArchive(ar);
   }
}
Пример #15
0
void CGWorldOpenGL::WriteGWorldToVRML(CArchive& file,STATIONSHOW SS)
{
    char szBuffer[128];
    file.WriteString("#VRML V1.0 ascii\n");
    //We should probably just use the defaults and make things run faster instead of setting
    //a light source.
    file.WriteString("Separator {\n\tDEF SceneInfo Info {\n\t\tstring ");
    file<<'"';
    file.WriteString("Modeled using On Station 3.1");
    file<<'"';
    file.WriteString("\n\t}\n}\n");

    int iTriangleGroupCount=m_TriangleGroupArray.GetSize();
    for (int i=0; i<iTriangleGroupCount; i++)
    {
        sprintf(szBuffer,"DEF TriangleStrip%i Separator {\n",i+1);
        file.WriteString(szBuffer);
        CGWorldTriangleGroup const * pGroup=m_TriangleGroupArray.GetAt(i);
        pGroup->DumpToVRML(file);
        file.WriteString("}\n");
    }

    //Next, do the fixed points if appropriate
    int iFixedPointCount=m_ConstraintArray.GetSize();
    CPosMatrix ptPos;
    CPosMatrix transformedPos;
    for (i=0; i<iFixedPointCount; i++)
    {
        sprintf(szBuffer,"DEF FixedPoint%i Separator {\n",i+1);
        file.WriteString(szBuffer);

        const CGWorldOpenGLConstraint & fixedPoint=m_ConstraintArray.GetAt(i);
        file.WriteString("\tMaterial {\n\t\tdiffuseColor 1.0 0.0 0.0\n\t}\n");
        sprintf(szBuffer,"\tTranslation {\n\t\ttranslation %f %f %f\n\t}\n",fixedPoint.position[0],fixedPoint.position[1],fixedPoint.position[2]);
        file.WriteString(szBuffer);
        file.WriteString("\tSphere {\n\t\tradius 3\n\t}\n");
        file.WriteString("}\n");
    }
}
Пример #16
0
void CGWorldTriangleFan::DumpToVRML(CArchive& file) const
{
    char szBuffer[256];
    //write material properties
    sprintf(szBuffer,"\tMaterial {\n\t\tdiffuseColor %f %f %f\n\t\tambientColor %f %f %f\n\t}\n",	((float)GetRValue(m_crColor))/255.0f,((float)GetGValue(m_crColor))/255.0f,((float)GetBValue(m_crColor))/255.0f,	((float)GetRValue(m_crColor))/255.0f,((float)GetGValue(m_crColor))/255.0f,((float)GetBValue(m_crColor))/255.0f);
    file.WriteString(szBuffer);

    file.WriteString("\tCoordinate3	{\n\t\tpoint [\n");

    for (int i=0; i<m_iNumVertices; i++)
    {
        sprintf(szBuffer,"\t\t\t%f %f %f",m_pVertices[i].m_fPos[0],m_pVertices[i].m_fPos[1],m_pVertices[i].m_fPos[2]);
        file.WriteString(szBuffer);
        if (i!=m_iNumVertices-1)
        {
            file.WriteString(",\n");
        }
        else
        {
            file.WriteString("\n");
        }
    }
    file.WriteString("\t\t]\n\t}\n");
    file.WriteString("\tIndexedFaceSet {\n\t\tcoordIndex [\n");
    for (i=0; i<m_iNumVertices; i++)
    {
        sprintf(szBuffer,"\t\t\t%i,%i,%i,-1",0,(i+1)%m_iNumVertices,(i+2)%m_iNumVertices);
        file.WriteString(szBuffer);
        if (i!=m_iNumVertices-1)
        {
            file.WriteString(",\n");
        }
        else
        {
            file.WriteString("\n");
        }
    }
    file.WriteString("\t\t]\n\t}\n");
}
void CVertexCollection::Serialize(CArchive& Archive, CTriangulation *Triangulation)
{
 double x = 0;
 double y = 0;
 double z = 0;
 CVertex *Vertex = NULL;
 CString sLine;

 if (Archive.IsStoring())
 {
  for (long VertexIndex = 4; VertexIndex < m_Collection.GetCount(); VertexIndex++)
  {
   Vertex = (CVertex *)m_Collection[VertexIndex];

   sLine.Format(_T(" %.3lf %.3lf %.3lf"),Vertex->m_Coordinate[0],Vertex->m_Coordinate[1], Vertex->m_Coordinate[2]);
   Archive.WriteString(sLine);
   Archive.WriteString(_T("\n"));
   m_VertexNumber++;
  }
 }
 else
 {
//Let's check file extension.

	 CFile *File = Archive.GetFile();
	 CString FilePath = File->GetFilePath();
	 char Ext[256];
	 _splitpath(FilePath, NULL, NULL, NULL, Ext);

//First four verteces are verteces of bounding box/
  for (int VertexIndex = 0; VertexIndex < 4; VertexIndex++)
  {
   Vertex = new CVertex(0, 0, 0, CVertex::BoundingBox);
   Vertex->m_Index = m_Collection.Add(Vertex);
  }

  do
  {
	  if (!sLine.IsEmpty())
   {
   CString XString;
   CString YString;
   CString ZString;

   int Start = 0;

   XString = sLine.Tokenize(_T(" "), Start);
   YString = sLine.Tokenize(_T(" "), Start);
   ZString = sLine.Tokenize(_T(" "), Start);

   sscanf_s(XString,_T("%lf.2"), &x);
   sscanf_s(YString,_T("%lf.2"), &y);
   sscanf_s(ZString,_T("%lf.2"), &z);

   Vertex = new CVertex(x, y, z, CVertex::Standalone);

   Vertex->m_Index = m_Collection.Add(Vertex);

   if (m_Collection.GetCount() == 5)
   {
    m_Min.m_Coordinate[0] = x;
    m_Min.m_Coordinate[1] = y;
    m_Min.m_Coordinate[2] = z;
    m_Max.m_Coordinate[0] = x;
    m_Max.m_Coordinate[1] = y;
    m_Max.m_Coordinate[2] = z;
   }
   else
   {
//todo = min
   if (m_Min.m_Coordinate[0] > x)
     m_Min.m_Coordinate[0] = x;
   if (m_Min.m_Coordinate[1] > y)
     m_Min.m_Coordinate[1] = y;
   if (m_Min.m_Coordinate[2] > z)
     m_Min.m_Coordinate[2] = z;

   if (m_Max.m_Coordinate[0] < x)
     m_Max.m_Coordinate[0] = x;
   if (m_Max.m_Coordinate[1] < y)
     m_Max.m_Coordinate[1] = y;
   if (m_Max.m_Coordinate[2] < z)
     m_Max.m_Coordinate[2] = z;
   }
   }
	  if (m_Collection.GetSize() > 100)
		  break;
  }
  while(Archive.ReadString(sLine));
//////////////////////////////////////////

 m_DeltaX = 0.25 * fabs((m_Max.m_Coordinate[0] - m_Min.m_Coordinate[0]));
 m_DeltaY = 0.25 * fabs((m_Max.m_Coordinate[1] - m_Min.m_Coordinate[1]));
 
 m_Min.m_Coordinate[2] = (double)((long)m_Min.m_Coordinate[2]);

//////////////////////////////////////////////
  Vertex = (CVertex *)m_Collection[0];

  Vertex->m_Coordinate[0] = m_Min.m_Coordinate[0] - 2 * m_DeltaX;
  Vertex->m_Coordinate[1] = m_Min.m_Coordinate[1] - 2 * m_DeltaY;
  Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2];

  Vertex = (CVertex *)m_Collection[1];

  Vertex->m_Coordinate[0] = m_Max.m_Coordinate[0] + 2 * m_DeltaX;
  Vertex->m_Coordinate[1] = m_Min.m_Coordinate[1] - 2 * m_DeltaY;
  Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2];

  Vertex = (CVertex *)m_Collection[2];

  Vertex->m_Coordinate[0] = m_Max.m_Coordinate[0] + 2 * m_DeltaX;
  Vertex->m_Coordinate[1] = m_Max.m_Coordinate[1] + 2 * m_DeltaY;
  Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2];

  Vertex = (CVertex *)m_Collection[3];

  Vertex->m_Coordinate[0] = m_Min.m_Coordinate[0] - 2 * m_DeltaX;
  Vertex->m_Coordinate[1] = m_Max.m_Coordinate[1] + 2 * m_DeltaY;
  Vertex->m_Coordinate[2] = m_Min.m_Coordinate[2];
 }
}