#
# Copyright © 2020 MSC.Software Corporation
#  
# Permission to use Scripts
#  
# Permission is granted to MSC.Software customers with valid licenses of the MSC Apex™ software 
# to use script files posted on this page (collectively “Scripts”) solely for customers’ own authorized 
# internal use in conjunction with licensed use of the MSC Apex software.  
# No other use is permitted.  No license to MSC Apex or other software is granted under this Permission.
#  
# SCRIPTS ARE PROVIDED ON AN "AS-IS" BASIS, WITH NO WARRANTIES OF ANY KIND.  USE OF THE SCRIPTS IS AT CUSTOMER'S SOLE RISK.
#  
# IN NO EVENT SHALL MSC.SOFTWARE CORPORATION, ITS AFFILIATES, SUBSIDIARIES, SUPPLIERS, AGENTS, REPRESENTATIVES OR EMPLOYEES BE LIABLE FOR ANY 
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, 
# STRICT LIABILITY, OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION USE OF THE SCRIPTS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
#  
# Customer shall indemnify, defend and hold MSC.Software Corporation, its affiliates, subsidiaries, suppliers, agents, 
# employees or representatives (collectively, “Indemnified Parties”) harmless from and against any third-party claims 
# brought against Indemnified Parties rising out of or in connection with Customer’s use of the Scripts.
#
import sys
import os
import apex_sdk
import clr

#.NET references
import System
import System.Windows.Controls as WPFControls
from System.Windows.Automation import AutomationProperties
from Microsoft.Win32 import OpenFileDialog
import System.Windows.Media as WPFMedia


#setting pre-defined properties of tool_propertyContainer
def getUIContent():
	my_toolProperty = apex_sdk.ToolPropertyContainer()

	my_toolProperty.TitleText = "Edit Contacts"

	file_path = os.path.dirname(os.path.realpath(__file__))
	my_toolProperty.TitleImageUriString = os.path.dirname(file_path) + './res/editContacts.png'


	my_toolProperty.WorkFlowInstructions = """<HTML><BODY>
	<P><SPAN> </SPAN></P>
	<P STYLE=\"font-size:10;\"><SPAN>
	Edit Contact Pairs. Custom Attributes are added to the contact pairs that are being processed from the Export Utils tool
	</SPAN></P>
	<P STYLE=\"font-size:10;\"><SPAN>Send questions, comments to stefan.tynelius@hexagon.com <br>
	Elvis sightings are as usual reported to larry.pearce@hexagon.com</SPAN></P></BODY></HTML>"""



	#handle apply button (green) click event
	my_toolProperty.AppliedCommand = apex_sdk.ActionCommand(System.Action(HandleApplyButton))
	# handle exit button (red) click event
	my_toolProperty.ExitCommand = apex_sdk.ActionCommand(System.Action(HandleExitButton))

	my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent()

	#define pickFiterTools
	my_toolProperty.ShowPickChoice = True
	my_toolProperty.IsCustomTool = True
	#setPickFilterTools()
	my_toolProperty.PickFilterList = setPickFilterTools()

	return my_toolProperty

def getCustomToolPropertyContent():

	my_Grid = WPFControls.Grid()

	createLayout(my_Grid, 20, 2)
	col=0
	row = 1


	try:
		defaultContactType=SettingsD['NASTRAN_JOB_SETUP']['SOL400DefaultContactType'].upper()
		if defaultContactType != "GLUE":
			defaultContactType="TOUCH"
		else:
			defaultContactType="GLUE"

	except:
		defaultContactType="GLUE"


	try:
		default_TouchingContactError=float(SettingsD['NASTRAN_JOB_SETUP']['SOL400TouchingContactError'])
	except:
		default_TouchingContactError=0.1

	try:
		default_GlueContactError=float(SettingsD['NASTRAN_JOB_SETUP']['SOL400GlueContactError'])
	except:
		default_GlueContactError=0.5	

	try:
		default_Friction=float(SettingsD['NASTRAN_JOB_SETUP']['SOL400DefaultFriction'])
	except:
		default_Friction=0.15


	#global showBodiessTextBox
	#showBodiessTextBox = createDataBox2(my_Grid, "Show Bodies", row, 1)
	#row += 1

	#WPFControls.Grid.SetColumnSpan(showBodiessTextBox, 2)

	showBodiesBtn = WPFControls.Button()
	showBodiesBtn.Content="Load Settings"
	#showBodiesBtn.Background = WPFMedia.Brushes.DeepSkyBlue

	#WPFControls.Grid.SetColumnSpan(showBodiesBtn, 2)

	WPFControls.Grid.SetRow(showBodiesBtn, row)
	WPFControls.Grid.SetColumn(showBodiesBtn, col)

	#Link a function to the Button "Click" event 
	#This function will be called every time the Button is clicked
	showBodiesBtn.Click+=HandleShowBodiesBtn

	# Add the controls to the Grid
	my_Grid.Children.Add(showBodiesBtn)	
	row += 1	

	# Add text blocks to show contact body names
	global body1textBlock
	body1textBlock=createTextBlock(my_Grid, "Body1", row, col)
	body1textBlock.Foreground = WPFMedia.Brushes.Red

	#add drobox for contact type
	global body1ContactBodyTypeBlock
	body1ContactBodyTypeBlock=createComboBoxOnly(my_Grid, ["Flexible"], 0, row, 1)
	#body1ContactBodyTypeBlock=createComboBoxOnly(my_Grid, ["Flexible", "Rigid"], 0, row, 1)
	row += 1

	global body2textBlock
	body2textBlock=createTextBlock(my_Grid, "Body2", row, col)
	body2textBlock.Foreground = WPFMedia.Brushes.LimeGreen
	

	#add drobox for contact type
	global body2ContactBodyTypeBlock
	#body2ContactBodyTypeBlock=createComboBoxOnly(my_Grid, ["Flexible", "Rigid"], 0, row, 1)
	body2ContactBodyTypeBlock=createComboBoxOnly(my_Grid, ["Flexible"], 0, row, 1)
	
	row += 1

	global contactTypeTextBox,  contactTypeComboBox
	contactTypeComboBox, contactTypeTextBox = createComboBox(my_Grid, "Contact Type:", ["Glue", "Touch"], 1, row, col)
	if defaultContactType=="GLUE":
		contactTypeComboBox.SelectedIndex = 0
	else:
		contactTypeComboBox.SelectedIndex = 1
	row += 1
	choices = contactTypeComboBox.SelectedValue.ToString().split(":")
	choice = choices[len(choices)-1].lstrip().rstrip()
	#
	contactTypeComboBox.SelectionChanged += contactTypeComboBoxCB
	#contactTypeTextBox       = System.Windows.Visibility.Collapsed
	#contactTypeComboBox        = System.Windows.Visibility.Collapsed





	#===


	global defaultTouchingTolTextBox,  defaultTouchingTolTextBlock
	defaultTouchingTolTextBox, defaultTouchingTolTextBlock= createDataBox(my_Grid, "Tocuhing Contact Tol.", str(default_TouchingContactError), row, col)
	if choice=="Glue":
		defaultTouchingTolTextBox.Visibility = System.Windows.Visibility.Collapsed
		defaultTouchingTolTextBlock.Visibility       = System.Windows.Visibility.Collapsed
	else:
		defaultTouchingTolTextBox.Visibility = System.Windows.Visibility.Visible
		defaultTouchingTolTextBlock.Visibility       = System.Windows.Visibility.Visible
	row += 1

	global defaultGlueTolTextBox,  defaultGlueTolTextBlock
	defaultGlueTolTextBox, defaultGlueTolTextBlock= createDataBox(my_Grid, "Glue Contact Tol.", str(default_GlueContactError), row, col)
	if choice=="Glue":
		defaultGlueTolTextBox.Visibility = System.Windows.Visibility.Visible
		defaultGlueTolTextBlock.Visibility       = System.Windows.Visibility.Visible
	else:
		defaultGlueTolTextBox.Visibility = System.Windows.Visibility.Collapsed
		defaultGlueTolTextBlock.Visibility       = System.Windows.Visibility.Collapsed
	row += 1

	global defaultFrictTextBox,  defaultFrictTextBlock
	defaultFrictTextBox, defaultFrictTextBlock= createDataBox(my_Grid, "Friction", str(default_Friction), row, col)
	if choice=="Glue":
		defaultFrictTextBox.Visibility = System.Windows.Visibility.Collapsed
		defaultFrictTextBlock.Visibility       = System.Windows.Visibility.Collapsed
	else:
		defaultFrictTextBox.Visibility = System.Windows.Visibility.Visible
		defaultFrictTextBlock.Visibility       = System.Windows.Visibility.Visible
	row += 1

	global biasTextBox,  biasTextBlock
	biasTextBox, biasTextBlock= createDataBox(my_Grid, "Contact Bias", "0.95", row, col)
	row += 1


	#
	global stressFreeInitial_Toggle		
	stressFreeInitial_Toggle  = createCheckBox(my_Grid, "Stress Free Inititial Contact", 1, row, col)
	if choice=="Glue":
		stressFreeInitial_Toggle.Visibility = System.Windows.Visibility.Collapsed
	else:
		stressFreeInitial_Toggle.Visibility = System.Windows.Visibility.Visible
	row += 1

	#
	global retainGapOverlaps_Toggle		
	retainGapOverlaps_Toggle  = createCheckBox(my_Grid, "Retain Gap Overlaps", 1, row, col)
	if choice=="Glue":
		retainGapOverlaps_Toggle.Visibility = System.Windows.Visibility.Visible
	else:
		retainGapOverlaps_Toggle.Visibility = System.Windows.Visibility.Collapsed
	row += 1

	return my_Grid


def contactTypeComboBoxCB(sender, event):

	global contactTypeComboBox
	global defaultTouchingTolTextBox,  defaultTouchingTolTextBlock
	global defaultGlueTolTextBox,  defaultGlueTolTextBlock
	global defaultFrictTextBox,  defaultFrictTextBlock

	choices = contactTypeComboBox.SelectedValue.ToString().split(":")
	choice = choices[len(choices)-1].lstrip().rstrip()

	if choice == "Glue":
		defaultTouchingTolTextBox.Visibility       = System.Windows.Visibility.Collapsed
		defaultTouchingTolTextBlock.Visibility         = System.Windows.Visibility.Collapsed
		defaultFrictTextBox.Visibility = System.Windows.Visibility.Collapsed
		defaultFrictTextBlock.Visibility       = System.Windows.Visibility.Collapsed
		defaultGlueTolTextBox.Visibility       = System.Windows.Visibility.Visible
		defaultGlueTolTextBlock.Visibility         = System.Windows.Visibility.Visible
		stressFreeInitial_Toggle.Visibility = System.Windows.Visibility.Collapsed
		retainGapOverlaps_Toggle.Visibility = System.Windows.Visibility.Visible





	else:
		defaultTouchingTolTextBox.Visibility       = System.Windows.Visibility.Visible
		defaultTouchingTolTextBlock.Visibility         = System.Windows.Visibility.Visible
		defaultFrictTextBox.Visibility = System.Windows.Visibility.Visible
		defaultFrictTextBlock.Visibility       = System.Windows.Visibility.Visible
		defaultGlueTolTextBox.Visibility       = System.Windows.Visibility.Collapsed
		defaultGlueTolTextBlock.Visibility         = System.Windows.Visibility.Collapsed
		stressFreeInitial_Toggle.Visibility = System.Windows.Visibility.Visible
		retainGapOverlaps_Toggle.Visibility = System.Windows.Visibility.Collapsed




def createLayout(parent, numRows, numCols):
	for k in range(numRows):
		parent.RowDefinitions.Add(WPFControls.RowDefinition())
	for k in range(numCols):
		parent.ColumnDefinitions.Add(WPFControls.ColumnDefinition())


def createComboBox(parent, title, labels, selected, row, col):
	textBlock = WPFControls.TextBlock()
	textBlock.Text = title
	WPFControls.Grid.SetRow(textBlock, row)
	WPFControls.Grid.SetColumn(textBlock, col)

	parent.Children.Add(textBlock)

	comboBox = WPFControls.ComboBox()
	for label in labels:
		item = WPFControls.ComboBoxItem()
		item.Content=label
		comboBox.Items.Add(item)

	WPFControls.Grid.SetRow(comboBox, row)
	WPFControls.Grid.SetColumn(comboBox, col+1)

	if selected > len(labels): selected = 0
	comboBox.SelectedIndex=str(selected)

	parent.Children.Add(comboBox)

	return comboBox, textBlock
	
def createComboBoxOnly(parent,  labels, selected, row, col):

	comboBox = WPFControls.ComboBox()
	for label in labels:
		item = WPFControls.ComboBoxItem()
		item.Content=label
		comboBox.Items.Add(item)

	WPFControls.Grid.SetRow(comboBox, row)
	WPFControls.Grid.SetColumn(comboBox, col)

	if selected > len(labels): selected = 0
	comboBox.SelectedIndex=str(selected)

	parent.Children.Add(comboBox)

	return comboBox	
	
	

def createTextBlock(parent, text, row, col):
	textBlock = WPFControls.TextBlock()
	textBlock.Text = text

	textBlock.Margin = System.Windows.Thickness(5.)

	WPFControls.Grid.SetRow(textBlock, row)
	WPFControls.Grid.SetColumn(textBlock, col)
	parent.Children.Add(textBlock)

	return textBlock



def updateComboBox(comboBox, comboItems):

	for comboItem in comboItems:
		item = WPFControls.ComboBoxItem()
		item.Content=comboItem
		comboBox.Items.Add(item)

	comboBox.SelectedIndex="0"

def createTextBlock(parent, text, row, col):
	textBlock = WPFControls.TextBlock()
	textBlock.Text = text

	textBlock.Margin = System.Windows.Thickness(5.)

	WPFControls.Grid.SetRow(textBlock, row)
	WPFControls.Grid.SetColumn(textBlock, col)
	parent.Children.Add(textBlock)

	return textBlock


def createTextBox(parent, value, row, col):
	textBox =WPFControls.TextBox()

	textBox.Margin = System.Windows.Thickness(5.)

	WPFControls.Grid.SetRow(textBox, row)
	WPFControls.Grid.SetColumn(textBox, col)
	textBox.Text=value

	parent.Children.Add(textBox)

	return textBox


def createDataBox(parent, title, value, row, col):
	textBlock = WPFControls.TextBlock()
	textBlock.Text = title
	WPFControls.Grid.SetRow(textBlock, row)
	WPFControls.Grid.SetColumn(textBlock, col)

	textBox =WPFControls.TextBox()
	WPFControls.Grid.SetRow(textBox, row)
	WPFControls.Grid.SetColumn(textBox, col+1)
	textBox.Text=value

	parent.Children.Add(textBlock)
	parent.Children.Add(textBox)

	return textBox,textBlock

def createCheckBox2(parent, label, row, col):

	checkBox = WPFControls.CheckBox()
	checkBox.Content = label
	WPFControls.Grid.SetRow(checkBox, row)
	WPFControls.Grid.SetColumn(checkBox, col)

	parent.Children.Add(checkBox)

	return checkBox

def createDataBox2(parent, value, row, col):
	textBox =WPFControls.TextBox()
	WPFControls.Grid.SetRow(textBox, row)
	WPFControls.Grid.SetColumn(textBox, col)
	textBox.Text=value

	parent.Children.Add(textBox)

	return textBox

def createCheckBox(parent, title, active, row, col):
	myWrapPanel = WPFControls.WrapPanel()
	myWrapPanel.Orientation = WPFControls.Orientation.Vertical

	CheckBox = WPFControls.CheckBox()
	CheckBox.Content = title
	myWrapPanel.Children.Add(CheckBox)

	WPFControls.Grid.SetRow(myWrapPanel, row)
	WPFControls.Grid.SetColumn(myWrapPanel, col)
	CheckBox.IsChecked = System.Nullable[System.Boolean](active)

	parent.Children.Add(myWrapPanel)

	return CheckBox

#set pickFilers
#some pick choices are commented out
def setPickFilterTools():
	pickChoices = System.Collections.Generic.List[System.String]()

	#exclusive picking and visibility picking	
	pickChoices.Add(apex_sdk.PickFilterTypes.ExclusivePicking)
	pickChoices.Add(apex_sdk.PickFilterTypes.VisibilityPicking)

	#Assembly and part
	#pickChoices.Add(apex_sdk.PickFilterTypes.Assembly)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Part)

	#Bodies	
	#pickChoices.Add(apex_sdk.PickFilterTypes.SolidMesh)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Solid)
	#pickChoices.Add(apex_sdk.PickFilterTypes.SurfaceMesh)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Surface)
	#pickChoices.Add(apex_sdk.PickFilterTypes.CurveMesh)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Curve)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Point)

	#features
	#pickChoices.Add(apex_sdk.PickFilterTypes.CellMesh)
	#pickChoices.Add(apex_sdk.PickFilterTypes.FaceMesh)
	#pickChoices.Add(apex_sdk.PickFilterTypes.EdgeMesh)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Cell)
	#pickChoices.Add(apex_sdk.PickFilterTypes.VertexMesh)

	#Lower Dimensional Entities
	#pickChoices.Add(apex_sdk.PickFilterTypes.Element3D)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Element2D)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Face)
	#pickChoices.Add(apex_sdk.PickFilterTypes.MeshSeed)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Element1D)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Edge)
	#pickChoices.Add(apex_sdk.PickFilterTypes.SeedPoint)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Node)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Vertex)

	#Sub Lower Dimensional Entities
	#pickChoices.Add(apex_sdk.PickFilterTypes.ElementEdge)
	#pickChoices.Add(apex_sdk.PickFilterTypes.ElementFace)

	#Interactions and connections
	#pickChoices.Add(apex_sdk.PickFilterTypes.DiscreteTie)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Connector)
	#pickChoices.Add(apex_sdk.PickFilterTypes.EdgeTie)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Joint)
	pickChoices.Add(apex_sdk.PickFilterTypes.Glue)
	#LBCs
	#pickChoices.Add(apex_sdk.PickFilterTypes.Pressure)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Gravity)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Constraint)
	#pickChoices.Add(apex_sdk.PickFilterTypes.ForceMoment)
	#pickChoices.Add(apex_sdk.PickFilterTypes.EnforcedMotion)

	#Attributes and other objects
	#pickChoices.Add(apex_sdk.PickFilterTypes.CompositeZone)
	#pickChoices.Add(apex_sdk.PickFilterTypes.LayeredPanel)
	#pickChoices.Add(apex_sdk.PickFilterTypes.InterfacePoint)
	#pickChoices.Add(apex_sdk.PickFilterTypes.PointMass)
	#pickChoices.Add(apex_sdk.PickFilterTypes.BeamSpan)
	#pickChoices.Add(apex_sdk.PickFilterTypes.Offset)

	#Sensors
	#pickChoices.Add(apex_sdk.PickFilterTypes.MotionEnvelopeSensor)
	#pickChoices.Add(apex_sdk.PickFilterTypes.ClearanceSensor)
	#pickChoices.Add(apex_sdk.PickFilterTypes.CrossSectionSensor)
	#pickChoices.Add(apex_sdk.PickFilterTypes.PointSensor)

	#Coordinate system
	#pickChoices.Add(apex_sdk.PickFilterTypes.CoordinateSystem)

	#Tool Registration
	#Tool Name has to be the same
	#apex_sdk.PickFilterRegistration.RegisterTool("Auto Tie Nodes", pickChoices)
	return pickChoices

#Function to handle the Import Button "Click" event
#This function gets called every time the Button is clicked
@apex_sdk.errorhandler
def HandleShowBodiesBtn(sender,args):

	file_path = os.path.dirname(os.path.realpath(__file__))
	script_path= os.path.join(file_path, 'highlightBodies.py')
	apex_sdk.runScriptFunction(script_path, "main", callback=highlightBodies)


@apex_sdk.errorhandler
def HandleApplyButton():
	# Create a Dictionary to store the user defined tool data  
	dictionary = {}

	choices = contactTypeComboBox.SelectedValue.ToString().split(":")
	choice = choices[len(choices)-1].lstrip().rstrip()
	dictionary["contactType"] = choice

	dictionary["TouchTol"] = defaultTouchingTolTextBox.Text
	dictionary["GlueTol"] = defaultGlueTolTextBox.Text
	dictionary["Friction"] = defaultFrictTextBox.Text
	dictionary["Bias"] = biasTextBox.Text
	dictionary["StressFreeInitial"] = stressFreeInitial_Toggle.IsChecked
	dictionary["RetainGapOverlaps"] =retainGapOverlaps_Toggle.IsChecked
	
	choices = body1ContactBodyTypeBlock.SelectedValue.ToString().split(":")
	choice = choices[len(choices)-1].lstrip().rstrip()
	dictionary["body1Type"] = choice
	
	choices = body2ContactBodyTypeBlock.SelectedValue.ToString().split(":")
	choice = choices[len(choices)-1].lstrip().rstrip()
	dictionary["body2Type"] = choice
	
	file_path = os.path.dirname(os.path.realpath(__file__))
	script_path= os.path.join(file_path, 'editContacts.py')

	apex_sdk.runScriptFunction(script_path, "main", dictionary)



# exit button (red) from tool header
@apex_sdk.errorhandler
def HandleExitButton():
	print("HandleExitButton")
	file_path = os.path.dirname(os.path.realpath(__file__))
	script_path= os.path.join(file_path, 'editContacts.py')
	# Create a Dictionary to store the user defined tool data  
	dictionary = {}

	#choices = frameTypeComboBox.SelectedValue.ToString().split(":")
	#choice = choices[len(choices)-1].lstrip().rstrip()

	apex_sdk.runScriptFunction(script_path, "exectuteOnExit", dictionary)


#This function receives data from the Script API function and updates the Tool UI 
@apex_sdk.errorhandler
def highlightBodies():
	global defaultTouchingTolTextBox, defaultTouchingTolTextBlock
	global defaultGlueTolTextBox, defaultTouchingTolTextBlock
	global biasTextBox, biasTextBlock
	global defaultFrictTextBox, defaultFrictTextBlock
	global contactTypeComboBox, contactTypeTextBox

	global body1textBlock, body2textBlock

	global body1_name
	global body2_name
	
	global body1ContactBodyTypeBlock, body2ContactBodyTypeBlock
	

	ret_dict = apex_sdk.getScriptFunctionReturnData()

	#body1_name=ret_dict['body1']
	#body2_name=ret_dict['body2']

	body1textBlock.Text=ret_dict['body1']
	body2textBlock.Text=ret_dict['body2']

	try:
		contactType=ret_dict["contactType"]
	except:
		contactType=""

	#contactTypeTextBox       = System.Windows.Visibility.Visible
	#contactTypeComboBox         = System.Windows.Visibility.Visible
	#biasTextBox.Visibility       = System.Windows.Visibility.Visible
	#biasTextBox.biasTextBlock       = System.Windows.Visibility.Visible
	
	if body1textBlock.Text=='Multiple Selections' or body1textBlock.Text=='None':
		body1ContactBodyTypeBlock.Visibility         = System.Windows.Visibility.Collapsed
		body2ContactBodyTypeBlock.Visibility         = System.Windows.Visibility.Collapsed
		body1textBlock.Foreground = WPFMedia.Brushes.Orange
		body2textBlock.Foreground = WPFMedia.Brushes.Orange
		
	else:
		body1ContactBodyTypeBlock.Visibility         = System.Windows.Visibility.Visible
		body2ContactBodyTypeBlock.Visibility         = System.Windows.Visibility.Visible
		body1textBlock.Foreground = WPFMedia.Brushes.Red
		body2textBlock.Foreground = WPFMedia.Brushes.LimeGreen

	if contactType == "Touch":
		contactTypeComboBox.SelectedIndex = 1
		defaultTouchingTolTextBox.Text = ret_dict["Tolerance"]
		defaultFrictTextBox.Text = ret_dict["Friction"]
		biasTextBox.Text = ret_dict["Bias"]

		#defaultTouchingTolTextBox.Visibility       = System.Windows.Visibility.Visible
		#defaultTouchingTolTextBlock.Visibility         = System.Windows.Visibility.Visible
		#defaultFrictTextBox.Visibility = System.Windows.Visibility.Visible
		#defaultFrictTextBlock.Visibility       = System.Windows.Visibility.Visible
		#defaultGlueTolTextBox.Visibility       = System.Windows.Visibility.Collapsed
		#defaultGlueTolTextBlock.Visibility         = System.Windows.Visibility.Collapsed	


	elif contactType == "Glue":
		contactTypeComboBox.SelectedIndex = 0
		defaultGlueTolTextBox.Text = ret_dict["Tolerance"]
		biasTextBox.Text = ret_dict["Bias"]

		#defaultTouchingTolTextBox.Visibility       = System.Windows.Visibility.Collapsed
		#defaultTouchingTolTextBlock.Visibility         = System.Windows.Visibility.Collapsed
		#defaultFrictTextBox.Visibility = System.Windows.Visibility.Collapsed
		#defaultFrictTextBlock.Visibility       = System.Windows.Visibility.Collapsed
		#defaultGlueTolTextBox.Visibility       = System.Windows.Visibility.Visible
		#defaultGlueTolTextBlock.Visibility         = System.Windows.Visibility.Visible
