Ejemplo n.º 1
0
BOOL CDlgFreeTrainList::LoadFreeTrainManageListFile()
{
  CString FileName = g_ProjectFilePath + "FeedTrain.lst";
  CFile file;
	if(!file.Open(FileName, CFile::modeRead))
  {
    ::AfxMessageBox(FileName + " 文件读取失败");
    return FALSE;
  }
  else
  {
    CArchive ar(&file,CArchive::load);

    g_FreeTrainManageList.RemoveAll();

    CString title = "FreeTrainList 1.0";
    ar>>title;

    WORD Count = g_FreeTrainManageList.GetCount();
    ar>>Count;
    
    for(int no=0;no<Count;no++)
    {
      struct TagFreeTrainStruct *pFreeTrain = new TagFreeTrainStruct;
      g_FreeTrainManageList.AddTail(pFreeTrain);
      ar>>pFreeTrain->InFeederUnitID;
      ar>>pFreeTrain->OutFeederUnitID;
      ar>>pFreeTrain->AverCurrent;
      ar>>pFreeTrain->AverAngle;
      ar>>pFreeTrain->CurrentChangeRate;
      ar>>pFreeTrain->InContinuedSeconds;
      ar>>pFreeTrain->ChangeContinuedSeconds;
      ar>>pFreeTrain->OutContinuedSeconds;
      ar>>pFreeTrain->StartupDelaySecond;
      CString InCurrentChangeRateList;
      CString OutCurrentChangeRateList;
      ar>>InCurrentChangeRateList;
      ar>>OutCurrentChangeRateList;
      strcpy(pFreeTrain->InCurrentChangeRateList,InCurrentChangeRateList.GetBuffer(0));
      strcpy(pFreeTrain->OutCurrentChangeRateList,OutCurrentChangeRateList.GetBuffer(0));
      ar>>g_SetCheck[no];
    }

    ar.Flush();
    ar.Close();
    file.Close();
  }	

  return TRUE;
}
Ejemplo n.º 2
0
void CInfGame::SetGlobals(CPtrList &list)
{
	INF_GAME_GLOBAL *pGlobal;
	POSITION pos = m_plGlobals.GetHeadPosition();
	while(pos)
	{
		pGlobal = (INF_GAME_GLOBAL*)m_plGlobals.GetNext(pos);
		delete pGlobal;
	}
	m_plGlobals.RemoveAll();

	pos = list.GetHeadPosition();
	while(pos)
	{
		pGlobal = (INF_GAME_GLOBAL*)list.GetNext(pos);
		m_plGlobals.AddTail(pGlobal);
	}
	m_infGame.dwGlobalVarCount = m_plGlobals.GetCount();

	list.RemoveAll();
}
Ejemplo n.º 3
0
/*-----------------------------------------------------------------
【函数介绍】:  关闭TCP服务
【入口参数】:  (无)
【出口参数】:  (无)
【返回  值】:  <=0:关闭TCP服务失败; =1:关闭TCP服务成功
------------------------------------------------------------------*/
int CTCPServer_CE::Close()
{
	//结束通讯线程
	SetEvent(m_exitThreadEvent);
	//等待1秒,如果读线程没有退出,则强制退出
	if (WaitForSingleObject(m_serverThreadHandle,1000) == WAIT_TIMEOUT)
	{
		TerminateThread(m_serverThreadHandle,0);
		TRACE(L"强制终止服务器端线程\n");
	}
	m_serverThreadHandle = NULL;
	//关闭Socket,释放资源
	int err = closesocket(m_ServerSocket);
	if (err == SOCKET_ERROR)
	{
		return -1;
	}

	//首先,关闭与所有客户端连接
	POSITION pos = m_ListClientSocket.GetHeadPosition();
	while (pos != NULL)
	{
		//得到客户端对象
        CTCPCustom_CE *pTcpCustom = (CTCPCustom_CE*)m_ListClientSocket.GetNext(pos);
		if (!pTcpCustom->Close())
		{
			TRACE(L"关闭客户端socket错误");
		}

		//释放内存
		delete pTcpCustom;
		pTcpCustom = NULL;
	}

	m_ListClientSocket.RemoveAll();
	
	WSACleanup();
	return 1;
}   
Ejemplo n.º 4
0
void CInfCreature::SetAffects(CPtrList &list)
{
	INF_AFF *pAff;
	POSITION posPrev;
	POSITION pos = m_plAffects.GetHeadPosition();
	while(pos)
	{
		posPrev = pos;
		pAff = (INF_AFF*)m_plAffects.GetNext(pos);

		// Delete all the affects except those handled elsewhere.
		if (pAff->dwAffectType == AFF_TYPE_PROF ||	
			 (pAff->dwAffectType == AFF_TYPE_SPELL && !strnicmp(pAff->chResRef3,"SPCL812",7))
			)
			continue;

		delete pAff;
		m_plAffects.RemoveAt(posPrev);
		m_infCre.dwAffectCount--;
		if (m_infCre.dwAffectCount < 0)
			m_infCre.dwAffectCount = 0;

		pos = m_plAffects.GetHeadPosition();
	}

	pos = list.GetHeadPosition();
	while(pos)
	{
		pAff = (INF_AFF*)list.GetNext(pos);

		m_plAffects.AddTail(pAff);
		m_infCre.dwAffectCount++;
	}

	list.RemoveAll();
}
Ejemplo n.º 5
0
void CedExporter::CreateExport(CeMap* cedFile)
{
	//CleanObjectLists(cedFile);
	//return;

	// Ensure root folders exist (methods will quietly fail if folders are already there)
	CreateDirectory("C:\\Backsight", 0);
	CreateDirectory("C:\\Backsight\\index", 0);

	// Ensure the export has not been done already by looking for an existing index entry
	LPCTSTR mapName = cedFile->GetFileName();
	CString indexFileName;
	indexFileName.Format("C:\\Backsight\\index\\%s.txt", mapName);
	CFileStatus fileStatus;
	if (CFile::GetStatus((LPCTSTR)indexFileName, fileStatus))
	{
		AfxMessageBox("Map has been exported previously");
		return;
	}

	IdFactory idFactory;
	CPtrArray items;

	// Generate a GUID for the project
	CString guid;
	FillGuidString(guid);

	// Record the current computer name
	CString machineName;
	FillComputerName(machineName);

	// Create the new project event (assuming UTM zone 14 on NAD83)
	CTime now = CTime::GetCurrentTime();
	int layerId = 10; // Survey layer
	items.Add(new NewProjectEvent_c(idFactory, now, (LPCTSTR)guid, mapName, layerId, "UTM83-14", "CEdit", (LPCTSTR)machineName));

	// Invent a pseudo-session to enclose all ID allocations (and any other stuff)
	items.Add(new NewSessionEvent_c(idFactory, now, "CEdit", ""));

	CeIdManager* idMan = CeIdHandle::GetIdManager();
	unsigned int nGroup = idMan->GetNumGroup();

	for (unsigned int i=0; i<nGroup; i++)
	{
		const CeIdGroup* group = idMan->GetpGroup(i);
		int groupId = idFactory.GetGroupId(group->GetGroupName());
		const CPtrList& ranges = group->GetIdRanges();

		POSITION pos = ranges.GetHeadPosition();
		while ( pos )
		{
			CeIdRange* range = (CeIdRange*)ranges.GetNext(pos);
			items.Add(new IdAllocation_c(idFactory, now, groupId, range->GetMin(), range->GetMax()));
		}
	}

	// Produce a definitive (correct) list of the features created
	// be each edit. This aims to overcome a defect in the lists associated
	// with CeImport edits (and perhaps other edits).
	idFactory.GenerateOperationFeatureLists(cedFile);
	
	// Generate any points that will be needed for line ends (whereas CEdit would let you have lines without
	// an end point, Backsight requires them)
	ImportOperation_c* extra = new ImportOperation_c(idFactory, now);
	GenerateExtraPoints(cedFile, idFactory, extra->Features);
	//AfxMessageBox("done extra points");

	// Represent the points as an import operation
	if (extra->Features.GetSize() == 0)
		delete extra;
	else
		items.Add(extra);

	items.Add(new EndSessionEvent_c(idFactory, now));

	// Now loop through each session (but ignore empty sessions).
	CPSEPtrList& sessions = cedFile->GetSessions();
	POSITION spos = sessions.GetHeadPosition();
	int totop = 0;

	while (spos != 0)
	{
		CeSession* session = (CeSession*)sessions.GetNext(spos);
		const CPSEPtrList& ops = session->GetOperations();
		int nop = ops.GetCount();
		totop += nop;

		if (nop > 0)
		{
			// Append the NewSessionEvent
			CTime startTime(session->GetStart().GetTimeValue());
			CTime endTime(session->GetEnd().GetTimeValue());
			items.Add(new NewSessionEvent_c(idFactory, startTime, (LPCTSTR)session->GetpWho()->GetpWho(), ""));

			// Figure out the average time between successive edits (treat the end session event as an "edit")
			LONG sessionSecs = (endTime - startTime).GetTotalSeconds();
			LONG secsPerEdit = sessionSecs / (nop + 2);

			POSITION opos = ops.GetHeadPosition();
			for (int i=0; i<nop; i++)
			{
				CeOperation* op = (CeOperation*)ops.GetNext(opos);
				LONG secs = (i+1) * secsPerEdit;
				CTimeSpan delta(0,0,0, secs);
				CTime when = startTime + delta;
				AppendExportItems(when, *op, idFactory, items);
			}

			// Append the end session event
			items.Add(new EndSessionEvent_c(idFactory, endTime));
		}
	}

	// Clear the lists of features associated with each edit
	idFactory.ClearOperationFeatureLists();

	// test
	CString t;
	t.Format("Number of edits=%d", totop);
	AfxMessageBox(t);
	//return;

	// Create the project folder
	CString projectFolder;
	projectFolder.Format("C:\\Backsight\\%s", (LPCTSTR)guid);
	CreateDirectory((LPCTSTR)projectFolder, 0);

	// Produce the output file
	unsigned int maxId = idFactory.GetNextId();
	CString fileName;
	fileName.Format("%s\\%u.txt", (LPCTSTR)projectFolder, maxId);

	FILE* fp = fopen((LPCTSTR)fileName, "w");
	TextEditWriter* tw = new TextEditWriter(fp);
	EditSerializer* es = new EditSerializer(idFactory, *tw);

	for (int ix=0; ix<items.GetSize(); ix++)
	{
		Persistent_c* p = (Persistent_c*)items.GetAt(ix);
		es->WritePersistent(DataField_Edit, *p);
	}

	delete es;
	delete tw;
	fclose(fp);

	// Write the index entry file
	fp = fopen((LPCTSTR)indexFileName, "w");
	fprintf(fp, "%s", (LPCTSTR)guid);
	fclose(fp);
	
	// Write point positions file
	CString ptsFileName;
	ptsFileName.Format("%s\\%s.pts", (LPCTSTR)projectFolder, mapName);
	idFactory.WritePointsFile((LPCTSTR)ptsFileName);

	// Remove the export objects
	for (int ip=0; ip<items.GetSize(); ip++)
	{
		Persistent_c* p = (Persistent_c*)items.GetAt(ip);
		delete p;
	}

	// Dump out attributes...

	// Obtain the mapping from schema to output file extension (for consistency with
	// current data distributions done by GeoManitoba).
	CeExportTypeUtil xt;
	int rcode = xt.Load();
	if ( rcode < 0 )
	{
		CString msg;
		xt.GetLoadMessage(msg,rcode);
		AfxMessageBox(msg);
		return;
	}

	// Collect the IDs
	CPtrList ids;
	cedFile->GetIds(ids);

	// Collect the rows attached to the IDs
	CPtrList rows;
	CeTableEx::CollectRows(rows, ids);

	// Group by table. Then dispense with the list of pointers to rows.
	CPtrList tables;
	CeTableEx::BinRows(tables, rows);
	rows.RemoveAll();

	// Go through each bin, exporting the info to an output text file.	
	POSITION pos = tables.GetHeadPosition();
	CString tableFileName;

	while ( pos )
	{
		CeTableEx* pTable = (CeTableEx*)tables.GetNext(pos);

		// Determine the name of the output file (based on the name of the schema)
		const CeSchema& schema = pTable->GetSchema();
		tableFileName.Format("%s\\%s-%s.txt", (LPCTSTR)projectFolder, mapName, xt.GetFileType(schema));

		// Write out the attributes
		pTable->Export((LPCTSTR)tableFileName);
		delete pTable;
	}

	// Remove pointers to the tables (now deleted).
	tables.RemoveAll();
}
/////////////////////////////////////////////////////////
// Demonstrate:
// IADsPropertyList::GetPropertyItem
// IADsPropertyEntry
//
void CDlgIADsPropertyList::OnGet()
{

    HRESULT hr;
    CString s;
    BSTR    bstr;
    VARIANT var;
    IDispatch *pDispatch;
    IADsPropertyEntry *pEntry;
    IADsPropertyValue *pValue;
    LONG  lADsType;


    UpdateData(TRUE);
    m_cValueList.ResetContent();

    bstr = m_sAttribute.AllocSysString();
    hr = m_pPropList->GetPropertyItem( bstr, m_cADsType.GetCurSel()+1, &var );
    SysFreeString( bstr );


    if ( SUCCEEDED(hr) )
    {
        pDispatch = V_DISPATCH( &var );
        hr = pDispatch->QueryInterface( IID_IADsPropertyEntry, (void**) &pEntry );
        VariantClear( &var );

        // IADsPropertyEntry
        if ( SUCCEEDED(hr) )
        {
            CPtrList dList;

            // get_Values return array of VT_DISPATH
            hr = pEntry->get_Values( &var );


            pEntry->get_ADsType( &lADsType);

            hr = VariantToPtrList( var, dList );

            pEntry->Release();

            ////////////////////////////
            // IADsPropertyValue
            /////////////////////////////
            if ( SUCCEEDED(hr) )
            {
                POSITION pos;
                pos = dList.GetHeadPosition();
                while ( pos != NULL )
                {
                    pDispatch = (IDispatch*) dList.GetAt(pos);
                    hr = pDispatch->QueryInterface( IID_IADsPropertyValue, (void**) &pValue );

                    if ( SUCCEEDED(hr) )
                    {
                        pValue->AddRef();
                        hr = PropertyValueToString( lADsType, pValue, s );
                        m_cValueList.AddString( s );
                        pValue->Release();
                    }
                    dList.GetNext(pos);
                }

            }

            dList.RemoveAll();
            VariantClear(&var);

        }

    }
}