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