NPAL17269: Performance pb. when creating a group with GUI.

This commit is contained in:
jfa 2007-10-16 10:34:26 +00:00
parent f9e7e9c10e
commit faef7428c3
2 changed files with 294 additions and 246 deletions

View File

@ -17,31 +17,31 @@
// //
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
// //
#include "GEOMGUI_OCCSelector.h" #include "GEOMGUI_OCCSelector.h"
#include <LightApp_DataSubOwner.h> #include <LightApp_DataSubOwner.h>
#include <OCCViewer_ViewModel.h> #include <OCCViewer_ViewModel.h>
#include <SALOME_InteractiveObject.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <AIS_Shape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <SelectMgr_IndexedMapOfOwner.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectBasics_SensitiveEntity.hxx>
#include <StdSelect_BRepOwner.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <SelectMgr_IndexedMapOfOwner.hxx>
#include <NCollection_DataMap.hxx>
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SalomeApp_Study.h> #include <SalomeApp_Study.h>
#include <SALOME_InteractiveObject.hxx>
#include <StdSelect_BRepOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_IndexedMapOfOwner.hxx>
#include <SelectBasics_SensitiveEntity.hxx>
#include <AIS_Shape.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <NCollection_DataMap.hxx>
//================================================================ //================================================================
@ -75,6 +75,9 @@ void GEOMGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
if (ic->HasOpenedContext()) if (ic->HasOpenedContext())
{ {
TopoDS_Shape curBigShape;
TopTools_IndexedMapOfShape subShapes;
for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) for (ic->InitSelected(); ic->MoreSelected(); ic->NextSelected())
{ {
Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(ic->SelectedOwner()); Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(ic->SelectedOwner());
@ -94,8 +97,11 @@ void GEOMGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
{ {
TopoDS_Shape bigShape = aisShape->Shape(); TopoDS_Shape bigShape = aisShape->Shape();
TopTools_IndexedMapOfShape subShapes; if (!bigShape.IsEqual(curBigShape))
{
curBigShape = bigShape;
TopExp::MapShapes(bigShape, subShapes); TopExp::MapShapes(bigShape, subShapes);
}
index = subShapes.FindIndex(subShape); index = subShapes.FindIndex(subShape);
} }
} }
@ -127,12 +133,13 @@ void GEOMGUI_OCCSelector::getSelection( SUIT_DataOwnerPtrList& aList ) const
} }
} }
} }
// add externally selected objects // add externally selected objects
SUIT_DataOwnerPtrList::const_iterator anExtIter; SUIT_DataOwnerPtrList::const_iterator anExtIter;
for(anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++) { for (anExtIter = mySelectedExternals.begin(); anExtIter != mySelectedExternals.end(); anExtIter++)
{
aList.append(*anExtIter); aList.append(*anExtIter);
} }
} }
//================================================================ //================================================================
@ -182,7 +189,9 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
Handle(AIS_InteractiveContext) ic = vw->getAISContext(); Handle(AIS_InteractiveContext) ic = vw->getAISContext();
NCollection_DataMap<TCollection_AsciiString, TColStd_IndexedMapOfInteger> indexesMap; // "entry - list_of_int" map for LOCAL selection // "entry - list_of_int" map for LOCAL selection
NCollection_DataMap<TCollection_AsciiString, TColStd_IndexedMapOfInteger> indexesMap;
QMap<QString,int> globalSelMap; // only Key=entry from this map is used. value(int) is NOT used at all. QMap<QString,int> globalSelMap; // only Key=entry from this map is used. value(int) is NOT used at all.
SelectMgr_IndexedMapOfOwner ownersmap; // map of owners to be selected SelectMgr_IndexedMapOfOwner ownersmap; // map of owners to be selected
@ -219,7 +228,8 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() ); const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr).operator->() );
if ( owner ) if ( owner )
{ {
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() ); SalomeApp_Study* appStudy =
dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
QString anEntry = appStudy->referencedToEntry( owner->entry() ); QString anEntry = appStudy->referencedToEntry( owner->entry() );
globalSelMap[anEntry] = 1; globalSelMap[anEntry] = 1;
@ -238,10 +248,36 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
SelectMgr_IndexedMapOfOwner owners; SelectMgr_IndexedMapOfOwner owners;
getEntityOwners( io, ic, owners ); // get all owners getEntityOwners( io, ic, owners ); // get all owners
for ( int i = 1, n = owners.Extent(); i <= n; i++ ) int i, n = owners.Extent();
{
Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(owners( i )); // 1. Prepare map of shapes for local selection
TopTools_IndexedMapOfShape aMapOfShapes;
bool isLocal = false;
Handle(StdSelect_BRepOwner) anOwner;
for (i = 1; i <= n && !isLocal; i++)
{
anOwner = Handle(StdSelect_BRepOwner)::DownCast(owners( i ));
if (!anOwner.IsNull() && anOwner->HasShape())
{
if (anOwner->ComesFromDecomposition() || !globalSelMap.contains(entryStr))
{
// has a local selection
Handle(AIS_Shape) aisShape = Handle(AIS_Shape)::DownCast( io );
if (!aisShape.IsNull() && indexesMap.IsBound((char*)entryStr.latin1()))
{
isLocal = true;
TopoDS_Shape shape = aisShape->Shape();
TopExp::MapShapes(shape, aMapOfShapes);
}
}
}
}
// 2. Process all owners
for (i = 1; i <= n; i++)
{
anOwner = Handle(StdSelect_BRepOwner)::DownCast(owners( i ));
if ( anOwner.IsNull() || !anOwner->HasShape() ) if ( anOwner.IsNull() || !anOwner->HasShape() )
continue; continue;
@ -255,14 +291,10 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
// LOCAL selection // LOCAL selection
else else
{ {
Handle(AIS_Shape) aisShape = Handle(AIS_Shape)::DownCast( io ); if (isLocal)
if ( !aisShape.IsNull() && indexesMap.IsBound( (char*)entryStr.latin1() ) )
{ {
TopoDS_Shape shape = aisShape->Shape(); const TColStd_IndexedMapOfInteger& subIndexes =
TopTools_IndexedMapOfShape aMapOfShapes; indexesMap.ChangeFind((char*)entryStr.latin1());
TopExp::MapShapes( shape, aMapOfShapes );
const TColStd_IndexedMapOfInteger& subIndexes = indexesMap.ChangeFind((char*)entryStr.latin1());
const TopoDS_Shape& aSubShape = anOwner->Shape(); const TopoDS_Shape& aSubShape = anOwner->Shape();
int aSubShapeId = aMapOfShapes.FindIndex( aSubShape ); int aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
@ -274,7 +306,7 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
ownersmap.Add( anOwner ); ownersmap.Add( anOwner );
} }
} }
} // end of local selection } // end of LOCAL selection
} // end of for(owners) } // end of for(owners)
} // end of if(entry) } // end of if(entry)
} // end of for(AIS_all_ios) } // end of for(AIS_all_ios)
@ -298,14 +330,17 @@ void GEOMGUI_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& aList )
// fill extra selected // fill extra selected
mySelectedExternals.clear(); mySelectedExternals.clear();
for ( SUIT_DataOwnerPtrList::const_iterator itr2 = aList.begin(); itr2 != aList.end(); ++itr2 ) { for ( SUIT_DataOwnerPtrList::const_iterator itr2 = aList.begin(); itr2 != aList.end(); ++itr2 )
const LightApp_DataSubOwner* subOwner = dynamic_cast<const LightApp_DataSubOwner*>( (*itr2).operator->() ); {
const LightApp_DataSubOwner* subOwner =
dynamic_cast<const LightApp_DataSubOwner*>( (*itr2).operator->() );
if ( !subOwner ) if ( !subOwner )
{ {
const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr2).operator->() ); const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*itr2).operator->() );
if ( owner ) if ( owner )
{ {
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() ); SalomeApp_Study* appStudy =
dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
QString anEntry = appStudy->referencedToEntry( owner->entry() ); QString anEntry = appStudy->referencedToEntry( owner->entry() );
if (globalSelMap[anEntry] == 1) mySelectedExternals.append(*itr2); if (globalSelMap[anEntry] == 1) mySelectedExternals.append(*itr2);
} }

View File

@ -401,9 +401,8 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
return; return;
GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() ); GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
GEOM::ListOfGO_var aSubShapes = aShOp->MakeExplode( myMainObj, getShapeType(), false ); GEOM::ListOfLong_var aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
if ( !aShOp->IsDone() ) if ( !aShOp->IsDone() )
return; return;
@ -413,7 +412,7 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
QListBoxItem* anItem; QListBoxItem* anItem;
for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) { for ( int i = 0, n = aSubShapes->length(); i < n; i++ ) {
CORBA::Long anIndex = aLocOp->GetSubShapeIndex( myMainObj, aSubShapes[i] ); CORBA::Long anIndex = aSubShapes[i];
if ( anIndex < 0 ) if ( anIndex < 0 )
continue; continue;
@ -424,7 +423,7 @@ void GroupGUI_GroupDlg::selectAllSubShapes()
myIdList->blockSignals( isBlocked ); myIdList->blockSignals( isBlocked );
highlightSubShapes(); highlightSubShapes();
updateState(); //updateState(); // already done in highlightSubShapes()
} }
//================================================================================= //=================================================================================
@ -585,20 +584,29 @@ void GroupGUI_GroupDlg::updateState()
TColStd_IndexedMapOfInteger aMapIndex; TColStd_IndexedMapOfInteger aMapIndex;
if ( IObjectCount() == 1 ) { SALOME_ListIO aSelIOs;
SalomeApp_Application* app = myGeomGUI->getApp();
if (app) {
LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
if (aSelMgr) {
aSelMgr->selectedObjects(aSelIOs);
if ( aSelIOs.Extent() == 1 ) {
Standard_Boolean aResult = Standard_False; Standard_Boolean aResult = Standard_False;
GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object_var anObj =
GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult ); GEOMBase::ConvertIOinGEOMObject( aSelIOs.First(), aResult );
if ( aResult && !anObj->_is_nil() ) if ( aResult && !anObj->_is_nil() )
((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))-> aSelMgr->GetIndexes( aSelIOs.First(), aMapIndex );
selectionMgr()->GetIndexes( firstIObject(), aMapIndex ); }
}
} }
// try to find out and process the object browser selection // try to find out and process the object browser selection
if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) { if ( !aMapIndex.Extent() && !CORBA::is_nil( myMainObj ) ) {
GEOM::ListOfGO anObjects; GEOM::ListOfGO anObjects;
GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects); //GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), anObjects);
GEOMBase::ConvertListOfIOInListOfGO(aSelIOs, anObjects);
GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() ); GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations( getStudyId() );
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() ); GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
@ -610,15 +618,14 @@ void GroupGUI_GroupDlg::updateState()
GEOM::GEOM_Object_var aGeomObj = anObjects[i]; GEOM::GEOM_Object_var aGeomObj = anObjects[i];
GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO(); GEOM::ListOfGO_var aSubObjects = new GEOM::ListOfGO();
TopoDS_Shape aShape; TopoDS_Shape aShape;
if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) if ( GEOMBase::GetShape(aGeomObj, aShape, getShapeType()) ) {
{
aSubObjects->length(1); aSubObjects->length(1);
aSubObjects[0] = aGeomObj; aSubObjects[0] = aGeomObj;
} }
else if (aGeomObj->GetType() == GEOM_GROUP) else if (aGeomObj->GetType() == GEOM_GROUP) {
aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false); aSubObjects = aShapesOp->MakeExplode( aGeomObj, getShapeType(), false);
else }
{ else {
aMapIndex.Clear(); aMapIndex.Clear();
break; break;
} }
@ -682,8 +689,7 @@ void GroupGUI_GroupDlg::highlightSubShapes()
Standard_Boolean isOk; Standard_Boolean isOk;
char* objIOR = GEOMBase::GetIORFromObject( myMainObj ); char* objIOR = GEOMBase::GetIORFromObject( myMainObj );
Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
GEOMBase::ConvertIORinGEOMAISShape( objIOR, isOk, true );
free( objIOR ); free( objIOR );
if ( !isOk || aSh.IsNull() ) if ( !isOk || aSh.IsNull() )
return; return;
@ -766,14 +772,22 @@ bool GroupGUI_GroupDlg::execute( ObjectList& objects )
if (!anOp->IsDone()) if (!anOp->IsDone())
return false; return false;
for ( int i = 0, n = aCurrList->length(); i < n; i++ ) { if (aCurrList->length() > 0)
anOp->RemoveObject( aGroup, aCurrList[i] ); {
anOp->DifferenceIDs(aGroup, aCurrList);
if (!anOp->IsDone()) if (!anOp->IsDone())
return false; return false;
} }
for ( int ii = 0, nn = myIdList->count(); ii < nn; ii++ ) { int ii, nn = myIdList->count();
anOp->AddObject( aGroup, myIdList->item( ii )->text().toInt() ); if (nn > 0)
{
GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
aNewList->length(nn);
for (ii = 0; ii < nn; ii++) {
aNewList[ii] = myIdList->item(ii)->text().toInt();
}
anOp->UnionIDs(aGroup, aNewList);
if (!anOp->IsDone()) if (!anOp->IsDone())
return false; return false;
} }
@ -811,4 +825,3 @@ GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather( GEOM::GEOM_Object_ptr theObj
} }
return aFatherObj._retn(); return aFatherObj._retn();
} }