1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
24 // File : SALOMEDSImpl_SObject.cxx
25 // Author : Sergey RUIN
28 #include "SALOMEDSImpl_SObject.hxx"
29 #include "SALOMEDSImpl_Attributes.hxx"
30 #include "SALOMEDSImpl_SComponent.hxx"
31 #include "SALOMEDSImpl_Study.hxx"
36 //============================================================================
37 /*! Function : empty constructor
40 //============================================================================
41 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject()
45 //============================================================================
46 /*! Function : copy constructor
49 //============================================================================
50 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const SALOMEDSImpl_SObject& theSObject)
52 _lab = theSObject._lab;
53 _value = theSObject._value;
54 _type = theSObject._type;
55 _name = theSObject._name;
60 //============================================================================
61 /*! Function : constructor
64 //============================================================================
65 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const DF_Label& theLabel)
73 //============================================================================
74 /*! Function : Desctructor
77 //============================================================================
78 SALOMEDSImpl_SObject::~SALOMEDSImpl_SObject()
82 //============================================================================
86 //============================================================================
87 std::string SALOMEDSImpl_SObject::GetID() const
92 //============================================================================
93 /*! Function : GetFatherComponent
96 //============================================================================
97 SALOMEDSImpl_SComponent SALOMEDSImpl_SObject::GetFatherComponent() const
99 SALOMEDSImpl_SComponent sco;
101 while (!SALOMEDSImpl_SComponent::IsA(LF) && !LF.IsRoot()) {
105 if(LF.IsRoot()) return sco;
107 return GetStudy()->GetSComponent(LF);
110 //============================================================================
111 /*! Function : GetFather
114 //============================================================================
115 SALOMEDSImpl_SObject SALOMEDSImpl_SObject::GetFather() const
117 return GetStudy()->GetSObject(_lab.Father());
120 //============================================================================
121 /*! Function : GetLastChild
124 //============================================================================
125 int SALOMEDSImpl_SObject::GetLastChildTag() const
127 return _lab.LastChildTag();
130 //============================================================================
131 /*! Function : GetStudy
134 //============================================================================
135 SALOMEDSImpl_Study* SALOMEDSImpl_SObject::GetStudy() const
137 return SALOMEDSImpl_Study::GetStudy(_lab);
140 //============================================================================
141 /*! Function : FindAttribute
142 * Purpose : Find attribute of given type on this SObject
144 //============================================================================
145 bool SALOMEDSImpl_SObject::FindAttribute(DF_Attribute*& theAttribute,
146 const std::string& theTypeOfAttribute) const
148 if(_lab.IsNull()) return false;
149 std::string aGUID = GetGUID(theTypeOfAttribute);
150 if ((theAttribute = _lab.FindAttribute(aGUID))) return true;
156 //============================================================================
157 /*! Function : GetAllAttributes
158 * Purpose : Returns list of all attributes for this sobject
160 //============================================================================
161 std::vector<DF_Attribute*> SALOMEDSImpl_SObject::GetAllAttributes() const
163 std::vector<DF_Attribute*> va1, va = _lab.GetAttributes();
164 for(int i = 0, len = va.size(); i<len; i++) {
165 SALOMEDSImpl_GenericAttribute* ga = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(va[i]);
166 if(ga && ga->Type() != std::string("AttributeReference"))
167 va1.push_back(va[i]);
174 //============================================================================
175 /*! Function : ReferencedObject
178 //============================================================================
179 bool SALOMEDSImpl_SObject::ReferencedObject(SALOMEDSImpl_SObject& theObject) const
181 SALOMEDSImpl_AttributeReference* Ref;
182 if (!(Ref=(SALOMEDSImpl_AttributeReference*)_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID())))
185 theObject = GetStudy()->GetSObject(Ref->Get());
189 //============================================================================
190 /*! Function : FindSubObject
193 //============================================================================
194 bool SALOMEDSImpl_SObject::FindSubObject(int theTag, SALOMEDSImpl_SObject& theObject)
196 DF_Label L = _lab.FindChild(theTag, false);
197 if (L.IsNull()) return false;
199 theObject = GetStudy()->GetSObject(L);
205 //============================================================================
206 /*! Function : GetName
209 //============================================================================
210 std::string SALOMEDSImpl_SObject::GetName() const
212 std::string aStr = "";
213 SALOMEDSImpl_AttributeName* aName;
214 if ((aName=(SALOMEDSImpl_AttributeName*)_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
215 aStr =aName->Value();
220 //============================================================================
221 /*! Function : GetComment
224 //============================================================================
225 std::string SALOMEDSImpl_SObject::GetComment() const
227 std::string aStr = "";
228 SALOMEDSImpl_AttributeComment* aComment;
229 if ((aComment=(SALOMEDSImpl_AttributeComment*)_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
230 aStr = aComment->Value();
235 //============================================================================
236 /*! Function : GetIOR
239 //============================================================================
240 std::string SALOMEDSImpl_SObject::GetIOR() const
242 std::string aStr = "";
243 SALOMEDSImpl_AttributeIOR* anIOR;
244 if ((anIOR=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
245 aStr = dynamic_cast<SALOMEDSImpl_AttributeIOR*>(anIOR)->Value();
251 std::string SALOMEDSImpl_SObject::GetGUID(const std::string& theType)
253 __AttributeTypeToGUIDForSObject
255 if (strncmp(theType.c_str(), "AttributeTreeNodeGUID",21) == 0) {
256 return theType.substr(21, theType.size());
258 if (strncmp(theType.c_str(), "AttributeUserID",15) == 0) {
259 return theType.substr(15, theType.size());
264 //============================================================================
265 /*! Function : SALOMEDSImpl_SComponent
268 //============================================================================
269 SALOMEDSImpl_SObject::operator SALOMEDSImpl_SComponent() const
271 SALOMEDSImpl_SComponent sco;
279 //============================================================================
280 /*! Function : GetPersistentCopy
283 //============================================================================
284 SALOMEDSImpl_SObject* SALOMEDSImpl_SObject::GetPersistentCopy() const
286 SALOMEDSImpl_SObject* so = new SALOMEDSImpl_SObject;
294 //============================================================================
295 /*! Function : IsComponent
298 //============================================================================
299 bool SALOMEDSImpl_SObject::IsComponent() const
301 return SALOMEDSImpl_SComponent::IsA(_lab);
304 void SALOMEDSImpl_SObject::SetAttrString(const std::string& name, const std::string& value)
306 if(name=="AttributeName")SALOMEDSImpl_AttributeName::Set(GetLabel(), value);
307 else if(name=="AttributeIOR")SALOMEDSImpl_AttributeIOR::Set(GetLabel(), value);
308 else if(name=="AttributeString")SALOMEDSImpl_AttributeString::Set(GetLabel(), value);
309 else if(name=="AttributePixMap")SALOMEDSImpl_AttributePixMap::Set(GetLabel(), value);