X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDSImpl%2FSALOMEDSImpl_SObject.cxx;h=b34f8f02bcfa16a9ef0847282d70b9806711bfe0;hb=c4eb57edc80fee5f74e977ac534da063c73cd48c;hp=bf4ff3beec1000a81c1881595a093276b1d22e39;hpb=e6bfea36374791cd31c274a2f97df90dc60ddaf3;p=modules%2Fkernel.git diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx index bf4ff3bee..b34f8f02b 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx @@ -1,29 +1,29 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server // File : SALOMEDSImpl_SObject.cxx // Author : Sergey RUIN // Module : SALOME - - - +// #include "SALOMEDSImpl_SObject.hxx" #include "SALOMEDSImpl_Attributes.hxx" #include "SALOMEDSImpl_SComponent.hxx" @@ -31,18 +31,39 @@ using namespace std; -#include #include +#include + +//============================================================================ +/*! Function : empty constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject::SALOMEDSImpl_SObject() +{ +} + +//============================================================================ +/*! Function : copy constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const SALOMEDSImpl_SObject& theSObject) +{ + _lab = theSObject._lab; + _value = theSObject._value; + _type = theSObject._type; + _name = theSObject._name; + +} -IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_SObject, MMgt_TShared ) -IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_SObject, MMgt_TShared ) //============================================================================ /*! Function : constructor * Purpose : */ //============================================================================ -SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const TDF_Label& theLabel) +SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const DF_Label& theLabel) :_lab(theLabel) { _value = ""; @@ -56,18 +77,17 @@ SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const TDF_Label& theLabel) */ //============================================================================ SALOMEDSImpl_SObject::~SALOMEDSImpl_SObject() -{} +{ +} //============================================================================ /*! Function : GetID * Purpose : */ //============================================================================ -TCollection_AsciiString SALOMEDSImpl_SObject::GetID() +string SALOMEDSImpl_SObject::GetID() const { - TCollection_AsciiString anEntry; - TDF_Tool::Entry (_lab,anEntry); - return anEntry; + return _lab.Entry(); } //============================================================================ @@ -75,14 +95,15 @@ TCollection_AsciiString SALOMEDSImpl_SObject::GetID() * Purpose : */ //============================================================================ -Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_SObject::GetFatherComponent() +SALOMEDSImpl_SComponent SALOMEDSImpl_SObject::GetFatherComponent() const { - TDF_Label LF = _lab; + SALOMEDSImpl_SComponent sco; + DF_Label LF = _lab; while (!SALOMEDSImpl_SComponent::IsA(LF) && !LF.IsRoot()) { LF = LF.Father(); } - if(LF.IsRoot()) return NULL; + if(LF.IsRoot()) return sco; return GetStudy()->GetSComponent(LF); } @@ -92,7 +113,7 @@ Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_SObject::GetFatherComponent() * Purpose : */ //============================================================================ -Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_SObject::GetFather() +SALOMEDSImpl_SObject SALOMEDSImpl_SObject::GetFather() const { return GetStudy()->GetSObject(_lab.Father()); } @@ -103,7 +124,7 @@ Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_SObject::GetFather() * Purpose : */ //============================================================================ -Handle(SALOMEDSImpl_Study) SALOMEDSImpl_SObject::GetStudy() +SALOMEDSImpl_Study* SALOMEDSImpl_SObject::GetStudy() const { return SALOMEDSImpl_Study::GetStudy(_lab); } @@ -113,13 +134,13 @@ Handle(SALOMEDSImpl_Study) SALOMEDSImpl_SObject::GetStudy() * Purpose : Find attribute of given type on this SObject */ //============================================================================ -bool SALOMEDSImpl_SObject::FindAttribute(Handle(TDF_Attribute)& theAttribute, - const TCollection_AsciiString& theTypeOfAttribute) +bool SALOMEDSImpl_SObject::FindAttribute(DF_Attribute*& theAttribute, + const string& theTypeOfAttribute) const { - if(_lab.IsNull()) return Standard_False; - Standard_GUID aGUID = GetGUID(theTypeOfAttribute); - if (_lab.FindAttribute(aGUID, theAttribute)) return Standard_True; - return Standard_False; + if(_lab.IsNull()) return false; + std::string aGUID = GetGUID(theTypeOfAttribute); + if ((theAttribute = _lab.FindAttribute(aGUID))) return true; + return false; } @@ -129,19 +150,16 @@ bool SALOMEDSImpl_SObject::FindAttribute(Handle(TDF_Attribute)& theAttribute, * Purpose : Returns list of all attributes for this sobject */ //============================================================================ -Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_SObject::GetAllAttributes() +vector SALOMEDSImpl_SObject::GetAllAttributes() const { - Standard_Integer NumAttr = _lab.NbAttributes(); - Handle(TColStd_HSequenceOfTransient) SeqOfAttr = new TColStd_HSequenceOfTransient(); - Handle(SALOMEDSImpl_GenericAttribute) anAttr; - if (NumAttr != 0) { - for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) { - anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(iter.Value()); - if(!anAttr.IsNull() && anAttr->Type() != "AttributeReference") - SeqOfAttr->Append(anAttr); - } + vector va1, va = _lab.GetAttributes(); + for(int i = 0, len = va.size(); i(va[i]); + if(ga && ga->Type() != string("AttributeReference")) + va1.push_back(va[i]); } - return SeqOfAttr; + + return va1; } @@ -150,10 +168,10 @@ Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_SObject::GetAllAttributes() * Purpose : */ //============================================================================ -bool SALOMEDSImpl_SObject::ReferencedObject(Handle(SALOMEDSImpl_SObject)& theObject) +bool SALOMEDSImpl_SObject::ReferencedObject(SALOMEDSImpl_SObject& theObject) const { - Handle(SALOMEDSImpl_AttributeReference) Ref; - if (!_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),Ref)) + SALOMEDSImpl_AttributeReference* Ref; + if (!(Ref=(SALOMEDSImpl_AttributeReference*)_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) return false; theObject = GetStudy()->GetSObject(Ref->Get()); @@ -165,9 +183,9 @@ bool SALOMEDSImpl_SObject::ReferencedObject(Handle(SALOMEDSImpl_SObject)& theObj * Purpose : */ //============================================================================ -bool SALOMEDSImpl_SObject::FindSubObject(int theTag, Handle(SALOMEDSImpl_SObject)& theObject) +bool SALOMEDSImpl_SObject::FindSubObject(int theTag, SALOMEDSImpl_SObject& theObject) { - TDF_Label L = _lab.FindChild(theTag, false); + DF_Label L = _lab.FindChild(theTag, false); if (L.IsNull()) return false; theObject = GetStudy()->GetSObject(L); @@ -181,12 +199,12 @@ bool SALOMEDSImpl_SObject::FindSubObject(int theTag, Handle(SALOMEDSImpl_SObject * Purpose : */ //============================================================================ -TCollection_AsciiString SALOMEDSImpl_SObject::GetName() +string SALOMEDSImpl_SObject::GetName() const { - TCollection_AsciiString aStr = ""; - Handle(SALOMEDSImpl_AttributeName) aName; - if (_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) { - aStr = aName->Value(); + string aStr = ""; + SALOMEDSImpl_AttributeName* aName; + if ((aName=(SALOMEDSImpl_AttributeName*)_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) { + aStr =aName->Value(); } return aStr; } @@ -196,11 +214,11 @@ TCollection_AsciiString SALOMEDSImpl_SObject::GetName() * Purpose : */ //============================================================================ -TCollection_AsciiString SALOMEDSImpl_SObject::GetComment() +string SALOMEDSImpl_SObject::GetComment() const { - TCollection_AsciiString aStr = ""; - Handle(SALOMEDSImpl_AttributeComment) aComment; - if (_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aComment)) { + string aStr = ""; + SALOMEDSImpl_AttributeComment* aComment; + if ((aComment=(SALOMEDSImpl_AttributeComment*)_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) { aStr = aComment->Value(); } return aStr; @@ -211,30 +229,64 @@ TCollection_AsciiString SALOMEDSImpl_SObject::GetComment() * Purpose : */ //============================================================================ -TCollection_AsciiString SALOMEDSImpl_SObject::GetIOR() +string SALOMEDSImpl_SObject::GetIOR() const { - TCollection_AsciiString aStr = ""; - Handle(SALOMEDSImpl_AttributeIOR) anIOR; - if (_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anIOR)) { - aStr = anIOR->Value(); + string aStr = ""; + SALOMEDSImpl_AttributeIOR* anIOR; + if ((anIOR=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { + aStr = dynamic_cast(anIOR)->Value(); } return aStr; } -Standard_GUID SALOMEDSImpl_SObject::GetGUID(const TCollection_AsciiString& theType) +std::string SALOMEDSImpl_SObject::GetGUID(const string& theType) { __AttributeTypeToGUIDForSObject - if (strncmp(theType.ToCString(), "AttributeTreeNodeGUID",21) == 0) { - const char* aCType = theType.ToCString(); - char* aGUIDString = new char[40]; - sprintf(aGUIDString, &(aCType[21])); - Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name - delete(aGUIDString); - return aGUID; + if (strncmp(theType.c_str(), "AttributeTreeNodeGUID",21) == 0) { + return theType.substr(21, theType.size()); } - return Standard_GUID(); + return ""; +} + +//============================================================================ +/*! Function : SALOMEDSImpl_SComponent + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject::operator SALOMEDSImpl_SComponent() const +{ + SALOMEDSImpl_SComponent sco; + sco._lab = _lab; + sco._name = _name; + sco._type = _type; + sco._value = _value; + return sco; +} + +//============================================================================ +/*! Function : GetPersistentCopy + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject* SALOMEDSImpl_SObject::GetPersistentCopy() const +{ + SALOMEDSImpl_SObject* so = new SALOMEDSImpl_SObject; + so->_lab = _lab; + so->_name = _name; + so->_type = _type; + so->_value = _value; + return so; } +//============================================================================ +/*! Function : IsComponent + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_SObject::IsComponent() const +{ + return SALOMEDSImpl_SComponent::IsA(_lab); +}