X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMClient%2FGEOM_Client.cxx;h=871cd861a93274e97ebe3191cd97bef9ce16bba1;hb=refs%2Ftags%2FV9_9_0a2;hp=ba8711e4190cc3812f60cc01de178cdd91239960;hpb=ec168c32f86cab8199030ec4e8e2b1cbd5e42670;p=modules%2Fgeom.git diff --git a/src/GEOMClient/GEOM_Client.cxx b/src/GEOMClient/GEOM_Client.cxx index ba8711e41..871cd861a 100644 --- a/src/GEOMClient/GEOM_Client.cxx +++ b/src/GEOMClient/GEOM_Client.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2021 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 @@ -25,8 +25,6 @@ #include -#include - #include #include "GEOM_Client.hxx" @@ -141,8 +139,9 @@ GEOM_Client GEOM_Client::get_client() //======================================================================= Standard_Boolean GEOM_Client::Find (const TCollection_AsciiString& IOR, TopoDS_Shape& S) { - if (myShapesMap.count(IOR) != 0) { - S = myShapesMap[IOR]; + std::map< TCollection_AsciiString , TopoDS_Shape >::iterator i2s = myShapesMap.find( IOR ); + if ( i2s != myShapesMap.end() ) { + S = i2s->second; return Standard_True; } return Standard_False; @@ -168,9 +167,10 @@ Standard_Boolean GEOM_Client::Find (const TopoDS_Shape& S, TCollection_AsciiStri // function : Bind() // purpose : //======================================================================= -void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S ) +void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& S, int Tick ) { myShapesMap[IOR] = S; + myTicksMap[IOR] = Tick; } //======================================================================= @@ -179,13 +179,8 @@ void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape& //======================================================================= void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR) { - if (myShapesMap.size() == 0) - return; - - if (myShapesMap.count(IOR) != 0) { - myShapesMap.erase(IOR); - _mySubShapes.erase(IOR); - } + if ( myShapesMap.erase( IOR )) + _mySubShapes.erase( IOR ); } //======================================================================= @@ -194,79 +189,89 @@ void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR) //======================================================================= void GEOM_Client::ClearClientBuffer() { - if (myShapesMap.size() == 0) - return; - _mySubShapes.clear(); myShapesMap.clear(); } -//======================================================================= -// function : BufferLength() -// purpose : -//======================================================================= -unsigned int GEOM_Client::BufferLength() -{ - return myShapesMap.size(); -} - //======================================================================= // function : GetShape() // purpose : //======================================================================= TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape ) { - TopoDS_Shape S; - CORBA::String_var anIOR = geom->GetStringFromIOR(aShape); - TCollection_AsciiString IOR = (char*)anIOR.in(); - Standard_Boolean anIndex = Find(IOR, S); + CORBA::String_var anIOR = geom->GetStringFromIOR(aShape); + TCollection_AsciiString IOR = anIOR.in(); + + // Special treatment for groups: group value (shape) is computed on + // first demand, and its tick is set to main shape's tick after that; + // tick of modified group is decremented. + // There is a not fixed problem: if anyone modifies a group and updates + // it before call to this method, the group will not be changed in the buffer + bool isModifiedSubShape = false; + int aShapeTick = aShape->GetTick(); + if ( !aShape->IsMainShape() ) { + int anOldTick = aShapeTick; + aShape->GetShapeType(); // compute subshape and update its tick, if not yet + aShapeTick = aShape->GetTick(); + isModifiedSubShape = (anOldTick != aShapeTick); + } - if (anIndex) return S; + std::map< TCollection_AsciiString , int >::iterator i2t = myTicksMap.find( IOR ); + if ( i2t != myTicksMap.end() ) { + if (i2t->second != aShapeTick || isModifiedSubShape) { + // The shape was modified, clean the stored one + RemoveShapeFromBuffer(IOR); + } + } + + TopoDS_Shape S; + if ( Find( IOR, S )) + return S; /******* in case of a MAIN GEOM::SHAPE ********/ - if (aShape->IsMainShape()) { + if ( aShape->IsMainShape() ) { S = Load(geom, aShape); - Bind(IOR, S); + Bind(IOR, S, aShapeTick); return S; } /******* in case of SUB GEOM::SHAPE ***********/ // Load and Explore the Main Shape - TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape()); - GEOM::ListOfLong_var list = aShape->GetSubShapeIndices(); + GEOM::GEOM_Object_var mainGO = aShape->GetMainShape(); + TopoDS_Shape aMainShape = GetShape( geom, mainGO ); + GEOM::ListOfLong_var list = aShape->GetSubShapeIndices(); - CORBA::String_var aMainIOR = geom->GetStringFromIOR(aShape->GetMainShape()); - TCollection_AsciiString mainIOR = (char*)aMainIOR.in(); + CORBA::String_var aMainIOR = geom->GetStringFromIOR( mainGO ); + TCollection_AsciiString mainIOR = aMainIOR.in(); //find subshapes only one time - if (_mySubShapes.count(mainIOR) == 0) + auto pos2isnew = _mySubShapes.insert( std::make_pair( mainIOR, std::vector() )); + std::vector & subShapes = pos2isnew.first->second; + if ( pos2isnew.second ) { TopTools_IndexedMapOfShape anIndices; - TopExp::MapShapes(aMainShape, anIndices); - Standard_Integer ii = 1, nbSubSh = anIndices.Extent(); - for (; ii <= nbSubSh; ii++) - { - _mySubShapes[mainIOR].push_back(anIndices.FindKey(ii)); - } + TopExp::MapShapes( aMainShape, anIndices ); + subShapes.insert( subShapes.end(), anIndices.cbegin(), anIndices.cend() ); } - /* Case of only one subshape */ - if (list->length() == 1 && list[0] > 0) { - S = _mySubShapes[mainIOR][list[0]-1]; + /* Case of only one subshape, excluding groups of one main shape */ + if ( list->length() == 1 && + !(aShape->GetType() == 37 && list[0] == 1) && + list[0] > 0 ) { + S = subShapes[list[0]-1]; } else { BRep_Builder B; TopoDS_Compound aCompound; B.MakeCompound(aCompound); - for (int i = 0; i < list->length(); i++) { - if (0 < list[i] && list[i] <= _mySubShapes[mainIOR].size()) { - TopoDS_Shape aSubShape = _mySubShapes[mainIOR][list[i]-1]; - B.Add(aCompound, aSubShape); - } - } + CORBA::Long nbSub = subShapes.size(); + for ( size_t i = 0; i < list->length(); i++ ) + if ( 0 < list[i] && list[i] <= nbSub ) + B.Add(aCompound, subShapes[list[i]-1] ); S = aCompound; } - Bind(IOR, S); + + Bind(IOR, S, aShapeTick); return S; }