46457a5c24c983fab12134db8333f1a7a666e5d8
[occt.git] / src / Draw / Draw_Main.cxx
1 // Created on: 1999-12-30
2 // Created by: Roman LYGIN
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifdef _WIN32
18 #include <windows.h>
19 #endif
20
21 #include <Draw_Main.hxx>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <Draw_Appli.hxx>
25 #include <OSD.hxx>
26 #include <TCollection_AsciiString.hxx>
27
28 #include <tcl.h>
29
30 #ifdef _WIN32
31 #include <sys/stat.h>
32 #include <Draw_Window.hxx>
33
34 #include <stdio.h>
35 #include <io.h>
36 #include <fcntl.h>
37
38 extern Draw_Viewer dout;
39
40 // extern Standard_IMPORT Standard_Boolean Draw_Interprete(char* command); //for C21
41 Standard_IMPORT Standard_Boolean Draw_Interprete(const char* command); //for C30
42 // true if complete command
43
44 // necessary for WNT in C21 only
45 static FDraw_InitAppli theDraw_InitAppli; //pointer to the Draw_InitAppli
46 #endif
47
48 #ifdef _WIN32
49
50 //=======================================================================
51 //NOTE: OCC11
52 //     On Windows NT, both console (UNIX-like) and windowed (classical on 
53 //     WNT, with three separated windows - input, output and graphic)
54 //     modes are supported.
55 //     Depending on compilation mode of executable (CONSOLE or WINDOWS),
56 //     either Draw_Main or Draw_WinMain becomes entry point;
57 //     the further different behaviour of DRAW is determined by variable 
58 //     Draw_IsConsoleSubsystem which is set by Draw_Main only
59 //=======================================================================
60
61 extern Standard_Boolean Draw_IsConsoleSubsystem;
62
63 //=======================================================================
64 //function : Draw_Main
65 //purpose  : 
66 //=======================================================================
67
68 Standard_Integer Draw_Main (int /*argc*/, char* argv[], const FDraw_InitAppli fDraw_InitAppli)
69 {
70   Draw_IsConsoleSubsystem = Standard_True;
71   theDraw_InitAppli = fDraw_InitAppli;
72
73   // MKV 01.02.05
74 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
75   Tcl_FindExecutable(argv[0]);
76 #endif
77
78   int aNbArgs = 0;
79   wchar_t** anArgVec = CommandLineToArgvW (GetCommandLineW(), &aNbArgs);
80   Draw_Appli (::GetModuleHandleW (NULL), NULL, SW_SHOW, aNbArgs, anArgVec, fDraw_InitAppli);
81   LocalFree (anArgVec);
82   return 0;
83 }
84
85 //=======================================================================
86 //function : Draw_WinMain
87 //purpose  : 
88 //=======================================================================
89
90 Standard_Integer Draw_WinMain (HINSTANCE hInstance, HINSTANCE hPrevinstance, LPSTR /*lpCmdLine*/, int nCmdShow, const FDraw_InitAppli fDraw_InitAppli)
91 {
92   theDraw_InitAppli = fDraw_InitAppli;
93   int aNbArgs = 0;
94   wchar_t** anArgVec = CommandLineToArgvW(GetCommandLineW(), &aNbArgs);
95   Draw_Appli (hInstance, hPrevinstance, nCmdShow, aNbArgs, anArgVec, fDraw_InitAppli);
96   LocalFree (anArgVec);
97   return 0;
98 }
99
100 #else
101
102 //=======================================================================
103 //function : Draw_Main
104 //purpose  : 
105 //=======================================================================
106
107 Standard_Integer Draw_Main (Standard_Integer argc, char* argv[], const FDraw_InitAppli fDraw_InitAppli)
108 {
109   // MKV 01.02.05
110 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
111   Tcl_FindExecutable(argv[0]);
112 #endif
113   Draw_Appli(argc, argv, fDraw_InitAppli);
114   return 0;
115 }
116
117 #endif