0023024: Update headers of OCCT files
[occt.git] / src / DPrsStd / DPrsStd.cxx
1 // Created on: 1998-06-29
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-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 #include <DPrsStd.ixx>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw.hxx>
26
27 #include <Draw_PluginMacro.hxx>
28 #include <DNaming.hxx>
29 #include <DDataStd.hxx> 
30 #include <DDF.hxx> 
31 #include <DDocStd.hxx>
32 //#include <AppStdL_Application.hxx>
33 #include <AppStd_Application.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <OSD_Path.hxx>
36 #include <OSD_Environment.hxx>
37 #include <OSD_Directory.hxx>
38 #include <OSD_File.hxx>
39
40 // avoid warnings on 'extern "C"' functions returning C++ classes
41 #ifdef WNT
42 #pragma warning(4:4190)
43 #endif
44 //static Handle(AppStdL_Application) stdApp;
45 static Handle(AppStd_Application) stdApp;
46 //=======================================================================
47 //function : AllComands
48 //purpose  : 
49 //=======================================================================
50
51 void DPrsStd::AllCommands (Draw_Interpretor& theCommands)
52 {
53   static Standard_Boolean done = Standard_False;
54   if (done) return;
55   done = Standard_True;
56
57   // APPLICATION  
58   if (stdApp.IsNull()) stdApp = new AppStd_Application ();//new AppStdL_Application ();
59
60   DPrsStd::AISPresentationCommands(theCommands); 
61   DPrsStd::AISViewerCommands(theCommands);  
62   //DPrsStd::BasicCommands(theCommands);  
63 }
64
65 //==============================================================================
66 // Found standard CAF Plugin
67 //==============================================================================
68 static Standard_Boolean FoundCAFPlugin () {
69
70  // Define Environment Variable 
71
72   char *plugin, *casroot, *standard;
73   plugin   = getenv("CSF_PluginDefaults");
74   standard = getenv("CSF_StandardDefaults");
75   casroot  = getenv("CASROOT");
76   Standard_Boolean hasPlugin = Standard_False; 
77   TCollection_AsciiString PluginName ;
78   if ( !plugin ) { 
79     if ( casroot ) {
80       PluginName = TCollection_AsciiString (casroot);
81       PluginName+="/src/StdResource" ;
82       hasPlugin = Standard_True ;
83     }
84   } else {
85     PluginName = TCollection_AsciiString (plugin);
86     hasPlugin = Standard_True ;
87   }
88   if (  hasPlugin ) {
89     OSD_Path aPath ( PluginName );
90     OSD_Directory aDir(aPath);
91     if ( aDir.Exists () ) {
92       TCollection_AsciiString PluginFileName = PluginName + "/Plugin" ;
93       OSD_File PluginFile ( PluginFileName );
94       if ( PluginFile.Exists() ) {
95         if (!plugin)   {
96           OSD_Environment PluginEnv   ( "CSF_PluginDefaults" , PluginName );
97           PluginEnv.Build();
98           if ( PluginEnv.Failed() ) {
99             cout << " Problem when initialise CSF_PluginDefaults whith " << PluginName.ToCString() << endl;
100           }
101         }
102         if (!standard) { 
103           OSD_Environment StandardEnv ( "CSF_StandardDefaults" , PluginName );
104           StandardEnv .Build();
105           if ( StandardEnv.Failed() ) {
106             cout << " Problem when initialise CSF_StandardDefaults whith " << PluginName.ToCString() << endl;
107           }
108         }
109       } else {
110         hasPlugin = Standard_False; 
111       }
112     } else {
113       hasPlugin = Standard_False; 
114     }
115   } 
116
117   if ( !hasPlugin ) { 
118     cout << " an environement variable named : CSF_PluginDefaults is mandatory to use OCAF " <<endl;
119     Standard_Failure::Raise ( "an environement variable named : CSF_PluginDefaults is mandatory to use OCAF" );
120   }  
121   
122   return hasPlugin ;
123 }
124
125 //==============================================================================
126 // DPrsStd::Factory
127 //==============================================================================
128 void DPrsStd::Factory(Draw_Interpretor& theDI)
129 {
130   if(!FoundCAFPlugin()) 
131     return;
132
133   static Standard_Boolean DPrsStdFactoryDone = Standard_False;
134   if (DPrsStdFactoryDone) return;
135   DPrsStdFactoryDone = Standard_True;
136
137   DDF::AllCommands(theDI);
138   DNaming::AllCommands(theDI);
139   DDataStd::AllCommands(theDI);  
140   DPrsStd::AllCommands(theDI);
141   DDocStd::AllCommands(theDI);
142 #ifdef DEB
143   cout << "Draw Plugin : All DF commands are loaded" << endl;
144 #endif
145 }
146
147 // Declare entry point PLUGINFACTORY
148 DPLUGIN(DPrsStd)