#=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~=~
#                    numgeo - GiD interface
#             Copyright (C) 2023-today Jan Machacek, Rahul Dogra
#=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~=~
#
# History
# - 28.11.2025, J. Machacek - Initial version, moved from numgeo.tcl
#
#
#=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~~=~=~

proc numgeo::draw_point_load { } {
    GiD_OpenGL draw -color $::gid_draw_opengl::rgb(orange)
    gid_draw_opengl::draw_point_load
}


proc numgeo::draw_surface_pressure { values_list } {
    foreach item $values_list {
        lassign $item key value unit
        set data($key) $value
        #set unit($key) $unit
    }
    set modulus $data(_value_)    
    if { $modulus > 0 } {
        set load_local_direction [list 0 -1 0] ;#considered positive pointing oposite to local normal
    } elseif { $modulus < 0 } {
        set load_local_direction [list 0 1 0] ;#considered positive pointing oposite to local normal
    } else {
        #the value could be set by other function field, intead as modulus, consider like positive modulus
        set load_local_direction [list 0 -1 0]
    }
    set dictionary [dict create load_type local load_vector $load_local_direction]    
    return $dictionary
}


proc numgeo::draw_loads_global { values_list } {
    foreach item $values_list {
        lassign $item key value unit
        set data($key) $value
    }

    set vx $data(_value_x_)
	set vy $data(_value_y_)
	set vz $data(_value_z_)
	
	set force [list $vx $vy $vz]

    set dictionary [dict create load_type global load_vector $force]    
    return $dictionary
}


proc my_loads_function_time { domNode } {
    set loads [list [list scalar]]   
    lappend loads [list interpolator_func x]
    return [join $loads ,]
}


proc my_loads_function_periodic { domNode } {
    set loads [list [list scalar]]   
    lappend loads [list interpolator_func Ai]
    return [join $loads ,]
}


proc numgeo::draw_dirichlet_disp { values_list } {

    foreach item $values_list {
        lassign $item key value unit
        set data($key) $value
    }
	
	if {$data(_x_) eq "fixed"} {
      set x 1
    } else {
      set x 0
    }
	if {$data(_y_) eq "fixed"} {
      set y 1
    } else {
      set y 0
    }
	if {$data(_z_) eq "fixed"} {
      set z 1
    } else {
      set z 0
    }
	
    #
    # Only 1 DoF constrained
    #
	if { $x == 1 && $y == 0 && $z == 0 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_1.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 1 0 0]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    } elseif { $x == 0 && $y == 1 && $z == 0 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_1.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 0 1 0]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    } elseif { $x == 0 && $y == 0 && $z == 1 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_1.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 0 0 1]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    #
    # 2 DoFs constrained
    #
    } elseif { $x == 1 && $y == 1 && $z == 0 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_xy.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 0 0 1]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    } elseif { $x == 1 && $y == 0 && $z == 1 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_2.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 1 0 0]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    } elseif { $x == 0 && $y == 1 && $z == 1 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_2.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 0 0 1]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    #
    # 3 DoFs constrained
    #
    } elseif { $x == 1 && $y == 1 && $z == 1 } {
      set full_filename [file join [numgeo::GetDir] symbols sym_bc_disp_3.msh]
      set color_lines black
      set color_surfaces coral
      set direction [list 0 0 1]
      set list_id [gid_draw_opengl::create_opengl_list_from_file_mesh_oriented_z_direction $full_filename $color_lines $color_surfaces $direction]
      return $list_id
    }
}