mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2024-11-11 16:19:17 +05:00
Optimize work with std::map
This commit is contained in:
parent
ed0f1a6b82
commit
43c219aae9
@ -119,7 +119,8 @@ GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HSequenceOfTransient)&
|
|||||||
{
|
{
|
||||||
if ( funs->Length() > 1 )
|
if ( funs->Length() > 1 )
|
||||||
(*this) << funs->Length() << " objects: ";
|
(*this) << funs->Length() << " objects: ";
|
||||||
for ( int i = 1; i <= funs->Length(); ++i )
|
int nb = Min( 100, funs->Length() ); // don't show huge lists
|
||||||
|
for ( int i = 1; i <= nb; ++i )
|
||||||
(*this) << funs->Value( i ) << " ";
|
(*this) << funs->Value( i ) << " ";
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
#include <Standard_Stream.hxx>
|
#include <Standard_Stream.hxx>
|
||||||
|
|
||||||
#include <Standard_Stream.hxx>
|
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "GEOM_Client.hxx"
|
#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)
|
Standard_Boolean GEOM_Client::Find (const TCollection_AsciiString& IOR, TopoDS_Shape& S)
|
||||||
{
|
{
|
||||||
if (myShapesMap.count(IOR) != 0) {
|
std::map< TCollection_AsciiString , TopoDS_Shape >::iterator i2s = myShapesMap.find( IOR );
|
||||||
S = myShapesMap[IOR];
|
if ( i2s != myShapesMap.end() ) {
|
||||||
|
S = i2s->second;
|
||||||
return Standard_True;
|
return Standard_True;
|
||||||
}
|
}
|
||||||
return Standard_False;
|
return Standard_False;
|
||||||
@ -179,13 +178,8 @@ void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape&
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
|
void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
|
||||||
{
|
{
|
||||||
if (myShapesMap.size() == 0)
|
if ( myShapesMap.erase( IOR ))
|
||||||
return;
|
_mySubShapes.erase( IOR );
|
||||||
|
|
||||||
if (myShapesMap.count(IOR) != 0) {
|
|
||||||
myShapesMap.erase(IOR);
|
|
||||||
_mySubShapes.erase(IOR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
@ -194,9 +188,6 @@ void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
void GEOM_Client::ClearClientBuffer()
|
void GEOM_Client::ClearClientBuffer()
|
||||||
{
|
{
|
||||||
if (myShapesMap.size() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_mySubShapes.clear();
|
_mySubShapes.clear();
|
||||||
myShapesMap.clear();
|
myShapesMap.clear();
|
||||||
}
|
}
|
||||||
@ -218,13 +209,12 @@ TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_p
|
|||||||
{
|
{
|
||||||
TopoDS_Shape S;
|
TopoDS_Shape S;
|
||||||
CORBA::String_var anIOR = geom->GetStringFromIOR(aShape);
|
CORBA::String_var anIOR = geom->GetStringFromIOR(aShape);
|
||||||
TCollection_AsciiString IOR = (char*)anIOR.in();
|
TCollection_AsciiString IOR = anIOR.in();
|
||||||
Standard_Boolean anIndex = Find(IOR, S);
|
if ( Find( IOR, S ))
|
||||||
|
return S;
|
||||||
if (anIndex) return S;
|
|
||||||
|
|
||||||
/******* in case of a MAIN GEOM::SHAPE ********/
|
/******* in case of a MAIN GEOM::SHAPE ********/
|
||||||
if (aShape->IsMainShape()) {
|
if ( aShape->IsMainShape() ) {
|
||||||
S = Load(geom, aShape);
|
S = Load(geom, aShape);
|
||||||
Bind(IOR, S);
|
Bind(IOR, S);
|
||||||
return S;
|
return S;
|
||||||
@ -232,38 +222,35 @@ TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_p
|
|||||||
|
|
||||||
/******* in case of SUB GEOM::SHAPE ***********/
|
/******* in case of SUB GEOM::SHAPE ***********/
|
||||||
// Load and Explore the Main Shape
|
// Load and Explore the Main Shape
|
||||||
TopoDS_Shape aMainShape = GetShape (geom, aShape->GetMainShape());
|
GEOM::GEOM_Object_var mainGO = aShape->GetMainShape();
|
||||||
|
TopoDS_Shape aMainShape = GetShape( geom, mainGO );
|
||||||
GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
|
GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
|
||||||
|
|
||||||
CORBA::String_var aMainIOR = geom->GetStringFromIOR(aShape->GetMainShape());
|
CORBA::String_var aMainIOR = geom->GetStringFromIOR( mainGO );
|
||||||
TCollection_AsciiString mainIOR = (char*)aMainIOR.in();
|
TCollection_AsciiString mainIOR = aMainIOR.in();
|
||||||
|
|
||||||
//find subshapes only one time
|
//find subshapes only one time
|
||||||
if (_mySubShapes.count(mainIOR) == 0)
|
auto pos2isnew = _mySubShapes.insert( std::make_pair( mainIOR, std::vector<TopoDS_Shape>() ));
|
||||||
|
std::vector<TopoDS_Shape> & subShapes = pos2isnew.first->second;
|
||||||
|
if ( pos2isnew.second )
|
||||||
{
|
{
|
||||||
TopTools_IndexedMapOfShape anIndices;
|
TopTools_IndexedMapOfShape anIndices;
|
||||||
TopExp::MapShapes(aMainShape, anIndices);
|
TopExp::MapShapes( aMainShape, anIndices );
|
||||||
Standard_Integer ii = 1, nbSubSh = anIndices.Extent();
|
subShapes.insert( subShapes.end(), anIndices.cbegin(), anIndices.cend() );
|
||||||
for (; ii <= nbSubSh; ii++)
|
|
||||||
{
|
|
||||||
_mySubShapes[mainIOR].push_back(anIndices.FindKey(ii));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Case of only one subshape */
|
/* Case of only one subshape */
|
||||||
if (list->length() == 1 && list[0] > 0) {
|
if ( list->length() == 1 && list[0] > 0 ) {
|
||||||
S = _mySubShapes[mainIOR][list[0]-1];
|
S = subShapes[list[0]-1];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BRep_Builder B;
|
BRep_Builder B;
|
||||||
TopoDS_Compound aCompound;
|
TopoDS_Compound aCompound;
|
||||||
B.MakeCompound(aCompound);
|
B.MakeCompound(aCompound);
|
||||||
for (size_t i = 0; i < list->length(); i++) {
|
CORBA::Long nbSub = subShapes.size();
|
||||||
if (0 < list[i] && list[i] <= (CORBA::Long)_mySubShapes[mainIOR].size()) {
|
for ( size_t i = 0; i < list->length(); i++ )
|
||||||
TopoDS_Shape aSubShape = _mySubShapes[mainIOR][list[i]-1];
|
if ( 0 < list[i] && list[i] <= nbSub )
|
||||||
B.Add(aCompound, aSubShape);
|
B.Add(aCompound, subShapes[list[i]-1] );
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
S = aCompound;
|
S = aCompound;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user