/*
 * Go2ProfileIsectAngle.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/zGo2ProfileIsectAngle.h>
#include <z/zGo2ProfileTypes.h>
#include <z/zGo2System.h>
#include <string.h>

/*
 * Go2ProfileIsectAngle Class 
 */

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

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

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

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_Init(Go2ProfileIsectAngle measurement, Go2UInt32 id, Go2Object system)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement);
    z32u i; 

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

    obj->Release = Go2ProfileIsectAngle_VRelease; 
    obj->Read = Go2ProfileIsectAngle_VRead; 
    obj->Write = Go2ProfileIsectAngle_VWrite; 

    for (i = 0; i < zCOUNT(obj->lines); ++i)
    {
        zCHECK(Go2ProfileLine_Construct(&obj->lines[i], system));       
    }

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_VRelease(Go2ProfileIsectAngle measurement)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement);
    z32u i; 

    for (i = 0; i < zCOUNT(obj->lines); ++i)
    {
        zCHECK(Go2Object_Destroy(obj->lines[i])); 
    }

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

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_VRead(Go2ProfileIsectAngle measurement, zXml xml, zXmlItem item)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement); 
    zChar* text = zNULL;
    z32u textCapacity = GO2_MEASUREMENT_SOURCE_TEXT_CAPACITY; 

    zXmlItem lineItem = zNIL; 
    z32u i; 

    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)); 
    

    lineItem = zXml_Child(xml, item, "Line"); 

    for (i = 0; i < zCOUNT(obj->lines); ++i)
    {
        zCHECK(!zIS_NIL(lineItem)); 
        zCHECK(Go2ProfileLine_Read(obj->lines[i], xml, lineItem)); 

        lineItem = zXml_NextSibling(xml, lineItem); 
    }

    zCHECK(zFree(text));

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_VWrite(Go2ProfileIsectAngle measurement, zXml xml, zXmlItem item)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement); 
    zXmlItem lineItem = zNIL; 
    z32u i; 

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

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

    for (i = 0; i < zCOUNT(obj->lines); ++i)
    {
        zCHECK(zXml_AddItem(xml, item, "Line", &lineItem)); 
        zCHECK(Go2ProfileLine_Write(obj->lines[i], xml, lineItem)); 
    }

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetId(Go2ProfileIsectAngle measurement, Go2UInt32 id)
{
    return Go2Measurement_SetId(measurement, id);     
}

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_Id(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_Id(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetName(Go2ProfileIsectAngle measurement, const Go2Char* name)
{
    return Go2Measurement_SetName(measurement, name);     
}

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

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_SourceOptionCount(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_SourceOptionCount(measurement);     
}

GO2_EXPORT(Go2ProfileSource) Go2ProfileIsectAngle_SourceOptionAt(Go2ProfileIsectAngle measurement, Go2UInt32 index)
{
    return Go2Measurement_SourceOptionAt(measurement, index);     
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetSource(Go2ProfileIsectAngle measurement, Go2ProfileSource source)
{
    return Go2Measurement_SetSource(measurement, source);     
}

GO2_EXPORT(Go2ProfileSource) Go2ProfileIsectAngle_Source(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_Source(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetDecisionMin(Go2ProfileIsectAngle measurement, Go2Double min)
{
    return Go2Measurement_SetDecisionMin(measurement, min);     
}

GO2_EXPORT(Go2Double) Go2ProfileIsectAngle_DecisionMin(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_DecisionMin(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetDecisionMax(Go2ProfileIsectAngle measurement, Go2Double max)
{
    return Go2Measurement_SetDecisionMax(measurement, max);     
}

GO2_EXPORT(Go2Double) Go2ProfileIsectAngle_DecisionMax(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_DecisionMax(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_EnableHold(Go2ProfileIsectAngle measurement, Go2Bool enable)
{
    return Go2Measurement_EnableHold(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2ProfileIsectAngle_HoldEnabled(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_HoldEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_EnableSmoothing(Go2ProfileIsectAngle measurement, Go2Bool enable)
{
    return Go2Measurement_EnableSmoothing(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2ProfileIsectAngle_SmoothingEnabled(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_SmoothingEnabled(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_SmoothingWindowMin(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_SmoothingWindowMin(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_SmoothingWindowMax(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_SmoothingWindowMax(measurement);  
} 

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetSmoothingWindow(Go2ProfileIsectAngle measurement, Go2UInt32 window)
{
    return Go2Measurement_SetSmoothingWindow(measurement, window);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_SmoothingWindow(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_SmoothingWindow(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_LineCount(Go2ProfileIsectAngle measurement)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement); 
    return zCOUNT(obj->lines); 
}

GO2_EXPORT(Go2ProfileLine) Go2ProfileIsectAngle_LineAt(Go2ProfileIsectAngle measurement, Go2UInt32 index)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement); 
    return obj->lines[index];  
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetAbsoluteResult(Go2ProfileIsectAngle measurement, Go2Bool absoluteResult)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK; 
}
 
GO2_EXPORT(Go2Bool) Go2ProfileIsectAngle_AbsoluteResult(Go2ProfileIsectAngle measurement)
{
    Go2ProfileIsectAngleClass* obj = zHANDLE_POINTER(measurement); 
    return obj->absoluteResult;   
}



GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetScale(Go2ProfileIsectAngle measurement, Go2Double scale){
    return Go2Measurement_SetScale(measurement, scale);
}

GO2_EXPORT(Go2Double) Go2ProfileIsectAngle_Scale(Go2ProfileIsectAngle measurement){
    return Go2Measurement_Scale(measurement);
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetOffset(Go2ProfileIsectAngle measurement, Go2Double offset){
    return Go2Measurement_SetOffset(measurement, offset);
}

GO2_EXPORT(Go2Double) Go2ProfileIsectAngle_Offset(Go2ProfileIsectAngle measurement){
    return Go2Measurement_Offset(measurement);
}

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_LinkOptionCount(Go2ProfileIsectAngle measurement)
{
    return Go2Measurement_LinkOptionCount(measurement);
}

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_LinkOptionAt(Go2ProfileIsectAngle measurement, Go2UInt32 index)
{
    return Go2Measurement_LinkOptionAt(measurement, index);
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_EnableLink(Go2ProfileIsectAngle measurement, Go2Bool enable)  
{
    return Go2Measurement_EnableLink(measurement, enable);  
}

GO2_EXPORT(Go2Bool) Go2ProfileIsectAngle_LinkEnabled(Go2ProfileIsectAngle measurement)  
{
    return Go2Measurement_LinkEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2ProfileIsectAngle_SetLink(Go2ProfileIsectAngle measurement, Go2UInt32 link) 
{
    return Go2Measurement_SetLink(measurement, link); 
}

GO2_EXPORT(Go2UInt32) Go2ProfileIsectAngle_Link(Go2ProfileIsectAngle measurement) 
{
    return Go2Measurement_Link(measurement); 
}
