puts "============"
puts "OCC25098"
puts "============"
puts ""
####################################################################################
# Visualization - Calculation of depth on selection of a wire is not accurate
####################################################################################

proc ParseEntityInfo {theInfoString} {
  set aStringArr [split $theInfoString " "]
  set aDepth ""
  set aDistance ""
  set aPoint ""
  set aType ""
  set aSize [llength $aStringArr]
  for {set aIdx 0} {$aIdx < $aSize} {incr aIdx} {
    set aItem [lindex $theInfoString $aIdx]
    if {[string compare $aItem "Depth:"] == 0} {
      set aDepth [string trim [lindex $theInfoString [expr $aIdx + 1]]]
    } elseif {[string compare $aItem "Distance:"] == 0} {
        set aDistance [string trim [lindex $theInfoString [expr $aIdx + 1]]]
    } elseif {[string compare $aItem "Point:"] == 0} {
        set aPoint [string trim [lindex $theInfoString [expr $aIdx + 1]]]
        append aPoint " "
        append aPoint [string trim [lindex $theInfoString [expr $aIdx + 2]]]
        append aPoint " "
        append aPoint [string trim [lindex $theInfoString [expr $aIdx + 3]]]
      } elseif {[string compare [string index $aItem 0] "("] == 0} {
        set aType [string trim $aItem]
    }
  }

  return [list $aDepth $aDistance $aPoint $aType]
}

pload VISUALIZATION MODELING
vinit

box b 10 10 10
vdisplay b
vremove b

explode b w
vdisplay b_5

vertex v1 10 0 0
vertex v2 10 10 0
edge e v1 v2
vdisplay e

vfit
vmoveto 240 300
set aOut [split [vstate -entities] "\n"]

# compare parameters of detected match: depth, distance and point
set aEdgeInfoList [ParseEntityInfo [lindex $aOut 1]]
set aWireInfoList [ParseEntityInfo [lindex $aOut 3]]
for {set aIdx 0} {$aIdx < 3} {incr aIdx} {
  if {[string equal [lindex $aEdgeInfoList $aIdx] [lindex $aWireInfoList $aIdx]] == 0} {
    set aDebugInfo "Characteristics are not equal at value nb: "
    append aDebugInfo [expr $aIdx + 1]
    puts $aDebugInfo
    set aDebugInfo "The values are: "
    append aDebugInfo [lindex $aEdgeInfoList $aIdx]
    append aDebugInfo " and "
    append aDebugInfo [lindex $aWireInfoList $aIdx]
    puts $aDebugInfo
    puts "ERROR"
    puts ""
  }
}

# checks that edge e is represented by correct shape and sensitive entity
if {[string equal [lindex $aEdgeInfoList 3] "(Select3D_SensitiveSegment)"] == 0} {
  puts "Wrong sensitive for segment! Value is: "
  puts [lindex $aEdgeInfoList 3]
  puts "Must be: (Select3D_SensitiveSegment)"
  puts "ERROR"
  puts ""
}

set aEdgeType [string trim [lindex $aOut 2]]
if {[string equal $aEdgeType "Detected Shape: BRep_TEdge"] == 0} {
  puts "Wrong type of edge! Value is: "
  puts $aEdgeType
  puts "Must be: Detected Shape: BRep_TEdge"
  puts "ERROR"
  puts ""
}

# checks that wire b_5 is represented by correct shape and sensitive entity
if {[string equal [lindex $aWireInfoList 3] "(Select3D_SensitiveWire)"] == 0} {
  puts "Wrong sensitive for wire! Value is: "
  puts [lindex $aWireInfoList 3]
  puts "Must be: (Select3D_SensitiveWire)"
  puts "ERROR"
  puts ""
}

set aWireType [string trim [lindex $aOut 4]]
if {[string equal $aWireType "Detected Shape: TopoDS_TWire"] == 0} {
  puts "Wrong type of wire! Value is: "
  puts $aWireType
  puts "Must be: Detected Shape: TopoDS_TWire"
  puts "ERROR"
  puts ""
}

set aWireSensitiveType [string trim [lindex $aOut 5]]
if {[string equal $aWireSensitiveType "Detected Child: Select3D_SensitiveCurve"] == 0} {
  puts "Wrong type of wire's inner sensitive! Value is: "
  puts $aWireSensitiveType
  puts "Must be: Detected Child: Select3D_SensitiveCurve"
  puts "ERROR"
}
