//
// TreeProperties.js
//
// Object holding tree properties
//
// Copyright (C) 1999-2002 Solidworks Corporation
// All rights reserved.
//

function TreeProperties(i_bDocumentName, i_bNumber, i_bDescription, 
	i_bRevision, i_bOwner, i_bStatus, i_projectLabels, i_bSaveAsDefault,
	i_strCustProp) {
    this.bDocumentName = i_bDocumentName;
    this.bNumber = i_bNumber;
    this.bDescription = i_bDescription;
    this.bRevision = i_bRevision;
    this.bStatus = i_bStatus;
    this.bOwner = i_bOwner;
    this.strCustProp = i_strCustProp;
    this.projectLabels = i_projectLabels;
    this.bSaveAsDefault = i_bSaveAsDefault;
    this.serialize = TreeProperties_serialize;
    this.getSerialized = TreeProperties_getSerialized;
    this.setDefault = TreeProperties_setDefault;
}

var arrTreePropNames = new Array("bDocumentName", "bNumber", "bDescription",
    "bRevision", "bStatus", "bOwner");


function TreeProperties_serialize(i_strCompact) {
    if (i_strCompact == null || i_strCompact == "") {
	this.setDefault();
    }
    else {
	if (i_strCompact.length >= 7) {
	    for (var i = 0 ; i < arrTreePropNames.length ; ++i) {
		this[arrTreePropNames[i]] 
		    = (i_strCompact.charAt(i) == 1) ? true : false;
	    }
            this.projectLabels = i_strCompact.charAt(i);
	    this.strCustProp = i_strCompact.substr(i+1);
	}
	else {
	    reportError("TreeProperties_serialize(" + i_strCompact + ") incorrect length");
	    this.setDefault();
	}
    }    
}


function TreeProperties_setDefault() {
    // Use defaults
    this.bDocumentName = 1;
    this.bNumber = 1;
    this.bDescription = 1;
    this.bRevision = 1;
    this.bOwner = 1;
    this.bStatus = 1;
    this.projectLabels = "D";
    this.strCustProp = "";
    return 1;
}


//
// TreeProperties_getSerialized
// Returns serialized string of contents
function TreeProperties_getSerialized() {
    var str = "";
    for (var i = 0 ; i < arrTreePropNames.length ; ++i) {
	str += (this[arrTreePropNames[i]] ? "1":"0");
    }
    str += this.projectLabels;
    str += this.strCustProp; // New: store a custom property label
    return str;
}

