CCAR: GEOM_Client modification to optimize the method find

and the method GetShape when a main shape has a lot of subshapes
The way of creation of GEOM_Client has also been changed : now, it's
a singleton object. It is possible to revert to the old creation way
by commenting the #define SINGLE_CLIENT instruction in GEOM_Client.hxx
This commit is contained in:
caremoli 2010-11-26 11:05:09 +00:00
parent 16f91b82f4
commit 614185e8fd
12 changed files with 62 additions and 22 deletions

View File

@ -2309,7 +2309,7 @@ void EntityGUI_SketcherDlg::FindLocalCS()
continue;
if (geomObj->GetType() == GEOM_MARKER) {
ComboBox1->addItem(geomObj->GetName());
TopoDS_Shape aShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
TopoDS_Shape aShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), geomObj);
gp_Ax3 aLCS;
aLCS.Transform(aShape.Location().Transformation());

View File

@ -53,7 +53,7 @@ nodist_libEntityGUI_la_SOURCES = \
UIC_FILES = \
ui_EntityGUI_1Sel_QTD.h \
ui_EntityGUI_2Sel1Check_QTD.h \
ui_EntityGUI_2Sel1Check_QTD.h \
ui_EntityGUI_1Sel1Spin1Check_QTD.h \
ui_EntityGUI_1Spin_QTD.h \
ui_EntityGUI_2Spin_QTD.h \

View File

@ -85,7 +85,7 @@ TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
if (GeomObject->_is_nil())
return result;
result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
result = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
return result;
}
@ -909,7 +909,7 @@ bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& t
{
if ( !CORBA::is_nil( theObject ) )
{
TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
TopoDS_Shape aTopoDSShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObject );
if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
{
theShape = aTopoDSShape;

View File

@ -656,7 +656,7 @@ void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
TCollection_AsciiString asciiIOR( (char *)IOR.in() );
GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
if ( !getStudy() || !getStudy()->studyDS() )
return;
@ -672,7 +672,7 @@ void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
_PTR(AttributeIOR) anIOR ( anAttr );
TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
}
}
}

View File

@ -117,12 +117,12 @@ GEOM_Client::GEOM_Client(Engines::Container_ptr client)
//=======================================================================
Standard_Integer GEOM_Client::Find( const TCollection_AsciiString& IOR, TopoDS_Shape& S )
{
for ( Standard_Integer i = 1; i<= myIORs.Length(); i++ ) {
if (myIORs.Value(i).IsEqual(IOR)) {
if(_myIndexes.count(IOR) != 0)
{
Standard_Integer i =_myIndexes[IOR];
S = myShapes.Value(i);
return i;
}
}
return 0;
}
@ -149,6 +149,7 @@ void GEOM_Client::Bind( const TCollection_AsciiString& IOR, const TopoDS_Shape&
{
myIORs.Append(IOR);
myShapes.Append(S);
_myIndexes[IOR]=myIORs.Length();
}
//=======================================================================
@ -165,6 +166,8 @@ void GEOM_Client::RemoveShapeFromBuffer( const TCollection_AsciiString& IOR)
if( anIndex != 0 ) {
myIORs.Remove(anIndex);
myShapes.Remove(anIndex);
_myIndexes.erase(IOR);
_mySubShapes.erase(IOR);
}
return;
}
@ -179,6 +182,8 @@ void GEOM_Client::ClearClientBuffer()
return;
myIORs.Clear();
myShapes.Clear();
_myIndexes.clear();
_mySubShapes.clear();
return;
}
@ -217,11 +222,23 @@ TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_p
GEOM::ListOfLong_var list = aShape->GetSubShapeIndices();
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aMainShape, anIndices);
CORBA::String_var aMainIOR = geom->GetStringFromIOR(aShape->GetMainShape());
TCollection_AsciiString mainIOR = (char*)aMainIOR.in();
//find subshapes only one time
if(_mySubShapes.count(mainIOR)==0)
{
TopExp::MapShapes(aMainShape, anIndices);
Standard_Integer ii = 1, nbSubSh = anIndices.Extent();
for (; ii <= nbSubSh; ii++)
{
_mySubShapes[mainIOR].push_back(anIndices.FindKey(ii));
}
}
/* Case of only one subshape */
if (list->length() == 1 && list[0] > 0) {
S = anIndices.FindKey(list[0]);
S = _mySubShapes[mainIOR][list[0]-1];
}
else {
BRep_Builder B;
@ -229,7 +246,7 @@ TopoDS_Shape GEOM_Client::GetShape( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_p
B.MakeCompound(aCompound);
for (int i = 0; i < list->length(); i++) {
if (0 < list[i] && list[i] <= anIndices.Extent()) {
TopoDS_Shape aSubShape = anIndices.FindKey(list[i]);
TopoDS_Shape aSubShape = _mySubShapes[mainIOR][list[i]-1];
B.Add(aCompound, aSubShape);
}
}

View File

@ -73,6 +73,18 @@ class TopoDS_Shape;
#define GEOMCLIENT_EXPORT
#endif
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Shape.hxx>
#include <map>
#include <vector>
/*
* if define SINGLE_CLIENT is not commented, the method get_client always returns the same GEOM_Client object (singleton object)
* and the SHAPE_READER macro can be used to define an object that is always this singleton object
* if define SINGLE_CLIENT is commented, we get the old way to define the GEOM_Client objects : get_client returns a new object
* and the SHAPE_READER macro defines also a new object
*/
#define SINGLE_CLIENT
//=====================================================================
// GEOM_Client : class definition
//=====================================================================
@ -113,14 +125,26 @@ public:
//Standard_EXPORT
unsigned int BufferLength() ;
TopoDS_Shape Load( GEOM::GEOM_Gen_ptr geom, GEOM::GEOM_Object_ptr aShape);
#ifdef SINGLE_CLIENT
static GEOM_Client& get_client() { static GEOM_Client a;return a; }
#else
static GEOM_Client get_client() { return GEOM_Client(); }
#endif
private:
// Fields PRIVATE
//
TColStd_SequenceOfAsciiString myIORs ;
TopTools_SequenceOfShape myShapes ;
std::map< TCollection_AsciiString , int > _myIndexes;
std::map< TCollection_AsciiString , std::vector<TopoDS_Shape> > _mySubShapes;
long pid_client;
};
#ifdef SINGLE_CLIENT
#define SHAPE_READER(obj) GEOM_Client& obj=GEOM_Client::get_client()
#else
#define SHAPE_READER(obj) GEOM_Client obj
#endif
#endif

View File

@ -139,7 +139,7 @@ bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
}
if ( !CORBA::is_nil( geomGen ) )
{
TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
TopoDS_Shape aTopoDSShape = GEOM_Client::get_client().GetShape( geomGen, theObject );
if ( !aTopoDSShape.IsNull() )
{

View File

@ -968,7 +968,7 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
return 0;
internalReset();
setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
myType = theObj->GetType();
// Update presentation
@ -1049,7 +1049,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
if ( !GeomObject->_is_nil() )
{
// finally set shape
setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
myType = GeomObject->GetType();
}
}

View File

@ -89,7 +89,7 @@ public:
static void Modified( bool = true );
GEOM_Client& GetShapeReader() { return myShapeReader; }
GEOM_Client& GetShapeReader() { static SHAPE_READER(myShapeReader);return myShapeReader; }
// Get active dialog box
QDialog* GetActiveDialogBox(){ return myActiveDialogBox; }
@ -169,7 +169,6 @@ private:
GUIMap myGUIMap; // GUI libraries map
QDialog* myActiveDialogBox; // active dialog box
GEOM_Client myShapeReader; // geom shape reader
gp_Ax3 myWorkingPlane;
QMap<int,QString> myRules; // popup rules
static StudyTextureMap myTextureMap; // texture map

View File

@ -68,7 +68,7 @@
#include <vtkRenderer.h>
static GEOM_Client ShapeReader;
static SHAPE_READER(ShapeReader);
inline OCCViewer_Viewer* GetOCCViewer(SUIT_Application* theApp){
SUIT_ViewWindow* window = theApp->desktop()->activeWindow();

View File

@ -654,7 +654,7 @@ int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMap
if (GEOMBase::GetShape(aGeomObj, aShape)) {
if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
TopTools_IndexedMapOfShape aMainMap;
TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
TopExp::MapShapes(aMainShape, aMainMap);
TopExp_Explorer anExp (aShape, getShapeType());
@ -804,12 +804,12 @@ void GroupGUI_GroupDlg::activateSelection()
SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
if (aView == 0) return;
TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
TopoDS_Shape aRestrictionShape;
if (subSelectionWay() == ALL_SUBSHAPES)
aRestrictionShape = aMainShape;
else if (!myInPlaceObj->_is_nil())
aRestrictionShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
aRestrictionShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
else ;
TopTools_IndexedMapOfShape aSubShapesMap;

View File

@ -213,7 +213,7 @@ void RepairGUI_SuppressFacesDlg::SelectionIntoArgument()
_PTR(Study) aStudy = appStudy->studyDS();
TopTools_IndexedMapOfShape aMainMap;
TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myObject);
TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myObject);
TopExp::MapShapes(aMainShape, aMainMap);
SALOME_ListIteratorOfListIO anIter (aSelList);