Salome HOME
PR: mergefrom branch BR_OCC_For_3_1_0b1 tag mergeto_BR_PR_V320b1_31mar06
[modules/kernel.git] / src / SALOMEDS / SALOMEDS.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEDS.cxx
25 //  Author : Sergey ANIKIN
26 //  Module : SALOME
27 //  $Header$
28
29 #ifdef WNT
30 #include <SALOMEDS.hxx>
31 #include <SALOMEDS_StudyManager.hxx>
32 #include <SALOMEDS_Study.hxx>
33 #include <SALOMEDS_SObject.hxx>
34 #include <SALOMEDS_StudyBuilder.hxx>
35 #include <SALOMEDS_SComponent.hxx>
36 #include <SALOMEDSClient.hxx>
37 #include <SALOMEDSClient_IParameters.hxx>
38 #include <SALOMEDS_IParameters.hxx>
39 #include <SALOMEDS_StudyManager_i.hxx>
40 #else
41 #include "SALOMEDS.hxx"
42 #include "SALOMEDS_StudyManager.hxx"
43 #include "SALOMEDS_Study.hxx"
44 #include "SALOMEDS_StudyBuilder.hxx"
45 #include "SALOMEDS_SObject.hxx"
46 #include "SALOMEDS_SComponent.hxx"
47 #include "SALOMEDSClient.hxx"
48 #include "SALOMEDSClient_IParameters.hxx"
49 #include "SALOMEDS_IParameters.hxx"
50 #include "SALOMEDS_StudyManager_i.hxx"
51 #endif
52
53 // IDL headers
54 #include <SALOMEconfig.h>
55 #include CORBA_SERVER_HEADER(SALOMEDS)
56 #include <SALOME_NamingService.hxx>
57
58 using namespace SALOMEDS;
59
60 // PAL8065: san -- Global recursive mutex for SALOMEDS methods
61 Utils_Mutex Locker::MutexDS;
62
63 // PAL8065: san -- Global SALOMEDS locker
64 Locker::Locker()
65 : Utils_Locker( &MutexDS )
66 {}
67
68 Locker::~Locker()
69 {}
70
71 void SALOMEDS::lock()
72 {
73   Locker::MutexDS.lock();
74 }
75
76 void SALOMEDS::unlock()
77 {
78   Locker::MutexDS.unlock();
79 }
80
81
82
83 // srn: Added new library methods that create basic SALOMEDS objects (StudyManager, Study, SComponent, SObject)
84
85 //=============================================================================
86 /*!
87  * C factory, accessible with dlsym, after dlopen
88  */
89 //=============================================================================
90
91
92 extern "C"
93 {
94
95 SALOMEDSClient_StudyManager* StudyManagerFactory()
96 {
97   return new SALOMEDS_StudyManager();
98 }
99
100 SALOMEDSClient_Study* StudyFactory(SALOMEDS::Study_ptr theStudy)
101 {
102   if(CORBA::is_nil(theStudy)) return NULL;
103   return new SALOMEDS_Study(theStudy);
104 }
105
106 SALOMEDSClient_SObject* SObjectFactory(SALOMEDS::SObject_ptr theSObject)
107 {
108   if(CORBA::is_nil(theSObject)) return NULL;
109   return new SALOMEDS_SObject(theSObject);
110 }
111
112 SALOMEDSClient_SComponent* SComponentFactory(SALOMEDS::SComponent_ptr theSComponent)
113 {
114   if(CORBA::is_nil(theSComponent)) return NULL;
115   return new SALOMEDS_SComponent(theSComponent);
116 }
117
118 SALOMEDSClient_StudyBuilder* BuilderFactory(SALOMEDS::StudyBuilder_ptr theBuilder)
119 {
120   if(CORBA::is_nil(theBuilder)) return NULL;
121   return new SALOMEDS_StudyBuilder(theBuilder);
122 }
123
124 SALOMEDSClient_StudyManager* CreateStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
125 {
126   cout << "############## CreateStudyManager"   << endl;
127   SALOME_NamingService namingService(orb);
128   CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" );
129   SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj );
130   if( CORBA::is_nil(theManager) ) {
131     SALOMEDS_StudyManager_i * aStudyManager_i = new  SALOMEDS_StudyManager_i(orb, root_poa);
132     // Activate the objects.  This tells the POA that the objects are ready to accept requests.
133     PortableServer::ObjectId_var aStudyManager_iid =  root_poa->activate_object(aStudyManager_i);
134     aStudyManager_i->register_name("/myStudyManager");
135   }
136   return new SALOMEDS_StudyManager();
137 }
138
139 SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap)
140 {
141   return new SALOMEDS_IParameters(ap);
142 }
143
144
145 SALOMEDS::SObject_ptr ConvertSObject(const _PTR(SObject)& theSObject)
146 {
147   
148   SALOMEDS_SObject* so = _CAST(SObject, theSObject);
149   if(!theSObject || !so) return SALOMEDS::SObject::_nil();
150   return so->GetSObject();
151 }
152
153 SALOMEDS::Study_ptr ConvertStudy(const _PTR(Study)& theStudy)
154 {
155   SALOMEDS_Study* study = _CAST(Study, theStudy);
156   if(!theStudy || !study) return SALOMEDS::Study::_nil();
157   return study->GetStudy();
158 }
159
160 SALOMEDS::StudyBuilder_ptr ConvertBuilder(const _PTR(StudyBuilder)& theBuilder)
161 {
162   SALOMEDS_StudyBuilder* builder = _CAST(StudyBuilder, theBuilder);
163   if(!theBuilder || !builder) return SALOMEDS::StudyBuilder::_nil(); 
164   return builder->GetBuilder();
165 }
166
167
168 }