Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / GEOMContext / GEOMContext.cxx
1 //
2 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
3 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
20 //
21 //
22 //
23 //  File   : GEOMContext.cxx
24 //  Author : Damien COQUERET
25 //  Module : GEOM
26 //  $Header: 
27
28 using namespace std;
29 #include "GEOMContext.h"
30 #include "QAD_Tools.h"
31
32 /* The object itself created in the static method 'GetOrCreateGEOMBase()' */
33 static GEOMContext* GeomGUI = 0;
34
35 //=======================================================================
36 // function : GEOMContext()
37 // purpose  : Constructor
38 //=======================================================================
39 GEOMContext::GEOMContext() :
40   QObject()
41 {
42 }
43
44
45 //=======================================================================
46 // function : ~GEOMContext()
47 // purpose  : Destructor
48 //=======================================================================
49 GEOMContext::~GEOMContext()
50 {
51 }
52
53
54 //=======================================================================
55 // function : GetGEOMContext() static
56 // purpose  : Returns current 'GeomGUI' a static pointer
57 //=======================================================================
58 GEOMContext* GEOMContext::GetGeomGUI()
59 {
60   return GeomGUI;
61 }
62
63
64 //=======================================================================
65 // function : GetOrCreateGEOMBase()
66 // purpose  : Gets or create an object 'GEOMBase' with initialisations
67 //          : Returns 'GeomGUI' as a pointer
68 //=======================================================================
69 GEOMContext* GEOMContext::GetOrCreateGeomGUI(QAD_Desktop* desktop)
70 {
71   if(GeomGUI == 0) {
72     GeomGUI = new GEOMContext();
73     Engines::Component_var comp = desktop->getEngine("FactoryServer", "GEOM");
74     GeomGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp);
75     
76     GeomGUI->myState = -1;
77     GeomGUI->myActiveDialogBox = 0;
78     GeomGUI->myFatherior = "";
79     GeomGUI->myGUILibrary = OSD_SharedLibrary();
80
81     /* GetCurrentStudy */
82     int studyId = desktop->getActiveStudy()->getStudyId();
83     GeomGUI->myComponentGeom->GetCurrentStudy(studyId);
84
85     GeomGUI->myNbGeom = GeomGUI->myComponentGeom->NbLabels();
86   }
87
88   /* GetCurrentStudy */
89   int studyId = desktop->getActiveStudy()->getStudyId();
90   GeomGUI->myComponentGeom->GetCurrentStudy(studyId);
91
92   GeomGUI->myNbGeom = GeomGUI->myComponentGeom->NbLabels();
93
94   return GeomGUI;
95 }
96
97
98 //=======================================================================
99 // function : LoadLibrary()
100 // purpose  :
101 //=======================================================================
102 bool GEOMContext::LoadLibrary(QString GUILibrary)
103 {
104   QCString libs;
105   QFileInfo fileInfo;
106   QString GUILib, fileString, dir;
107
108   if(libs = getenv("LD_LIBRARY_PATH")) {
109     QStringList dirList = QStringList::split(":", libs, false); // skip empty entries
110     for(int i = dirList.count()-1; i >= 0; i--) {
111       dir = dirList[i];
112       fileString = QAD_Tools::addSlash(dir) + GUILibrary;
113       fileInfo.setFile(fileString);
114       if(fileInfo.exists()) {
115         GUILib = fileInfo.fileName();
116         break;
117       }
118     }
119   }
120
121   myGUILibrary.SetName(TCollection_AsciiString((char*)GUILib.latin1()).ToCString());
122   bool res = myGUILibrary.DlOpen(OSD_RTLD_LAZY);
123   if(!res)
124     cout<<"Can't open library : "<<myGUILibrary.DlError()<<endl;
125   return res;
126 }
127
128
129 //=======================================================================
130 // function : SetActiveDialogBox()
131 // purpose  : 
132 //=======================================================================
133 void GEOMContext::SetActiveDialogBox(QDialog* aDlg)
134 {
135   myActiveDialogBox = (QDialog*)aDlg;
136   return;
137 }
138
139
140 //=======================================================================
141 // function : EmitSignalDeactivateDialog()
142 // purpose  : Emit a signal to deactivate the active dialog Box
143 //=======================================================================
144 void GEOMContext::EmitSignalDeactivateDialog()
145 {
146   emit SignalDeactivateActiveDialog();
147   return;
148 }
149
150
151 //=======================================================================
152 // function : EmitSignalCloseAllDialogs()
153 // purpose  : Emit a signal to deactivate all non modal dialogs box
154 //=======================================================================
155 void GEOMContext::EmitSignalCloseAllDialogs()
156 {
157   emit SignalCloseAllDialogs();
158   return;
159 }
160
161
162 //=======================================================================
163 // function : EmitSignalDefaultStepValueChanged()
164 // purpose  : 
165 //=======================================================================
166 void GEOMContext::EmitSignalDefaultStepValueChanged(double newVal)
167 {
168   emit SignalDefaultStepValueChanged(newVal);
169   return;
170 }