# by apn master-master 03.12.2012
#puts "TODO OCC12345 ALL: An exception was caught"
#puts "TODO OCC12345 ALL: \\*\\* Exception \\*\\*.*"
puts "TODO OCC12345 ALL: Faulty OCC294"
puts "TODO OCC12345 ALL: Error : OCC294"
#puts "TODO OCC12345 ALL: TEST INCOMPLETE"

puts "========================"
puts " BUC60906 "
puts "========================"

cpulimit 3000
pload QAcommands

stepread [locate_data_file carcasse_gauche_simpl3.stp] a *

tpcompound com

set AllEdgesList [explode com e]
set list [split ${AllEdgesList}]
set NumbEdges [llength ${list}]
set delta 0.03
set IsSmallEdges 0

set IsOK 1

for {set i 1} {${i} <= ${NumbEdges}} {incr i} {
   set i_tolerance [maxtolerance com_${i}]
   set i_list [split ${i_tolerance} "\n\t"]
   set i_listLength [llength ${i_list}]
   if { ${i_listLength} < 7 } then {
      puts "BUC60906 - Error : i = ${i}"
      puts "BUC60906 - Error : i_listLength = ${i_listLength}"
   }
   set i_EdgeList [lindex ${i_list} 3]
   set i_MaxEdgeTolerance [lindex [split ${i_EdgeList}] [expr [llength [split ${i_EdgeList}] ] - 2] ]
   #puts "i_MaxEdgeTolerance = ${i_MaxEdgeTolerance}"
   if { ${i_MaxEdgeTolerance} > ${delta} } then {
       set IsSmallEdges 1
       puts "Remove ${i}-th small edge with a tolerance of ${delta} mm"

       if [catch { OCC294 shape_result com com_${i} } result] {
          puts "Error : OCC294"
          set IsOK 0
          break
       }

       renamevar shape_result com
   }
}
if { ${IsOK} == 1 } {
   if { ${IsSmallEdges} == 0 } {
      puts "Error : here are not small edges"
      set IsOK 0
   }
}

if { ${IsOK} == 1 } {
   set fullness [nbshapes com]
   regexp {VERTEX +: +([-0-9.+eE]+)} $fullness full vert
   regexp {EDGE +: +([-0-9.+eE]+)} $fullness full edg
   if { $edg == 0 || $vert == 0 } { 
      puts "Error : it is Faulty result" 
      set IsOK 0
   }
} 

if { ${IsOK} == 1 } {
   fixshape result com ${delta}
    checkshape result
   checkshape result r
}

set 2dviewer 0
