]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_SComponent_i.cxx
Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_SComponent_i.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_SComponent_i.cxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SALOMEDS_SComponent_i.hxx"
30 #include "SALOMEDS_Study_i.hxx"
31 #include "SALOMEDS.hxx"
32
33 #include "utilities.h"
34
35 using namespace std;
36
37 SALOMEDS_Study_i::TSObjectHolder 
38 SALOMEDS_SComponent_i::New(SALOMEDS_Study_i* theStudy,
39                            const TDF_Label& theLabel)
40 {
41   SALOMEDS_Study_i::TSObjectHolder aSObjectHolder;
42   SALOMEDS_Study_i::TSObjectMap& anSObjectMap = theStudy->GetSObjectMap();
43   SALOMEDS_Study_i::TSObjectMap::const_iterator anIter = anSObjectMap.find(theLabel);
44   if(anIter != anSObjectMap.end()){
45     aSObjectHolder = anIter->second;
46     SALOMEDS_SObject_i* aSObject = aSObjectHolder.first;
47     if(dynamic_cast<SALOMEDS_SComponent_i*>(aSObject))
48       return aSObjectHolder;
49   }
50   TCollection_AsciiString anEntry;
51   TDF_Tool::Entry(theLabel,anEntry);
52   SALOMEDS_SComponent_i* aSComponent = new SALOMEDS_SComponent_i(theStudy,theLabel);
53   aSObjectHolder.first = aSComponent;
54   aSObjectHolder.second = aSComponent->_this();
55   anSObjectMap[theLabel] = aSObjectHolder;
56
57   return aSObjectHolder;
58 }
59
60 SALOMEDS_SComponent_i*
61 SALOMEDS_SComponent_i::NewPtr(SALOMEDS_Study_i* theStudy,
62                               const TDF_Label& theLabel)
63 {
64   return dynamic_cast<SALOMEDS_SComponent_i*>(New(theStudy,theLabel).first);
65 }
66
67 SALOMEDS::SComponent_var
68 SALOMEDS_SComponent_i::NewRef(SALOMEDS_Study_i* theStudy,
69                               const TDF_Label& theLabel)
70 {
71   return SALOMEDS::SComponent::_narrow(New(theStudy,theLabel).second);
72 }
73
74 //============================================================================
75 /*! Function : constructor
76  *  Purpose  : 
77  */
78 //============================================================================
79 SALOMEDS_SComponent_i::SALOMEDS_SComponent_i(SALOMEDS_Study_i* theStudy,
80                                              const TDF_Label& theLabel):
81   SALOMEDS_SObject_i(theStudy,theLabel)
82 {
83 }
84   
85 //============================================================================
86 /*! Function : destructor
87  *  Purpose  : 
88  */
89 //============================================================================
90 SALOMEDS_SComponent_i::~SALOMEDS_SComponent_i()
91 {
92 }
93   
94   
95 //============================================================================
96 /*! Function : ComponentDataType
97  *  Purpose  : 
98  */
99 //============================================================================
100 char* SALOMEDS_SComponent_i::ComponentDataType()
101 {
102   SALOMEDS::Locker lock;
103
104   //DEB
105   //    MESSAGE("In SALOMEDS_SComponent_i::ComponentDataType");
106   //    TCollection_AsciiString anEntry;
107   //    TDF_Tool::Entry (_lab,anEntry);
108   //    MESSAGE("in SALOMEDS_SComponent_i, Entry :"<<anEntry);
109   // END DEB
110
111   Standard_CString res = "";
112   Handle(TDataStd_Comment) type;
113   if ( _lab.FindAttribute(TDataStd_Comment::GetID(),type) ) {
114     TCollection_AsciiString ch(type->Get());
115     res = ch.ToCString();
116   }
117
118   return CORBA::string_dup(res);
119 }
120   
121
122 //============================================================================
123 /*! Function : ComponentIOR
124  *  Purpose  : 
125  */
126 //============================================================================
127 CORBA::Boolean SALOMEDS_SComponent_i::ComponentIOR(CORBA::String_out IOR)
128 {
129   SALOMEDS::Locker lock;
130
131   Handle(SALOMEDS_IORAttribute) ior;
132   if (!_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),ior) )
133       return false;
134   TCollection_AsciiString ch(ior->Get());
135   IOR = CORBA::string_dup(ch.ToCString());
136   return true;
137 }
138   
139
140 //============================================================================
141 /*! Function : IsA
142  *  Purpose  : 
143  */
144 //============================================================================
145 Standard_Boolean SALOMEDS_SComponent_i::IsA(const TDF_Label& Lab)
146 {
147   Handle(TDF_Attribute) Att;
148   // scomponent must contain comment and belong to the 2th depth label
149   if ( Lab.FindAttribute(TDataStd_Comment::GetID(), Att) && Lab.Depth() == 2) {
150     return Standard_True;
151   }
152   return Standard_False;
153 }
154   
155