예제 #1
0
 public int SetModuleDirectory(string ModuleDirectoryPath)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.SetModuleDirectoryExternal(theModel, ModuleDirectoryPath));
 }
예제 #2
0
 public int LoadModuleParameters(string ModuleParameterFileName)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.LoadModuleParametersExternal(theModel, ModuleParameterFileName));
 }
예제 #3
0
 public void SetLogCallback(LogCallback theCallback)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     DesktopEarlabDLL.SetLogCallbackExternal(theModel, theCallback);
 }
예제 #4
0
 public DesktopEarlabDLL()
 {
     theModel = DesktopEarlabDLL.CreateModelExternal();
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Failed to initialize model");
     }
 }
예제 #5
0
 public int StopModules()
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.StopModulesExternal(theModel));
 }
예제 #6
0
 public int RunModel(int NumFrames)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     return(DesktopEarlabDLL.RunModelExternal(theModel, NumFrames));
 }
예제 #7
0
 public void SetOutputDirectory(string OutputDirectoryPath)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     DesktopEarlabDLL.SetOutputDirectoryExternal(theModel, OutputDirectoryPath);
 }
예제 #8
0
 public int UnloadModel()
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     Environment.CurrentDirectory = SavedPath;
     return(DesktopEarlabDLL.UnloadModelExternal(theModel));
 }
예제 #9
0
 public int LoadModelConfigFile(string ModelConfigFileName, float FrameSize_uS)
 {
     if (theModel == IntPtr.Zero)
     {
         throw new ApplicationException("Model not initialized");
     }
     SavedPath = Environment.CurrentDirectory;
     Environment.CurrentDirectory = Path.GetDirectoryName(ModelConfigFileName);
     return(DesktopEarlabDLL.LoadModelConfigFileExternal(theModel, ModelConfigFileName, FrameSize_uS));
 }
예제 #10
0
        private void RunModel()
        {
            int i;
            DesktopEarlabDLL theDLL = new DesktopEarlabDLL();

            mStoppedCleanly      = false;
            btnRun.Enabled       = false;
            btnStop.Enabled      = true;
            udFrameCount.Enabled = false;
            progressBar.Visible  = true;

            ClearLog();

            mRunning         = false;
            sbTextPanel.Text = "Running";
            Log("Starting simulation");

            theDLL.SetLogCallback(mLogCallback);

            Log("Module directory: \"" + mModuleDirectory.Value + "\"");
            if (theDLL.SetModuleDirectory(mModuleDirectory.Value) == 0)
            {
                Log("Error setting module directory");
                return;
            }

            Log("Model configuration: \"" + mDiagramFile.Value + "\"");
            if (theDLL.LoadModelConfigFile(mDiagramFile.Value, 1000.0f) == 0)
            {
                Log("Error loading model config file");
                return;
            }

            Log("Module parameters: \"" + mParameterFile.Value + "\"");
            if (theDLL.LoadModuleParameters(mParameterFile.Value) == 0)
            {
                Log("Error loading module parameter file");
                return;
            }

            Log("Setting current directory to output directory (\"" + mOutputDirectory.Value + "\")");
            theDLL.SetOutputDirectory(mOutputDirectory.Value);

            Log("Starting modules");
            if (theDLL.StartModules() == 0)
            {
                Log("Error starting modules");
                return;
            }

            for (i = 0; i < mFrameCount.Value; i++)
            {
                mRunning = true;
                if (mStopModel)
                {
                    break;
                }
                progressBar.Value = i;
                sbTextPanel.Text  = "Processing frame " + (i + 1) + " of " + mFrameCount.Value;

                Log("Starting frame " + (i + 1) + " of " + mFrameCount.Value);
                try
                {
                    if (theDLL.AdvanceModules() == 0)
                    {
                        Log("Error processing frame " + i + " of " + mFrameCount.Value);
                        return;
                    }
                }
                catch (Exception e)
                {
                    Log("Caught exception: " + e.ToString());
                }
                Application.DoEvents();
                Thread.Sleep(100);
            }

            sbTextPanel.Text = "Stopping";
            Log("Stopping modules");
            if (theDLL.StopModules() == 0)
            {
                Log("Error stopping modules");
                return;
            }

            Log("Unloading modules");
            if (theDLL.UnloadModel() == 0)
            {
                Log("Error unloading model");
                return;
            }

            btnRun.Enabled       = true;
            btnStop.Enabled      = false;
            btnAbort.Enabled     = false;
            udFrameCount.Enabled = true;
            progressBar.Visible  = false;
            UpdateStatusDisplay();
            udFrameCount.Focus();
            mStoppedCleanly = true;
            mRunning        = false;
        }