Differences Column

A way to display a column showing changes since the last baseline.

Create a DXL attribute called MY_CHANGES using the code below.

//  Attribute DXL to calculate differences between current and previous version.
/*
	Attribute DXL to hold differences between the current
	object and the corresponding object in the most recent baseline

	This is a very simplistic script, but does do the job.

	What to do:

	1. Create a DXL attribute called say "MY_CHANGES" and add the contents of this file as the code.
	   Make the attribute applicable to objects only and turn off
	   history and change bars etc.

	2. Add a layout DXL column and enter the following line of DXL:

			displayRichWithColor(obj."MY_CHANGES" "")

	   Set column header to something liek "Changes since baseline (F5 to refresh)"

	3. Save the view.

	The new column will show marked up text displaying diffeences between
	the current object and the object in teh previous version.

	New objects are marked as "New".

	NOTE:
	This does not highlight when objects have been moved or deleted.

	Displaying that the object has been moved is straight forward
	just compare the object numbers.

	Tony Goodman.
*/

/******************************************************************************
	Open the most recent baseline
******************************************************************************/
bool openLastBaseline(Module newMod, Module &oldMod)
{
	Baseline b = getMostRecentBaseline(newMod)

	oldMod = null

	if (!null b)
	{
		// load baseline for reading in the background
		oldMod = load(newMod, b, false)

		return(true)
	}

	return(false)
}

/******************************************************************************
	Get list of attributes to compare
******************************************************************************/
void getAttrs(Module newMod, Skip attrs)
{
	AttrDef ad = null
	string  adDxl = ""

	// loop through attributes in module
	for ad in newMod do
	{
		if (!null ad)
		{
			// only interested in object attributes
			if (ad.object)
			{
				// exclude system attributes
				if (ad.system) continue

				// exclude DXL attributes
				adDxl = ad.dxl

				if (adDxl "" != "") continue

				// to exclude an attribute insert test for it here
				if (ad.name == "Object Heading") continue
				if (ad.name == "Object Text") continue

				put(attrs, ad.name, ad.name)
			}
		}
	}
}

/******************************************************************************
	Compare Objects
******************************************************************************/
void compareObjects(Object oldObj, Object obj, Skip skipAttrs, Buffer diffBuf)
{
	string res       = ""
	string aName     = ""
	bool   multiple  = false

    Buffer oh = create()
    Buffer nh = create()
    Buffer ot = create()
    Buffer nt = create()
    Buffer tempBuf = create

    setempty(diffBuf)

    oh += oldObj."Object Heading" ""
    ot += oldObj."Object Text" ""

    nh += obj."Object Heading" ""
    nt += obj."Object Text" ""

    // Handle Tables TBC

    // changes to object heading
    if (oh != nh)
    {
	    // create differences string
	    diff(tempBuf, oh, nh)
	    diffBuf += "{\\i Object Heading : }"
	    diffBuf += tempBuf

	    multiple = true
    }

    // changes to object text
    if (ot != nt)
    {
    	// create differences string
	    diff(tempBuf, ot, nt)
	    diffBuf += "{\\i " (multiple ? "\\par " : "") "Object Text : }"
	    diffBuf += tempBuf

	    multiple = true
    }

    // changes to other attributes
    for aName in skipAttrs do
    {
        setempty(ot)
        setempty(nt)

        ot += probeAttr_(oldObj, aName)
        nt += probeAttr_(obj, aName)

        if (ot != nt)
        {
	    	// create differences string
			diff(tempBuf, ot, nt)
			diffBuf += "{\\i " (multiple ? "\\par " : "") aName ": }"
			diffBuf += tempBuf

			multiple = true
        }
    }

    diffBuf += " "

    delete(oh)
    delete(nh)
    delete(ot)
    delete(nt)
    delete(tempBuf)
}

/******************************************************************************
	MAIN
******************************************************************************/
Module newMod    = current Module
Module oldMod    = null
Object oldObj    = null
int    objNo     = obj."Absolute Number"
Buffer diffBuf   = create
Skip   skipAttrs = createString

getAttrs(newMod, skipAttrs)

if (openLastBaseline(newMod, oldMod))
{
	oldObj = object(objNo, oldMod)

	if (null oldObj)
	{
		diffBuf += "New"
	}
	else
	{
		compareObjects(oldObj, obj, skipAttrs, diffBuf)
	}
}
else
{
	diffBuf += "N/A"
}

obj.attrDXLName = tempStringOf(diffBuf)

//print(stringOf(diffBuf))

delete(diffBuf)
delete(skipAttrs)

Then add a layout DXL column with the following code, where MY_CHANGES is the name of the DXL attribute you just created. This will give you a dynamic column that shows red-lined mark up of changes made to the obejct since the previous baseline.


displayRichWithColor(obj."MY_CHANGES" "")