X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM%2FGEOM_Function.cxx;h=17b45b06457c5393a651130dff16fdad539ee7b5;hb=58803ba33ee53a5944d565373782e5f0868c5461;hp=4112c03ad2c0cb3f8b6216132a91e648fe7c2d8a;hpb=b7cff0a4ec43ee005440c53e196b5c94f076dbca;p=modules%2Fgeom.git diff --git a/src/GEOM/GEOM_Function.cxx b/src/GEOM/GEOM_Function.cxx index 4112c03ad..17b45b064 100644 --- a/src/GEOM/GEOM_Function.cxx +++ b/src/GEOM/GEOM_Function.cxx @@ -1,8 +1,33 @@ -using namespace std; +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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, 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 +// 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 +// -#include "GEOM_Function.hxx" -#include "GEOM_Object.hxx" -#include "GEOM_Solver.hxx" +#include + +#include +#include +#include +#include + +#include #include "utilities.h" @@ -11,6 +36,8 @@ using namespace std; #include #include #include +#include +#include #include #include #include @@ -20,6 +47,7 @@ using namespace std; #include #include #include +#include #include #include #include @@ -34,12 +62,27 @@ using namespace std; #include #include +#include + +#include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC +// This modification was introduced in frame of Mantis issue 0021251. +// This line allows to keep shape orientation together with the shape itself. +// Otherwise orientation can be lost in some cases. +#define KEEP_ORIENTATION_0021251 + #define ARGUMENT_LABEL 1 #define RESULT_LABEL 2 #define DESCRIPTION_LABEL 3 #define HISTORY_LABEL 4 +#define SUBSHAPES_LABEL 5 // 0020756: GetGroups +#define NAMING_LABEL 6 // 0020750: Naming during STEP import +#define CALLBACK_LABEL 1 // TDataStd_Comment + +#ifdef KEEP_ORIENTATION_0021251 +#define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation +#endif #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL)) #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition)) @@ -84,7 +127,7 @@ Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry) */ //============================================================================= GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType) -: _label(theEntry) + : _label(theEntry), _isCallBackData(false) { TFunction_Function::Set(theEntry, theGUID); TDataStd_Integer::Set(theEntry, theType); @@ -99,6 +142,38 @@ GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& the aRoot->Append(aNode); } +//================================================================================ +/*! + * \brief + * + * + */ +//================================================================================ + +GEOM_Function::~GEOM_Function() +{ + if ( _isCallBackData ) { + _label.FindChild( CALLBACK_LABEL ).ForgetAttribute( TDataStd_Comment::GetID() ); + } +} + +//================================================================================ +/*! + * \brief Retuns true if this function is the last one in the study + */ +//================================================================================ + +bool GEOM_Function::IsLastFuntion() +{ + bool isLast = false; + + Handle(TDataStd_TreeNode) aNode; + if (_label.FindAttribute(GetFunctionTreeID(), aNode)) + isLast = !aNode->HasNext(); + + return isLast; +} + //============================================================================= /*! * GetOwner @@ -140,47 +215,111 @@ TopoDS_Shape GEOM_Function::GetValue() TopoDS_Shape aShape; TDF_Label aLabel = GetOwnerEntry(); - if(aLabel.IsRoot()) return aShape; + if (aLabel.IsRoot()) return aShape; Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel); - if(anObject.IsNull()) return aShape; - if(!anObject->IsMainShape()) { - try { - GEOM_Solver aSolver(GEOM_Engine::GetEngine()); - if (!aSolver.ComputeFunction(this)) { - MESSAGE("GEOM_Object::GetValue Error : Can't build a sub shape"); - return aShape; - } + if (anObject.IsNull()) return aShape; + + if (!anObject->IsMainShape()) { + bool isResult = false; + TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL); + if (!aResultLabel.IsNull()) { + Handle(TNaming_NamedShape) aNS; + if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) + isResult = true; } - catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); - MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString()); - return aShape; + + // compare tics + if (isResult) { + // tic of this + Standard_Integer aTic = anObject->GetTic(); + + // tic of main shape + GEOM_ISubShape aCI (this); + TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry(); + if (aLabelObjMainSh.IsRoot()) return aShape; + Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh); + if (anObjMainSh.IsNull()) return aShape; + Standard_Integer aTicMainSh = anObjMainSh->GetTic(); + + // compare + isResult = ((aTic == aTicMainSh) ? true : false); + } + + if (!isResult) { + try { + OCC_CATCH_SIGNALS; + GEOM_Solver aSolver(GEOM_Engine::GetEngine()); + if (!aSolver.ComputeFunction(this)) { + MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape"); + return aShape; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString()); + return aShape; + } } } TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL); Handle(TNaming_NamedShape) aNS; - if(!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape; + if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape; aShape = aNS->Get(); +#ifdef KEEP_ORIENTATION_0021251 + // 0021251: TNaming_NamedShape doesn't store orientation + TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL); + Handle(TDataStd_Integer) anInteger; + if (anOrientationLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) { + aShape.Orientation((TopAbs_Orientation)anInteger->Get()); + } +#endif + _isDone = true; return aShape; } //============================================================================= /*! - * GetValue + * SetValue */ //============================================================================= void GEOM_Function::SetValue(TopoDS_Shape& theShape) { _isDone = false; TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL); - TNaming_Builder aBuilder(aResultLabel); + TNaming_Builder aBuilder (aResultLabel); aBuilder.Generated(theShape); +#ifdef KEEP_ORIENTATION_0021251 + // 0021251: TNaming_NamedShape doesn't store orientation + TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL); + TDataStd_Integer::Set(anOrientationLabel, (int)theShape.Orientation()); +#endif + + // synchronisation between main shape and its sub-shapes + TDF_Label aLabel = GetOwnerEntry(); + if (aLabel.IsRoot()) return; + Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel); + if (anObject.IsNull()) return; + if (anObject->IsMainShape()) { + // increase modifications counter of this (main) shape + anObject->IncrementTic(); + } + else { + // update modifications counter of this (sub-) shape to be the same as on main shape + GEOM_ISubShape aCI (this); + TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry(); + if (aLabelObjMainSh.IsRoot()) return; + Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh); + if (anObjMainSh.IsNull()) return; + + anObject->SetTic(anObjMainSh->GetTic()); + } + _isDone = true; } @@ -218,10 +357,11 @@ TCollection_AsciiString GEOM_Function::GetDescription() * SetDescription */ //============================================================================= -void GEOM_Function::SetDescription(TCollection_AsciiString& theDescription) +void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription) { TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL); - Handle(TDataStd_Comment) aComment = TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription)); + Handle(TDataStd_Comment) aComment = + TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription)); } //============================================================================= @@ -354,6 +494,74 @@ Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition) return anIntegerArray->Array(); } +//============================================================================= +/*! + * SetByteArray + */ +//============================================================================= +void GEOM_Function::SetByteArray (int thePosition, + const Handle(TColStd_HArray1OfByte)& theArray) +{ + _isDone = false; + if(thePosition <= 0) return; + TDF_Label anArgLabel = ARGUMENT(thePosition); + Handle(TDataStd_ByteArray) anAttr = + TDataStd_ByteArray::Set(anArgLabel, theArray->Lower(), theArray->Upper()); + anAttr->ChangeArray(theArray); + _isDone = true; +} + +//============================================================================= +/*! + * GetByteArray + */ +//============================================================================= +Handle(TColStd_HArray1OfByte) GEOM_Function::GetByteArray(int thePosition) +{ + _isDone = false; + if(thePosition <= 0) return 0; + Handle(TDataStd_ByteArray) aByteArray; + TDF_Label anArgLabel = ARGUMENT(thePosition); + if(!anArgLabel.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray)) return 0; + + _isDone = true; + return aByteArray->InternalArray(); +} + +//============================================================================= +/*! + * SetBooleanArray + */ +//============================================================================= +void GEOM_Function::SetBooleanArray (int thePosition, + const Handle(TColStd_HArray1OfByte)& theArray) +{ + _isDone = false; + if(thePosition <= 0) return; + TDF_Label anArgLabel = ARGUMENT(thePosition); + Handle(TDataStd_BooleanArray) anAttr = + TDataStd_BooleanArray::Set(anArgLabel, theArray->Lower(), theArray->Upper()); + anAttr->SetInternalArray(theArray); + _isDone = true; +} + +//============================================================================= +/*! + * GetBooleanArray + */ +//============================================================================= +Handle(TColStd_HArray1OfByte) GEOM_Function::GetBooleanArray(int thePosition) +{ + _isDone = false; + if(thePosition <= 0) return 0; + Handle(TDataStd_BooleanArray) aBooleanArray; + TDF_Label anArgLabel = ARGUMENT(thePosition); + if(!anArgLabel.FindAttribute(TDataStd_BooleanArray::GetID(), aBooleanArray)) return 0; + + _isDone = true; + return aBooleanArray->InternalArray(); +} + //============================================================================= /*! * SetString @@ -381,9 +589,10 @@ TCollection_AsciiString GEOM_Function::GetString(int thePosition) Handle(TDataStd_Comment) aString; TDF_Label anArgLabel = ARGUMENT(thePosition); if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes; - + char *str = new char[aString->Get().LengthOfCString()+1]; + aString->Get().ToUTF8CString(str); + aRes = TCollection_AsciiString(str); _isDone = true; - aRes = TCollection_AsciiString(aString->Get()); return aRes; } @@ -395,8 +604,8 @@ TCollection_AsciiString GEOM_Function::GetString(int thePosition) void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference) { _isDone = false; - if(thePosition <= 0) return; - if(theReference.IsNull()) return; + if (thePosition <= 0) return; + if (theReference.IsNull()) return; TDF_Label anArgLabel = ARGUMENT(thePosition); TDF_Reference::Set(anArgLabel, theReference->GetEntry()); TDataStd_UAttribute::Set(anArgLabel, GetDependencyID()); @@ -433,9 +642,9 @@ void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1 if(thePosition <= 0 || theArray.IsNull()) return; TDF_Label anArgLabel = ARGUMENT(thePosition); - Handle(TDataStd_ExtStringArray) anArray = new TDataStd_ExtStringArray; + Handle(TDataStd_ExtStringArray) anArray = + TDataStd_ExtStringArray::Set(anArgLabel, theArray->Lower(), theArray->Upper()); anArray->ChangeArray(theArray); - anArgLabel.AddAttribute(anArray); _isDone = true; } @@ -458,6 +667,18 @@ Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePos return anArray->Array(); } +//======================================================================= +//function : HasData +//purpose : Returns true if data of given type already exists +//======================================================================= + +bool GEOM_Function::HasData(int thePosition, const Standard_GUID& dataID) +{ + if(thePosition <= 0) return false; + TDF_Label anArgLabel = ARGUMENT(thePosition); + return anArgLabel.IsAttribute( dataID ); +} + //======================================================================= //function : GetReferencesTreeID //purpose : @@ -594,6 +815,85 @@ void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq) } } +//============================================================================= +/*! + * AddSubShapeReference + */ +//============================================================================= +void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape) +{ + _isDone = false; + + TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL); + + Handle(TDataStd_ExtStringList) aList; + if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) { + aList = new TDataStd_ExtStringList; + aSubShapesLabel.AddAttribute(aList); + } + + TCollection_AsciiString anEntry; + TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry); + aList->Append(anEntry); + + _isDone = true; +} + +//============================================================================= +/*! + * RemoveSubShapeReference + */ +//============================================================================= +void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape) +{ + _isDone = false; + + TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL); + + Handle(TDataStd_ExtStringList) aList; + if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) { + TCollection_AsciiString anEntry; + TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry); + aList->Remove(anEntry); + } + + _isDone = true; +} + +//============================================================================= +/*! + * HasSubShapeReferences + */ +//============================================================================= +bool GEOM_Function::HasSubShapeReferences() +{ + _isDone = true; + + TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL); + return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID()); +} + +//============================================================================= +/*! + * GetSubShapeReferences + */ +//============================================================================= +const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences() +{ + _isDone = false; + + TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL); + + Handle(TDataStd_ExtStringList) aList; + if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) { + aList = new TDataStd_ExtStringList; + aSubShapesLabel.AddAttribute(aList); + } + + _isDone = true; + return aList->List(); +} + //============================================================================= /*! * GetHistoryEntry @@ -637,43 +937,61 @@ TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label& theArgu return aHistoryCurLabel; } -//======================================================================= -//function : GEOM_Function_Type_ -//purpose : -//======================================================================= -Standard_EXPORT Handle_Standard_Type& GEOM_Function_Type_() +//============================================================================= +/*! + * GetNamingEntry + */ +//============================================================================= +TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create) { + return _label.FindChild(NAMING_LABEL, create); +} - 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); +//================================================================================ +/*! + * Save a pointer to a data holder intended to pass temporary data Driver -> Operation. + * This method should be called by Operation to set the data holder. + * An instance of GEOM_Function that sets the data holder will remove the + * corresponding OCAF attribute at it's destruction + */ +//================================================================================ +void GEOM_Function::SetCallBackData( void* data ) +{ + std::ostringstream strm; + strm << (long long) data; + TCollection_ExtendedString string( strm.str().c_str() ); - static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,NULL}; - static Handle_Standard_Type _aType = new Standard_Type("GEOM_Function", - sizeof(GEOM_Function), - 1, - (Standard_Address)_Ancestors, - (Standard_Address)NULL); + TDF_Label aChild = _label.FindChild(CALLBACK_LABEL); + TDataStd_Comment::Set(aChild, string); - return _aType; + _isCallBackData = true; // I will remove TDataStd_Comment at destruction } -//======================================================================= -//function : DownCast -//purpose : -//======================================================================= +//================================================================================ +/*! + * Returns a pointer to a data holder intended to pass data Driver -> Operation. + * This method should be called by Driver to get the data holder to fill it in. + * Returns NULL if the Operation have not set the data holder. + */ +//================================================================================ -const Handle(GEOM_Function) Handle(GEOM_Function)::DownCast(const Handle(Standard_Transient)& AnObject) +void* GEOM_Function::GetCallBackData() { - Handle(GEOM_Function) _anOtherObject; + Handle(TDataStd_Comment) aComment; + TDF_Label aChild = _label.FindChild( CALLBACK_LABEL ); + if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return NULL; + TCollection_AsciiString string( aComment->Get() ); - if (!AnObject.IsNull()) { - if (AnObject->IsKind(STANDARD_TYPE(GEOM_Function))) { - _anOtherObject = Handle(GEOM_Function)((Handle(GEOM_Function)&)AnObject); - } - } + long long address; +#ifndef WIN32 + address = atoll ( string.ToCString() ); +#else + address = _strtoi64 ( string.ToCString(), NULL, 10 ); +#endif - return _anOtherObject ; + return reinterpret_cast ( address ); } + +IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient); +IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );