package JavaFoilEmbedding;

// JavaFoil.jar
import MH.JavaFoil.*;
// MHClasses.jar
import MH.AeroTools.*;

/**
 * <p>JavaFoil Embedded.</p>
 * <p>Example for embedding JavaFoil into Java frameworks</p>
 * <p>Copyright (c) 2007 MH AeroTools</p>
 * <p>
 * JavaFoil can be embedded into other Java applications. Using the scripting
 * interface it is possible to execute scripts directly without having to
 * run javaFoil in batch mode. This rduced startup time when many runs are
 * needed and makes it possible to automate tedious tasks.
 * </p>
 *
 * @author Martin Hepperle
 * @version 1.0 (May 2007)
 */
public class EmbeddingExample
{
   /**
    * The main method, called at startup to create an EmbeddingExample object.
    * @param args String[] - not used
    */
   public static void main ( String[] args )
   {
      EmbeddingExample theExample = new EmbeddingExample ();

      // terminate VM otherwise it might continue to run
      //System.exit ( -1 );
   }


   /**
    * This object demonstrates how to
    * - create a javaFoil object,<br>
    * - execute script commands,<br>
    * - use the log file.<br>
    * <h4>Example code:</h4>
    * <hr>
    * <pre>
    *       // STEP 1: create a new instance of JavaFoil
    *       JavaFoil jf = new JavaFoil();
    * <br>
    *       // STEP 2: perform startup initialization (must be done, important!)
    *       // this variant does not create a log file
    *       jf.startEmbedded();
    *       // this alternative variant creates a log file
    *       //jf.startEmbedded("filename.log");
    * <br>
    *       // STEP 3: now run script commands as usual
    *       jf.runScriptLine("Options.Country(0)");
    *       jf.runScriptLine("Geometry.CreateAirfoil(0;61;12;30;0.000;40.000;0;0;1)");
    * <br>
    *       jf.runScriptLine("Polar.Analyze(500000;500000;100000;-5;15;1;100;100;0;0)");
    *       jf.runScriptLine("Polar.Save(\"Z:/polar.txt\")");
    * <br>
    *       // Let's generate an error.
    *       // As no log file exists, an error dialog is displayed
    *       jf.runScriptLine("SetLogFile(\"\\//THIS*?is*@no@*?validfilename\")");
    * <br>
    *       // Create a log file which will be used for following commands
    *       jf.runScriptLine("SetLogFile(\"JavaFoil.log\")");
    *       // generate an error
    *       jf.runScriptLine("Can this be wrong");
    *       jf.runScriptLine("");
    * <br>
    *       // STEP N: Terminate JavaFoil
    *       jf.exitEmbedded ();
    *       // You should NOT use the Exit() script command because this will exit
    *       // your application too. You can set jf to null in order to release memory.
    *       // jf  = null;
    * </pre>
    * <hr>
    */
   public EmbeddingExample ()
   {
      // Create a new instance of JavaFoil
      JavaFoil jf = new JavaFoil ();

      // Perform startup initialization (must be done, important!)
      // this variant creates a log file named "JavaFoil.log"
      jf.startEmbedded ();
      // this alternative variant creates a log file with a specific name
      //jf.startEmbedded("filename.log");

      // Run script commands as usual
      jf.runScriptLine ( "Options.Country(0)" );
      jf.runScriptLine (
         "Geometry.CreateAirfoil(0;121;12;30;0.000;40.000;0;0;1)" );
      jf.runScriptLine (
         "Polar.Analyze(500000;500000;100000;-5;15;1;100;100;0;0)" );
      jf.runScriptLine ( "Polar.Save(\"Z:/polar.txt\")" );

      // Now generate an error
      jf.runScriptLine ( "Can this be wrong" );

      // You should NOT use the Exit() script command because this will exit
      // your application too.
      // NOT: jf.runScriptLine("Exit()");

      jf.exitEmbedded ();
      jf = null;
   }
}
