Salome HOME
NPAL17269: Performance pb. when creating a group with GUI.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 //
23 //  File   : GEOMContext.cxx
24 //  Author : Damien COQUERET
25 //  Module : GEOM
26 //  $Header: 
27
28 #include "GEOMContext.h"
29 #include "QAD_Tools.h"
30
31 using namespace std;
32
33 /* The object itself created in the static method 'GetOrCreateGEOMBase()' */
34 static GEOMContext* GeomGUI = 0;
35
36 //=======================================================================
37 // function : GEOMContext()
38 // purpose  : Constructor
39 //=======================================================================
40 GEOMContext::GEOMContext() :
41   QObject()
42 {
43 }
44
45
46 //=======================================================================
47 // function : ~GEOMContext()
48 // purpose  : Destructor
49 //=======================================================================
50 GEOMContext::~GEOMContext()
51 {
52 }
53
54
55 //=======================================================================
56 // function : GetGEOMContext() static
57 // purpose  : Returns current 'GeomGUI' a static pointer
58 //=======================================================================
59 GEOMContext* GEOMContext::GetGeomGUI()
60 {
61   return GeomGUI;
62 }
63
64
65 //=======================================================================
66 // function : GetOrCreateGEOMBase()
67 // purpose  : Gets or create an object 'GEOMBase' with initialisations
68 //          : Returns 'GeomGUI' as a pointer
69 //=======================================================================
70 GEOMContext* GEOMContext::GetOrCreateGeomGUI(QAD_Desktop* desktop)
71 {
72   if(GeomGUI == 0) {
73     GeomGUI = new GEOMContext();
74     Engines::Component_var comp = desktop->getEngine("FactoryServer", "GEOM");
75     GeomGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp);
76     
77     GeomGUI->myState = -1;
78     GeomGUI->myActiveDialogBox = 0;
79     GeomGUI->myFatherior = "";
80     GeomGUI->myGUILibrary = OSD_SharedLibrary();
81
82     /* GetCurrentStudy */
83     int studyId = desktop->getActiveStudy()->getStudyId();
84     GeomGUI->myComponentGeom->GetCurrentStudy(studyId);
85
86     GeomGUI->myNbGeom = GeomGUI->myComponentGeom->NbLabels();
87   }
88
89   /* GetCurrentStudy */
90   int studyId = desktop->getActiveStudy()->getStudyId();
91   GeomGUI->myComponentGeom->GetCurrentStudy(studyId);
92
93   GeomGUI->myNbGeom = GeomGUI->myComponentGeom->NbLabels();
94
95   return GeomGUI;
96 }
97
98
99 //=======================================================================
100 // function : LoadLibrary()
101 // purpose  :
102 //=======================================================================
103 bool GEOMContext::LoadLibrary(QString GUILibrary)
104 {
105   QCString libs;
106   QFileInfo fileInfo;
107   QString GUILib, fileString, dir;
108
109   if(libs = getenv("LD_LIBRARY_PATH")) {
110     QStringList dirList = QStringList::split(":", libs, false); // skip empty entries
111     for(int i = dirList.count()-1; i >= 0; i--) {
112       dir = dirList[i];
113       fileString = QAD_Tools::addSlash(dir) + GUILibrary;
114       fileInfo.setFile(fileString);
115       if(fileInfo.exists()) {
116         GUILib = fileInfo.fileName();
117         break;
118       }
119     }
120   }
121
122   myGUILibrary.SetName(TCollection_AsciiString((char*)GUILib.latin1()).ToCString());
123   bool res = myGUILibrary.DlOpen(OSD_RTLD_LAZY);
124   if(!res)
125     cout<<"Can't open library : "<<myGUILibrary.DlError()<<endl;
126   return res;
127 }
128
129
130 //=======================================================================
131 // function : SetActiveDialogBox()
132 // purpose  : 
133 //=======================================================================
134 void GEOMContext::SetActiveDialogBox(QDialog* aDlg)
135 {
136   myActiveDialogBox = (QDialog*)aDlg;
137   return;
138 }
139
140
141 //=======================================================================
142 // function : EmitSignalDeactivateDialog()
143 // purpose  : Emit a signal to deactivate the active dialog Box
144 //=======================================================================
145 void GEOMContext::EmitSignalDeactivateDialog()
146 {
147   emit SignalDeactivateActiveDialog();
148   return;
149 }
150
151
152 //=======================================================================
153 // function : EmitSignalCloseAllDialogs()
154 // purpose  : Emit a signal to deactivate all non modal dialogs box
155 //=======================================================================
156 void GEOMContext::EmitSignalCloseAllDialogs()
157 {
158   emit SignalCloseAllDialogs();
159   return;
160 }
161
162
163 //=======================================================================
164 // function : EmitSignalDefaultStepValueChanged()
165 // purpose  : 
166 //=======================================================================
167 void GEOMContext::EmitSignalDefaultStepValueChanged(double newVal)
168 {
169   emit SignalDefaultStepValueChanged(newVal);
170   return;
171 }