void CRepositoryBrowser::Refresh()
{
	BeginWaitCursor();
	if (m_nExternalOvl >= 0)
		SYS_IMAGE_LIST().SetOverlayImage(m_nExternalOvl, OVERLAY_EXTERNAL);

	m_RepoTree.DeleteAllItems();
	m_RepoList.DeleteAllItems();
	m_TreeRoot.m_ShadowTree.clear();
	m_TreeRoot.m_sName = "";
	m_TreeRoot.m_bFolder = true;

	TVINSERTSTRUCT tvinsert = {0};
	tvinsert.hParent = TVI_ROOT;
	tvinsert.hInsertAfter = TVI_ROOT;
	tvinsert.itemex.mask = TVIF_DI_SETITEM | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
	tvinsert.itemex.pszText = L"/";
	tvinsert.itemex.lParam = (LPARAM)&m_TreeRoot;
	tvinsert.itemex.iImage = m_nIconFolder;
	tvinsert.itemex.iSelectedImage = m_nOpenIconFolder;
	m_TreeRoot.m_hTree= m_RepoTree.InsertItem(&tvinsert);

	ReadTree(&m_TreeRoot);
	m_RepoTree.Expand(m_TreeRoot.m_hTree, TVE_EXPAND);
	FillListCtrlForShadowTree(&m_TreeRoot);
	m_RepoTree.SelectItem(m_TreeRoot.m_hTree);
	EndWaitCursor();
}
Exemple #2
0
DirTree *DirTree_CreateFromFile(geVFile *File)
{
	DirTree *		Res;
	DirTree_Header	Header;
	long			StartPosition;
	long			EndPosition;
	
	if	(geVFile_Tell(File, &StartPosition) == GE_FALSE)
		return GE_FALSE;

	if	(geVFile_Read(File, &Header, sizeof(Header)) == GE_FALSE)
		return NULL;

	if	(Header.Signature != DIRTREE_FILE_SIGNATURE)
		return GE_FALSE;

	if	(ReadTree(File, &Res) == GE_FALSE)
		return NULL;

	geVFile_Tell(File, &EndPosition);
	if	(Header.Size != EndPosition - StartPosition)
	{
		DirTree_Destroy(Res);
		return NULL;
	}

	return Res;
}
void HuffmanProcessor::Decompress(char* input_filename)
{
    input = ifstream(input_filename, ios::binary);
    root = new Node();

    ReadTree(root);
}
Exemple #4
0
static bool ReadTree(LoaderState& State, const XMLObjectVector& vec)
{
	XMLObjectVector ret;
	bool success = true;
	for (auto& obj : vec)
		success &= loadObjectTree(State, obj, ret);
	if (!ret.empty())
		success &= ReadTree(State, ret);
	return success;
}
void CRepositoryBrowser::OnTvnItemExpandingRepoTree(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
	*pResult = 0;

	CShadowFilesTree* pTree = (CShadowFilesTree*)(m_RepoTree.GetItemData(pNMTreeView->itemNew.hItem));
	if (pTree == NULL)
	{
		ASSERT(FALSE);
		return;
	}

	if (!pTree->m_bLoaded)
	{
		pTree->m_bLoaded = true;
		ReadTree(pTree, pTree->GetFullName());
	}
}
Exemple #6
0
bool loadTree(LoaderState& State, const char * sceneName, std::vector<RLIGHT>& Lights)
{
	DMLog("loadTree %s\n", sceneName);

	XMLActor actor;
	XMLObjectVector ret;
	XMLLightVector lights;

	auto found = TryForEachPath(State.Paths, sceneName, [&](auto& Path) {
		return XMLParser::parseScene(Path.c_str(), actor, ret, &lights);
	});
	if (!found)
	{
		MLog("loadTree -- Failed to load %s\n", sceneName);
		return false;
	}
	else
		DMLog("loadTree -- loaded %s\n", sceneName);

	for (auto& srcLight : lights)
	{
		Lights.emplace_back();
		auto& dstLight = Lights.back();
		dstLight.Position = srcLight.Position;
		dstLight.Color = srcLight.Diffuse;
		dstLight.fAttnStart = srcLight.AttStart;
		dstLight.fAttnEnd = srcLight.AttEnd;
		dstLight.fIntensity = srcLight.Intensity;
		dstLight.Name = srcLight.Name;
	}

	DMLog("loadTree -- actor.isValid = %d\n", actor.isValid);
	if (actor.isValid)
	{
		if (!load(State, actor.eluName.c_str()))
		{
			MLog("loadTree(%s) -- Failed to load actor thing\n", sceneName);
		}
	}

	ReadTree(State, ret);

	return true;
}
Exemple #7
0
bool loadPropTree(LoaderState& State, const char * propName)
{
	DMLog("loadPropTree %s\n", propName);

	XMLObjectVector ret;

	auto found = TryForEachPath(State.Paths, propName, [&](auto& Path) {
		return XMLParser::parseProp(Path.c_str(), ret);
	});
	if (!found)
	{
		MLog("loadPropTree -- Failed to load %s\n", propName);
		return false;
	}

	ReadTree(State, ret);

	return true;
}
void CRepositoryBrowser::FillListCtrlForTreeNode(HTREEITEM treeNode)
{
	m_RepoList.DeleteAllItems();

	CShadowFilesTree* pTree = (CShadowFilesTree*)(m_RepoTree.GetItemData(treeNode));
	if (pTree == NULL)
	{
		ASSERT(FALSE);
		return;
	}

	CString url = _T("/") + pTree->GetFullName();
	GetDlgItem(IDC_REPOBROWSER_URL)->SetWindowText(url);

	if (!pTree->m_bLoaded)
	{
		pTree->m_bLoaded = true;
		ReadTree(pTree, pTree->GetFullName());
	}

	FillListCtrlForShadowTree(pTree);
}
Exemple #9
0
int main(int argc, char **argv)
{
	int i, j, k, treeNo, sumLength;
	char ch;
	TTree **treeSet;
	FILE *text_fv;
	clock_t totalStart;
	double totalSecs, scale, sum;
	char *ancestor;

	totalStart = clock();

	ReadParams(argc, argv);

	if (rateHetero == CodonRates && invariableSites) {
		fprintf(stderr, "Invariable sites model cannot be used with codon rate heterogeneity.\n");
		exit(4);
	}

	if (writeAncestors && fileFormat == NEXUSFormat) {
		fprintf(stderr, "Warning - When writing ancestral sequences, relaxed PHYLIP format is used.\n");
	}

	if (writeAncestors && maxPartitions > 1) {
		fprintf(stderr, "Writing ancestral sequences can only be used for a single partition.\n");
		exit(4);
	}
			
	if (!userSeed)
		randomSeed = CreateSeed();
		
	SetSeed(randomSeed);

	if (!quiet)
 		PrintTitle();
	
	numTrees = OpenTreeFile();

	/* if (!treeFile) { */
		ReadFileParams();
	/*} */


	if ((ancestorSeq>0 && !hasAlignment) || ancestorSeq>numSequences) {
		fprintf(stderr, "Bad ancestral sequence number: %d (%d sequences loaded)\n", ancestorSeq, numSequences);
		exit(4);
	}
	
	if (textFile) {
		if ( (text_fv=fopen(textFileName, "rt"))==NULL ) {
			fprintf(stderr, "Error opening text file for insertion into output: '%s'\n", textFileName);
			exit(4);
		}
	}

	ancestor=NULL;
	if (hasAlignment) {
		AllocateMemory();	
		ReadFile();
		
		if (numSites<0)
			numSites=numAlignmentSites;		
			
		if (ancestorSeq>0) {
			if (numSites!=numAlignmentSites) {
				fprintf(stderr, "Ancestral sequence is of a different length to the simulated sequences (%d)\n", numAlignmentSites);
				exit(4);
			}
			ancestor=sequences[ancestorSeq-1];
		}
	} else if (numSites<0)
		numSites=1000;
	
	SetModel(model);
	
	numTaxa=-1;
	scale=1.0;
	
	treeSet = (TTree **)malloc(sizeof(TTree **) * maxPartitions);
	if (treeSet==NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(5);
	}
	
	partitionLengths = (int *)malloc(sizeof(int) * maxPartitions);
	if (partitionLengths==NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(5);
	}
	
	partitionRates = (double *)malloc(sizeof(double) * maxPartitions);
	if (partitionRates==NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(5);
	}
	
	for (i = 0; i < maxPartitions; i++) {
		if ((treeSet[i]=NewTree())==NULL) {
			fprintf(stderr, "Out of memory\n");
			exit(5);
		}
	}
					
	CreateRates();
	
	treeNo=0;
	do {
		partitionLengths[0] = -1;
		ReadTree(tree_fv, treeSet[0], treeNo+1, 0, NULL, &partitionLengths[0], &partitionRates[0]);

		if (treeNo==0) {
			numTaxa=treeSet[0]->numTips;
			
			if (!quiet)
				fprintf(stderr, "Random number generator seed: %ld\n\n", randomSeed);
				
			if (fileFormat == NEXUSFormat) {
				fprintf(stdout, "#NEXUS\n");
				fprintf(stdout, "[\nGenerated by %s %s\n\n", PROGRAM_NAME, VERSION_NUMBER);
				PrintVerbose(stdout);
				fprintf(stdout, "]\n\n");
			}
		} else if (treeSet[0]->numTips != numTaxa) {
			fprintf(stderr, "All trees must have the same number of tips.\n");
			exit(4);
		}
		
		if (maxPartitions == 1) {
			if (partitionLengths[0] != -1) {
				fprintf(stderr, "\nWARNING: The treefile contained partion lengths but only one partition\n");
				fprintf(stderr, "was specified.\n");
			}
			partitionLengths[0] = numSites;
		}

		sumLength = partitionLengths[0];
		i = 1;
		while (sumLength < numSites && i <= maxPartitions) {
			if (!IsTreeAvail(tree_fv)) {
				fprintf(stderr, "\nA set of trees number %d had less partition length (%d) than\n", treeNo + 1, sumLength);
				fprintf(stderr, "was required to make a sequence of length %d.\n", numSites);
				exit(4);
			}
				
			ReadTree(tree_fv, treeSet[i], treeNo+1, treeSet[0]->numTips, treeSet[0]->names, 
						&partitionLengths[i], &partitionRates[i]);
						
			if (treeSet[i]->numTips != numTaxa) {
				fprintf(stderr, "All trees must have the same number of tips.\n");
				exit(4);
			}
			
			sumLength += partitionLengths[i];
			i++;
		}
		if (i > maxPartitions) {
			fprintf(stderr, "\nA set of trees number %d had more partitions (%d) than\n", treeNo + 1, i);
			fprintf(stderr, "was specified in the user options (%d).\n", maxPartitions);
		}
		numPartitions = i;
				
		if (sumLength != numSites) {
			fprintf(stderr, "The sum of the partition lengths in the treefile does not equal\n");
			fprintf(stderr, "the specified number of sites.\n");
			exit(4);
		}
			
		for (i = 0; i < numPartitions; i++)
			CreateSequences(treeSet[i], partitionLengths[i]);
		
		if (numPartitions > 1) {
			sum = 0.0;
			for (i = 0; i < numPartitions; i++)
				sum += partitionRates[i] * partitionLengths[i];
				
			for (i = 0; i < numPartitions; i++)
				partitionRates[i] *= numSites / sum;
		}
		
		if (treeNo==0 && verbose && !quiet) {
			PrintVerbose(stderr);
			InitProgressBar(numTrees*numDatasets);
			DrawProgressBar();
		}

		for (i=0; i<numDatasets; i++) {
			SetCategories();
			
			k = 0;
			for (j = 0; j < numPartitions; j++) {
				scale = partitionRates[j];
				
				if (scaleTrees) { 
					if (!treeSet[j]->rooted) {
						fprintf(stderr, "To scale tree length, they must be rooted and ultrametric.\n");
						exit(4);
					}
					scale *= treeScale/treeSet[j]->totalLength;
				} else if (scaleBranches)
					scale *= branchScale;

				EvolveSequences(treeSet[j], k, partitionLengths[j], scale, ancestor);
				k += partitionLengths[j];
			}
			
			if (writeAncestors)
				WriteAncestralSequences(stdout, treeSet[0]);
			else
				WriteSequences(stdout, (numTrees > 1 ? treeNo+1 : -1), (numDatasets > 1 ? i+1 : -1), treeSet, partitionLengths);

			if (writeRates) {
				WriteRates(stderr);
			}

			if (textFile) {
				while (!feof(text_fv)) {
					ch = fgetc(text_fv);
					if (!feof(text_fv))
						fputc(ch, stdout);
				}
				fputc('\n', stdout);
				rewind(text_fv);
			}
			
			if (verbose && !quiet)
				ProgressBar();
		}
				
		for (i = 0; i < numPartitions; i++)
			DisposeTree(treeSet[i]);
			
		treeNo++;
	} while (IsTreeAvail(tree_fv));
	
/*	for (i = 0; i < maxPartitions; i++)
		FreeTree(treeSet[i]);	*/
	
	if (treeFile)
		fclose(tree_fv);

	if (textFile)
		fclose(text_fv);

	totalSecs = (double)(clock() - totalStart) / CLOCKS_PER_SEC;
	if (!quiet) {
		fprintf(stderr, "Time taken: %G seconds\n", totalSecs);
		if (verboseMemory)
			fprintf(stderr, "Total memory used: %ld\n", totalMem);
	}
	
	return 0;
}
Exemple #10
0
static	geBoolean	ReadTree(geVFile *File, DirTree **TreePtr)
{
	int			Terminator;
	int			Length;
	DirTree *	Tree;

	if	(geVFile_Read(File, &Terminator, sizeof(Terminator)) == GE_FALSE)
		return GE_FALSE;

	if	(Terminator == DIRTREE_LIST_TERMINATED)
	{
		*TreePtr = NULL;
		return GE_TRUE;
	}

	Tree = geRam_Allocate(sizeof(*Tree));
	if	(!Tree)
		return GE_FALSE;
	memset(Tree, 0, sizeof(*Tree));

	// Read the name
	if	(geVFile_Read(File, &Length, sizeof(Length)) == GE_FALSE)
		goto fail;

	assert(Length > 0);
	Tree->Name = geRam_Allocate(Length);
	if	(!Tree->Name)
	{
		geRam_Free(Tree);
		return GE_FALSE;
	}
	
	if	(geVFile_Read(File, Tree->Name, Length) == GE_FALSE)
		goto fail;

//printf("Reading '%s'\n", Tree->Name);

	// Read out the attribute information
	if	(geVFile_Read(File, &Tree->Time, sizeof(Tree->Time)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->AttributeFlags, sizeof(Tree->AttributeFlags)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->Size, sizeof(Tree->Size)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->Offset, sizeof(Tree->Offset)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->Hints.HintDataLength, sizeof(Tree->Hints.HintDataLength)) == GE_FALSE)
		goto fail;

	if	(Tree->Hints.HintDataLength != 0)
	{
		Tree->Hints.HintData = geRam_Allocate(Tree->Hints.HintDataLength);
		if	(!Tree->Hints.HintData)
			goto fail;
		//bug fix. someone got copy happy and forgot to remove the & from Tree->Hints.HintData
		if	(geVFile_Read(File, Tree->Hints.HintData, Tree->Hints.HintDataLength) == GE_FALSE)
			goto fail;
	}

//printf("Reading children of '%s'\n", Tree->Name);
	// Read the children
	if	(ReadTree(File, &Tree->Children) == GE_FALSE)
		goto fail;

//printf("Reading siblings of '%s'\n", Tree->Name);
	// Read the Siblings
	if	(ReadTree(File, &Tree->Siblings) == GE_FALSE)
		goto fail;

//DirTree_Dump(Tree);

	*TreePtr = Tree;

	return GE_TRUE;

fail:
	DirTree_Destroy(Tree);
	return GE_FALSE;
}