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

0012121: Optimization of existing selection classes

This commit is contained in:
SAN, AAA 2011-12-29 12:48:06 +00:00 committed by bugmaster
parent dfc06d1f07
commit ac04d1012c
27 changed files with 1325 additions and 629 deletions

View File

@ -15,7 +15,13 @@
-- selection or graphic structure. These are deduced -- selection or graphic structure. These are deduced
-- from your reference object. -- from your reference object.
-- The relation between the connected interactive object -- The relation between the connected interactive object
-- and its source is generally one of geometric transformation. -- and its source is generally one of geometric transformation.
-- AIS_ConnectedInteractive class doesn't support selection
-- modes different from 0. Descendants should redefine ComputeSelection()
-- method in order to handle other selection modes and generate connected
-- sensitive entities properly. Refer to AIS_ConnectedShape class
-- for exisiting implementation of a connected interactive object
-- for AIS_Shape that supports all standard sub-shape selection modes.
-- Warning -- Warning
-- An Interactive entity which is view (or projector) -- An Interactive entity which is view (or projector)
-- dependent requires recalculation of views in hidden -- dependent requires recalculation of views in hidden
@ -140,14 +146,9 @@ is
ComputeSelection(me:mutable; aSelection :mutable Selection from SelectMgr; ComputeSelection(me:mutable; aSelection :mutable Selection from SelectMgr;
aMode : Integer) is redefined virtual private; aMode : Integer) is redefined virtual private;
---Level: Public ---Level: Public
---Purpose: Recovers and calculates any sensitive primitive, ---Purpose: Generates sensitive entities by copying
-- aSelection, available in Shape mode, specified by -- them from myReference selection, creates and sets an entity
-- aMode. As a rule, these are sensitive faces. -- owner for this entities and adds them to aSelection
-- This method is defined as virtual. This enables you to
-- implement it in the creation of a new class of
-- Interactive Object. You need to do this and in so
-- doing, redefine this method, if you create a class
-- which enriches the list of signatures and types.
AcceptShapeDecomposition(me) returns Boolean from Standard is AcceptShapeDecomposition(me) returns Boolean from Standard is
redefined virtual; redefined virtual;

View File

@ -137,39 +137,39 @@ void AIS_ConnectedInteractive::Compute(const Handle_PrsMgr_PresentationManager2d
//function : ComputeSelection //function : ComputeSelection
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_ConnectedInteractive::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
const Standard_Integer aMode) void AIS_ConnectedInteractive::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
const Standard_Integer aMode)
{ {
if(!(HasLocation() ||HasConnection())) return; if(!(HasLocation() ||HasConnection())) return;
aSel->Clear(); aSel->Clear();
if(!myReference->HasSelection(aMode)) if(!myReference->HasSelection(aMode))
myReference->UpdateSelection(aMode); myReference->UpdateSelection(aMode);
// static OSD_Timer KronSel;
// cout<<"debut calcul connexion primitives pour le mode "<<aMode<<endl;
// KronSel.Reset();
// KronSel.Start();
const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection(aMode); const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection(aMode);
Handle(SelectMgr_EntityOwner) OWN = new SelectMgr_EntityOwner(this); Handle(SelectMgr_EntityOwner) OWN = new SelectMgr_EntityOwner(this);
Handle(Select3D_SensitiveEntity) SE3D,SNew; Handle(Select3D_SensitiveEntity) SE3D, SNew;
if(TheRefSel->IsEmpty()) if(TheRefSel->IsEmpty())
myReference->UpdateSelection(aMode); myReference->UpdateSelection(aMode);
for(TheRefSel->Init();TheRefSel->More();TheRefSel->Next()){ for(TheRefSel->Init();TheRefSel->More();TheRefSel->Next())
SE3D = *((Handle(Select3D_SensitiveEntity)*) &(TheRefSel->Sensitive())); {
if(!SE3D.IsNull()){ SE3D = Handle(Select3D_SensitiveEntity)::DownCast(TheRefSel->Sensitive());
if(!SE3D.IsNull())
{
// Get the copy of SE3D
SNew = SE3D->GetConnected(myLocation); SNew = SE3D->GetConnected(myLocation);
if(aMode==0) if(aMode==0)
SNew->Set(OWN); {
SNew->Set(OWN);
// In case if SE3D caches some location-dependent data
// that must be updated after setting OWN
SNew->SetLocation(myLocation);
}
aSel->Add(SNew); aSel->Add(SNew);
} }
} }
// KronSel.Stop();
// cout<<"fin calcul connexion primitives pour le mode "<<aMode<<endl;
// KronSel.Show();
} }
void AIS_ConnectedInteractive::UpdateLocation() void AIS_ConnectedInteractive::UpdateLocation()

View File

@ -98,45 +98,24 @@ is
aPresentation : mutable Presentation from Prs3d) aPresentation : mutable Presentation from Prs3d)
is redefined virtual private; is redefined virtual private;
Compute(me : mutable;
aPresentationManager : PresentationManager3d from PrsMgr;
aPresentation : mutable Presentation from Prs3d;
aMode : Integer from Standard = 0)
---Level: Public
---Purpose: this method is redefined virtual;
-- when the instance is connected to another
-- InteractiveObject,this method doesn't
-- compute anything, but just uses the
-- presentation of this last object, with
-- a transformation if there's one stored.
is redefined;
ComputeSelection(me:mutable; aSelection :mutable Selection from SelectMgr;
aMode : Integer from Standard)
is redefined virtual private;
---Purpose:
-- Recovers and calculates any sensitive primitive,
-- aSelection, available in Shape mode, specified by
-- aMode . As a rule, these are sensitive faces.
-- This method is defined as virtual. This enables you to
-- implement it in the creation of a new class of
-- Interactive Object. You need to do this and in so
-- doing, redefine this method, if you create a class
-- which enriches the list of signatures and types.
Compute(me:mutable; Compute(me:mutable;
aPresentationManager: PresentationManager2d from PrsMgr; aPresentationManager: PresentationManager2d from PrsMgr;
aPresentation: mutable GraphicObject from Graphic2d; aPresentation: mutable GraphicObject from Graphic2d;
aMode: Integer from Standard = 0) aMode: Integer from Standard = 0)
raises NotImplemented from Standard
is redefined;
---Level: Internal ---Level: Internal
---Purpose: this method should fill the presentation according to the ---Purpose: this method should fill the presentation according to the
-- enumerated mode of the application and to the display parameter -- enumerated mode of the application and to the display parameter
-- of the application. -- of the application.
raises NotImplemented from Standard ComputeSelection(me:mutable; aSelection :mutable Selection from SelectMgr;
is redefined; aMode : Integer from Standard)
is redefined virtual private;
---Purpose: Generates sensitive entities by copying
-- them from myReferense selection specified by aMode,
-- creates and sets an entity owner for this entities and adds
-- them to aSelection.
Shape(me:mutable) returns Shape from TopoDS; Shape(me:mutable) returns Shape from TopoDS;
---C++: return const& ---C++: return const&

View File

@ -27,6 +27,8 @@
#include <SelectBasics_EntityOwner.hxx> #include <SelectBasics_EntityOwner.hxx>
#include <AIS_MultipleConnectedShape.hxx> #include <AIS_MultipleConnectedShape.hxx>
#include <Precision.hxx> #include <Precision.hxx>
#include <NCollection_DataMap.hxx>
#include <NCollection_List.hxx>
//======================================================================= //=======================================================================
//function : AIS_ConnectedShape //function : AIS_ConnectedShape
@ -159,27 +161,22 @@ void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPre
AIS_ConnectedInteractive::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ; AIS_ConnectedInteractive::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
} }
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& /*aPresentationManager3d*/,
const Handle_Prs3d_Presentation& /*aPresentation*/,
const int /*anInteger*/)
{
Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d&, const Handle_Prs3d_Presentation&, const int)");
// AIS_ConnectedInteractive::Compute( aPresentationManager3d ,aPresentation,anInteger) ; not accessible
}
//======================================================================= //=======================================================================
//function : ComputeSelection //function : ComputeSelection
//purpose : Attention fragile... //purpose : Attention fragile...
//======================================================================= //=======================================================================
static Standard_Boolean IsEqual( const TopoDS_Shape& theLeft,
void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, const TopoDS_Shape& theRight )
const Standard_Integer aMode)
{ {
return theLeft.IsEqual(theRight);
}
void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
typedef NCollection_List<Handle(Select3D_SensitiveEntity)> SensitiveList;
typedef NCollection_DataMap<TopoDS_Shape, SensitiveList > Shapes2EntitiesMap;
UpdateShape(); UpdateShape();
aSelection->Clear(); aSelection->Clear();
// It is checked if there is nothing to do with the reference // It is checked if there is nothing to do with the reference
@ -187,79 +184,76 @@ void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aS
if(!myReference->HasSelection(aMode)) if(!myReference->HasSelection(aMode))
myReference->UpdateSelection(aMode); myReference->UpdateSelection(aMode);
const Handle(SelectMgr_Selection)& RefSel = myReference->Selection(aMode); const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection(aMode);
if(RefSel->IsEmpty()) if(aRefSel->IsEmpty())
myReference->UpdateSelection(aMode);
if(RefSel->UpdateStatus()==SelectMgr_TOU_Full)
myReference->UpdateSelection(aMode); myReference->UpdateSelection(aMode);
// depending on the type of decomposition, connected primitives are subtracted if(aRefSel->UpdateStatus()==SelectMgr_TOU_Full)
// it is necessary to follow the order of creation of StdSelect_BRepSelectionTool... myReference->UpdateSelection(aMode);
TopAbs_ShapeEnum TheType = AIS_Shape::SelectionType(aMode); Handle(StdSelect_BRepOwner) anOwner;
Handle(StdSelect_BRepOwner) OWNR; TopLoc_Location aBidLoc;
Handle(Select3D_SensitiveEntity) SE,NiouSE; Handle(Select3D_SensitiveEntity) aSE, aNewSE;
TopLoc_Location BidLoc; Shapes2EntitiesMap aShapes2EntitiesMap;
SensitiveList aSEList;
TopoDS_Shape aSubShape;
switch(TheType){ // Fill in the map of subshapes and corresponding
case TopAbs_VERTEX: // sensitive entities associated with aMode
case TopAbs_EDGE: for(aRefSel->Init(); aRefSel->More(); aRefSel->Next())
case TopAbs_WIRE: {
case TopAbs_FACE: aSE = Handle(Select3D_SensitiveEntity)::DownCast(aRefSel->Sensitive());
case TopAbs_SHELL: if(!aSE.IsNull())
{ {
TopTools_IndexedMapOfShape subshaps; anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSE->OwnerId());
TopExp::MapShapes(myOwnSh,TheType,subshaps); if(!anOwner.IsNull())
{
RefSel->Init(); aSubShape = anOwner->Shape();
for(Standard_Integer I=1; if(!aShapes2EntitiesMap.IsBound(aSubShape))
I<=subshaps.Extent()&& RefSel->More(); {
RefSel->Next(),I++){ aShapes2EntitiesMap.Bind(aSubShape, aSEList);
}
SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive())); aShapes2EntitiesMap(aSubShape).Append(aSE);
if(!SE.IsNull()){
OWNR = new StdSelect_BRepOwner(subshaps(I),this,SE->OwnerId()->Priority());
if(myLocation.IsIdentity())
NiouSE = SE->GetConnected(BidLoc);
else
NiouSE = SE->GetConnected(myLocation);
NiouSE->Set(OWNR);
aSelection->Add(NiouSE);
}
} }
break;
}
case TopAbs_SHAPE:
default:
{
// In case if there is only one owner of the set of
// sensible primitives...
OWNR = new StdSelect_BRepOwner(myOwnSh,this);
Standard_Boolean FirstIncr(Standard_True);
for(RefSel->Init();RefSel->More();RefSel->Next()){
SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
if(FirstIncr){
Standard_Integer Prior = SE->OwnerId()->Priority();
Handle(SelectBasics_EntityOwner)::DownCast(OWNR)->Set(Prior);
FirstIncr = Standard_False;}
if(myLocation.IsIdentity())
NiouSE = SE->GetConnected(BidLoc);
else
NiouSE = SE->GetConnected(myLocation);
NiouSE->Set(OWNR);
aSelection->Add(NiouSE);
}
break;
} }
} }
StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
// Fill in selection from aShapes2EntitiesMap
Shapes2EntitiesMap::Iterator aMapIt(aShapes2EntitiesMap);
for(; aMapIt.More(); aMapIt.Next())
{
aSEList = aMapIt.Value();
anOwner = new StdSelect_BRepOwner(aMapIt.Key(),
this,
aSEList.First()->OwnerId()->Priority(),
Standard_True);
SensitiveList::Iterator aListIt(aSEList);
for(; aListIt.More(); aListIt.Next())
{
aSE = aListIt.Value();
if(myLocation.IsIdentity())
{
aNewSE = aSE->GetConnected(aBidLoc);
aNewSE->Set(anOwner);
// In case if aSE caches some location-dependent data
// that must be updated after setting anOwner
aNewSE->SetLocation(aBidLoc);
}
else
{
aNewSE = aSE->GetConnected(myLocation);
aNewSE->Set(anOwner);
// In case if aSE caches some location-dependent data
// that must be updated after setting anOwner
aNewSE->SetLocation(myLocation);
}
aSelection->Add(aNewSE);
}
}
StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
} }
//======================================================================= //=======================================================================
//function : Shape //function : Shape

View File

@ -899,7 +899,7 @@ call_togl_draw_structure
/*ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ /*ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
default: { default: {
key.id = openglWsId; key.id = openglWsId;
TsmSendMessage (telem, DisplayTraverse, node->elem.data, 0, &key); TsmSendMessage (telem, DisplayTraverse, node->elem.data, 1, &key);
} }
} }
} }

View File

@ -20,11 +20,10 @@
//================================================== //==================================================
Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Bnd_Box& BBox): const Bnd_Box& BBox):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
mybox3d(BBox){} mybox3d(BBox){}
//================================================== //==================================================
// Function: Constructor // Function: Constructor
// Purpose : // Purpose :
@ -32,28 +31,29 @@ mybox3d(BBox){}
Select3D_SensitiveBox:: Select3D_SensitiveBox::
Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Real XMin, const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real ZMin, const Standard_Real ZMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real ZMax): const Standard_Real ZMax):
Select3D_SensitiveEntity(OwnerId) Select3D_SensitiveEntity(OwnerId)
{ {
mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax); mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
} }
//================================================== //==================================================
// Function: Project // Function: Project
// Purpose : // Purpose :
//================================================== //==================================================
void Select3D_SensitiveBox:: void Select3D_SensitiveBox::
Project(const Handle(Select3D_Projector)& aProj) Project(const Handle(Select3D_Projector)& aProj)
{ {
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj... Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
if(HasLocation()){ if(HasLocation())
{
Bnd_Box B = mybox3d.Transformed(Location().Transformation()); Bnd_Box B = mybox3d.Transformed(Location().Transformation());
ProjectBox(aProj,B); ProjectBox(aProj,B);
} }
@ -62,14 +62,14 @@ Project(const Handle(Select3D_Projector)& aProj)
} }
//================================================== //==================================================
// Function: // Function: Areas
// Purpose : // Purpose :
//================================================== //==================================================
void Select3D_SensitiveBox:: void Select3D_SensitiveBox::
Areas(SelectBasics_ListOfBox2d& aSeq) Areas(SelectBasics_ListOfBox2d& aSeq)
{ aSeq.Append(mybox2d);} { aSeq.Append(mybox2d);}
//======================================================================= //=======================================================================
//function : GetConnected //function : GetConnected
//purpose : //purpose :
@ -84,43 +84,39 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLo
return NiouEnt; return NiouEnt;
} }
//================================================== //==================================================
// Function: // Function: Matches
// Purpose : // Purpose :
//================================================== //==================================================
Standard_Boolean Select3D_SensitiveBox:: Standard_Boolean Select3D_SensitiveBox::
Matches(const Standard_Real X, Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin); Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
DMin=0.; DMin=0.;
return Standard_True; return Standard_True;
} }
//================================================== //==================================================
// Function: // Function: Matches
// Purpose : // Purpose :
//================================================== //==================================================
Standard_Boolean Select3D_SensitiveBox:: Standard_Boolean Select3D_SensitiveBox::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Bnd_Box2d BoundBox; Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
return(!BoundBox.IsOut(mybox2d)); return(!BoundBox.IsOut(mybox2d));
} }
//======================================================================= //=======================================================================
//function : Matches //function : Matches
//purpose : //purpose :
@ -128,13 +124,12 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveBox:: Standard_Boolean Select3D_SensitiveBox::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
return(!aBox.IsOut(mybox2d)); return(!aBox.IsOut(mybox2d));
} }
//======================================================================= //=======================================================================
//function : Dump //function : Dump
//purpose : //purpose :
@ -152,10 +147,11 @@ void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean Full
S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]"; S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl; S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
if(FullDump){ if(FullDump)
{
// S<<"\t\t\tOwner:"<<myOwnerId<<endl; // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);} Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
} }
@ -165,7 +161,7 @@ void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean Full
//======================================================================= //=======================================================================
void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj, void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj,
const Bnd_Box& aBox) const Bnd_Box& aBox)
{ {
mybox2d.SetVoid(); mybox2d.SetVoid();
gp_Pnt2d curp2d; gp_Pnt2d curp2d;

View File

@ -25,7 +25,9 @@ uses
Location from TopLoc, Location from TopLoc,
Pnt from Select3D, Pnt from Select3D,
Pnt2d from Select3D, Pnt2d from Select3D,
Projector from Select3D Projector from Select3D,
SensitiveEntity from Select3D,
Circle from Geom
is is
Create (OwnerId : EntityOwner from SelectBasics; Create (OwnerId : EntityOwner from SelectBasics;
@ -68,7 +70,7 @@ is
FilledCircle : Boolean from Standard = Standard_False) FilledCircle : Boolean from Standard = Standard_False)
returns mutable SensitiveCircle; returns mutable SensitiveCircle;
---Purpose: Constructs the sensitive circle object defined by the ---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the array of points apolyg3d, and the Boolean FilledCircle. -- owner OwnerId, the array of points apolyg3d, and the Boolean FilledCircle.
-- If the length of apolyg3d is more then 1, the first point of apolyg3d -- If the length of apolyg3d is more then 1, the first point of apolyg3d
-- must be equal to the last point of apolyg3d. -- must be equal to the last point of apolyg3d.
@ -102,7 +104,13 @@ is
GetPoint3d(me;rank:Integer) returns Pnt from gp; GetPoint3d(me;rank:Integer) returns Pnt from gp;
---Level: Internal ---Level: Internal
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual; Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
GetConnected(me: mutable; theLocation : Location from TopLoc)
returns SensitiveEntity from Select3D
is redefined virtual;
---Level: Public
---Purpose: Returns the copy of this.
Project(me: mutable;aProjector: Projector from Select3D) is redefined virtual; Project(me: mutable;aProjector: Projector from Select3D) is redefined virtual;
@ -116,6 +124,9 @@ fields
myDetectedIndex : Integer from Standard; -- used for depth... myDetectedIndex : Integer from Standard; -- used for depth...
myCenter2D : Pnt2d from Select3D; -- used for Matches() myCenter2D : Pnt2d from Select3D; -- used for Matches()
myCenter3D : Pnt from Select3D; -- used for Matches() myCenter3D : Pnt from Select3D; -- used for Matches()
myCircle : Circle from Geom;
mystart : Real from Standard; -- used for GetConnected()
myend : Real from Standard; -- used for GetConnected()
end SensitiveCircle; end SensitiveCircle;

View File

@ -15,10 +15,7 @@
#include <Select3D_Pnt2d.hxx> #include <Select3D_Pnt2d.hxx>
#include <Select3D_Projector.hxx> #include <Select3D_Projector.hxx>
//=======================================================================
//function : Select3D_SensitiveCircle (constructeur)
//purpose : Definition of a sensitive circle
//=======================================================================
static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C, static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber) const Standard_Integer anInputNumber)
{ {
@ -26,6 +23,7 @@ static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C,
return 2*anInputNumber+1; return 2*anInputNumber+1;
return 1; return 1;
} }
static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C, static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber) const Standard_Integer anInputNumber)
{ {
@ -33,19 +31,28 @@ static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
return 2*anInputNumber-1; return 2*anInputNumber-1;
return 1; return 1;
} }
//=======================================================================
//function : Select3D_SensitiveCircle (constructor)
//purpose : Definition of a sensitive circle
//=======================================================================
Select3D_SensitiveCircle:: Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Circle)& TheCircle, const Handle(Geom_Circle)& TheCircle,
const Standard_Boolean FilledCircle, const Standard_Boolean FilledCircle,
const Standard_Integer NbPoints): const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)), Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle), myFillStatus(FilledCircle),
myDetectedIndex(-1) myDetectedIndex(-1),
myCircle(TheCircle),
mystart(0),
myend(0)
{ {
if(mynbpoints!=1){ if(mynbpoints!=1)
gp_Pnt p1,p2;//,pmid; {
gp_Vec v1;//,v2; gp_Pnt p1,p2;
gp_Vec v1;
Standard_Real ustart = TheCircle->FirstParameter(),uend = TheCircle->LastParameter(); Standard_Real ustart = TheCircle->FirstParameter(),uend = TheCircle->LastParameter();
Standard_Real du = (uend-ustart)/NbPoints; Standard_Real du = (uend-ustart)/NbPoints;
Standard_Real R = TheCircle->Radius(); Standard_Real R = TheCircle->Radius();
@ -76,40 +83,42 @@ myDetectedIndex(-1)
// Get myCenter3D // Get myCenter3D
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0]; myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
} }
} }
//======================================================================= //=======================================================================
//function : Select3D_SensitiveCircle (constructeur) //function : Select3D_SensitiveCircle (constructor)
//purpose : Definition of a sensitive arc //purpose : Definition of a sensitive arc
//======================================================================= //=======================================================================
Select3D_SensitiveCircle:: Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Circle)& TheCircle, const Handle(Geom_Circle)& TheCircle,
const Standard_Real u1, const Standard_Real u1,
const Standard_Real u2, const Standard_Real u2,
const Standard_Boolean FilledCircle, const Standard_Boolean FilledCircle,
const Standard_Integer NbPoints): const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)), Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle), myFillStatus(FilledCircle),
myDetectedIndex(-1) myDetectedIndex(-1),
myCircle(TheCircle),
mystart(u1),
myend(u2)
{ {
if(mynbpoints > 1)
if(mynbpoints > 1){ {
gp_Pnt p1,p2;//,pmid; gp_Pnt p1,p2;
gp_Vec v1;//,v2; gp_Vec v1;
Standard_Real ustart = u1; if (u1 > u2)
Standard_Real uend = u2; {
mystart = u2;
myend = u1;
}
if (u1 > u2) {ustart=u1;uend=u2;} Standard_Real du = (myend-mystart)/(NbPoints-1);
Standard_Real du = (uend-ustart)/(NbPoints-1);
Standard_Real R = TheCircle->Radius(); Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1; Standard_Integer rank = 1;
Standard_Real curu =ustart; Standard_Real curu = mystart;
for(Standard_Integer i=1;i<=NbPoints-1;i++) for(Standard_Integer i=1;i<=NbPoints-1;i++)
{ {
@ -124,7 +133,7 @@ myDetectedIndex(-1)
rank++; rank++;
curu+=du; curu+=du;
} }
TheCircle->D0(uend,p1); TheCircle->D0(myend,p1);
((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1; ((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1;
// Get myCenter3D // Get myCenter3D
myCenter3D = TheCircle->Location(); myCenter3D = TheCircle->Location();
@ -141,12 +150,15 @@ myDetectedIndex(-1)
//function : Select3D_SensitiveCircle //function : Select3D_SensitiveCircle
//purpose : //purpose :
//======================================================================= //=======================================================================
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& Thepolyg3d, const Handle(TColgp_HArray1OfPnt)& Thepolyg3d,
const Standard_Boolean FilledCircle): const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d), Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle), myFillStatus(FilledCircle),
myDetectedIndex(-1) myDetectedIndex(-1),
mystart(0),
myend(0)
{ {
if (mynbpoints > 1) if (mynbpoints > 1)
ComputeCenter3D(); ComputeCenter3D();
@ -154,12 +166,19 @@ myDetectedIndex(-1)
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0]; myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
} }
//=======================================================================
//function : Select3D_SensitiveCircle
//purpose :
//=======================================================================
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& Thepolyg3d, const TColgp_Array1OfPnt& Thepolyg3d,
const Standard_Boolean FilledCircle): const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d), Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle), myFillStatus(FilledCircle),
myDetectedIndex(-1) myDetectedIndex(-1),
mystart(0),
myend(0)
{ {
if (mynbpoints > 1) if (mynbpoints > 1)
ComputeCenter3D(); ComputeCenter3D();
@ -167,13 +186,17 @@ myDetectedIndex(-1)
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0]; myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
} }
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle:: Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real X, Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
if(mynbpoints>1) if(mynbpoints>1)
{ {
Standard_Boolean Found = Standard_False; Standard_Boolean Found = Standard_False;
@ -229,15 +252,19 @@ Matches(const Standard_Real X,
return Found; return Found;
} }
return Standard_True; return Standard_True;
} }
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle:: Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real XMin, Matches(const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
myDetectedIndex =-1; myDetectedIndex =-1;
Bnd_Box2d abox; Bnd_Box2d abox;
@ -249,7 +276,6 @@ Matches(const Standard_Real XMin,
return Standard_True; return Standard_True;
} }
//======================================================================= //=======================================================================
//function : Matches //function : Matches
//purpose : //purpose :
@ -257,8 +283,8 @@ Matches(const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveCircle:: Standard_Boolean Select3D_SensitiveCircle::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
@ -267,24 +293,31 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7; Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=mynbpoints;j++){ for(Standard_Integer j=1;j<=mynbpoints;j++)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]); Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
if(RES!=1) return Standard_False; if(RES!=1) return Standard_False;
} }
return Standard_True; return Standard_True;
} }
//=======================================================================
//function : ArrayBounds
//purpose :
//=======================================================================
void Select3D_SensitiveCircle:: void Select3D_SensitiveCircle::
ArrayBounds(Standard_Integer & Low, ArrayBounds(Standard_Integer & Low,
Standard_Integer & Up) const Standard_Integer & Up) const
{ {
Low = 0; Low = 0;
Up = mynbpoints-1; Up = mynbpoints-1;
} }
//=======================================================================
//function : GetPoint3d
//purpose :
//=======================================================================
gp_Pnt Select3D_SensitiveCircle:: gp_Pnt Select3D_SensitiveCircle::
GetPoint3d(const Standard_Integer Rank) const GetPoint3d(const Standard_Integer Rank) const
@ -317,9 +350,11 @@ void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean F
S<<"\t\tExisting Location"<<endl; S<<"\t\tExisting Location"<<endl;
if(FullDump){ if(FullDump)
{
Standard_Integer EndIndex = isclosed? mynbpoints-2 : mynbpoints-1, nbpt(0); Standard_Integer EndIndex = isclosed? mynbpoints-2 : mynbpoints-1, nbpt(0);
for(Standard_Integer i=0;i<EndIndex;i+=2){ for(Standard_Integer i=0;i<EndIndex;i+=2)
{
CDG +=((Select3D_Pnt*)mypolyg3d)[i]; CDG +=((Select3D_Pnt*)mypolyg3d)[i];
nbpt++; nbpt++;
} }
@ -333,30 +368,85 @@ void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean F
} }
} }
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveCircle::ComputeDepth(const gp_Lin& EyeLine) const Standard_Real Select3D_SensitiveCircle::ComputeDepth(const gp_Lin& EyeLine) const
{ {
gp_Pnt CDG; gp_Pnt CDG;
if(myDetectedIndex==-1){ if(myDetectedIndex==-1)
{
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[0]); gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[0]);
Standard_Boolean isclosed = 1==mynbpoints; Standard_Boolean isclosed = 1==mynbpoints;
Standard_Integer EndIndex = isclosed ? mynbpoints-2 : mynbpoints-1, nbpt(0); Standard_Integer EndIndex = isclosed ? mynbpoints-2 : mynbpoints-1, nbpt(0);
for(Standard_Integer i=1;i<EndIndex;i+=2){ for(Standard_Integer i=1;i<EndIndex;i+=2)
{
CurCoord +=((Select3D_Pnt*)mypolyg3d)[i]; CurCoord +=((Select3D_Pnt*)mypolyg3d)[i];
nbpt++; nbpt++;
} }
CDG.SetXYZ(CurCoord); CDG.SetXYZ(CurCoord);
} }
else{ else
{
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[myDetectedIndex]); gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[myDetectedIndex]);
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+1]; CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+1];
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+2]; CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+2];
CDG.SetXYZ(CurCoord); CDG.SetXYZ(CurCoord);
} }
return ElCLib::Parameter(EyeLine,CDG); return ElCLib::Parameter(EyeLine,CDG);
} }
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected(const TopLoc_Location& theLocation)
{
// Create a copy of this
Handle(Select3D_SensitiveEntity) aNewEntity;
// this was constructed using Handle(Geom_Circle)
if(!myCircle.IsNull())
{
if((myend-mystart) > Precision::Confusion())
{
// Arc
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, myCircle, mystart, myend, myFillStatus);
}
else
{
// Circle
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, myCircle, myFillStatus);
}
}
// this was constructed using TColgp_Array1OfPnt
else
{
TColgp_Array1OfPnt aPolyg(1, mynbpoints);
for(Standard_Integer i = 1; i <= mynbpoints; ++i)
{
aPolyg.SetValue(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
}
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, aPolyg, myFillStatus);
}
if(HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);
return aNewEntity;
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProjector) void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProjector)
{ {
Select3D_SensitivePoly::Project(aProjector); Select3D_SensitivePoly::Project(aProjector);
@ -366,21 +456,26 @@ void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProject
myCenter2D = aCenter; myCenter2D = aCenter;
} }
//=======================================================================
//function : ComputeCenter3D
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::ComputeCenter3D() void Select3D_SensitiveCircle::ComputeCenter3D()
{ {
gp_XYZ aCenter(0., 0., 0.); gp_XYZ aCenter(0., 0., 0.);
if (mynbpoints > 1) if(mynbpoints > 1)
{ {
// The mass of points system // The mass of points system
Standard_Integer aMass = mynbpoints - 1; Standard_Integer aMass = mynbpoints - 1;
// Find the circle barycenter // Find the circle barycenter
for (Standard_Integer i = 0; i < mynbpoints-1; ++i) for(Standard_Integer i = 0; i < mynbpoints-1; ++i)
{ {
aCenter += ((Select3D_Pnt*)mypolyg3d)[i]; aCenter += ((Select3D_Pnt*)mypolyg3d)[i];
} }
myCenter3D = aCenter / aMass; myCenter3D = aCenter / aMass;
} }
else if (mynbpoints == 1) else if (mynbpoints == 1)
{ {
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0]; myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
} }
@ -388,8 +483,8 @@ void Select3D_SensitiveCircle::ComputeCenter3D()
// It can lead to incorrect computation of // It can lead to incorrect computation of
// parameter DMin in method Matches. // parameter DMin in method Matches.
// In spite of this myCenter3D isn't left uninitialized // In spite of this myCenter3D isn't left uninitialized
else else
{ {
myCenter3D = aCenter; myCenter3D = aCenter;
} }
} }

View File

@ -24,7 +24,8 @@ uses
Array1OfPnt2d from TColgp, Array1OfPnt2d from TColgp,
HArray1OfPnt from TColgp, HArray1OfPnt from TColgp,
Box2d from Bnd, Box2d from Bnd,
Location from TopLoc Location from TopLoc,
SensitiveEntity from Select3D
is is
@ -50,7 +51,7 @@ is
---Level: Public ---Level: Public
---Purpose: Creation of Sensitive Curve from Points. ---Purpose: Creation of Sensitive Curve from Points.
-- Warning : This Method should disappear in the next version... -- Warning : This Method should disappear in the next version...
Matches(me :mutable; Matches(me :mutable;
X,Y : Real from Standard; X,Y : Real from Standard;
aTol: Real from Standard; aTol: Real from Standard;
@ -85,9 +86,16 @@ is
---Category: Internal Methods ---Category: Internal Methods
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual; Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
LoadPoints(me:mutable;aCurve:Curve from Geom;NbPoints: Integer) is static private; LoadPoints(me:mutable;aCurve:Curve from Geom;NbPoints: Integer) is static private;
GetConnected(me: mutable; theLocation : Location from TopLoc)
returns SensitiveEntity from Select3D
is redefined virtual;
---Level: Public
---Purpose: Returns the copy of this
fields fields
mylastseg : Integer from Standard; mylastseg : Integer from Standard;
myCurve : Curve from Geom;
end SensitiveCurve; end SensitiveCurve;

View File

@ -15,39 +15,44 @@
//================================================== //==================================================
// Function: // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitiveCurve Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId, ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Curve)& C, const Handle(Geom_Curve)& C,
const Standard_Integer NbPoints): const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, NbPoints), Select3D_SensitivePoly(OwnerId, NbPoints),
mylastseg(0) mylastseg(0),
myCurve(C)
{ {
LoadPoints(C,NbPoints); LoadPoints(C,NbPoints);
} }
//================================================== //==================================================
// Function: Creation // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitiveCurve Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId, ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints): const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints), Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0) mylastseg(0)
{ {
} }
//================================================== //==================================================
// Function: Creation // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitiveCurve Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId, ::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints): const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints), Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0) mylastseg(0)
{ {
} }
@ -55,11 +60,12 @@ mylastseg(0)
// Function: Matches // Function: Matches
// Purpose : // Purpose :
//================================================== //==================================================
Standard_Boolean Select3D_SensitiveCurve Standard_Boolean Select3D_SensitiveCurve
::Matches(const Standard_Real X, ::Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
Standard_Integer Rank; Standard_Integer Rank;
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints); TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
@ -73,11 +79,10 @@ Standard_Boolean Select3D_SensitiveCurve
mylastseg = Rank; mylastseg = Rank;
// compute and validate the depth (::Depth()) along the eyeline // compute and validate the depth (::Depth()) along the eyeline
return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin);
} }
return Standard_False; return Standard_False;
} }
//================================================== //==================================================
// Function: Matches // Function: Matches
// Purpose : know if a box touches the projected polygon // Purpose : know if a box touches the projected polygon
@ -86,11 +91,11 @@ Standard_Boolean Select3D_SensitiveCurve
Standard_Boolean Select3D_SensitiveCurve:: Standard_Boolean Select3D_SensitiveCurve::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Bnd_Box2d BoundBox; Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
@ -108,9 +113,9 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveCurve:: Standard_Boolean Select3D_SensitiveCurve::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv; Standard_Real Tolu,Tolv;
@ -118,17 +123,16 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7; Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=0;j<mynbpoints;j++){ for(Standard_Integer j=0;j<mynbpoints;j++)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]); Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]);
if(RES!=1) return Standard_False; if(RES!=1) return Standard_False;
} }
return Standard_True; return Standard_True;
} }
//================================================== //==================================================
// Function: // Function: LoadPoints
// Purpose : // Purpose :
//================================================== //==================================================
@ -160,11 +164,13 @@ void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean Fu
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl; S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
if(FullDump){ if(FullDump)
{
// S<<"\t\t\tOwner:"<<myOwnerId<<endl; // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d); Select3D_SensitiveEntity::DumpBox(S,mybox2d);
} }
} }
//======================================================================= //=======================================================================
//function : ComputeDepth //function : ComputeDepth
//purpose : //purpose :
@ -172,10 +178,43 @@ void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean Fu
Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
{ {
if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement... if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement...
gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]); gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]);
TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1]; TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1];
TheCDG/=2.; TheCDG/=2.;
return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG)); return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG));
} }
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCurve::GetConnected(const TopLoc_Location &theLocation)
{
// Create a copy of this
Handle(Select3D_SensitiveEntity) aNewEntity;
// this was constructed using Handle(Geom_Curve)
if (!myCurve.IsNull())
{
aNewEntity = new Select3D_SensitiveCurve(myOwnerId, myCurve);
}
// this was constructed using TColgp_HArray1OfPnt
else
{
Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, mynbpoints);
// Fill the array with points from mypolyg3d
for (Standard_Integer i = 1; i <= mynbpoints; ++i)
{
aPoints->SetValue(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
}
aNewEntity = new Select3D_SensitiveCurve(myOwnerId, aPoints);
}
if (HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);
return aNewEntity;
}

View File

@ -62,7 +62,12 @@ is
GetConnected(me:mutable;aLocation: Location from TopLoc) GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is virtual; returns SensitiveEntity from Select3D is virtual;
---Purpose: Returns the sensitive entity found at the location aLocation. ---Purpose: Originally this method intended to return sensitive
-- entity with new location aLocation, but currently sensitive
-- entities do not hold a location, instead HasLocation() and
-- Location() methods call corresponding entity owner's methods.
-- Thus all entities returned by GetConnected() share the same
-- location propagated from corresponding selectable object.
-- You must redefine this function for any type of -- You must redefine this function for any type of
-- sensitive entity which can accept another connected -- sensitive entity which can accept another connected
-- sensitive entity.//can be connected to another sensitive entity. -- sensitive entity.//can be connected to another sensitive entity.

View File

@ -39,9 +39,9 @@ void Select3D_SensitiveEntity::Project(const Handle(Select3D_Projector)& aPrj)
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real X, Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
if (!mylastprj.IsNull()) if (!mylastprj.IsNull())
{ {
@ -62,10 +62,10 @@ Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real X,
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real XMin, Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
return Standard_False; return Standard_False;
} }
@ -76,8 +76,8 @@ Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real XMin,
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const TColgp_Array1OfPnt2d& aPoly, Standard_Boolean Select3D_SensitiveEntity::Matches(const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
return Standard_False; return Standard_False;
} }
@ -99,13 +99,13 @@ void Select3D_SensitiveEntity::Dump(Standard_OStream& S,const Standard_Boolean F
void Select3D_SensitiveEntity::DumpBox(Standard_OStream& S,const Bnd_Box2d& b2d) void Select3D_SensitiveEntity::DumpBox(Standard_OStream& S,const Bnd_Box2d& b2d)
{ {
if(!b2d.IsVoid()){ if(!b2d.IsVoid())
{
Standard_Real xmin,ymin,xmax,ymax; Standard_Real xmin,ymin,xmax,ymax;
b2d.Get(xmin,ymin,xmax,ymax); b2d.Get(xmin,ymin,xmax,ymax);
S<<"\t\t\tBox2d: PMIN ["<<xmin<<" , "<<ymin<<"]"<<endl; S<<"\t\t\tBox2d: PMIN ["<<xmin<<" , "<<ymin<<"]"<<endl;
S<<"\t\t\t PMAX ["<<xmax<<" , "<<ymax<<"]"<<endl; S<<"\t\t\t PMAX ["<<xmax<<" , "<<ymax<<"]"<<endl;
} }
} }
//======================================================================= //=======================================================================
@ -136,9 +136,11 @@ void Select3D_SensitiveEntity::UpdateLocation(const TopLoc_Location& aLoc)
if(aLoc.IsIdentity() || aLoc == Location()) return; if(aLoc.IsIdentity() || aLoc == Location()) return;
if(!HasLocation()) if(!HasLocation())
SetLocation(aLoc); SetLocation(aLoc);
else { else
{
TopLoc_Location compLoc = aLoc * Location(); TopLoc_Location compLoc = aLoc * Location();
SetLocation(compLoc);} SetLocation(compLoc);
}
} }
//======================================================================= //=======================================================================
@ -186,7 +188,7 @@ Standard_Real Select3D_SensitiveEntity::Depth() const
//======================================================================= //=======================================================================
gp_Lin Select3D_SensitiveEntity::GetEyeLine(const Standard_Real X, gp_Lin Select3D_SensitiveEntity::GetEyeLine(const Standard_Real X,
const Standard_Real Y) const const Standard_Real Y) const
{ {
gp_Lin L; gp_Lin L;
if (!mylastprj.IsNull()) if (!mylastprj.IsNull())
@ -225,7 +227,7 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveEntity::GetConnected(const To
} }
//======================================================================= //=======================================================================
//function : GetConnected //function : SetLastDepth
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveEntity::SetLastDepth(const Standard_Real aDepth) void Select3D_SensitiveEntity::SetLastDepth(const Standard_Real aDepth)

View File

@ -20,7 +20,8 @@ uses
Array1OfPnt2d from TColgp, Array1OfPnt2d from TColgp,
Box2d from Bnd, Box2d from Bnd,
TypeOfSensitivity from Select3D, TypeOfSensitivity from Select3D,
Location from TopLoc Location from TopLoc,
SensitiveEntity from Select3D
is is
@ -43,7 +44,7 @@ is
-- owner OwnerId, the array of points ThePoints, and -- owner OwnerId, the array of points ThePoints, and
-- the sensitivity type Sensitivity. -- the sensitivity type Sensitivity.
-- The array of points is the outer polygon of the geometric face. -- The array of points is the outer polygon of the geometric face.
Matches(me :mutable; Matches(me :mutable;
X,Y : Real from Standard; X,Y : Real from Standard;
aTol: Real from Standard; aTol: Real from Standard;
@ -76,7 +77,13 @@ is
-- in some particular case, a custom sensitive face class can be implemented at application level -- in some particular case, a custom sensitive face class can be implemented at application level
-- that overrides default ComputeDepth() behavior. -- that overrides default ComputeDepth() behavior.
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual; Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
GetConnected(me: mutable; theLocation : Location from TopLoc)
returns SensitiveEntity from Select3D
is redefined virtual;
---Level: Public
---Purpose: Returns the copy of this
fields fields

View File

@ -36,8 +36,8 @@
Select3D_SensitiveFace:: Select3D_SensitiveFace::
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints, const TColgp_Array1OfPnt& ThePoints,
const Select3D_TypeOfSensitivity aType): const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId, ThePoints), Select3D_SensitivePoly(OwnerId, ThePoints),
mytype (aType), mytype (aType),
myDetectedIndex(-1) myDetectedIndex(-1)
@ -46,14 +46,14 @@ myDetectedIndex(-1)
} }
//================================================== //==================================================
// Function: // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitiveFace:: Select3D_SensitiveFace::
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints, const Handle(TColgp_HArray1OfPnt)& ThePoints,
const Select3D_TypeOfSensitivity aType): const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId, ThePoints), Select3D_SensitivePoly(OwnerId, ThePoints),
mytype (aType), mytype (aType),
myDetectedIndex(-1) myDetectedIndex(-1)
@ -62,15 +62,15 @@ myDetectedIndex(-1)
} }
//================================================== //==================================================
// Function: // Function: Matches
// Purpose : // Purpose :
//================================================== //==================================================
Standard_Boolean Select3D_SensitiveFace:: Standard_Boolean Select3D_SensitiveFace::
Matches(const Standard_Real X, Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
#ifndef DEB #ifndef DEB
Standard_Real DMin2 = 0.; Standard_Real DMin2 = 0.;
@ -78,7 +78,8 @@ Matches(const Standard_Real X,
Standard_Real DMin2; Standard_Real DMin2;
#endif #endif
Standard_Real Xmin,Ymin,Xmax,Ymax; Standard_Real Xmin,Ymin,Xmax,Ymax;
if(!Bnd_Box2d(mybox2d).IsVoid()){ if(!Bnd_Box2d(mybox2d).IsVoid())
{
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax); Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus(); DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus();
} }
@ -90,20 +91,22 @@ Matches(const Standard_Real X,
gp_XY CDG(0.,0.); gp_XY CDG(0.,0.);
// for(Standard_Integer I=1;I<=Nbp-1;I++){ // for(Standard_Integer I=1;I<=Nbp-1;I++){
Standard_Integer I; Standard_Integer I;
for(I=1;I<mynbpoints-1;I++){ for(I=1;I<mynbpoints-1;I++)
{
CDG+=((Select3D_Pnt2d*)mypolyg2d)[I-1]; CDG+=((Select3D_Pnt2d*)mypolyg2d)[I-1];
} }
if(mynbpoints>1){ if(mynbpoints>1)
{
CDG/= (mynbpoints-1); CDG/= (mynbpoints-1);
} }
DMin2=Min(DMin2,gp_XY(CDG.X()-X,CDG.Y()-Y).SquareModulus()); DMin2=Min(DMin2,gp_XY(CDG.X()-X,CDG.Y()-Y).SquareModulus());
DMin = Sqrt(DMin2); DMin = Sqrt(DMin2);
Standard_Boolean isplane2d(Standard_True); Standard_Boolean isplane2d(Standard_True);
for( I=1;I<mynbpoints-1;I++){ for( I=1;I<mynbpoints-1;I++)
{
gp_XY V1(((Select3D_Pnt2d*)mypolyg2d)[I]),V(X,Y); gp_XY V1(((Select3D_Pnt2d*)mypolyg2d)[I]),V(X,Y);
V1-=((Select3D_Pnt2d*)mypolyg2d)[I-1]; V1-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
V-=((Select3D_Pnt2d*)mypolyg2d)[I-1]; V-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
@ -122,17 +125,6 @@ Matches(const Standard_Real X,
{ {
return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin); return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
} }
//detection d'une auto - intersection dans le polygon 2D; si oui on sort
// if (!AutoComputeFlag(myautointer)) {
// if(mypolyg2d.Length()>4) {
// if (SelectBasics_BasicTool::AutoInter(mypolyg2d)) {
// SetAutoInterFlag(myautointer);
// }
// }
// SetAutoComputeFlag(myautointer);
// }
// if (AutoInterFlag(myautointer)) return Standard_True;
// //
//otherwise it is checked if the point is in the face... //otherwise it is checked if the point is in the face...
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints); TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
@ -141,13 +133,14 @@ Matches(const Standard_Real X,
Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y)); Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y));
Standard_Boolean res(Standard_False); Standard_Boolean res(Standard_False);
switch(TheStat){ switch(TheStat)
{
case 0: case 0:
res = Standard_True; res = Standard_True;
case 1: case 1:
{ {
if(mytype!=Select3D_TOS_BOUNDARY) if(mytype!=Select3D_TOS_BOUNDARY)
res = Standard_True; res = Standard_True;
} }
} }
if (res) if (res)
@ -164,15 +157,16 @@ Matches(const Standard_Real X,
Standard_Boolean Select3D_SensitiveFace:: Standard_Boolean Select3D_SensitiveFace::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Bnd_Box2d BoundBox; Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=1;j<=mynbpoints-1;j++){ for(Standard_Integer j=1;j<=mynbpoints-1;j++)
{
if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j-1])) return Standard_False; if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j-1])) return Standard_False;
} }
return Standard_True; return Standard_True;
@ -185,9 +179,9 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveFace:: Standard_Boolean Select3D_SensitiveFace::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv; Standard_Real Tolu,Tolv;
@ -195,18 +189,19 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7; Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=mynbpoints;j++){ for(Standard_Integer j=1;j<=mynbpoints;j++)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]); Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
if(RES!=1) return Standard_False; if(RES!=1) return Standard_False;
} }
return Standard_True; return Standard_True;
} }
//======================================================================= //=======================================================================
//function : Dump //function : Dump
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{ {
S<<"\tSensitiveFace 3D :"<<endl;; S<<"\tSensitiveFace 3D :"<<endl;;
@ -216,7 +211,8 @@ void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean Ful
if(mytype==Select3D_TOS_BOUNDARY) if(mytype==Select3D_TOS_BOUNDARY)
S<<"\t\tSelection Of Bounding Polyline Only"<<endl; S<<"\t\tSelection Of Bounding Polyline Only"<<endl;
if(FullDump){ if(FullDump)
{
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl; S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl; // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
@ -228,6 +224,7 @@ void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean Ful
//function : ComputeDepth //function : ComputeDepth
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
{ {
Standard_Real aDepth = Precision::Infinite(); Standard_Real aDepth = Precision::Infinite();
@ -244,3 +241,28 @@ Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
} }
return aDepth; return aDepth;
} }
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected(const TopLoc_Location &theLocation)
{
// Create a copy of this
TColgp_Array1OfPnt aPoints(1, mynbpoints);
for (Standard_Integer i = 1; i <= mynbpoints; ++i)
{
aPoints.SetValue(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
}
Handle(Select3D_SensitiveEntity) aNewEntity =
new Select3D_SensitiveFace(myOwnerId, aPoints, mytype);
if (HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);
return aNewEntity;
}

View File

@ -130,7 +130,10 @@ is
---Purpose: returns the depth of the touched entity ---Purpose: returns the depth of the touched entity
SetLastPrj(me:mutable;aPrj:Projector from Select3D) is redefined virtual; SetLastPrj(me:mutable;aPrj:Projector from Select3D) is redefined virtual;
Set(me:mutable;TheOwnerId: EntityOwner from SelectBasics) is redefined static;
---Purpose: Sets the owner for all entities in group
GetEntities(me) GetEntities(me)
returns ListOfSensitive from Select3D; returns ListOfSensitive from Select3D;

View File

@ -8,8 +8,12 @@
#include <Select3D_ListIteratorOfListOfSensitive.hxx> #include <Select3D_ListIteratorOfListOfSensitive.hxx>
#include <Precision.hxx> #include <Precision.hxx>
//=======================================================================
//function : Creation
//purpose :
//=======================================================================
Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Boolean MatchAll): const Standard_Boolean MatchAll):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
myMustMatchAll(MatchAll), myMustMatchAll(MatchAll),
myLastRank(0), myLastRank(0),
@ -18,10 +22,14 @@ myY(0.)
{ {
} }
Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId, //=======================================================================
Select3D_ListOfSensitive& TheList, //function : Creation
const Standard_Boolean MatchAll): //purpose :
//=======================================================================
Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
Select3D_ListOfSensitive& TheList,
const Standard_Boolean MatchAll):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
myMustMatchAll(MatchAll), myMustMatchAll(MatchAll),
myLastRank(0), myLastRank(0),
@ -35,6 +43,7 @@ myY(0.)
//function : Add //function : Add
//purpose : No control of entities inside //purpose : No control of entities inside
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL) void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
{myList.Append(LL);} {myList.Append(LL);}
@ -42,9 +51,11 @@ void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
//function : Add //function : Add
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive) void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
{ {
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
if(It.Value()==aSensitive) return; if(It.Value()==aSensitive) return;
} }
myList.Append(aSensitive); myList.Append(aSensitive);
@ -54,10 +65,13 @@ void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensi
//function : Remove //function : Remove
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive) void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
{ {
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
if(It.Value()==aSensitive){ {
if(It.Value()==aSensitive)
{
myList.Remove(It); myList.Remove(It);
return; return;
} }
@ -68,19 +82,22 @@ void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSe
//function : IsIn //function : IsIn
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
{ {
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
if(It.Value()==aSensitive) if(It.Value()==aSensitive)
return Standard_True; return Standard_True;
} }
return Standard_False; return Standard_False;
} }
//======================================================================= //=======================================================================
//function : Clear //function : Clear
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Clear() void Select3D_SensitiveGroup::Clear()
{myList.Clear();} {myList.Clear();}
@ -93,7 +110,8 @@ void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProject
{ {
Select3D_SensitiveEntity::Project(aProjector); // to set the field last proj... Select3D_SensitiveEntity::Project(aProjector); // to set the field last proj...
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
It.Value()->Project(aProjector); It.Value()->Project(aProjector);
} }
} }
@ -105,7 +123,8 @@ void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProject
void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes) void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
{ {
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
It.Value()->Areas(boxes); It.Value()->Areas(boxes);
} }
} }
@ -119,7 +138,8 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const Top
{ {
Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll); Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
Select3D_ListOfSensitive LL; Select3D_ListOfSensitive LL;
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
LL.Append(It.Value()->GetConnected(aLocation)); LL.Append(It.Value()->GetConnected(aLocation));
} }
newgroup->Add(LL); newgroup->Add(LL);
@ -135,18 +155,24 @@ void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
{ {
if(aLoc.IsIdentity()) return; if(aLoc.IsIdentity()) return;
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
It.Value()->SetLocation(aLoc);
}
if(HasLocation()) if(HasLocation())
if(aLoc == Location()) return; if(aLoc == Location()) return;
Select3D_SensitiveEntity::SetLocation(aLoc); Select3D_SensitiveEntity::SetLocation(aLoc);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
if(It.Value()->HasLocation()){ {
if(It.Value()->Location()!=aLoc) if(It.Value()->HasLocation())
It.Value()->SetLocation(It.Value()->Location()*aLoc); {
if(It.Value()->Location()!=aLoc)
It.Value()->SetLocation(It.Value()->Location()*aLoc);
} }
else else
It.Value()->SetLocation(aLoc); It.Value()->SetLocation(aLoc);
} }
} }
@ -154,15 +180,16 @@ void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
//function : ResetLocation //function : ResetLocation
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::ResetLocation() void Select3D_SensitiveGroup::ResetLocation()
{ {
if(!HasLocation()) return; if(!HasLocation()) return;
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
{
if(It.Value()->HasLocation() && It.Value()->Location()!=Location()) if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
It.Value()->SetLocation(It.Value()->Location()*Location().Inverted()); It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
else else
It.Value()->ResetLocation(); It.Value()->ResetLocation();
} }
Select3D_SensitiveEntity::ResetLocation(); Select3D_SensitiveEntity::ResetLocation();
} }
@ -171,10 +198,11 @@ void Select3D_SensitiveGroup::ResetLocation()
//function : Matches //function : Matches
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
const Standard_Real Y, Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
const Standard_Real aTol, const Standard_Real Y,
Standard_Real& DMin) const Standard_Real aTol,
Standard_Real& DMin)
{ {
myLastRank = 0; myLastRank = 0;
myLastTol = aTol; myLastTol = aTol;
@ -198,25 +226,28 @@ Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
//purpose : si on doit tout matcher, on ne repond oui que si toutes //purpose : si on doit tout matcher, on ne repond oui que si toutes
// les primitives repondent oui // les primitives repondent oui
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin, Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Boolean result(Standard_True); Standard_Boolean result(Standard_True);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol)){ {
if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol))
{
if(!myMustMatchAll) if(!myMustMatchAll)
return Standard_True; return Standard_True;
} }
// ca ne matches pas.. // ca ne matches pas..
else { else
if(myMustMatchAll) {
return Standard_False; if(myMustMatchAll)
else return Standard_False;
result = Standard_False; else
result = Standard_False;
} }
} }
return result; return result;
@ -229,27 +260,29 @@ Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveGroup:: Standard_Boolean Select3D_SensitiveGroup::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Boolean result(Standard_True); Standard_Boolean result(Standard_True);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
if(It.Value()->Matches(aPoly, aBox, aTol)){ {
if(!myMustMatchAll) if(It.Value()->Matches(aPoly, aBox, aTol))
return Standard_True; {
if(!myMustMatchAll)
return Standard_True;
} }
else { else
if(myMustMatchAll) {
return Standard_False; if(myMustMatchAll)
else return Standard_False;
result = Standard_False; else
result = Standard_False;
} }
} }
return result; return result;
} }
//======================================================================= //=======================================================================
//function : ComputeDepth //function : ComputeDepth
//purpose : to optimise, the minimum depth for //purpose : to optimise, the minimum depth for
@ -285,6 +318,7 @@ Standard_Real Select3D_SensitiveGroup::ComputeDepth(const gp_Lin& EyeLine) const
//function : MaxBoxes //function : MaxBoxes
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
{ {
Standard_Integer nbboxes(0); Standard_Integer nbboxes(0);
@ -294,9 +328,28 @@ Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
return nbboxes; return nbboxes;
} }
//=======================================================================
//function : SetLastPrj
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::SetLastPrj(const Handle(Select3D_Projector)& Prj) void Select3D_SensitiveGroup::SetLastPrj(const Handle(Select3D_Projector)& Prj)
{ {
Select3D_SensitiveEntity::SetLastPrj(Prj); Select3D_SensitiveEntity::SetLastPrj(Prj);
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
It.Value()->SetLastPrj(Prj); It.Value()->SetLastPrj(Prj);
} }
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void Select3D_SensitiveGroup::Set
(const Handle(SelectBasics_EntityOwner)& TheOwnerId)
{
Select3D_SensitiveEntity::Set(TheOwnerId);
// set TheOwnerId for each element of sensitive group
for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
It.Value()->Set(TheOwnerId);
}

View File

@ -14,13 +14,13 @@
#include <CSLib_Class2d.hxx> #include <CSLib_Class2d.hxx>
//================================================== //==================================================
// Function: // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitivePoint Select3D_SensitivePoint
::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner, ::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
const gp_Pnt& aPoint): const gp_Pnt& aPoint):
Select3D_SensitiveEntity(anOwner) Select3D_SensitiveEntity(anOwner)
{ {
SetSensitivityFactor(4.); SetSensitivityFactor(4.);
@ -28,9 +28,10 @@ Select3D_SensitiveEntity(anOwner)
} }
//================================================== //==================================================
// Function: // Function: Project
// Purpose : // Purpose :
//================================================== //==================================================
void Select3D_SensitivePoint void Select3D_SensitivePoint
::Project (const Handle(Select3D_Projector)& aProj) ::Project (const Handle(Select3D_Projector)& aProj)
{ {
@ -38,7 +39,8 @@ void Select3D_SensitivePoint
gp_Pnt2d aPoint2d; gp_Pnt2d aPoint2d;
if(!HasLocation()) if(!HasLocation())
aProj->Project(mypoint, aPoint2d); aProj->Project(mypoint, aPoint2d);
else{ else
{
gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z); gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z);
aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d); aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
} }
@ -46,9 +48,10 @@ void Select3D_SensitivePoint
} }
//================================================== //==================================================
// Function: // Function: Areas
// Purpose : // Purpose :
//================================================== //==================================================
void Select3D_SensitivePoint void Select3D_SensitivePoint
::Areas(SelectBasics_ListOfBox2d& boxes) ::Areas(SelectBasics_ListOfBox2d& boxes)
{ {
@ -57,16 +60,16 @@ void Select3D_SensitivePoint
boxes.Append(abox); boxes.Append(abox);
} }
//================================================== //==================================================
// Function: // Function: Matches
// Purpose : // Purpose :
//================================================== //==================================================
Standard_Boolean Select3D_SensitivePoint Standard_Boolean Select3D_SensitivePoint
::Matches(const Standard_Real X, ::Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
DMin = gp_Pnt2d(X,Y).Distance(myprojpt); DMin = gp_Pnt2d(X,Y).Distance(myprojpt);
if(DMin<=aTol*SensitivityFactor()) if(DMin<=aTol*SensitivityFactor())
@ -77,12 +80,17 @@ Standard_Boolean Select3D_SensitivePoint
return Standard_False; return Standard_False;
} }
//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitivePoint:: Standard_Boolean Select3D_SensitivePoint::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Bnd_Box2d B; Bnd_Box2d B;
B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax)); B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
@ -90,7 +98,6 @@ Matches (const Standard_Real XMin,
return !B.IsOut(myprojpt); return !B.IsOut(myprojpt);
} }
//======================================================================= //=======================================================================
//function : Matches //function : Matches
//purpose : //purpose :
@ -98,8 +105,8 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitivePoint:: Standard_Boolean Select3D_SensitivePoint::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
@ -114,12 +121,11 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
return Standard_False; return Standard_False;
} }
//======================================================================= //=======================================================================
//function : Point //function : Point
//purpose : //purpose :
//======================================================================= //=======================================================================
gp_Pnt Select3D_SensitivePoint::Point() const gp_Pnt Select3D_SensitivePoint::Point() const
{return mypoint;} {return mypoint;}
@ -136,7 +142,6 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const Top
return NiouEnt; return NiouEnt;
} }
//======================================================================= //=======================================================================
//function : Dump //function : Dump
//purpose : //purpose :
@ -161,5 +166,3 @@ Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
{ {
return ElCLib::Parameter(EyeLine,mypoint); return ElCLib::Parameter(EyeLine,mypoint);
} }

View File

@ -38,7 +38,7 @@ is
---Level: Public ---Level: Public
---Purpose: Constructs the sensitive circle object defined by the ---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the circle Circle, the Boolean -- owner OwnerId, the circle Circle, the Boolean
-- FilledCircle and the number of points NbOfPoints. -- FilledCircle and the number of points NbOfPoints.
Project (me:mutable;aProjector : Projector from Select3D) is redefined virtual; Project (me:mutable;aProjector : Projector from Select3D) is redefined virtual;
---Level: Public ---Level: Public
@ -69,4 +69,4 @@ fields
mypolyg2d : Address from Standard is protected; mypolyg2d : Address from Standard is protected;
mybox2d : Box2d from Select3D is protected; mybox2d : Box2d from Select3D is protected;
mynbpoints : Integer from Standard is protected; mynbpoints : Integer from Standard is protected;
end SensitiveFace; end SensitivePoly;

View File

@ -14,7 +14,7 @@
Select3D_SensitivePoly:: Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints): const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitiveEntity(OwnerId) Select3D_SensitiveEntity(OwnerId)
{ {
mynbpoints = ThePoints.Upper()-ThePoints.Lower()+1; mynbpoints = ThePoints.Upper()-ThePoints.Lower()+1;
@ -25,13 +25,13 @@ Select3D_SensitiveEntity(OwnerId)
} }
//================================================== //==================================================
// Function: // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitivePoly:: Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints): const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitiveEntity(OwnerId) Select3D_SensitiveEntity(OwnerId)
{ {
mynbpoints = ThePoints->Upper()-ThePoints->Lower()+1; mynbpoints = ThePoints->Upper()-ThePoints->Lower()+1;
@ -42,13 +42,13 @@ Select3D_SensitiveEntity(OwnerId)
} }
//================================================== //==================================================
// Function: // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitivePoly:: Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer NbPoints): const Standard_Integer NbPoints):
Select3D_SensitiveEntity(OwnerId) Select3D_SensitiveEntity(OwnerId)
{ {
mynbpoints = NbPoints; mynbpoints = NbPoints;
@ -57,7 +57,7 @@ Select3D_SensitiveEntity(OwnerId)
} }
//================================================== //==================================================
// Function: // Function: Project
// Purpose : // Purpose :
//================================================== //==================================================
@ -85,7 +85,7 @@ void Select3D_SensitivePoly::Project(const Handle(Select3D_Projector)& aProj)
} }
//================================================== //==================================================
// Function: // Function: Areas
// Purpose : // Purpose :
//================================================== //==================================================
void Select3D_SensitivePoly void Select3D_SensitivePoly
@ -95,7 +95,7 @@ void Select3D_SensitivePoly
} }
//================================================== //==================================================
// Function: // Function: Destroy
// Purpose : // Purpose :
//================================================== //==================================================
void Select3D_SensitivePoly::Destroy() void Select3D_SensitivePoly::Destroy()

View File

@ -27,12 +27,11 @@
// Purpose :Constructor // Purpose :Constructor
//===================================================== //=====================================================
Select3D_SensitiveSegment:: Select3D_SensitiveSegment::
Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveSegment(const Handle(SelectBasics_EntityOwner)& OwnerId,
const gp_Pnt& FirstP, const gp_Pnt& FirstP,
const gp_Pnt& LastP, const gp_Pnt& LastP,
const Standard_Integer MaxRect): const Standard_Integer MaxRect):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
mymaxrect(MaxRect) mymaxrect(MaxRect)
{ {
@ -44,6 +43,7 @@ mymaxrect(MaxRect)
// Function : // Function :
// Purpose : // Purpose :
//===================================================== //=====================================================
void Select3D_SensitiveSegment void Select3D_SensitiveSegment
::Project(const Handle(Select3D_Projector)& aProj) ::Project(const Handle(Select3D_Projector)& aProj)
{ {
@ -51,13 +51,15 @@ void Select3D_SensitiveSegment
gp_Pnt2d aPoint2dStart; gp_Pnt2d aPoint2dStart;
gp_Pnt2d aPoint2dEnd; gp_Pnt2d aPoint2dEnd;
if(HasLocation()){ if(HasLocation())
{
gp_Pnt aStart(mystart.x, mystart.y, mystart.z); gp_Pnt aStart(mystart.x, mystart.y, mystart.z);
gp_Pnt aEnd(myend.x, myend.y, myend.z); gp_Pnt aEnd(myend.x, myend.y, myend.z);
aProj->Project(aStart.Transformed(Location().Transformation()),aPoint2dStart); aProj->Project(aStart.Transformed(Location().Transformation()),aPoint2dStart);
aProj->Project(aEnd.Transformed(Location().Transformation()),aPoint2dEnd); aProj->Project(aEnd.Transformed(Location().Transformation()),aPoint2dEnd);
} }
else{ else
{
aProj->Project(mystart,aPoint2dStart); aProj->Project(mystart,aPoint2dStart);
aProj->Project(myend,aPoint2dEnd); aProj->Project(myend,aPoint2dEnd);
} }
@ -69,43 +71,48 @@ void Select3D_SensitiveSegment
// Function : Areas // Function : Areas
// Purpose : // Purpose :
//===================================================== //=====================================================
void Select3D_SensitiveSegment void Select3D_SensitiveSegment
::Areas(SelectBasics_ListOfBox2d& theareas) ::Areas(SelectBasics_ListOfBox2d& theareas)
{ {
// gp_Dir2d dy (0.,1.); // gp_Dir2d dy (0.,1.);
gp_Pnt2d aPStart(myprojstart.x,myprojstart.y); gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
if(aPStart.Distance(myprojend)<=Precision::Confusion()){ if(aPStart.Distance(myprojend)<=Precision::Confusion())
{
Bnd_Box2d curbox; Bnd_Box2d curbox;
curbox.Set(myprojstart); curbox.Set(myprojstart);
theareas.Append(curbox); theareas.Append(curbox);
} }
else { else
{
gp_Vec2d MyVec(myprojstart,myprojend);//,VAxx(gp_Dir2d(0.,1.)); gp_Vec2d MyVec(myprojstart,myprojend);//,VAxx(gp_Dir2d(0.,1.));
Standard_Real theangle = Abs(gp_Dir2d(0.,1.).Angle(gp_Vec2d(myprojstart,myprojend))); Standard_Real theangle = Abs(gp_Dir2d(0.,1.).Angle(gp_Vec2d(myprojstart,myprojend)));
if(theangle>=M_PI/2.) theangle-=M_PI/2; if(theangle>=M_PI/2.) theangle-=M_PI/2;
if(theangle>=M_PI/12. && theangle <=5*M_PI/12.) if(theangle>=M_PI/12. && theangle <=5*M_PI/12.)
{ {
TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1); TColgp_Array1OfPnt2d BoxPoint (1,mymaxrect+1);
BoxPoint (1) = myprojstart; BoxPoint (1) = myprojstart;
BoxPoint(mymaxrect+1)=myprojend; BoxPoint(mymaxrect+1)=myprojend;
gp_Vec2d Vtr = MyVec/mymaxrect; gp_Vec2d Vtr = MyVec/mymaxrect;
// for (Standard_Integer i=2;i<=mymaxrect;i++) Standard_Integer i;
Standard_Integer i; for ( i=2;i<=mymaxrect;i++)
for ( i=2;i<=mymaxrect;i++) {
{BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);} BoxPoint (i) = BoxPoint (i-1).Translated(Vtr);
for (i=2;i<=mymaxrect+1;i++) }
{ Bnd_Box2d curbox; for (i=2;i<=mymaxrect+1;i++)
curbox.Set(BoxPoint(i-1)); {
curbox.Add(BoxPoint(i)); Bnd_Box2d curbox;
theareas.Append(curbox); curbox.Set(BoxPoint(i-1));
} curbox.Add(BoxPoint(i));
theareas.Append(curbox);
}
} }
else else
{ {
Bnd_Box2d curbox; Bnd_Box2d curbox;
curbox.Set(myprojstart); curbox.Set(myprojstart);
curbox.Add(myprojend); curbox.Add(myprojend);
theareas.Append(curbox); theareas.Append(curbox);
} }
} }
} }
@ -114,11 +121,12 @@ void Select3D_SensitiveSegment
// Function : Matches // Function : Matches
// Purpose : // Purpose :
//===================================================== //=====================================================
Standard_Boolean Select3D_SensitiveSegment Standard_Boolean Select3D_SensitiveSegment
::Matches(const Standard_Real X, ::Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
gp_Pnt2d aPStart(myprojstart.x,myprojstart.y); gp_Pnt2d aPStart(myprojstart.x,myprojstart.y);
gp_Pnt2d aPEnd(myprojend.x,myprojend.y); gp_Pnt2d aPEnd(myprojend.x,myprojend.y);
@ -127,12 +135,17 @@ Standard_Boolean Select3D_SensitiveSegment
return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); // compute and validate depth return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); // compute and validate depth
} }
//=====================================================
// Function : Matches
// Purpose :
//=====================================================
Standard_Boolean Select3D_SensitiveSegment:: Standard_Boolean Select3D_SensitiveSegment::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Bnd_Box2d BoundBox; Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
@ -141,7 +154,6 @@ Matches (const Standard_Real XMin,
return Standard_True; return Standard_True;
} }
//======================================================================= //=======================================================================
//function : Matches //function : Matches
//purpose : //purpose :
@ -149,8 +161,8 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveSegment:: Standard_Boolean Select3D_SensitiveSegment::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
@ -173,9 +185,13 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
//function : GetConnected //function : GetConnected
//purpose : //purpose :
//======================================================================= //=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveSegment::GetConnected(const TopLoc_Location& aLoc)
Handle(Select3D_SensitiveEntity) Select3D_SensitiveSegment::
GetConnected(const TopLoc_Location& aLoc)
{ {
Handle(Select3D_SensitiveSegment) NiouEnt = new Select3D_SensitiveSegment(myOwnerId,mystart,myend,mymaxrect); Handle(Select3D_SensitiveSegment) NiouEnt =
new Select3D_SensitiveSegment(myOwnerId,mystart,myend,mymaxrect);
if(HasLocation()) NiouEnt->SetLocation(Location()); if(HasLocation()) NiouEnt->SetLocation(Location());
NiouEnt->UpdateLocation(aLoc); NiouEnt->UpdateLocation(aLoc);
return NiouEnt; return NiouEnt;

View File

@ -21,7 +21,8 @@ uses
XY from gp, XY from gp,
Pnt from gp, Pnt from gp,
TypeOfSensitivity from Select3D, TypeOfSensitivity from Select3D,
Location from TopLoc Location from TopLoc,
SensitiveEntity from Select3D
is is
Create (OwnerId : EntityOwner from SelectBasics; Create (OwnerId : EntityOwner from SelectBasics;
@ -30,7 +31,7 @@ is
returns mutable SensitiveTriangle; returns mutable SensitiveTriangle;
---Level: Public ---Level: Public
---Purpose: Constructs a sensitive triangle object defined by the ---Purpose: Constructs a sensitive triangle object defined by the
-- owner OwnerId, the points P1, P2, P3, and the type of sensitivity Sensitivity. -- owner OwnerId, the points P1, P2, P3, and the type of sensitivity Sensitivity.
Matches(me :mutable; Matches(me :mutable;
X,Y : Real from Standard; X,Y : Real from Standard;
@ -85,7 +86,13 @@ is
Dmin : out Real from Standard) returns Integer from Standard; Dmin : out Real from Standard) returns Integer from Standard;
---Purpose: Dmin gives the distance between the cdg and aPoint return ---Purpose: Dmin gives the distance between the cdg and aPoint return
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual; Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
GetConnected(me: mutable; theLocation : Location from TopLoc)
returns SensitiveEntity from Select3D
is redefined virtual;
---Level: Public
---Purpose: Returns the copy of this
fields fields

View File

@ -43,16 +43,16 @@ static Standard_Boolean S3D_Str_NearSegment (const gp_XY& p0, const gp_XY& p1, c
} }
//================================================== //==================================================
// Function: // Function: Creation
// Purpose : // Purpose :
//================================================== //==================================================
Select3D_SensitiveTriangle:: Select3D_SensitiveTriangle::
Select3D_SensitiveTriangle(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveTriangle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const gp_Pnt& P0, const gp_Pnt& P0,
const gp_Pnt& P1, const gp_Pnt& P1,
const gp_Pnt& P2, const gp_Pnt& P2,
const Select3D_TypeOfSensitivity aType): const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId,3), Select3D_SensitivePoly(OwnerId,3),
mytype (aType) mytype (aType)
{ {
@ -62,21 +62,22 @@ mytype (aType)
} }
//================================================== //==================================================
// Function: // Function: Matches
// Purpose : // Purpose :
//================================================== //==================================================
Standard_Boolean Select3D_SensitiveTriangle:: Standard_Boolean Select3D_SensitiveTriangle::
Matches(const Standard_Real X, Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin); Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
if(Bnd_Box2d(mybox2d).IsOut(gp_Pnt2d(X,Y))) return Standard_False; if(Bnd_Box2d(mybox2d).IsOut(gp_Pnt2d(X,Y))) return Standard_False;
Standard_Integer Res; Standard_Integer Res;
switch (mytype){ switch (mytype)
{
case Select3D_TOS_BOUNDARY: case Select3D_TOS_BOUNDARY:
Res = Status(X,Y,aTol,DMin); Res = Status(X,Y,aTol,DMin);
return Res== 1; return Res== 1;
@ -92,25 +93,31 @@ Matches(const Standard_Real X,
return Standard_True; return Standard_True;
} }
//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveTriangle:: Standard_Boolean Select3D_SensitiveTriangle::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Bnd_Box2d B; Bnd_Box2d B;
B.Update(Min(XMin,XMax)-aTol, B.Update(Min(XMin,XMax)-aTol,
Min(YMin,YMax)-aTol, Min(YMin,YMax)-aTol,
Max(XMin,XMax)+aTol, Max(XMin,XMax)+aTol,
Max(YMin,YMax)+aTol); Max(YMin,YMax)+aTol);
for(Standard_Integer i=0;i<=2;i++){ for(Standard_Integer i=0;i<=2;i++)
{
if(B.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i])) if(B.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i]))
return Standard_False;} return Standard_False;
}
return Standard_True; return Standard_True;
} }
//======================================================================= //=======================================================================
//function : Matches //function : Matches
//purpose : //purpose :
@ -118,8 +125,8 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveTriangle:: Standard_Boolean Select3D_SensitiveTriangle::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
@ -128,20 +135,31 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7; Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer i=0;i<=2;i++){ for(Standard_Integer i=0;i<=2;i++)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[i]); Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[i]);
if(RES!=1) return Standard_False; if(RES!=1) return Standard_False;
} }
return Standard_True; return Standard_True;
} }
//==================================================
// Function: Points3D
// Purpose :
//==================================================
void Select3D_SensitiveTriangle::Points3D(gp_Pnt& P0,gp_Pnt& P1,gp_Pnt& P2) const void Select3D_SensitiveTriangle::Points3D(gp_Pnt& P0,gp_Pnt& P1,gp_Pnt& P2) const
{ {
P0 = ((Select3D_Pnt*)mypolyg3d)[0]; P1 = ((Select3D_Pnt*)mypolyg3d)[1]; P2 = ((Select3D_Pnt*)mypolyg3d)[2]; P0 = ((Select3D_Pnt*)mypolyg3d)[0];
P1 = ((Select3D_Pnt*)mypolyg3d)[1];
P2 = ((Select3D_Pnt*)mypolyg3d)[2];
} }
//==================================================
// Function: Center3D
// Purpose :
//==================================================
gp_Pnt Select3D_SensitiveTriangle::Center3D() const gp_Pnt Select3D_SensitiveTriangle::Center3D() const
{ {
gp_XYZ CDG(((Select3D_Pnt*)mypolyg3d)[0]); gp_XYZ CDG(((Select3D_Pnt*)mypolyg3d)[0]);
@ -149,7 +167,12 @@ gp_Pnt Select3D_SensitiveTriangle::Center3D() const
CDG += ((Select3D_Pnt*)mypolyg3d)[2]; CDG += ((Select3D_Pnt*)mypolyg3d)[2];
CDG /=3.; CDG /=3.;
return gp_Pnt(CDG);; return gp_Pnt(CDG);;
} }
//==================================================
// Function: Center2D
// Purpose :
//==================================================
gp_XY Select3D_SensitiveTriangle::Center2D() const gp_XY Select3D_SensitiveTriangle::Center2D() const
{ {
@ -163,30 +186,26 @@ gp_XY Select3D_SensitiveTriangle::Center2D() const
//======================================================================= //=======================================================================
Standard_Integer Select3D_SensitiveTriangle::Status(const Standard_Real X, Standard_Integer Select3D_SensitiveTriangle::Status(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) const Standard_Real& DMin) const
{ {
return Status(((Select3D_Pnt2d*)mypolyg2d)[0],((Select3D_Pnt2d*)mypolyg2d)[1], return Status(((Select3D_Pnt2d*)mypolyg2d)[0],((Select3D_Pnt2d*)mypolyg2d)[1],
((Select3D_Pnt2d*)mypolyg2d)[2],gp_XY(X,Y),aTol,DMin); ((Select3D_Pnt2d*)mypolyg2d)[2],gp_XY(X,Y),aTol,DMin);
} }
//======================================================================= //=======================================================================
//function : Status //function : Status
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0, Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
const gp_XY& p1, const gp_XY& p1,
const gp_XY& p2, const gp_XY& p2,
const gp_XY& TheP, const gp_XY& TheP,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
Bnd_Box2d B; Bnd_Box2d B;
B.Update(p0.X(),p0.Y());B.Update(p1.X(),p1.Y());B.Update(p2.X(),p2.Y()); B.Update(p0.X(),p0.Y());B.Update(p1.X(),p1.Y());B.Update(p2.X(),p2.Y());
B.Enlarge(aTol); B.Enlarge(aTol);
@ -277,7 +296,7 @@ Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
DMin = ( aD < 0 ? -aD : 0. ); DMin = ( aD < 0 ? -aD : 0. );
return 0; return 0;
} }
//======================================================================= //=======================================================================
//function : Dump //function : Dump
//purpose : //purpose :
@ -295,7 +314,8 @@ void Select3D_SensitiveTriangle::Dump(Standard_OStream& S,const Standard_Boolean
S<<"\t\t P1 [ "<<COORD(1,x)<<" , "<<COORD(1,y) <<" , "<<COORD(1,z)<<" ]"<<endl; S<<"\t\t P1 [ "<<COORD(1,x)<<" , "<<COORD(1,y) <<" , "<<COORD(1,z)<<" ]"<<endl;
S<<"\t\t P2 [ "<<COORD(2,x)<<" , "<<COORD(2,y) <<" , "<<COORD(2,z)<<" ]"<<endl; S<<"\t\t P2 [ "<<COORD(2,x)<<" , "<<COORD(2,y) <<" , "<<COORD(2,z)<<" ]"<<endl;
if(FullDump){ if(FullDump)
{
S<<"\t\tProjected Points"<<endl; S<<"\t\tProjected Points"<<endl;
S<<"\t\t 0.[ "<<COORD2d(0,x)<<" , "<<COORD2d(0,y)<<" ]"<<endl; S<<"\t\t 0.[ "<<COORD2d(0,x)<<" , "<<COORD2d(0,y)<<" ]"<<endl;
@ -303,24 +323,26 @@ void Select3D_SensitiveTriangle::Dump(Standard_OStream& S,const Standard_Boolean
S<<"\t\t 2.[ "<<COORD2d(2,x)<<" , "<<COORD2d(2,y)<<" ]"<<endl; S<<"\t\t 2.[ "<<COORD2d(2,x)<<" , "<<COORD2d(2,y)<<" ]"<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl; // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d); Select3D_SensitiveEntity::DumpBox(S,mybox2d);
} }
} }
//======================================================================= //=======================================================================
//function : ComputeDepth //function : ComputeDepth
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Real Select3D_SensitiveTriangle::ComputeDepth(const gp_Lin& EyeLine) const Standard_Real Select3D_SensitiveTriangle::ComputeDepth(const gp_Lin& EyeLine) const
{ {
gp_Pnt P1(((Select3D_Pnt*)mypolyg3d)[0].x, ((Select3D_Pnt*)mypolyg3d)[0].y, ((Select3D_Pnt*)mypolyg3d)[0].z); gp_Pnt P1 = ((Select3D_Pnt*)mypolyg3d)[0];
gp_Pnt P2(((Select3D_Pnt*)mypolyg3d)[1].x, ((Select3D_Pnt*)mypolyg3d)[1].y, ((Select3D_Pnt*)mypolyg3d)[1].z); gp_Pnt P2 = ((Select3D_Pnt*)mypolyg3d)[1];
gp_Pnt P3(((Select3D_Pnt*)mypolyg3d)[2].x, ((Select3D_Pnt*)mypolyg3d)[2].y, ((Select3D_Pnt*)mypolyg3d)[2].z); gp_Pnt P3 = ((Select3D_Pnt*)mypolyg3d)[2];
gp_Trsf TheTrsf ; gp_Trsf TheTrsf ;
if(HasLocation()) if(HasLocation())
TheTrsf = Location().Transformation(); TheTrsf = Location().Transformation();
if(TheTrsf.Form()!=gp_Identity){ if(TheTrsf.Form()!=gp_Identity)
{
P1.Transform(TheTrsf); P1.Transform(TheTrsf);
P2.Transform(TheTrsf); P2.Transform(TheTrsf);
P3.Transform(TheTrsf); P3.Transform(TheTrsf);
@ -344,12 +366,35 @@ Standard_Real Select3D_SensitiveTriangle::ComputeDepth(const gp_Lin& EyeLine) co
if(Abs(val2)>Precision::Confusion()) if(Abs(val2)>Precision::Confusion())
prof =val1/val2; prof =val1/val2;
if (prof==Precision::Infinite()){ if (prof==Precision::Infinite())
{
prof= ElCLib::Parameter(EyeLine,P1); prof= ElCLib::Parameter(EyeLine,P1);
prof = Min (prof, ElCLib::Parameter(EyeLine,P2)); prof = Min (prof, ElCLib::Parameter(EyeLine,P2));
prof = Min (prof, ElCLib::Parameter(EyeLine,P3)); prof = Min (prof, ElCLib::Parameter(EyeLine,P3));
} }
return prof; return prof;
} }
//==================================================
// Function: GetConnected
// Purpose :
//==================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangle::
GetConnected(const TopLoc_Location &theLocation)
{
// Create a copy of this
Handle(Select3D_SensitiveEntity) aNewEntity =
new Select3D_SensitiveTriangle(myOwnerId,
((Select3D_Pnt*)mypolyg3d)[0],
((Select3D_Pnt*)mypolyg3d)[1],
((Select3D_Pnt*)mypolyg3d)[2],
mytype);
if (HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);
return aNewEntity;
}

View File

@ -78,10 +78,10 @@ static Standard_Boolean S3D_STriangul_NearSegment (const gp_XY& p0, const gp_XY&
// } // }
static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1, static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1,
const Standard_Integer e2, const Standard_Integer e2,
const Standard_Integer N1, const Standard_Integer N1,
const Standard_Integer N2, const Standard_Integer N2,
const Standard_Integer N3) const Standard_Integer N3)
{ {
Standard_Integer bid1 = (e1 == N1) ? N1 : ((e1 == N2) ? N2 : ( e1==N3 ? N3 : 0)); Standard_Integer bid1 = (e1 == N1) ? N1 : ((e1 == N2) ? N2 : ( e1==N3 ? N3 : 0));
if(bid1==0) return Standard_False; if(bid1==0) return Standard_False;
@ -91,19 +91,17 @@ static Standard_Boolean S3D_IsEdgeIn(const Standard_Integer e1,
return Standard_True; return Standard_True;
} }
//======================================================================= //=======================================================================
//function : Select3D_SensitiveTriangulation //function : Select3D_SensitiveTriangulation
//purpose : //purpose :
//======================================================================= //=======================================================================
Select3D_SensitiveTriangulation:: Select3D_SensitiveTriangulation::
Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Poly_Triangulation)& Trg, const Handle(Poly_Triangulation)& Trg,
const TopLoc_Location& Loc, const TopLoc_Location& Loc,
const Standard_Boolean InteriorFlag): const Standard_Boolean InteriorFlag):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg), myTriangul(Trg),
myiniloc(Loc), myiniloc(Loc),
myIntFlag(InteriorFlag), myIntFlag(InteriorFlag),
@ -121,34 +119,38 @@ myDetectedTr(-1)
Standard_Integer n[3]; Standard_Integer n[3];
// to find connections in case when the border is not concerned... // to find connections in case when the border is not concerned...
if(!myIntFlag){ if(!myIntFlag)
{
myFreeEdges = new TColStd_HArray1OfInteger(1,2*S3D_NumberOfFreeEdges(Trg)); myFreeEdges = new TColStd_HArray1OfInteger(1,2*S3D_NumberOfFreeEdges(Trg));
TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1(); TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
Poly_Connect pc(myTriangul); Poly_Connect pc(myTriangul);
Standard_Integer t[3]; Standard_Integer t[3];
Standard_Integer i,j; Standard_Integer i,j;
for ( i = 1; i <= nbTriangles; i++) { for ( i = 1; i <= nbTriangles; i++)
{
pc.Triangles(i,t[0],t[1],t[2]); pc.Triangles(i,t[0],t[1],t[2]);
triangles(i).Get(n[0],n[1],n[2]); triangles(i).Get(n[0],n[1],n[2]);
cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.; cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++)
Standard_Integer k = (j+1) % 3; {
if (t[j] == 0) { Standard_Integer k = (j+1) % 3;
FreeE(fr) = n[j]; if (t[j] == 0)
FreeE(fr+1)= n[k]; {
fr += 2; FreeE(fr) = n[j];
} FreeE(fr+1)= n[k];
fr += 2;
}
} }
} }
} }
else{ else{
for (Standard_Integer i = 1; i <= nbTriangles; i++) { for (Standard_Integer i = 1; i <= nbTriangles; i++)
{
triangles(i).Get(n[0],n[1],n[2]); triangles(i).Get(n[0],n[1],n[2]);
cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.; cdg += (Nodes(n[0]).XYZ() + Nodes(n[1]).XYZ()+ Nodes(n[2]).XYZ())/3.;
} }
} }
if(nbTriangles!=0) cdg /= nbTriangles; if(nbTriangles!=0) cdg /= nbTriangles;
myCDG3D = gp_Pnt(cdg); myCDG3D = gp_Pnt(cdg);
@ -163,13 +165,14 @@ myDetectedTr(-1)
//function : Select3D_SensitiveTriangulation //function : Select3D_SensitiveTriangulation
//purpose : //purpose :
//======================================================================= //=======================================================================
Select3D_SensitiveTriangulation:: Select3D_SensitiveTriangulation::
Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveTriangulation(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Poly_Triangulation)& Trg, const Handle(Poly_Triangulation)& Trg,
const TopLoc_Location& Loc, const TopLoc_Location& Loc,
const Handle(TColStd_HArray1OfInteger)& FreeEdges, const Handle(TColStd_HArray1OfInteger)& FreeEdges,
const gp_Pnt& TheCDG, const gp_Pnt& TheCDG,
const Standard_Boolean InteriorFlag): const Standard_Boolean InteriorFlag):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
myTriangul(Trg), myTriangul(Trg),
myiniloc(Loc), myiniloc(Loc),
@ -180,6 +183,7 @@ myNodes2d(1,Trg->NbNodes()),
myDetectedTr(-1) myDetectedTr(-1)
{ {
} }
//======================================================================= //=======================================================================
//function : Project //function : Project
//purpose : //purpose :
@ -221,10 +225,11 @@ void Select3D_SensitiveTriangulation::Areas(SelectBasics_ListOfBox2d& boxes)
//function : Matches //function : Matches
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real X, Standard_Boolean Select3D_SensitiveTriangulation::
const Standard_Real Y, Matches(const Standard_Real X,
const Standard_Real aTol, const Standard_Real Y,
Standard_Real& DMin) const Standard_Real aTol,
Standard_Real& DMin)
{ {
// get view direction (necessary for calculation of depth) from field mylastprj of the base class // get view direction (necessary for calculation of depth) from field mylastprj of the base class
if (mylastprj.IsNull()) if (mylastprj.IsNull())
@ -319,26 +324,27 @@ Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real X,
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real XMin, Standard_Boolean Select3D_SensitiveTriangulation::
const Standard_Real YMin, Matches(const Standard_Real XMin,
const Standard_Real XMax, const Standard_Real YMin,
const Standard_Real YMax, const Standard_Real XMax,
const Standard_Real aTol) const Standard_Real YMax,
const Standard_Real aTol)
{ {
Bnd_Box2d B; Bnd_Box2d B;
B.Update(Min(XMin,XMax)-aTol, B.Update(Min(XMin,XMax)-aTol,
Min(YMin,YMax)-aTol, Min(YMin,YMax)-aTol,
Max(XMin,XMax)+aTol, Max(XMin,XMax)+aTol,
Max(YMin,YMax)+aTol); Max(YMin,YMax)+aTol);
for(Standard_Integer i=myNodes2d.Lower();i<=myNodes2d.Upper();i++){ for(Standard_Integer i=myNodes2d.Lower();i<=myNodes2d.Upper();i++)
{
if(B.IsOut(myNodes2d(i))) if(B.IsOut(myNodes2d(i)))
return Standard_False; return Standard_False;
} }
return Standard_True; return Standard_True;
} }
//======================================================================= //=======================================================================
//function : Matches //function : Matches
//purpose : //purpose :
@ -346,8 +352,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::Matches(const Standard_Real XM
Standard_Boolean Select3D_SensitiveTriangulation:: Standard_Boolean Select3D_SensitiveTriangulation::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Real Umin,Vmin,Umax,Vmax; Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax); aBox.Get(Umin,Vmin,Umax,Vmax);
@ -356,21 +362,26 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7; Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=myNodes2d.Length();j++){ for(Standard_Integer j=1;j<=myNodes2d.Length();j++)
{
Standard_Integer RES = aClassifier2d.SiDans(myNodes2d(j)); Standard_Integer RES = aClassifier2d.SiDans(myNodes2d(j));
if(RES!=1) return Standard_False; if(RES!=1) return Standard_False;
} }
return Standard_True; return Standard_True;
} }
//=======================================================================
//function : Status
//purpose :
//=======================================================================
Standard_Integer Select3D_SensitiveTriangulation::
Standard_Integer Select3D_SensitiveTriangulation::Status (const gp_XY& TheP, Status (const gp_XY& TheP,
const gp_XY& Proj0, const gp_XY& Proj0,
const gp_XY& Proj1, const gp_XY& Proj1,
const gp_XY& Proj2, const gp_XY& Proj2,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DD) const Standard_Real& DD) const
{ {
return Select3D_SensitiveTriangle::Status(Proj0,Proj1,Proj2,TheP,aTol,DD); return Select3D_SensitiveTriangle::Status(Proj0,Proj1,Proj2,TheP,aTol,DD);
} }
@ -381,24 +392,31 @@ Standard_Integer Select3D_SensitiveTriangulation::Status (const gp_XY& TheP,
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer IndexOfTriangle, Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer IndexOfTriangle,
Standard_Integer& FoundIndex) const Standard_Integer& FoundIndex) const
{ {
FoundIndex=-1; FoundIndex=-1;
Standard_Integer n[3]; Standard_Integer n[3];
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles(); const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
triangles(IndexOfTriangle).Get(n[0],n[1],n[2]); triangles(IndexOfTriangle).Get(n[0],n[1],n[2]);
TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1(); TColStd_Array1OfInteger& FreeE = myFreeEdges->ChangeArray1();
for(Standard_Integer I=1;I<=FreeE.Length() && FoundIndex==-1;I+=2){ for(Standard_Integer I=1;I<=FreeE.Length() && FoundIndex==-1;I+=2)
{
if(FreeE(I) == n[0]){ if(FreeE(I) == n[0])
{
if(FreeE(I+1)== n[1] || FreeE(I+1)== n[2]) FoundIndex=I;} if(FreeE(I+1)== n[1] || FreeE(I+1)== n[2])
else if(FreeE(I) == n[1]){ FoundIndex=I;
if(FreeE(I+1)== n[0] || FreeE(I+1)== n[2]) FoundIndex=I;} }
else if(FreeE(I) == n[2]){ else if(FreeE(I) == n[1])
if(FreeE(I+1)== n[0] || FreeE(I+1)== n[1]) FoundIndex=I;} {
if(FreeE(I+1)== n[0] || FreeE(I+1)== n[2])
FoundIndex=I;
}
else if(FreeE(I) == n[2])
{
if(FreeE(I+1)== n[0] || FreeE(I+1)== n[1])
FoundIndex=I;
}
} }
return FoundIndex!=-1; return FoundIndex!=-1;
@ -409,32 +427,38 @@ Standard_Boolean Select3D_SensitiveTriangulation::IsFree(const Standard_Integer
//function : GetConnected //function : GetConnected
//purpose : //purpose :
//======================================================================= //=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangulation:: Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangulation::
GetConnected(const TopLoc_Location& aLoc) GetConnected(const TopLoc_Location& aLoc)
{ {
Handle(Select3D_SensitiveTriangulation) NiouEnt = Handle(Select3D_SensitiveTriangulation) NiouEnt =
new Select3D_SensitiveTriangulation(myOwnerId,myTriangul,myiniloc,myFreeEdges,myCDG3D,myIntFlag); new Select3D_SensitiveTriangulation(myOwnerId,myTriangul,myiniloc,myFreeEdges,myCDG3D,myIntFlag);
if(HasLocation()) NiouEnt->SetLocation(Location()); if(HasLocation())
NiouEnt->SetLocation(Location());
// TopLoc_Location TheLocToApply = HasLocation() ? Location()*aLoc : aLoc; // TopLoc_Location TheLocToApply = HasLocation() ? Location()*aLoc : aLoc;
// if(!TheLocToApply.IsIdentity()) // if(!TheLocToApply.IsIdentity())
NiouEnt->UpdateLocation(aLoc); NiouEnt->UpdateLocation(aLoc);
return NiouEnt; return NiouEnt;
} }
//======================================================================= //=======================================================================
//function : ResetLocation //function : ResetLocation
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveTriangulation::ResetLocation() void Select3D_SensitiveTriangulation::ResetLocation()
{ {
Select3D_SensitiveEntity::ResetLocation(); Select3D_SensitiveEntity::ResetLocation();
ComputeTotalTrsf(); ComputeTotalTrsf();
} }
//=======================================================================
//function : SetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveTriangulation::SetLocation(const TopLoc_Location& aLoc) void Select3D_SensitiveTriangulation::SetLocation(const TopLoc_Location& aLoc)
{ {
Select3D_SensitiveEntity::SetLocation(aLoc); Select3D_SensitiveEntity::SetLocation(aLoc);
@ -460,7 +484,8 @@ void Select3D_SensitiveTriangulation::Dump(Standard_OStream& S,const Standard_Bo
S<<"\t\tNb Nodes : "<<myTriangul->NbNodes()<<endl; S<<"\t\tNb Nodes : "<<myTriangul->NbNodes()<<endl;
S<<"\t\tNb Free Edges: "<<myFreeEdges->Length()/2<<endl; S<<"\t\tNb Free Edges: "<<myFreeEdges->Length()/2<<endl;
if(FullDump){ if(FullDump)
{
// S<<"\t\t\tOwner:"<<myOwnerId<<endl; // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d); Select3D_SensitiveEntity::DumpBox(S,mybox2d);
} }
@ -470,6 +495,7 @@ void Select3D_SensitiveTriangulation::Dump(Standard_OStream& S,const Standard_Bo
//function : ComputeDepth //function : ComputeDepth
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLine) const Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLine) const
{ {
if(myDetectedTr==-1) return Precision::Infinite(); // currently not implemented... if(myDetectedTr==-1) return Precision::Infinite(); // currently not implemented...
@ -480,8 +506,10 @@ Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLin
triangles(myDetectedTr).Get(n1,n2,n3); triangles(myDetectedTr).Get(n1,n2,n3);
gp_Pnt P[3]={Nodes(n1),Nodes(n2),Nodes(n3)}; gp_Pnt P[3]={Nodes(n1),Nodes(n2),Nodes(n3)};
if(myTrsf.Form()!=gp_Identity){ if(myTrsf.Form()!=gp_Identity)
for(Standard_Integer i =0;i<=2;i++){ {
for(Standard_Integer i =0;i<=2;i++)
{
P[i].Transform(myTrsf); P[i].Transform(myTrsf);
} }
} }
@ -509,7 +537,8 @@ Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLin
#endif #endif
// 3 pts mixed... // 3 pts mixed...
if(SingularCase ==2){ if(SingularCase ==2)
{
prof= ElCLib::Parameter(EyeLine,P[0]); prof= ElCLib::Parameter(EyeLine,P[0]);
return prof; return prof;
} }
@ -522,7 +551,8 @@ Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLin
gp_Vec OPo(Oye,P[0]); gp_Vec OPo(Oye,P[0]);
// 2 points mixed... the intersection between the segment and the target line eye/point. // 2 points mixed... the intersection between the segment and the target line eye/point.
// //
if(SingularCase!=-1){ if(SingularCase!=-1)
{
gp_Vec V = SingularCase==0 ? Vtr[2] : Vtr[0]; gp_Vec V = SingularCase==0 ? Vtr[2] : Vtr[0];
gp_Vec Det = Dir^V; gp_Vec Det = Dir^V;
gp_Vec VSM = OPo^V; gp_Vec VSM = OPo^V;
@ -533,15 +563,16 @@ Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLin
else if(Det.Z()> Precision::Confusion()) else if(Det.Z()> Precision::Confusion())
prof = VSM.Z()/Det.Z(); prof = VSM.Z()/Det.Z();
} }
else{ else
{
Standard_Real val1 = OPo.DotCross(Vtr[0],Vtr[2]); Standard_Real val1 = OPo.DotCross(Vtr[0],Vtr[2]);
Standard_Real val2 = Dir.DotCross(Vtr[0],Vtr[2]); Standard_Real val2 = Dir.DotCross(Vtr[0],Vtr[2]);
if(Abs(val2)>Precision::Confusion()) if(Abs(val2)>Precision::Confusion())
prof =val1/val2; prof =val1/val2;
} }
if (prof==Precision::Infinite()){ if (prof==Precision::Infinite())
{
prof= ElCLib::Parameter(EyeLine,P[0]); prof= ElCLib::Parameter(EyeLine,P[0]);
prof = Min (prof, ElCLib::Parameter(EyeLine,P[1])); prof = Min (prof, ElCLib::Parameter(EyeLine,P[1]));
prof = Min (prof, ElCLib::Parameter(EyeLine,P[2])); prof = Min (prof, ElCLib::Parameter(EyeLine,P[2]));
@ -554,9 +585,11 @@ Standard_Real Select3D_SensitiveTriangulation::ComputeDepth(const gp_Lin& EyeLin
//function : DetectedTriangle //function : DetectedTriangle
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1,
gp_Pnt& P2, Standard_Boolean Select3D_SensitiveTriangulation::
gp_Pnt& P3) const DetectedTriangle(gp_Pnt& P1,
gp_Pnt& P2,
gp_Pnt& P3) const
{ {
if(myDetectedTr==-1) return Standard_False; // currently not implemented... if(myDetectedTr==-1) return Standard_False; // currently not implemented...
const Poly_Array1OfTriangle& triangles = myTriangul->Triangles(); const Poly_Array1OfTriangle& triangles = myTriangul->Triangles();
@ -567,7 +600,8 @@ Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1,
P1 = Nodes(n1); P1 = Nodes(n1);
P2 = Nodes(n2); P2 = Nodes(n2);
P3 = Nodes(n3); P3 = Nodes(n3);
if(myTrsf.Form()!=gp_Identity){ if(myTrsf.Form()!=gp_Identity)
{
P1.Transform(myTrsf); P1.Transform(myTrsf);
P2.Transform(myTrsf); P2.Transform(myTrsf);
P3.Transform(myTrsf); P3.Transform(myTrsf);
@ -580,8 +614,11 @@ Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle(gp_Pnt& P1,
// Function : DetectedTriangle2d // Function : DetectedTriangle2d
// Purpose : // Purpose :
//============================================================================= //=============================================================================
Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle2d(
gp_Pnt2d& P1, gp_Pnt2d& P2, gp_Pnt2d& P3) const Standard_Boolean Select3D_SensitiveTriangulation::
DetectedTriangle2d(gp_Pnt2d& P1,
gp_Pnt2d& P2,
gp_Pnt2d& P3) const
{ {
if(myDetectedTr==-1) if(myDetectedTr==-1)
return Standard_False; // currently not implemented... return Standard_False; // currently not implemented...
@ -603,23 +640,30 @@ Standard_Boolean Select3D_SensitiveTriangulation::DetectedTriangle2d(
} }
else else
return Standard_False; return Standard_False;
} }
//=============================================================================
// Function : ComputeTotalTrsf
// Purpose :
//=============================================================================
void Select3D_SensitiveTriangulation::ComputeTotalTrsf() void Select3D_SensitiveTriangulation::ComputeTotalTrsf()
{ {
Standard_Boolean hasloc = (HasLocation() || !myiniloc.IsIdentity()); Standard_Boolean hasloc = (HasLocation() || !myiniloc.IsIdentity());
if(hasloc){ if(hasloc)
{
if(myiniloc.IsIdentity()) if(myiniloc.IsIdentity())
myTrsf = Location().Transformation(); myTrsf = Location().Transformation();
else if(HasLocation()){ else if(HasLocation())
{
myTrsf = (Location()*myiniloc).Transformation(); myTrsf = (Location()*myiniloc).Transformation();
} }
else else
myTrsf = myiniloc.Transformation(); myTrsf = myiniloc.Transformation();
} }
else{ else
{
gp_Trsf TheId; gp_Trsf TheId;
myTrsf = TheId; myTrsf = TheId;
} }

View File

@ -95,7 +95,10 @@ is
---Purpose:returns <mymaxrect> ---Purpose:returns <mymaxrect>
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual; Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
Set(me:mutable;TheOwnerId: EntityOwner from SelectBasics) is redefined static;
---Purpose: Sets the owner for all entities in wire
SetLastPrj(me:mutable;aPrj: Projector from Select3D) is redefined virtual; SetLastPrj(me:mutable;aPrj: Projector from Select3D) is redefined virtual;

View File

@ -22,10 +22,9 @@
// Purpose :Constructor // Purpose :Constructor
//===================================================== //=====================================================
Select3D_SensitiveWire:: Select3D_SensitiveWire::
Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId, Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer MaxRect): const Standard_Integer MaxRect):
Select3D_SensitiveEntity(OwnerId), Select3D_SensitiveEntity(OwnerId),
mymaxrect(MaxRect), mymaxrect(MaxRect),
myDetectedIndex(-1) myDetectedIndex(-1)
@ -35,16 +34,12 @@ myDetectedIndex(-1)
// Function : Add // Function : Add
// Purpose : // Purpose :
//===================================================== //=====================================================
void Select3D_SensitiveWire void Select3D_SensitiveWire
::Add(const Handle(Select3D_SensitiveEntity)& aSensitive) ::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
{ {
if ( !aSensitive .IsNull()) { if(!aSensitive.IsNull())
if(!HasLocation()) mysensitive.Append(aSensitive);
mysensitive.Append(aSensitive);
else
mysensitive.Append(aSensitive->GetConnected(Location()));
}
} }
//======================================================================= //=======================================================================
@ -64,14 +59,15 @@ void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc)
Select3D_SensitiveEntity::SetLocation(aLoc); Select3D_SensitiveEntity::SetLocation(aLoc);
for(Standard_Integer i=1;i<=mysensitive.Length();i++){ for(Standard_Integer i=1;i<=mysensitive.Length();i++){
if(mysensitive(i)->HasLocation()){ if(mysensitive(i)->HasLocation()){
if(mysensitive(i)->Location()!=aLoc) if(mysensitive(i)->Location()!=aLoc)
mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc); mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
} }
else else
mysensitive(i)->SetLocation(aLoc); mysensitive(i)->SetLocation(aLoc);
} }
} }
//======================================================================= //=======================================================================
//function : ResetLocation //function : ResetLocation
//purpose : //purpose :
@ -89,6 +85,7 @@ void Select3D_SensitiveWire::ResetLocation()
} }
Select3D_SensitiveEntity::ResetLocation(); Select3D_SensitiveEntity::ResetLocation();
} }
//===================================================== //=====================================================
// Function : Project // Function : Project
// Purpose : // Purpose :
@ -96,7 +93,7 @@ void Select3D_SensitiveWire::ResetLocation()
void Select3D_SensitiveWire void Select3D_SensitiveWire
::Project(const Handle(Select3D_Projector)& aProj) ::Project(const Handle(Select3D_Projector)& aProj)
{ {
for ( Standard_Integer i=1; i<=mysensitive.Length(); i++) for(Standard_Integer i=1; i<=mysensitive.Length(); i++)
mysensitive(i)->Project(aProj); mysensitive(i)->Project(aProj);
Select3D_SensitiveEntity::Project(aProj); Select3D_SensitiveEntity::Project(aProj);
} }
@ -105,6 +102,7 @@ void Select3D_SensitiveWire
// Function : Areas // Function : Areas
// Purpose : // Purpose :
//===================================================== //=====================================================
void Select3D_SensitiveWire void Select3D_SensitiveWire
::Areas(SelectBasics_ListOfBox2d& theareas) ::Areas(SelectBasics_ListOfBox2d& theareas)
{ {
@ -118,7 +116,6 @@ void Select3D_SensitiveWire
BB.Add(it.Value()); BB.Add(it.Value());
theareas.Append(BB); theareas.Append(BB);
} }
//===================================================== //=====================================================
@ -127,20 +124,23 @@ void Select3D_SensitiveWire
//===================================================== //=====================================================
Standard_Boolean Select3D_SensitiveWire Standard_Boolean Select3D_SensitiveWire
::Matches(const Standard_Real X, ::Matches(const Standard_Real X,
const Standard_Real Y, const Standard_Real Y,
const Standard_Real aTol, const Standard_Real aTol,
Standard_Real& DMin) Standard_Real& DMin)
{ {
Standard_Integer i; Standard_Integer i;
Standard_Real Dcur; Standard_Real Dcur;
DMin = Precision::Infinite(); DMin = Precision::Infinite();
Standard_Boolean IsTouched = Standard_False; Standard_Boolean IsTouched = Standard_False;
for (i=1; i<=mysensitive.Length(); i++) { for (i=1; i<=mysensitive.Length(); i++)
if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur)) { {
if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur))
{
IsTouched = Standard_True; IsTouched = Standard_True;
if(Dcur<=DMin){ if(Dcur<=DMin)
myDetectedIndex = i; {
DMin = Dcur; myDetectedIndex = i;
DMin = Dcur;
} }
} }
} }
@ -155,15 +155,17 @@ Standard_Boolean Select3D_SensitiveWire
// Function : Matches // Function : Matches
// Purpose : // Purpose :
//===================================================== //=====================================================
Standard_Boolean Select3D_SensitiveWire::
Standard_Boolean Select3D_SensitiveWire::
Matches (const Standard_Real XMin, Matches (const Standard_Real XMin,
const Standard_Real YMin, const Standard_Real YMin,
const Standard_Real XMax, const Standard_Real XMax,
const Standard_Real YMax, const Standard_Real YMax,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Integer i; Standard_Integer i;
for (i=1; i<=mysensitive.Length(); i++) { for (i=1; i<=mysensitive.Length(); i++)
{
if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol))) if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol)))
return Standard_False; return Standard_False;
} }
@ -177,11 +179,12 @@ Matches (const Standard_Real XMin,
Standard_Boolean Select3D_SensitiveWire:: Standard_Boolean Select3D_SensitiveWire::
Matches (const TColgp_Array1OfPnt2d& aPoly, Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox, const Bnd_Box2d& aBox,
const Standard_Real aTol) const Standard_Real aTol)
{ {
Standard_Integer i; Standard_Integer i;
for (i=1; i<=mysensitive.Length(); i++) { for (i=1; i<=mysensitive.Length(); i++)
{
if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol))) if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol)))
return Standard_False; return Standard_False;
} }
@ -193,6 +196,7 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
// Function : MaxBoxes // Function : MaxBoxes
// Purpose : // Purpose :
//===================================================== //=====================================================
Standard_Integer Select3D_SensitiveWire:: Standard_Integer Select3D_SensitiveWire::
MaxBoxes () const MaxBoxes () const
{ {
@ -203,11 +207,12 @@ MaxBoxes () const
//function : GetConnected //function : GetConnected
//purpose : //purpose :
//======================================================================= //=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc) Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc)
{ {
Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId); Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId);
for(Standard_Integer i=1;i<=mysensitive.Length();i++) for(Standard_Integer i=1;i<=mysensitive.Length();i++)
SWIR->Add(mysensitive(i)); SWIR->Add(mysensitive(i)->GetConnected(aLoc));
if(HasLocation()) if(HasLocation())
SWIR->SetLocation(Location()*aLoc); SWIR->SetLocation(Location()*aLoc);
@ -241,6 +246,7 @@ void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean Ful
//function : ComputeDepth //function : ComputeDepth
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const
{ {
@ -255,6 +261,7 @@ Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const
//function : SetLastPrj //function : SetLastPrj
//purpose : //purpose :
//======================================================================= //=======================================================================
void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj) void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj)
{ {
Select3D_SensitiveEntity::SetLastPrj(Prj); Select3D_SensitiveEntity::SetLastPrj(Prj);
@ -267,6 +274,7 @@ void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj)
//function : GetEdges //function : GetEdges
//purpose : returns the sensitive edges stored in this wire //purpose : returns the sensitive edges stored in this wire
//======================================================================= //=======================================================================
void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges ) void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges )
{ {
theEdges.Clear(); theEdges.Clear();
@ -277,6 +285,7 @@ void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdge
// Function : GetLastDetected // Function : GetLastDetected
// Purpose : // Purpose :
//============================================================================= //=============================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
{ {
Handle(Select3D_SensitiveEntity) aRes; Handle(Select3D_SensitiveEntity) aRes;
@ -286,3 +295,19 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
return aRes; return aRes;
} }
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void Select3D_SensitiveWire::Set(const Handle_SelectBasics_EntityOwner &TheOwnerId)
{
Select3D_SensitiveEntity::Set(TheOwnerId);
// Set TheOwnerId for each element of sensitive wire
for (Standard_Integer i = 1; i <= mysensitive.Length(); ++i)
{
mysensitive.Value(i)->Set(TheOwnerId);
}
}

View File

@ -23,7 +23,7 @@ is
aSensitivityFactor : ShortReal from Standard =1); aSensitivityFactor : ShortReal from Standard =1);
Set (me:mutable ; TheOwnerId : EntityOwner) is static; Set (me:mutable ; TheOwnerId : EntityOwner) is virtual;
---Level: Public ---Level: Public

View File

@ -109,7 +109,12 @@
#include <SelectMgr_Selection.hxx> #include <SelectMgr_Selection.hxx>
#include <StdFail_NotDone.hxx> #include <StdFail_NotDone.hxx>
#include <StdPrs_ShadedShape.hxx> #include <StdPrs_ShadedShape.hxx>
#include <TopoDS_Wire.hxx> #include <TopoDS_Wire.hxx>
#include <AIS_ConnectedShape.hxx>
#include <TopLoc_Location.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
#include <strings.h> #include <strings.h>
@ -3485,6 +3490,327 @@ static Standard_Integer VSetLocation (Draw_Interpretor& di,
return 0; return 0;
} }
//===============================================================================================
//function : VConnect
//purpose : Creates and displays AIS_ConnectedInteractive object from input object and location
//Draw arg : vconnect name object Xo Yo Zo Xu Xv Xw Zu Zv Zw
//===============================================================================================
static Standard_Integer VConnect(Draw_Interpretor& di,
Standard_Integer argc,
const char ** argv)
{
// Check argumnets
if(argc != 12)
{
std::cout << "vconnect error: expect 11 argumnets\n";
return 1; // TCL_ERROR
}
// Get values
TCollection_AsciiString aName(argv[1]);
TCollection_AsciiString anOriginObjectName(argv[2]);
if(aName.IsEqual(anOriginObjectName))
{
std::cout << "vconnect error: equal names for connected objects\n";
return 1; // TCL_ERROR
}
// Check if the origin shape is not null
Handle(AIS_InteractiveObject) anOriginObject;
if(GetMapOfAIS().IsBound2(anOriginObjectName))
{
Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginObjectName);
anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj);
if(anOriginObject.IsNull())
{
std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n!";
return 1; // TCL_ERROR
}
}
// Get location data
Standard_Real aXo = atof(argv[3]);
Standard_Real aYo = atof(argv[4]);
Standard_Real aZo = atof(argv[5]);
Standard_Real aXu = atof(argv[6]);
Standard_Real aXv = atof(argv[7]);
Standard_Real aXw = atof(argv[8]);
Standard_Real aZu = atof(argv[9]);
Standard_Real aZv = atof(argv[10]);
Standard_Real aZw = atof(argv[11]);
// Create transformation
gp_Pnt aPoint(aXo, aYo, aZo);
gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
if(!anXDir.IsNormal(aZDir, Precision::Angular()))
{
std::cout << "vconnect error : XDir expects to be normal to ZDir\n";
return 1; // TCL_ERROR
}
gp_Ax3 anAx3(aPoint, aZDir, anXDir);
gp_Trsf aTrsf;
aTrsf.SetTransformation(anAx3);
TopLoc_Location aLocation(aTrsf);
// Create connected object
Handle(AIS_ConnectedInteractive) aConnectedObject = new AIS_ConnectedInteractive();
aConnectedObject->Connect(anOriginObject, aLocation);
// Check if there is another object with given name
// and remove it from context
if(GetMapOfAIS().IsBound2(aName))
{
Handle(AIS_InteractiveObject) anObj =
Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
TheAISContext()->Remove(anObj, Standard_False);
GetMapOfAIS().UnBind2(aName);
}
// Bind connected object to its name
GetMapOfAIS().Bind(aConnectedObject, aName);
// Display connected object
TheAISContext()->Display(aConnectedObject);
return 0;
}
//===============================================================================================
//function : VConnectShape
//purpose : Creates and displays AIS_ConnectedShape from input shape and location
//Draw arg : vconnectsh name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw
//===============================================================================================
static Standard_Integer VConnectShape(Draw_Interpretor& di,
Standard_Integer argc,
const char ** argv)
{
// Check argumnets
if(argc != 12)
{
std::cout << "vconnectsh error: expect 11 argumnets\n";
return 1; // TCL_ERROR
}
// Get values
TCollection_AsciiString aName(argv[1]);
TCollection_AsciiString anOriginShapeName(argv[2]);
if(aName.IsEqual(anOriginShapeName))
{
std::cout << "vconnectsh error: equal names for connected shapes\n";
return 1; // TCL_ERROR
}
// Check if the origin shape is not null
Handle(AIS_InteractiveObject) anOriginShape;
if(GetMapOfAIS().IsBound2(anOriginShapeName))
{
Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(anOriginShapeName);
anOriginShape = Handle(AIS_InteractiveObject)::DownCast(anObj);
if(anOriginShape.IsNull())
{
std::cout << "Shape " << anOriginShapeName << " is used for non AIS viewer\n!";
return 1; // TCL_ERROR
}
}
// Get location data
Standard_Real aXo = atof(argv[3]);
Standard_Real aYo = atof(argv[4]);
Standard_Real aZo = atof(argv[5]);
Standard_Real aXu = atof(argv[6]);
Standard_Real aXv = atof(argv[7]);
Standard_Real aXw = atof(argv[8]);
Standard_Real aZu = atof(argv[9]);
Standard_Real aZv = atof(argv[10]);
Standard_Real aZw = atof(argv[11]);
// Create transformation
gp_Pnt aPoint(aXo, aYo, aZo);
gp_Dir anXDir(aXu, aXv, aXw), aZDir(aZu, aZv, aZw);
if(!anXDir.IsNormal(aZDir, Precision::Angular()))
{
std::cout << "vconnectsh error : XDir expects to be normal to ZDir\n";
return 1; // TCL_ERROR
}
gp_Ax3 anAx3(aPoint, aZDir, anXDir);
gp_Trsf aTrsf;
aTrsf.SetTransformation(anAx3);
TopLoc_Location aLocation(aTrsf);
// Create connected shape
Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(anOriginShape);
Handle(AIS_ConnectedShape) aConnectedShape = new AIS_ConnectedShape(aShape);
aConnectedShape->Connect(anOriginShape, aLocation);
// Check if there is another object with given name
// and remove it from context
if(GetMapOfAIS().IsBound2(aName))
{
Handle(AIS_InteractiveObject) anObj =
Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
TheAISContext()->Remove(anObj, Standard_False);
GetMapOfAIS().UnBind2(aName);
}
// Bind connected shape to its name
GetMapOfAIS().Bind(aConnectedShape, aName);
// Display connected shape
TheAISContext()->Display(aConnectedShape);
return 0;
}
//===============================================================================================
//function : VSetSelectionMode
//purpose : Sets input selection mode for input object or for all displayed objects
//Draw arg : vselmode [object] mode On/Off (1/0)
//===============================================================================================
// function : InList
// purpose : checks if theMode is already turned on for theObj
Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext,
Handle(AIS_InteractiveObject) theObj,
Standard_Integer theMode)
{
TColStd_ListOfInteger anArray;
theAISContext->ActivatedModes(theObj, anArray);
TColStd_ListIteratorOfListOfInteger anIt(anArray);
for(; anIt.More(); anIt.Next())
{
if(anIt.Value() == theMode)
return Standard_True;
}
return Standard_False;
}
static Standard_Integer VSetSelectionMode(Draw_Interpretor& di,
Standard_Integer argc,
const char ** argv)
{
// Check errors
Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext();
if(anAISContext.IsNull())
{
std::cout << "Call vinit before!\n";
return 1; // TCL_ERROR
}
// Check the arguments
if(argc != 3 && argc != 4)
{
std::cout << "vselmode error : expects at least 2 arguments\n";
return 1; // TCL_ERROR
}
Handle(AIS_InteractiveObject) anObj;
// Set new selection mode for all objects in context
if(argc == 3)
{
// Get arguments
Standard_Integer aMode = atoi(argv[1]);
Standard_Boolean isTurnOn = atoi(argv[2]);
// Get all displayed objects
AIS_ListOfInteractive anObjList;
anAISContext->DisplayedObjects(anObjList);
AIS_ListIteratorOfListOfInteractive anObjIter;
if(aMode == 0)
{
if(anAISContext->HasOpenedContext())
anAISContext->CloseLocalContext();
}
// Turn on aMode
if(aMode != 0 && isTurnOn)
{
if(!anAISContext->HasOpenedContext())
{
anAISContext->OpenLocalContext();
for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
{
anAISContext->Activate(anObjIter.Value(), aMode);
}
}
else
{
for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
{
anObj = anObjIter.Value();
if(!InList(anAISContext, anObj, aMode))
anAISContext->Activate(anObj, aMode);
}
}
}
// Turn off aMode
if(aMode != 0 && !isTurnOn)
{
if(anAISContext->HasOpenedContext())
{
for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next())
{
anObj = anObjIter.Value();
if(InList(anAISContext, anObj, aMode))
anAISContext->Deactivate(anObj, aMode);
}
}
}
}
// Set new selection mode for named object
else
{
// Get argumnets
Standard_Integer aMode = atoi(argv[2]);
Standard_Boolean isTurnOn = atoi(argv[3]);
TCollection_AsciiString aName(argv[1]);
// Check if there is an object with given name in context
if(GetMapOfAIS().IsBound2(aName))
{
anObj = Handle(AIS_InteractiveObject)::
DownCast(GetMapOfAIS().Find2(aName));
if(anObj.IsNull())
{
std::cout << "vselmode error : object name is used for non AIS viewer\n";
return 1; // TCL_ERROR
}
}
if(aMode == 0)
{
if(anAISContext->HasOpenedContext())
anAISContext->CloseLocalContext();
}
// Turn on aMode
if(aMode != 0 && isTurnOn)
{
if(!anAISContext->HasOpenedContext())
{
anAISContext->OpenLocalContext();
anAISContext->Activate(anObj, aMode);
}
else
{
if(!InList(anAISContext, anObj, aMode))
anAISContext->Activate(anObj, aMode);
}
}
// Turn off aMode
if(aMode != 0 && !isTurnOn)
{
if(anAISContext->HasOpenedContext())
{
if(InList(anAISContext, anObj, aMode))
anAISContext->Deactivate(anObj, aMode);
}
}
}
return 0;
}
//======================================================================= //=======================================================================
//function : ObjectsCommands //function : ObjectsCommands
//purpose : //purpose :
@ -3569,4 +3895,16 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands)
theCommands.Add("vdrawparray", theCommands.Add("vdrawparray",
"vdrawparray : vdrawparray Name TypeOfArray [EnableVbo=1] [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id [edge_hidden = { 'h' }] ]", "vdrawparray : vdrawparray Name TypeOfArray [EnableVbo=1] [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id [edge_hidden = { 'h' }] ]",
__FILE__,VDrawPArray,group); __FILE__,VDrawPArray,group);
theCommands.Add("vconnect",
"vconnect : name object Xo Yo Zo Xu Xv Xw Zu Zv Zw",
__FILE__, VConnect, group);
theCommands.Add("vconnectsh",
"vconnectsh : name shape Xo Yo Zo Xu Xv Xw Zu Zv Zw",
__FILE__, VConnectShape, group);
theCommands.Add("vselmode",
"vselmode : [object] mode On/Off (1/0)",
__FILE__, VSetSelectionMode, group);
} }