Challenge

Creating widget for reversing normals in Hypermesh using tcl/tk

AIM: To create a widget containing buttons for toggling normals display and for reversing the normals in Hypermesh using tcl/tk.

PROCEDURE:

The code prepared in tcl/tk for creating the required widget is given below:

*setnormalsdisplaytype 1
*setsurfacenormalsdisplaytype 1
*createmark elems 1 "displayed"
proc box {} {tk_messageBox -message "No elements were selected" -icon warning -type ok}
set a .window
catch {destroy $a}
toplevel $a -class TopClass
wm title $a "Normals"
wm geometry $a 380x130+400+400
wm resizable $a 0 0
wm deiconify $a 
button $a.01 -text "Normals on" -font {times 20 bold} -justify center -command {*createmark elems 1 "displayed";*normalsdisplay elems 1 1} 
place $a.01 -x 10 -y 10 -height 35 -width 350
button $a.02 -text "Normals off" -font {times 20 bold} -justify center -command {*createmark elems 1 "displayed"; *normalsoff} 
place $a.02 -x 10 -y 50 -height 35 -width 350
button $a.03 -text "Reverse normals" -font {times 20 bold} -justify center -command {
*createmarkpanel elems 2 "Select elements for reversing normal"; set z [hm_marklength elems 2]
if {$z!=0} {*normalsreverse elems 2} else {puts [set prompt [box]]}
*normalsoff}
place $a.03 -x 10 -y 90 -height 35 -width 350

The breakdown of the code is given below:

*setnormalsdisplaytype 1
*setsurfacenormalsdisplaytype 1
*createmark elems 1 "displayed"

The first line sets the display type of normals to "colour" mode. The second line sets the surface normals display type to "colour" mode. The third line creates a mark containing the list of all displayed elements.

proc box {} {tk_messageBox -message "No elements were selected" -icon warning -type ok}
set a .window
catch {destroy $a}
toplevel $a -class TopClass
wm title $a "Normals"
wm geometry $a 380x130+400+400
wm resizable $a 0 0
wm deiconify $a 

The first line creates a procedure named "box" which creates a message displaying "No elements were selected" with the icon "warning" and type "ok". This will, later on, be used in the code to display a prompt if no elements are selected for reversal by the user. The next few lines create a window with variable name "a" and dimensions 380x130 which is non-resizable and titled "Normals".

button $a.01 -text "Normals on" -font {times 20 bold} -justify center -command {*createmark elems 1 "displayed";*normalsdisplay elems 1 1} 
place $a.01 -x 10 -y 10 -height 35 -width 350
button $a.02 -text "Normals off" -font {times 20 bold} -justify center -command {*createmark elems 1 "displayed"; *normalsoff} 
place $a.02 -x 10 -y 50 -height 35 -width 350

These lines create two buttons named "Normals on" and "Normals off" with variable names "a.01" and "a.02" respectively. The "Normals on" button has a command which creates a mark number 1 with all displayed elements. Then these elements have their normals displayed. The "Normals off" button also creates mark number 1 with all displayed elements but turns off all the normals.

button $a.03 -text "Reverse normals" -font {times 20 bold} -justify center -command {
	*createmarkpanel elems 2 "Select elements for reversing normal"; set z [hm_marklength elems 2]
	if {$z!=0} {*normalsreverse elems 2} else {puts [set prompt [box]]}
	*normalsoff}
place $a.03 -x 10 -y 90 -height 35 -width 350

The final button is named "Reverse normals" which creates a panel for selecting elements to be reversed. The user is given a panel and has to select elements that they want to reverse the normals for. These elements are then stored in mark number 2. Next, the length of these elements is stored in a variable "z". If the user does not select any elements, then z becomes 0. If z is 0, then the prompt is shown displaying that "No elements were selected" which was coded in the procedure named "Box" earlier. If z is not zero, then the selected elements in mark 2 have their normals reversed.

The widget is as shown below:

When normals are turned on:

Blue and red colour indicate opposite normal directions. When normals are turned off:

When we click on "Reverse normals", the panel shows up as follows:

When elements are selected for reversal and "proceed" is clicked, the following change occurs to the normals:

The elements selected went from blue to red, i.e reversing their normals. If no element is chosen by the user, the following prompt is shown:

To create keyboard shortcuts, create new procedures in the file as shown below:

proc normon {} {*createmark elems 1 "displayed";*normalsdisplay elems 1 1}
proc normoff {} {*createmark elems 1 "displayed"; *normalsoff}
proc revnorm {} {*createmarkpanel elems 2 "Select elements for reversing normal"
	set z [hm_marklength elems 2]
	if {$z!=0} {*normals elems 2} else {puts [set prompt [box]]}; *normalsoff}

Then include them in Hypermesh by going to Tools => Keyboard settings and assigning keys to each procedure as shown below:

CONCLUSION: The required widget for showing/hiding normals and reversing normals for selected elements was successfully coded using tcl/tk.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.