private static void PL_WalkDescLinks(GDMTree tree, Graph graph, GKVarCache <GDMFamilyRecord, PGNode> pgNodes, PGNode prevNode, GDMIndividualRecord ancestor) { for (int i = 0, count = ancestor.SpouseToFamilyLinks.Count; i < count; i++) { var family = tree.GetPtrValue(ancestor.SpouseToFamilyLinks[i]); var node = pgNodes[family]; if (node != null && node.Type != PGNodeType.Default) { Vertex vtx = graph.FindVertex(node.FamilyXRef); if (vtx == null) { vtx = graph.AddVertex(node.FamilyXRef, node); } if (prevNode != null) { graph.AddDirectedEdge(prevNode.FamilyXRef, node.FamilyXRef, 1, null); } prevNode = node; } for (int k = 0, count2 = family.Children.Count; k < count2; k++) { GDMIndividualRecord child = tree.GetPtrValue(family.Children[k]); PL_WalkDescLinks(tree, graph, pgNodes, prevNode, child); } } }
private void TryRenderTreeSlice(ITreeChart treeBox, int index, GDMIndividualRecord currentPatriarch) { IndiObj indi = fIndiQueue[index]; fProcessed.Add(indi.IRec.XRef); int depthLimit = 3; float scaleFactor = 1.0f; int tries = 0; RenderStage stage = RenderStage.Normal; while (true) { treeBox.Model.DepthLimit = depthLimit; treeBox.Model.Scale = scaleFactor; treeBox.GenChart(indi.IRec, indi.TreeKind, false); tries += 1; ExtSize imageSize = treeBox.GetImageSize(); var sf = GfxHelper.ZoomToFit(imageSize.Width, imageSize.Height, fPageSize.GetWidth(), fPageSize.GetHeight()); if (sf < 1.0f) { // need to reduce image's size switch (stage) { case RenderStage.Normal: depthLimit -= 1; stage = RenderStage.Shrink; break; case RenderStage.Grow: depthLimit -= 1; stage = RenderStage.Break; break; case RenderStage.Shrink: scaleFactor = sf; stage = RenderStage.Break; break; } } else if (sf > 1.0f) { // need to increase image's size switch (stage) { case RenderStage.Normal: case RenderStage.Grow: depthLimit += 1; stage = RenderStage.Grow; break; case RenderStage.Shrink: scaleFactor = sf; stage = RenderStage.Break; break; } } if (stage == RenderStage.Break || tries > 10) { break; } } scaleFactor = Math.Min(1.0f, scaleFactor); treeBox.Model.DepthLimit = depthLimit; treeBox.Model.Scale = scaleFactor; treeBox.GenChart(indi.IRec, indi.TreeKind, false); treeBox.RenderImage(RenderTarget.Printer, true); var indiNums = new GKVarCache <GDMIndividualRecord, int>(); for (int i = 0; i < treeBox.Model.Persons.Count; i++) { TreeChartPerson person = treeBox.Model.Persons[i]; GDMIndividualRecord indiRec = person.Rec; if (indiRec == null) { continue; } int iNum = indiNums[indiRec]; var offset = treeBox.Model.GetOffsets(); int ix = offset.X + person.Rect.Left; int iy = offset.Y + person.Rect.Top - (int)fTextFont.Size; string iRef = indiRec.XRef + "#" + iNum; fRenderer.DrawAnchor(iRef, iRef, fTextFont, null, ix, iy); iNum += 1; indiNums[indiRec] = iNum; if (!person.CanExpand) { continue; } ix = offset.X + person.Rect.Left; iy = offset.Y + person.Rect.Bottom; iRef = indiRec.XRef + "#" + iNum; fRenderer.DrawHyperlink(iRef, iRef, fLinkFont, null, ix, iy); if (person.HasFlag(PersonFlag.pfAncWalk)) { if (person.HasFlag(PersonFlag.pfHasInvAnc) && !IsPatriarchsDescendant(indiRec, currentPatriarch)) { CheckQueue(indiRec, TreeChartKind.ckAncestors); } } else if (person.HasFlag(PersonFlag.pfDescWalk)) { if (person.HasFlag(PersonFlag.pfSpouse)) { if (person.HasFlag(PersonFlag.pfHasInvAnc) && !IsPatriarchsDescendant(indiRec, currentPatriarch)) { CheckQueue(indiRec, TreeChartKind.ckAncestors); } } else { if (person.HasFlag(PersonFlag.pfHasInvDesc) && TreeTools.PL_SearchAnc(fTree, indiRec, currentPatriarch, true)) { CheckQueue(indiRec, TreeChartKind.ckDescendants); } } } } }
public static Graph GetPatriarchsGraph(IBaseContext context, int gensMin, bool datesCheck, bool loneSuppress) { Graph graph = new Graph(); try { using (ExtList <PatriarchObj> patList = GetPatriarchsList(context, gensMin, datesCheck)) { var pgNodes = new GKVarCache <GDMFamilyRecord, PGNode>(); // prepare int count = patList.Count; for (int i = 0; i < count; i++) { PatriarchObj patNode = patList[i]; GDMIndividualRecord iRec = patNode.IRec; int count2 = iRec.SpouseToFamilyLinks.Count; for (int k = 0; k < count2; k++) { GDMFamilyRecord family = context.Tree.GetPtrValue(iRec.SpouseToFamilyLinks[k]); pgNodes[family] = new PGNode(family.XRef, PGNodeType.Patriarch, patNode.DescGenerations); } } IProgressController progress = AppHost.Progress; try { int patCount = patList.Count; progress.ProgressInit(LangMan.LS(LSID.LSID_LinksSearch), patCount); for (int i = 0; i < patCount; i++) { PatriarchObj patr = patList[i]; for (int j = i + 1; j < patCount; j++) { PatriarchObj patr2 = patList[j]; GDMFamilyRecord cross = TreeTools.PL_SearchIntersection(context.Tree, patr.IRec, patr2.IRec); if (cross != null) { var node = pgNodes[cross]; if (node != null && node.Type == PGNodeType.Patriarch) { // dummy } else { int size = GKUtils.GetDescGenerations(context.Tree, context.Tree.GetPtrValue(cross.Husband)); if (size == 0) { size = 1; } pgNodes[cross] = new PGNode(cross.XRef, PGNodeType.Intersection, size); } } } progress.ProgressStep(); } } finally { progress.ProgressDone(); } // create graph int count3 = patList.Count; for (int i = 0; i < count3; i++) { PatriarchObj patNode = patList[i]; PL_WalkDescLinks(context.Tree, graph, pgNodes, null, patNode.IRec); } /*if (gpl_params.aLoneSuppress) { * for (int i = aList.Count - 1; i >= 0; i--) { * PatriarchObj patr = aList[i] as PatriarchObj; * if (patr.ILinks.Count == 0) aList.Delete(i); * } * aList.Pack();*/ } } catch (Exception ex) { Logger.WriteError("PatriarchsMan.GetPatriarchsGraph()", ex); } return(graph); }