1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
23 // File : SALOMEDSImpl_SObject.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_SObject.hxx"
28 #include "SALOMEDSImpl_Attributes.hxx"
29 #include "SALOMEDSImpl_SComponent.hxx"
30 #include "SALOMEDSImpl_Study.hxx"
37 //============================================================================
38 /*! Function : empty constructor
41 //============================================================================
42 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject()
46 //============================================================================
47 /*! Function : copy constructor
50 //============================================================================
51 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const SALOMEDSImpl_SObject& theSObject)
53 _lab = theSObject._lab;
54 _value = theSObject._value;
55 _type = theSObject._type;
56 _name = theSObject._name;
61 //============================================================================
62 /*! Function : constructor
65 //============================================================================
66 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const DF_Label& theLabel)
74 //============================================================================
75 /*! Function : Desctructor
78 //============================================================================
79 SALOMEDSImpl_SObject::~SALOMEDSImpl_SObject()
83 //============================================================================
87 //============================================================================
88 string SALOMEDSImpl_SObject::GetID() const
93 //============================================================================
94 /*! Function : GetFatherComponent
97 //============================================================================
98 SALOMEDSImpl_SComponent SALOMEDSImpl_SObject::GetFatherComponent() const
100 SALOMEDSImpl_SComponent sco;
102 while (!SALOMEDSImpl_SComponent::IsA(LF) && !LF.IsRoot()) {
106 if(LF.IsRoot()) return sco;
108 return GetStudy()->GetSComponent(LF);
111 //============================================================================
112 /*! Function : GetFather
115 //============================================================================
116 SALOMEDSImpl_SObject SALOMEDSImpl_SObject::GetFather() const
118 return GetStudy()->GetSObject(_lab.Father());
122 //============================================================================
123 /*! Function : GetStudy
126 //============================================================================
127 SALOMEDSImpl_Study* SALOMEDSImpl_SObject::GetStudy() const
129 return SALOMEDSImpl_Study::GetStudy(_lab);
132 //============================================================================
133 /*! Function : FindAttribute
134 * Purpose : Find attribute of given type on this SObject
136 //============================================================================
137 bool SALOMEDSImpl_SObject::FindAttribute(DF_Attribute*& theAttribute,
138 const string& theTypeOfAttribute) const
140 if(_lab.IsNull()) return false;
141 std::string aGUID = GetGUID(theTypeOfAttribute);
142 if ((theAttribute = _lab.FindAttribute(aGUID))) return true;
148 //============================================================================
149 /*! Function : GetAllAttributes
150 * Purpose : Returns list of all attributes for this sobject
152 //============================================================================
153 vector<DF_Attribute*> SALOMEDSImpl_SObject::GetAllAttributes() const
155 vector<DF_Attribute*> va1, va = _lab.GetAttributes();
156 for(int i = 0, len = va.size(); i<len; i++) {
157 SALOMEDSImpl_GenericAttribute* ga = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(va[i]);
158 if(ga && ga->Type() != string("AttributeReference"))
159 va1.push_back(va[i]);
166 //============================================================================
167 /*! Function : ReferencedObject
170 //============================================================================
171 bool SALOMEDSImpl_SObject::ReferencedObject(SALOMEDSImpl_SObject& theObject) const
173 SALOMEDSImpl_AttributeReference* Ref;
174 if (!(Ref=(SALOMEDSImpl_AttributeReference*)_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID())))
177 theObject = GetStudy()->GetSObject(Ref->Get());
181 //============================================================================
182 /*! Function : FindSubObject
185 //============================================================================
186 bool SALOMEDSImpl_SObject::FindSubObject(int theTag, SALOMEDSImpl_SObject& theObject)
188 DF_Label L = _lab.FindChild(theTag, false);
189 if (L.IsNull()) return false;
191 theObject = GetStudy()->GetSObject(L);
197 //============================================================================
198 /*! Function : GetName
201 //============================================================================
202 string SALOMEDSImpl_SObject::GetName() const
205 SALOMEDSImpl_AttributeName* aName;
206 if ((aName=(SALOMEDSImpl_AttributeName*)_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
207 aStr =aName->Value();
212 //============================================================================
213 /*! Function : GetComment
216 //============================================================================
217 string SALOMEDSImpl_SObject::GetComment() const
220 SALOMEDSImpl_AttributeComment* aComment;
221 if ((aComment=(SALOMEDSImpl_AttributeComment*)_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
222 aStr = aComment->Value();
227 //============================================================================
228 /*! Function : GetIOR
231 //============================================================================
232 string SALOMEDSImpl_SObject::GetIOR() const
235 SALOMEDSImpl_AttributeIOR* anIOR;
236 if ((anIOR=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
237 aStr = dynamic_cast<SALOMEDSImpl_AttributeIOR*>(anIOR)->Value();
243 std::string SALOMEDSImpl_SObject::GetGUID(const string& theType)
245 __AttributeTypeToGUIDForSObject
247 if (strncmp(theType.c_str(), "AttributeTreeNodeGUID",21) == 0) {
248 return theType.substr(21, theType.size());
253 //============================================================================
254 /*! Function : SALOMEDSImpl_SComponent
257 //============================================================================
258 SALOMEDSImpl_SObject::operator SALOMEDSImpl_SComponent() const
260 SALOMEDSImpl_SComponent sco;
268 //============================================================================
269 /*! Function : GetPersistentCopy
272 //============================================================================
273 SALOMEDSImpl_SObject* SALOMEDSImpl_SObject::GetPersistentCopy() const
275 SALOMEDSImpl_SObject* so = new SALOMEDSImpl_SObject;
283 //============================================================================
284 /*! Function : IsComponent
287 //============================================================================
288 bool SALOMEDSImpl_SObject::IsComponent() const
290 return SALOMEDSImpl_SComponent::IsA(_lab);