#
# 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.
#
# MSC Apex - User Defined Tools using Python Scripts
# Simple Layout UI Example
# 
import sys
import os
import apex_sdk
import clr

# .NET references
import System
import System.Windows.Controls as WPFControls

# Define current file path of example
current_file_path = os.path.dirname(os.path.realpath(__file__))


# Set pre-defined properties of ToolPropertyContainer
def getUIContent():

   my_toolProperty = apex_sdk.ToolPropertyContainer()

   # Provide an icon and a name for the tool property panel
   my_toolProperty.TitleImageUriString = os.path.join(os.path.dirname(current_file_path), r"res\Robot_48.png")
   my_toolProperty.TitleText = "Simple Layout"   

   # Define UI
   my_toolProperty.ToolPropertyContent = getCustomToolPropertyContent()
  
   return my_toolProperty


# Define Layout and Components
def getCustomToolPropertyContent():

   # Create a Grid
   my_Grid = WPFControls.Grid()
   
   # Add 3 Rows and Two Columns
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())

   my_Grid.ColumnDefinitions.Add(WPFControls.ColumnDefinition())
   my_Grid.ColumnDefinitions.Add(WPFControls.ColumnDefinition())

   # Row 0
   # Create a label (TextBlock)
   # Set it's Text value
   # Assign it to Row 0, Column 0
   meshTextBlock = WPFControls.TextBlock()
   meshTextBlock.Text = "Mesh Size:"
   WPFControls.Grid.SetRow(meshTextBlock, 0)
   WPFControls.Grid.SetColumn(meshTextBlock, 0)
   global meshSizeTextBox

   # Create an empty input TextBox assign it to Row 0, Column 1
   meshSizeTextBox = WPFControls.TextBox()
   WPFControls.Grid.SetRow(meshSizeTextBox, 0)
   WPFControls.Grid.SetColumn(meshSizeTextBox, 1)

   # Add the Row 0 controls to the Grid
   my_Grid.Children.Add(meshTextBlock)
   my_Grid.Children.Add(meshSizeTextBox)

   # Row 1
   # Create a label
   meshTypeTextBlock = WPFControls.TextBlock()
   meshTypeTextBlock.Text = "Mesh Type:"
   WPFControls.Grid.SetRow(meshTypeTextBlock, 1)
   WPFControls.Grid.SetColumn(meshTypeTextBlock, 0)

   # Create a Combo box, 
   # Define it's contents
   # Assign it to Row 1, Column 1
   global meshTypeComboBox
   meshTypeComboBox = WPFControls.ComboBox()
   item1 = WPFControls.ComboBoxItem();

   item1.Content = "Mixed"
   meshTypeComboBox.Items.Add(item1)
   item2 = WPFControls.ComboBoxItem()
   item2.Content = "Auto"
   meshTypeComboBox.Items.Add(item2)
   meshTypeComboBox.SelectedIndex="0"
   WPFControls.Grid.SetRow(meshTypeComboBox, 1)
   WPFControls.Grid.SetColumn(meshTypeComboBox, 1)

   # Add the Row 1 controls to the Grid
   my_Grid.Children.Add(meshTypeTextBlock)
   my_Grid.Children.Add(meshTypeComboBox)

   # Return the Grid
   return my_Grid
