Salome HOME
PR: merge from tag mergeto_trunk_17Jan05
[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_SComponent_i* SALOMEDS_SComponent_i::New(SALOMEDS_Study_i* theStudy,
37                                                   const TDF_Label& theLabel)
38 {
39   SALOMEDS_SComponent_i* aSComponent = NULL;
40   SALOMEDS_Study_i::TSObjectMap& anSObjectMap = theStudy->GetSObjectMap();
41   SALOMEDS_Study_i::TSObjectMap::const_iterator anIter = anSObjectMap.find(theLabel);
42   //cout<<"SALOMEDS_SComponent_i::New - "<<theLabel.Tag()<<" - "<<anSObjectMap.size()<<endl;
43   if(anIter != anSObjectMap.end()){
44     SALOMEDS_SObject_i* aSObject = anIter->second;
45     aSComponent = dynamic_cast<SALOMEDS_SComponent_i*>(aSObject);
46   }
47   if(aSComponent == NULL){
48     aSComponent = new SALOMEDS_SComponent_i(theStudy,theLabel);
49     anSObjectMap[theLabel] = aSComponent;
50   }
51   return aSComponent;
52 }
53
54 //============================================================================
55 /*! Function : constructor
56  *  Purpose  : 
57  */
58 //============================================================================
59 SALOMEDS_SComponent_i::SALOMEDS_SComponent_i(SALOMEDS_Study_i* theStudy,
60                                              const TDF_Label& theLabel):
61   SALOMEDS_SObject_i(theStudy,theLabel)
62 {
63 }
64   
65 //============================================================================
66 /*! Function : destructor
67  *  Purpose  : 
68  */
69 //============================================================================
70 SALOMEDS_SComponent_i::~SALOMEDS_SComponent_i()
71 {
72 }
73   
74   
75 //============================================================================
76 /*! Function : ComponentDataType
77  *  Purpose  : 
78  */
79 //============================================================================
80 char* SALOMEDS_SComponent_i::ComponentDataType()
81 {
82   //DEB
83   //    MESSAGE("In SALOMEDS_SComponent_i::ComponentDataType");
84   //    TCollection_AsciiString anEntry;
85   //    TDF_Tool::Entry (_lab,anEntry);
86   //    MESSAGE("in SALOMEDS_SComponent_i, Entry :"<<anEntry);
87   // END DEB
88
89   Standard_CString res = "";
90   Handle(TDataStd_Comment) type;
91   if ( _lab.FindAttribute(TDataStd_Comment::GetID(),type) ) {
92     TCollection_AsciiString ch(type->Get());
93     res = ch.ToCString();
94   }
95
96   return CORBA::string_dup(res);
97 }
98   
99
100 //============================================================================
101 /*! Function : ComponentIOR
102  *  Purpose  : 
103  */
104 //============================================================================
105 CORBA::Boolean SALOMEDS_SComponent_i::ComponentIOR(CORBA::String_out IOR)
106 {
107   Handle(SALOMEDS_IORAttribute) ior;
108   if (!_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),ior) )
109       return false;
110   TCollection_AsciiString ch(ior->Get());
111   IOR = CORBA::string_dup(ch.ToCString());
112   return true;
113 }
114   
115
116 //============================================================================
117 /*! Function : IsA
118  *  Purpose  : 
119  */
120 //============================================================================
121 Standard_Boolean SALOMEDS_SComponent_i::IsA(const TDF_Label& Lab)
122 {
123   Handle(TDF_Attribute) Att;
124   // scomponent must contain comment and belong to the 2th depth label
125   if ( Lab.FindAttribute(TDataStd_Comment::GetID(), Att) && Lab.Depth() == 2) {
126     return Standard_True;
127   }
128   return Standard_False;
129 }
130   
131