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

/*
 * Go2ProfileGrooveX Class
 */

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

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

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

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_Init(Go2ProfileGrooveX measurement, Go2UInt32 id, Go2Object system)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement);

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

    obj->Release = Go2ProfileGrooveX_VRelease; 
    obj->Read = Go2ProfileGrooveX_VRead; 
    obj->Write = Go2ProfileGrooveX_VWrite; 

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

    return GO2_OK; 
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_VRelease(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement);

    zCHECK(Go2Object_Destroy(obj->area)); 

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

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_VRead(Go2ProfileGrooveX measurement, zXml xml, zXmlItem item)
{
    Go2ProfileGrooveXClass* 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, "Shape", (z32s*) &obj->shape)); 
    zCHECK(zXml_Child32s(xml, item, "SelectType", (z32s*) &obj->selectType));
    zCHECK(zXml_Child32u(xml, item, "SelectN", &obj->selectN));
    zCHECK(zXml_Child32s(xml, item, "Location", (z32s*) &obj->location));
    zCHECK(zXml_Child64f(xml, item, "WidthMin", &obj->widthMin));
    zCHECK(zXml_Child64f(xml, item, "WidthMax", &obj->widthMax));
    zCHECK(zXml_Child64f(xml, item, "DepthMin", &obj->depthMin));

    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) Go2ProfileGrooveX_VWrite(Go2ProfileGrooveX measurement, zXml xml, zXmlItem item)
{
    Go2ProfileGrooveXClass* 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, "Shape", obj->shape)); 
    zCHECK(zXml_SetChild32s(xml, item, "SelectType", obj->selectType)); 
    zCHECK(zXml_SetChild32u(xml, item, "SelectN", obj->selectN)); 
    zCHECK(zXml_SetChild32s(xml, item, "Location", obj->location)); 
    zCHECK(zXml_SetChild64f(xml, item, "WidthMin", obj->widthMin)); 
    zCHECK(zXml_SetChild64f(xml, item, "WidthMax", obj->widthMax)); 
    zCHECK(zXml_SetChild64f(xml, item, "DepthMin", obj->depthMin)); 

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

    return GO2_OK; 
}


GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetId(Go2ProfileGrooveX measurement, Go2UInt32 id)
{
    return Go2Measurement_SetId(measurement, id);     
}

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_Id(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_Id(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetName(Go2ProfileGrooveX measurement, const Go2Char* name)
{
    return Go2Measurement_SetName(measurement, name);     
}

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

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_SourceOptionCount(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_SourceOptionCount(measurement);     
}

GO2_EXPORT(Go2ProfileSource) Go2ProfileGrooveX_SourceOptionAt(Go2ProfileGrooveX measurement, Go2UInt32 index)
{
    return Go2Measurement_SourceOptionAt(measurement, index);     
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetSource(Go2ProfileGrooveX measurement, Go2ProfileSource source)
{
    return Go2Measurement_SetSource(measurement, source);     
}

GO2_EXPORT(Go2ProfileSource) Go2ProfileGrooveX_Source(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_Source(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetDecisionMin(Go2ProfileGrooveX measurement, Go2Double min)
{
    return Go2Measurement_SetDecisionMin(measurement, min);     
}

GO2_EXPORT(Go2Double) Go2ProfileGrooveX_DecisionMin(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_DecisionMin(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetDecisionMax(Go2ProfileGrooveX measurement, Go2Double max)
{
    return Go2Measurement_SetDecisionMax(measurement, max);     
}

GO2_EXPORT(Go2Double) Go2ProfileGrooveX_DecisionMax(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_DecisionMax(measurement);     
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_EnableHold(Go2ProfileGrooveX measurement, Go2Bool enable)
{
    return Go2Measurement_EnableHold(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2ProfileGrooveX_HoldEnabled(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_HoldEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_EnableSmoothing(Go2ProfileGrooveX measurement, Go2Bool enable)
{
    return Go2Measurement_EnableSmoothing(measurement, enable);  
} 

GO2_EXPORT(Go2Bool) Go2ProfileGrooveX_SmoothingEnabled(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_SmoothingEnabled(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_SmoothingWindowMin(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_SmoothingWindowMin(measurement);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_SmoothingWindowMax(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_SmoothingWindowMax(measurement);  
} 

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetSmoothingWindow(Go2ProfileGrooveX measurement, Go2UInt32 window)
{
    return Go2Measurement_SetSmoothingWindow(measurement, window);  
} 

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_SmoothingWindow(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_SmoothingWindow(measurement);  
} 

GO2_EXPORT(Go2ProfileArea) Go2ProfileGrooveX_Area(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->area;  
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetShape(Go2ProfileGrooveX measurement, Go2ProfileGrooveShape shape)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK;      
}
 
GO2_EXPORT(Go2ProfileGrooveShape) Go2ProfileGrooveX_Shape(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->shape;      
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetSelectType(Go2ProfileGrooveX measurement, Go2ProfileGrooveSelectType type)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK;      
}
 
GO2_EXPORT(Go2ProfileGrooveSelectType) Go2ProfileGrooveX_SelectType(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->selectType;      
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetSelectN(Go2ProfileGrooveX measurement, Go2UInt32 n)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK;      
}
 
GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_SelectN(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->selectN;      
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetLocation(Go2ProfileGrooveX measurement, Go2ProfileGrooveLocation location)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK;      
}

GO2_EXPORT(Go2ProfileGrooveLocation) Go2ProfileGrooveX_Location(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->location;      
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetDepthMin(Go2ProfileGrooveX measurement, Go2Double depth)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

    zCHECK(Go2System_CheckConfigurable(obj->system)); 
    obj->depthMin = depth; 
    zCHECK(Go2System_SetModified(obj->system)); 

    return GO2_OK;      
}
 
GO2_EXPORT(Go2Double) Go2ProfileGrooveX_DepthMin(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->depthMin;      
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetWidthMin(Go2ProfileGrooveX measurement, Go2Double width)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK;      
}

GO2_EXPORT(Go2Double) Go2ProfileGrooveX_WidthMin(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->widthMin;      
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetWidthMax(Go2ProfileGrooveX measurement, Go2Double width)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 

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

    return GO2_OK;      
}

GO2_EXPORT(Go2Double) Go2ProfileGrooveX_WidthMax(Go2ProfileGrooveX measurement)
{
    Go2ProfileGrooveXClass* obj = zHANDLE_POINTER(measurement); 
    return obj->widthMax;      
}




GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetScale(Go2ProfileGrooveX measurement, Go2Double scale){
    return Go2Measurement_SetScale(measurement, scale);
}

GO2_EXPORT(Go2Double) Go2ProfileGrooveX_Scale(Go2ProfileGrooveX measurement){
    return Go2Measurement_Scale(measurement);
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetOffset(Go2ProfileGrooveX measurement, Go2Double offset){
    return Go2Measurement_SetOffset(measurement, offset);
}

GO2_EXPORT(Go2Double) Go2ProfileGrooveX_Offset(Go2ProfileGrooveX measurement){
    return Go2Measurement_Offset(measurement);
}

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_LinkOptionCount(Go2ProfileGrooveX measurement)
{
    return Go2Measurement_LinkOptionCount(measurement);
}

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_LinkOptionAt(Go2ProfileGrooveX measurement, Go2UInt32 index)
{
    return Go2Measurement_LinkOptionAt(measurement, index);
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_EnableLink(Go2ProfileGrooveX measurement, Go2Bool enable)  
{
    return Go2Measurement_EnableLink(measurement, enable);  
}

GO2_EXPORT(Go2Bool) Go2ProfileGrooveX_LinkEnabled(Go2ProfileGrooveX measurement)  
{
    return Go2Measurement_LinkEnabled(measurement);  
}

GO2_EXPORT(Go2Status) Go2ProfileGrooveX_SetLink(Go2ProfileGrooveX measurement, Go2UInt32 link) 
{
    return Go2Measurement_SetLink(measurement, link); 
}

GO2_EXPORT(Go2UInt32) Go2ProfileGrooveX_Link(Go2ProfileGrooveX measurement) 
{
    return Go2Measurement_Link(measurement); 
}
