@Echo off

set JobMgr_Debug=OFF

if "%UGII_BASE_DIR:~-2%" equ "85" goto :StepOver
  set UGII_BASE_DIR=%UGII_BASE_DIR:75=85%
:StepOver
set UGII_ROOT_DIR=%UGII_BASE_DIR%\ugii

call :DateTimeNowGet
set CmdCurRoot_DP=%~dp0
set CmdCurRoot_DP=%CmdCurRoot_DP:~0,-1%
set PATH=%UGII_ROOT_DIR%;%CmdCurRoot_DP%;%PATH%

set NxCheckBox_Exe_DPNE=%~dpn0.exe

 set Part_N=%~n1
 set Part_DPNE=%~1
 set Part_DP=%~dp1
 set Part_DP=%Part_DP:~0,-1%
 REM dir "%NxCheckBox_Exe_DPNE%"
 Echo NxCheckBox_Exe_DPNE:[%NxCheckBox_Exe_DPNE%]

 if "%Part_N%" equ "" goto :ExitErr
 if not exist "%Part_DPNE%" goto :ExitErr
 if not exist "%NxCheckBox_Exe_DPNE%" goto :ExitErr

:Start
 set outdir_DP=%Part_DP%\%Part_N%_CBData\%DateTimeNowFileExt%
 if not exist "%outdir_DP%" md "%outdir_DP%"

 set log_DPNE=%outdir_DP%\01-NxCBLog.txt
 set result_DPNE=%outdir_DP%\02-NxCBResult_csv.txt
 set toRun="%NxCheckBox_Exe_DPNE%"
 set toRun=%toRun% -part="%Part_DPNE%"
 set toRun=%toRun% -log="%log_DPNE%"
 set toRun=%toRun% -result="%result_DPNE%"
 set toRun=%toRun% -outdir="%outdir_DP%"
 set toRun=%toRun% -DetailOption=25,26
 set toRun=%toRun% -Cgm_Def_Color_Option=3
 set toRun=%toRun% -UpdateAllFeatures
 set toRun=%toRun% -UpdateAllViews
REM  set toRun=%toRun% -StruktureSync
 set toRun=%toRun% -ExtractCGM_toDir="%outdir_DP%"

 set temp=%outdir_DP%
 set UGII_TMP_DIR=%temp%
 set UGII_SMP_ENABLE=
 set UGII_UGSOLIDS_TMP=%UGII_TMP_DIR%
 set UGII_KEEP_SYSTEM_LOG=TRUE

 rem new: 30.01.2013 20:10
 set NXCB_ANALYZE_NORMALIZED_MASS_PROPS=TRUE

 Echo --------------------------------------------------------------------------
 Echo NXCheckBox Nativ is Processing:
 Echo Part: %Part_DPNE%
 Echo Log.: %log_DPNE%
 Echo Res.: %result_DPNE%
 Echo Dir.: %outdir_DP%
 Echo.
if /I "%JobMgr_Debug%" equ "ON" pause

 start "" Explorer "%outdir_DP%"
 %toRun%
 set NxCheckBox_ErrLevel=%ERRORLEVEL%

 echo --------------------------------------------------------------------------
 echo Result:
 Echo Excuting Errorlevel:[%NxCheckBox_ErrLevel%]
 Echo Type result_DPNE
 type "%result_DPNE%"

 if /I "%JobMgr_Debug%" equ "ON" pause
 pause
Goto :End


:ExitErr
 Echo err cannot get Help
 Echo Posible Reasons:
 Echo P1 = "%1"
 Echo P2 = "%2"
 Echo - cannot find PartFile...........: [%Part_DPNE%]
 Echo - cannot find NxCheckBox_Exe_DPNE:[%NxCheckBox_Exe_DPNE%]
 pause
 goto :end

:End
 if /I "%JobMgr_Debug%" equ "ON" pause
 goto :eof

rem ##### ---------------- Standard Subroutines ------------------------- ######
rem ============================================================================
:DateTimeNowGet
 rem call :DateTimeNowGet
 rem Set File_LPNE=%DatRoot_DP%\MyName-%DateTimeNowFileExt%.txt


 if     "%time:~0,1%"==" " set time-h=0%time:~1,1%
 if not "%time:~0,1%"==" " set time-h=%time:~0,2%

 if     "%time:~3,1%"==" " set time-m=0%time:~4,1%
 if not "%time:~3,1%"==" " set time-m=%time:~3,2%

 set Date-Y=%Date:~-4,4%
 set Date-M=%Date:~-7,2%
 set Date-D=%Date:~-10,2%
 set DateTimeNowFileExt=%Date-Y%-%Date-M%-%Date-D%-%time-h%-%time-m%
 goto :eof
rem ============================================================================
:Wait
 set waitTime=2
 if not "%1"=="" set waitTime=%1
 CHOICE.exe /C:w /N /T:w,%waitTime% "warte %waitTime%[sec] oder [w] fuer weiter druecken: "
 goto :eof

rem ============================================================================
:Parse_All
 rem parst alle File Bezeichner aus
 rem "\" abschneiden
 set Parse_all$temp=%~dp1
 set Parse_all$temp=%Parse_all$temp:~0,-1%
 call :Parse_PLast %Parse_all$temp% %2_PLast %2_PLast2
 call :Parse_PathCutLastDir %~dp0 %2_DPnoPLast
 set %2_DP=%Parse_all$temp%
 set %2_D=%~d1
 rem "\" hinten und vorne abschneiden
 set Parse_all$temp=%~p1
 set Parse_all$temp=%Parse_all$temp:~1,-1%
 set %2_P=%Parse_all$temp%
 set %2_NE=%~nx1
 set %2_N=%~n1
 set %2_E=%~x1
 set %2_DPNE=%1
 set %2_DPN=%~dpn1
 set Parse_all$temp=
 goto :eof

:Parse_PLast
 rem parst den LetzenPath
 set %2=%~n1
 set %3=%~nx1
 goto :eof


:Parse_PathCutLastDir
 rem schneidet das letzte Verzeichniss Uebergeben path ab
 rem P1 = Name der Variablen
 rem P2 = der Übergebene Path
 rem Example : call :PathCutLastDir "%~dp0" MyVar_DP

 set PathCutLastDir$temp=%1
 set PathCutLastDir$temp=%PathCutLastDir$temp:"=%
 set PathCutLastDir$tempLastChar=%PathCutLastDir$temp:~-1%
 set PathCutLastDir$tempNoBacks=%PathCutLastDir$temp:~0,-1%

 if "%PathCutLastDir$tempLastChar%"=="\" (
   rem "\" abschneiden wenn vorhanden
   call :PathCutLastDirDo PathCutLastDir$tempRes %PathCutLastDir$tempNoBacks%
 ) else (
   rem
   call :PathCutLastDirDo PathCutLastDir$tempRes %PathCutLastDir$temp%
 )
 set PathCutLastDir$tempRes=%PathCutLastDir$tempRes:~0,-1%
 set %2=%PathCutLastDir$tempRes%
 set PathCutLastDir$temp=
 set PathCutLastDirDo$temp1=
 set PathCutLastDir$tempNoBacks=
 set PathCutLastDir$tempNoLastChar=
 set PathCutLastDir$tempLastChar=
 set PathCutLastDir$tempRes=
 goto :eof

:PathCutLastDirDo
 rem hiermit schneiden wir den Path ab
 rem echo.
 rem Echo P1=%1 P2=%2
 set PathCutLastDirDo$temp=%~dp2
 rem "\" abschneiden
 set PathCutLastDirDo$temp1=%PathCutLastDir$temp:~0,-1%
 set %1=%PathCutLastDirDo$temp%
 set PathCutLastDirDo$temp=
 set PathCutLastDirDo$temp1=
 goto :eof
rem ============================================================================
:Echo
 rem Echos Text auf die Console und in eine Datei (wenn angegeben)
 setlocal
   set TextToEcho=%1
   set TextToEcho=%TextToEcho:"=%
   set EchoToFile_DPNE=%2
   set EchoToFile_DPNE=%EchoToFile_DPNE:"=%
   if "%EchoToFile_DPNE%"=="=" set EchoToFile_DPNE=

   rem - Ausgabe Console
   if NOT "%TextToEcho%"=="." Echo %TextToEcho%
   if     "%TextToEcho%"=="." Echo.

   rem - Ausgabe in File
   if "%EchoToFile_DPNE%"=="" goto :EchoEnd
   if NOT "%TextToEcho%"=="." Echo %TextToEcho% >>"%EchoToFile_DPNE%"
   if     "%TextToEcho%"=="." Echo.>>"%EchoToFile_DPNE%"
 :EchoEnd
 endlocal
 goto :eof

rem ============================================================================
:ColorSet
 REM Examples:
 REM call :ColorSet IsExecuting
 REM call :ColorSet IsIdel
 REM call :ColorSet End
 REM call :ColorSet Ende
 REM call :ColorSet Ok
 REM call :ColorSet Err

 rem -- cmd Color Farbinfo:
 REM    0 = Schwarz        8 = Dunkelgrau
 REM    1 = Dunkelblau     9 = Blau
 REM    2 = Dunkelgrün     A = Grün
 REM    3 = Blaugrün       B = Zyan
 REM    4 = Dunkelrot      C = Rot
 REM    5 = Lila           D = Magenta
 REM    6 = Ocker          E = Gelb
 REM    7 = Hellgrau       F = Weiß
 rem -- Farben nach Status setzen
 rem Gelb Schwarz
 if /I "%~1" equ "IsExecuting" set JobColorLast=E0
 rem Blaugrün Schwarz 15.11.2010 07:45 Hellgrau Schwarz
 if /I "%~1" equ "IsIdel"      set JobColorLast=70
 rem Hellgrau Schwarz
 if /I "%~1" equ "End"         set JobColorLast=70
 if /I "%~1" equ "Ende"        set JobColorLast=70
 rem Gruen Schwarz
 if /I "%~1" equ "Ok"          set JobColorLast=A0
 rem Rot Schwarz
 if /I "%~1" equ "Err"         set JobColorLast=C0

 rem jetzt die Farbe setzen
 if not "%JobColorLast%"=="" color %JobColorLast%
 goto :eof



