netgen/ng/occgeom.tcl

441 lines
14 KiB
Tcl
Raw Normal View History

2011-01-14 22:03:35 +05:00
if { [catch { load liboccvis[info sharedlibextension] Ng_OCC } result ] } {
2011-05-13 17:56:59 +06:00
# puts "cannot load occ"
# puts "error: $result"
2013-08-07 21:30:42 +06:00
}
2011-01-15 01:50:12 +05:00
2013-08-07 21:30:42 +06:00
if { [catch { Ng_OCCCommand isoccgeometryloaded }] } {
# dummy
2011-01-15 01:50:12 +05:00
proc rebuildoccdialog { } { }
2011-01-14 22:03:35 +05:00
} {
puts "OCC module loaded"
set hasocc yes
2011-01-15 01:50:12 +05:00
2011-01-14 22:03:35 +05:00
.ngmenu.geometry add separator
2011-01-11 01:27:43 +05:00
.ngmenu.geometry add command -label "IGES/STEP Topology Explorer/Doctor..." \
-command { occdialog; }
# Philippose - 30/01/2009
# Add menu item for local face mesh size definition in the
# TCL Gui
.ngmenu.geometry add command -label "Edit Face Mesh Size..." \
-command { surfacemeshsizedialog }
# .ngmenu.geometry add command -label "OCC Construction" \
# -command { Ng_OCCConstruction; }
set entities [ ]
proc occdialogbuildtree {} {
global entities
set w .occ_dlg
2016-11-11 16:13:33 +05:00
#set hlist [$w.mtre subwidget hlist]
2011-01-11 01:27:43 +05:00
set entities [Ng_GetOCCData getentities]
set nrentities [expr [llength $entities]]
if {$nrentities != 0} {
2016-11-11 16:13:33 +05:00
#$hlist add Topology -itemtype text -text "Topology"
2011-01-11 01:27:43 +05:00
2016-11-11 16:13:33 +05:00
#$hlist add Topology/CompSolids -itemtype text -text "Composite Solids" -data "Composite Solids"
#$hlist add Topology/FreeSolids -itemtype text -text "Free Solids" -data "Free Solids"
#$hlist add Topology/FreeShells -itemtype text -text "Free Shells" -data "Free Shells"
#$hlist add Topology/FreeFaces -itemtype text -text "Free Faces" -data "Free Faces"
#$hlist add Topology/FreeWires -itemtype text -text "Free Wires" -data "Free Wires"
#$hlist add Topology/FreeEdges -itemtype text -text "Free Edges" -data "Free Edges"
#$hlist add Topology/FreeVertices -itemtype text -text "Free Vertices" -data "Free Vertices"
$w.tree insert {Topology} end -id "CompSolids" -text "Composite Solids"
$w.tree insert {Topology} end -id "FreeSolids" -text "Free Solids"
$w.tree insert {Topology} end -id "FreeShells" -text "Free Shells"
$w.tree insert {Topology} end -id "FreeFaces" -text "Free Faces"
$w.tree insert {Topology} end -id "FreeWires" -text "Free Wires"
$w.tree insert {Topology} end -id "FreeEdges" -text "Free Edges"
$w.tree insert {Topology} end -id "FreeVertices" -text "Free Vertices"
2011-01-11 01:27:43 +05:00
# $hlist add SingularEntities -itemtype text -text "Entities marked as singular"
2016-11-11 16:13:33 +05:00
$w.tree item "Topology" -open true
2011-01-11 01:27:43 +05:00
set i [expr 0]
while {$i < $nrentities} {
set entity [lindex $entities [expr $i]]
incr i 1
set entityname [lindex $entities [expr $i]]
2016-11-11 16:13:33 +05:00
#$hlist add Topology/$entity -text $entityname -data $entityname
set myroot [string range $entity 0 [string last / $entity]-1]
2016-11-12 06:27:13 +05:00
$w.tree insert $myroot end -id $entity -text $entityname -value 1
2011-01-11 01:27:43 +05:00
incr i 1
2016-11-11 16:13:33 +05:00
#$w.mtre close Topology/$entity
2011-01-11 01:27:43 +05:00
}
2016-11-11 16:13:33 +05:00
#$w.mtre autosetmode
2011-01-11 01:27:43 +05:00
2016-11-11 16:13:33 +05:00
#$w.mtre open Topology
#$w.mtre close Topology/CompSolids
#$w.mtre close Topology/FreeSolids
#$w.mtre close Topology/FreeShells
#$w.mtre close Topology/FreeFaces
#$w.mtre close Topology/FreeWires
#$w.mtre close Topology/FreeEdges
#$w.mtre close Topology/FreeVertices
2011-01-11 01:27:43 +05:00
set i [expr 0]
while {$i < $nrentities} {
set entity [lindex $entities [expr $i]]
2016-11-11 16:13:33 +05:00
#$w.mtre close Topology/$entity
$w.tree item $entity -open false
2011-01-11 01:27:43 +05:00
incr i 2
}
set faces [Ng_OCCCommand getunmeshedfaceinfo]
set nrfaces [expr [llength $faces]]
if {$nrfaces >= 2} {
2016-11-11 16:13:33 +05:00
#$hlist add ErrorFaces -itemtype text -text "Faces with surface meshing error"
$w.tree insert {} end -id "ErrorFaces" -text "Faces with surface meshing error"
2016-11-11 16:13:33 +05:00
#$w.mtre open ErrorFaces
$w.tree item ErrorFaces -open true
2011-01-11 01:27:43 +05:00
set i [expr 0]
while {$i < $nrfaces} {
set entity [lindex $faces [expr $i]]
2016-11-11 16:13:33 +05:00
set myroot [string range $entity 0 [string last / $entity]-1]
2016-11-12 06:27:13 +05:00
if { [string length $myroot] == 0 } {
set myroot "ErrorFaces"
}
2011-01-11 01:27:43 +05:00
incr i 1
set entityname [lindex $faces [expr $i]]
2016-11-11 16:13:33 +05:00
#$hlist add ErrorFaces/$entity -text $entityname -data $entityname
$w.tree insert $myroot end -id $entity -text $entityname -value 0
2011-01-11 01:27:43 +05:00
incr i 1
}
}
set faces [Ng_OCCCommand getnotdrawablefaces]
set nrfaces [expr [llength $faces]]
if {$nrfaces >= 2} {
2016-11-11 16:13:33 +05:00
#$hlist add NotDrawableFaces -itemtype text -text "Faces impossible to visualize"
$w.tree insert {} -id NotDrawableFaces -text "Faces impossible to visualize"
#$w.mtre open NotDrawableFaces
$w.tree item NotDrawableFaces -open true
2011-01-11 01:27:43 +05:00
set i [expr 0]
while {$i < $nrfaces} {
set entity [lindex $faces [expr $i]]
2016-11-11 16:13:33 +05:00
set myroot [string range $entity 0 [string last / $entity]-1]
2016-11-12 06:27:13 +05:00
if { [string length $myroot ] == 0 } {
set myroot NotDrawableFaces
}
2011-01-11 01:27:43 +05:00
incr i 1
set entityname [lindex $faces [expr $i]]
2016-11-11 16:13:33 +05:00
#$hlist add NotDrawableFaces/$entity -text $entityname -data $entityname
2016-11-12 06:27:13 +05:00
$w.tree insert $myroot end -id $entity -text $entityname -value 0
2011-01-11 01:27:43 +05:00
incr i 1
}
}
2016-11-11 16:13:33 +05:00
#$w.mtre autosetmode
2011-01-11 01:27:43 +05:00
puts "done"
}
}
proc rebuildoccdialog {} {
if {[winfo exists .occ_dlg] == 1} {
2016-11-11 16:13:33 +05:00
.occ_dlg.tree delete [.occ_dlg.tree children Topology]
#[.occ_dlg.mtre subwidget hlist] delete all
2011-01-11 01:27:43 +05:00
occdialogbuildtree
}
}
proc checkoccloaded { } {
set isoccgeometryloaded [Ng_OCCCommand isoccgeometryloaded]
if {$isoccgeometryloaded == 0} {
puts "no IGES/STEP geometry loaded"
destroy .occ_dlg
}
}
#proc setocctolerance { } {
# set w .setocctolerance
#}
proc selectentity { entityname } {
global entities
set nrentities [expr [llength $entities]]
set i [expr 0]
while {$i < $nrentities} {
set entitylength []
set entity2 [lindex $entities [expr $i]]
incr i 1
set entityname2 [lindex $entities [expr $i]]
incr i 1
set entityname2 [string range $entityname2 0 [expr [string length $entityname]-1]]
if {$entityname == $entityname2} {
2016-11-12 06:27:13 +05:00
# #set hlist [.occ_dlg.mtre subwidget hlist]
# #.occ_dlg.mtre open Topology
# .occ_dlg.tree item Topology -open true
# puts $entity2
# set slashpos [string last "/" $entity2]
# set entity3 [string range $entity2 0 [expr $slashpos-1]]
# while {$slashpos != -1} {
# #.occ_dlg.mtre open Topology/$entity3
# .occ_dlg.tree item $entity3 -open true
# puts $entity3
# set slashpos [string last "/" $entity3]
# set entity3 [string range $entity3 0 [expr $slashpos-1]]
# }
2016-11-11 16:13:33 +05:00
#$hlist selection clear
2016-11-12 06:27:13 +05:00
.occ_dlg.tree see $entity2
.occ_dlg.tree selection set $entity2
2011-01-11 01:27:43 +05:00
}
}
}
proc occdialog { } {
uplevel 1 {
global entities
set selectvisual geometry
Ng_SetVisParameters
redraw
set w .occ_dlg
if {[winfo exists .occ_dlg] == 1} {
wm withdraw $w
wm deiconify $w
focus $w
} {
toplevel $w
2016-11-11 16:13:33 +05:00
ttk::treeview $w.tree
$w.tree insert {} end -id "Topology" -text "Topology"
pack $w.tree -fill both -expand yes
2011-01-11 01:27:43 +05:00
occdialogbuildtree
2016-11-12 06:27:13 +05:00
2016-11-11 16:13:33 +05:00
bind $w.tree <Double-1> {
set entityname [.occ_dlg.tree item [.occ_dlg.tree selection] -text ]
2016-11-12 06:27:13 +05:00
set rootname ""
if {[.occ_dlg.tree item [.occ_dlg.tree selection] -value] == 1 } {
set rootname "Topology"
}
2011-01-11 01:27:43 +05:00
set spacepos [string first " " $entityname]
2016-11-11 16:13:33 +05:00
set entitytype [string range $entityname 0 [expr $spacepos-1]]
2011-01-11 01:27:43 +05:00
set helpstring [string range $entityname [expr $spacepos+1] [expr [string length $entityname]-1]]
set spacepos2 [string first " " $helpstring]
2016-11-11 16:13:33 +05:00
set entitynumber [string range $helpstring 0 [expr $spacepos2-1]]
2011-01-11 01:27:43 +05:00
if {$rootname == "Topology"} {
Ng_OCCCommand highlightentity $entitytype $entitynumber
set selectvisual geometry
redraw
} {
set brackpos [string first " (" $entityname]
if {$brackpos != -1} {
set entityname [string range $entityname 0 $brackpos]
}
selectentity $entityname
}
2016-11-12 06:27:13 +05:00
}
2016-11-10 18:31:04 +05:00
ttk::button $w.cl -text "Close" -command {
2011-01-11 01:27:43 +05:00
destroy .occ_dlg
}
2016-11-10 18:31:04 +05:00
ttk::button $w.show -text "Show" -command {
2016-11-11 16:13:33 +05:00
set entityname [.occ_dlg.tree item [.occ_dlg.tree selection] -text ]
2011-01-11 01:27:43 +05:00
set spacepos [string first " " $entityname]
set entitytype [string range $entityname 0 [expr $spacepos-1]]
set helpstring [string range $entityname [expr $spacepos+1] [expr [string length $entityname]-1]]
set spacepos2 [string first " " $helpstring]
set entitynumber [string range $helpstring 0 [expr $spacepos2-1]]
Ng_OCCCommand show $entitytype $entitynumber
set selectvisual geometry
# Ng_SetVisParameters
redraw
}
2016-11-10 18:31:04 +05:00
ttk::button $w.hide -text "Hide" -command {
2016-11-11 16:13:33 +05:00
set entityname [.occ_dlg.tree item [.occ_dlg.tree selection] -text ]
2011-01-11 01:27:43 +05:00
set spacepos [string first " " $entityname]
set entitytype [string range $entityname 0 [expr $spacepos-1]]
set helpstring [string range $entityname [expr $spacepos+1] [expr [string length $entityname]-1]]
set spacepos2 [string first " " $helpstring]
set entitynumber [string range $helpstring 0 [expr $spacepos2-1]]
Ng_OCCCommand hide $entitytype $entitynumber
set selectvisual geometry
# Ng_SetVisParameters
redraw
}
2016-11-11 16:13:33 +05:00
ttk::button $w.swaporientation -text "Swap orientation" -command {
set entityname [.occ_dlg.tree item [.occ_dlg.tree selection] -text ]
2011-01-11 01:27:43 +05:00
set spacepos [string first " " $entityname]
set entitytype [string range $entityname 0 [expr $spacepos-1]]
set helpstring [string range $entityname [expr $spacepos+1] [expr [string length $entityname]-1]]
set spacepos2 [string first " " $helpstring]
set entitynumber [string range $helpstring 0 [expr $spacepos2-1]]
Ng_OCCCommand swaporientation $entitytype $entitynumber
set selectvisual geometry
# Ng_SetVisParameters
redraw
2016-11-11 16:13:33 +05:00
.occ_dlg.tree delete [.occ_dlg.tree children Topology]
#[.occ_dlg.mtre subwidget hlist] delete all
2011-01-11 01:27:43 +05:00
occdialogbuildtree
}
2016-11-10 18:31:04 +05:00
ttk::button $w.marksingular -text "Mark/Unmark as singular" -command {
2016-11-11 16:13:33 +05:00
set entityname [.occ_dlg.tree item [.occ_dlg.tree selection] -text ]
2011-01-11 01:27:43 +05:00
set spacepos [string first " " $entityname]
if { $spacepos != 0 } {
set entitytype [string range $entityname 0 [expr $spacepos-1]]
set helpstring [string range $entityname [expr $spacepos+1] [expr [string length $entityname]-1]]
set spacepos2 [string first " " $helpstring]
if { $spacepos2 != 0 } {
set entitynumber [string range $helpstring 0 [expr $spacepos2-1]]
2016-11-12 06:27:13 +05:00
puts $entitytype
puts $entitynumber
2011-01-11 01:27:43 +05:00
global ismarkedsingular
Ng_OCCCommand marksingular $entitytype $entitynumber
2016-11-12 06:27:13 +05:00
2011-01-11 01:27:43 +05:00
if { $ismarkedsingular == 0 } {
2016-11-12 06:27:13 +05:00
.occ_dlg.tree tag remove "Color" [.occ_dlg.tree selection]
2011-01-11 01:27:43 +05:00
} {
2016-11-11 16:13:33 +05:00
.occ_dlg.tree tag add "Color" [.occ_dlg.tree selection]
.occ_dlg.tree tag configure "Color" -foreground "red"
.occ_dlg.tree tag configure "Color" -background "blue"
2011-01-11 01:27:43 +05:00
}
}
2016-11-12 06:27:13 +05:00
}
2011-01-11 01:27:43 +05:00
}
2016-11-10 18:31:04 +05:00
ttk::checkbutton $w.zoomtohighlightedentity -text "Zoom to highlighted entity" \
2011-01-11 01:27:43 +05:00
-variable occoptions.zoomtohighlightedentity \
-command {
Ng_SetOCCVisParameters
if { ${occoptions.zoomtohighlightedentity} == 1} {
set selectvisual geometry
# Ng_SetVisParameters
Ng_OCCCommand redrawstatus 1
redraw
} {
Ng_OCCCommand redrawstatus 0
}
}
2016-11-10 18:31:04 +05:00
ttk::frame $w.healing -relief groove -borderwidth 3
2011-01-11 01:27:43 +05:00
2016-11-10 18:31:04 +05:00
ttk::button $w.healing.checkentities -text "Analyze geometry" -command {
2011-01-11 01:27:43 +05:00
set irregent [Ng_OCCCommand findsmallentities]
set w .occ_dlg
set nritems [expr [llength $irregent]]
set i [expr 0]
2016-11-12 06:27:13 +05:00
if {$nritems > 0 } {
if { [.occ_dlg.tree exists ProblematicEntities] == 1 } {
$w.tree delete ProblematicEntities
}
$w.tree insert {} end -id ProblematicEntities -text "Problematic Entities"
}
2011-01-11 01:27:43 +05:00
while {$i < $nritems} {
set entity [lindex $irregent [expr $i]]
incr i 1
set entityname [lindex $irregent [expr $i]]
2016-11-12 06:27:13 +05:00
#puts $entity
#puts $entityname
set myroot [string range $entity 0 [string last / $entity]-1]
if { [string length $myroot] == 0 } {
set myroot ProblematicEntities
}
$w.tree insert $myroot end -id $entity -text $entityname
2011-01-11 01:27:43 +05:00
incr i 1
}
2016-11-12 06:27:13 +05:00
$w.tree item ProblematicEntities -open true
2011-01-11 01:27:43 +05:00
}
2016-11-10 18:31:04 +05:00
# tixControl $w.healing.tolerance -label "Healing tolerance: " -integer false \
# -variable occoptions.tolerance -min 1e-9 -max 1e6 \
# -options {
# entry.width 6
# label.width 25
# label.anchor e
# }
ttk::frame $w.healing.tolerance
ttk::label $w.healing.tolerance.label -text "Healing tolerance: "
ttk::spinbox $w.healing.tolerance.sp -textvariable occoptions.tolerance -width 6 -increment 0.01 -validate focus -validatecommand "my_validatespinbox %W %P 12" \
-invalidcommand "my_invalidspinbox %W" -from -1e-9 -to 1e6
grid $w.healing.tolerance.label $w.healing.tolerance.sp
ttk::checkbutton $w.healing.fixsmalledges -text "Fix small edges" \
2011-01-11 01:27:43 +05:00
-variable occoptions.fixsmalledges
2016-11-10 18:31:04 +05:00
ttk::checkbutton $w.healing.fixspotstripfaces -text "Fix spot/strip faces" \
2011-01-11 01:27:43 +05:00
-variable occoptions.fixspotstripfaces
2016-11-10 18:31:04 +05:00
ttk::checkbutton $w.healing.sewfaces -text "Sew faces" \
2011-01-11 01:27:43 +05:00
-variable occoptions.sewfaces
2016-11-10 18:31:04 +05:00
ttk::checkbutton $w.healing.makesolids -text "Make solids" \
2011-01-11 01:27:43 +05:00
-variable occoptions.makesolids
2016-11-10 18:31:04 +05:00
ttk::checkbutton $w.healing.splitpartitions -text "Split partitions" \
2011-01-11 01:27:43 +05:00
-variable occoptions.splitpartitions
2016-11-10 18:31:04 +05:00
ttk::button $w.healing.heal -text "Heal geometry" -command {
2016-11-12 06:27:13 +05:00
#.occ_dlg.healing.tolerance.sp invoke
2011-01-11 01:27:43 +05:00
Ng_OCCCommand shapehealing
redraw
2016-11-11 16:13:33 +05:00
.occ_dlg.tree delete [.occ_dlg.tree children Topology]
#[.occ_dlg.mtre subwidget hlist] delete all
2011-01-11 01:27:43 +05:00
occdialogbuildtree
}
pack $w.healing.checkentities
pack $w.healing.tolerance $w.healing.fixsmalledges \
$w.healing.fixspotstripfaces $w.healing.sewfaces \
$w.healing.makesolids $w.healing.splitpartitions -anchor w
pack $w.healing.heal
pack $w.show $w.hide
pack $w.zoomtohighlightedentity -anchor w
# pack $w.checkentities
pack $w.swaporientation
pack $w.marksingular
pack $w.healing -fill x
pack $w.cl
wm withdraw $w
wm geom $w +100+100
wm deiconify $w
wm title $w "IGES/STEP Topology Explorer/Doctor"
focus .occ_dlg
}
}
}
2011-01-15 01:50:12 +05:00
}