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 void Test_TreeChartPerson() { using (TreeChartPerson tcPerson = new TreeChartPerson(null)) { Assert.IsNotNull(tcPerson); tcPerson.BuildBy(null); Assert.AreEqual(null, tcPerson.Rec); Assert.AreEqual(null, tcPerson.Portrait); Assert.AreEqual(0, tcPerson.PortraitWidth); tcPerson.Divorced = false; Assert.AreEqual(false, tcPerson.Divorced); tcPerson.Divorced = true; Assert.AreEqual(true, tcPerson.Divorced); tcPerson.IsDup = false; Assert.AreEqual(false, tcPerson.IsDup); tcPerson.IsDup = true; Assert.AreEqual(true, tcPerson.IsDup); Assert.AreEqual(0, tcPerson.Height); Assert.AreEqual(0, tcPerson.Width); tcPerson.IsDead = false; Assert.AreEqual(false, tcPerson.IsDead); tcPerson.IsDead = true; Assert.AreEqual(true, tcPerson.IsDead); Assert.AreEqual(0, tcPerson.PtX); tcPerson.PtX = 11; Assert.AreEqual(11, tcPerson.PtX); Assert.AreEqual(0, tcPerson.PtY); tcPerson.PtY = 22; Assert.AreEqual(22, tcPerson.PtY); tcPerson.Selected = false; Assert.AreEqual(false, tcPerson.Selected); tcPerson.Selected = true; Assert.AreEqual(true, tcPerson.Selected); Assert.AreEqual(GDMSex.svUnknown, tcPerson.Sex); tcPerson.Sex = GDMSex.svMale; Assert.AreEqual(GDMSex.svMale, tcPerson.Sex); EnumSet <SpecialUserRef> enums = tcPerson.Signs; Assert.IsTrue(enums.IsEmpty()); Assert.AreEqual(0, tcPerson.GetChildsCount()); Assert.AreEqual(0, tcPerson.GetSpousesCount()); TreeChartPerson child = new TreeChartPerson(null); tcPerson.AddChild(null); tcPerson.AddChild(child); Assert.AreEqual(1, tcPerson.GetChildsCount()); Assert.AreEqual(child, tcPerson.GetChild(0)); TreeChartPerson spouse = new TreeChartPerson(null); tcPerson.AddSpouse(null); tcPerson.AddSpouse(spouse); Assert.AreEqual(1, tcPerson.GetSpousesCount()); Assert.AreEqual(spouse, tcPerson.GetSpouse(0)); Assert.IsFalse(tcPerson.HasFlag(PersonFlag.pfDescWalk)); tcPerson.SetFlag(PersonFlag.pfDescWalk); Assert.IsTrue(tcPerson.HasFlag(PersonFlag.pfDescWalk)); tcPerson.BuildBy(null); ExtRect psnRt = tcPerson.Rect; Assert.IsTrue(psnRt.IsEmpty()); tcPerson.Sex = GDMSex.svMale; var color = ((ColorHandler)tcPerson.GetSelectedColor()).Handle; Assert.AreEqual(Color.FromArgb(255, Color.Blue), color); tcPerson.Sex = GDMSex.svFemale; color = ((ColorHandler)tcPerson.GetSelectedColor()).Handle; Assert.AreEqual(Color.FromArgb(255, Color.Red), color); tcPerson.Sex = GDMSex.svUnknown; color = ((ColorHandler)tcPerson.GetSelectedColor()).Handle; Assert.AreEqual(Color.FromArgb(255, Color.Black), color); } }