X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM%2FGEOM_Object.cxx;h=7471cd8ea66fd365933d44b17ec72a9ac3886e16;hb=d617faae6bc5aeb91b63796618a20c7c13037b6c;hp=88ca1b7b12b3d110f7943ab8adbeedca68f0ee59;hpb=73555c78ebf12a1fdb85157b8e7934ad566ae90a;p=modules%2Fgeom.git diff --git a/src/GEOM/GEOM_Object.cxx b/src/GEOM/GEOM_Object.cxx index 88ca1b7b1..7471cd8ea 100644 --- a/src/GEOM/GEOM_Object.cxx +++ b/src/GEOM/GEOM_Object.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // 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. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,37 +20,18 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include +#include "GEOM_Object.hxx" -#include "utilities.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include - -#define FUNCTION_LABEL(theNb) (_label.FindChild(1).FindChild((theNb))) -#define TYPE_LABEL 2 -#define FREE_LABEL 3 -#define TIC_LABEL 4 + +#include "utilities.h" + +// #define FUNCTION_LABEL(theNb) (_label.FindChild(1).FindChild((theNb))) +// #define TYPE_LABEL 2 -- Labels used by GEOM_BaseObject +// #define FREE_LABEL 3 +// #define TIC_LABEL 4 #define COLOR_LABEL 5 #define AUTO_COLOR_LABEL 6 #define MARKER_LABEL 7 @@ -59,50 +40,16 @@ #define MARKER_LABEL_SIZE 2 #define MARKER_LABEL_ID 3 -//======================================================================= -//function : GetObjectID -//purpose : -//======================================================================= -const Standard_GUID& GEOM_Object::GetObjectID() -{ - static Standard_GUID anObjectID("FF1BBB01-5D14-4df2-980B-3A668264EA16"); - return anObjectID; -} - -//======================================================================= -//function : GetSubShapeID -//purpose : -//======================================================================= -const Standard_GUID& GEOM_Object::GetSubShapeID() -{ - static Standard_GUID anObjectID("FF1BBB68-5D14-4df2-980B-3A668264EA16"); - return anObjectID; -} - //============================================================================= /*! * GetObject */ //============================================================================= -Handle(GEOM_Object) GEOM_Object::GetObject(TDF_Label& theLabel) -{ - if (!theLabel.IsAttribute(GetObjectID())) return NULL; - - TCollection_AsciiString anEntry; - TDF_Tool::Entry(theLabel, anEntry); - - Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theLabel.Data()); - if(aDoc.IsNull()) return NULL; - - Handle(TDataStd_Integer) anID; - if(!aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) return NULL; - - - GEOM_Engine* anEngine= GEOM_Engine::GetEngine(); - if(anEngine == NULL) return NULL; - return anEngine->GetObject(anID->Get(), (char*) anEntry.ToCString()); - +Handle(GEOM_Object) GEOM_Object::GetObject(const TDF_Label& theLabel) +{ + Handle(GEOM_BaseObject) base = GEOM_BaseObject::GetObject(theLabel); + return Handle(GEOM_Object)::DownCast( base ); } //============================================================================= @@ -110,36 +57,11 @@ Handle(GEOM_Object) GEOM_Object::GetObject(TDF_Label& theLabel) * GetReferencedObject */ //============================================================================= -Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel) -{ - Handle(TDF_Reference) aRef; - if (!theLabel.FindAttribute(TDF_Reference::GetID(), aRef)) { - return NULL; - } - - if(aRef.IsNull() || aRef->Get().IsNull()) { - return NULL; - } - - - // Get TreeNode of a referenced function - Handle(TDataStd_TreeNode) aT, aFather; - if (!TDataStd_TreeNode::Find(aRef->Get(), aT)) { - return NULL; - } - - // Get TreeNode of Object of the referenced function - aFather = aT->Father(); - if (aFather.IsNull()) { - return NULL; - } - - // Get label of the referenced object - TDF_Label aLabel = aFather->Label(); - - - return GEOM_Object::GetObject(aLabel); +Handle(GEOM_Object) GEOM_Object::GetReferencedObject(const TDF_Label& theLabel) +{ + Handle(GEOM_BaseObject) base = GEOM_BaseObject::GetReferencedObject(theLabel); + return Handle(GEOM_Object)::DownCast( base ); } //============================================================================= @@ -147,17 +69,10 @@ Handle(GEOM_Object) GEOM_Object::GetReferencedObject(TDF_Label& theLabel) * Constructor: private */ //============================================================================= + GEOM_Object::GEOM_Object(TDF_Label& theEntry) - : _label(theEntry), _ior(""), _docID(-1) + : GEOM_BaseObject(theEntry) { - Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data()); - if(!aDoc.IsNull()) { - Handle(TDataStd_Integer) anID; - if(aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) _docID = anID->Get(); - } - - if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root)) - _root = TDataStd_TreeNode::Set(theEntry); } //============================================================================= @@ -165,23 +80,10 @@ GEOM_Object::GEOM_Object(TDF_Label& theEntry) * Constructor: public */ //============================================================================= + GEOM_Object::GEOM_Object(TDF_Label& theEntry, int theType) -: _label(theEntry), _ior(""), _docID(-1) + : GEOM_BaseObject( theEntry, theType ) { - Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(_label.Data()); - if(!aDoc.IsNull()) { - Handle(TDataStd_Integer) anID; - if(aDoc->Main().FindAttribute(TDataStd_Integer::GetID(), anID)) _docID = anID->Get(); - } - - theEntry.ForgetAllAttributes(Standard_True); - - if(!theEntry.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), _root)) - _root = TDataStd_TreeNode::Set(theEntry); - - TDataStd_Integer::Set(theEntry.FindChild(TYPE_LABEL), theType); - - TDataStd_UAttribute::Set(theEntry, GetObjectID()); } //============================================================================= @@ -191,94 +93,9 @@ GEOM_Object::GEOM_Object(TDF_Label& theEntry, int theType) //============================================================================= GEOM_Object::~GEOM_Object() { - MESSAGE("GEOM_Object::~GEOM_Object()"); -} - -//============================================================================= -/*! - * GetType - */ -//============================================================================= -int GEOM_Object::GetType() -{ - Handle(TDataStd_Integer) aType; - if(!_label.FindChild(TYPE_LABEL).FindAttribute(TDataStd_Integer::GetID(), aType)) return -1; - - return aType->Get(); -} - -//============================================================================= -/*! - * SetType - */ -//============================================================================= -void GEOM_Object::SetType(int theType) -{ - TDataStd_Integer::Set(_label.FindChild(TYPE_LABEL), theType); -} - - -//============================================================================= -/*! - * Returns modifications counter of this object. - * Comparing this value with modifications counters of argument objects - * (on which this object depends) we decide whether this object needs to be updated. - */ -//============================================================================= -int GEOM_Object::GetTic() -{ - Handle(TDataStd_Integer) aTicAttr; - if (!_label.FindChild(TIC_LABEL).FindAttribute(TDataStd_Integer::GetID(), aTicAttr)) - return 0; - - return aTicAttr->Get(); -} - -//============================================================================= -/*! - * Set another value of modifications counter. - * - * Use this method to update modifications counter of dependent object - * to be equal to modifications counter of its argument. - * This is commonly done in GEOM_Function::GetValue() - */ -//============================================================================= -void GEOM_Object::SetTic(int theTic) -{ - TDataStd_Integer::Set(_label.FindChild(TIC_LABEL), theTic); -} - -//============================================================================= -/*! - * Increment modifications counter to mark this object as modified. - * - * Commonly called from GEOM_Function::SetValue() - */ -//============================================================================= -void GEOM_Object::IncrementTic() -{ - TDF_Label aTicLabel = _label.FindChild(TIC_LABEL); - - Standard_Integer aTic = 0; - Handle(TDataStd_Integer) aTicAttr; - if (aTicLabel.FindAttribute(TDataStd_Integer::GetID(), aTicAttr)) - aTic = aTicAttr->Get(); - - TDataStd_Integer::Set(aTicLabel, aTic + 1); + //MESSAGE("GEOM_Object::~GEOM_Object()"); } - -//============================================================================= -/*! - * GetDocID - */ -//============================================================================= -int GEOM_Object::GetDocID() -{ - return _docID; -} - - //============================================================================= /*! * GetValue @@ -296,33 +113,6 @@ TopoDS_Shape GEOM_Object::GetValue() return aShape; } -//============================================================================= -/*! - * SetName - */ -//============================================================================= -void GEOM_Object::SetName(const char* theName) -{ - TDataStd_Name::Set(_label, (char*)theName); -} - -//============================================================================= -/*! - * GetName - */ -//============================================================================= -char* GEOM_Object::GetName() -{ - Handle(TDataStd_Name) aNameAttr; - if(!_label.FindAttribute(TDataStd_Name::GetID(), aNameAttr)) return NULL; - - TCollection_AsciiString aName(aNameAttr->Get()); - // do not return pointer of local variable - // return aName.ToCString(); - // the following code could lead to memory leak, so take care about recieved pointer - return strdup(aName.ToCString()); -} - //============================================================================= /*! * SetColor @@ -472,58 +262,6 @@ void GEOM_Object::UnsetMarker() SetMarkerStd((Aspect_TypeOfMarker)-1, 0.); } -//============================================================================= -/*! - * SetAuxData - */ -//============================================================================= -void GEOM_Object::SetAuxData(const char* theData) -{ - TDataStd_Comment::Set(_label, (char*)theData); -} - -//============================================================================= -/*! - * GetAuxData - */ -//============================================================================= -TCollection_AsciiString GEOM_Object::GetAuxData() -{ - TCollection_AsciiString aData; - - Handle(TDataStd_Comment) aCommentAttr; - if (_label.FindAttribute(TDataStd_Comment::GetID(), aCommentAttr)) - aData = aCommentAttr->Get(); - - return aData; -} - -//============================================================================= -/*! - * SetParameters - */ -//============================================================================= -void GEOM_Object::SetParameters(const TCollection_AsciiString& theParameters) -{ - if( _parameters.IsEmpty() ) - _parameters = theParameters; - else { - _parameters += "|"; - _parameters += theParameters; - } -} - -//============================================================================= -/*! - * GetParameters - */ -//============================================================================= -TCollection_AsciiString GEOM_Object::GetParameters() const -{ - return _parameters; -} - - //============================================================================= /*! * IsSubShape @@ -532,171 +270,31 @@ TCollection_AsciiString GEOM_Object::GetParameters() const bool GEOM_Object::IsMainShape() { Handle(GEOM_Function) aFunction = GetFunction(1); - if(aFunction.IsNull() || aFunction->GetDriverGUID() != GetSubShapeID()) return true; // mkr : IPAL9921 + if(aFunction.IsNull() || aFunction->GetDriverGUID() != GetSubShapeID()) + return true; // mkr : IPAL9921 return false; } - -//============================================================================= +//================================================================================ /*! - * AddFunction + * \brief Returns GetLastFunction() of given objects */ -//============================================================================= -Handle(GEOM_Function) GEOM_Object::AddFunction(const Standard_GUID& theGUID, - int theFunctionType, - bool allowSubShape) -{ - Standard_Integer nb = GetNbFunctions(); - if(!allowSubShape && nb == 1 && theGUID == GetSubShapeID()) return NULL; //It's impossible to add a function to sub-shape - nb++; - TDF_Label aChild = FUNCTION_LABEL(nb); - - Handle(TDataStd_TreeNode) aNode = TDataStd_TreeNode::Set(aChild); - _root->Append(aNode); - - Handle(GEOM_Function) aFunction = new GEOM_Function(aChild, theGUID, theFunctionType); +//================================================================================ - return aFunction; - -} - -//============================================================================= -/*! - * GetNbFunctions - */ -//============================================================================= -int GEOM_Object::GetNbFunctions() +Handle(TColStd_HSequenceOfTransient) +GEOM_Object::GetLastFunctions( const std::list< Handle(GEOM_Object) >& theObjects ) { - Standard_Integer nb = 0; - for(TDataStd_ChildNodeIterator CI(_root); CI.More(); CI.Next()) nb++; - return nb; -} - -//============================================================================= -/*! - * GetFunction - */ -//============================================================================= -Handle(GEOM_Function) GEOM_Object::GetFunction(int theFunctionNumber) -{ - TDF_Label aChild = FUNCTION_LABEL(theFunctionNumber); - return GEOM_Function::GetFunction(aChild); -} - -//============================================================================= -/*! - * GetlastFunction - */ -//============================================================================= -Handle(GEOM_Function) GEOM_Object::GetLastFunction() -{ - Standard_Integer nb = GetNbFunctions(); - if(nb) return GetFunction(nb); - - return NULL; -} - - -//============================================================================= -/*! - * GetAllDependency - */ -//============================================================================= -Handle(TColStd_HSequenceOfTransient) GEOM_Object::GetAllDependency() -{ - Handle(TColStd_HSequenceOfTransient) anArray; - TDF_LabelSequence aSeq; - Standard_Integer nb = GetNbFunctions(); - if(nb == 0) return anArray; - for(Standard_Integer i=1; i<=nb; i++) { - Handle(GEOM_Function) aFunction = GetFunction(i); - if(aFunction.IsNull()) continue; - aFunction->GetDependency(aSeq); - } - - Standard_Integer aLength = aSeq.Length(); - if(aLength > 0) { - anArray = new TColStd_HSequenceOfTransient; - for(Standard_Integer j =1; j<=aLength; j++) { - Handle(GEOM_Object) aRefObj = GetReferencedObject(aSeq(j)); - if(!aRefObj.IsNull()) anArray->Append(aRefObj); - } + Handle(TColStd_HSequenceOfTransient) funs = new TColStd_HSequenceOfTransient; + std::list::const_iterator it = theObjects.begin(); + for (; it != theObjects.end(); it++) + { + Handle(GEOM_Function) fun = (*it)->GetLastFunction(); + if ( fun.IsNull()) + return Handle(TColStd_HSequenceOfTransient)(); + funs->Append( fun ); } - - return anArray; -} - -//============================================================================= -/*! - * GetLastDependency - */ -//============================================================================= -Handle(TColStd_HSequenceOfTransient) GEOM_Object::GetLastDependency() -{ - Handle(TColStd_HSequenceOfTransient) anArray; - Handle(GEOM_Function) aFunction = GetLastFunction(); - if (aFunction.IsNull()) return anArray; - - TDF_LabelSequence aSeq; - aFunction->GetDependency(aSeq); - Standard_Integer aLength = aSeq.Length(); - if (aLength > 0) { - anArray = new TColStd_HSequenceOfTransient; - for (Standard_Integer i = 1; i <= aLength; i++) - anArray->Append(GetReferencedObject(aSeq(i))); - } - - return anArray; -} - -//============================================================================= -/*! - * GetFreeLabel - */ -//============================================================================= -TDF_Label GEOM_Object::GetFreeLabel() -{ - return _label.FindChild(FREE_LABEL); -} - -//======================================================================= -//function : GEOM_Object_Type_ -//purpose : -//======================================================================= -Standard_EXPORT Handle_Standard_Type& GEOM_Object_Type_() -{ - - static Handle_Standard_Type aType1 = STANDARD_TYPE(MMgt_TShared); - if ( aType1.IsNull()) aType1 = STANDARD_TYPE(MMgt_TShared); - static Handle_Standard_Type aType2 = STANDARD_TYPE(Standard_Transient); - if ( aType2.IsNull()) aType2 = STANDARD_TYPE(Standard_Transient); - - - static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,NULL}; - static Handle_Standard_Type _aType = new Standard_Type("GEOM_Object", - sizeof(GEOM_Object), - 1, - (Standard_Address)_Ancestors, - (Standard_Address)NULL); - return _aType; -} - -//======================================================================= -//function : DownCast -//purpose : -//======================================================================= - -const Handle(GEOM_Object) Handle(GEOM_Object)::DownCast(const Handle(Standard_Transient)& AnObject) -{ - Handle(GEOM_Object) _anOtherObject; - - if (!AnObject.IsNull()) { - if (AnObject->IsKind(STANDARD_TYPE(GEOM_Object))) { - _anOtherObject = Handle(GEOM_Object)((Handle(GEOM_Object)&)AnObject); - } - } - - return _anOtherObject ; + return funs; } +IMPLEMENT_STANDARD_RTTIEXT(GEOM_Object, GEOM_BaseObject )