1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0026886: Visualization, TKV3d - eliminate global variables

- AIS_InteractiveContext - create new dummy class field to have an empty TopoDS_Shape object.
- AIS_Point, PrsMgr_PresentableObject - rename static variables to local function variables.
- AIS_Shape, SelectMgr_SelectableObject - remove unused static variables.
- Graphic3d_MaterialAspect, V3d_Viewer - make global static variables as constant.
- V3d_View - move global variable zRotation to class field.
- Move a variable theCurrentSelection as a field of AIS_InteractiveContext and AIS_LocalContext classes. Multiple selection is not used now, so each Context have an own selection.
- Move myStructGenId from Graphic3d_StructureManager to Graphic3d_GraphicDriver for identifying the structures in the driver.
- Move default variable (no shading light) from static value to the class field of OpenGL_View.
Porting note:
- Static methods of AIS_Selection is not used now. Methods of
  AIS_InteractiveContext::InitSelected(),::MoreSelected(),::NextSelected()
  should be used instead of static methods of AIS_Selection.
This commit is contained in:
mpa
2016-04-08 09:47:47 +03:00
committed by bugmaster
parent 83da37b115
commit 016e595986
39 changed files with 313 additions and 778 deletions

View File

@@ -21,147 +21,50 @@
#include <Standard_Transient.hxx>
#include <Standard_Type.hxx>
#include <Standard_TypeMismatch.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_SequenceOfTransient.hxx>
IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection,MMgt_TShared)
#define MaxSizeOfResult 100000
//current selection (handle)
static Handle(AIS_Selection) theCurrentSelection;
static void AIS_Sel_CurrentSelection (Handle(AIS_Selection)& InputSel)
{
if(!InputSel.IsNull())
theCurrentSelection = InputSel;
else
InputSel = theCurrentSelection;
}
static TColStd_SequenceOfTransient& AIS_Sel_GetSelections()
{
static TColStd_SequenceOfTransient Selections;
return Selections;
}
//=======================================================================
//function : AIS_Selection
//purpose :
//=======================================================================
AIS_Selection::AIS_Selection(const Standard_CString aName) :
myName(TCollection_AsciiString(aName)),
AIS_Selection::AIS_Selection() :
myNb(0)
{
myResultMap.ReSize( MaxSizeOfResult ); // for maximum performnace on medium selections ( < 100000 objects )
}
//=======================================================================
//function : CreateSelection
//purpose :
//=======================================================================
Standard_Boolean AIS_Selection::CreateSelection(const Standard_CString aName)
{
Handle(AIS_Selection) S = AIS_Selection::Selection(aName);
if(!S.IsNull())
return Standard_False;
S = new AIS_Selection(aName);
AIS_Sel_GetSelections().Prepend(S);
AIS_Sel_CurrentSelection(S);
return Standard_True;
}
//=======================================================================
//function : Selection
//purpose :
//=======================================================================
Handle(AIS_Selection) AIS_Selection::Selection(const Standard_CString aName)
{
Handle(AIS_Selection) S;
if(AIS_Sel_GetSelections().IsEmpty()) return S;
Handle(Standard_Transient) curobj;
Handle(AIS_Selection) Sel;
// Standard_Boolean found(Standard_False);
for(Standard_Integer I =1; I<= AIS_Sel_GetSelections().Length();I++){
curobj = AIS_Sel_GetSelections().Value(I);
Sel = Handle(AIS_Selection)::DownCast (curobj);
if(Sel->myName.IsEqual(aName))
return Sel;
}
return S;
}
//=======================================================================
//function : Find
//purpose :
//=======================================================================
Standard_Boolean AIS_Selection::Find(const Standard_CString aName)
{
Handle(AIS_Selection) S = AIS_Selection::Selection(aName);
return !S.IsNull();
}
//=======================================================================
//function : SetCurrentSelection
//purpose :
//=======================================================================
Standard_Boolean AIS_Selection::SetCurrentSelection (const Standard_CString aName)
{
AIS_Selection::CreateSelection(aName);
Handle(AIS_Selection) anAISSelection = AIS_Selection::Selection(aName) ;
AIS_Sel_CurrentSelection ( anAISSelection ) ;
return Standard_True;
}
//=======================================================================
//function : Select
//purpose :
//=======================================================================
void AIS_Selection::Select()
{
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if(!S.IsNull()){
S->myNb=0;
S->myresult.Clear();
S->myResultMap.Clear();
}
myNb=0;
myresult.Clear();
myResultMap.Clear();
}
//=======================================================================
//function : CurrentSelection
//purpose :
//=======================================================================
Handle(AIS_Selection) AIS_Selection::CurrentSelection() {
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
return S;
}
//=======================================================================
//function : Select
//purpose :
//=======================================================================
AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObject)
{
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if(S.IsNull()) return AIS_SS_NotDone;
Handle(AIS_InteractiveObject) anAISObj;
Handle(SelectMgr_EntityOwner) owner = Handle(SelectMgr_EntityOwner)::DownCast( anObject );
if ( owner.IsNull() )
anAISObj = Handle(AIS_InteractiveObject)::DownCast( anObject );
if ( S->myResultMap.IsBound( anObject ) ){
AIS_NListTransient::Iterator aListIter = S->myResultMap.Find( anObject );
if ( myResultMap.IsBound( anObject ) ){
AIS_NListTransient::Iterator aListIter = myResultMap.Find( anObject );
//skt-----------------------------------------------------------------
if( S->myIterator == aListIter ) {
if( S->myIterator.More() )
S->myIterator.Next();
if( myIterator == aListIter ) {
if( myIterator.More() )
myIterator.Next();
else
S->myIterator = AIS_NListTransient::Iterator();
myIterator = AIS_NListTransient::Iterator();
}
//--------------------------------------------------------------------
// In the mode of advanced mesh selection only one owner is created
@@ -170,16 +73,16 @@ AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObjec
// the same as previous selected (IsForcedHilight call)
if( !anAISObj.IsNull() || ( !owner.IsNull() && !owner->IsForcedHilight() ) )
{
S->myresult.Remove( aListIter );
S->myResultMap.UnBind( anObject );
myresult.Remove( aListIter );
myResultMap.UnBind( anObject );
// update list iterator for next object in <myresult> list if any
if ( aListIter.More() ){
const Handle(Standard_Transient)& aNextObject = aListIter.Value();
if ( S->myResultMap.IsBound( aNextObject ) )
S->myResultMap( aNextObject ) = aListIter;
if ( myResultMap.IsBound( aNextObject ) )
myResultMap( aNextObject ) = aListIter;
else
S->myResultMap.Bind( aNextObject, aListIter );
myResultMap.Bind( aNextObject, aListIter );
}
return AIS_SS_Removed;
}
@@ -188,8 +91,8 @@ AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObjec
}
AIS_NListTransient::Iterator aListIter;
S->myresult.Append( anObject, aListIter );
S->myResultMap.Bind( anObject, aListIter );
myresult.Append( anObject, aListIter );
myResultMap.Bind( anObject, aListIter );
return AIS_SS_Added;
}
@@ -199,16 +102,12 @@ AIS_SelectStatus AIS_Selection::Select(const Handle(Standard_Transient)& anObjec
//=======================================================================
AIS_SelectStatus AIS_Selection::AddSelect(const Handle(Standard_Transient)& anObject)
{
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if(S.IsNull()) return AIS_SS_NotDone;
if ( S->myResultMap.IsBound( anObject ) )
if ( myResultMap.IsBound( anObject ) )
return AIS_SS_NotDone;
AIS_NListTransient::Iterator aListIter;
S->myresult.Append( anObject, aListIter );
S->myResultMap.Bind( anObject, aListIter );
myresult.Append( anObject, aListIter );
myResultMap.Bind( anObject, aListIter );
return AIS_SS_Added;
}
@@ -218,14 +117,10 @@ AIS_SelectStatus AIS_Selection::AddSelect(const Handle(Standard_Transient)& anOb
//purpose :
//=======================================================================
void AIS_Selection::ClearAndSelect(const Handle(Standard_Transient)& anObject) {
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if(S.IsNull()) return;
void AIS_Selection::ClearAndSelect(const Handle(Standard_Transient)& anObject)
{
Select();
Select(anObject);
}
@@ -233,14 +128,9 @@ void AIS_Selection::ClearAndSelect(const Handle(Standard_Transient)& anObject) {
//function : Extent
//purpose :
//=======================================================================
Standard_Integer AIS_Selection::Extent() {
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if (S.IsNull())
return 0;
return S->myresult.Extent();
Standard_Integer AIS_Selection::Extent() const
{
return myresult.Extent();
}
//=======================================================================
@@ -249,63 +139,16 @@ Standard_Integer AIS_Selection::Extent() {
//=======================================================================
Handle(Standard_Transient) AIS_Selection::Single()
{
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if (S.IsNull())
return Handle(Standard_Transient)();
S->Init();
return S->Value();
Init();
return Value();
}
//=======================================================================
//function : IsSelected
//purpose :
//=======================================================================
Standard_Boolean AIS_Selection::IsSelected(const Handle(Standard_Transient)& anObject)
Standard_Boolean AIS_Selection::IsSelected(const Handle(Standard_Transient)& anObject) const
{
Handle(AIS_Selection) S;
AIS_Sel_CurrentSelection (S);
if(S.IsNull()) return Standard_False;
return S->myResultMap.IsBound( anObject );
return myResultMap.IsBound( anObject );
}
//=======================================================================
//function : Index
//purpose :
//=======================================================================
Standard_Integer AIS_Selection::Index(const Standard_CString aName)
{
Handle (Standard_Transient) curobj;
for(Standard_Integer I =1; I<= AIS_Sel_GetSelections().Length();I++){
curobj = AIS_Sel_GetSelections().Value(I);
if(Handle(AIS_Selection)::DownCast (curobj)->myName.IsEqual(aName))
return I;
}
return 0;
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
void AIS_Selection::Remove(const Standard_CString aName)
{
Standard_Integer I = AIS_Selection::Index(aName);
if(I!=0) {
Handle(AIS_Selection) selection = Handle(AIS_Selection)::DownCast( AIS_Sel_GetSelections().Value(I) );
Standard_Integer stored = selection->NbStored();
if ( stored )
selection->Select();
AIS_Sel_GetSelections().Remove(I);
}
}
// clean the static current selection handle
void AIS_Selection::ClearCurrentSelection()
{
theCurrentSelection.Nullify();
}