////////////////////////////////////////////////////////////////////////
package com.altair.hwpmtraining;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.beans.*;
import java.util.Vector;
import com.altair.hwm.interfaces.*;
import com.altair.hwm.beans.utils.*;
import com.altair.hwm.beans.utils.events.*;
import com.altair.hwm.comm.*;
import com.altair.hwm.comm.hm.*;
/**
* Title: HMImport
* Description: Launch an HM session and load a model in it.
* Copyright Copyright (c) 2001
* Company: Altair Engineering, Inc.
*/
public class HMImport extends HWMBasePanel implements ActionListener
//The path to the HM executable
protected String m_strHMExecPath = "";
//Session name for communicating with HWMCommHM
protected String m_strSessionName = HWMBeanUtils.DEF_HW_SESSION;
//* UI components used in this bean
protected HWMTextField m_txtFile = null;
protected HWMButton m_btnImport = null;
protected HWMFileBrowser m_hwmFileBrowser = null;
/**
* Constructor
*/
public HMImport()
try
jbInit();
}
catch(Exception exception)
exception.printStackTrace();
}
}
/**
* Builds GUI
* @throws Exception
*/
private void jbInit() throws Exception
//Set the layout of this panel as GridbagLayout
setLayout(new GridBagLayout());
//Create and add listeners to UI components
HWMLabel lblFile = new HWMLabel("File");
m_txtFile = new HWMTextField("");
m_btnImport = new HWMButton("Import");
m_hwmFileBrowser = new HWMFileBrowser();
m_btnImport.addActionListener(this);
m_hwmFileBrowser.addHWMCmdEventListener(new HWMCmdEventListener()
public void OnCmdSuccess(HWMCmdEvent hwmCmdEvent)
{
m_txtFile.setText(m_hwmFileBrowser.GetSelectedFilename());
}
public void OnCmdFailed(HWMCmdEvent hwmCmdEvent) {}
});
//Add tooltips
m_txtFile.setToolTipText("File to be imported into HM");
m_hwmFileBrowser.setToolTipText("File Browser");
m_btnImport.setToolTipText("Import the file in Hypermesh");
//Add the components to the panel
this.add(lblFile,
new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(9, 9, 9, 3), 0, 0));
this.add(m_txtFile,
new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
new Insets(9, 3, 9, 3), 0, 0));
this.add(m_hwmFileBrowser,
new GridBagConstraints(2, 0, 1, 1, 0.0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(9, 3, 9, 3), 0, 0));
this.add(m_btnImport,
new GridBagConstraints(3, 0, 1, 1, 0.0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(9, 3, 9, 9), 0, 0));
}
/**
* This method is called by the HWPM engine to set the interface with
* which the bean can communicate directly with the HWPM classes.
* @param hwmFrameWork The interface with which a bean can
* communicate with HWPM
*/
public void SetFrameWork(IHWMFrameWork hwmFrameWork)
super.SetFrameWork( hwmFrameWork );
}
/**
* The play method needs to execute the functionaliy. This may be
* invoked in the replay mode.
*/
public void Play()
this. ImportModel();
}
/**
* Callback for import model button and file type combo box
*/
public void actionPerformed(ActionEvent event)
Object objSource = event.getSource();
try
if(objSource == m_btnImport)
ImportModel();
}
catch (Exception exception)
exception.printStackTrace();
}
}
/**
* Imports the selected model into Hypermesh
* @throws Exception
*/
public void ImportModel() throws Exception
//First launch HyperMesh, if it has not already been
HWMCommMgr hwmCommMgr = GetFrameWork().GetCommMgr();
HWMCommHM commHM = hwmCommMgr.StartHM(m_strHMExecPath, null,
null, m_strSessionName);
//Send the command through commHM to load the model
String strHMFile = this.m_txtFile.getText();
strHMFile = strHMFile.replace('\\', '/');
String strCommand = "*readfile " + '"' + strHMFile + '"';
commHM.SendCommand(strCommand);
//Fire command success event
fireOnCmdSuccess(new HWMCmdEvent(this, 1));
}
/**
* Save the required props in the datamodel (so that they persist)
*/
public void SaveProperties()
//Get the datamodel
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
super.SaveProperties();
//Session Name
hwmDataModel.SetProperty(GetBeanName()+"::HW_SESSION_NAME",
this.m_strSessionName);
//HM exectable Path
hwmDataModel.SetProperty(GetBeanName()+"::HM_EXEC_PATH",
this.m_strHMExecPath);
//The HM Filename
hwmDataModel.SetProperty(GetBeanName()+"::HM_FILENAME",
this.m_txtFile.getText());
}
/**
* Get the required properties from the datamodel and initialize self
*/
public void ReadProperties()
String strTemp;
//Get the datamodel
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
super.ReadProperties();
//Session Name
strTemp = (String)
hwmDataModel.GetProperty(GetBeanName()+"::HW_SESSION_NAME");
if (strTemp != null) m_strSessionName = strTemp;
//HM executable Path
strTemp = (String)
hwmDataModel.GetProperty(GetBeanName()+"::HM_EXEC_PATH");
if (strTemp != null) m_strHMExecPath = strTemp;
//HM Filename
strTemp = (String)
hwmDataModel.GetProperty(GetBeanName()+"::HM_FILENAME");
if (strTemp != null) this.m_txtFile.setText(strTemp);
}
/**
* Returns the session name for HM communication
* @return String The session name for HM Comm
*/
public String GetSessionName()
return m_strSessionName;
}
/**
* Sets the session name for HM communication
* @param strSessionName The session name for HM Comm
*/
public void SetSessionName(String strSessionName)
m_strSessionName = strSessionName;
}
/**
* Gets path to the HM execuatable.
* @return String The full path to the HM executable
*/
public String GetHMExecPath()
return this.m_strHMExecPath;
}
/**
* Sets path to the HM execuatable that needs to be launched
* @param strHMPath The full path to the HM executable
*/
public void SetHMExecPath(String strHMPath)
m_strHMExecPath = strHMPath;
}
/**
* Enables the UI
*/
public void Enable()
this.setEnabled(true);
}
/**
* Disables the UI
*/
public void Disable()
this.setEnabled(false);
}
/**
* Enables/disable the UI
* @param bEnable If true the UI is enabled else disabled
*/
public void setEnabled( boolean bEnable )
this.m_btnImport.setEnabled(bEnable);
super.setEnabled(bEnable);
}
}
////////////////////////////////////////////////////////////////////////
package com.altair.hwpmtraining;
import java.beans.*;
import java.lang.reflect.*;
import com.altair.hwm.beans.utils.HWMSimpleBeanInfo;
/**
* Title: HMImportBeanInfo<p>
* Description: Beaninfo for HMImport<p>
* Company: Altair Engineering, Inc.<p>
*/
public class HMImportBeanInfo extends HWMSimpleBeanInfo
/**
* Constructor
*/
public HMImportBeanInfo()
super(HMImport.class);
}
/**
* Returns the Bean Descriptor for HMImport bean
* @returns HMImportBean BeanDescriptor
*/
public BeanDescriptor getBeanDescriptor()
BeanDescriptor beanDesc = new BeanDescriptor( m_classBeanSrc );
beanDesc.setDisplayName( "Import File");
beanDesc.setShortDescription("Imports file into HM");
return beanDesc;
}
/**
* Returns an array of PropertyDescriptors representing the
* properties of HMImport Bean.
*
* @returns A PropertyDescriptor array, representing the properties
* of the HMImport Bean and the properties of the base class
*/
public PropertyDescriptor[] getPropertyDescriptors()
try
//Session name
PropertyDescriptor propDescSessionName= new PropertyDescriptor(
"HW_SESSION_NAME", m_classBeanSrc,
"GetSessionName", "SetSessionName");
propDescSessionName.setDisplayName("HM Session Name");
propDescSessionName.setShortDescription(
"HM Session to which the commands are to be sent");
propDescSessionName.setBound(true);
//HM Executable Path
PropertyDescriptor propDescHMPath= new PropertyDescriptor(
"HM_EXEC_PATH", m_classBeanSrc,
"GetHMExecPath", "SetHMExecPath");
propDescHMPath.setDisplayName("HM Executable Path");
propDescHMPath.setShortDescription(
"The path to the HM executable to be launched");
propDescHMPath.setBound(true);
//Create an array of property descriptors
PropertyDescriptor[] arrPropDescs =
new PropertyDescriptor[] { propDescSessionName,
propDescHMPath };
return super.AppendPropertyDescriptors(arrPropDescs);
}
catch( IntrospectionException exceptionIntrospection)
exceptionIntrospection.printStackTrace();
return null;
}
}
/**
* Returns an array of MethodDescriptors in the HMImport bean
*
* @returns A MethodDescriptor array, containing the methods of the
* HMImport bean and the methods of the base class
*/
public MethodDescriptor[] getMethodDescriptors()
try
//ImportModel
Method methodImportModel = m_classBeanSrc.getMethod(
"ImportModel", null);
MethodDescriptor methDescImportModel = new
MethodDescriptor( methodImportModel );
//Create the array of method descriptors
MethodDescriptor[] arrmethDescriptors = { methDescImportModel};
return super.AppendMethodDescriptors(arrmethDescriptors);
}
catch( NoSuchMethodException exceptionNoSuchMethod )
exceptionNoSuchMethod.printStackTrace();
return null;
}
}
/**
* Show only the HWMCmdEvent
* @return EventSetDescriptor[] The array of events that the bean
* exposes
*/
public EventSetDescriptor[] getEventSetDescriptors()
return super.GetEventSetDescriptors();
}
}