/*********************************************************** ******************\
FILE: StartExercise5.java
PURPOSE: Start the J-Link program for Exercise 5. Uses the static method
"Exercise5.executeOperation()" which is the solution to this exercise.
09-Apr-99 I-01-34 JCN $$1 Created.
\*********************************************************** ******************/
import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcExceptions.*;
import com.ptc.pfc.pfcSolid.*;
import com.ptc.pfc.pfcWindow.*;
/**
* Test application class for Exercise 5.
*/
public class StartExercise5 {
private static Model test_model;
/**
* Model name for test application
*/
private static String model = "EXERCISE5";
private static Session session;
/**
* J-Link start method
*/
public static void start ()
{
try {
session = pfcGlobal.GetProESession();
test_model = session.GetModel (model, ModelType.MDL_PART);
}
catch (jxthrowable x)
{
printMsg("Error initializing test program: "+x);
x.printStackTrace();
return;
}
if (test_model == null)
{
printMsg("Please load 'Exercise5.prt' and rerun the program");
return;
}
executeOperations();
}
/**
* J-Link stop method.
*/
public static void stop ()
{
printMsg("Stopped");
}
/**
* Executes the bulk of the operations needed to set up the exercise.
*/
public static void executeOperations()
{
Features features;
String suppress = "SUPP";
String resume = "RES";
String delete = "DEL";
String name;
Feature suppress_feat = null;
Feature resume_feat = null;
Feature delete_feat = null;
Solid test_solid = (Solid) test_model;
Window model_window;
try {
features = ((Solid)test_model).ListFeaturesByType(Boolean.FALSE, null);
for (int i =0; i < features.getarraysize(); i++)
{
if (features.get(i).GetName() != null)
{
name = features.get(i).GetName();
if (name.equalsIgnoreCase(suppress))
{
printMsg("Found 'SUPP'!");
suppress_feat = features.get(i);
}
if (name.equalsIgnoreCase(resume))
{
resume_feat = features.get(i);
printMsg("Found 'RES'!");
}
if (name.equalsIgnoreCase (delete))
{
printMsg("Found 'DEL'!");
delete_feat = features.get(i);
}
}
}
}
catch (jxthrowable x)
{
printMsg("Exception caught :"+x);
x.printStackTrace();
}
// Check if null required for compilation. Utility method
// 'executeOperation' is the solution to exercise 5.
if (suppress_feat != null)
{
Exercise5.executeOperation (suppress_feat, 0);
}
if (resume_feat != null)
{
Exercise5.executeOperation (resume_feat, 1);
}
if (delete_feat != null)
{
Exercise5.executeOperation (delete_feat, 2);
}
try {
// CreateModelWindow returns the window which contains the model
// if it already exists.
model_window = session.CreateModelWindow (test_model);
// Needed to show the changes in the window and on the Model Tree
model_window.Repaint();
model_window.Activate();
}
catch (jxthrowable x)
{
printMsg("Execption caught: "+x);
x.printStackTrace();
}
}
public static void printMsg(String Msg)
{
System.out.println("StartExercise5 :"+Msg);
}
}