f803b71fb7f3db6023c9ee716e10347ebba58106
[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 static void Draw_InitAppli(Draw_Interpretor& theCommands)
95 {
96   theDraw_InitAppli (theCommands);
97 }
98 #endif
99
100 #ifdef WNT
101 //=======================================================================
102 //NOTE: OCC11
103 //     On Windows NT, both console (UNIX-like) and windowed (classical on 
104 //     WNT, with three separated windows - input, output and graphic)
105 //     modes are supported.
106 //     Depending on compilation mode of executable (CONSOLE or WINDOWS),
107 //     either _main_ or _WinMain_ becomes entry point;
108 //     the further different behaviour of DRAW is determined by variable 
109 //     Draw_IsConsoleSubsystem which is set by _main_ only
110 //=======================================================================
111
112   
113 extern Standard_Boolean Draw_IsConsoleSubsystem;
114
115 //=======================================================================
116 //function : _main_
117 //purpose  : 
118 //=======================================================================
119
120 Standard_Integer _main_ (int /*argc*/, char* argv[], char* /*envp*/[], const FDraw_InitAppli fDraw_InitAppli)
121 {
122   Draw_IsConsoleSubsystem = Standard_True;
123   //return _WinMain_(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli);
124   theDraw_InitAppli = fDraw_InitAppli;
125   //ParseCommandLine(GetCommandLine());
126
127   // MKV 01.02.05
128 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
129   Tcl_FindExecutable(argv[0]);
130 #endif
131
132   Draw_Appli(::GetModuleHandle(NULL), NULL, GetCommandLine(), SW_SHOW, fDraw_InitAppli);
133   return 0;
134
135 }
136
137 //=======================================================================
138 //function : _WinMain_
139 //purpose  : 
140 //=======================================================================
141
142 Standard_Integer _WinMain_ (HINSTANCE /*hInstance*/, HINSTANCE /*hPrevinstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/, const FDraw_InitAppli /*fDraw_InitAppli*/)
143 {
144 //  theDraw_InitAppli = fDraw_InitAppli;
145 //  ParseCommandLine (lpCmdLine);
146 //  Draw_Appli(hInstance, hPrevinstance, lpCmdLine, nCmdShow, Draw_InitAppli); // for C30;
147   return 0;
148 }
149 #else
150 //=======================================================================
151 //function : _main_
152 //purpose  : 
153 //=======================================================================
154
155 Standard_Integer _main_ (Standard_Integer argc, char* argv[], const FDraw_InitAppli fDraw_InitAppli)
156 {
157   // MKV 01.02.05
158 #if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)))
159   Tcl_FindExecutable(argv[0]);
160 #endif
161   Draw_Appli(argc, argv, fDraw_InitAppli);
162   return 0;
163 }
164 #endif
165