727dc63ac7aea7e52306254a38b6841f12bdadb9
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 // *******************************************************************
23 //    RLN  06 January 2000
24 // *******************************************************************
25 // This file is built from former NTMain.pxx duplicated in many executables
26 // extending DRAW Test Harness.
27 // Now is implemented only in one instance.
28
29 // Differences between CAS.CADE versions:
30 //  - in C21 Draw_Appli is defined in Draw.cxx (DRAW UL) and calls externally
31 // defined Draw_InitAppli. Moreover, on WNT Draw_Appli was not declared as 
32 // Standard_EXPORT and therefore it has to be duplicated explicitly in this
33 // code as in Draw.cxx.
34 //  - in C30 Draw_Appli accepts Draw_InitAppli as parameter which is given to
35 // it in each executable. Draw_Appli is declared as Standard_EXPORT and
36 // therefore it needs not to be duplicated.
37
38 // To have only one instance of this file and to call it from all the executables
39 // thereare defined macros in .hxx that replace main/WinMain functions and which
40 // calls _main_/_WinMain_ defined in this file with specified Draw_InitAppli.
41 // To avoid Unresolved symbols on WNT, Draw_InitAppli is explicitly defined in this
42 // is initialized by main/_WinMain_.  
43
44 // WARNING: Although versions C21 and C30 are synchronised as much as they can,
45 // there are two versions of this file for both configurations. This is explained by:
46 // - Standard_IMPOR is differently defined,
47 // - Draw_Appli is differently declared.
48
49
50
51 #ifdef HAVE_CONFIG_H
52 # include <config.h>
53 #endif
54
55 #ifdef HAVE_STRINGS_H
56 # include <strings.h>
57 #endif
58   
59 #ifdef WNT
60 #include <windows.h> /* SW_SHOW */
61 #endif
62
63 #include <Draw_Main.hxx>
64 #include <stdlib.h>
65 #include <string.h>
66 #include <Draw_Appli.hxx>
67 #include <OSD.hxx>
68
69 #include <tcl.h>
70
71 #ifdef WNT
72 #include <sys/stat.h>
73 #include <Draw_Window.hxx>
74
75 #include <stdio.h>
76 #include <io.h>
77 #include <fcntl.h>
78
79 extern Draw_Viewer dout;
80
81 static char* ColorNames[MAXCOLOR] = {
82   "White","Red","Green","Blue","Cyan","Gold","Magenta",
83   "Maroon","Orange","Pink","Salmon","Violet","Yellow","Khaki","Coral"
84   };
85
86 static   Standard_Boolean XLoop;
87
88 // extern Standard_IMPORT Standard_Boolean Draw_Interprete(char* command); //for C21
89 Standard_IMPORT Standard_Boolean Draw_Interprete(const char* command); //for C30
90 // true if complete command
91
92 // necessary for WNT in C21 only
93 static FDraw_InitAppli theDraw_InitAppli; //pointer to the Draw_InitAppli
94 #endif
95
96 #ifdef WNT
97 //=======================================================================
98 //NOTE: OCC11
99 //     On Windows NT, both console (UNIX-like) and windowed (classical on 
100 //     WNT, with three separated windows - input, output and graphic)
101 //     modes are supported.
102 //     Depending on compilation mode of executable (CONSOLE or WINDOWS),
103 //     either _main_ or _WinMain_ becomes entry point;
104 //     the further different behaviour of DRAW is determined by variable 
105 //     Draw_IsConsoleSubsystem which is set by _main_ only
106 //=======================================================================
107
108   
109 extern Standard_Boolean Draw_IsConsoleSubsystem;
110
111 //=======================================================================
112 //function : _main_
113 //purpose  : 
114 //=======================================================================
115
116 Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDraw_InitAppli fDraw_InitAppli)
117 {
118   Draw_IsConsoleSubsystem = Standard_True;
119   //return _WinMain_(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli);
120   theDraw_InitAppli = fDraw_InitAppli;
121   //ParseCommandLine(GetCommandLine());
122
123   // MKV 01.02.05
124 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
125   Tcl_FindExecutable(argv[0]);
126 #endif
127
128   Draw_Appli(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli);
129   return 0;
130
131 }
132
133 //=======================================================================
134 //function : _WinMain_
135 //purpose  : 
136 //=======================================================================
137
138 Standard_Integer _WinMain_ (HINSTANCE /*hInstance*/, HINSTANCE /*hPrevinstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/, const FDraw_InitAppli /*fDraw_InitAppli*/)
139 {
140 //  theDraw_InitAppli = fDraw_InitAppli;
141 //  ParseCommandLine (lpCmdLine);
142 //  Draw_Appli(hInstance, hPrevinstance, lpCmdLine, nCmdShow, Draw_InitAppli); // for C30;
143   return 0;
144 }
145 #else
146 //=======================================================================
147 //function : _main_
148 //purpose  : 
149 //=======================================================================
150
151 Standard_Integer _main_ (Standard_Integer argc, char* argv[], const FDraw_InitAppli fDraw_InitAppli)
152 {
153   // MKV 01.02.05
154 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
155   Tcl_FindExecutable(argv[0]);
156 #endif
157   Draw_Appli(argc, argv, fDraw_InitAppli);
158   return 0;
159 }
160 #endif
161