// twist.h // // The source files in the "Twist" group support the historical objects used by Twistory, abstracted from the GUI objects // // by John D. de Boer #include "common.h" #include "cstring.h" #include "cyber.h" #include "disk.h" #include "floating.h" #include "frame.h" #include "graph.h" #include "gui.h" #include "tapedeck.h" #include "vector.h" #include "view.h" #include "zoom.h" #include "calend.h" #include "polygon.h" #include "sphcoord.h" #include "sphpoly.h" // prototypes from tword.c void SpellCheck(const char *S, bool ExpectCap); void SaveDictionary(void); void InitDictionary(void); void PurgeDictionary(void); // Time enum { timeInval, // uninitialised or invalid date timeJD, // Julian date timeBegin, // always existed timeStill // still in existence }; typedef struct { short kind; // validity and enumeration of interval type long jd, // julian date unc; // uncertainty in days bool guess; // whether the date in memory is guessed, i.e. it is absent in the TTT file } Day; typedef struct { Day start, // beginning of time interval end; // end date of time interval (not zero-based: the actual day!) } Span; typedef struct { long jd1, // beginning of allowed date range jd2, // end of allowed date range jd, // current julian date dt; // number of days corresponding to half of a window's width short year, // current year month, // current month day, // current day year1, // beginning of allowed date range year2; // end of allowed date range } TimeGlobs; enum { stepDay=0,stepWeek,stepMonth,stepYear,stepDecade,stepCentury }; typedef struct { short running, // whether animation is going, and in which sense: -1, 0 or 1 unit, // enumeration of time step units: days, months or years speed, // enumeration of increment amounts incr; // number of either days, months or years in each step long days; // nominal number of days in each step Span intv; // the period between the current time and the next forward step } StepGlobs; // prototypes from twhen.c void InitDay(Day *D); void InitSpan(Span *S); bool DatesEqual(const Day *A, const Day *B); bool DatesInOrder(const Day *A, const Day *B, bool Unc); bool DatesInStrictOrder(const Day *A, const Day *B, bool Unc); bool ZeroSpan(const Span *S); bool DateInSpan(const Day *D, const Span *S, bool Unc); bool SpansOverlap(const Span *A, const Span *B, bool Unc); void StretchSpanToDate(Span *Sp, const Day *D); void SpanIntersection(const Span *A, const Span *B, Span *In); void SpanUnion(const Span *A, const Span *B, Span *Un); void StartAnim(void); void StopAnim(void); void ReverseAnim(void); void SetStep(int UNIT, int SPEED); // for twayitwas.c void Slower(bool Much); void Faster(bool Much); void NearestStepSize(real DT); void TimeSteps(int N); void GoToYear(int YEAR); void GoToJD(long JD); void InitTimeBounds(void); void StretchBoundsToSpan(const Span *S); void InitTime(void); string DateStr(const Day *D, bool EraIfBC, bool ForceEra, bool Circa); // Geographic locations typedef struct { bool good; // validity long lat,lng; // geodetic latitude and longitude in minutes of arc short unc; // uncertainty in kilometres } GeoRef; typedef struct Place { long leg; // 'CITY' struct Place *sup, // larger region to which this place belongs, if any *rep; // area which replaces this one in time vector pos; // unit geocentric vector GeoRef loc; // geographic location short rad; // radius of region in kilometres bool waypt, // whether it is a 'virtual' place, created by a georef in an itinerary rather than by definition water, // whether it is a water feature hassub; // whether the region has at least one subregion Span when; // date range of historical references string name, // name aka, // alternate name adj; // name of inhabitants colour rgb; // colour for an inhabitant's bar on timeline picture flag, // flag/colour used to fill an inhabitant's bar on timeline flag2; // a one-column image of the right edge of flag point pt; // used by drawmap.c: rendering calculations bool good, // used by drawmap.c: whether projection was successful oth, // used by drawmap.c: if good==0, then true if point is over the horizon draw, // used by drawmap.c: whether it is appropriate to draw a place name part; // used by drawmap.c: whether region is too large, but part is visible short size, // used by drawmap.c: whether the area is the right size to be drawn stack; // used by drawmap.c: the number of things drawn there so far } Place; // prototypes from twhere.c void GeoRefToVector(GeoRef *G, vector *V, const char *S); string GeoRefString(GeoRef *G); void InitPlaces(void); Place *NewPlace(bool AddToList); void PurgePlaces(void); void OrderPlacesBySize(void); void VerifyNewPlace(Place *C); void CheckPlaceDelta(Place *C); void PlaceReference(Place *C, const Span *D); Place *FindPlace(const char *S); bool PlaceMatch(Place *C, const char *S); Place *CreateWaypoint(GeoRef *G); // Voyages enum { travLeft,travThere,travNotYet }; typedef struct { Place *city; // waypoint Span time; // span of time at the waypoint int there; // traveler's presence there during current time step; used by drawmap.c } ArrDep; typedef struct { short leg; // index of waypoint/leg that traveller is on at current time; -1 if not on any Place *c1, // waypoint or start of leg *c2; // end of leg or waypoint real frac; // progress along leg if c1!=c2; 0.0 <= frac < 1.0 } Progress; typedef struct { Span time; // time span for whole itinerary, from first departure to last arrival short num; // number of itinerary points, including end Progress st, // waypoint/leg traveller is on at current time en, // waypoint/leg that traveller will be on at end of time step ust, // like st, but including uncertainty uen; // like en, but including uncertainty ArrDep **ad; // itinerary data: places, and arrival and departure dates } Travels; // prototypes from twhither.c void InitTravels(void); Travels *NewTravels(const Place *C); void OldTravels(Travels *T); void AddArrival(Travels *T, const Day *D); void AddStop(Travels *T, const Place *C); void AddDeparture(Travels *T, const Day *D); void VerifyTravels(Travels *T, const Span *Life, char *S); Place *CurrentLocation(const Travels *T, const Day *D); bool TravelMatch(const Travels *T, const char *S); void DoTravelCalcs(Travels *T); // Tree profiles for genealogies typedef struct { short left,right; // horizontal extent of a row of a tree shape } tpelem; typedef struct { short top, // first row of tree shape bottom; // first row below tree shape tpelem row[0]; // width of each row } treeprofile; // Hyperlinks in to an item typedef struct { short num; void ***link; } listoflinks; void AddLinkIn(void *To, const void *From); // in twho.c // Marriages typedef struct { string spref; // as-yet-unresolved reference to spouse by name struct Person *to; // spouse Day on; // date Place *at; // place } Wedding; // People #define MAXOCC (4) #define MAXREIGN (3) enum { powAcceeded,powAppointed,powTook,powElected, powAbdicated,powDeposed,powRetired,powDied }; typedef struct Person { long leg; // 'PERS' string name, // name (first & last, but normally not middle names) surname, // surname only, for drawing on larger time scales aka, // alias or alternate name info, // text information ref, // references to literature gen1, // first line of name in family tree box gen2, // second line (if any) of name in family tree box src, // name of source file cap; // picture caption char sex; // 'M' or 'F'; bool trans, // true if person was translated, rather than dying ambig, // whether name is identical to another person's name followed; // whether his/her info window has been opened Span life, // date of birth & death reign[MAXREIGN]; // period(s) of reign; dates of accession and, usually, death short nrgn, // number of reigns/periods in office pow[MAXREIGN], // enum; condition of coming to power ret[MAXREIGN], // enum; condition of leaving power nchild, // number of children (determined only if used; -1 otherwise) nocc, // number of occupations occ[MAXOCC]; // occupations listoflinks inbnd; // a list of items with links TO this person short nmarr; // number of marriages Wedding ***wed; // wedding data struct Person *father, // father *mother, // mother ***children; // links to children (determined only if used) string faref, // as-yet unresolved reference to the father moref; // as-yet unresolved reference to the mother bool fagrand, // whether the father reference is to an ancestor more distant than the direct parent mogrand, // whether the mother reference is to an ancestor more distant than the direct parent **chgrand; // whether any child references are to descendents more distant than direct offspring float moright, // calc by gentree.c: how far right of person mother's box is drawn faright, // calc by gentree.c: how far right of person father's box is drawn rightmo, // calc by gentree.c: how far right of mother box is drawn rightfa, // calc by gentree.c: how far right of father box is drawn gw1,gw2,ght, // drawn widths of gen1 and gen2, and height of gen box horzwas, // used by drawgen.c: the horizontal coordinate used when first drawn mingen; // used by gentree.c: age in years at first child's birth (default 1000.0) bool gendid, // used by gentree.c: whether already included in this profile gendrew; // used by drawgen.c: whether already drawn on this tree short genser; // used by gentree.c: serial number for HTML hyperlink rect genrect; // used by gentree.c: reauired for HTML image map; filled by regular drawing routine Place *home, // place of primary residence (default map position) *nation, // region of nationality or alignment; determines time-line colour *pob,*pod; // places of birth and death Travels *trav; // travels, if any bool show; // used by twhich.c long sorttime; // set by twhich.c float left, // used by drawline.c right, // used by drawline.c vert; // used by drawline.c bool seen, // used by drawline.c draw, // used by drawmap.c fade; // used by drawmap.c: whether current time intersects only with uncertainty rect rect; // used by drawline.c point pt; // used by drawmap.c short match; // used by the Find window FSRef *pict; // reference to a picture } Person; // prototypes from twocc.c void InitOccs(void); void PurgeOccs(void); int NewOccupation(char *S); void SetOccIcon(int OCC, picture P); void SetOccSynonym(int OCC, char *S); void SetOccFemale(int OCC); int ParseOccupation(const char *S, bool *Fem); void OccShow(int OCC, bool Show); bool ShowOcc(int OCC); picture PersonIcon(Person *P); bitmap *PersonBitmap(Person *P); char *OccName(int OCC); bool FamilyMember(Person *P); bool OccupationMatch(Person *P, const char *S); // prototypes from twho.c bool VoidIsPers(const void *V); void InitPeople(void); Person *NewPerson(bool AddToList); void PurgePeople(void); void AddOccupation(Person *P, int OCC); void OrderPeopleByDOB(void); Person *FindPerson(const char *S, const Span *L, bool GenErr, const void *From); void VerifyNewPerson(Person *P); void CheckPersonDelta(Person *P); void AddMarriage(Person *P, string Sp, Day D, Place *C); void MakeChildList(Person *P); void PurgeGenCalcs(void); void ResolveFather(Person *P, bool GenErr); void ResolveMother(Person *P, bool GenErr); void ResolvePersonReferences(Person *P); bool Female(Person *P); Place *PersonLocation(Person *P, Day *D); // prototypes from gentree.c typedef struct { short slice, // number of years per profile slice size, // font size line, // line height margin, // size of margin, in pixels, between text and edge of box space, // the space between adjacent boxes and vertical lines brh; // the box-to-horizontal-rule spacing FontInfo font; // font size information real scale; // vertical scale, equal to number of pixels per year } genvars; void setgenparameters(const genvars *G); void resetgendone(void); treeprofile *descendantsprofile(window *W, Person *P); treeprofile *ancestorsprofile(window *W, Person *P); void genhtml(window *W, Person *P); // Historic events typedef struct { long leg; // 'EVNT' short ntype, // number of types type[MAXOCC]; // enumeration of types string name, // short description; for a publication, this would be the title aka, // synonym info, // text information ref, // references to literature src, // name of source file cap; // picture caption Span date; // dates of start and, if applicable, end of event Place *place; // place of occurence Person *pers; // author or other person with whom event is closely associated string persref; // as yet unresolved link to a person Travels *trav; // itinerary, if any listoflinks inbnd; // a list of items with links TO this event long sorttime; // set by twhich.c bool show, // used by twhich.c followed; // whether its info window has been opened float left, // used by drawline.c right, // used by drawline.c vert; // used by drawline.c bool seen, // used by drawline.c draw, // used by drawmap.c fade; // used by drawmap.c: whether current time intersects only with uncertainty rect rect; // used by drawline.c point pt; // used by drawmap.c short match; // used by the Find window FSRef *pict; // reference to a picture } Event; // prototypes from twypes.c void InitTypes(void); void PurgeTypes(void); int NewType(char *S); void SetTypeIcon(int TYPE, picture P); void SetTypeSynonym(int TYPE, char *S); void SetTypeColour(int TYPE, colour *C); int ParseType(const char *S); void TypeShow(int TYPE, bool Show); bool ShowType(int TYPE); //CIconHandle EventIcon(Event *E); picture EventIcon(Event *E); bitmap *EventBitmap(Event *E); char *TypeName(int TYPE); void TypeColour(Event *E, colour *C); bool TypeMatch(Event *E, const char *S); // prototypes from twhat.c bool VoidIsEvent(const void *V); void InitEvents(void); Event *NewEvent(bool AddToList); void PurgeEvents(void); void AddType(Event *E, int TYPE); Event *FindEvent(const char *S, const Span *L, bool GenErr, const void *From); void VerifyNewEvent(Event *E); void CheckEventDelta(Event *E); void OrderEventsByDate(void); void ResolveEventPerson(Event *E, bool GenErr); void ResolveEventReferences(Event *E); // prototypes from twinfo.c typedef struct { short start, // starting character of text run end; // ending character of text run void *link; // person or event refered to } InfoLink; typedef struct { long len, // length of "text" string tlen; // length of title text string text; // the rest of the information short links; // number of hyperlinks InfoLink **link; // the hyperlinks } InfoPara; void InitInfoPara(InfoPara *D); void PurgeInfoPara(InfoPara *D); void CheckInfoText(const void *VFrom, string S, const Span *L, bool GenErr); void MakePersInfo(const Person *P, InfoPara *D); string MakeHTMLInfo(const Person *P); void MakeEventInfo(const Event *E, InfoPara *D); // The "People" and "Event" menu items typedef struct { string name; // the name of the menu item bool show; // whether this item is checked in the menu short num; // the length of the array mbr[] short mbr[0]; // the occupations/event types which are associated with this menu item } SubItem; typedef struct { bool people; // whether it should appear in the "People" menu, rather than "Events" string name; // menu item name short num, // number of SubItem records; if num>1, the menu is hierarchical place; // place in either "People" or "Events" menu (1-based item number) SubItem ****item; // occupation/type groupings associated with menu item short id; // the menu ID, if it is hierarchical MenuRef menu; // the menu, if it is hierarchical } FilterItem; typedef struct { bool office, // whether leaders, etc., are to be sorted by accession date, rather than birth assoc, // whether to show event associated with shown people group; // whether to sort associated events right after people } SortGlobs; // prototypes from twhich.c FilterItem *NewFilterItem(void); void FilterItemName(FilterItem *F, char *S); void FilterItemOff(FilterItem *F); void FilterItemMember(FilterItem *F, char *S); void FilterItemMemberIcon(FilterItem *F, picture P); void FilterItemMemberSynonym(FilterItem *F, char *S); void FilterItemMemberFemale(FilterItem *F); void FilterItemMemberColour(FilterItem *F, colour *C); void VerifyNewFilterItem(FilterItem *F); void AdjustFilterMenu(FilterItem *F); void DoFilterSubMenu(FilterItem *F, int ITEM, int SHOW); void DoFilterItem(FilterItem *F, int SHOW); void SetUpOrder(void); void DeleteFromOrder(void *V); void MakeMenus(void); void SaveWhichInArray(void); void InitWhich(int PEOPLEID, int EVENTID); void PurgeWhich(void); void ShowThisItem(void *V); // "Spheres of influence" (empires, kingdoms, etc.) typedef struct { vectorpoly **poly; // the region, a spherical polygon Span date; // start and end times of polygon, which must be contiguous with neighbours } TimePoly; typedef struct { string name; // name to appear GeoRef loc; // where the name is to be drawn vector pos; // unit geocentric vector for "loc" field short rad; // mean radius of region in kilometres colour rgb; // its colour on the map Span date; // start first polygon, and end of last one short num; // number of polygons TimePoly **polys; // the spherical polygons } Sphere; // prototypes from twixt.c void InitSpheres(void); Sphere *NewSphere(bool AddToList); void PurgeSpheres(void); void NewSphereDate(Sphere *S, const Day *D); void SphereEndDate(Sphere *S, const Day *D); void AddPolyToSphere(Sphere *S, vectorpoly **P); void VerifyNewSphere(Sphere *S); void CheckSphereDelta(Sphere *S); void InitGlobe(void); void UsePolys(vectorpolys **P); void PurgeGlobe(void); // prototypes from twicon.c void InitTwIcon(void); void PurgeIcons(void); picture IconFromName(const char *S); picture DefaultPersonIcon(void); picture DefaultEventIcon(void); bitmap *DefaultPersonBitmap(void); bitmap *DefaultEventBitmap(void); void ReleaseIcon(picture P, bitmap *B); void DrawIcon(window *W, picture Im, point P, float Mag); //void OutlineIcon(CIconHandle Icon, Point P); bool BitmapHit(bitmap *B, point P, float Mag); // prototypes from twarn.c void NoteOld(string S); void Note(const char *S); void WarnOld(string S); void Warning(const char *S); void DangerOld(string S); void Danger(const char *S); void PurgeWarnings(void); void InitWarnings(void); // prototypes from ttt.c void WaitCursor(void); typedef struct { bool ad, // whether default era is A.D. delta; // whether the database is being read only to determine the difference with the already-loaded database } ParseDefaults; typedef struct TTTTask { bool begun, // whether the task of reading "file" has begun done, // whether the task of reading "file" is finished finished; // whether the post-reading tasks are also done; used only for the top-level TTTTask file file; // the file to be read string text, // the text of the file path; // the pathname for the progress dialog char *p; // next character to be parsed in text ParseDefaults pd; // default parsing settings struct TTTTask *next; // the next file refered to within the current file short num, // number of sub-files (occurences of #file) did; // number of sub-files finished real f1, // lower bound of progress bar for this file f2; // upper bound of progress bar for this file short post[4]; // post-reading task process (0=not started; -1=done) } TTTTask; void SetItemFileName(const void *V); void InitTTTTask(TTTTask *T); void DoTTTTask(TTTTask *T); void Purge(void); bool CanDoDelta(void); void DoDeltaTask(file *F); void InitTTT(void);