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.
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;
return TCollection_AsciiString ("AIS_CurContext_")
+ 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;
}
//=======================================================================
else
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);
+}
//function : EntityOwners
//purpose :
//=======================================================================
-void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
+void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
const Handle(AIS_InteractiveObject)& theIObj,
const Standard_Integer theMode) const
{
else
aModes.Append( theMode );
+ if (theOwners.IsNull())
+ theOwners = new SelectMgr_IndexedMapOfOwner();
+
TColStd_ListIteratorOfListOfInteger anItr( aModes );
for (; anItr.More(); anItr.Next() )
{
Handle(SelectMgr_EntityOwner) aOwner =
Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
if ( !aOwner.IsNull() )
- theOwners.Add( aOwner );
+ theOwners->Add( aOwner );
}
}
}
myMainVS(aCtx->MainSelector()),
myFilters(new SelectMgr_OrFilter()),
myAutoHilight(Standard_True),
+myMapOfOwner (new SelectMgr_IndexedMapOfOwner()),
mylastindex(0),
mylastgood(0),
myCurDetected(0),
{
ClearDetected();
Clear();
- myMapOfOwner.Clear();
+ myMapOfOwner->Clear();
mylastindex=0;
// clear the selector...
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))
- myMapOfOwner(I)->Unhilight(myMainPM);
+ if(myMapOfOwner->FindKey (I)->IsHilighted(myMainPM))
+ myMapOfOwner->FindKey (I)->Unhilight(myMainPM);
else
{
const Handle(SelectMgr_SelectableObject)& SO =
- myMapOfOwner.FindKey(I)->Selectable();
+ myMapOfOwner->FindKey (I)->Selectable();
if(myActiveObjects.IsBound(SO))
{
const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
Att->DisplayMode()==-1 &&
Att->SelectionModes().IsEmpty())
{
- myMapOfOwner(I)->Clear(myMainPM);
+ myMapOfOwner->FindKey (I)->Clear(myMainPM);
}
}
}
{return myCurDetected<myDetectedSeq.Length();}
inline Standard_Boolean AIS_LocalContext::IsValidIndex(const Standard_Integer indx) const
-{ return (indx>0 && indx<=myMapOfOwner.Extent());}
+{ return (indx>0 && indx<=myMapOfOwner->Extent());}
// result of courses..
if (aDetectedNb == 0 || myDetectedSeq.IsEmpty())
{
- if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent())
+ if (mylastindex != 0 && mylastindex <= myMapOfOwner->Extent())
{
myMainPM->ClearImmediateDraw();
- Unhilight (myMapOfOwner (mylastindex), theView);
+ Unhilight (myMapOfOwner->FindKey (mylastindex), theView);
if (theToRedrawImmediate)
{
theView->RedrawImmediate();
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);
{
AIS_Selection::SetCurrentSelection (mySelName.ToCString());
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;
AIS_Selection::Select (anOwner);
anOwner->SetSelected (toSelect);
// 4. AIS_LocalContext - myMapOfOwner : remove entity owners from myMapOfOwner
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())
{
continue;
}
}
}
- myMapOfOwner.Clear();
- myMapOfOwner.Assign (anOwnersToKeep);
- mylastindex = myMapOfOwner.FindIndex (aLastPicked);
+ myMapOfOwner->Clear();
+ myMapOfOwner->Assign (anOwnersToKeep);
+ mylastindex = myMapOfOwner->FindIndex (aLastPicked);
if (!IsValidIndex (mylastindex))
{
myMainPM->ClearImmediateDraw();
//
//=======================================================================================================
- const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner)
- ? myMapOfOwner.FindIndex (thePickOwner)
- : myMapOfOwner.Add (thePickOwner);
+ const Standard_Integer aNewIndex = myMapOfOwner->Contains (thePickOwner)
+ ? myMapOfOwner->FindIndex (thePickOwner)
+ : myMapOfOwner->Add (thePickOwner);
// For the advanced mesh selection mode the owner indices comparison
// is not effective because in that case only one owner manage the
{
myMainPM->ClearImmediateDraw();
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);
}
static TopoDS_Shape bidsh;
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;
return BROwnr->Shape();
}
{
Handle(AIS_InteractiveObject) Iobj;
if(IsValidIndex(mylastindex)){
- Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
+ Handle(SelectMgr_SelectableObject) SO = myMapOfOwner->FindKey(mylastindex)->Selectable();
Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
}
return Iobj;
{
Handle(SelectMgr_EntityOwner) bid;
if(!IsValidIndex(mylastindex)) return bid;
- return myMapOfOwner.FindKey(mylastindex);
+ return myMapOfOwner->FindKey(mylastindex);
}
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();
if (myActiveObjects.IsBound (aSel)) { // debug of jmi
const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
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
ComesFromDecomposition(Index);
}
myMainPM->BeginImmediateDraw();
- const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex);
+ const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner->FindKey (mylastindex);
const Standard_Integer aHilightMode = anOwner->HasSelectable()
? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()))
: 0;
- myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode);
+ myMapOfOwner->FindKey (mylastindex)->Unhilight (myMainPM, aHilightMode);
myMainPM->EndImmediateDraw (theView);
mylastindex = 0;
return Standard_True;
SelectMgr_CompareResults.hxx
SelectMgr_FrustumBuilder.hxx
SelectMgr_FrustumBuilder.cxx
+SelectMgr_IndexedMapOfOwner.hxx
SelectMgr_SelectableObjectSet.hxx
SelectMgr_SelectableObjectSet.cxx
SelectMgr_BaseFrustum.hxx
class SequenceOfOwner instantiates Sequence from TCollection
(EntityOwner from SelectMgr);
- class IndexedMapOfOwner instantiates IndexedMap from TCollection
- (EntityOwner from SelectMgr,MapTransientHasher from TColStd);
-
class SequenceOfSelector instantiates Sequence from TCollection
(ViewerSelector from SelectMgr);
pointer SOPtr to SelectableObject from SelectMgr;
imported CompareResults;
-
+ imported transient class IndexedMapOfOwner;
imported SelectableObjectSet;
imported FrustumBuilder;
imported BaseFrustum;
--- /dev/null
+// 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
uses
Box from Bnd,
+ IndexedMapOfOwner from SelectMgr,
SelectionManager from SelectMgr,
Selection from SelectMgr,
SequenceOfSelection from SelectMgr,
---C++: return const&
---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
myselections : SequenceOfSelection is protected;
{
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;
+}
-- @param theMargin [in] the margin coefficient for view borders.
-- @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;
Margin : Coefficient = 0.01 );
---Level: Public
//function : FitAll
//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)
{
return;
}
- if (!FitMinMax (myCamera, MyView->MinMaxValues(), theMargin, 10.0 * Precision::Confusion()))
+ if (!FitMinMax (myCamera, theBox, theMargin, 10.0 * Precision::Confusion()))
{
return;
}
}
else if (!strcasecmp (buf_ret, "F"))
{
- // FitAll
- aView->FitAll();
+ if (ViewerTest::GetAISContext()->NbSelected() > 0)
+ {
+ ViewerTest::GetAISContext()->FitSelected (aView);
+ }
+ else
+ {
+ // FitAll
+ aView->FitAll();
+ }
}
else if (!strcasecmp (buf_ret, "H"))
{
}
-
//==============================================================================
//function : VFit
//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();
- if (!aView.IsNull())
+
+ if (theArgc == 2)
{
+ TCollection_AsciiString anArg (theArgv[1]);
+ anArg.LowerCase();
+ if (anArg == "-selected")
+ {
+ ViewerTest::GetAISContext()->FitSelected (aView);
+ return 0;
+ }
+ }
+ if (aView.IsNull() == Standard_False) {
aView->FitAll();
}
return 0;
"vpick : vpick X Y Z [shape subshape] ( all variables as string )",
VPick,group);
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);
theCommands.Add ("vfitarea",
"vfitarea x1 y1 x2 y2"
--- /dev/null
+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