From 614185e8fd155a9af27fb7c31cf2bf6fc51d3d24 Mon Sep 17 00:00:00 2001 From: caremoli Date: Fri, 26 Nov 2010 11:05:09 +0000 Subject: [PATCH] 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 --- src/EntityGUI/EntityGUI_SketcherDlg.cxx | 2 +- src/EntityGUI/Makefile.am | 2 +- src/GEOMBase/GEOMBase.cxx | 4 +-- src/GEOMBase/GEOMBase_Helper.cxx | 4 +-- src/GEOMClient/GEOM_Client.cxx | 29 +++++++++++++++---- src/GEOMClient/GEOM_Client.hxx | 24 +++++++++++++++ .../GEOM_SelectionFilter.cxx | 2 +- src/GEOMGUI/GEOM_Displayer.cxx | 4 +-- src/GEOMGUI/GeometryGUI.h | 3 +- src/GEOMGUI/GeometryGUI_Swig.cxx | 2 +- src/GroupGUI/GroupGUI_GroupDlg.cxx | 6 ++-- src/RepairGUI/RepairGUI_SuppressFacesDlg.cxx | 2 +- 12 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/EntityGUI/EntityGUI_SketcherDlg.cxx b/src/EntityGUI/EntityGUI_SketcherDlg.cxx index 0400c1a4a..26f75a952 100644 --- a/src/EntityGUI/EntityGUI_SketcherDlg.cxx +++ b/src/EntityGUI/EntityGUI_SketcherDlg.cxx @@ -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()); diff --git a/src/EntityGUI/Makefile.am b/src/EntityGUI/Makefile.am index 1508f378f..c91a7ec91 100644 --- a/src/EntityGUI/Makefile.am +++ b/src/EntityGUI/Makefile.am @@ -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 \ diff --git a/src/GEOMBase/GEOMBase.cxx b/src/GEOMBase/GEOMBase.cxx index efd69ff3c..c35c11ea4 100644 --- a/src/GEOMBase/GEOMBase.cxx +++ b/src/GEOMBase/GEOMBase.cxx @@ -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; diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index de5f92978..28e585e94 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -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 ); } } } diff --git a/src/GEOMClient/GEOM_Client.cxx b/src/GEOMClient/GEOM_Client.cxx index 0e07e69d3..3e047e220 100644 --- a/src/GEOMClient/GEOM_Client.cxx +++ b/src/GEOMClient/GEOM_Client.cxx @@ -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); } } diff --git a/src/GEOMClient/GEOM_Client.hxx b/src/GEOMClient/GEOM_Client.hxx index f5f9cafc2..d20029719 100644 --- a/src/GEOMClient/GEOM_Client.hxx +++ b/src/GEOMClient/GEOM_Client.hxx @@ -73,6 +73,18 @@ class TopoDS_Shape; #define GEOMCLIENT_EXPORT #endif +#include +#include +#include +#include + +/* + * 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 > _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 diff --git a/src/GEOMFiltersSelection/GEOM_SelectionFilter.cxx b/src/GEOMFiltersSelection/GEOM_SelectionFilter.cxx index f90cc20e5..e8ca2276e 100644 --- a/src/GEOMFiltersSelection/GEOM_SelectionFilter.cxx +++ b/src/GEOMFiltersSelection/GEOM_SelectionFilter.cxx @@ -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() ) { diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 3196289e5..eb0cf2658 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -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(); } } diff --git a/src/GEOMGUI/GeometryGUI.h b/src/GEOMGUI/GeometryGUI.h index 4e4dd3921..175daa04c 100644 --- a/src/GEOMGUI/GeometryGUI.h +++ b/src/GEOMGUI/GeometryGUI.h @@ -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 myRules; // popup rules static StudyTextureMap myTextureMap; // texture map diff --git a/src/GEOMGUI/GeometryGUI_Swig.cxx b/src/GEOMGUI/GeometryGUI_Swig.cxx index 9c9c9533d..e052481da 100644 --- a/src/GEOMGUI/GeometryGUI_Swig.cxx +++ b/src/GEOMGUI/GeometryGUI_Swig.cxx @@ -68,7 +68,7 @@ #include -static GEOM_Client ShapeReader; +static SHAPE_READER(ShapeReader); inline OCCViewer_Viewer* GetOCCViewer(SUIT_Application* theApp){ SUIT_ViewWindow* window = theApp->desktop()->activeWindow(); diff --git a/src/GroupGUI/GroupGUI_GroupDlg.cxx b/src/GroupGUI/GroupGUI_GroupDlg.cxx index 327b0d4bb..1b2caa0d2 100644 --- a/src/GroupGUI/GroupGUI_GroupDlg.cxx +++ b/src/GroupGUI/GroupGUI_GroupDlg.cxx @@ -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(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; diff --git a/src/RepairGUI/RepairGUI_SuppressFacesDlg.cxx b/src/RepairGUI/RepairGUI_SuppressFacesDlg.cxx index 2469cefe6..65a390055 100644 --- a/src/RepairGUI/RepairGUI_SuppressFacesDlg.cxx +++ b/src/RepairGUI/RepairGUI_SuppressFacesDlg.cxx @@ -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); -- 2.39.2