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

0024623: Visualization - improve selection mechanism

Redesign of selection mechanism:
- implemented 3-level BVH tree for selection;
- selection now calculates in 3D space;
- intersection tests were moved to SelectMgr_BaseFrustum descendants;
- removed .cdl files in Select3D and .cdl related to selection in MeshVS;
- SelectMgr_ViewerSelectors are now shared between local and global contexts;
- transformations of sensitive entities are now stored in SelectMgr_SelectableObject only. Sensitive entities are independent from transformations, it is applied to SelectMgr_SelectingVolumeManager instance only;
- connected and multiple connected interactive objects are now represented by their child objects only for SelectMgr_SelectionManager;
- if interactive object has child objects, they will be stored as separate objects in SelectMgr_SelectionManager now.
- test cases bugs/vis/bug24623_1, bug24623_2, bug24623_3, bug24623_4 to test performance and memory issues.
This commit is contained in:
vpa
2015-04-06 12:31:00 +03:00
committed by bugmaster
parent 7a91ad6e81
commit f751596e46
269 changed files with 12626 additions and 11723 deletions

3
src/StdSelect/FILES Normal file
View File

@@ -0,0 +1,3 @@
StdSelect_ViewerSelector3d.hxx
StdSelect_ViewerSelector3d.cxx
StdSelect_ViewerSelector3d.lxx

View File

@@ -51,7 +51,8 @@ uses
TColStd,
gp,
Select3D,
Graphic3d,Visual3d,
Graphic3d,
Visual3d,
Quantity,
Prs3d,
V3d,
@@ -88,10 +89,8 @@ is
---Purpose: Selection sensitivity mode. SM_WINDOW mode uses the
-- specified pixel tolerance to compute the sensitivity value,
-- SM_VIEW mode allows to define the sensitivity manually.
class ViewerSelector3d;
class BRepSelectionTool;
class BRepOwner;
@@ -103,6 +102,8 @@ is
class FaceFilter;
class ShapeTypeFilter;
imported transient class ViewerSelector3d;
---Category: Private Classes
private class Prs;
@@ -111,13 +112,10 @@ is
private class IndexedDataMapOfOwnerPrs instantiates IndexedDataMap from TCollection
(EntityOwner from SelectBasics,Prs from StdSelect,MapTransientHasher from TColStd);
GetProjector (aView: View from V3d) returns Projector from Select3D;
---Purpose: Returns the 3D projector for the view aView.
SetDrawerForBRepOwner(aSelection: Selection from SelectMgr;
aDrawer : Drawer from Prs3d);
---Purpose: puts The same drawer in every BRepOwner Of SensitivePrimitive
-- Used Only for hilight Of BRepOwner...
SetDrawerForBRepOwner(aSelection: Selection from SelectMgr;
aDrawer : Drawer from Prs3d);
---Purpose: puts The same drawer in every BRepOwner Of SensitivePrimitive
-- Used Only for hilight Of BRepOwner...
end StdSelect;

View File

@@ -31,29 +31,6 @@
#include <gp_Ax3.hxx>
#include <StdSelect_BRepOwner.hxx>
Handle(Select3D_Projector) StdSelect::GetProjector(const Handle(V3d_View)& aViou)
{
Standard_Real Focale=0.,Xat,Yat,Zat,XUp,YUp,ZUp,DX,DY,DZ;
Standard_Boolean Pers=Standard_False;
// NKV - 31/07/07 - Fix for perspective view
if ( aViou->Type() == V3d_PERSPECTIVE ) {
Pers = Standard_True;
Focale = aViou->Focale();} // must be replaced by the method Focale
aViou->At(Xat,Yat,Zat);
aViou->Up(XUp,YUp,ZUp);
aViou->Proj(DX,DY,DZ);
gp_Pnt At (Xat,Yat,Zat);
gp_Dir Zpers (DX,DY,DZ);
gp_Dir Ypers (XUp,YUp,ZUp);
gp_Dir Xpers = Ypers.Crossed(Zpers);
gp_Ax3 Axe (At, Zpers, Xpers);
gp_Trsf T;
T.SetTransformation(Axe);
return new Select3D_Projector(T,Pers,Focale);
}
//=======================================================================
//function : SetDrawerForBRepOwner
//purpose :
@@ -65,7 +42,7 @@ void StdSelect::SetDrawerForBRepOwner(const Handle(SelectMgr_Selection)& /*Sel*/
// Handle(StdSelect_BRepOwner) BROWN;
// for(Sel->Init();Sel->More();Sel->Next()){
// BROWN = Handle(StdSelect_BRepOwner)::DownCast(Sel->Sensitive()->OwnerId());
// BROWN = Handle(StdSelect_BRepOwner)::DownCast(Sel->Sensitive()->BaseSensitive()->OwnerId());
// if(!BROWN.IsNull())
// BROWN->SetDrawer(Drwr);
// }

View File

@@ -53,18 +53,18 @@ class BRepSelectionTool from StdSelect
--
uses
Selection from SelectMgr,
Shape from TopoDS,
Face from TopoDS,
ShapeEnum from TopAbs,
SelectableObject from SelectMgr,
BRepOwner from StdSelect,
SensitiveEntity from Select3D,
ListOfSensitive from Select3D
Selection from SelectMgr,
Shape from TopoDS,
Face from TopoDS,
ShapeEnum from TopAbs,
SelectableObject from SelectMgr,
BRepOwner from StdSelect,
SensitiveEntity from Select3D,
EntitySequence from Select3D
is
Load(myclass;
aSelection : Selection from SelectMgr;
aSelection : Selection from SelectMgr;
aShape : Shape from TopoDS;
aType : ShapeEnum from TopAbs;
theDeflection : Real from Standard;
@@ -90,7 +90,7 @@ is
Load(myclass;
aSelection : Selection from SelectMgr;
aSelection : Selection from SelectMgr;
Origin : SelectableObject from SelectMgr;
aShape : Shape from TopoDS;
aType : ShapeEnum from TopAbs;
@@ -152,6 +152,14 @@ is
-- computed for the faces which have none. If it is false,
-- sensitive entities on these faces will be calculated.
preBuildBVH (myclass;
theSelection : Selection from SelectMgr)
is private;
---Level: Internal
---Purpose: Traverses the selection given and pre-builds BVH trees for heavyweight
-- sensitive entities containing more than BVH_PRIMITIVE_LIMIT (defined in .cxx file)
-- sub-elements
GetEdgeSensitive(myclass;
aShape : Shape from TopoDS;
anOwner : BRepOwner from StdSelect;
@@ -160,7 +168,7 @@ is
theDeflectionAngle : Real from Standard;
NbPOnEdge : Integer;
MaximalParameter : Real from Standard;
aSensitive : in out SensitiveEntity from Select3D)
aSensitive : in out SensitiveEntity from Select3D)
is private;
---Level: Internal
---Purpose:
@@ -169,7 +177,7 @@ is
GetSensitiveForFace(myclass;
aFace : Face from TopoDS;
anOwner : BRepOwner from StdSelect;
OutList : in out ListOfSensitive from Select3D;
OutList : in out EntitySequence from Select3D;
AutoTriangulation : Boolean from Standard = Standard_True;
NbPOnEdge : Integer = 9;
MaxiParam : Real from Standard =500;

View File

@@ -31,6 +31,7 @@
#include <Bnd_Box.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Circle.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Select3D_SensitiveCircle.hxx>
#include <Select3D_SensitiveCurve.hxx>
#include <Select3D_SensitiveSegment.hxx>
@@ -40,9 +41,7 @@
#include <Select3D_SensitiveTriangulation.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <Select3D_SensitiveGroup.hxx>
#include <Select3D_ListIteratorOfListOfSensitive.hxx>
#include <Select3D_ListOfSensitiveTriangle.hxx>
#include <SelectMgr_Selection.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <TColgp_SequenceOfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
@@ -61,6 +60,40 @@
#include <Standard_NullObject.hxx>
#include <Standard_ErrorHandler.hxx>
#define BVH_PRIMITIVE_LIMIT 800000
//==================================================
// function: preBuildBVH
// purpose : Pre-builds BVH tree for heavyweight
// sensitive entities with sub-elements
// amount more than BVH_PRIMITIVE_LIMIT
//==================================================
void StdSelect_BRepSelectionTool::preBuildBVH (const Handle(SelectMgr_Selection)& theSelection)
{
for (theSelection->Init(); theSelection->More(); theSelection->Next())
{
const Handle(SelectBasics_SensitiveEntity)& aSensitive = theSelection->Sensitive()->BaseSensitive();
if (aSensitive->NbSubElements() >= BVH_PRIMITIVE_LIMIT)
{
aSensitive->BVH();
}
if (aSensitive->IsInstance ("Select3D_SensitiveGroup"))
{
const Handle(Select3D_SensitiveGroup)& aGroup = Handle(Select3D_SensitiveGroup)::DownCast (aSensitive);
const Select3D_EntitySequence& aSubEntities = aGroup->GetEntities();
for (Select3D_EntitySequenceIter aSubEntitiesIter (aSubEntities); aSubEntitiesIter.More(); aSubEntitiesIter.Next())
{
const Handle(Select3D_SensitiveEntity)& aSubEntity = aSubEntitiesIter.Value();
if (aSubEntity->NbSubElements() >= BVH_PRIMITIVE_LIMIT)
{
aSubEntity->BVH();
}
}
}
}
}
//==================================================
// Function: Load
// Purpose :
@@ -156,9 +189,11 @@ void StdSelect_BRepSelectionTool
for (theSelection->Init(); theSelection->More(); theSelection->Next())
{
Handle(SelectMgr_EntityOwner) anOwner
= Handle(SelectMgr_EntityOwner)::DownCast (theSelection->Sensitive()->OwnerId());
= Handle(SelectMgr_EntityOwner)::DownCast (theSelection->Sensitive()->BaseSensitive()->OwnerId());
anOwner->Set (theSelectableObj);
}
preBuildBVH (theSelection);
}
//==================================================
@@ -217,11 +252,11 @@ void StdSelect_BRepSelectionTool
case TopAbs_FACE:
{
const TopoDS_Face& aFace = TopoDS::Face (theShape);
Select3D_ListOfSensitive aSensitiveList;
Select3D_EntitySequence aSensitiveList;
GetSensitiveForFace (aFace, theOwner,
aSensitiveList,
isAutoTriangulation, theNbPOnEdge, theMaxParam);
for (Select3D_ListIteratorOfListOfSensitive aSensIter (aSensitiveList);
for (Select3D_EntitySequenceIter aSensIter (aSensitiveList);
aSensIter.More(); aSensIter.Next())
{
theSelection->Add (aSensIter.Value());
@@ -575,7 +610,7 @@ Standard_Integer StdSelect_BRepSelectionTool::GetStandardPriority (const TopoDS_
Standard_Boolean StdSelect_BRepSelectionTool
::GetSensitiveForFace (const TopoDS_Face& theFace,
const Handle(StdSelect_BRepOwner)& theOwner,
Select3D_ListOfSensitive& theSensitiveList,
Select3D_EntitySequence& theSensitiveList,
const Standard_Boolean /*theAutoTriangulation*/,
const Standard_Integer NbPOnEdge,
const Standard_Real theMaxParam,

View File

@@ -1,199 +0,0 @@
-- Created on: 1995-03-15
-- Created by: Robert COUBLANC
-- Copyright (c) 1995-1999 Matra Datavision
-- Copyright (c) 1999-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.
-- Modified by rob jun 25 98 : Add Method : Reactivate projector...
class ViewerSelector3d from StdSelect inherits ViewerSelector from SelectMgr
---Purpose: Selector Usable by Viewers from V3d
-- Accepts Only Sensitive Entities inheriting Select3D entities...
uses
View from V3d,
Selection from SelectMgr,
EntityOwner from SelectMgr,
Projector from Select3D,
Group from Graphic3d,
Structure from Graphic3d,
SequenceOfHClipPlane from Graphic3d,
Array1OfReal from TColStd,
Array1OfPnt2d from TColgp,
SensitivityMode from StdSelect,
Lin from gp,
Pnt from gp,
Dir from gp,
XYZ from gp
is
Create returns ViewerSelector3d from StdSelect;
---Purpose: Constructs an empty 3D selector object.
Create (theProj : Projector from Select3D) returns ViewerSelector3d from StdSelect;
---Purpose: Constructs a 3D selector object defined by the projector <theProj>.
Convert (me : mutable; theSel : Selection from SelectMgr)
is redefined static;
---Level: Public
---Purpose: Processes the projection of the sensitive primitives
-- in the active view ; to be done before the selection action...
Set (me : mutable; theProj : Projector from Select3D) is static;
---Purpose: Sets the new projector <theProj> to replace the one used at construction time.
SetSensitivityMode (me : mutable;
theMode : SensitivityMode from StdSelect) is static;
---Purpose: Sets the selection sensitivity mode. SM_WINDOW mode
-- uses the specified pixel tolerance to compute the sensitivity
-- value, SM_VIEW mode allows to define the sensitivity manually.
SensitivityMode (me) returns SensitivityMode from StdSelect;
---C++: inline
---Purpose: Returns the selection sensitivity mode.
SetPixelTolerance (me : mutable;
theTolerance : Integer) is static;
---Purpose: Sets the pixel tolerance <theTolerance>.
PixelTolerance (me) returns Integer from Standard;
---C++: inline
---Purpose: Returns the pixel tolerance.
Pick (me : mutable; theXPix, theYPix : Integer;
theView : View from V3d) is static;
---Level: Public
---Purpose: Picks the sensitive entity at the pixel coordinates of
-- the mouse <theXPix> and <theYPix>. The selector looks for touched areas and owners.
Pick (me : mutable; theXPMin, theYPMin, theXPMax, theYPMax : Integer; theView : View from V3d) is static;
---Purpose: Picks the sensitive entity according to the minimum
-- and maximum pixel values <theXPMin>, <theYPMin>, <theXPMax>
-- and <theYPMax> defining a 2D area for selection in the 3D view aView.
Pick (me : mutable; thePolyline : Array1OfPnt2d from TColgp; theView : View from V3d) is static;
---Level: Public
---Purpose: pick action - input pixel values for polyline selection for selection.
---Category: Inquire Methods
Projector (me) returns Projector from Select3D;
---Level: Public
---Purpose: Returns the current Projector.
---C++: inline
---C++: return const&
---Category: Internal Methods
-- -----------------
UpdateProj (me : mutable;
theView : View from V3d) returns Boolean is static private;
---Level: Internal
DisplayAreas (me : mutable;
theView : View from V3d) is static;
---Purpose: Displays sensitive areas found in the view <theView>.
ClearAreas (me : mutable;
theView : View from V3d) is static;
---Purpose: Clears the view aView of sensitive areas found in it.
DisplaySensitive (me : mutable; theView : View from V3d) is static;
--- Purpose: Displays sensitives in view <theView>.
ClearSensitive (me : mutable; theView : View from V3d) is static;
DisplaySensitive (me : mutable;
theSel : Selection from SelectMgr;
theView : View from V3d;
theToClearOthers : Boolean from Standard = Standard_True)
is static;
DisplayAreas (me : mutable;
theSel : Selection from SelectMgr;
theView : View from V3d;
theToClearOthers : Boolean from Standard = Standard_True)
is static;
ComputeSensitivePrs (me : mutable; theSel: Selection from SelectMgr)
is static private;
---Level: Internal
ComputeAreasPrs (me : mutable; theSel : Selection from SelectMgr)
is static private;
---Level: Internal
SetClipping (me : mutable; thePlanes : SequenceOfHClipPlane from Graphic3d) is protected;
---Level: Internal
---Purpose: Set view clipping for the selector.
-- @param thePlanes [in] the view planes.
ComputeClipRange (me; thePlanes : SequenceOfHClipPlane from Graphic3d;
thePickLine : Lin from gp;
theDepthMin, theDepthMax : out Real from Standard)
is protected;
---Level: Internal
---Purpose: Computed depth boundaries for the passed set of clipping planes and picking line.
-- @param thePlanes [in] the planes.
-- @param thePickLine [in] the picking line.
-- @param theDepthMin [out] minimum depth limit.
-- @param theDepthMax [out] maximum depth limit.
PickingLine (me; theX, theY : Real from Standard)
returns Lin from gp
is redefined protected;
---Level: Internal
---Purpose: For more details please refer to base class.
DepthClipping (me; theX, theY : Real from Standard;
theMin, theMax : out Real from Standard)
is redefined protected;
---Level: Internal
---Purpose: For more details please refer to base class.
DepthClipping (me; theX, theY : Real from Standard;
theOwner : EntityOwner from SelectMgr;
theMin, theMax : out Real from Standard)
is redefined protected;
---Level: Internal
---Purpose: For more details please refer to base class.
HasDepthClipping (me; theOwner : EntityOwner from SelectMgr)
returns Boolean is redefined protected;
---Level: Internal
---Purpose: For more details please refer to base class.
fields
myProjector : Projector from Select3D;
myPrevAt : Real from Standard[3];
myPrevUp : Real from Standard[3];
myPrevProj : Real from Standard[3];
myPrevAxialScale : Real from Standard[3];
myPrevFOV : Real from Standard;
myPrevScale : Real from Standard;
myPrevOrthographic : Boolean from Standard;
mySensMode : SensitivityMode from StdSelect;
myPixelTolerance : Integer from Standard;
myToUpdateTolerance : Boolean from Standard;
--areas verification...
myareagroup : Group from Graphic3d;
mysensgroup : Group from Graphic3d;
mystruct : Structure from Graphic3d;
myClipPlanes : SequenceOfHClipPlane from Graphic3d;
end ViewerSelector3d;

View File

@@ -14,7 +14,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <StdSelect_ViewerSelector3d.ixx>
#include <StdSelect_ViewerSelector3d.hxx>
#include <StdSelect.hxx>
#include <SelectBasics_SensitiveEntity.hxx>
#include <Graphic3d_AspectLine3d.hxx>
@@ -27,12 +27,13 @@
#include <gp_Pln.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_SequenceOfHClipPlane.hxx>
#include <Graphic3d_Structure.hxx>
#include <SelectMgr_SelectableObject.hxx>
#include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
#include <SelectBasics_ListOfBox2d.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TColgp_HArray1OfPnt2d.hxx>
#include <Select3D_SensitiveCurve.hxx>
#include <Select3D_SensitiveSegment.hxx>
@@ -42,17 +43,15 @@
#include <Select3D_SensitiveTriangulation.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <Select3D_SensitiveWire.hxx>
#include <Select3D_SensitiveEntitySequence.hxx>
#include <Select3D_ListOfSensitiveTriangle.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <Select3D_ListIteratorOfListOfSensitiveTriangle.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation.hxx>
#include <Aspect_Grid.hxx>
#include <Aspect_TypeOfMarker.hxx>
#include <Aspect_Window.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_ArrayOfPoints.hxx>
#include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
#include <Poly_Connect.hxx>
#include <TColStd_HArray1OfInteger.hxx>
@@ -64,6 +63,11 @@
#include <V3d_Viewer.hxx>
#include <TColgp_SequenceOfPnt.hxx>
#include <OSD_Timer.hxx>
IMPLEMENT_STANDARD_HANDLE (StdSelect_ViewerSelector3d, SelectMgr_ViewerSelector)
IMPLEMENT_STANDARD_RTTIEXT(StdSelect_ViewerSelector3d, SelectMgr_ViewerSelector)
static Standard_Integer StdSel_NumberOfFreeEdges (const Handle(Poly_Triangulation)& Trg)
{
Standard_Integer nFree = 0;
@@ -83,105 +87,17 @@ static Standard_Integer StdSel_NumberOfFreeEdges (const Handle(Poly_Triangulatio
// Function : Constructor
// Purpose :
//=======================================================================
StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d()
: myProjector (new Select3D_Projector()),
myPrevFOV (0.0),
myPrevScale (0.0),
myPrevOrthographic (Standard_True),
mySensMode (StdSelect_SM_WINDOW),
myPixelTolerance (2),
myToUpdateTolerance (Standard_True)
{
myPrevAt[0] = 0.0;
myPrevAt[1] = 0.0;
myPrevAt[2] = 0.0;
myPrevUp[0] = 0.0;
myPrevUp[1] = 0.0;
myPrevUp[2] = 0.0;
myPrevProj[0] = 0.0;
myPrevProj[1] = 0.0;
myPrevProj[2] = 0.0;
myPrevAxialScale[0] = 0.0;
myPrevAxialScale[1] = 0.0;
myPrevAxialScale[2] = 0.0;
}
//=======================================================================
// Function : Constructor
// Purpose :
//=======================================================================
StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d (const Handle(Select3D_Projector)& theProj)
: myProjector (theProj),
myPrevFOV (0.0),
myPrevScale (0.0),
myPrevOrthographic (Standard_True),
mySensMode (StdSelect_SM_WINDOW),
myPixelTolerance (2),
myToUpdateTolerance (Standard_True)
{
myPrevAt[0] = 0.0;
myPrevAt[1] = 0.0;
myPrevAt[2] = 0.0;
myPrevUp[0] = 0.0;
myPrevUp[1] = 0.0;
myPrevUp[2] = 0.0;
myPrevProj[0] = 0.0;
myPrevProj[1] = 0.0;
myPrevProj[2] = 0.0;
myPrevAxialScale[0] = 0.0;
myPrevAxialScale[1] = 0.0;
myPrevAxialScale[2] = 0.0;
}
//=======================================================================
// Function: Convert
// Purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::Convert (const Handle(SelectMgr_Selection)& theSel)
{
for (theSel->Init(); theSel->More(); theSel->Next())
{
if (theSel->Sensitive()->NeedsConversion())
{
Handle(Select3D_SensitiveEntity) aSE = *((Handle(Select3D_SensitiveEntity)*) &(theSel->Sensitive()));
aSE->Project (myProjector);
if (!tosort)
{
tosort = Standard_True;
}
}
}
}
//=======================================================================
// Function: Set
// Purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::Set (const Handle(Select3D_Projector)& theProj)
{
myProjector = theProj;
toupdate = Standard_True;
}
//=======================================================================
// Function: SetSensitivityMode
// Purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::SetSensitivityMode (const StdSelect_SensitivityMode theMode)
{
mySensMode = theMode;
toupdate = Standard_True;
}
StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d() {}
//=======================================================================
// Function: SetPixelTolerance
// Purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::SetPixelTolerance (const Standard_Integer theTolerance)
void StdSelect_ViewerSelector3d::SetPixelTolerance (const Standard_Real theTolerance)
{
if (myPixelTolerance != theTolerance)
if (mytolerance != theTolerance)
{
myPixelTolerance = theTolerance;
mytolerance = theTolerance;
myToUpdateTolerance = Standard_True;
}
}
@@ -195,15 +111,23 @@ void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPix,
const Handle(V3d_View)& theView)
{
SetClipping (theView->GetClipPlanes());
UpdateProj (theView);
Standard_Real aPnt3d[3];
theView->Convert (theXPix, theYPix,
aPnt3d[0], aPnt3d[1], aPnt3d[2]);
gp_Pnt2d aPnt2d;
myProjector->Project (gp_Pnt (aPnt3d[0], aPnt3d[1], aPnt3d[2]), aPnt2d);
if(myToUpdateTolerance)
{
mySelectingVolumeMgr.SetPixelTolerance (mytolerance);
myToUpdateTolerance = Standard_False;
}
InitSelect (aPnt2d.X(), aPnt2d.Y());
mySelectingVolumeMgr.SetCamera (theView->Camera());
mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Point);
Standard_Integer aWidth = 0, aHeight = 0;
theView->Window()->Size (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
gp_Pnt2d aMousePos (static_cast<Standard_Real> (theXPix),
static_cast<Standard_Real> (theYPix));
mySelectingVolumeMgr.BuildSelectingVolume (aMousePos);
TraverseSensitives();
}
//=======================================================================
@@ -216,32 +140,19 @@ void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin,
const Standard_Integer theYPMax,
const Handle(V3d_View)& theView)
{
if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
{
SetSensitivity (theView->Convert (myPixelTolerance));
myToUpdateTolerance = Standard_False;
}
mySelectingVolumeMgr.SetCamera (theView->Camera());
mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box);
Standard_Integer aWidth = 0, aHeight = 0;
theView->Window()->Size (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
gp_Pnt2d aMinMousePos (static_cast<Standard_Real> (theXPMin),
static_cast<Standard_Real> (theYPMin));
gp_Pnt2d aMaxMousePos (static_cast<Standard_Real> (theXPMax),
static_cast<Standard_Real> (theYPMax));
mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos,
aMaxMousePos);
UpdateProj (theView);
Standard_Real aX1 = 0.0;
Standard_Real aY1 = 0.0;
Standard_Real aZ1 = 0.0;
Standard_Real aX2 = 0.0;
Standard_Real aY2 = 0.0;
Standard_Real aZ2 = 0.0;
gp_Pnt2d aP2d1;
gp_Pnt2d aP2d2;
theView->Convert (theXPMin, theYPMin, aX1, aY1, aZ1);
theView->Convert (theXPMax, theYPMax, aX2, aY2, aZ2);
myProjector->Project (gp_Pnt (aX1, aY1, aZ1), aP2d1);
myProjector->Project (gp_Pnt (aX2, aY2, aZ2), aP2d2);
InitSelect (Min (aP2d1.X(), aP2d2.X()),
Min (aP2d1.Y(), aP2d2.Y()),
Max (aP2d1.X(), aP2d2.X()),
Max (aP2d1.Y(), aP2d2.Y()));
TraverseSensitives();
}
//=======================================================================
@@ -251,295 +162,22 @@ void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin,
void StdSelect_ViewerSelector3d::Pick (const TColgp_Array1OfPnt2d& thePolyline,
const Handle(V3d_View)& theView)
{
if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
{
SetSensitivity (theView->Convert (myPixelTolerance));
myToUpdateTolerance = Standard_False;
}
mySelectingVolumeMgr.SetCamera (theView->Camera());
mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Polyline);
Standard_Integer aWidth = 0, aHeight = 0;
theView->Window()->Size (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.BuildSelectingVolume (thePolyline);
UpdateProj (theView);
Standard_Integer aNbPix = thePolyline.Length();
// Convert pixel
Handle(TColgp_HArray1OfPnt2d) aP2d = new TColgp_HArray1OfPnt2d (1, aNbPix);
for (Standard_Integer aPntIt = 1; aPntIt <= aNbPix; ++aPntIt)
{
Standard_Integer aXP = (Standard_Integer)(thePolyline (aPntIt).X());
Standard_Integer aYP = (Standard_Integer)(thePolyline (aPntIt).Y());
Standard_Real aX = 0.0;
Standard_Real aY = 0.0;
Standard_Real aZ = 0.0;
gp_Pnt2d aPnt2d;
theView->Convert (aXP, aYP, aX, aY, aZ);
myProjector->Project (gp_Pnt (aX, aY, aZ), aPnt2d);
aP2d->SetValue (aPntIt, aPnt2d);
}
const TColgp_Array1OfPnt2d& aPolyConvert = aP2d->Array1();
InitSelect (aPolyConvert);
TraverseSensitives();
}
//=======================================================================
// Function: DisplayAreas
// Purpose : display the activated areas...
//=======================================================================
void StdSelect_ViewerSelector3d::DisplayAreas (const Handle(V3d_View)& theView)
{
if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
{
SetSensitivity (theView->Convert (myPixelTolerance));
myToUpdateTolerance = Standard_False;
}
UpdateProj (theView);
UpdateSort(); // Updates the activated areas
if (mystruct.IsNull())
{
mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
}
if (myareagroup.IsNull())
{
myareagroup = mystruct->NewGroup();
}
SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive anIt (myentities);
Handle(Select3D_Projector) aProjector = StdSelect::GetProjector (theView);
aProjector->SetView (theView);
Standard_Real aXmin = 0.0;
Standard_Real aYmin = 0.0;
Standard_Real aXmax = 0.0;
Standard_Real aYmax = 0.0;
gp_Pnt aPbid;
SelectBasics_ListOfBox2d aBoxList;
TColgp_SequenceOfPnt aSeqLines;
for (; anIt.More(); anIt.Next())
{
anIt.Value()->Areas (aBoxList);
for (SelectBasics_ListIteratorOfListOfBox2d aBoxIt (aBoxList); aBoxIt.More(); aBoxIt.Next())
{
aBoxIt.Value().Get (aXmin, aYmin, aXmax, aYmax);
aPbid.SetCoord (aXmin - mytolerance, aYmin - mytolerance, 0.0);
aProjector->Transform (aPbid, aProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
aPbid.SetCoord (aXmax + mytolerance, aYmin - mytolerance, 0.0);
aProjector->Transform (aPbid, aProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
aPbid.SetCoord (aXmax + mytolerance, aYmax + mytolerance, 0.0);
aProjector->Transform (aPbid, aProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
aPbid.SetCoord (aXmin - mytolerance, aYmax + mytolerance, 0.0);
aProjector->Transform (aPbid, aProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
}
}
if (aSeqLines.Length())
{
Standard_Integer aN = 0;
Standard_Integer aNp = 0;
const Standard_Integer aNbl = aSeqLines.Length() / 4;
Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines (5 * aNbl, aNbl);
for (aNp = 1, aN = 0; aN < aNbl; aN++)
{
aPrims->AddBound (5);
const gp_Pnt &aPnt1 = aSeqLines (aNp++);
aPrims->AddVertex (aPnt1);
aPrims->AddVertex (aSeqLines (aNp++));
aPrims->AddVertex (aSeqLines (aNp++));
aPrims->AddVertex (aSeqLines (aNp++));
aPrims->AddVertex (aPnt1);
}
myareagroup->AddPrimitiveArray (aPrims);
}
myareagroup->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_AQUAMARINE1, Aspect_TOL_DASH, 1.0));
myareagroup->Structure()->SetDisplayPriority (10);
myareagroup->Structure()->Display();
theView->Update();
}
//=======================================================================
// Function: ClearAreas
// Purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::ClearAreas (const Handle(V3d_View)& theView)
{
if (myareagroup.IsNull())
{
return;
}
myareagroup->Clear();
if (!theView.IsNull())
{
theView->Update();
}
}
//=======================================================================
// Function: UpdateProj
// Purpose :
//=======================================================================
Standard_Boolean StdSelect_ViewerSelector3d::UpdateProj (const Handle(V3d_View)& theView)
{
// Check common properties of camera
Standard_Real anUp[3];
Standard_Real aProj[3];
Standard_Real anAxialScale[3];
theView->Up (anUp[0], anUp[1], anUp[2]);
theView->Proj (aProj[0], aProj[1], aProj[2]);
theView->AxialScale (anAxialScale[0], anAxialScale[1], anAxialScale[2]);
Standard_Boolean isOrthographic = theView->Type() == V3d_ORTHOGRAPHIC;
Standard_Boolean toUpdateProjector = myPrevOrthographic != isOrthographic
|| myPrevUp[0] != anUp[0]
|| myPrevUp[1] != anUp[1]
|| myPrevUp[2] != anUp[2]
|| myPrevProj[0] != aProj[0]
|| myPrevProj[1] != aProj[1]
|| myPrevProj[2] != aProj[2]
|| myPrevAxialScale[0] != anAxialScale[0]
|| myPrevAxialScale[1] != anAxialScale[1]
|| myPrevAxialScale[2] != anAxialScale[2];
// Check properties of perspective camera
Standard_Real anAt[3];
Standard_Real aScale = theView->Scale();
Standard_Real aFOV = theView->Camera()->FOVy();
theView->At (anAt[0], anAt[1], anAt[2]);
if (!isOrthographic && !toUpdateProjector)
{
toUpdateProjector = myPrevAt[0] != anAt[0]
|| myPrevAt[1] != anAt[1]
|| myPrevAt[2] != anAt[2]
|| myPrevScale != aScale
|| myPrevFOV != aFOV;
}
myToUpdateTolerance = aScale != myPrevScale;
// Update projector if anything changed
if (toUpdateProjector)
{
toupdate = Standard_True;
myToUpdateTolerance = Standard_True;
if (isOrthographic)
{
// For orthographic view use only direction of projection and up vector
// Panning, and zooming has no effect on 2D selection sensitives.
Handle (Graphic3d_Camera) aCamera = new Graphic3d_Camera();
aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
aCamera->SetCenter (gp::Origin());
aCamera->SetDirection (gp_Dir (-aProj[0], -aProj[1], -aProj[2]));
aCamera->SetUp (gp_Dir (anUp[0], anUp[1], anUp[2]));
aCamera->SetDistance (1.0);
aCamera->SetAxialScale (gp_XYZ (anAxialScale[0], anAxialScale[1], anAxialScale[2]));
myProjector = new Select3D_Projector (aCamera->OrientationMatrix(), Graphic3d_Mat4d());
}
else
{
// For perspective projection panning, zooming and location of view
// has effect. Thus, use current view and projection matrices from
// view camera. Exception is that the projection transformation
// is scaled from NDC to size of displaying frame of view space in order
// to maintain consistence with pixel tolerance conversion.
const Graphic3d_Mat4d& aMVMatrix = theView->Camera()->OrientationMatrix();
const Graphic3d_Mat4d& aProjMatrix = theView->Camera()->ProjectionMatrix();
gp_XYZ aViewDimensions = theView->Camera()->ViewDimensions();
Graphic3d_Mat4d aScaledProj;
aScaledProj.ChangeValue (0, 0) = aViewDimensions.X();
aScaledProj.ChangeValue (1, 1) = aViewDimensions.Y();
aScaledProj.ChangeValue (2, 2) = aViewDimensions.Z();
Graphic3d_Mat4d aScaledProjMatrix = aScaledProj * aProjMatrix;
Standard_Real aZNear = theView->Camera()->ZNear();
Standard_Real aZFar = theView->Camera()->ZFar();
myProjector = new Select3D_Projector (aMVMatrix, aScaledProjMatrix, aZNear, aZFar);
}
}
myPrevAt[0] = anAt[0];
myPrevAt[1] = anAt[1];
myPrevAt[2] = anAt[2];
myPrevUp[0] = anUp[0];
myPrevUp[1] = anUp[1];
myPrevUp[2] = anUp[2];
myPrevProj[0] = aProj[0];
myPrevProj[1] = aProj[1];
myPrevProj[2] = aProj[2];
myPrevAxialScale[0] = anAxialScale[0];
myPrevAxialScale[1] = anAxialScale[1];
myPrevAxialScale[2] = anAxialScale[2];
myPrevFOV = aFOV;
myPrevScale = aScale;
myPrevOrthographic = isOrthographic;
if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
{
SetSensitivity (theView->Convert (myPixelTolerance));
myToUpdateTolerance = Standard_False;
}
if (toupdate)
{
UpdateConversion();
}
if (tosort)
{
UpdateSort();
}
return Standard_True;
}
//=======================================================================
// Function: DisplaySensitive.
// Purpose : Display active primitives.
//=======================================================================
void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theView)
{
if (myToUpdateTolerance && SensitivityMode() == StdSelect_SM_WINDOW)
{
SetSensitivity (theView->Convert (myPixelTolerance));
myToUpdateTolerance = Standard_False;
}
if (toupdate)
{
UpdateProj (theView);
}
if (tosort)
{
UpdateSort(); // Updates the activated areas
}
// Preparation des structures
if (mystruct.IsNull())
{
@@ -559,14 +197,15 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theVi
mysensgroup->SetPrimitivesAspect (
new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0));
SelectMgr_DataMapIteratorOfDataMapOfSelectionActivation anIt (myselections);
for (; anIt.More(); anIt.Next())
for (Standard_Integer anObjectIdx = 0; anObjectIdx <= mySelectableObjects->Size(); ++anObjectIdx)
{
if (anIt.Value()==0)
const Handle (SelectMgr_SelectableObject)& anObject = mySelectableObjects->GetObjectById (anObjectIdx);
for (anObject->Init(); anObject->More(); anObject->Next())
{
const Handle(SelectMgr_Selection)& aSel = anIt.Key();
ComputeSensitivePrs (aSel);
if (anObject->CurrentSelection()->GetSelectionState() == SelectMgr_SOS_Activated)
{
ComputeSensitivePrs (anObject->CurrentSelection(), anObject->Transformation());
}
}
}
@@ -602,6 +241,7 @@ void StdSelect_ViewerSelector3d::ClearSensitive (const Handle(V3d_View)& theView
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Selection)& theSel,
const gp_Trsf& theTrsf,
const Handle(V3d_View)& theView,
const Standard_Boolean theToClearOthers)
{
@@ -627,39 +267,7 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Select
mysensgroup->Clear();
}
ComputeSensitivePrs (theSel);
mystruct->SetDisplayPriority (10);
mystruct->Display();
theView->Update();
}
//=======================================================================
//function : DisplayAreas
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::DisplayAreas (const Handle(SelectMgr_Selection)& theSel,
const Handle(V3d_View)& theView,
const Standard_Boolean theToClearOthers)
{
if (mystruct.IsNull())
{
mystruct = new Graphic3d_Structure (theView->Viewer()->Viewer());
}
if (mysensgroup.IsNull())
{
myareagroup = mystruct->NewGroup();
myareagroup->SetGroupPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_AQUAMARINE1, Aspect_TOL_DASH, 1.0));
}
if (theToClearOthers)
{
myareagroup->Clear();
}
ComputeAreasPrs (theSel);
ComputeSensitivePrs (theSel, theTrsf);
mystruct->SetDisplayPriority (10);
mystruct->Display();
@@ -671,19 +279,17 @@ void StdSelect_ViewerSelector3d::DisplayAreas (const Handle(SelectMgr_Selection)
//function : ComputeSensitivePrs
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Selection)& theSel)
void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Selection)& theSel,
const gp_Trsf& theLoc)
{
TColgp_SequenceOfPnt aSeqLines, aSeqFree;
TColStd_SequenceOfInteger aSeqBnds;
for (theSel->Init(); theSel->More(); theSel->Next())
{
Handle(Select3D_SensitiveEntity) Ent = Handle(Select3D_SensitiveEntity)::DownCast(theSel->Sensitive());
const Standard_Boolean hasloc = (Ent.IsNull()? Standard_False : Ent->HasLocation());
TopLoc_Location theloc;
if(hasloc)
theloc = Ent->Location();
Handle(Select3D_SensitiveEntity) Ent =
Handle(Select3D_SensitiveEntity)::DownCast(theSel->Sensitive()->BaseSensitive());
const Standard_Boolean hasloc = theLoc.Form() != gp_Identity;
//==============
// Box
@@ -709,7 +315,7 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
if(hasloc)
{
for (i = 0; i <= 7; i++)
theboxpoint[i].Transform (theloc.Transformation());
theboxpoint[i].Transform (theLoc);
}
aSeqBnds.Append(5);
@@ -736,14 +342,14 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
{
Handle(Select3D_SensitiveFace) aFace = Handle(Select3D_SensitiveFace)::DownCast(Ent);
Handle(TColgp_HArray1OfPnt) TheHPts;
aFace->Points3D(TheHPts);
aFace->GetPoints(TheHPts);
const TColgp_Array1OfPnt& ThePts = TheHPts->Array1();
aSeqBnds.Append(ThePts.Length());
for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
{
if (hasloc)
aSeqLines.Append(ThePts(I).Transformed (theloc.Transformation()));
aSeqLines.Append(ThePts(I).Transformed (theLoc));
else
aSeqLines.Append(ThePts(I));
}
@@ -762,7 +368,7 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
{
if (hasloc)
aSeqLines.Append(ThePts(I).Transformed (theloc.Transformation()));
aSeqLines.Append(ThePts(I).Transformed (theLoc));
else
aSeqLines.Append(ThePts(I));
}
@@ -773,12 +379,11 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveWire))
{
Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast(Ent);
Select3D_SensitiveEntitySequence EntitySeq;
aWire->GetEdges (EntitySeq);
const NCollection_Vector<Handle(Select3D_SensitiveEntity)>& anEntities = aWire->GetEdges();
for (int i = 1; i <= EntitySeq.Length(); i++)
for (int i = 0; i < anEntities.Length(); i++)
{
Handle(Select3D_SensitiveEntity) SubEnt = Handle(Select3D_SensitiveEntity)::DownCast(EntitySeq.Value(i));
Handle(Select3D_SensitiveEntity) SubEnt = Handle(Select3D_SensitiveEntity)::DownCast(anEntities.Value(i));
//Segment
if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment))
@@ -787,8 +392,8 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->EndPoint().XYZ());
if (hasloc)
{
P1.Transform(theloc.Transformation());
P2.Transform(theloc.Transformation());
P1.Transform(theLoc);
P2.Transform(theLoc);
}
aSeqBnds.Append(2);
aSeqLines.Append(P1);
@@ -813,9 +418,9 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
if (hasloc)
{
aPnts[0].Transform (theloc.Transformation());
aPnts[1].Transform (theloc.Transformation());
aPnts[2].Transform (theloc.Transformation());
aPnts[0].Transform (theLoc);
aPnts[1].Transform (theLoc);
aPnts[2].Transform (theLoc);
}
aSeqBnds.Append (4);
@@ -838,7 +443,7 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++)
{
if (hasloc)
aSeqLines.Append(ThePts(I).Transformed (theloc.Transformation()));
aSeqLines.Append(ThePts(I).Transformed (theLoc));
else
aSeqLines.Append(ThePts(I));
}
@@ -854,8 +459,8 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->EndPoint().XYZ());
if (hasloc)
{
P1.Transform (theloc.Transformation());
P2.Transform (theloc.Transformation());
P1.Transform (theLoc);
P2.Transform (theLoc);
}
aSeqBnds.Append(2);
aSeqLines.Append(P1);
@@ -881,9 +486,9 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
if (hasloc)
{
aPnts[0].Transform (theloc.Transformation());
aPnts[1].Transform (theloc.Transformation());
aPnts[2].Transform (theloc.Transformation());
aPnts[0].Transform (theLoc);
aPnts[1].Transform (theLoc);
aPnts[2].Transform (theLoc);
}
aSeqBnds.Append (4);
@@ -900,7 +505,7 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
{
gp_Pnt P = hasloc ?
Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point() :
Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point().Transformed (theloc.Transformation());
Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point().Transformed (theLoc);
Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
anArrayOfPoints->AddVertex (P.X(), P.Y(), P.Z());
mysensgroup->AddPrimitiveArray (anArrayOfPoints);
@@ -922,9 +527,9 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
bidloc = (*((Handle(Select3D_SensitiveTriangulation)*) &Ent))->GetInitLocation();
if (bidloc.IsIdentity())
iloc = theloc;
iloc = theLoc;
else
iloc = theloc * bidloc;
iloc = theLoc * bidloc;
Standard_Integer i;
for (i = 1; i <= PT->NbTriangles(); i++)
@@ -1026,66 +631,6 @@ void StdSelect_ViewerSelector3d::ComputeSensitivePrs (const Handle(SelectMgr_Sel
}
}
//=======================================================================
//function : ComputeAreaPrs
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::ComputeAreasPrs (const Handle(SelectMgr_Selection)& theSel)
{
Standard_Real aXmin = 0.0;
Standard_Real aYmin = 0.0;
Standard_Real aXmax = 0.0;
Standard_Real aYmax = 0.0;
gp_Pnt aPbid;
SelectBasics_ListOfBox2d aBoxList;
TColgp_SequenceOfPnt aSeqLines;
for (theSel->Init(); theSel->More(); theSel->Next())
{
theSel->Sensitive()->Areas (aBoxList);
for (SelectBasics_ListIteratorOfListOfBox2d aBoxIt (aBoxList); aBoxIt.More(); aBoxIt.Next())
{
aBoxIt.Value().Get (aXmin, aYmin, aXmax, aYmax);
aPbid.SetCoord (aXmin - mytolerance, aYmin - mytolerance, 0.0);
myProjector->Transform (aPbid, myProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
aPbid.SetCoord (aXmax + mytolerance, aYmin - mytolerance, 0.0);
myProjector->Transform (aPbid, myProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
aPbid.SetCoord (aXmax + mytolerance, aYmax + mytolerance, 0.0);
myProjector->Transform (aPbid, myProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
aPbid.SetCoord (aXmin - mytolerance, aYmax + mytolerance, 0.0);
myProjector->Transform (aPbid, myProjector->InvertedTransformation());
aSeqLines.Append (aPbid);
}
}
if (aSeqLines.Length())
{
Standard_Integer aN = 0;
Standard_Integer aNP = 0;
const Standard_Integer aNBL = aSeqLines.Length() / 4;
Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines (5 * aNBL, aNBL);
for (aNP = 1, aN = 0; aN < aNBL; aN++)
{
aPrims->AddBound (5);
const gp_Pnt &aP1 = aSeqLines (aNP++);
aPrims->AddVertex (aP1);
aPrims->AddVertex (aSeqLines (aNP++));
aPrims->AddVertex (aSeqLines (aNP++));
aPrims->AddVertex (aSeqLines (aNP++));
aPrims->AddVertex (aP1);
}
myareagroup->AddPrimitiveArray (aPrims);
}
}
//=======================================================================
//function : SetClipping
//purpose :
@@ -1095,104 +640,6 @@ void StdSelect_ViewerSelector3d::SetClipping (const Graphic3d_SequenceOfHClipPla
myClipPlanes = thePlanes;
}
//=======================================================================
//function : ComputeClipRange
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::ComputeClipRange (const Graphic3d_SequenceOfHClipPlane& thePlanes,
const gp_Lin& thePickLine,
Standard_Real& theDepthMin,
Standard_Real& theDepthMax) const
{
theDepthMin = RealFirst();
theDepthMax = RealLast();
Standard_Real aPlaneA, aPlaneB, aPlaneC, aPlaneD;
Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes);
for (; aPlaneIt.More(); aPlaneIt.Next())
{
const Handle(Graphic3d_ClipPlane)& aClipPlane = aPlaneIt.Value();
if (!aClipPlane->IsOn())
continue;
gp_Pln aGeomPlane = aClipPlane->ToPlane();
aGeomPlane.Coefficients (aPlaneA, aPlaneB, aPlaneC, aPlaneD);
const gp_Dir& aPlaneDir = aGeomPlane.Axis().Direction();
const gp_Dir& aPickDir = thePickLine.Direction();
const gp_XYZ& aPntOnLine = thePickLine.Location().XYZ();
const gp_XYZ& aPlaneDirXYZ = aPlaneDir.XYZ();
Standard_Real aDotProduct = aPickDir.Dot (aPlaneDir);
Standard_Real aDistance = -(aPntOnLine.Dot (aPlaneDirXYZ) + aPlaneD);
// check whether the pick line is parallel to clip plane
if (Abs (aDotProduct) < Precision::Angular())
{
if (aDistance > 0.0)
{
// line lies above the plane, thus no selection is possible
theDepthMin = 0.0;
theDepthMax = 0.0;
return;
}
// line lies below the plane and is not clipped, skip
continue;
}
// compute distance to point of pick line intersection with the plane
Standard_Real aIntDist = aDistance / aDotProduct;
// change depth limits for case of opposite and directed planes
if (aDotProduct < 0.0)
{
theDepthMax = Min (aIntDist, theDepthMax);
}
else if (aIntDist > theDepthMin)
{
theDepthMin = Max (aIntDist, theDepthMin);
}
}
}
//=======================================================================
//function : PickingLine
//purpose :
//=======================================================================
gp_Lin StdSelect_ViewerSelector3d::PickingLine(const Standard_Real theX, const Standard_Real theY) const
{
return myProjector->Shoot (theX, theY);
}
//=======================================================================
//function : DepthClipping
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::DepthClipping (const Standard_Real theX,
const Standard_Real theY,
Standard_Real& theDepthMin,
Standard_Real& theDepthMax) const
{
return ComputeClipRange (myClipPlanes, PickingLine (theX, theY), theDepthMin, theDepthMax);
}
//=======================================================================
//function : DepthClipping
//purpose :
//=======================================================================
void StdSelect_ViewerSelector3d::DepthClipping (const Standard_Real theX,
const Standard_Real theY,
const Handle(SelectMgr_EntityOwner)& theOwner,
Standard_Real& theDepthMin,
Standard_Real& theDepthMax) const
{
return ComputeClipRange (theOwner->Selectable()->GetClipPlanes(),
PickingLine (theX, theY),
theDepthMin, theDepthMax);
}
//=======================================================================
//function : HasDepthClipping
//purpose :
@@ -1207,3 +654,13 @@ Standard_Boolean StdSelect_ViewerSelector3d::HasDepthClipping (const Handle(Sele
const Handle(SelectMgr_SelectableObject)& aSelectable = theOwner->Selectable();
return (aSelectable->GetClipPlanes().Size() > 0);
}
//=======================================================================
//function : ResetSelectionActivationStatus
//purpose : Marks all sensitive entities, stored in viewer selector,
// as inactive for selection
//=======================================================================
void StdSelect_ViewerSelector3d::ResetSelectionActivationStatus()
{
resetSelectionActivationStatus();
}

View File

@@ -0,0 +1,112 @@
// Created on: 1995-03-15
// Created by: Robert COUBLANC
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-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 _StdSelect_ViewerSelector3d_HeaderFile
#define _StdSelect_ViewerSelector3d_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Standard_DefineHandle.hxx>
#include <Handle_Graphic3d_Group.hxx>
#include <Handle_Graphic3d_Structure.hxx>
#include <Graphic3d_SequenceOfHClipPlane.hxx>
#include <SelectMgr_ViewerSelector.hxx>
#include <SelectMgr_Selection.hxx>
#include <Handle_V3d_View.hxx>
#include <Handle_SelectMgr_EntityOwner.hxx>
#include <NCollection_Handle.hxx>
class Graphic3d_Group;
class Graphic3d_Structure;
class V3d_View;
class TColgp_Array1OfPnt2d;
class SelectMgr_EntityOwner;
class SelectMgr_SelectableObjectSet;
//! Selector Usable by Viewers from V3d
class StdSelect_ViewerSelector3d : public SelectMgr_ViewerSelector
{
public:
//! Constructs an empty 3D selector object.
Standard_EXPORT StdSelect_ViewerSelector3d();
//! Sets the pixel tolerance <theTolerance>.
Standard_EXPORT void SetPixelTolerance (const Standard_Real theTolerance);
//! Returns the pixel tolerance.
Standard_Real PixelTolerance() const;
//! Picks the sensitive entity at the pixel coordinates of
//! the mouse <theXPix> and <theYPix>. The selector looks for touched areas and owners.
Standard_EXPORT void Pick (const Standard_Integer theXPix,
const Standard_Integer theYPix,
const Handle(V3d_View)& theView);
//! Picks the sensitive entity according to the minimum
//! and maximum pixel values <theXPMin>, <theYPMin>, <theXPMax>
//! and <theYPMax> defining a 2D area for selection in the 3D view aView.
Standard_EXPORT void Pick (const Standard_Integer theXPMin,
const Standard_Integer theYPMin,
const Standard_Integer theXPMax,
const Standard_Integer theYPMax,
const Handle(V3d_View)& theView);
//! pick action - input pixel values for polyline selection for selection.
Standard_EXPORT void Pick (const TColgp_Array1OfPnt2d& thePolyline,
const Handle(V3d_View)& theView);
//! Displays sensitives in view <theView>.
Standard_EXPORT void DisplaySensitive (const Handle(V3d_View)& theView);
Standard_EXPORT void ClearSensitive (const Handle(V3d_View)& theView);
Standard_EXPORT void DisplaySensitive (const Handle(SelectMgr_Selection)& theSel,
const gp_Trsf& theTrsf,
const Handle(V3d_View)& theView,
const Standard_Boolean theToClearOthers = Standard_True);
//! Marks all sensitive entities, stored in viewer selector, as inactive for selection
Standard_EXPORT void ResetSelectionActivationStatus();
Standard_EXPORT virtual Standard_Boolean HasDepthClipping (const Handle(SelectMgr_EntityOwner)& theOwner) const Standard_OVERRIDE;
DEFINE_STANDARD_RTTI(StdSelect_ViewerSelector3d)
protected:
//! Set view clipping for the selector.
//! @param thePlanes [in] the view planes.
Standard_EXPORT void SetClipping (const Graphic3d_SequenceOfHClipPlane& thePlanes);
private:
void ComputeSensitivePrs (const Handle(SelectMgr_Selection)& theSel, const gp_Trsf& theLoc);
Handle_Graphic3d_Group myareagroup;
Handle_Graphic3d_Group mysensgroup;
Handle_Graphic3d_Structure mystruct;
Graphic3d_SequenceOfHClipPlane myClipPlanes;
};
DEFINE_STANDARD_HANDLE(StdSelect_ViewerSelector3d, SelectMgr_ViewerSelector)
#include <StdSelect_ViewerSelector3d.lxx>
#endif

View File

@@ -12,17 +12,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
inline StdSelect_SensitivityMode StdSelect_ViewerSelector3d::SensitivityMode() const
inline Standard_Real StdSelect_ViewerSelector3d::PixelTolerance() const
{
return mySensMode;
}
inline Standard_Integer StdSelect_ViewerSelector3d::PixelTolerance() const
{
return myPixelTolerance;
}
inline const Handle(Select3D_Projector)& StdSelect_ViewerSelector3d::Projector() const
{
return myProjector;
return mytolerance;
}