private void ProcessPersonStem(TVPerson person, TVPerson relative, TVPersonType type) { try { if (person == null) { return; } if (person.Stem == null && (type == TVPersonType.Patriarch || type == TVPersonType.Child)) { person.Stem = new TVStem(); fStems.Add(person.Stem); } switch (type) { case TVPersonType.Spouse: relative.Stem.AddSpouse(person); break; case TVPersonType.Child: relative.Stem.AddChild(person); break; case TVPersonType.Patriarch: break; } } catch (Exception ex) { Logger.LogWrite("TreeVizControl.ProcessPersonStem(): " + ex.Message); } }
private void DrawPerson(TVPerson person) { if (person == null || !person.IsVisible) { return; } try { int endYear = (fCurYear < person.DeathYear) ? fCurYear : person.DeathYear; float zBirth, zDeath; zBirth = fYearSize * (person.BirthYear - fMinYear); zDeath = fYearSize * (endYear - fMinYear); PointF ppt = person.Pt; OpenGL.glPushName(OBJ_NODE + (uint)person.Idx); OpenGL.glPushMatrix(); SetLineColor(person.Sex); OpenGL.glBegin(OpenGL.GL_LINES); OpenGL.glVertex3f(ppt.X, ppt.Y, zBirth); OpenGL.glVertex3f(ppt.X, ppt.Y, zDeath); OpenGL.glEnd(); OpenGL.glPopMatrix(); OpenGL.glPopName(); if (fDebug && person.Type == TVPersonType.Patriarch) { OpenGL.glPushMatrix(); OpenGL.glTranslatef(ppt.X, ppt.Y, 0); OpenGL.glColor3f(0.9F, 0.1F, 0.1F); DrawCircle(person.BaseRadius); OpenGL.glPopMatrix(); } if (person.Parent != null) { PointF parentPt = person.Parent.Pt; OpenGL.glPushMatrix(); SetLineColor(person.Sex); OpenGL.glBegin(OpenGL.GL_LINES); OpenGL.glVertex3f(parentPt.X, parentPt.Y, zBirth); OpenGL.glVertex3f(ppt.X, ppt.Y, zBirth); OpenGL.glEnd(); OpenGL.glPopMatrix(); } } catch (Exception ex) { Logger.LogWrite("TreeVizControl.DrawPerson(): " + ex.Message); } }
private TVPerson PreparePerson(TVPerson parent, GEDCOMIndividualRecord iRec, TVPersonType type) { try { TVPerson result; if (fPersonsIndex.TryGetValue(iRec.XRef, out result)) { // the person is already in the general index; so this is someone's spouse in another tree previously processed if (parent == null) { // parent == null, if this is patriarch or someone's spouse without his parents // if it's a spouse and is already in the index - therefore, // this person was married with the delegates of two different genera that are processed through their patriarchs? } else { result.Parent = parent; PointF prevPt = result.Stem.Pt; PointF parentPt = parent.Pt; PointF midpoint = GetLineMidpoint(prevPt.X, prevPt.Y, parentPt.X, parentPt.Y); result.Stem.Pt = midpoint; result.Stem.Update(); } return(null); } else { result = new TVPerson(parent, iRec); result.Type = type; fPersons.Add(result); fPersonsIndex.Add(iRec.XRef, result); result.BirthYear = fBase.Context.FindBirthYear(iRec); result.DeathYear = fBase.Context.FindDeathYear(iRec); // FIXME: alter to the pre-statistically a certain life expectancy if (result.DeathYear == 0) { result.DeathYear = result.BirthYear + 75; } } return(result); } catch (Exception ex) { Logger.LogWrite("TreeVizControl.PreparePerson(): " + ex.Message); return(null); } }
public TVPerson(TVPerson parent, GEDCOMIndividualRecord iRec) { Idx = NextIdx++; Parent = parent; IRec = iRec; Sex = iRec.Sex; Spouses = new List <TVPerson>(); Childs = new List <TVPerson>(); BeautySpouses = random.Next(0, 360); BeautyChilds = random.Next(0, 360); }
public void AddSpouse(TVPerson spouse) { // first item if (Spouses.Count == 0) { BaseRadius = spouse.BaseRadius; GenSlice = spouse.GenSlice; Pt = spouse.Pt; } spouse.Stem = this; Spouses.Add(spouse); }
private bool IsVisible(TVPerson person) { if (person == null) { return(false); } if (person.BirthYear > fCurYear) { return(false); } // not to display a person for which auto-detection of dates to no avail return(person.BirthYear >= fMinYear && person.DeathYear >= fMinYear); }
public void Update() { // to recalculate the coordinates of the spouses, because the coordinates of this person could change // "genSlice / 3" - it's radius of spouses PointF[] pts = TreeVizControl.GetCirclePoints(BeautySpouses, Pt, Spouses.Count, GenSlice / 3); for (int i = 0, count = Spouses.Count; i < count; i++) { TVPerson spp = Spouses[i]; spp.Pt = pts[i]; } // recalculate coordinates of visible children pts = TreeVizControl.GetCirclePoints(BeautyChilds, Pt, Childs.Count, BaseRadius / 2); for (int i = 0, count = Childs.Count; i < count; i++) { TVPerson chp = Childs[i]; chp.Pt = pts[i]; } }
private void RecalcDescendants(TVPerson person) { try { // recalculate the coordinates of the spouses, because the coordinates of this person could change // "genSlice / 3" - it's radius of spouses PointF[] pts = GetCirclePoints(person.BeautySpouses, person.Pt, person.Spouses.Count, person.GenSlice / 3); for (int i = 0, count = person.Spouses.Count; i < count; i++) { TVPerson spp = person.Spouses[i]; if (IsVisible(spp)) { spp.IsVisible = true; person.Spouses[i].Pt = pts[i]; } } // recalculate of coordinates of visible children pts = GetCirclePoints(person.BeautyChilds, person.Pt, person.Childs.Count, person.BaseRadius / 2); for (int i = 0, count = person.Childs.Count; i < count; i++) { TVPerson chp = person.Childs[i]; if (!chp.IsVisible && IsVisible(chp)) { chp.IsVisible = true; } if (chp.IsVisible) { chp.Pt = pts[i]; chp.BaseRadius = (float)((person.BaseRadius / 2) * 0.95); chp.DescGenerations = person.DescGenerations - 1; RecalcDescendants(chp); } } } catch (Exception ex) { Logger.LogWrite("TreeVizControl.recalcDescendants.2(): " + ex.Message); } }
public override void glDraw() { try { OpenGL.glClear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); OpenGL.glLoadIdentity(); OpenGL.glInitNames(); OpenGL.glTranslatef(0.0f, 0.0f, z); OpenGL.glRotatef(xrot, 1.0f, 0.0f, 0.0f); OpenGL.glRotatef(yrot, 0.0f, 1.0f, 0.0f); OpenGL.glRotatef(zrot, 0.0f, 0.0f, 1.0f); DrawAxis(); // FIXME: labels of centuries are displayed from the beginning a personalized timeline, // need to alter the output according to chronological ages for (int i = 0; i <= 5; i++) { OpenGL.glPushMatrix(); OpenGL.glTranslatef(0, 0, i * 100 * fYearSize); OpenGL.glColor3f(0.9F, 0.1F, 0.1F); DrawCircle(0.1F); OpenGL.glPopMatrix(); } DrawArborSystem(); int num = fPersons.Count; for (int i = 0; i < num; i++) { TVPerson prs = fPersons[i]; DrawPerson(prs); } } catch (Exception ex) { Logger.LogWrite("TreeVizControl.glDraw(): " + ex.Message); } }
public void AddChild(TVPerson child) { child.Stem = this; Childs.Add(child); }
private void PrepareDescendants(TVPerson person) { if (person == null) { return; } try { int gens = (person.DescGenerations <= 0) ? 1 : person.DescGenerations; person.GenSlice = person.BaseRadius / gens; // ? GEDCOMIndividualRecord iRec = person.IRec; foreach (GEDCOMSpouseToFamilyLink spLink in iRec.SpouseToFamilyLinks) { GEDCOMFamilyRecord famRec = spLink.Family; bool alreadyPrepared = false; // processing the spouse of the current person GEDCOMIndividualRecord spouse = famRec.GetSpouseBy(iRec); if (spouse != null) { TVPerson sps = PreparePerson(null, spouse, TVPersonType.Spouse); if (sps == null) { // this can occur only when processing of the patriarchs later than those already processed, // i.e. if the at first was already processed the patriarch, born in 1710, was processed his childrens // and one of theirs spouses being a patriarch of new branches! Logger.LogWrite("TreeVizControl.PrepareDescendants(): an unexpected collision"); alreadyPrepared = true; } else { ProcessPersonStem(sps, person, TVPersonType.Spouse); person.Spouses.Add(sps); } } if (!alreadyPrepared) { // processing children of the current family foreach (GEDCOMPointer childPtr in famRec.Children) { GEDCOMIndividualRecord child = (GEDCOMIndividualRecord)childPtr.Value; // exclude childless branches if (EXCLUDE_CHILDLESS && (fBase.Context.IsChildless(child) || child.GetTotalChildsCount() < 1)) { continue; } TVPerson chp = PreparePerson(person, child, TVPersonType.Child); if (chp == null) { // this is someone spouse and already prepared, intersection of branches Logger.LogWrite("TreeVizControl.PrepareDescendants(): intersection"); } else { chp.BaseRadius = (float)((person.BaseRadius / 2) * 0.95); chp.DescGenerations = person.DescGenerations - 1; ProcessPersonStem(chp, person, TVPersonType.Child); person.Childs.Add(chp); PrepareDescendants(chp); } } } } } catch (Exception ex) { Logger.LogWrite("TreeVizControl.PrepareDescendants(): " + ex.Message); } }
public void OnArborStop(object sender, EventArgs eArgs) { FreeRotate = false; fMinYear = 0; try { // load from ArborSystem points and signatures of the patriarchs foreach (ArborNode node in fSys.Nodes) { PatriarchObj patObj = (PatriarchObj)node.Data; GEDCOMIndividualRecord iRec = (GEDCOMIndividualRecord)fBase.Context.Tree.XRefIndex_Find(node.Sign); int descGens = patObj.DescGenerations; TVPerson patr = PreparePerson(null, iRec, TVPersonType.Patriarch); if (patr != null) { patr.Pt = new PointF((float)node.Pt.X * MAGIC_SCALE, (float)node.Pt.Y * MAGIC_SCALE); patr.DescGenerations = descGens; patr.BaseRadius = 100; ProcessPersonStem(patr, null, TVPersonType.Patriarch); if (fMinYear == 0) { fMinYear = patr.BirthYear; } else { if (fMinYear > patr.BirthYear) { fMinYear = patr.BirthYear; } } } } // prepare the radii of the bases of the patriarchs foreach (ArborEdge edge in fSys.Edges) { TVPerson srcPers = FindPersonByXRef(edge.Source.Sign); TVPerson tgtPers = FindPersonByXRef(edge.Target.Sign); if (srcPers == null || tgtPers == null) { continue; } float rad = (float)Dist(srcPers.Pt, tgtPers.Pt) * 3 / 7; if (srcPers.BaseRadius > rad) { srcPers.BaseRadius = rad; } if (tgtPers.BaseRadius > rad) { tgtPers.BaseRadius = rad; } } // prepare the range of years fMaxYear = DateTime.Now.Year; fYearSize = BASE_SCALE / (fMaxYear - fMinYear); fTick = 0; fCurYear = fMinYear; // prepare tree, the base number - only the patriarchs int count = fPersons.Count; for (int i = 0; i < count; i++) { TVPerson prs = fPersons[i]; PrepareDescendants(prs); } for (int i = 0; i < fStems.Count; i++) { TVStem stem = fStems[i]; stem.Update(); } StartTimer(); } catch (Exception ex) { Logger.LogWrite("TreeVizControl.onArborStop(): " + ex.Message); } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (fMouseDrag) { int dx = e.X - fLastX; int dy = e.Y - fLastY; if (fFreeRotate) { //xrot += 0.001f * dy; //yrot += 0.001f * dx; xrot += 0.001f * dy; //ok zrot += 0.001f * dx; //ok } else { zrot += 0.001f * dx; } } else { uint objectId = retrieveObjectId(e.X, e.Y); switch (objectId) { case OBJ_X: SelectedObject = "X-axis"; break; case OBJ_Y: SelectedObject = "Y-axis"; break; case OBJ_Z: SelectedObject = "Z-axis"; break; default: if (objectId >= OBJ_NODE) { int id = (int)(objectId - OBJ_NODE); TVPerson prs = FindPersonByIdx(id); if (prs != null) { SelectedObject = "[" + prs.IRec.XRef + "] " + prs.IRec.GetPrimaryFullName() + ", " + prs.BirthYear.ToString() + " - " + prs.DeathYear.ToString(); } else { SelectedObject = "<none>"; } } else { SelectedObject = "<none>"; } break; } } }