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