1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0026209: Visualization - provide a method to fit view to the specific bounding box

Methods V3d_View::FitAll and NIS_View::FitAll3d now take arbitrary bounding box as a parameter;
Option -selected added to vfit command to fit only selected entities in Draw;
F key press now fits selected objects if any by default.
This commit is contained in:
vpa 2015-05-14 19:32:05 +03:00 committed by bugmaster
parent ab1c121bb9
commit b586500b1e
15 changed files with 301 additions and 43 deletions

View File

@ -1942,6 +1942,16 @@ is
ClearActiveSensitive(me:mutable;aView:View from V3d) is static; ClearActiveSensitive(me:mutable;aView:View from V3d) is static;
FitSelected (me : mutable;
theView : View from V3d;
theMargin : Real from Standard = 0.01;
theToUpdate : Boolean from Standard = Standard_True)
is static;
---Level: Public
---Purpose: Fits the view correspondingly to the bounds of selected objects.
-- Infinite objects are ignored if infinite state of AIS_InteractiveObject
-- is set to true.
DisplayActiveSensitive(me:mutable; DisplayActiveSensitive(me:mutable;

View File

@ -68,6 +68,9 @@ namespace
return TCollection_AsciiString ("AIS_CurContext_") return TCollection_AsciiString ("AIS_CurContext_")
+ TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR)); + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
} }
typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
} }
//======================================================================= //=======================================================================
@ -2824,3 +2827,65 @@ void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& th
else else
return; return;
} }
//=======================================================================
//function : FitSelected
//purpose : Fits the view corresponding to the bounds of selected objects
//=======================================================================
void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
const Standard_Real theMargin,
const Standard_Boolean theToUpdate)
{
Standard_CString aSelName = HasOpenedContext() ?
myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
: myCurrentName.ToCString();
Bnd_Box aBndSelected;
const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
AIS_MapOfObjectOwners anObjectOwnerMap;
for (aSelection->Init(); aSelection->More(); aSelection->Next())
{
const Handle(AIS_InteractiveObject)& anObj =
Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
if (!anObj.IsNull())
{
if (anObj->IsInfinite())
continue;
Bnd_Box aTmpBnd;
anObj->BoundingBox (aTmpBnd);
aBndSelected.Add (aTmpBnd);
}
else
{
const Handle(SelectMgr_EntityOwner)& anOwner =
Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value());
if (anOwner.IsNull())
continue;
Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
{
anOwnerMap = new SelectMgr_IndexedMapOfOwner();
anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
}
anOwnerMap->Add (anOwner);
}
}
for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
{
const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
aBndSelected.Add (aTmpBox);
}
anObjectOwnerMap.Clear();
if (aBndSelected.IsVoid())
return;
theView->FitAll (aBndSelected, theMargin, theToUpdate);
}

View File

@ -1079,7 +1079,7 @@ Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const
//function : EntityOwners //function : EntityOwners
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners, void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
const Handle(AIS_InteractiveObject)& theIObj, const Handle(AIS_InteractiveObject)& theIObj,
const Standard_Integer theMode) const const Standard_Integer theMode) const
{ {
@ -1092,6 +1092,9 @@ void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners
else else
aModes.Append( theMode ); aModes.Append( theMode );
if (theOwners.IsNull())
theOwners = new SelectMgr_IndexedMapOfOwner();
TColStd_ListIteratorOfListOfInteger anItr( aModes ); TColStd_ListIteratorOfListOfInteger anItr( aModes );
for (; anItr.More(); anItr.Next() ) for (; anItr.More(); anItr.Next() )
{ {
@ -1110,7 +1113,7 @@ void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners
Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner) aOwner =
Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId()); Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
if ( !aOwner.IsNull() ) if ( !aOwner.IsNull() )
theOwners.Add( aOwner ); theOwners->Add( aOwner );
} }
} }
} }

View File

@ -74,6 +74,7 @@ mySM(aCtx->SelectionManager()),
myMainVS(aCtx->MainSelector()), myMainVS(aCtx->MainSelector()),
myFilters(new SelectMgr_OrFilter()), myFilters(new SelectMgr_OrFilter()),
myAutoHilight(Standard_True), myAutoHilight(Standard_True),
myMapOfOwner (new SelectMgr_IndexedMapOfOwner()),
mylastindex(0), mylastindex(0),
mylastgood(0), mylastgood(0),
myCurDetected(0), myCurDetected(0),
@ -606,7 +607,7 @@ void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
{ {
ClearDetected(); ClearDetected();
Clear(); Clear();
myMapOfOwner.Clear(); myMapOfOwner->Clear();
mylastindex=0; mylastindex=0;
// clear the selector... // clear the selector...
@ -1050,16 +1051,16 @@ HasFilters(const TopAbs_ShapeEnum aType) const
void AIS_LocalContext::ClearDetected() void AIS_LocalContext::ClearDetected()
{ {
for(Standard_Integer I=1;I<=myMapOfOwner.Extent();I++) for(Standard_Integer I=1;I<=myMapOfOwner->Extent();I++)
{ {
if(!myMapOfOwner(I).IsNull()) if(!myMapOfOwner->FindKey (I).IsNull())
{ {
if(myMapOfOwner(I)->IsHilighted(myMainPM)) if(myMapOfOwner->FindKey (I)->IsHilighted(myMainPM))
myMapOfOwner(I)->Unhilight(myMainPM); myMapOfOwner->FindKey (I)->Unhilight(myMainPM);
else else
{ {
const Handle(SelectMgr_SelectableObject)& SO = const Handle(SelectMgr_SelectableObject)& SO =
myMapOfOwner.FindKey(I)->Selectable(); myMapOfOwner->FindKey (I)->Selectable();
if(myActiveObjects.IsBound(SO)) if(myActiveObjects.IsBound(SO))
{ {
const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO); const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
@ -1068,7 +1069,7 @@ void AIS_LocalContext::ClearDetected()
Att->DisplayMode()==-1 && Att->DisplayMode()==-1 &&
Att->SelectionModes().IsEmpty()) Att->SelectionModes().IsEmpty())
{ {
myMapOfOwner(I)->Clear(myMainPM); myMapOfOwner->FindKey (I)->Clear(myMainPM);
} }
} }
} }

View File

@ -61,4 +61,4 @@ inline Standard_Boolean AIS_LocalContext::HasNextDetected() const
{return myCurDetected<myDetectedSeq.Length();} {return myCurDetected<myDetectedSeq.Length();}
inline Standard_Boolean AIS_LocalContext::IsValidIndex(const Standard_Integer indx) const inline Standard_Boolean AIS_LocalContext::IsValidIndex(const Standard_Integer indx) const
{ return (indx>0 && indx<=myMapOfOwner.Extent());} { return (indx>0 && indx<=myMapOfOwner->Extent());}

View File

@ -95,10 +95,10 @@ AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix,
// result of courses.. // result of courses..
if (aDetectedNb == 0 || myDetectedSeq.IsEmpty()) if (aDetectedNb == 0 || myDetectedSeq.IsEmpty())
{ {
if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent()) if (mylastindex != 0 && mylastindex <= myMapOfOwner->Extent())
{ {
myMainPM->ClearImmediateDraw(); myMainPM->ClearImmediateDraw();
Unhilight (myMapOfOwner (mylastindex), theView); Unhilight (myMapOfOwner->FindKey (mylastindex), theView);
if (theToRedrawImmediate) if (theToRedrawImmediate)
{ {
theView->RedrawImmediate(); theView->RedrawImmediate();
@ -148,7 +148,7 @@ AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer
return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed; return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed;
} }
const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex); const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner->FindKey (aDetIndex);
ClearSelected (Standard_False); ClearSelected (Standard_False);
@ -314,7 +314,7 @@ AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateV
{ {
AIS_Selection::SetCurrentSelection (mySelName.ToCString()); AIS_Selection::SetCurrentSelection (mySelName.ToCString());
Standard_Integer aSelNum = AIS_Selection::Extent(); Standard_Integer aSelNum = AIS_Selection::Extent();
const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex); const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner->FindKey (aDetIndex);
Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True;
AIS_Selection::Select (anOwner); AIS_Selection::Select (anOwner);
anOwner->SetSelected (toSelect); anOwner->SetSelected (toSelect);
@ -940,9 +940,9 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec
// 4. AIS_LocalContext - myMapOfOwner : remove entity owners from myMapOfOwner // 4. AIS_LocalContext - myMapOfOwner : remove entity owners from myMapOfOwner
SelectMgr_IndexedMapOfOwner anOwnersToKeep; SelectMgr_IndexedMapOfOwner anOwnersToKeep;
for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++) for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner->Extent(); anIdx++)
{ {
Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner (anIdx); Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner->FindKey (anIdx);
if (anOwner.IsNull()) if (anOwner.IsNull())
{ {
continue; continue;
@ -960,9 +960,9 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec
} }
} }
} }
myMapOfOwner.Clear(); myMapOfOwner->Clear();
myMapOfOwner.Assign (anOwnersToKeep); myMapOfOwner->Assign (anOwnersToKeep);
mylastindex = myMapOfOwner.FindIndex (aLastPicked); mylastindex = myMapOfOwner->FindIndex (aLastPicked);
if (!IsValidIndex (mylastindex)) if (!IsValidIndex (mylastindex))
{ {
myMainPM->ClearImmediateDraw(); myMainPM->ClearImmediateDraw();
@ -1159,9 +1159,9 @@ void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& theP
// //
//======================================================================================================= //=======================================================================================================
const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner) const Standard_Integer aNewIndex = myMapOfOwner->Contains (thePickOwner)
? myMapOfOwner.FindIndex (thePickOwner) ? myMapOfOwner->FindIndex (thePickOwner)
: myMapOfOwner.Add (thePickOwner); : myMapOfOwner->Add (thePickOwner);
// For the advanced mesh selection mode the owner indices comparison // For the advanced mesh selection mode the owner indices comparison
// is not effective because in that case only one owner manage the // is not effective because in that case only one owner manage the
@ -1173,9 +1173,9 @@ void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& theP
{ {
myMainPM->ClearImmediateDraw(); myMainPM->ClearImmediateDraw();
if (mylastindex != 0 if (mylastindex != 0
&& mylastindex <= myMapOfOwner.Extent()) && mylastindex <= myMapOfOwner->Extent())
{ {
const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex); const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner->FindKey (mylastindex);
Unhilight (aLastOwner, theView); Unhilight (aLastOwner, theView);
} }
@ -1222,7 +1222,7 @@ AIS_LocalContext::DetectedShape() const
static TopoDS_Shape bidsh; static TopoDS_Shape bidsh;
if(mylastindex != 0) if(mylastindex != 0)
{ {
Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex)); Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner->FindKey (mylastindex));
if(BROwnr.IsNull()) return bidsh; if(BROwnr.IsNull()) return bidsh;
return BROwnr->Shape(); return BROwnr->Shape();
} }
@ -1239,7 +1239,7 @@ AIS_LocalContext::DetectedInteractive() const
{ {
Handle(AIS_InteractiveObject) Iobj; Handle(AIS_InteractiveObject) Iobj;
if(IsValidIndex(mylastindex)){ if(IsValidIndex(mylastindex)){
Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable(); Handle(SelectMgr_SelectableObject) SO = myMapOfOwner->FindKey(mylastindex)->Selectable();
Iobj = *((Handle(AIS_InteractiveObject)*) &SO); Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
} }
return Iobj; return Iobj;
@ -1252,7 +1252,7 @@ Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
{ {
Handle(SelectMgr_EntityOwner) bid; Handle(SelectMgr_EntityOwner) bid;
if(!IsValidIndex(mylastindex)) return bid; if(!IsValidIndex(mylastindex)) return bid;
return myMapOfOwner.FindKey(mylastindex); return myMapOfOwner->FindKey(mylastindex);
} }
@ -1263,7 +1263,7 @@ Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
{ {
const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex); const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner->FindKey(PickedIndex);
Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable(); Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
if (myActiveObjects.IsBound (aSel)) { // debug of jmi if (myActiveObjects.IsBound (aSel)) { // debug of jmi
const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel); const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
@ -1300,7 +1300,7 @@ void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
{ {
if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull()) if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner->FindKey(Index)).IsNull())
return Standard_False; return Standard_False;
return return
ComesFromDecomposition(Index); ComesFromDecomposition(Index);
@ -1383,12 +1383,12 @@ Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)
} }
myMainPM->BeginImmediateDraw(); myMainPM->BeginImmediateDraw();
const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex); const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner->FindKey (mylastindex);
const Standard_Integer aHilightMode = anOwner->HasSelectable() const Standard_Integer aHilightMode = anOwner->HasSelectable()
? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable())) ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
: 0; : 0;
myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode); myMapOfOwner->FindKey (mylastindex)->Unhilight (myMainPM, aHilightMode);
myMainPM->EndImmediateDraw (theView); myMainPM->EndImmediateDraw (theView);
mylastindex = 0; mylastindex = 0;
return Standard_True; return Standard_True;

View File

@ -1,6 +1,7 @@
SelectMgr_CompareResults.hxx SelectMgr_CompareResults.hxx
SelectMgr_FrustumBuilder.hxx SelectMgr_FrustumBuilder.hxx
SelectMgr_FrustumBuilder.cxx SelectMgr_FrustumBuilder.cxx
SelectMgr_IndexedMapOfOwner.hxx
SelectMgr_SelectableObjectSet.hxx SelectMgr_SelectableObjectSet.hxx
SelectMgr_SelectableObjectSet.cxx SelectMgr_SelectableObjectSet.cxx
SelectMgr_BaseFrustum.hxx SelectMgr_BaseFrustum.hxx

View File

@ -236,9 +236,6 @@ is
class SequenceOfOwner instantiates Sequence from TCollection class SequenceOfOwner instantiates Sequence from TCollection
(EntityOwner from SelectMgr); (EntityOwner from SelectMgr);
class IndexedMapOfOwner instantiates IndexedMap from TCollection
(EntityOwner from SelectMgr,MapTransientHasher from TColStd);
class SequenceOfSelector instantiates Sequence from TCollection class SequenceOfSelector instantiates Sequence from TCollection
(ViewerSelector from SelectMgr); (ViewerSelector from SelectMgr);
@ -256,7 +253,7 @@ is
pointer SOPtr to SelectableObject from SelectMgr; pointer SOPtr to SelectableObject from SelectMgr;
imported CompareResults; imported CompareResults;
imported transient class IndexedMapOfOwner;
imported SelectableObjectSet; imported SelectableObjectSet;
imported FrustumBuilder; imported FrustumBuilder;
imported BaseFrustum; imported BaseFrustum;

View File

@ -0,0 +1,28 @@
// Created on: 2015-05-14
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _SelectMgr_IndexedMapOfOwner_HeaderFile
#define _SelectMgr_IndexedMapOfOwner_HeaderFile
#include <NCollection_Handle.hxx>
#include <NCollection_IndexedMap.hxx>
class SelectMgr_EntityOwner;
class Handle(SelectMgr_EntityOwner);
typedef NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> SelectMgr_IndexedMapOfOwner;
typedef NCollection_Handle<NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> > Handle(SelectMgr_IndexedMapOfOwner);
#endif // _SelectMgr_IndexedMapOfOwner_HeaderFile

View File

@ -30,6 +30,7 @@ deferred class SelectableObject from SelectMgr inherits PresentableObject from
uses uses
Box from Bnd, Box from Bnd,
IndexedMapOfOwner from SelectMgr,
SelectionManager from SelectMgr, SelectionManager from SelectMgr,
Selection from SelectMgr, Selection from SelectMgr,
SequenceOfSelection from SelectMgr, SequenceOfSelection from SelectMgr,
@ -239,6 +240,12 @@ is
---C++: return const& ---C++: return const&
---Purpose: Returns common entity owner if the object is an assembly ---Purpose: Returns common entity owner if the object is an assembly
BndBoxOfSelected (me : mutable;
theOwners : out IndexedMapOfOwner from SelectMgr)
returns Box from Bnd;
---Purpose: Returns a bounding box of sensitive entities with the owners given
-- if they are a part of activated selection
fields fields
myselections : SequenceOfSelection is protected; myselections : SequenceOfSelection is protected;

View File

@ -580,3 +580,49 @@ const Handle(SelectMgr_EntityOwner)& SelectMgr_SelectableObject::GetAssemblyOwne
{ {
return myAssemblyOwner; return myAssemblyOwner;
} }
//=======================================================================
//function : BndBoxOfSelected
//purpose : Returns a bounding box of sensitive entities with the owners given
// if they are a part of activated selection
//=======================================================================
Bnd_Box SelectMgr_SelectableObject::BndBoxOfSelected (Handle(SelectMgr_IndexedMapOfOwner)& theOwners)
{
Bnd_Box aBnd;
if (theOwners->IsEmpty())
return aBnd;
for (Init(); More(); Next())
{
const Handle(SelectMgr_Selection)& aSel = CurrentSelection();
if (aSel->GetSelectionState() != SelectMgr_SOS_Activated)
continue;
for (aSel->Init(); aSel->More(); aSel->Next())
{
const Handle(SelectMgr_EntityOwner) anOwner =
Handle(SelectMgr_EntityOwner)::DownCast (aSel->Sensitive()->BaseSensitive()->OwnerId());
if (theOwners->Contains (anOwner))
{
Select3D_BndBox3d aBox = aSel->Sensitive()->BaseSensitive()->BoundingBox();
Bnd_Box aTmpBnd;
aTmpBnd.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(),
aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z());
aBnd.Add (aTmpBnd);
Standard_Integer anOwnerIdx = theOwners->FindIndex (anOwner);
if (theOwners->Size() != anOwnerIdx)
{
theOwners->Swap (anOwnerIdx, theOwners->Size());
}
theOwners->RemoveLast();
if (theOwners->IsEmpty())
return aBnd;
}
}
}
return aBnd;
}

View File

@ -796,6 +796,19 @@ is
-- @param theMargin [in] the margin coefficient for view borders. -- @param theMargin [in] the margin coefficient for view borders.
-- @param theToUpdate [in] flag to perform view update. -- @param theToUpdate [in] flag to perform view update.
FitAll (me : mutable;
theBox : Box from Bnd;
theMargin : Coefficient = 0.01;
theToUpdate : Boolean from Standard = Standard_True);
---Level: Public
---Purpose: Adjust view parameters to fit the displayed scene, respecting height / width ratio
-- according to the custom bounding box given.
-- Throws program error exception if margin coefficient is < 0 or >= 1.
-- Updates the view.
-- @param theBox [in] the custom bounding box to fit.
-- @param theMargin [in] the margin coefficient for view borders.
-- @param theToUpdate [in] flag to perform view update.
DepthFitAll( me : mutable ; Aspect : Coefficient = 0.01; DepthFitAll( me : mutable ; Aspect : Coefficient = 0.01;
Margin : Coefficient = 0.01 ); Margin : Coefficient = 0.01 );
---Level: Public ---Level: Public

View File

@ -1451,16 +1451,25 @@ void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, co
//function : FitAll //function : FitAll
//purpose : //purpose :
//============================================================================= //=============================================================================
void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean theToUpdate) void V3d_View::FitAll (const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate)
{ {
Standard_ASSERT_RAISE (theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient"); FitAll (MyView->MinMaxValues(), theMargin, theToUpdate);
}
//=============================================================================
//function : FitAll
//purpose :
//=============================================================================
void V3d_View::FitAll (const Bnd_Box& theBox, const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate)
{
Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
if (MyView->NumberOfDisplayedStructures() == 0) if (MyView->NumberOfDisplayedStructures() == 0)
{ {
return; return;
} }
if (!FitMinMax (myCamera, MyView->MinMaxValues(), theMargin, 10.0 * Precision::Confusion())) if (!FitMinMax (myCamera, theBox, theMargin, 10.0 * Precision::Confusion()))
{ {
return; return;
} }

View File

@ -1344,10 +1344,17 @@ void VT_ProcessKeyPress (const char* buf_ret)
aView->Reset(); aView->Reset();
} }
else if (!strcasecmp (buf_ret, "F")) else if (!strcasecmp (buf_ret, "F"))
{
if (ViewerTest::GetAISContext()->NbSelected() > 0)
{
ViewerTest::GetAISContext()->FitSelected (aView);
}
else
{ {
// FitAll // FitAll
aView->FitAll(); aView->FitAll();
} }
}
else if (!strcasecmp (buf_ret, "H")) else if (!strcasecmp (buf_ret, "H"))
{ {
// HLR // HLR
@ -2458,7 +2465,6 @@ static void OSWindowSetup()
} }
//============================================================================== //==============================================================================
//function : VFit //function : VFit
@ -2466,11 +2472,49 @@ static void OSWindowSetup()
//Draw arg : No args //Draw arg : No args
//============================================================================== //==============================================================================
static int VFit(Draw_Interpretor& , Standard_Integer , const char** ) static int VFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgc, const char** theArgv)
{ {
if (theArgc > 2)
{
std::cout << "Wrong number of arguments! Use: vfit [-selected]" << std::endl;
}
const Handle(V3d_View) aView = ViewerTest::CurrentView(); const Handle(V3d_View) aView = ViewerTest::CurrentView();
<<<<<<< .mine
Handle(NIS_View) V = Handle(NIS_View)::DownCast (aView);
if (theArgc == 2)
{
TCollection_AsciiString anArg (theArgv[1]);
anArg.LowerCase();
if (anArg == "-selected")
{
ViewerTest::GetAISContext()->FitSelected (V.IsNull() ? aView : V);
return 0;
}
}
if (V.IsNull() == Standard_False) {
V->FitAll3d();
} else if (aView.IsNull() == Standard_False) {
=======
if (!aView.IsNull()) if (!aView.IsNull())
{ {
>>>>>>> .theirs
aView->FitAll(); aView->FitAll();
} }
return 0; return 0;
@ -8413,7 +8457,8 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"vpick : vpick X Y Z [shape subshape] ( all variables as string )", "vpick : vpick X Y Z [shape subshape] ( all variables as string )",
VPick,group); VPick,group);
theCommands.Add("vfit" , theCommands.Add("vfit" ,
"vfit or <F> : vfit", "vfit or <F> [-selected]"
"\n\t\t: [-selected] fits the scene according to bounding box of currently selected objects",
__FILE__,VFit,group); __FILE__,VFit,group);
theCommands.Add ("vfitarea", theCommands.Add ("vfitarea",
"vfitarea x1 y1 x2 y2" "vfitarea x1 y1 x2 y2"

33
tests/bugs/vis/bug26209 Normal file
View File

@ -0,0 +1,33 @@
puts "============"
puts "CR26209"
puts "============"
puts ""
##########################################################################################
puts "Visualization - provide a method to fit view to the specific bounding box"
##########################################################################################
pload VISUALIZATION MODELING
box b 1 1 1
vinit View1
vdisplay b
vfit
vselmode b 2 1
vselmode b 1 1
vselect 330 334
vfit -selected
checkcolor 330 334 0 0 0
checkcolor 330 131 0.8 0.8 0.8
vselect 0 0
vfit
vselect 29 104
vselect 204 2 1
vfit -selected
checkcolor 29 104 0 0 0
checkcolor 2 317 0.8 0.8 0.8
vdump ${imagedir}/${casename}.png