/*
 * Go2ProfileStripHeight.c
 * 
 * Gocator system communication library
 * Copyright (C) 2013 by LMI Technologies Inc.
 * 
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 */

#include <z/Go2Measurements/zGo2ProfileStripHeight.h>
#include <z/zGo2ProfileTypes.h>
#include <z/zGo2System.h>
#include <string.h>

/*
 * Go2ProfileStripHeight Class
 */

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_Construct(Go2ProfileStripHeight* measurement, Go2UInt32 id, Go2Object system)
{
    Go2ProfileStripHeight output = zNIL; 
    Go2Status status = GO2_OK; 

    zCHECK(zCalloc(&output, 1, sizeof(Go2ProfileStripHeightClass))); 

    if (!zSUCCESS(status = Go2ProfileStripHeight_Init(output, id, system)))
    {
        zCHECK(Go2Object_Destroy(output)); 
        return status; 
    }
    
    *measurement = output; 

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_Init(Go2ProfileStripHeight measurement, Go2UInt32 id, Go2Object system)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement);

    zCHECK(Go2Measurement_Init(measurement, GO2_TYPE_PROFILE_STRIP_HEIGHT, id, system)); 

    obj->Release = Go2ProfileStripHeight_VRelease; 
    obj->Read = Go2ProfileStripHeight_VRead; 
    obj->Write = Go2ProfileStripHeight_VWrite; 

    obj->baseType = GO2_PROFILE_STRIP_BASE_NONE;
    obj->location = GO2_PROFILE_STRIP_LOCATION_LEFT;
    obj->leftEdgeType = 0xF; //enable all
    obj->rightEdgeType = 0xF; //enable all
    obj->tiltEnabled = 1;
    obj->selectType = GO2_PROFILE_STRIP_SELECT_BEST;
    obj->selectN = 0; //not applicable with BEST, set it anyways
    obj->transitionWidth = 2.0;
    obj->supportWidth = 5.0;
    obj->edgeHeightMin = 2.0;
    obj->voidMax = 0;
    obj->widthMin = 0;

    zCHECK(Go2ProfileArea_Construct(&obj->area, system));       

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_VRelease(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement);

    zCHECK(Go2Object_Destroy(obj->area)); 

    zCHECK(Go2Measurement_VRelease(measurement));  
        
    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_VRead(Go2ProfileStripHeight measurement, zXml xml, zXmlItem item)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    zChar* text = zNULL;
    z32u textCapacity = GO2_MEASUREMENT_SOURCE_TEXT_CAPACITY; 

    zXmlItem areaItem = zNIL; 

    zCHECK(Go2Measurement_VRead(measurement, xml, item)); 

    zCHECK(zCalloc(&text, textCapacity, sizeof(zChar)));
    zCHECK(zXml_ChildText(xml, item, "SourceOptions", text, textCapacity)); 
    zCHECK(Go2OptionList_ParseList(text, obj->sourceOptions));  

    zCHECK(zXml_Child32u(xml, item, "Source", &obj->source)); 
    
    zCHECK(zXml_Child32s(xml, item, "BaseType", (z32s*) &obj->baseType)); 
    zCHECK(zXml_Child32s(xml, item, "Location", (z32s*) &obj->location)); 
    zCHECK(zXml_Child32u(xml, item, "LeftEdgeType", &obj->leftEdgeType)); 
    zCHECK(zXml_Child32u(xml, item, "RightEdgeType", &obj->rightEdgeType)); 
    zCHECK(zXml_Child32s(xml, item, "TiltEnabled", &obj->tiltEnabled)); 
    zCHECK(zXml_Child32s(xml, item, "SelectType", (z32s*) &obj->selectType));
    zCHECK(zXml_Child32u(xml, item, "SelectN", &obj->selectN));
    zCHECK(zXml_Child64f(xml, item, "EdgeSupportWidth", &obj->supportWidth));
    zCHECK(zXml_Child64f(xml, item, "EdgeTransitionWidthMax", &obj->transitionWidthMax));
    zCHECK(zXml_Child64f(xml, item, "EdgeTransitionWidth", &obj->transitionWidth));
    zCHECK(zXml_Child64f(xml, item, "VoidMaxLimitMax", &obj->voidMaxLimitMax));
    zCHECK(zXml_Child64f(xml, item, "VoidMax", &obj->voidMax));
    zCHECK(zXml_Child64f(xml, item, "WidthMin", &obj->widthMin));
    zCHECK(zXml_Child64f(xml, item, "EdgeHeightMin", &obj->edgeHeightMin));

    zCHECK(!zIS_NIL(areaItem = zXml_Child(xml, item, "Area"))); 
    zCHECK(Go2ProfileArea_Read(obj->area, xml, areaItem)); 

    zCHECK(zFree(text));

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_VWrite(Go2ProfileStripHeight measurement, zXml xml, zXmlItem item)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    zXmlItem areaItem = zNIL; 

    zCHECK(Go2Measurement_VWrite(measurement, xml, item)); 

    zCHECK(zXml_SetChild32u(xml, item, "Source", obj->source)); 

    zCHECK(zXml_SetChild32s(xml, item, "BaseType", obj->baseType)); 
    zCHECK(zXml_SetChild32s(xml, item, "Location", obj->location)); 
    zCHECK(zXml_SetChild32u(xml, item, "LeftEdgeType", obj->leftEdgeType)); 
    zCHECK(zXml_SetChild32u(xml, item, "RightEdgeType", obj->rightEdgeType)); 
    zCHECK(zXml_SetChild32s(xml, item, "TiltEnabled", obj->tiltEnabled)); 
    zCHECK(zXml_SetChild32s(xml, item, "SelectType", obj->selectType)); 
    zCHECK(zXml_SetChild32u(xml, item, "SelectN", obj->selectN)); 
    zCHECK(zXml_SetChild64f(xml, item, "EdgeSupportWidth", obj->supportWidth));
    zCHECK(zXml_SetChild64f(xml, item, "EdgeTransitionWidth", obj->transitionWidth));
    zCHECK(zXml_SetChild64f(xml, item, "VoidMax", obj->voidMax));
    zCHECK(zXml_SetChild64f(xml, item, "WidthMin", obj->widthMin));
    zCHECK(zXml_SetChild64f(xml, item, "EdgeHeightMin", obj->edgeHeightMin));

    zCHECK(zXml_AddItem(xml, item, "Area", &areaItem)); 
    zCHECK(Go2ProfileArea_Write(obj->area, xml, areaItem)); 

    return GO2_OK; 
}


GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetId(Go2ProfileStripHeight measurement, Go2UInt32 id)
{
    return Go2Measurement_SetId(measurement, id);     
}

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_Id(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_Id(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetName(Go2ProfileStripHeight measurement, const Go2Char* name)
{
    return Go2Measurement_SetName(measurement, name);     
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_Name(Go2ProfileStripHeight measurement, Go2Char* name, Go2UInt32 capacity)
{
    return Go2Measurement_Name(measurement, name, capacity);     
}

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_SourceOptionCount(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_SourceOptionCount(measurement);     
}

GO2_EXPORT(Go2ProfileSource) Go2ProfileStripHeight_SourceOptionAt(Go2ProfileStripHeight measurement, Go2UInt32 index)
{
    return Go2Measurement_SourceOptionAt(measurement, index);     
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetSource(Go2ProfileStripHeight measurement, Go2ProfileSource source)
{
    return Go2Measurement_SetSource(measurement, source);     
}

GO2_EXPORT(Go2ProfileSource) Go2ProfileStripHeight_Source(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_Source(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetDecisionMin(Go2ProfileStripHeight measurement, Go2Double min)
{
    return Go2Measurement_SetDecisionMin(measurement, min);     
}

GO2_EXPORT(Go2Double) Go2ProfileStripHeight_DecisionMin(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_DecisionMin(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetDecisionMax(Go2ProfileStripHeight measurement, Go2Double max)
{
    return Go2Measurement_SetDecisionMax(measurement, max);     
}

GO2_EXPORT(Go2Double) Go2ProfileStripHeight_DecisionMax(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_DecisionMax(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_EnableHold(Go2ProfileStripHeight measurement, Go2Bool enable)
{
    return Go2Measurement_EnableHold(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2ProfileStripHeight_HoldEnabled(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_HoldEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_EnableSmoothing(Go2ProfileStripHeight measurement, Go2Bool enable)
{
    return Go2Measurement_EnableSmoothing(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2ProfileStripHeight_SmoothingEnabled(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_SmoothingEnabled(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_SmoothingWindowMin(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_SmoothingWindowMin(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_SmoothingWindowMax(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_SmoothingWindowMax(measurement);  
} 

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetSmoothingWindow(Go2ProfileStripHeight measurement, Go2UInt32 window)
{
    return Go2Measurement_SetSmoothingWindow(measurement, window);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_SmoothingWindow(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_SmoothingWindow(measurement);  
} 

GO2_EXPORT(Go2ProfileArea) Go2ProfileStripHeight_Area(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->area;  
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetBaseType(Go2ProfileStripHeight measurement, Go2ProfileStripBaseType baseType)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->baseType = baseType; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2ProfileStripBaseType) Go2ProfileStripHeight_BaseType(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->baseType;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetLocation(Go2ProfileStripHeight measurement, Go2ProfileStripLocation location)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->location = location; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2ProfileStripLocation) Go2ProfileStripHeight_Location(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->location;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_EnableLeftEdgeType(Go2ProfileStripHeight measurement, Go2ProfileStripEdgeType type, Go2Bool enable)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    if(enable)
    {
        obj->leftEdgeType |= (Go2UInt32)type; 
    }
    else
    {
        obj->leftEdgeType &= ~((Go2UInt32)type); 
    }
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;
}

GO2_EXPORT(Go2Bool) Go2ProfileStripHeight_LeftEdgeTypeEnabled(Go2ProfileStripHeight measurement, Go2ProfileStripEdgeType type)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return (obj->leftEdgeType & (Go2UInt32)type) != 0;   
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_EnableRightEdgeType(Go2ProfileStripHeight measurement, Go2ProfileStripEdgeType type, Go2Bool enable)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    if(enable)
    {
        obj->rightEdgeType |= (Go2UInt32)type; 
    }
    else
    {
        obj->rightEdgeType &= ~((Go2UInt32)type); 
    }
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;
}

GO2_EXPORT(Go2Bool) Go2ProfileStripHeight_RightEdgeTypeEnabled(Go2ProfileStripHeight measurement, Go2ProfileStripEdgeType type)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return (obj->rightEdgeType & (Go2UInt32)type) != 0;   
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_EnableTilt(Go2ProfileStripHeight measurement, Go2Bool enable)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->tiltEnabled = enable;
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;
}

GO2_EXPORT(Go2Bool) Go2ProfileStripHeight_TiltEnabled(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->tiltEnabled;   
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetSelectType(Go2ProfileStripHeight measurement, Go2ProfileStripSelectType type)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->selectType = type; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2ProfileStripSelectType) Go2ProfileStripHeight_SelectType(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->selectType;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetSelectN(Go2ProfileStripHeight measurement, Go2UInt32 n)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->selectN = n; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_SelectN(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->selectN;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetEdgeSupportWidth(Go2ProfileStripHeight measurement, Go2Double width)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->supportWidth = width; 
    zCHECK(Go2System_SyncConfig(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2Double) Go2ProfileStripHeight_EdgeSupportWidth(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->supportWidth;      
}

GO2_EXPORT(Go2Double) Go2ProfileStripHeight_EdgeTransitionWidthMax(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->transitionWidthMax;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetEdgeTransitionWidth(Go2ProfileStripHeight measurement, Go2Double width)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_Set64f(obj->system, &obj->transitionWidth, width, 0, obj->transitionWidthMax));
    zCHECK(Go2System_SyncConfig(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2Double) Go2ProfileStripHeight_EdgeTransitionWidth(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->transitionWidth;      
}

GO2_EXPORT(Go2Double) Go2ProfileStripHeight_VoidMaxLimitMax(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->voidMaxLimitMax;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetVoidMax(Go2ProfileStripHeight measurement, Go2Double width)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    zCHECK(Go2System_Set64f(obj->system, &obj->voidMax, width, 0, obj->voidMaxLimitMax));
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2Double) Go2ProfileStripHeight_VoidMax(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->voidMax;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetWidthMin(Go2ProfileStripHeight measurement, Go2Double width)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->widthMin = width; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2Double) Go2ProfileStripHeight_WidthMin(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->widthMin;      
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetEdgeHeightMin(Go2ProfileStripHeight measurement, Go2Double height)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->edgeHeightMin = height; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2Double) Go2ProfileStripHeight_EdgeHeightMin(Go2ProfileStripHeight measurement)
{
    Go2ProfileStripHeightClass* obj = zHANDLE_POINTER(measurement); 
    return obj->edgeHeightMin;      
}




GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetScale(Go2ProfileStripHeight measurement, Go2Double scale){
    return Go2Measurement_SetScale(measurement, scale);
}

GO2_EXPORT(Go2Double) Go2ProfileStripHeight_Scale(Go2ProfileStripHeight measurement){
    return Go2Measurement_Scale(measurement);
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetOffset(Go2ProfileStripHeight measurement, Go2Double offset){
    return Go2Measurement_SetOffset(measurement, offset);
}

GO2_EXPORT(Go2Double) Go2ProfileStripHeight_Offset(Go2ProfileStripHeight measurement){
    return Go2Measurement_Offset(measurement);
}

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_LinkOptionCount(Go2ProfileStripHeight measurement)
{
    return Go2Measurement_LinkOptionCount(measurement);
}

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_LinkOptionAt(Go2ProfileStripHeight measurement, Go2UInt32 index)
{
    return Go2Measurement_LinkOptionAt(measurement, index);
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_EnableLink(Go2ProfileStripHeight measurement, Go2Bool enable)  
{
    return Go2Measurement_EnableLink(measurement, enable);  
}

GO2_EXPORT(Go2Bool) Go2ProfileStripHeight_LinkEnabled(Go2ProfileStripHeight measurement)  
{
    return Go2Measurement_LinkEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2ProfileStripHeight_SetLink(Go2ProfileStripHeight measurement, Go2UInt32 link) 
{
    return Go2Measurement_SetLink(measurement, link); 
}

GO2_EXPORT(Go2UInt32) Go2ProfileStripHeight_Link(Go2ProfileStripHeight measurement) 
{
    return Go2Measurement_Link(measurement); 
}
